1- # coding: utf-8
2- # cython: freethreading_compatible = True
31from cpython cimport *
42cdef extern from " Python.h" :
53 ctypedef struct PyObject
@@ -324,6 +322,7 @@ cdef class Unpacker:
324322 PyMem_Free(self .buf)
325323 self .buf = NULL
326324
325+ @cython.critical_section
327326 def __init__ (self , file_like = None , *, Py_ssize_t read_size = 0 ,
328327 bint use_list = True , bint raw = False , int timestamp = 0 , bint strict_map_key = True ,
329328 object object_hook = None , object object_pairs_hook = None , object list_hook = None ,
@@ -384,6 +383,7 @@ cdef class Unpacker:
384383 max_str_len, max_bin_len, max_array_len,
385384 max_map_len, max_ext_len)
386385
386+ @cython.critical_section
387387 def feed (self , object next_bytes ):
388388 """ Append `next_bytes` to internal buffer."""
389389 cdef Py_buffer pybuff
@@ -484,6 +484,7 @@ cdef class Unpacker:
484484 else :
485485 raise ValueError (" Unpack failed: error = %d " % (ret,))
486486
487+ @cython.critical_section
487488 def read_bytes (self , Py_ssize_t nbytes ):
488489 """ Read a specified number of raw bytes from the stream"""
489490 cdef Py_ssize_t nread
@@ -496,20 +497,23 @@ cdef class Unpacker:
496497 self .stream_offset += nread
497498 return ret
498499
500+ @cython.critical_section
499501 def unpack (self ):
500502 """ Unpack one object
501503
502504 Raises `OutOfData` when there are no more bytes to unpack.
503505 """
504506 return self ._unpack(unpack_construct)
505507
508+ @cython.critical_section
506509 def skip (self ):
507510 """ Read and ignore one object, returning None
508511
509512 Raises `OutOfData` when there are no more bytes to unpack.
510513 """
511514 return self ._unpack(unpack_skip)
512515
516+ @cython.critical_section
513517 def read_array_header (self ):
514518 """ assuming the next object is an array, return its size n, such that
515519 the next n unpack() calls will iterate over its contents.
@@ -518,6 +522,7 @@ cdef class Unpacker:
518522 """
519523 return self ._unpack(read_array_header)
520524
525+ @cython.critical_section
521526 def read_map_header (self ):
522527 """ assuming the next object is a map, return its size n, such that the
523528 next n * 2 unpack() calls will iterate over its key-value pairs.
@@ -526,6 +531,7 @@ cdef class Unpacker:
526531 """
527532 return self ._unpack(read_map_header)
528533
534+ @cython.critical_section
529535 def tell (self ):
530536 """ Returns the current position of the Unpacker in bytes, i.e., the
531537 number of bytes that were read from the input, also the starting
@@ -536,6 +542,7 @@ cdef class Unpacker:
536542 def __iter__ (self ):
537543 return self
538544
545+ @cython.critical_section
539546 def __next__ (self ):
540547 return self ._unpack(unpack_construct, 1 )
541548
0 commit comments