diff options
author | Naoki INADA <inada-n@klab.jp> | 2009-12-17 11:13:47 +0900 |
---|---|---|
committer | Naoki INADA <inada-n@klab.jp> | 2009-12-17 11:13:47 +0900 |
commit | 77e3e59620d65589451c833fa01e9c9e5f39624d (patch) | |
tree | 9486f063c73b9c82acad8ecfbe42c1f22fd48882 /msgpack/unpack.h | |
parent | af7c4d2a60086503ee9c124f8cc79a05c2fabe70 (diff) | |
download | msgpack-python-77e3e59620d65589451c833fa01e9c9e5f39624d.tar.gz |
Add `use_tuple` option that returns tuple for array object to Unpacker.
Diffstat (limited to 'msgpack/unpack.h')
-rw-r--r-- | msgpack/unpack.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/msgpack/unpack.h b/msgpack/unpack.h index 40058d0..0bf2568 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -20,6 +20,7 @@ #include "unpack_define.h" typedef struct unpack_user { + int use_tuple; } unpack_user; @@ -135,7 +136,8 @@ static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o) { - PyObject *p = PyList_New(n); + PyObject *p = u->use_tuple ? PyTuple_New(n) : PyList_New(n); + if (!p) return -1; *o = p; @@ -143,7 +145,15 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac } static inline int template_callback_array_item(unpack_user* u, unsigned int current, msgpack_unpack_object* c, msgpack_unpack_object o) -{ PyList_SET_ITEM(*c, current, o); return 0; } +{ + if (u->use_tuple) { + PyTuple_SET_ITEM(*c, current, o); + } + else { + PyList_SET_ITEM(*c, current, o); + } + return 0; +} static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o) { |