mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-24 17:30:46 +02:00
python: Disable gc while deserializing.
This commit is contained in:
@@ -9,6 +9,9 @@ cdef extern from "Python.h":
|
|||||||
|
|
||||||
from libc.stdlib cimport *
|
from libc.stdlib cimport *
|
||||||
from libc.string cimport *
|
from libc.string cimport *
|
||||||
|
import gc
|
||||||
|
_gc_disable = gc.disable
|
||||||
|
_gc_enable = gc.enable
|
||||||
|
|
||||||
cdef extern from "pack.h":
|
cdef extern from "pack.h":
|
||||||
struct msgpack_packer:
|
struct msgpack_packer:
|
||||||
@@ -187,7 +190,9 @@ def unpackb(object packed, object object_hook=None, object list_hook=None, bint
|
|||||||
if not PyCallable_Check(list_hook):
|
if not PyCallable_Check(list_hook):
|
||||||
raise TypeError("list_hook must be a callable.")
|
raise TypeError("list_hook must be a callable.")
|
||||||
ctx.user.list_hook = <PyObject*>list_hook
|
ctx.user.list_hook = <PyObject*>list_hook
|
||||||
|
_gc_disable()
|
||||||
ret = template_execute(&ctx, buf, buf_len, &off)
|
ret = template_execute(&ctx, buf, buf_len, &off)
|
||||||
|
_gc_enable()
|
||||||
if ret == 1:
|
if ret == 1:
|
||||||
return template_data(&ctx)
|
return template_data(&ctx)
|
||||||
else:
|
else:
|
||||||
@@ -326,7 +331,9 @@ cdef class Unpacker(object):
|
|||||||
"""unpack one object"""
|
"""unpack one object"""
|
||||||
cdef int ret
|
cdef int ret
|
||||||
while 1:
|
while 1:
|
||||||
|
_gc_disable()
|
||||||
ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head)
|
ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head)
|
||||||
|
_gc_enable()
|
||||||
if ret == 1:
|
if ret == 1:
|
||||||
o = template_data(&self.ctx)
|
o = template_data(&self.ctx)
|
||||||
template_init(&self.ctx)
|
template_init(&self.ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user