1- # coding: utf-8
2-
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
@@ -400,6 +400,7 @@ cdef class Unpacker:
400400 finally :
401401 PyBuffer_Release(& pybuff)
402402
403+ @cython.critical_section
403404 cdef append_buffer(self , void * _buf, Py_ssize_t _buf_len):
404405 cdef:
405406 char * buf = self .buf
@@ -484,6 +485,7 @@ cdef class Unpacker:
484485 else :
485486 raise ValueError (" Unpack failed: error = %d " % (ret,))
486487
488+ @cython.critical_section
487489 def read_bytes (self , Py_ssize_t nbytes ):
488490 """ Read a specified number of raw bytes from the stream"""
489491 cdef Py_ssize_t nread
@@ -496,20 +498,23 @@ cdef class Unpacker:
496498 self .stream_offset += nread
497499 return ret
498500
501+ @cython.critical_section
499502 def unpack (self ):
500503 """ Unpack one object
501504
502505 Raises `OutOfData` when there are no more bytes to unpack.
503506 """
504507 return self ._unpack(unpack_construct)
505508
509+ @cython.critical_section
506510 def skip (self ):
507511 """ Read and ignore one object, returning None
508512
509513 Raises `OutOfData` when there are no more bytes to unpack.
510514 """
511515 return self ._unpack(unpack_skip)
512516
517+ @cython.critical_section
513518 def read_array_header (self ):
514519 """ assuming the next object is an array, return its size n, such that
515520 the next n unpack() calls will iterate over its contents.
@@ -518,6 +523,7 @@ cdef class Unpacker:
518523 """
519524 return self ._unpack(read_array_header)
520525
526+ @cython.critical_section
521527 def read_map_header (self ):
522528 """ assuming the next object is a map, return its size n, such that the
523529 next n * 2 unpack() calls will iterate over its key-value pairs.
@@ -526,6 +532,7 @@ cdef class Unpacker:
526532 """
527533 return self ._unpack(read_map_header)
528534
535+ @cython.critical_section
529536 def tell (self ):
530537 """ Returns the current position of the Unpacker in bytes, i.e., the
531538 number of bytes that were read from the input, also the starting
@@ -536,6 +543,7 @@ cdef class Unpacker:
536543 def __iter__ (self ):
537544 return self
538545
546+ @cython.critical_section
539547 def __next__ (self ):
540548 return self ._unpack(unpack_construct, 1 )
541549
0 commit comments