@@ -209,7 +209,7 @@ cdef extern from "unpack.h":
209
209
PyObject* key
210
210
211
211
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
213
213
void template_init(template_context* ctx)
214
214
object template_data(template_context* ctx)
215
215
@@ -255,7 +255,7 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
255
255
if not PyCallable_Check(list_hook):
256
256
raise TypeError (" list_hook must be a callable." )
257
257
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 )
259
259
if ret == 1 :
260
260
obj = template_data(& ctx)
261
261
if off < buf_len:
@@ -451,12 +451,18 @@ cdef class Unpacker(object):
451
451
else :
452
452
self .file_like = None
453
453
454
- cpdef _unpack(self , bool construct):
454
+ cdef _unpack(self , bint construct):
455
455
cdef int ret
456
+ cdef object obj
456
457
while 1 :
457
458
ret = template_execute(& self .ctx, self .buf, self .buf_tail, & self .buf_head, construct)
458
459
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
460
466
elif ret == 0 :
461
467
if self .file_like is not None :
462
468
self .read_from_file()
@@ -465,23 +471,19 @@ cdef class Unpacker(object):
465
471
else :
466
472
raise ValueError (" Unpack failed: error = %d " % (ret,))
467
473
468
- cpdef unpack(self ):
474
+ def unpack (self ):
469
475
""" unpack one object"""
470
- self ._unpack(True )
471
- o = template_data(& self .ctx)
472
- template_init(& self .ctx)
473
-
476
+ return self ._unpack(1 )
474
477
475
- cpdef skip(self ):
478
+ def skip (self ):
476
479
""" read and ignore one object, returning None"""
477
- self ._unpack(False )
478
- template_init(& self .ctx)
480
+ return self ._unpack(0 )
479
481
480
482
def __iter__ (self ):
481
483
return self
482
484
483
485
def __next__ (self ):
484
- return self .unpack( )
486
+ return self ._unpack( 1 )
485
487
486
488
# for debug.
487
489
# def _buf(self):
0 commit comments