mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-26 15:14:10 +00:00
free buffer when packer deleted.
This commit is contained in:
parent
a06a5ce46f
commit
85b68fbf8c
2 changed files with 437 additions and 225 deletions
|
|
@ -59,6 +59,8 @@ cdef class Packer:
|
||||||
|
|
||||||
msgpack_packer_init(&self.pk, <void*>self, <msgpack_packer_write>_packer_write)
|
msgpack_packer_init(&self.pk, <void*>self, <msgpack_packer_write>_packer_write)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
free(self.buff);
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""Flash local buffer and output stream if it has 'flush()' method."""
|
"""Flash local buffer and output stream if it has 'flush()' method."""
|
||||||
|
|
@ -98,7 +100,7 @@ cdef class Packer:
|
||||||
"""
|
"""
|
||||||
msgpack_pack_map(&self.pk, len)
|
msgpack_pack_map(&self.pk, len)
|
||||||
|
|
||||||
def pack(self, object o):
|
cdef __pack(self, object o):
|
||||||
cdef long long intval
|
cdef long long intval
|
||||||
cdef double fval
|
cdef double fval
|
||||||
cdef char* rawval
|
cdef char* rawval
|
||||||
|
|
@ -140,6 +142,11 @@ cdef class Packer:
|
||||||
# TODO: Serialize with defalt() like simplejson.
|
# TODO: Serialize with defalt() like simplejson.
|
||||||
raise TypeError, "can't serialize %r" % (o,)
|
raise TypeError, "can't serialize %r" % (o,)
|
||||||
|
|
||||||
|
def pack(self, obj, flush=True):
|
||||||
|
self.__pack(obj)
|
||||||
|
if flush:
|
||||||
|
self.flush()
|
||||||
|
|
||||||
cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l):
|
cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l):
|
||||||
if packer.length + l > packer.allocated:
|
if packer.length + l > packer.allocated:
|
||||||
if packer.length > 0:
|
if packer.length > 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue