diff options
| author | INADA Naoki <songofacandy@gmail.com> | 2013-10-20 09:18:50 -0700 |
|---|---|---|
| committer | INADA Naoki <songofacandy@gmail.com> | 2013-10-20 09:18:50 -0700 |
| commit | e802abebf18f0126aaad0c7bdf8ba0042cb4602d (patch) | |
| tree | 67e86c2d28bce248448c8bb92ba196c1381c5d12 /msgpack/unpack.h | |
| parent | ec0691fb2c7ca28eb4544b98dcb5e59933233997 (diff) | |
| parent | d84a403bc0bbbb36c4a5833e00269eef6c4a91ae (diff) | |
| download | msgpack-python-e802abebf18f0126aaad0c7bdf8ba0042cb4602d.tar.gz | |
Merge pull request #79 from msgpack/newspec
[WIP] Newspec stage 2.
Diffstat (limited to 'msgpack/unpack.h')
| -rw-r--r-- | msgpack/unpack.h | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/msgpack/unpack.h b/msgpack/unpack.h index 03c735e..aced40b 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -24,6 +24,7 @@ typedef struct unpack_user { PyObject *object_hook; bool has_pairs_hook; PyObject *list_hook; + PyObject *ext_hook; const char *encoding; const char *unicode_errors; } unpack_user; @@ -156,7 +157,7 @@ static inline int unpack_callback_array_item(unpack_user* u, unsigned int curren static inline int unpack_callback_array_end(unpack_user* u, msgpack_unpack_object* c) { if (u->list_hook) { - PyObject *new_c = PyEval_CallFunction(u->list_hook, "(O)", *c); + PyObject *new_c = PyObject_CallFunctionObjArgs(u->list_hook, *c, NULL); if (!new_c) return -1; Py_DECREF(*c); @@ -202,7 +203,7 @@ static inline int unpack_callback_map_item(unpack_user* u, unsigned int current, static inline int unpack_callback_map_end(unpack_user* u, msgpack_unpack_object* c) { if (u->object_hook) { - PyObject *new_c = PyEval_CallFunction(u->object_hook, "(O)", *c); + PyObject *new_c = PyObject_CallFunctionObjArgs(u->object_hook, *c, NULL); if (!new_c) return -1; @@ -235,4 +236,25 @@ static inline int unpack_callback_bin(unpack_user* u, const char* b, const char* return 0; } +static inline int unpack_callback_ext(unpack_user* u, const char* base, const char* pos, + unsigned int lenght, msgpack_unpack_object* o) +{ + PyObject *py; + int8_t typecode = (int8_t)*pos++; + if (!u->ext_hook) { + PyErr_SetString(PyExc_AssertionError, "u->ext_hook cannot be NULL"); + return -1; + } + // length also includes the typecode, so the actual data is lenght-1 +#if PY_MAJOR_VERSION == 2 + py = PyObject_CallFunction(u->ext_hook, "(is#)", typecode, pos, lenght-1); +#else + py = PyObject_CallFunction(u->ext_hook, "(iy#)", typecode, pos, lenght-1); +#endif + if (!py) + return -1; + *o = py; + return 0; +} + #include "unpack_template.h" |
