gemini-code-assist[bot] commented on code in PR #38407:
URL: https://github.com/apache/beam/pull/38407#discussion_r3219970160


##########
sdks/python/apache_beam/utils/byte_limited_queue.pxd:
##########
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# cython: overflowcheck=True
+
+cdef class ByteLimitedQueue(object):
+  cdef readonly int max_elements
+  cdef readonly int max_bytes
+  cdef readonly int _byte_size
+  cdef readonly object _mutex
+  cdef readonly object _not_empty
+  cdef readonly object _waiting_writers
+  cdef readonly object _queue
+  cdef readonly int _blocked_bytes
+
+  cpdef bint _is_full_locked(self, int item_bytes) except -1

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Using `int` for byte sizes and element counts in Cython can lead to overflow 
issues on 32-bit systems or when handling very large data volumes (e.g., 
`_blocked_bytes` could easily exceed 2GB if many writers are blocked). It is 
safer to use `Py_ssize_t` or `long long` for these fields to ensure they can 
handle 64-bit values.
   
   ```
   cdef class ByteLimitedQueue(object):
     cdef readonly Py_ssize_t max_elements
     cdef readonly Py_ssize_t max_bytes
     cdef readonly Py_ssize_t _byte_size
     cdef readonly object _mutex
     cdef readonly object _not_empty
     cdef readonly object _waiting_writers
     cdef readonly object _queue
     cdef readonly Py_ssize_t _blocked_bytes
   
     cpdef bint _is_full_locked(self, Py_ssize_t item_bytes) except -1
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to