@@ -209,7 +209,7 @@ cdef extern from "unpack.h":
209209 PyObject* key
210210
211211 int template_execute(template_context* ctx, const_char_ptr data,
212- size_t len , size_t* off, bool construct) except - 1
212+ size_t len , size_t* off, bint construct) except - 1
213213 void template_init(template_context* ctx)
214214 object template_data(template_context* ctx)
215215
@@ -255,7 +255,7 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
255255 if not PyCallable_Check(list_hook):
256256 raise TypeError (" list_hook must be a callable." )
257257 ctx.user.list_hook = < PyObject* > list_hook
258- ret = template_execute(& ctx, buf, buf_len, & off, True )
258+ ret = template_execute(& ctx, buf, buf_len, & off, 1 )
259259 if ret == 1 :
260260 obj = template_data(& ctx)
261261 if off < buf_len:
@@ -451,12 +451,18 @@ cdef class Unpacker(object):
451451 else :
452452 self .file_like = None
453453
454- cpdef _unpack(self , bool construct):
454+ cdef _unpack(self , bint construct):
455455 cdef int ret
456+ cdef object obj
456457 while 1 :
457458 ret = template_execute(& self .ctx, self .buf, self .buf_tail, & self .buf_head, construct)
458459 if ret == 1 :
459- return
460+ if construct:
461+ obj = template_data(& self .ctx)
462+ else :
463+ obj = None
464+ template_init(& self .ctx)
465+ return obj
460466 elif ret == 0 :
461467 if self .file_like is not None :
462468 self .read_from_file()
@@ -465,23 +471,19 @@ cdef class Unpacker(object):
465471 else :
466472 raise ValueError (" Unpack failed: error = %d " % (ret,))
467473
468- cpdef unpack(self ):
474+ def unpack (self ):
469475 """ unpack one object"""
470- self ._unpack(True )
471- o = template_data(& self .ctx)
472- template_init(& self .ctx)
473-
476+ return self ._unpack(1 )
474477
475- cpdef skip(self ):
478+ def skip (self ):
476479 """ read and ignore one object, returning None"""
477- self ._unpack(False )
478- template_init(& self .ctx)
480+ return self ._unpack(0 )
479481
480482 def __iter__ (self ):
481483 return self
482484
483485 def __next__ (self ):
484- return self .unpack( )
486+ return self ._unpack( 1 )
485487
486488 # for debug.
487489 # def _buf(self):
0 commit comments