diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx index f758c0c4..e0463617 100644 --- a/msgpack/_unpacker.pyx +++ b/msgpack/_unpacker.pyx @@ -46,7 +46,7 @@ cdef extern from "unpack.h": Py_ssize_t count ctypedef int (*execute_fn)(unpack_context* ctx, const char* data, - Py_ssize_t len, Py_ssize_t* off) except? -1 + Py_ssize_t len, Py_ssize_t* off) except -1 execute_fn unpack_construct execute_fn unpack_skip execute_fn read_array_header @@ -206,8 +206,6 @@ def unpackb(object packed, *, object object_hook=None, object list_hook=None, raise FormatError elif ret == -3: raise StackError - elif PyErr_Occurred(): - raise else: raise ValueError("Unpack failed: error = %d" % (ret,)) @@ -502,8 +500,6 @@ cdef class Unpacker: raise FormatError elif ret == -3: raise StackError - elif PyErr_Occurred(): - raise else: raise ValueError("Unpack failed: error = %d" % (ret,)) finally: diff --git a/msgpack/unpack.h b/msgpack/unpack.h index 55cfdab9..eb4330ac 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -40,11 +40,6 @@ struct unpack_context; typedef struct unpack_context unpack_context; typedef int (*execute_fn)(unpack_context *ctx, const char* data, Py_ssize_t len, Py_ssize_t* off); -static inline msgpack_unpack_object unpack_callback_root(unpack_user* u) -{ - return NULL; -} - static inline int unpack_callback_uint16(unpack_user* u, uint16_t d, msgpack_unpack_object* o) { PyObject *p = PyLong_FromLong((long)d); diff --git a/msgpack/unpack_template.h b/msgpack/unpack_template.h index ab5887ae..797a2f91 100644 --- a/msgpack/unpack_template.h +++ b/msgpack/unpack_template.h @@ -35,11 +35,6 @@ struct unpack_context { unsigned int cs; unsigned int trail; unsigned int top; - /* - unpack_stack* stack; - unsigned int stack_size; - unpack_stack embed_stack[MSGPACK_EMBED_STACK_SIZE]; - */ unpack_stack stack[MSGPACK_EMBED_STACK_SIZE]; }; @@ -49,22 +44,9 @@ static inline void unpack_init(unpack_context* ctx) ctx->cs = CS_HEADER; ctx->trail = 0; ctx->top = 0; - /* - ctx->stack = ctx->embed_stack; - ctx->stack_size = MSGPACK_EMBED_STACK_SIZE; - */ - ctx->stack[0].obj = unpack_callback_root(&ctx->user); + ctx->stack[0].obj = NULL; } -/* -static inline void unpack_destroy(unpack_context* ctx) -{ - if(ctx->stack_size != MSGPACK_EMBED_STACK_SIZE) { - free(ctx->stack); - } -} -*/ - static inline PyObject* unpack_data(unpack_context* ctx) { return (ctx)->stack[0].obj; @@ -94,9 +76,6 @@ static inline int unpack_execute(bool construct, unpack_context* ctx, const char unsigned int cs = ctx->cs; unsigned int top = ctx->top; unpack_stack* stack = ctx->stack; - /* - unsigned int stack_size = ctx->stack_size; - */ unpack_user* user = &ctx->user; PyObject* obj = NULL; @@ -319,6 +298,7 @@ static inline int unpack_execute(bool construct, unpack_context* ctx, const char start_container(_map, _msgpack_load32(uint32_t,n), CT_MAP_KEY); default: + PyErr_Format(PyExc_RuntimeError, "Invalid state: %d", cs); goto _failed; } } @@ -355,6 +335,7 @@ static inline int unpack_execute(bool construct, unpack_context* ctx, const char goto _header_again; default: + PyErr_Format(PyExc_RuntimeError, "Invalid container type: %u", c->ct); goto _failed; }