mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-11-10 06:21:03 +00:00
Merge pull request #155 from methane/fix/152
Decrease refcnt when error happend while unpacking
This commit is contained in:
commit
dbe6572ee5
2 changed files with 7 additions and 2 deletions
|
|
@ -47,6 +47,7 @@ cdef extern from "unpack.h":
|
|||
execute_fn read_map_header
|
||||
void unpack_init(unpack_context* ctx)
|
||||
object unpack_data(unpack_context* ctx)
|
||||
void unpack_clear(unpack_context* ctx)
|
||||
|
||||
cdef inline init_ctx(unpack_context *ctx,
|
||||
object object_hook, object object_pairs_hook,
|
||||
|
|
@ -141,8 +142,8 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
|
|||
if off < buf_len:
|
||||
raise ExtraData(obj, PyBytes_FromStringAndSize(buf+off, buf_len-off))
|
||||
return obj
|
||||
else:
|
||||
raise UnpackValueError("Unpack failed: error = %s" % (ret,))
|
||||
unpack_clear(&ctx)
|
||||
raise UnpackValueError("Unpack failed: error = %d" % (ret,))
|
||||
|
||||
|
||||
def unpack(object stream, object object_hook=None, object list_hook=None,
|
||||
|
|
|
|||
|
|
@ -70,6 +70,10 @@ static inline PyObject* unpack_data(unpack_context* ctx)
|
|||
return (ctx)->stack[0].obj;
|
||||
}
|
||||
|
||||
static inline PyObject* unpack_clear(unpack_context *ctx)
|
||||
{
|
||||
Py_CLEAR(ctx->stack[0].obj);
|
||||
}
|
||||
|
||||
template <bool construct>
|
||||
static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize_t len, Py_ssize_t* off)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue