From 3628ea22d4079fa0a235a938eadf7b24943e326c Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Fri, 22 May 2009 14:31:20 +0900 Subject: add pyx --- python/msgpack.pyx | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 python/msgpack.pyx (limited to 'python') diff --git a/python/msgpack.pyx b/python/msgpack.pyx new file mode 100644 index 0000000..6885317 --- /dev/null +++ b/python/msgpack.pyx @@ -0,0 +1,162 @@ +# coding: utf-8 + + +cdef extern from "Python.h": + ctypedef char* const_char_ptr "const char*" + cdef object PyString_FromStringAndSize(const_char_ptr b, Py_ssize_t len) + +cdef extern from "stdlib.h": + void* malloc(int) + void free(void*) +cdef extern from "string.h": + int memcpy(char*dst, char*src, unsigned int size) + +cdef extern from "msgpack/pack.h": + ctypedef int (*msgpack_packer_write)(void* data, const_char_ptr buf, unsigned int len) + + struct msgpack_packer: + void *data + msgpack_packer_write callback + + void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) + void msgpack_pack_int(msgpack_packer* pk, int d) + void msgpack_pack_nil(msgpack_packer* pk) + void msgpack_pack_true(msgpack_packer* pk) + void msgpack_pack_false(msgpack_packer* pk) + void msgpack_pack_long_long(msgpack_packer* pk, long long d) + void msgpack_pack_double(msgpack_packer* pk, double d) + void msgpack_pack_array(msgpack_packer* pk, size_t l) + void msgpack_pack_map(msgpack_packer* pk, size_t l) + void msgpack_pack_raw(msgpack_packer* pk, size_t l) + void msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) + +cdef extern from "msgpack/unpack.h": + ctypedef struct msgpack_unpacker + + +cdef int BUFF_SIZE=2*1024 + +cdef class Packer: + cdef char* buff + cdef unsigned int length + cdef unsigned int allocated + cdef msgpack_packer pk + cdef object strm + + def __init__(self, strm, int size=0): + """Make packer that pack data into strm. + + strm must have `write(bytes)` method. + size specifies local buffer size. + """ + if size <= 0: + size = BUFF_SIZE + + self.strm = strm + self.buff = malloc(size) + self.allocated = size + self.length = 0 + + msgpack_packer_init(&self.pk, self, _packer_write) + + + def flush(self): + """Flash local buffer and output stream if it has 'flush()' method.""" + if self.length > 0: + self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) + self.length = 0 + if hasattr(self.strm, 'flush'): + self.strm.flush() + + def pack_list(self, len): + """Start packing sequential objects. + + Example: + + packer.pack_list(2) + packer.pack('foo') + packer.pack('bar') + + This code is same as below code: + + packer.pack(['foo', 'bar']) + """ + msgpack_pack_array(&self.pk, len) + + def pack_dict(self, len): + """Start packing key-value objects. + + Example: + + packer.pack_dict(1) + packer.pack('foo') + packer.pack('bar') + + This code is same as below code: + + packer.pack({'foo', 'bar'}) + """ + msgpack_pack_map(&self.pk, len) + + def __call__(self, object o): + cdef long long intval + cdef double fval + cdef char* rawval + + if o is None: + msgpack_pack_nil(&self.pk) + elif o is True: + msgpack_pack_true(&self.pk) + elif o is False: + msgpack_pack_false(&self.pk) + elif isinstance(o, int): + intval = o + msgpack_pack_long_long(&self.pk, intval) + elif isinstance(o, float): + fval = 9 + msgpack_pack_double(&self.pk, fval) + elif isinstance(o, str): + rawval = o + msgpack_pack_raw(&self.pk, len(o)) + msgpack_pack_raw_body(&self.pk, rawval, len(o)) + elif isinstance(o, unicode): + # todo + pass + elif isinstance(o, dict): + msgpack_pack_map(&self.pk, len(o)) + for k,v in o.iteritems(): + self(k) + self(v) + elif isinstance(o, tuple): + msgpack_pack_array(&self.pk, len(o)) + for v in o: + self(v) + elif isinstance(o, list): + msgpack_pack_array(&self.pk, len(o)) + for v in o: + self(v) + elif hasattr(o, "__msgpack__"): + o.__msgpack__(self) + else: + raise TypeError, "can't serialize %r" % (o,) + +cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): + if packer.length + l > packer.allocated: + if packer.length > 0: + packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + if l > 64: + packer.strm.write(PyString_FromStringAndSize(b, l)) + packer.length = 0 + else: + memcpy(packer.buff, b, l) + packer.length = l + else: + memcpy(packer.buff + packer.length, b, l) + packer.length += l + return 0 + +cdef class Unpacker: + def __init__(self): + pass + def unpack(strm): + pass -- cgit v1.2.1 From 711e4817a5e35a32c4b577664d8096de00fa802b Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 8 Jun 2009 00:23:38 +0900 Subject: support packing long and tuple. add missing files. --- python/msgpack.pyx | 53 ++++--- python/pack.h | 130 ++++++++++++++++++ python/unpack.h | 397 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 563 insertions(+), 17 deletions(-) create mode 100644 python/pack.h create mode 100644 python/unpack.h (limited to 'python') diff --git a/python/msgpack.pyx b/python/msgpack.pyx index 6885317..ceae9b6 100644 --- a/python/msgpack.pyx +++ b/python/msgpack.pyx @@ -3,15 +3,17 @@ cdef extern from "Python.h": ctypedef char* const_char_ptr "const char*" + ctypedef struct PyObject cdef object PyString_FromStringAndSize(const_char_ptr b, Py_ssize_t len) cdef extern from "stdlib.h": void* malloc(int) void free(void*) + cdef extern from "string.h": int memcpy(char*dst, char*src, unsigned int size) -cdef extern from "msgpack/pack.h": +cdef extern from "pack.h": ctypedef int (*msgpack_packer_write)(void* data, const_char_ptr buf, unsigned int len) struct msgpack_packer: @@ -30,7 +32,7 @@ cdef extern from "msgpack/pack.h": void msgpack_pack_raw(msgpack_packer* pk, size_t l) void msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) -cdef extern from "msgpack/unpack.h": +cdef extern from "unpack.h": ctypedef struct msgpack_unpacker @@ -98,7 +100,7 @@ cdef class Packer: """ msgpack_pack_map(&self.pk, len) - def __call__(self, object o): + def pack(self, object o): cdef long long intval cdef double fval cdef char* rawval @@ -109,6 +111,9 @@ cdef class Packer: msgpack_pack_true(&self.pk) elif o is False: msgpack_pack_false(&self.pk) + elif isinstance(o, long): + intval = o + msgpack_pack_long_long(&self.pk, intval) elif isinstance(o, int): intval = o msgpack_pack_long_long(&self.pk, intval) @@ -120,24 +125,21 @@ cdef class Packer: msgpack_pack_raw(&self.pk, len(o)) msgpack_pack_raw_body(&self.pk, rawval, len(o)) elif isinstance(o, unicode): - # todo - pass + o = o.encode('utf-8') + rawval = o + msgpack_pack_raw(&self.pk, len(o)) + msgpack_pack_raw_body(&self.pk, rawval, len(o)) elif isinstance(o, dict): msgpack_pack_map(&self.pk, len(o)) for k,v in o.iteritems(): - self(k) - self(v) - elif isinstance(o, tuple): - msgpack_pack_array(&self.pk, len(o)) - for v in o: - self(v) - elif isinstance(o, list): + self.pack(k) + self.pack(v) + elif isinstance(o, tuple) or isinstance(o, list): msgpack_pack_array(&self.pk, len(o)) for v in o: - self(v) - elif hasattr(o, "__msgpack__"): - o.__msgpack__(self) + self.pack(v) else: + # TODO: Serialize with defalt() like simplejson. raise TypeError, "can't serialize %r" % (o,) cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): @@ -155,8 +157,25 @@ cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): packer.length += l return 0 +cdef extern from "msgpack/zone.h": + ctypedef struct msgpack_zone + +cdef extern from "unpack.c": + ctypedef struct template_context: + pass + int template_execute(template_context* ctx, const_char_ptr data, size_t len, size_t* off) + void template_init(template_context* ctx) + PyObject* template_data(template_context* ctx) + + cdef class Unpacker: def __init__(self): pass - def unpack(strm): - pass + + def unpack(self, bytes_): + cdef const_char_ptr p = bytes_ + cdef template_context ctx + cdef size_t off = 0 + template_init(&ctx) + template_execute(&ctx, p, len(bytes_), &off) + return template_data(&ctx) diff --git a/python/pack.h b/python/pack.h new file mode 100644 index 0000000..4a336d5 --- /dev/null +++ b/python/pack.h @@ -0,0 +1,130 @@ +/* + * MessagePack for Python packing routine + * + * Copyright (C) 2009 Naoki INADA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MSGPACK_PACK_H__ +#define MSGPACK_PACK_H__ + +#if _MSC_VER +typedef signed char uint8_t; +typedef unsigned char uint8_t; +typedef short int16_t; +typedef unsigned short uint16_t; +typedef int int32_t; +typedef unsigned int uint32_t; +typedef long long int64_t; +typedef unsigned long long uint64_t; +#elif +#include +#endif + +#include +#include +#include "msgpack/pack_define.h" +#include "msgpack/object.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef int (*msgpack_packer_write)(void* data, const char* buf, unsigned int len); + +typedef struct msgpack_packer { + void* data; + msgpack_packer_write callback; +} msgpack_packer; + +static void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback); + +static msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback); +static void msgpack_packer_free(msgpack_packer* pk); + +static int msgpack_pack_short(msgpack_packer* pk, short d); +static int msgpack_pack_int(msgpack_packer* pk, int d); +static int msgpack_pack_long(msgpack_packer* pk, long d); +static int msgpack_pack_long_long(msgpack_packer* pk, long long d); +static int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d); +static int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d); +static int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d); +static int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d); + +static int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d); +static int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d); +static int msgpack_pack_uint32(msgpack_packer* pk, uint32_t d); +static int msgpack_pack_uint64(msgpack_packer* pk, uint64_t d); +static int msgpack_pack_int8(msgpack_packer* pk, int8_t d); +static int msgpack_pack_int16(msgpack_packer* pk, int16_t d); +static int msgpack_pack_int32(msgpack_packer* pk, int32_t d); +static int msgpack_pack_int64(msgpack_packer* pk, int64_t d); + +static int msgpack_pack_float(msgpack_packer* pk, float d); +static int msgpack_pack_double(msgpack_packer* pk, double d); + +static int msgpack_pack_nil(msgpack_packer* pk); +static int msgpack_pack_true(msgpack_packer* pk); +static int msgpack_pack_false(msgpack_packer* pk); + +static int msgpack_pack_array(msgpack_packer* pk, unsigned int n); + +static int msgpack_pack_map(msgpack_packer* pk, unsigned int n); + +static int msgpack_pack_raw(msgpack_packer* pk, size_t l); +static int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l); + +int msgpack_pack_object(msgpack_packer* pk, msgpack_object d); + + + +#define msgpack_pack_inline_func(name) \ + static inline int msgpack_pack ## name + +#define msgpack_pack_inline_func_cint(name) \ + static inline int msgpack_pack ## name + +#define msgpack_pack_user msgpack_packer* + +#define msgpack_pack_append_buffer(user, buf, len) \ + return (*(user)->callback)((user)->data, (const char*)buf, len) + +#include "msgpack/pack_template.h" + +static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) +{ + pk->data = data; + pk->callback = callback; +} + +static inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback) +{ + msgpack_packer* pk = (msgpack_packer*)calloc(1, sizeof(msgpack_packer)); + if(!pk) { return NULL; } + msgpack_packer_init(pk, data, callback); + return pk; +} + +static inline void msgpack_packer_free(msgpack_packer* pk) +{ + free(pk); +} + + +#ifdef __cplusplus +} +#endif + +#endif /* msgpack/pack.h */ + diff --git a/python/unpack.h b/python/unpack.h new file mode 100644 index 0000000..d578360 --- /dev/null +++ b/python/unpack.h @@ -0,0 +1,397 @@ +/* + * MessagePack for Python unpacking routine + * + * Copyright (C) 2009 Naoki INADA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "msgpack/unpack.h" +#include "msgpack/unpack_define.h" +#include + +#include "Python.h" + + +typedef struct { + int reserved; +} unpack_user; + + +#define msgpack_unpack_struct(name) \ + struct template ## name + +#define msgpack_unpack_func(ret, name) \ + ret template ## name + +#define msgpack_unpack_callback(name) \ + template_callback ## name + +#define msgpack_unpack_object PyObject* + +#define msgpack_unpack_user unpack_user + + +struct template_context; +typedef struct template_context template_context; + +static void template_init(template_context* ctx); + +static msgpack_unpack_object template_data(template_context* ctx); + +static int template_execute(template_context* ctx, + const char* data, size_t len, size_t* off); + + +static inline msgpack_unpack_object template_callback_root(unpack_user* u) +{ PyObject *o = Py_None; Py_INCREF(o); return o; } + +static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong((long)d); return 0; } + +static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong((long)d); return 0; } + +static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_unpack_object* o) +{ + if (d >= 0x80000000UL) { + *o = PyLong_FromUnsignedLongLong((unsigned long long)d); + } else { + *o = PyInt_FromLong((long)d); + } + return 0; +} + +static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o) +{ *o = PyLong_FromUnsignedLongLong(d); return 0; } + +static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong(d); return 0; } + +static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong(d); return 0; } + +static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong(d); return 0; } + +static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o) +{ *o = PyLong_FromLongLong(d); return 0; } + +static inline int template_callback_float(unpack_user* u, float d, msgpack_unpack_object* o) +{ *o = PyFloat_FromDouble((double)d); return 0; } + +static inline int template_callback_double(unpack_user* u, double d, msgpack_unpack_object* o) +{ *o = PyFloat_FromDouble(d); return 0; } + +static inline int template_callback_nil(unpack_user* u, msgpack_unpack_object* o) +{ *o = Py_None; Py_INCREF(o); return 0; } + +static inline int template_callback_true(unpack_user* u, msgpack_unpack_object* o) +{ *o = Py_True; Py_INCREF(o); return 0; } + +static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* o) +{ *o = Py_False; Py_INCREF(o); return 0; } + +static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o) +{ + /* TODO: use PyList_New(n). */ + *o = PyList_New(0); + return 0; +} + +static inline int template_callback_array_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object o) +{ + PyList_Append(*c, o); + return 0; +} + +static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o) +{ + *o = PyDict_New(); + return 0; +} + +static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v) +{ + PyDict_SetItem(*c, k, v); + return 0; +} + +static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) +{ + *o = PyString_FromStringAndSize(p, l); + return 0; +} + +#include "msgpack/unpack_template.h" + + +#if 0 +#define CTX_CAST(m) ((template_context*)(m)) +#define CTX_REFERENCED(mpac) CTX_CAST((mpac)->ctx)->user.referenced + + +static const size_t COUNTER_SIZE = sizeof(unsigned int); + +static inline void init_count(void* buffer) +{ + *(volatile unsigned int*)buffer = 1; +} + +static inline void decl_count(void* buffer) +{ + //if(--*(unsigned int*)buffer == 0) { + if(__sync_sub_and_fetch((unsigned int*)buffer, 1) == 0) { + free(buffer); + } +} + +static inline void incr_count(void* buffer) +{ + //++*(unsigned int*)buffer; + __sync_add_and_fetch((unsigned int*)buffer, 1); +} + +static inline unsigned int get_count(void* buffer) +{ + return *(volatile unsigned int*)buffer; +} + + + +bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size) +{ + if(initial_buffer_size < COUNTER_SIZE) { + initial_buffer_size = COUNTER_SIZE; + } + + char* buffer = (char*)malloc(initial_buffer_size); + if(buffer == NULL) { + return false; + } + + void* ctx = malloc(sizeof(template_context)); + if(ctx == NULL) { + free(buffer); + return false; + } + + msgpack_zone* z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); + if(z == NULL) { + free(ctx); + free(buffer); + return false; + } + + mpac->buffer = buffer; + mpac->used = COUNTER_SIZE; + mpac->free = initial_buffer_size - mpac->used; + mpac->off = COUNTER_SIZE; + mpac->parsed = 0; + mpac->initial_buffer_size = initial_buffer_size; + mpac->z = z; + mpac->ctx = ctx; + + init_count(mpac->buffer); + + template_init(CTX_CAST(mpac->ctx)); + CTX_CAST(mpac->ctx)->user.z = mpac->z; + CTX_CAST(mpac->ctx)->user.referenced = false; + + return true; +} + +void msgpack_unpacker_destroy(msgpack_unpacker* mpac) +{ + msgpack_zone_free(mpac->z); + free(mpac->ctx); + decl_count(mpac->buffer); +} + + +msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size) +{ + msgpack_unpacker* mpac = (msgpack_unpacker*)malloc(sizeof(msgpack_unpacker)); + if(mpac == NULL) { + return NULL; + } + + if(!msgpack_unpacker_init(mpac, initial_buffer_size)) { + free(mpac); + return NULL; + } + + return mpac; +} + +void msgpack_unpacker_free(msgpack_unpacker* mpac) +{ + msgpack_unpacker_destroy(mpac); + free(mpac); +} + +bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size) +{ + if(mpac->used == mpac->off && get_count(mpac->buffer) == 1 + && !CTX_REFERENCED(mpac)) { + // rewind buffer + mpac->free += mpac->used - COUNTER_SIZE; + mpac->used = COUNTER_SIZE; + mpac->off = COUNTER_SIZE; + + if(mpac->free >= size) { + return true; + } + } + + if(mpac->off == COUNTER_SIZE) { + size_t next_size = (mpac->used + mpac->free) * 2; // include COUNTER_SIZE + while(next_size < size + mpac->used) { + next_size *= 2; + } + + char* tmp = (char*)realloc(mpac->buffer, next_size); + if(tmp == NULL) { + return false; + } + + mpac->buffer = tmp; + mpac->free = next_size - mpac->used; + + } else { + size_t next_size = mpac->initial_buffer_size; // include COUNTER_SIZE + size_t not_parsed = mpac->used - mpac->off; + while(next_size < size + not_parsed + COUNTER_SIZE) { + next_size *= 2; + } + + char* tmp = (char*)malloc(next_size); + if(tmp == NULL) { + return false; + } + + init_count(tmp); + + memcpy(tmp+COUNTER_SIZE, mpac->buffer+mpac->off, not_parsed); + + if(CTX_REFERENCED(mpac)) { + if(!msgpack_zone_push_finalizer(mpac->z, decl_count, mpac->buffer)) { + free(tmp); + return false; + } + CTX_REFERENCED(mpac) = false; + } else { + decl_count(mpac->buffer); + } + + mpac->buffer = tmp; + mpac->used = not_parsed + COUNTER_SIZE; + mpac->free = next_size - mpac->used; + mpac->off = COUNTER_SIZE; + } + + return true; +} + +int msgpack_unpacker_execute(msgpack_unpacker* mpac) +{ + size_t off = mpac->off; + int ret = template_execute(CTX_CAST(mpac->ctx), + mpac->buffer, mpac->used, &mpac->off); + if(mpac->off > off) { + mpac->parsed += mpac->off - off; + } + return ret; +} + +msgpack_unpack_object msgpack_unpacker_data(msgpack_unpacker* mpac) +{ + return template_data(CTX_CAST(mpac->ctx)); +} + +msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac) +{ + if(!msgpack_unpacker_flush_zone(mpac)) { + return false; + } + + msgpack_zone* r = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); + if(r == NULL) { + return NULL; + } + + msgpack_zone* old = mpac->z; + mpac->z = r; + + return old; +} + +void msgpack_unpacker_reset_zone(msgpack_unpacker* mpac) +{ + msgpack_zone_clear(mpac->z); +} + +bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac) +{ + if(CTX_REFERENCED(mpac)) { + if(!msgpack_zone_push_finalizer(mpac->z, decl_count, mpac->buffer)) { + return false; + } + CTX_REFERENCED(mpac) = false; + + incr_count(mpac->buffer); + } + + return true; +} + +void msgpack_unpacker_reset(msgpack_unpacker* mpac) +{ + template_init(CTX_CAST(mpac->ctx)); + // don't reset referenced flag + mpac->parsed = 0; +} + + +msgpack_unpack_return +msgpack_unpack(const char* data, size_t len, size_t* off, + msgpack_zone* z, msgpack_unpack_object* result) +{ + template_context ctx; + template_init(&ctx); + + ctx.user.z = z; + ctx.user.referenced = false; + + size_t noff = 0; + if(off != NULL) { noff = *off; } + + int ret = template_execute(&ctx, data, len, &noff); + if(ret < 0) { + return MSGPACK_UNPACK_PARSE_ERROR; + } + + if(off != NULL) { *off = noff; } + + if(ret == 0) { + return MSGPACK_UNPACK_CONTINUE; + } + + *result = template_data(&ctx); + + if(noff < len) { + return MSGPACK_UNPACK_EXTRA_BYTES; + } + + return MSGPACK_UNPACK_SUCCESS; +} +#endif -- cgit v1.2.1 From d8a3bc920caa06f21adcfc288c4c597bb9d33157 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 8 Jun 2009 01:30:43 +0900 Subject: refactoring --- python/msgpack.pyx | 58 +++++++----- python/pack.h | 67 ++++++------- python/unpack.h | 273 +---------------------------------------------------- 3 files changed, 68 insertions(+), 330 deletions(-) (limited to 'python') diff --git a/python/msgpack.pyx b/python/msgpack.pyx index ceae9b6..c454c5d 100644 --- a/python/msgpack.pyx +++ b/python/msgpack.pyx @@ -1,5 +1,6 @@ # coding: utf-8 +from cStringIO import StringIO cdef extern from "Python.h": ctypedef char* const_char_ptr "const char*" @@ -32,13 +33,15 @@ cdef extern from "pack.h": void msgpack_pack_raw(msgpack_packer* pk, size_t l) void msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) -cdef extern from "unpack.h": - ctypedef struct msgpack_unpacker - cdef int BUFF_SIZE=2*1024 cdef class Packer: + """Packer that pack data into strm. + + strm must have `write(bytes)` method. + size specifies local buffer size. + """ cdef char* buff cdef unsigned int length cdef unsigned int allocated @@ -46,11 +49,6 @@ cdef class Packer: cdef object strm def __init__(self, strm, int size=0): - """Make packer that pack data into strm. - - strm must have `write(bytes)` method. - size specifies local buffer size. - """ if size <= 0: size = BUFF_SIZE @@ -157,25 +155,41 @@ cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): packer.length += l return 0 -cdef extern from "msgpack/zone.h": - ctypedef struct msgpack_zone +def pack(object o, object stream): + packer = Packer(stream) + packer.pack(o) + packer.flush() + +def packs(object o): + buf = StringIO() + packer = Packer(buf) + packer.pack(o) + packer.flush() + return buf.getvalue() -cdef extern from "unpack.c": +cdef extern from "unpack.h": ctypedef struct template_context: pass - int template_execute(template_context* ctx, const_char_ptr data, size_t len, size_t* off) + int template_execute(template_context* ctx, const_char_ptr data, + size_t len, size_t* off) void template_init(template_context* ctx) PyObject* template_data(template_context* ctx) -cdef class Unpacker: - def __init__(self): - pass +def unpacks(object packed_bytes): + """Unpack packed_bytes to object. Returns unpacked object.""" + cdef const_char_ptr p = packed_bytes + cdef template_context ctx + cdef size_t off = 0 + template_init(&ctx) + template_execute(&ctx, p, len(packed_bytes), &off) + return template_data(&ctx) - def unpack(self, bytes_): - cdef const_char_ptr p = bytes_ - cdef template_context ctx - cdef size_t off = 0 - template_init(&ctx) - template_execute(&ctx, p, len(bytes_), &off) - return template_data(&ctx) +def unpack(object stream): + """unpack from stream.""" + packed = stream.read() + return unpacks(packed) + +cdef class Unpacker: + """Do nothing. This function is for symmetric to Packer""" + unpack = staticmethod(unpacks) diff --git a/python/pack.h b/python/pack.h index 4a336d5..f3935fb 100644 --- a/python/pack.h +++ b/python/pack.h @@ -15,9 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MSGPACK_PACK_H__ -#define MSGPACK_PACK_H__ - #if _MSC_VER typedef signed char uint8_t; typedef unsigned char uint8_t; @@ -27,14 +24,13 @@ typedef int int32_t; typedef unsigned int uint32_t; typedef long long int64_t; typedef unsigned long long uint64_t; -#elif +#else #include #endif #include #include #include "msgpack/pack_define.h" -#include "msgpack/object.h" #ifdef __cplusplus extern "C" { @@ -48,44 +44,42 @@ typedef struct msgpack_packer { msgpack_packer_write callback; } msgpack_packer; -static void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback); - -static msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback); -static void msgpack_packer_free(msgpack_packer* pk); +static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback); -static int msgpack_pack_short(msgpack_packer* pk, short d); -static int msgpack_pack_int(msgpack_packer* pk, int d); -static int msgpack_pack_long(msgpack_packer* pk, long d); -static int msgpack_pack_long_long(msgpack_packer* pk, long long d); -static int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d); -static int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d); -static int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d); -static int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d); +static inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback); +static inline void msgpack_packer_free(msgpack_packer* pk); -static int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d); -static int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d); -static int msgpack_pack_uint32(msgpack_packer* pk, uint32_t d); -static int msgpack_pack_uint64(msgpack_packer* pk, uint64_t d); -static int msgpack_pack_int8(msgpack_packer* pk, int8_t d); -static int msgpack_pack_int16(msgpack_packer* pk, int16_t d); -static int msgpack_pack_int32(msgpack_packer* pk, int32_t d); -static int msgpack_pack_int64(msgpack_packer* pk, int64_t d); +static inline int msgpack_pack_short(msgpack_packer* pk, short d); +static inline int msgpack_pack_int(msgpack_packer* pk, int d); +static inline int msgpack_pack_long(msgpack_packer* pk, long d); +static inline int msgpack_pack_long_long(msgpack_packer* pk, long long d); +static inline int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d); +static inline int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d); +static inline int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d); +static inline int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d); -static int msgpack_pack_float(msgpack_packer* pk, float d); -static int msgpack_pack_double(msgpack_packer* pk, double d); +static inline int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d); +static inline int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d); +static inline int msgpack_pack_uint32(msgpack_packer* pk, uint32_t d); +static inline int msgpack_pack_uint64(msgpack_packer* pk, uint64_t d); +static inline int msgpack_pack_int8(msgpack_packer* pk, int8_t d); +static inline int msgpack_pack_int16(msgpack_packer* pk, int16_t d); +static inline int msgpack_pack_int32(msgpack_packer* pk, int32_t d); +static inline int msgpack_pack_int64(msgpack_packer* pk, int64_t d); -static int msgpack_pack_nil(msgpack_packer* pk); -static int msgpack_pack_true(msgpack_packer* pk); -static int msgpack_pack_false(msgpack_packer* pk); +static inline int msgpack_pack_float(msgpack_packer* pk, float d); +static inline int msgpack_pack_double(msgpack_packer* pk, double d); -static int msgpack_pack_array(msgpack_packer* pk, unsigned int n); +static inline int msgpack_pack_nil(msgpack_packer* pk); +static inline int msgpack_pack_true(msgpack_packer* pk); +static inline int msgpack_pack_false(msgpack_packer* pk); -static int msgpack_pack_map(msgpack_packer* pk, unsigned int n); +static inline int msgpack_pack_array(msgpack_packer* pk, unsigned int n); -static int msgpack_pack_raw(msgpack_packer* pk, size_t l); -static int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l); +static inline int msgpack_pack_map(msgpack_packer* pk, unsigned int n); -int msgpack_pack_object(msgpack_packer* pk, msgpack_object d); +static inline int msgpack_pack_raw(msgpack_packer* pk, size_t l); +static inline int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l); @@ -125,6 +119,3 @@ static inline void msgpack_packer_free(msgpack_packer* pk) #ifdef __cplusplus } #endif - -#endif /* msgpack/pack.h */ - diff --git a/python/unpack.h b/python/unpack.h index d578360..eb72001 100644 --- a/python/unpack.h +++ b/python/unpack.h @@ -15,12 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "msgpack/unpack.h" #include "msgpack/unpack_define.h" -#include - -#include "Python.h" - typedef struct { int reserved; @@ -44,11 +39,11 @@ typedef struct { struct template_context; typedef struct template_context template_context; -static void template_init(template_context* ctx); +static inline void template_init(template_context* ctx); -static msgpack_unpack_object template_data(template_context* ctx); +static inline msgpack_unpack_object template_data(template_context* ctx); -static int template_execute(template_context* ctx, +static inline int template_execute(template_context* ctx, const char* data, size_t len, size_t* off); @@ -133,265 +128,3 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha } #include "msgpack/unpack_template.h" - - -#if 0 -#define CTX_CAST(m) ((template_context*)(m)) -#define CTX_REFERENCED(mpac) CTX_CAST((mpac)->ctx)->user.referenced - - -static const size_t COUNTER_SIZE = sizeof(unsigned int); - -static inline void init_count(void* buffer) -{ - *(volatile unsigned int*)buffer = 1; -} - -static inline void decl_count(void* buffer) -{ - //if(--*(unsigned int*)buffer == 0) { - if(__sync_sub_and_fetch((unsigned int*)buffer, 1) == 0) { - free(buffer); - } -} - -static inline void incr_count(void* buffer) -{ - //++*(unsigned int*)buffer; - __sync_add_and_fetch((unsigned int*)buffer, 1); -} - -static inline unsigned int get_count(void* buffer) -{ - return *(volatile unsigned int*)buffer; -} - - - -bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size) -{ - if(initial_buffer_size < COUNTER_SIZE) { - initial_buffer_size = COUNTER_SIZE; - } - - char* buffer = (char*)malloc(initial_buffer_size); - if(buffer == NULL) { - return false; - } - - void* ctx = malloc(sizeof(template_context)); - if(ctx == NULL) { - free(buffer); - return false; - } - - msgpack_zone* z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); - if(z == NULL) { - free(ctx); - free(buffer); - return false; - } - - mpac->buffer = buffer; - mpac->used = COUNTER_SIZE; - mpac->free = initial_buffer_size - mpac->used; - mpac->off = COUNTER_SIZE; - mpac->parsed = 0; - mpac->initial_buffer_size = initial_buffer_size; - mpac->z = z; - mpac->ctx = ctx; - - init_count(mpac->buffer); - - template_init(CTX_CAST(mpac->ctx)); - CTX_CAST(mpac->ctx)->user.z = mpac->z; - CTX_CAST(mpac->ctx)->user.referenced = false; - - return true; -} - -void msgpack_unpacker_destroy(msgpack_unpacker* mpac) -{ - msgpack_zone_free(mpac->z); - free(mpac->ctx); - decl_count(mpac->buffer); -} - - -msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size) -{ - msgpack_unpacker* mpac = (msgpack_unpacker*)malloc(sizeof(msgpack_unpacker)); - if(mpac == NULL) { - return NULL; - } - - if(!msgpack_unpacker_init(mpac, initial_buffer_size)) { - free(mpac); - return NULL; - } - - return mpac; -} - -void msgpack_unpacker_free(msgpack_unpacker* mpac) -{ - msgpack_unpacker_destroy(mpac); - free(mpac); -} - -bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size) -{ - if(mpac->used == mpac->off && get_count(mpac->buffer) == 1 - && !CTX_REFERENCED(mpac)) { - // rewind buffer - mpac->free += mpac->used - COUNTER_SIZE; - mpac->used = COUNTER_SIZE; - mpac->off = COUNTER_SIZE; - - if(mpac->free >= size) { - return true; - } - } - - if(mpac->off == COUNTER_SIZE) { - size_t next_size = (mpac->used + mpac->free) * 2; // include COUNTER_SIZE - while(next_size < size + mpac->used) { - next_size *= 2; - } - - char* tmp = (char*)realloc(mpac->buffer, next_size); - if(tmp == NULL) { - return false; - } - - mpac->buffer = tmp; - mpac->free = next_size - mpac->used; - - } else { - size_t next_size = mpac->initial_buffer_size; // include COUNTER_SIZE - size_t not_parsed = mpac->used - mpac->off; - while(next_size < size + not_parsed + COUNTER_SIZE) { - next_size *= 2; - } - - char* tmp = (char*)malloc(next_size); - if(tmp == NULL) { - return false; - } - - init_count(tmp); - - memcpy(tmp+COUNTER_SIZE, mpac->buffer+mpac->off, not_parsed); - - if(CTX_REFERENCED(mpac)) { - if(!msgpack_zone_push_finalizer(mpac->z, decl_count, mpac->buffer)) { - free(tmp); - return false; - } - CTX_REFERENCED(mpac) = false; - } else { - decl_count(mpac->buffer); - } - - mpac->buffer = tmp; - mpac->used = not_parsed + COUNTER_SIZE; - mpac->free = next_size - mpac->used; - mpac->off = COUNTER_SIZE; - } - - return true; -} - -int msgpack_unpacker_execute(msgpack_unpacker* mpac) -{ - size_t off = mpac->off; - int ret = template_execute(CTX_CAST(mpac->ctx), - mpac->buffer, mpac->used, &mpac->off); - if(mpac->off > off) { - mpac->parsed += mpac->off - off; - } - return ret; -} - -msgpack_unpack_object msgpack_unpacker_data(msgpack_unpacker* mpac) -{ - return template_data(CTX_CAST(mpac->ctx)); -} - -msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac) -{ - if(!msgpack_unpacker_flush_zone(mpac)) { - return false; - } - - msgpack_zone* r = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE); - if(r == NULL) { - return NULL; - } - - msgpack_zone* old = mpac->z; - mpac->z = r; - - return old; -} - -void msgpack_unpacker_reset_zone(msgpack_unpacker* mpac) -{ - msgpack_zone_clear(mpac->z); -} - -bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac) -{ - if(CTX_REFERENCED(mpac)) { - if(!msgpack_zone_push_finalizer(mpac->z, decl_count, mpac->buffer)) { - return false; - } - CTX_REFERENCED(mpac) = false; - - incr_count(mpac->buffer); - } - - return true; -} - -void msgpack_unpacker_reset(msgpack_unpacker* mpac) -{ - template_init(CTX_CAST(mpac->ctx)); - // don't reset referenced flag - mpac->parsed = 0; -} - - -msgpack_unpack_return -msgpack_unpack(const char* data, size_t len, size_t* off, - msgpack_zone* z, msgpack_unpack_object* result) -{ - template_context ctx; - template_init(&ctx); - - ctx.user.z = z; - ctx.user.referenced = false; - - size_t noff = 0; - if(off != NULL) { noff = *off; } - - int ret = template_execute(&ctx, data, len, &noff); - if(ret < 0) { - return MSGPACK_UNPACK_PARSE_ERROR; - } - - if(off != NULL) { *off = noff; } - - if(ret == 0) { - return MSGPACK_UNPACK_CONTINUE; - } - - *result = template_data(&ctx); - - if(noff < len) { - return MSGPACK_UNPACK_EXTRA_BYTES; - } - - return MSGPACK_UNPACK_SUCCESS; -} -#endif -- cgit v1.2.1 From c930f5367b41ef141e80a76506fd91b49fe7d426 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 8 Jun 2009 01:43:50 +0900 Subject: add cythoned source and setup script. --- python/msgpack | 1 + python/msgpack.c | 3231 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ python/setup.py | 29 + 3 files changed, 3261 insertions(+) create mode 120000 python/msgpack create mode 100644 python/msgpack.c create mode 100644 python/setup.py (limited to 'python') diff --git a/python/msgpack b/python/msgpack new file mode 120000 index 0000000..430db49 --- /dev/null +++ b/python/msgpack @@ -0,0 +1 @@ +../msgpack \ No newline at end of file diff --git a/python/msgpack.c b/python/msgpack.c new file mode 100644 index 0000000..50ec6fc --- /dev/null +++ b/python/msgpack.c @@ -0,0 +1,3231 @@ +/* Generated by Cython 0.11.2 on Mon Jun 8 01:28:30 2009 */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include "structmember.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#if PY_VERSION_HEX < 0x02040000 + #define METH_COEXIST 0 + #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) +#endif +#if PY_VERSION_HEX < 0x02050000 + typedef int Py_ssize_t; + #define PY_SSIZE_T_MAX INT_MAX + #define PY_SSIZE_T_MIN INT_MIN + #define PY_FORMAT_SIZE_T "" + #define PyInt_FromSsize_t(z) PyInt_FromLong(z) + #define PyInt_AsSsize_t(o) PyInt_AsLong(o) + #define PyNumber_Index(o) PyNumber_Int(o) + #define PyIndex_Check(o) PyNumber_Check(o) +#endif +#if PY_VERSION_HEX < 0x02060000 + #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) + #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) + #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) + #define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, + #define PyType_Modified(t) + + typedef struct { + void *buf; + PyObject *obj; + Py_ssize_t len; + Py_ssize_t itemsize; + int readonly; + int ndim; + char *format; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; + void *internal; + } Py_buffer; + + #define PyBUF_SIMPLE 0 + #define PyBUF_WRITABLE 0x0001 + #define PyBUF_FORMAT 0x0004 + #define PyBUF_ND 0x0008 + #define PyBUF_STRIDES (0x0010 | PyBUF_ND) + #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) + #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) + #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) + #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) + +#endif +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" +#endif +#if PY_MAJOR_VERSION >= 3 + #define Py_TPFLAGS_CHECKTYPES 0 + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyString_Type PyBytes_Type + #define PyString_CheckExact PyBytes_CheckExact + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define PyBytes_Type PyString_Type +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func) +#endif +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#else + #define _USE_MATH_DEFINES +#endif +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) +#else + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) +#endif +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_NAMESTR(n) ((char *)(n)) + #define __Pyx_DOCSTR(n) ((char *)(n)) +#else + #define __Pyx_NAMESTR(n) (n) + #define __Pyx_DOCSTR(n) (n) +#endif +#ifdef __cplusplus +#define __PYX_EXTERN_C extern "C" +#else +#define __PYX_EXTERN_C extern +#endif +#include +#define __PYX_HAVE_API__msgpack +#include "stdlib.h" +#include "string.h" +#include "pack.h" +#include "unpack.h" +#define __PYX_USE_C99_COMPLEX defined(_Complex_I) + + +#ifdef __GNUC__ +#define INLINE __inline__ +#elif _WIN32 +#define INLINE __inline +#else +#define INLINE +#endif + +typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char is_identifier;} __Pyx_StringTabEntry; /*proto*/ + + + +static int __pyx_skip_dispatch = 0; + + +/* Type Conversion Predeclarations */ + +#if PY_MAJOR_VERSION < 3 +#define __Pyx_PyBytes_FromString PyString_FromString +#define __Pyx_PyBytes_FromStringAndSize PyString_FromStringAndSize +#define __Pyx_PyBytes_AsString PyString_AsString +#else +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +#define __Pyx_PyBytes_AsString PyBytes_AsString +#endif + +#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) +static INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); + +#if !defined(T_PYSSIZET) +#if PY_VERSION_HEX < 0x02050000 +#define T_PYSSIZET T_INT +#elif !defined(T_LONGLONG) +#define T_PYSSIZET \ + ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \ + ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1)) +#else +#define T_PYSSIZET \ + ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \ + ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : \ + ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1))) +#endif +#endif + +#if !defined(T_SIZET) +#if !defined(T_ULONGLONG) +#define T_SIZET \ + ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \ + ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1)) +#else +#define T_SIZET \ + ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \ + ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : \ + ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1))) +#endif +#endif + +static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); + +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) + + +#ifdef __GNUC__ +/* Test for GCC > 2.95 */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) +#else /* __GNUC__ > 2 ... */ +#define likely(x) (x) +#define unlikely(x) (x) +#endif /* __GNUC__ > 2 ... */ +#else /* __GNUC__ */ +#define likely(x) (x) +#define unlikely(x) (x) +#endif /* __GNUC__ */ + +static PyObject *__pyx_m; +static PyObject *__pyx_b; +static PyObject *__pyx_empty_tuple; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; +static const char **__pyx_f; + + +#ifdef CYTHON_REFNANNY +typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*NewContext)(const char*, int, const char*); + void (*FinishContext)(void**); +} __Pyx_RefnannyAPIStruct; +static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL; +#define __Pyx_ImportRefcountAPI(name) (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI") +#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r) +#define __Pyx_SetupRefcountContext(name) void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__) +#define __Pyx_FinishRefcountContext() __Pyx_Refnanny->FinishContext(&__pyx_refchk) +#else +#define __Pyx_INCREF(r) Py_INCREF(r) +#define __Pyx_DECREF(r) Py_DECREF(r) +#define __Pyx_GOTREF(r) +#define __Pyx_GIVEREF(r) +#define __Pyx_XDECREF(r) Py_XDECREF(r) +#define __Pyx_SetupRefcountContext(name) +#define __Pyx_FinishRefcountContext() +#endif /* CYTHON_REFNANNY */ +#define __Pyx_XGIVEREF(r) if((r) == NULL) ; else __Pyx_GIVEREF(r) +#define __Pyx_XGOTREF(r) if((r) == NULL) ; else __Pyx_GOTREF(r) + +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, PyObject* kw_name); /*proto*/ + +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ + +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +static INLINE void __Pyx_RaiseTooManyValuesError(void); + +static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/ +static int __Pyx_EndUnpack(PyObject *); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ + +static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/ + +static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); + +static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); + +static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); + +static INLINE char __Pyx_PyInt_AsChar(PyObject *); + +static INLINE short __Pyx_PyInt_AsShort(PyObject *); + +static INLINE int __Pyx_PyInt_AsInt(PyObject *); + +static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); + +static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); + +static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); + +static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); + +static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); + +static INLINE long __Pyx_PyInt_AsLong(PyObject *); + +static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); + +static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); + +static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); + +static void __Pyx_WriteUnraisable(const char *name); /*proto*/ + +static void __Pyx_AddTraceback(const char *funcname); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ + +/* Type declarations */ + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":39 + * cdef int BUFF_SIZE=2*1024 + * + * cdef class Packer: # <<<<<<<<<<<<<< + * """Packer that pack data into strm. + * + */ + +struct __pyx_obj_7msgpack_Packer { + PyObject_HEAD + char *buff; + unsigned int length; + unsigned int allocated; + struct msgpack_packer pk; + PyObject *strm; +}; + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":193 + * return unpacks(packed) + * + * cdef class Unpacker: # <<<<<<<<<<<<<< + * """Do nothing. This function is for symmetric to Packer""" + * unpack = staticmethod(unpacks) + */ + +struct __pyx_obj_7msgpack_Unpacker { + PyObject_HEAD +}; +/* Module declarations from msgpack */ + +static PyTypeObject *__pyx_ptype_7msgpack_Packer = 0; +static PyTypeObject *__pyx_ptype_7msgpack_Unpacker = 0; +static int __pyx_v_7msgpack_BUFF_SIZE; +static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *, const char*, unsigned int); /*proto*/ +#define __Pyx_MODULE_NAME "msgpack" +int __pyx_module_is_main_msgpack = 0; + +/* Implementation of msgpack */ +static char __pyx_k___main__[] = "__main__"; +static PyObject *__pyx_kp___main__; +static char __pyx_k___init__[] = "__init__"; +static PyObject *__pyx_kp___init__; +static char __pyx_k_flush[] = "flush"; +static PyObject *__pyx_kp_flush; +static char __pyx_k_pack_list[] = "pack_list"; +static PyObject *__pyx_kp_pack_list; +static char __pyx_k_pack_dict[] = "pack_dict"; +static PyObject *__pyx_kp_pack_dict; +static char __pyx_k_pack[] = "pack"; +static PyObject *__pyx_kp_pack; +static char __pyx_k_unpack[] = "unpack"; +static PyObject *__pyx_kp_unpack; +static char __pyx_k_strm[] = "strm"; +static PyObject *__pyx_kp_strm; +static char __pyx_k_size[] = "size"; +static PyObject *__pyx_kp_size; +static char __pyx_k_len[] = "len"; +static PyObject *__pyx_kp_len; +static char __pyx_k_o[] = "o"; +static PyObject *__pyx_kp_o; +static char __pyx_k_stream[] = "stream"; +static PyObject *__pyx_kp_stream; +static char __pyx_k_packed_bytes[] = "packed_bytes"; +static PyObject *__pyx_kp_packed_bytes; +static char __pyx_k_cStringIO[] = "cStringIO"; +static PyObject *__pyx_kp_cStringIO; +static char __pyx_k_StringIO[] = "StringIO"; +static PyObject *__pyx_kp_StringIO; +static char __pyx_k_staticmethod[] = "staticmethod"; +static PyObject *__pyx_kp_staticmethod; +static char __pyx_k_unpacks[] = "unpacks"; +static PyObject *__pyx_kp_unpacks; +static char __pyx_k_write[] = "write"; +static PyObject *__pyx_kp_write; +static char __pyx_k_1[] = "flush"; +static PyObject *__pyx_kp_1; +static char __pyx_k_encode[] = "encode"; +static PyObject *__pyx_kp_encode; +static char __pyx_k_iteritems[] = "iteritems"; +static PyObject *__pyx_kp_iteritems; +static char __pyx_k_TypeError[] = "TypeError"; +static PyObject *__pyx_kp_TypeError; +static char __pyx_k_getvalue[] = "getvalue"; +static PyObject *__pyx_kp_getvalue; +static char __pyx_k_read[] = "read"; +static PyObject *__pyx_kp_read; +static PyObject *__pyx_builtin_staticmethod; +static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_kp_2; +static PyObject *__pyx_kp_3; +static char __pyx_k_2[] = "utf-8"; +static char __pyx_k_3[] = "can't serialize %r"; + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":51 + * cdef object strm + * + * def __init__(self, strm, int size=0): # <<<<<<<<<<<<<< + * if size <= 0: + * size = BUFF_SIZE + */ + +static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_strm = 0; + int __pyx_v_size; + int __pyx_r; + int __pyx_t_1; + static PyObject **__pyx_pyargnames[] = {&__pyx_kp_strm,&__pyx_kp_size,0}; + __Pyx_SetupRefcountContext("__init__"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[2] = {0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_strm); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 1) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_size); + if (unlikely(value)) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_strm = values[0]; + if (values[1]) { + __pyx_v_size = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_size = 0; + } + } else { + __pyx_v_size = 0; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: __pyx_v_size = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + case 1: __pyx_v_strm = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack.Packer.__init__"); + return -1; + __pyx_L4_argument_unpacking_done:; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":52 + * + * def __init__(self, strm, int size=0): + * if size <= 0: # <<<<<<<<<<<<<< + * size = BUFF_SIZE + * + */ + __pyx_t_1 = (__pyx_v_size <= 0); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":53 + * def __init__(self, strm, int size=0): + * if size <= 0: + * size = BUFF_SIZE # <<<<<<<<<<<<<< + * + * self.strm = strm + */ + __pyx_v_size = __pyx_v_7msgpack_BUFF_SIZE; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":55 + * size = BUFF_SIZE + * + * self.strm = strm # <<<<<<<<<<<<<< + * self.buff = malloc(size) + * self.allocated = size + */ + __Pyx_INCREF(__pyx_v_strm); + __Pyx_GIVEREF(__pyx_v_strm); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm = __pyx_v_strm; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":56 + * + * self.strm = strm + * self.buff = malloc(size) # <<<<<<<<<<<<<< + * self.allocated = size + * self.length = 0 + */ + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff = ((char *)malloc(__pyx_v_size)); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":57 + * self.strm = strm + * self.buff = malloc(size) + * self.allocated = size # <<<<<<<<<<<<<< + * self.length = 0 + * + */ + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->allocated = __pyx_v_size; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":58 + * self.buff = malloc(size) + * self.allocated = size + * self.length = 0 # <<<<<<<<<<<<<< + * + * msgpack_packer_init(&self.pk, self, _packer_write) + */ + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":60 + * self.length = 0 + * + * msgpack_packer_init(&self.pk, self, _packer_write) # <<<<<<<<<<<<<< + * + * + */ + msgpack_packer_init((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), ((void *)__pyx_v_self), ((int (*)(void *, const char*, unsigned int))__pyx_f_7msgpack__packer_write)); + + __pyx_r = 0; + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":63 + * + * + * def flush(self): # <<<<<<<<<<<<<< + * """Flash local buffer and output stream if it has 'flush()' method.""" + * if self.length > 0: + */ + +static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObject *unused); /*proto*/ +static char __pyx_doc_7msgpack_6Packer_flush[] = "Flash local buffer and output stream if it has 'flush()' method."; +static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObject *unused) { + PyObject *__pyx_r = NULL; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_SetupRefcountContext("flush"); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":65 + * def flush(self): + * """Flash local buffer and output stream if it has 'flush()' method.""" + * if self.length > 0: # <<<<<<<<<<<<<< + * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) + * self.length = 0 + */ + __pyx_t_1 = (((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length > 0); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":66 + * """Flash local buffer and output stream if it has 'flush()' method.""" + * if self.length > 0: + * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) # <<<<<<<<<<<<<< + * self.length = 0 + * if hasattr(self.strm, 'flush'): + */ + __pyx_t_2 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyString_FromStringAndSize(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff, ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":67 + * if self.length > 0: + * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) + * self.length = 0 # <<<<<<<<<<<<<< + * if hasattr(self.strm, 'flush'): + * self.strm.flush() + */ + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":68 + * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) + * self.length = 0 + * if hasattr(self.strm, 'flush'): # <<<<<<<<<<<<<< + * self.strm.flush() + * + */ + __pyx_t_1 = PyObject_HasAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":69 + * self.length = 0 + * if hasattr(self.strm, 'flush'): + * self.strm.flush() # <<<<<<<<<<<<<< + * + * def pack_list(self, len): + */ + __pyx_t_3 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L6; + } + __pyx_L6:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("msgpack.Packer.flush"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":71 + * self.strm.flush() + * + * def pack_list(self, len): # <<<<<<<<<<<<<< + * """Start packing sequential objects. + * + */ + +static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyObject *__pyx_v_len); /*proto*/ +static char __pyx_doc_7msgpack_6Packer_pack_list[] = "Start packing sequential objects.\n\n Example:\n\n packer.pack_list(2)\n packer.pack('foo')\n packer.pack('bar')\n\n This code is same as below code:\n\n packer.pack(['foo', 'bar'])\n "; +static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyObject *__pyx_v_len) { + PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + __Pyx_SetupRefcountContext("pack_list"); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":84 + * packer.pack(['foo', 'bar']) + * """ + * msgpack_pack_array(&self.pk, len) # <<<<<<<<<<<<<< + * + * def pack_dict(self, len): + */ + __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_array((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("msgpack.Packer.pack_list"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":86 + * msgpack_pack_array(&self.pk, len) + * + * def pack_dict(self, len): # <<<<<<<<<<<<<< + * """Start packing key-value objects. + * + */ + +static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_len); /*proto*/ +static char __pyx_doc_7msgpack_6Packer_pack_dict[] = "Start packing key-value objects.\n\n Example:\n\n packer.pack_dict(1)\n packer.pack('foo')\n packer.pack('bar')\n\n This code is same as below code:\n\n packer.pack({'foo', 'bar'})\n "; +static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_len) { + PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + __Pyx_SetupRefcountContext("pack_dict"); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":99 + * packer.pack({'foo', 'bar'}) + * """ + * msgpack_pack_map(&self.pk, len) # <<<<<<<<<<<<<< + * + * def pack(self, object o): + */ + __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_map((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("msgpack.Packer.pack_dict"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":101 + * msgpack_pack_map(&self.pk, len) + * + * def pack(self, object o): # <<<<<<<<<<<<<< + * cdef long long intval + * cdef double fval + */ + +static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_v_o); /*proto*/ +static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_v_o) { + PY_LONG_LONG __pyx_v_intval; + double __pyx_v_fval; + char *__pyx_v_rawval; + PyObject *__pyx_v_k; + PyObject *__pyx_v_v; + PyObject *__pyx_r = NULL; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PY_LONG_LONG __pyx_t_3; + char *__pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_t_9; + int __pyx_t_10; + __Pyx_SetupRefcountContext("pack"); + __Pyx_INCREF(__pyx_v_o); + __pyx_v_k = Py_None; __Pyx_INCREF(Py_None); + __pyx_v_v = Py_None; __Pyx_INCREF(Py_None); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":106 + * cdef char* rawval + * + * if o is None: # <<<<<<<<<<<<<< + * msgpack_pack_nil(&self.pk) + * elif o is True: + */ + __pyx_t_1 = (__pyx_v_o == Py_None); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":107 + * + * if o is None: + * msgpack_pack_nil(&self.pk) # <<<<<<<<<<<<<< + * elif o is True: + * msgpack_pack_true(&self.pk) + */ + msgpack_pack_nil((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk)); + goto __pyx_L5; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":108 + * if o is None: + * msgpack_pack_nil(&self.pk) + * elif o is True: # <<<<<<<<<<<<<< + * msgpack_pack_true(&self.pk) + * elif o is False: + */ + __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = (__pyx_v_o == __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":109 + * msgpack_pack_nil(&self.pk) + * elif o is True: + * msgpack_pack_true(&self.pk) # <<<<<<<<<<<<<< + * elif o is False: + * msgpack_pack_false(&self.pk) + */ + msgpack_pack_true((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk)); + goto __pyx_L5; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":110 + * elif o is True: + * msgpack_pack_true(&self.pk) + * elif o is False: # <<<<<<<<<<<<<< + * msgpack_pack_false(&self.pk) + * elif isinstance(o, long): + */ + __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = (__pyx_v_o == __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":111 + * msgpack_pack_true(&self.pk) + * elif o is False: + * msgpack_pack_false(&self.pk) # <<<<<<<<<<<<<< + * elif isinstance(o, long): + * intval = o + */ + msgpack_pack_false((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk)); + goto __pyx_L5; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":112 + * elif o is False: + * msgpack_pack_false(&self.pk) + * elif isinstance(o, long): # <<<<<<<<<<<<<< + * intval = o + * msgpack_pack_long_long(&self.pk, intval) + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyLong_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":113 + * msgpack_pack_false(&self.pk) + * elif isinstance(o, long): + * intval = o # <<<<<<<<<<<<<< + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, int): + */ + __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_intval = __pyx_t_3; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":114 + * elif isinstance(o, long): + * intval = o + * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< + * elif isinstance(o, int): + * intval = o + */ + msgpack_pack_long_long((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_intval); + goto __pyx_L5; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":115 + * intval = o + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, int): # <<<<<<<<<<<<<< + * intval = o + * msgpack_pack_long_long(&self.pk, intval) + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyInt_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":116 + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, int): + * intval = o # <<<<<<<<<<<<<< + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, float): + */ + __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_intval = __pyx_t_3; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":117 + * elif isinstance(o, int): + * intval = o + * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< + * elif isinstance(o, float): + * fval = 9 + */ + msgpack_pack_long_long((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_intval); + goto __pyx_L5; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":118 + * intval = o + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, float): # <<<<<<<<<<<<<< + * fval = 9 + * msgpack_pack_double(&self.pk, fval) + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyFloat_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":119 + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, float): + * fval = 9 # <<<<<<<<<<<<<< + * msgpack_pack_double(&self.pk, fval) + * elif isinstance(o, str): + */ + __pyx_v_fval = 9; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":120 + * elif isinstance(o, float): + * fval = 9 + * msgpack_pack_double(&self.pk, fval) # <<<<<<<<<<<<<< + * elif isinstance(o, str): + * rawval = o + */ + msgpack_pack_double((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_fval); + goto __pyx_L5; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":121 + * fval = 9 + * msgpack_pack_double(&self.pk, fval) + * elif isinstance(o, str): # <<<<<<<<<<<<<< + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyString_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":122 + * msgpack_pack_double(&self.pk, fval) + * elif isinstance(o, str): + * rawval = o # <<<<<<<<<<<<<< + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + */ + __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_rawval = __pyx_t_4; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":123 + * elif isinstance(o, str): + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, unicode): + */ + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_5); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":124 + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< + * elif isinstance(o, unicode): + * o = o.encode('utf-8') + */ + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw_body((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_rawval, __pyx_t_5); + goto __pyx_L5; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":125 + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, unicode): # <<<<<<<<<<<<<< + * o = o.encode('utf-8') + * rawval = o + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyUnicode_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":126 + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, unicode): + * o = o.encode('utf-8') # <<<<<<<<<<<<<< + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __Pyx_INCREF(__pyx_kp_2); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_kp_2); + __Pyx_GIVEREF(__pyx_kp_2); + __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_v_o); + __pyx_v_o = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":127 + * elif isinstance(o, unicode): + * o = o.encode('utf-8') + * rawval = o # <<<<<<<<<<<<<< + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + */ + __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_rawval = __pyx_t_4; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":128 + * o = o.encode('utf-8') + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, dict): + */ + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_5); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":129 + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< + * elif isinstance(o, dict): + * msgpack_pack_map(&self.pk, len(o)) + */ + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw_body((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_rawval, __pyx_t_5); + goto __pyx_L5; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":130 + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, dict): # <<<<<<<<<<<<<< + * msgpack_pack_map(&self.pk, len(o)) + * for k,v in o.iteritems(): + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyDict_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":131 + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, dict): + * msgpack_pack_map(&self.pk, len(o)) # <<<<<<<<<<<<<< + * for k,v in o.iteritems(): + * self.pack(k) + */ + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_map((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_5); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":132 + * elif isinstance(o, dict): + * msgpack_pack_map(&self.pk, len(o)) + * for k,v in o.iteritems(): # <<<<<<<<<<<<<< + * self.pack(k) + * self.pack(v) + */ + __pyx_t_7 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_iteritems); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) { + __pyx_t_5 = 0; __pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); + } else { + __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + for (;;) { + if (likely(PyList_CheckExact(__pyx_t_7))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; + } else if (likely(PyTuple_CheckExact(__pyx_t_7))) { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; + } else { + __pyx_t_6 = PyIter_Next(__pyx_t_7); + if (!__pyx_t_6) { + if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + if (PyTuple_CheckExact(__pyx_t_6) && likely(PyTuple_GET_SIZE(__pyx_t_6) == 2)) { + PyObject* tuple = __pyx_t_6; + __pyx_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_2); + __pyx_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_v_k); + __pyx_v_k = __pyx_2; + __pyx_2 = 0; + __Pyx_DECREF(__pyx_v_v); + __pyx_v_v = __pyx_3; + __pyx_3 = 0; + } else { + __pyx_1 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_2 = __Pyx_UnpackItem(__pyx_1, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + __pyx_3 = __Pyx_UnpackItem(__pyx_1, 1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_3); + if (__Pyx_EndUnpack(__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; + __Pyx_DECREF(__pyx_v_k); + __pyx_v_k = __pyx_2; + __pyx_2 = 0; + __Pyx_DECREF(__pyx_v_v); + __pyx_v_v = __pyx_3; + __pyx_3 = 0; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":133 + * msgpack_pack_map(&self.pk, len(o)) + * for k,v in o.iteritems(): + * self.pack(k) # <<<<<<<<<<<<<< + * self.pack(v) + * elif isinstance(o, tuple) or isinstance(o, list): + */ + __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_v_k); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k); + __Pyx_GIVEREF(__pyx_v_k); + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":134 + * for k,v in o.iteritems(): + * self.pack(k) + * self.pack(v) # <<<<<<<<<<<<<< + * elif isinstance(o, tuple) or isinstance(o, list): + * msgpack_pack_array(&self.pk, len(o)) + */ + __pyx_t_8 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_pack); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_v_v); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); + __Pyx_GIVEREF(__pyx_v_v); + __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L5; + } + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":135 + * self.pack(k) + * self.pack(v) + * elif isinstance(o, tuple) or isinstance(o, list): # <<<<<<<<<<<<<< + * msgpack_pack_array(&self.pk, len(o)) + * for v in o: + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyTuple_Type))); + if (!__pyx_t_1) { + __pyx_t_9 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyList_Type))); + __pyx_t_10 = __pyx_t_9; + } else { + __pyx_t_10 = __pyx_t_1; + } + if (__pyx_t_10) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":136 + * self.pack(v) + * elif isinstance(o, tuple) or isinstance(o, list): + * msgpack_pack_array(&self.pk, len(o)) # <<<<<<<<<<<<<< + * for v in o: + * self.pack(v) + */ + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_array((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_5); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":137 + * elif isinstance(o, tuple) or isinstance(o, list): + * msgpack_pack_array(&self.pk, len(o)) + * for v in o: # <<<<<<<<<<<<<< + * self.pack(v) + * else: + */ + if (PyList_CheckExact(__pyx_v_o) || PyTuple_CheckExact(__pyx_v_o)) { + __pyx_t_5 = 0; __pyx_t_7 = __pyx_v_o; __Pyx_INCREF(__pyx_t_7); + } else { + __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + } + for (;;) { + if (likely(PyList_CheckExact(__pyx_t_7))) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break; + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; + } else if (likely(PyTuple_CheckExact(__pyx_t_7))) { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break; + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; + } else { + __pyx_t_6 = PyIter_Next(__pyx_t_7); + if (!__pyx_t_6) { + if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_DECREF(__pyx_v_v); + __pyx_v_v = __pyx_t_6; + __pyx_t_6 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":138 + * msgpack_pack_array(&self.pk, len(o)) + * for v in o: + * self.pack(v) # <<<<<<<<<<<<<< + * else: + * # TODO: Serialize with defalt() like simplejson. + */ + __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_v_v); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); + __Pyx_GIVEREF(__pyx_v_v); + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":141 + * else: + * # TODO: Serialize with defalt() like simplejson. + * raise TypeError, "can't serialize %r" % (o,) # <<<<<<<<<<<<<< + * + * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): + */ + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_7)); + __Pyx_INCREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + __pyx_t_8 = PyNumber_Remainder(__pyx_kp_3, ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_Raise(__pyx_builtin_TypeError, __pyx_t_8, 0); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L5:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_2); + __Pyx_XDECREF(__pyx_3); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("msgpack.Packer.pack"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_k); + __Pyx_DECREF(__pyx_v_v); + __Pyx_DECREF(__pyx_v_o); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":143 + * raise TypeError, "can't serialize %r" % (o,) + * + * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): # <<<<<<<<<<<<<< + * if packer.length + l > packer.allocated: + * if packer.length > 0: + */ + +static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__pyx_v_packer, const char* __pyx_v_b, unsigned int __pyx_v_l) { + int __pyx_r; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_SetupRefcountContext("_packer_write"); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":144 + * + * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): + * if packer.length + l > packer.allocated: # <<<<<<<<<<<<<< + * if packer.length > 0: + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + */ + __pyx_t_1 = ((__pyx_v_packer->length + __pyx_v_l) > __pyx_v_packer->allocated); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":145 + * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): + * if packer.length + l > packer.allocated: + * if packer.length > 0: # <<<<<<<<<<<<<< + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + * if l > 64: + */ + __pyx_t_1 = (__pyx_v_packer->length > 0); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":146 + * if packer.length + l > packer.allocated: + * if packer.length > 0: + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) # <<<<<<<<<<<<<< + * if l > 64: + * packer.strm.write(PyString_FromStringAndSize(b, l)) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyString_FromStringAndSize(__pyx_v_packer->buff, __pyx_v_packer->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":147 + * if packer.length > 0: + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + * if l > 64: # <<<<<<<<<<<<<< + * packer.strm.write(PyString_FromStringAndSize(b, l)) + * packer.length = 0 + */ + __pyx_t_1 = (__pyx_v_l > 64); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":148 + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + * if l > 64: + * packer.strm.write(PyString_FromStringAndSize(b, l)) # <<<<<<<<<<<<<< + * packer.length = 0 + * else: + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyString_FromStringAndSize(__pyx_v_b, __pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":149 + * if l > 64: + * packer.strm.write(PyString_FromStringAndSize(b, l)) + * packer.length = 0 # <<<<<<<<<<<<<< + * else: + * memcpy(packer.buff, b, l) + */ + __pyx_v_packer->length = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":151 + * packer.length = 0 + * else: + * memcpy(packer.buff, b, l) # <<<<<<<<<<<<<< + * packer.length = l + * else: + */ + memcpy(__pyx_v_packer->buff, __pyx_v_b, __pyx_v_l); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":152 + * else: + * memcpy(packer.buff, b, l) + * packer.length = l # <<<<<<<<<<<<<< + * else: + * memcpy(packer.buff + packer.length, b, l) + */ + __pyx_v_packer->length = __pyx_v_l; + } + __pyx_L5:; + goto __pyx_L3; + } + /*else*/ { + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":154 + * packer.length = l + * else: + * memcpy(packer.buff + packer.length, b, l) # <<<<<<<<<<<<<< + * packer.length += l + * return 0 + */ + memcpy((__pyx_v_packer->buff + __pyx_v_packer->length), __pyx_v_b, __pyx_v_l); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":155 + * else: + * memcpy(packer.buff + packer.length, b, l) + * packer.length += l # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_v_packer->length += __pyx_v_l; + } + __pyx_L3:; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":156 + * memcpy(packer.buff + packer.length, b, l) + * packer.length += l + * return 0 # <<<<<<<<<<<<<< + * + * def pack(object o, object stream): + */ + __pyx_r = 0; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_WriteUnraisable("msgpack._packer_write"); + __pyx_r = 0; + __pyx_L0:; + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":158 + * return 0 + * + * def pack(object o, object stream): # <<<<<<<<<<<<<< + * packer = Packer(stream) + * packer.pack(o) + */ + +static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_o = 0; + PyObject *__pyx_v_stream = 0; + PyObject *__pyx_v_packer; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + static PyObject **__pyx_pyargnames[] = {&__pyx_kp_o,&__pyx_kp_stream,0}; + __Pyx_SetupRefcountContext("pack"); + __pyx_self = __pyx_self; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[2] = {0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_o); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_stream); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_o = values[0]; + __pyx_v_stream = values[1]; + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + __pyx_v_o = PyTuple_GET_ITEM(__pyx_args, 0); + __pyx_v_stream = PyTuple_GET_ITEM(__pyx_args, 1); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack.pack"); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":159 + * + * def pack(object o, object stream): + * packer = Packer(stream) # <<<<<<<<<<<<<< + * packer.pack(o) + * packer.flush() + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_v_stream); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stream); + __Pyx_GIVEREF(__pyx_v_stream); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_packer); + __pyx_v_packer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":160 + * def pack(object o, object stream): + * packer = Packer(stream) + * packer.pack(o) # <<<<<<<<<<<<<< + * packer.flush() + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":161 + * packer = Packer(stream) + * packer.pack(o) + * packer.flush() # <<<<<<<<<<<<<< + * + * def packs(object o): + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack.pack"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_packer); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":163 + * packer.flush() + * + * def packs(object o): # <<<<<<<<<<<<<< + * buf = StringIO() + * packer = Packer(buf) + */ + +static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v_o); /*proto*/ +static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v_o) { + PyObject *__pyx_v_buf; + PyObject *__pyx_v_packer; + PyObject *__pyx_r = NULL; + PyObject *__pyx_1 = 0; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_SetupRefcountContext("packs"); + __pyx_self = __pyx_self; + __pyx_v_buf = Py_None; __Pyx_INCREF(Py_None); + __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":164 + * + * def packs(object o): + * buf = StringIO() # <<<<<<<<<<<<<< + * packer = Packer(buf) + * packer.pack(o) + */ + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_StringIO); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; + __Pyx_DECREF(__pyx_v_buf); + __pyx_v_buf = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":165 + * def packs(object o): + * buf = StringIO() + * packer = Packer(buf) # <<<<<<<<<<<<<< + * packer.pack(o) + * packer.flush() + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_v_buf); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_buf); + __Pyx_GIVEREF(__pyx_v_buf); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_packer); + __pyx_v_packer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":166 + * buf = StringIO() + * packer = Packer(buf) + * packer.pack(o) # <<<<<<<<<<<<<< + * packer.flush() + * return buf.getvalue() + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":167 + * packer = Packer(buf) + * packer.pack(o) + * packer.flush() # <<<<<<<<<<<<<< + * return buf.getvalue() + * + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":168 + * packer.pack(o) + * packer.flush() + * return buf.getvalue() # <<<<<<<<<<<<<< + * + * cdef extern from "unpack.h": + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_getvalue); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack.packs"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_buf); + __Pyx_DECREF(__pyx_v_packer); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":179 + * + * + * def unpacks(object packed_bytes): # <<<<<<<<<<<<<< + * """Unpack packed_bytes to object. Returns unpacked object.""" + * cdef const_char_ptr p = packed_bytes + */ + +static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx_v_packed_bytes); /*proto*/ +static char __pyx_doc_7msgpack_unpacks[] = "Unpack packed_bytes to object. Returns unpacked object."; +static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx_v_packed_bytes) { + const char* __pyx_v_p; + template_context __pyx_v_ctx; + size_t __pyx_v_off; + PyObject *__pyx_r = NULL; + const char* __pyx_t_1; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3; + __Pyx_SetupRefcountContext("unpacks"); + __pyx_self = __pyx_self; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":181 + * def unpacks(object packed_bytes): + * """Unpack packed_bytes to object. Returns unpacked object.""" + * cdef const_char_ptr p = packed_bytes # <<<<<<<<<<<<<< + * cdef template_context ctx + * cdef size_t off = 0 + */ + __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_packed_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_p = __pyx_t_1; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":183 + * cdef const_char_ptr p = packed_bytes + * cdef template_context ctx + * cdef size_t off = 0 # <<<<<<<<<<<<<< + * template_init(&ctx) + * template_execute(&ctx, p, len(packed_bytes), &off) + */ + __pyx_v_off = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":184 + * cdef template_context ctx + * cdef size_t off = 0 + * template_init(&ctx) # <<<<<<<<<<<<<< + * template_execute(&ctx, p, len(packed_bytes), &off) + * return template_data(&ctx) + */ + template_init((&__pyx_v_ctx)); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":185 + * cdef size_t off = 0 + * template_init(&ctx) + * template_execute(&ctx, p, len(packed_bytes), &off) # <<<<<<<<<<<<<< + * return template_data(&ctx) + * + */ + __pyx_t_2 = PyObject_Length(__pyx_v_packed_bytes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + template_execute((&__pyx_v_ctx), __pyx_v_p, __pyx_t_2, (&__pyx_v_off)); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":186 + * template_init(&ctx) + * template_execute(&ctx, p, len(packed_bytes), &off) + * return template_data(&ctx) # <<<<<<<<<<<<<< + * + * def unpack(object stream): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = template_data((&__pyx_v_ctx)); + __Pyx_INCREF(((PyObject *)__pyx_t_3)); + __pyx_r = ((PyObject *)__pyx_t_3); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("msgpack.unpacks"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":188 + * return template_data(&ctx) + * + * def unpack(object stream): # <<<<<<<<<<<<<< + * """unpack from stream.""" + * packed = stream.read() + */ + +static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_v_stream); /*proto*/ +static char __pyx_doc_7msgpack_unpack[] = "unpack from stream."; +static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_v_stream) { + PyObject *__pyx_v_packed; + PyObject *__pyx_r = NULL; + PyObject *__pyx_1 = 0; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_SetupRefcountContext("unpack"); + __pyx_self = __pyx_self; + __pyx_v_packed = Py_None; __Pyx_INCREF(Py_None); + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":190 + * def unpack(object stream): + * """unpack from stream.""" + * packed = stream.read() # <<<<<<<<<<<<<< + * return unpacks(packed) + * + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_packed); + __pyx_v_packed = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":191 + * """unpack from stream.""" + * packed = stream.read() + * return unpacks(packed) # <<<<<<<<<<<<<< + * + * cdef class Unpacker: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_v_packed); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_packed); + __Pyx_GIVEREF(__pyx_v_packed); + __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("msgpack.unpack"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_packed); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_7msgpack_Packer(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_7msgpack_Packer *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_7msgpack_Packer *)o); + p->strm = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_7msgpack_Packer(PyObject *o) { + struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; + Py_XDECREF(p->strm); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_7msgpack_Packer(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; + if (p->strm) { + e = (*v)(p->strm, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_7msgpack_Packer(PyObject *o) { + struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; + PyObject* tmp; + tmp = ((PyObject*)p->strm); + p->strm = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static struct PyMethodDef __pyx_methods_7msgpack_Packer[] = { + {__Pyx_NAMESTR("flush"), (PyCFunction)__pyx_pf_7msgpack_6Packer_flush, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_flush)}, + {__Pyx_NAMESTR("pack_list"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_list, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_list)}, + {__Pyx_NAMESTR("pack_dict"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_dict, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_dict)}, + {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Packer = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*reserved*/ + #else + 0, /*nb_long*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_Packer = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_Packer = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Packer = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +PyTypeObject __pyx_type_7msgpack_Packer = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("msgpack.Packer"), /*tp_name*/ + sizeof(struct __pyx_obj_7msgpack_Packer), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_7msgpack_Packer, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &__pyx_tp_as_number_Packer, /*tp_as_number*/ + &__pyx_tp_as_sequence_Packer, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Packer, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Packer, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("Packer that pack data into strm.\n\n strm must have `write(bytes)` method.\n size specifies local buffer size.\n "), /*tp_doc*/ + __pyx_tp_traverse_7msgpack_Packer, /*tp_traverse*/ + __pyx_tp_clear_7msgpack_Packer, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_7msgpack_Packer, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pf_7msgpack_6Packer___init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_7msgpack_Packer, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ +}; + +static PyObject *__pyx_tp_new_7msgpack_Unpacker(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_7msgpack_Unpacker(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static struct PyMethodDef __pyx_methods_7msgpack_Unpacker[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Unpacker = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*reserved*/ + #else + 0, /*nb_long*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_Unpacker = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_Unpacker = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Unpacker = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +PyTypeObject __pyx_type_7msgpack_Unpacker = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("msgpack.Unpacker"), /*tp_name*/ + sizeof(struct __pyx_obj_7msgpack_Unpacker), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_7msgpack_Unpacker, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &__pyx_tp_as_number_Unpacker, /*tp_as_number*/ + &__pyx_tp_as_sequence_Unpacker, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Unpacker, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Unpacker, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ + __Pyx_DOCSTR("Do nothing. This function is for symmetric to Packer"), /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_7msgpack_Unpacker, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_7msgpack_Unpacker, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ +}; + +static struct PyMethodDef __pyx_methods[] = { + {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_pack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("packs"), (PyCFunction)__pyx_pf_7msgpack_packs, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("unpacks"), (PyCFunction)__pyx_pf_7msgpack_unpacks, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_unpacks)}, + {__Pyx_NAMESTR("unpack"), (PyCFunction)__pyx_pf_7msgpack_unpack, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_unpack)}, + {0, 0, 0, 0} +}; + +static void __pyx_init_filenames(void); /*proto*/ + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + __Pyx_NAMESTR("msgpack"), + 0, /* m_doc */ + -1, /* m_size */ + __pyx_methods /* m_methods */, + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1}, + {&__pyx_kp___init__, __pyx_k___init__, sizeof(__pyx_k___init__), 1, 1, 1}, + {&__pyx_kp_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 1, 1, 1}, + {&__pyx_kp_pack_list, __pyx_k_pack_list, sizeof(__pyx_k_pack_list), 1, 1, 1}, + {&__pyx_kp_pack_dict, __pyx_k_pack_dict, sizeof(__pyx_k_pack_dict), 1, 1, 1}, + {&__pyx_kp_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 1, 1, 1}, + {&__pyx_kp_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 1, 1, 1}, + {&__pyx_kp_strm, __pyx_k_strm, sizeof(__pyx_k_strm), 1, 1, 1}, + {&__pyx_kp_size, __pyx_k_size, sizeof(__pyx_k_size), 1, 1, 1}, + {&__pyx_kp_len, __pyx_k_len, sizeof(__pyx_k_len), 1, 1, 1}, + {&__pyx_kp_o, __pyx_k_o, sizeof(__pyx_k_o), 1, 1, 1}, + {&__pyx_kp_stream, __pyx_k_stream, sizeof(__pyx_k_stream), 1, 1, 1}, + {&__pyx_kp_packed_bytes, __pyx_k_packed_bytes, sizeof(__pyx_k_packed_bytes), 1, 1, 1}, + {&__pyx_kp_cStringIO, __pyx_k_cStringIO, sizeof(__pyx_k_cStringIO), 1, 1, 1}, + {&__pyx_kp_StringIO, __pyx_k_StringIO, sizeof(__pyx_k_StringIO), 1, 1, 1}, + {&__pyx_kp_staticmethod, __pyx_k_staticmethod, sizeof(__pyx_k_staticmethod), 1, 1, 1}, + {&__pyx_kp_unpacks, __pyx_k_unpacks, sizeof(__pyx_k_unpacks), 1, 1, 1}, + {&__pyx_kp_write, __pyx_k_write, sizeof(__pyx_k_write), 1, 1, 1}, + {&__pyx_kp_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 1, 0}, + {&__pyx_kp_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 1, 1, 1}, + {&__pyx_kp_iteritems, __pyx_k_iteritems, sizeof(__pyx_k_iteritems), 1, 1, 1}, + {&__pyx_kp_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 1, 1, 1}, + {&__pyx_kp_getvalue, __pyx_k_getvalue, sizeof(__pyx_k_getvalue), 1, 1, 1}, + {&__pyx_kp_read, __pyx_k_read, sizeof(__pyx_k_read), 1, 1, 1}, + {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 0}, + {&__pyx_kp_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 0}, + {0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_staticmethod = __Pyx_GetName(__pyx_b, __pyx_kp_staticmethod); if (!__pyx_builtin_staticmethod) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_kp_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + return 0; + __pyx_L1_error:; + return -1; +} + +#if PY_MAJOR_VERSION < 3 +PyMODINIT_FUNC initmsgpack(void); /*proto*/ +PyMODINIT_FUNC initmsgpack(void) +#else +PyMODINIT_FUNC PyInit_msgpack(void); /*proto*/ +PyMODINIT_FUNC PyInit_msgpack(void) +#endif +{ + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + #ifdef CYTHON_REFNANNY + void* __pyx_refchk = NULL; + __Pyx_Refnanny = __Pyx_ImportRefcountAPI("refnanny"); + if (!__Pyx_Refnanny) { + PyErr_Clear(); + __Pyx_Refnanny = __Pyx_ImportRefcountAPI("Cython.Runtime.refnanny"); + if (!__Pyx_Refnanny) + Py_FatalError("failed to import refnanny module"); + } + __pyx_refchk = __Pyx_Refnanny->NewContext("PyMODINIT_FUNC PyInit_msgpack(void)", __LINE__, __FILE__); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Library function declarations ---*/ + __pyx_init_filenames(); + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Initialize various global constants etc. ---*/ + if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Module creation code ---*/ + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4(__Pyx_NAMESTR("msgpack"), __pyx_methods, 0, 0, PYTHON_API_VERSION); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #if PY_MAJOR_VERSION < 3 + Py_INCREF(__pyx_m); + #endif + __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__pyx_module_is_main_msgpack) { + if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + } + /*--- Builtin init code ---*/ + if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_skip_dispatch = 0; + /*--- Global init code ---*/ + /*--- Function export code ---*/ + /*--- Type init code ---*/ + if (PyType_Ready(&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Packer", (PyObject *)&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_7msgpack_Packer = &__pyx_type_7msgpack_Packer; + if (PyType_Ready(&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Unpacker", (PyObject *)&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_7msgpack_Unpacker = &__pyx_type_7msgpack_Unpacker; + /*--- Type import code ---*/ + /*--- Function import code ---*/ + /*--- Execution code ---*/ + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":3 + * # coding: utf-8 + * + * from cStringIO import StringIO # <<<<<<<<<<<<<< + * + * cdef extern from "Python.h": + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_kp_StringIO); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_StringIO); + __Pyx_GIVEREF(__pyx_kp_StringIO); + __pyx_1 = __Pyx_Import(__pyx_kp_cStringIO, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_StringIO); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + if (PyObject_SetAttr(__pyx_m, __pyx_kp_StringIO, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_2); __pyx_2 = 0; + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":37 + * + * + * cdef int BUFF_SIZE=2*1024 # <<<<<<<<<<<<<< + * + * cdef class Packer: + */ + __pyx_v_7msgpack_BUFF_SIZE = 2048; + + /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":195 + * cdef class Unpacker: + * """Do nothing. This function is for symmetric to Packer""" + * unpack = staticmethod(unpacks) # <<<<<<<<<<<<<< + */ + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_1); + __Pyx_GIVEREF(__pyx_1); + __pyx_1 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_staticmethod, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_7msgpack_Unpacker->tp_dict, __pyx_kp_unpack, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_7msgpack_Unpacker); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_2); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("msgpack"); + Py_DECREF(__pyx_m); __pyx_m = 0; + __pyx_L0:; + __Pyx_FinishRefcountContext(); + #if PY_MAJOR_VERSION < 3 + return; + #else + return __pyx_m; + #endif +} + +static const char *__pyx_filenames[] = { + "msgpack.pyx", +}; + +/* Runtime support code */ + +static void __pyx_init_filenames(void) { + __pyx_f = __pyx_filenames; +} + +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AS_STRING(kw_name)); + #endif +} + +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *number, *more_or_less; + + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + number = (num_expected == 1) ? "" : "s"; + PyErr_Format(PyExc_TypeError, + #if PY_VERSION_HEX < 0x02050000 + "%s() takes %s %d positional argument%s (%d given)", + #else + "%s() takes %s %zd positional argument%s (%zd given)", + #endif + func_name, more_or_less, num_expected, number, num_found); +} + +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + } else { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { + #else + if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) { + #endif + goto invalid_keyword_type; + } else { + for (name = first_kw_arg; *name; name++) { + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) break; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) break; + #endif + } + if (*name) { + values[name-argnames] = value; + } else { + /* unexpected keyword found */ + for (name=argnames; name != first_kw_arg; name++) { + if (**name == key) goto arg_passed_twice; + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) goto arg_passed_twice; + #endif + } + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + } + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, **name); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) { + PyObject *__import__ = 0; + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + __import__ = __Pyx_GetAttrString(__pyx_b, "__import__"); + if (!__import__) + goto bad; + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + module = PyObject_CallFunctionObjArgs(__import__, + name, global_dict, empty_dict, list, NULL); +bad: + Py_XDECREF(empty_list); + Py_XDECREF(__import__); + Py_XDECREF(empty_dict); + return module; +} + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { + PyObject *result; + result = PyObject_GetAttr(dict, name); + if (!result) + PyErr_SetObject(PyExc_NameError, name); + return result; +} + +static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + #if PY_VERSION_HEX < 0x02050000 + "need more than %d value%s to unpack", (int)index, + #else + "need more than %zd value%s to unpack", index, + #endif + (index == 1) ? "" : "s"); +} + +static INLINE void __Pyx_RaiseTooManyValuesError(void) { + PyErr_SetString(PyExc_ValueError, "too many values to unpack"); +} + +static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) { + PyObject *item; + if (!(item = PyIter_Next(iter))) { + if (!PyErr_Occurred()) { + __Pyx_RaiseNeedMoreValuesError(index); + } + } + return item; +} + +static int __Pyx_EndUnpack(PyObject *iter) { + PyObject *item; + if ((item = PyIter_Next(iter))) { + Py_DECREF(item); + __Pyx_RaiseTooManyValuesError(); + return -1; + } + else if (!PyErr_Occurred()) + return 0; + else + return -1; +} + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { + Py_XINCREF(type); + Py_XINCREF(value); + Py_XINCREF(tb); + /* First, check the traceback argument, replacing None with NULL. */ + if (tb == Py_None) { + Py_DECREF(tb); + tb = 0; + } + else if (tb != NULL && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + /* Next, replace a missing value with None */ + if (value == NULL) { + value = Py_None; + Py_INCREF(value); + } + #if PY_VERSION_HEX < 0x02050000 + if (!PyClass_Check(type)) + #else + if (!PyType_Check(type)) + #endif + { + /* Raising an instance. The value should be a dummy. */ + if (value != Py_None) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + /* Normalize to raise , */ + Py_DECREF(value); + value = type; + #if PY_VERSION_HEX < 0x02050000 + if (PyInstance_Check(type)) { + type = (PyObject*) ((PyInstanceObject*)type)->in_class; + Py_INCREF(type); + } + else { + type = 0; + PyErr_SetString(PyExc_TypeError, + "raise: exception must be an old-style class or instance"); + goto raise_error; + } + #else + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + #endif + } + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} + +static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + +#if PY_MAJOR_VERSION >= 3 + /* Note: this is a temporary work-around to prevent crashes in Python 3.0 */ + if ((tstate->exc_type != NULL) & (tstate->exc_type != Py_None)) { + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + PyErr_NormalizeException(&type, &value, &tb); + PyErr_NormalizeException(&tmp_type, &tmp_value, &tmp_tb); + tstate->exc_type = 0; + tstate->exc_value = 0; + tstate->exc_traceback = 0; + PyException_SetContext(value, tmp_value); + Py_DECREF(tmp_type); + Py_XDECREF(tmp_tb); + } +#endif + + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} + +static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { + PyThreadState *tstate = PyThreadState_GET(); + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +} + + +static INLINE int __Pyx_StrEq(const char *s1, const char *s2) { + while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } + return *s1 == *s2; +} + +static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { + if (sizeof(unsigned char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned char)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (unsigned char)-1; + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned char"); + return (unsigned char)-1; + } + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to unsigned char"); + return (unsigned char)-1; + } + return (unsigned char)val; + } + return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); +} + +static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { + if (sizeof(unsigned short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned short)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (unsigned short)-1; + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned short"); + return (unsigned short)-1; + } + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to unsigned short"); + return (unsigned short)-1; + } + return (unsigned short)val; + } + return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); +} + +static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { + if (sizeof(unsigned int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned int)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (unsigned int)-1; + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned int"); + return (unsigned int)-1; + } + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to unsigned int"); + return (unsigned int)-1; + } + return (unsigned int)val; + } + return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); +} + +static INLINE char __Pyx_PyInt_AsChar(PyObject* x) { + if (sizeof(char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(char)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (char)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to char"); + return (char)-1; + } + return (char)val; + } + return (char)__Pyx_PyInt_AsLong(x); +} + +static INLINE short __Pyx_PyInt_AsShort(PyObject* x) { + if (sizeof(short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(short)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (short)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to short"); + return (short)-1; + } + return (short)val; + } + return (short)__Pyx_PyInt_AsLong(x); +} + +static INLINE int __Pyx_PyInt_AsInt(PyObject* x) { + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (int)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { + if (sizeof(signed char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed char)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (signed char)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to signed char"); + return (signed char)-1; + } + return (signed char)val; + } + return (signed char)__Pyx_PyInt_AsSignedLong(x); +} + +static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { + if (sizeof(signed short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed short)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (signed short)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to signed short"); + return (signed short)-1; + } + return (signed short)val; + } + return (signed short)__Pyx_PyInt_AsSignedLong(x); +} + +static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { + if (sizeof(signed int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed int)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (signed int)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to signed int"); + return (signed int)-1; + } + return (signed int)val; + } + return (signed int)__Pyx_PyInt_AsSignedLong(x); +} + +static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return (unsigned long)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return PyLong_AsUnsignedLong(x); + } else { + unsigned long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned long)-1; + val = __Pyx_PyInt_AsUnsignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return (unsigned PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return PyLong_AsUnsignedLongLong(x); + } else { + unsigned PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsUnsignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE long __Pyx_PyInt_AsLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + return (long)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + return PyLong_AsLong(x); + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (long)-1; + val = __Pyx_PyInt_AsLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + return (PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + return PyLong_AsLongLong(x); + } else { + PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + return (signed long)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + return PyLong_AsLong(x); + } else { + signed long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed long)-1; + val = __Pyx_PyInt_AsSignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + return (signed PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + return PyLong_AsLongLong(x); + } else { + signed PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsSignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static void __Pyx_WriteUnraisable(const char *name) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +} + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" + +static void __Pyx_AddTraceback(const char *funcname) { + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + PyObject *py_globals = 0; + PyObject *empty_string = 0; + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(__pyx_filename); + #else + py_srcfile = PyUnicode_FromString(__pyx_filename); + #endif + if (!py_srcfile) goto bad; + if (__pyx_clineno) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_globals = PyModule_GetDict(__pyx_m); + if (!py_globals) goto bad; + #if PY_MAJOR_VERSION < 3 + empty_string = PyString_FromStringAndSize("", 0); + #else + empty_string = PyBytes_FromStringAndSize("", 0); + #endif + if (!empty_string) goto bad; + py_code = PyCode_New( + 0, /*int argcount,*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*int kwonlyargcount,*/ + #endif + 0, /*int nlocals,*/ + 0, /*int stacksize,*/ + 0, /*int flags,*/ + empty_string, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + __pyx_lineno, /*int firstlineno,*/ + empty_string /*PyObject *lnotab*/ + ); + if (!py_code) goto bad; + py_frame = PyFrame_New( + PyThreadState_GET(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + py_globals, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + py_frame->f_lineno = __pyx_lineno; + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + Py_XDECREF(empty_string); + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode && (!t->is_identifier)) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else /* Python 3+ has unicode identifiers */ + if (t->is_identifier || (t->is_unicode && t->intern)) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->is_unicode) { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + ++t; + } + return 0; +} + +/* Type Conversion Functions */ + +static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + if (x == Py_True) return 1; + else if ((x == Py_False) | (x == Py_None)) return 0; + else return PyObject_IsTrue(x); +} + +static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { + PyNumberMethods *m; + const char *name = NULL; + PyObject *res = NULL; +#if PY_VERSION_HEX < 0x03000000 + if (PyInt_Check(x) || PyLong_Check(x)) +#else + if (PyLong_Check(x)) +#endif + return Py_INCREF(x), x; + m = Py_TYPE(x)->tp_as_number; +#if PY_VERSION_HEX < 0x03000000 + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = PyNumber_Long(x); + } +#else + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Long(x); + } +#endif + if (res) { +#if PY_VERSION_HEX < 0x03000000 + if (!PyInt_Check(res) && !PyLong_Check(res)) { +#else + if (!PyLong_Check(res)) { +#endif + PyErr_Format(PyExc_TypeError, + "__%s__ returned non-%s (type %.200s)", + name, name, Py_TYPE(res)->tp_name); + Py_DECREF(res); + return NULL; + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} + +static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject* x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} + +static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { +#if PY_VERSION_HEX < 0x02050000 + if (ival <= LONG_MAX) + return PyInt_FromLong((long)ival); + else { + unsigned char *bytes = (unsigned char *) &ival; + int one = 1; int little = (int)*(unsigned char*)&one; + return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); + } +#else + return PyInt_FromSize_t(ival); +#endif +} + +static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { + unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); + if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { + return (size_t)-1; + } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to size_t"); + return (size_t)-1; + } + return (size_t)val; +} + + diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 0000000..8bfdf82 --- /dev/null +++ b/python/setup.py @@ -0,0 +1,29 @@ +from distutils.core import setup, Extension + +version = '0.0.1' + +msgpack_mod = Extension('msgpack', sources=['msgpack.c']) + +desc = 'MessagePack serializer/desirializer.' +long_desc = desc + """ + +Python binding of MessagePack_. + +This package is under development. + +.. _MessagePack: http://msgpack.sourceforge.jp/ + +What's MessagePack? (from http://msgpack.sourceforge.jp/) + + MessagePack is a binary-based efficient data interchange format that is + focused on high performance. It is like JSON, but very fast and small. +""" + +setup(name='msgpack', + author='Naoki INADA', + author_email='songofacandy@gmail.com', + version=version, + ext_modules=[msgpack_mod], + description='The MessagePack serializer/desirializer.', + long_description=long_desc, + ) -- cgit v1.2.1 From 17d2ca2d63b3eb8b9d6028c180dc00f1f10be51e Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 8 Jun 2009 04:33:47 +0900 Subject: Fix unpacking True, False and True. --- python/unpack.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'python') diff --git a/python/unpack.h b/python/unpack.h index eb72001..e51557f 100644 --- a/python/unpack.h +++ b/python/unpack.h @@ -26,7 +26,7 @@ typedef struct { struct template ## name #define msgpack_unpack_func(ret, name) \ - ret template ## name + static inline ret template ## name #define msgpack_unpack_callback(name) \ template_callback ## name @@ -39,16 +39,8 @@ typedef struct { struct template_context; typedef struct template_context template_context; -static inline void template_init(template_context* ctx); - -static inline msgpack_unpack_object template_data(template_context* ctx); - -static inline int template_execute(template_context* ctx, - const char* data, size_t len, size_t* off); - - static inline msgpack_unpack_object template_callback_root(unpack_user* u) -{ PyObject *o = Py_None; Py_INCREF(o); return o; } +{ return NULL; } static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_unpack_object* o) { *o = PyInt_FromLong((long)d); return 0; } @@ -88,13 +80,13 @@ static inline int template_callback_double(unpack_user* u, double d, msgpack_unp { *o = PyFloat_FromDouble(d); return 0; } static inline int template_callback_nil(unpack_user* u, msgpack_unpack_object* o) -{ *o = Py_None; Py_INCREF(o); return 0; } +{ Py_INCREF(Py_None); *o = Py_None; return 0; } static inline int template_callback_true(unpack_user* u, msgpack_unpack_object* o) -{ *o = Py_True; Py_INCREF(o); return 0; } +{ Py_INCREF(Py_True); *o = Py_True; return 0; } static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* o) -{ *o = Py_False; Py_INCREF(o); return 0; } +{ Py_INCREF(Py_False); *o = Py_False; return 0; } static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o) { -- cgit v1.2.1 From 935db853f0d70576c84f908c69d809877796503b Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 8 Jun 2009 04:33:58 +0900 Subject: add test. --- python/testformat.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 python/testformat.py (limited to 'python') diff --git a/python/testformat.py b/python/testformat.py new file mode 100644 index 0000000..a00123c --- /dev/null +++ b/python/testformat.py @@ -0,0 +1,64 @@ +from unittest import TestCase, main +from msgpack import packs, unpacks + +class TestFormat(TestCase): + def __check(self, obj, expected_packed): + packed = packs(obj) + self.assertEqual(packed, expected_packed) + unpacked = unpacks(packed) + self.assertEqual(unpacked, obj) + + def testSimpleValues(self): + self.__check(None, '\xc0') + self.__check(True, '\xc3') + self.__check(False, '\xc2') + self.__check( + [None, False, True], + '\x93\xc0\xc2\xc3' + ) + + def testFixnum(self): + self.__check( + [[0,64,127], [-32,-16,-1]], + "\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff" + ) + + def testFixArray(self): + self.__check( + [[],[[None]]], + "\x92\x90\x91\x91\xc0" + ) + + def testFixRaw(self): + self.__check( + ["", "a", "bc", "def"], + "\x94\xa0\xa1a\xa2bc\xa3def" + ) + pass + + def testFixMap(self): + self.__check( + {False: {None: None}, True:{None:{}}}, + "\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80" + ) + pass + + +class TestUnpack(TestCase): + def __check(self, packed, obj): + self.assertEqual(unpacks(packed), obj) + + def testuint(self): + self.__check( + "\x99\xcc\x00\xcc\x80\xcc\xff\xcd\x00\x00\xcd\x80\x00" + "\xcd\xff\xff\xce\x00\x00\x00\x00\xce\x80\x00\x00\x00" + "\xce\xff\xff\xff\xff", + [0, 128, 255, 0, 32768, 65535, 0, + 2147483648, 4294967295], + ) + + + + +if __name__ == '__main__': + main() -- cgit v1.2.1 From 560bd901f83c9024ed88b738b80e14de337847c5 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 8 Jun 2009 12:46:02 +0900 Subject: Fix double INCREF-ing when unpacking. --- python/msgpack.c | 20 +++++++++++--------- python/msgpack.pyx | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'python') diff --git a/python/msgpack.c b/python/msgpack.c index 50ec6fc..e044f18 100644 --- a/python/msgpack.c +++ b/python/msgpack.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.2 on Mon Jun 8 01:28:30 2009 */ +/* Generated by Cython 0.11.2 on Mon Jun 8 12:41:02 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -1724,7 +1724,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx PyObject *__pyx_r = NULL; const char* __pyx_t_1; Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3; + PyObject *__pyx_t_3 = NULL; __Pyx_SetupRefcountContext("unpacks"); __pyx_self = __pyx_self; @@ -1752,7 +1752,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx * cdef size_t off = 0 * template_init(&ctx) # <<<<<<<<<<<<<< * template_execute(&ctx, p, len(packed_bytes), &off) - * return template_data(&ctx) + * return template_data(&ctx) */ template_init((&__pyx_v_ctx)); @@ -1760,7 +1760,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx * cdef size_t off = 0 * template_init(&ctx) * template_execute(&ctx, p, len(packed_bytes), &off) # <<<<<<<<<<<<<< - * return template_data(&ctx) + * return template_data(&ctx) * */ __pyx_t_2 = PyObject_Length(__pyx_v_packed_bytes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -1769,19 +1769,21 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":186 * template_init(&ctx) * template_execute(&ctx, p, len(packed_bytes), &off) - * return template_data(&ctx) # <<<<<<<<<<<<<< + * return template_data(&ctx) # <<<<<<<<<<<<<< * * def unpack(object stream): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = template_data((&__pyx_v_ctx)); - __Pyx_INCREF(((PyObject *)__pyx_t_3)); - __pyx_r = ((PyObject *)__pyx_t_3); + __pyx_t_3 = template_data((&__pyx_v_ctx)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("msgpack.unpacks"); __pyx_r = NULL; __pyx_L0:; @@ -1791,7 +1793,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx } /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":188 - * return template_data(&ctx) + * return template_data(&ctx) * * def unpack(object stream): # <<<<<<<<<<<<<< * """unpack from stream.""" diff --git a/python/msgpack.pyx b/python/msgpack.pyx index c454c5d..8b2006a 100644 --- a/python/msgpack.pyx +++ b/python/msgpack.pyx @@ -173,7 +173,7 @@ cdef extern from "unpack.h": int template_execute(template_context* ctx, const_char_ptr data, size_t len, size_t* off) void template_init(template_context* ctx) - PyObject* template_data(template_context* ctx) + object template_data(template_context* ctx) def unpacks(object packed_bytes): @@ -183,7 +183,7 @@ def unpacks(object packed_bytes): cdef size_t off = 0 template_init(&ctx) template_execute(&ctx, p, len(packed_bytes), &off) - return template_data(&ctx) + return template_data(&ctx) def unpack(object stream): """unpack from stream.""" -- cgit v1.2.1 From 9c9393bff919fa4ad9e8ff64feaf28859a0c22e6 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 8 Jun 2009 13:21:38 +0900 Subject: Fix setup script doesn't work. --- python/MANIFEST | 8 ++++++++ python/setup.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 python/MANIFEST (limited to 'python') diff --git a/python/MANIFEST b/python/MANIFEST new file mode 100644 index 0000000..c7dd3a3 --- /dev/null +++ b/python/MANIFEST @@ -0,0 +1,8 @@ +msgpack.c +setup.py +pack.h +unpack.h +msgpack/pack_define.h +msgpack/pack_template.h +msgpack/unpack_define.h +msgpack/unpack_template.h diff --git a/python/setup.py b/python/setup.py index 8bfdf82..e5651a0 100644 --- a/python/setup.py +++ b/python/setup.py @@ -24,6 +24,6 @@ setup(name='msgpack', author_email='songofacandy@gmail.com', version=version, ext_modules=[msgpack_mod], - description='The MessagePack serializer/desirializer.', + description=desc, long_description=long_desc, ) -- cgit v1.2.1 From 85ca59411868ab84d874ad28e56213f5374e5ca8 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Tue, 9 Jun 2009 13:12:29 +0900 Subject: free buffer when packer deleted. --- python/msgpack.c | 653 +++++++++++++++++++++++++++++++++++------------------ python/msgpack.pyx | 9 +- 2 files changed, 437 insertions(+), 225 deletions(-) (limited to 'python') diff --git a/python/msgpack.c b/python/msgpack.c index e044f18..821f65b 100644 --- a/python/msgpack.c +++ b/python/msgpack.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.2 on Mon Jun 8 12:41:02 2009 */ +/* Generated by Cython 0.11.2 on Tue Jun 9 13:10:11 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -317,13 +317,15 @@ static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); static void __Pyx_WriteUnraisable(const char *name); /*proto*/ +static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ + static void __Pyx_AddTraceback(const char *funcname); /*proto*/ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Type declarations */ -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":39 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":39 * cdef int BUFF_SIZE=2*1024 * * cdef class Packer: # <<<<<<<<<<<<<< @@ -333,6 +335,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ struct __pyx_obj_7msgpack_Packer { PyObject_HEAD + struct __pyx_vtabstruct_7msgpack_Packer *__pyx_vtab; char *buff; unsigned int length; unsigned int allocated; @@ -340,7 +343,7 @@ struct __pyx_obj_7msgpack_Packer { PyObject *strm; }; -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":193 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":200 * return unpacks(packed) * * cdef class Unpacker: # <<<<<<<<<<<<<< @@ -351,11 +354,26 @@ struct __pyx_obj_7msgpack_Packer { struct __pyx_obj_7msgpack_Unpacker { PyObject_HEAD }; + + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":39 + * cdef int BUFF_SIZE=2*1024 + * + * cdef class Packer: # <<<<<<<<<<<<<< + * """Packer that pack data into strm. + * + */ + +struct __pyx_vtabstruct_7msgpack_Packer { + PyObject *(*__pack)(struct __pyx_obj_7msgpack_Packer *, PyObject *); +}; +static struct __pyx_vtabstruct_7msgpack_Packer *__pyx_vtabptr_7msgpack_Packer; /* Module declarations from msgpack */ static PyTypeObject *__pyx_ptype_7msgpack_Packer = 0; static PyTypeObject *__pyx_ptype_7msgpack_Unpacker = 0; static int __pyx_v_7msgpack_BUFF_SIZE; +static PyObject *__pyx_k_1 = 0; static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *, const char*, unsigned int); /*proto*/ #define __Pyx_MODULE_NAME "msgpack" int __pyx_module_is_main_msgpack = 0; @@ -365,6 +383,8 @@ static char __pyx_k___main__[] = "__main__"; static PyObject *__pyx_kp___main__; static char __pyx_k___init__[] = "__init__"; static PyObject *__pyx_kp___init__; +static char __pyx_k___del__[] = "__del__"; +static PyObject *__pyx_kp___del__; static char __pyx_k_flush[] = "flush"; static PyObject *__pyx_kp_flush; static char __pyx_k_pack_list[] = "pack_list"; @@ -381,6 +401,8 @@ static char __pyx_k_size[] = "size"; static PyObject *__pyx_kp_size; static char __pyx_k_len[] = "len"; static PyObject *__pyx_kp_len; +static char __pyx_k_obj[] = "obj"; +static PyObject *__pyx_kp_obj; static char __pyx_k_o[] = "o"; static PyObject *__pyx_kp_o; static char __pyx_k_stream[] = "stream"; @@ -397,8 +419,8 @@ static char __pyx_k_unpacks[] = "unpacks"; static PyObject *__pyx_kp_unpacks; static char __pyx_k_write[] = "write"; static PyObject *__pyx_kp_write; -static char __pyx_k_1[] = "flush"; -static PyObject *__pyx_kp_1; +static char __pyx_k_2[] = "flush"; +static PyObject *__pyx_kp_2; static char __pyx_k_encode[] = "encode"; static PyObject *__pyx_kp_encode; static char __pyx_k_iteritems[] = "iteritems"; @@ -411,12 +433,12 @@ static char __pyx_k_read[] = "read"; static PyObject *__pyx_kp_read; static PyObject *__pyx_builtin_staticmethod; static PyObject *__pyx_builtin_TypeError; -static PyObject *__pyx_kp_2; static PyObject *__pyx_kp_3; -static char __pyx_k_2[] = "utf-8"; -static char __pyx_k_3[] = "can't serialize %r"; +static PyObject *__pyx_kp_4; +static char __pyx_k_3[] = "utf-8"; +static char __pyx_k_4[] = "can't serialize %r"; -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":51 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":51 * cdef object strm * * def __init__(self, strm, int size=0): # <<<<<<<<<<<<<< @@ -478,7 +500,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * return -1; __pyx_L4_argument_unpacking_done:; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":52 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":52 * * def __init__(self, strm, int size=0): * if size <= 0: # <<<<<<<<<<<<<< @@ -488,7 +510,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * __pyx_t_1 = (__pyx_v_size <= 0); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":53 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":53 * def __init__(self, strm, int size=0): * if size <= 0: * size = BUFF_SIZE # <<<<<<<<<<<<<< @@ -500,7 +522,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * } __pyx_L6:; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":55 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":55 * size = BUFF_SIZE * * self.strm = strm # <<<<<<<<<<<<<< @@ -513,7 +535,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * __Pyx_DECREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm = __pyx_v_strm; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":56 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":56 * * self.strm = strm * self.buff = malloc(size) # <<<<<<<<<<<<<< @@ -522,7 +544,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * */ ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff = ((char *)malloc(__pyx_v_size)); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":57 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":57 * self.strm = strm * self.buff = malloc(size) * self.allocated = size # <<<<<<<<<<<<<< @@ -531,7 +553,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * */ ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->allocated = __pyx_v_size; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":58 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":58 * self.buff = malloc(size) * self.allocated = size * self.length = 0 # <<<<<<<<<<<<<< @@ -540,12 +562,12 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * */ ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":60 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":60 * self.length = 0 * * msgpack_packer_init(&self.pk, self, _packer_write) # <<<<<<<<<<<<<< * - * + * def __del__(self): */ msgpack_packer_init((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), ((void *)__pyx_v_self), ((int (*)(void *, const char*, unsigned int))__pyx_f_7msgpack__packer_write)); @@ -554,8 +576,36 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * return __pyx_r; } -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":63 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":62 + * msgpack_packer_init(&self.pk, self, _packer_write) + * + * def __del__(self): # <<<<<<<<<<<<<< + * free(self.buff); + * + */ + +static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObject *unused); /*proto*/ +static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObject *unused) { + PyObject *__pyx_r = NULL; + __Pyx_SetupRefcountContext("__del__"); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":63 * + * def __del__(self): + * free(self.buff); # <<<<<<<<<<<<<< + * + * def flush(self): + */ + free(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":65 + * free(self.buff); * * def flush(self): # <<<<<<<<<<<<<< * """Flash local buffer and output stream if it has 'flush()' method.""" @@ -572,7 +622,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec PyObject *__pyx_t_4 = NULL; __Pyx_SetupRefcountContext("flush"); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":65 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":67 * def flush(self): * """Flash local buffer and output stream if it has 'flush()' method.""" * if self.length > 0: # <<<<<<<<<<<<<< @@ -582,29 +632,29 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec __pyx_t_1 = (((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length > 0); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":66 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":68 * """Flash local buffer and output stream if it has 'flush()' method.""" * if self.length > 0: * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) # <<<<<<<<<<<<<< * self.length = 0 * if hasattr(self.strm, 'flush'): */ - __pyx_t_2 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyString_FromStringAndSize(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff, ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyString_FromStringAndSize(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff, ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":67 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":69 * if self.length > 0: * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) * self.length = 0 # <<<<<<<<<<<<<< @@ -616,26 +666,26 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec } __pyx_L5:; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":68 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":70 * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) * self.length = 0 * if hasattr(self.strm, 'flush'): # <<<<<<<<<<<<<< * self.strm.flush() * */ - __pyx_t_1 = PyObject_HasAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_HasAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_2); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":69 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":71 * self.length = 0 * if hasattr(self.strm, 'flush'): * self.strm.flush() # <<<<<<<<<<<<<< * * def pack_list(self, len): */ - __pyx_t_3 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; @@ -657,7 +707,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec return __pyx_r; } -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":71 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":73 * self.strm.flush() * * def pack_list(self, len): # <<<<<<<<<<<<<< @@ -672,14 +722,14 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyO size_t __pyx_t_1; __Pyx_SetupRefcountContext("pack_list"); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":84 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":86 * packer.pack(['foo', 'bar']) * """ * msgpack_pack_array(&self.pk, len) # <<<<<<<<<<<<<< * * def pack_dict(self, len): */ - __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} msgpack_pack_array((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -693,7 +743,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyO return __pyx_r; } -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":86 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":88 * msgpack_pack_array(&self.pk, len) * * def pack_dict(self, len): # <<<<<<<<<<<<<< @@ -708,14 +758,14 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyO size_t __pyx_t_1; __Pyx_SetupRefcountContext("pack_dict"); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":99 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":101 * packer.pack({'foo', 'bar'}) * """ * msgpack_pack_map(&self.pk, len) # <<<<<<<<<<<<<< * - * def pack(self, object o): + * cdef __pack(self, object o): */ - __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} msgpack_pack_map((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -729,16 +779,15 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyO return __pyx_r; } -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":101 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":103 * msgpack_pack_map(&self.pk, len) * - * def pack(self, object o): # <<<<<<<<<<<<<< + * cdef __pack(self, object o): # <<<<<<<<<<<<<< * cdef long long intval * cdef double fval */ -static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_v_o); /*proto*/ -static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_v_o) { +static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Packer *__pyx_v_self, PyObject *__pyx_v_o) { PY_LONG_LONG __pyx_v_intval; double __pyx_v_fval; char *__pyx_v_rawval; @@ -758,12 +807,12 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject PyObject *__pyx_t_8 = NULL; int __pyx_t_9; int __pyx_t_10; - __Pyx_SetupRefcountContext("pack"); + __Pyx_SetupRefcountContext("__pack"); __Pyx_INCREF(__pyx_v_o); __pyx_v_k = Py_None; __Pyx_INCREF(Py_None); __pyx_v_v = Py_None; __Pyx_INCREF(Py_None); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":106 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":108 * cdef char* rawval * * if o is None: # <<<<<<<<<<<<<< @@ -773,66 +822,66 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_t_1 = (__pyx_v_o == Py_None); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":107 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":109 * * if o is None: * msgpack_pack_nil(&self.pk) # <<<<<<<<<<<<<< * elif o is True: * msgpack_pack_true(&self.pk) */ - msgpack_pack_nil((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk)); - goto __pyx_L5; + msgpack_pack_nil((&__pyx_v_self->pk)); + goto __pyx_L3; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":108 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":110 * if o is None: * msgpack_pack_nil(&self.pk) * elif o is True: # <<<<<<<<<<<<<< * msgpack_pack_true(&self.pk) * elif o is False: */ - __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = (__pyx_v_o == __pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":109 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":111 * msgpack_pack_nil(&self.pk) * elif o is True: * msgpack_pack_true(&self.pk) # <<<<<<<<<<<<<< * elif o is False: * msgpack_pack_false(&self.pk) */ - msgpack_pack_true((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk)); - goto __pyx_L5; + msgpack_pack_true((&__pyx_v_self->pk)); + goto __pyx_L3; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":110 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":112 * elif o is True: * msgpack_pack_true(&self.pk) * elif o is False: # <<<<<<<<<<<<<< * msgpack_pack_false(&self.pk) * elif isinstance(o, long): */ - __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = (__pyx_v_o == __pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":111 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":113 * msgpack_pack_true(&self.pk) * elif o is False: * msgpack_pack_false(&self.pk) # <<<<<<<<<<<<<< * elif isinstance(o, long): * intval = o */ - msgpack_pack_false((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk)); - goto __pyx_L5; + msgpack_pack_false((&__pyx_v_self->pk)); + goto __pyx_L3; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":112 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":114 * elif o is False: * msgpack_pack_false(&self.pk) * elif isinstance(o, long): # <<<<<<<<<<<<<< @@ -842,28 +891,28 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyLong_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":113 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":115 * msgpack_pack_false(&self.pk) * elif isinstance(o, long): * intval = o # <<<<<<<<<<<<<< * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, int): */ - __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_intval = __pyx_t_3; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":114 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":116 * elif isinstance(o, long): * intval = o * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< * elif isinstance(o, int): * intval = o */ - msgpack_pack_long_long((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_intval); - goto __pyx_L5; + msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_intval); + goto __pyx_L3; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":115 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":117 * intval = o * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, int): # <<<<<<<<<<<<<< @@ -873,28 +922,28 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyInt_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":116 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":118 * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, int): * intval = o # <<<<<<<<<<<<<< * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, float): */ - __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_intval = __pyx_t_3; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":117 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":119 * elif isinstance(o, int): * intval = o * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< * elif isinstance(o, float): * fval = 9 */ - msgpack_pack_long_long((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_intval); - goto __pyx_L5; + msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_intval); + goto __pyx_L3; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":118 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":120 * intval = o * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, float): # <<<<<<<<<<<<<< @@ -904,7 +953,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyFloat_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":119 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":121 * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, float): * fval = 9 # <<<<<<<<<<<<<< @@ -913,18 +962,18 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject */ __pyx_v_fval = 9; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":120 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":122 * elif isinstance(o, float): * fval = 9 * msgpack_pack_double(&self.pk, fval) # <<<<<<<<<<<<<< * elif isinstance(o, str): * rawval = o */ - msgpack_pack_double((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_fval); - goto __pyx_L5; + msgpack_pack_double((&__pyx_v_self->pk), __pyx_v_fval); + goto __pyx_L3; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":121 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":123 * fval = 9 * msgpack_pack_double(&self.pk, fval) * elif isinstance(o, str): # <<<<<<<<<<<<<< @@ -934,39 +983,39 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyString_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":122 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":124 * msgpack_pack_double(&self.pk, fval) * elif isinstance(o, str): * rawval = o # <<<<<<<<<<<<<< * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) */ - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_rawval = __pyx_t_4; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":123 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":125 * elif isinstance(o, str): * rawval = o * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, unicode): */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_5); + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_5); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":124 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":126 * rawval = o * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< * elif isinstance(o, unicode): * o = o.encode('utf-8') */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw_body((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_rawval, __pyx_t_5); - goto __pyx_L5; + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_5); + goto __pyx_L3; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":125 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":127 * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, unicode): # <<<<<<<<<<<<<< @@ -976,21 +1025,21 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyUnicode_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":126 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":128 * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, unicode): * o = o.encode('utf-8') # <<<<<<<<<<<<<< * rawval = o * msgpack_pack_raw(&self.pk, len(o)) */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __Pyx_INCREF(__pyx_kp_2); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_kp_2); - __Pyx_GIVEREF(__pyx_kp_2); - __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_kp_3); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_kp_3); + __Pyx_GIVEREF(__pyx_kp_3); + __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; @@ -998,39 +1047,39 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_v_o = __pyx_t_7; __pyx_t_7 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":127 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":129 * elif isinstance(o, unicode): * o = o.encode('utf-8') * rawval = o # <<<<<<<<<<<<<< * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) */ - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_rawval = __pyx_t_4; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":128 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":130 * o = o.encode('utf-8') * rawval = o * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, dict): */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_5); + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_5); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":129 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":131 * rawval = o * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< * elif isinstance(o, dict): * msgpack_pack_map(&self.pk, len(o)) */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw_body((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_v_rawval, __pyx_t_5); - goto __pyx_L5; + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_5); + goto __pyx_L3; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":130 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":132 * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, dict): # <<<<<<<<<<<<<< @@ -1040,32 +1089,32 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyDict_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":131 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":133 * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, dict): * msgpack_pack_map(&self.pk, len(o)) # <<<<<<<<<<<<<< * for k,v in o.iteritems(): * self.pack(k) */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_map((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_5); + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_map((&__pyx_v_self->pk), __pyx_t_5); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":132 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":134 * elif isinstance(o, dict): * msgpack_pack_map(&self.pk, len(o)) * for k,v in o.iteritems(): # <<<<<<<<<<<<<< * self.pack(k) * self.pack(v) */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_iteritems); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_iteritems); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) { __pyx_t_5 = 0; __pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); } else { - __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); } __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; @@ -1079,7 +1128,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject } else { __pyx_t_6 = PyIter_Next(__pyx_t_7); if (!__pyx_t_6) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; } __Pyx_GOTREF(__pyx_t_6); @@ -1096,14 +1145,14 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_v_v = __pyx_3; __pyx_3 = 0; } else { - __pyx_1 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_1 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_2 = __Pyx_UnpackItem(__pyx_1, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_2 = __Pyx_UnpackItem(__pyx_1, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_2); - __pyx_3 = __Pyx_UnpackItem(__pyx_1, 1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_3 = __Pyx_UnpackItem(__pyx_1, 1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_3); - if (__Pyx_EndUnpack(__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_EndUnpack(__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_1); __pyx_1 = 0; __Pyx_DECREF(__pyx_v_k); __pyx_v_k = __pyx_2; @@ -1113,51 +1162,51 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_3 = 0; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":133 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":135 * msgpack_pack_map(&self.pk, len(o)) * for k,v in o.iteritems(): * self.pack(k) # <<<<<<<<<<<<<< * self.pack(v) * elif isinstance(o, tuple) or isinstance(o, list): */ - __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_k); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k); __Pyx_GIVEREF(__pyx_v_k); - __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":134 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":136 * for k,v in o.iteritems(): * self.pack(k) * self.pack(v) # <<<<<<<<<<<<<< * elif isinstance(o, tuple) or isinstance(o, list): * msgpack_pack_array(&self.pk, len(o)) */ - __pyx_t_8 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_pack); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_v); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); __Pyx_GIVEREF(__pyx_v_v); - __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L5; + goto __pyx_L3; } - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":135 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":137 * self.pack(k) * self.pack(v) * elif isinstance(o, tuple) or isinstance(o, list): # <<<<<<<<<<<<<< @@ -1173,17 +1222,17 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject } if (__pyx_t_10) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":136 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":138 * self.pack(v) * elif isinstance(o, tuple) or isinstance(o, list): * msgpack_pack_array(&self.pk, len(o)) # <<<<<<<<<<<<<< * for v in o: * self.pack(v) */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_array((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_5); + __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_array((&__pyx_v_self->pk), __pyx_t_5); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":137 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":139 * elif isinstance(o, tuple) or isinstance(o, list): * msgpack_pack_array(&self.pk, len(o)) * for v in o: # <<<<<<<<<<<<<< @@ -1193,7 +1242,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject if (PyList_CheckExact(__pyx_v_o) || PyTuple_CheckExact(__pyx_v_o)) { __pyx_t_5 = 0; __pyx_t_7 = __pyx_v_o; __Pyx_INCREF(__pyx_t_7); } else { - __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); } for (;;) { @@ -1206,7 +1255,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject } else { __pyx_t_6 = PyIter_Next(__pyx_t_7); if (!__pyx_t_6) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; } __Pyx_GOTREF(__pyx_t_6); @@ -1215,51 +1264,51 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_v_v = __pyx_t_6; __pyx_t_6 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":138 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":140 * msgpack_pack_array(&self.pk, len(o)) * for v in o: * self.pack(v) # <<<<<<<<<<<<<< * else: * # TODO: Serialize with defalt() like simplejson. */ - __pyx_t_6 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_v); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); __Pyx_GIVEREF(__pyx_v_v); - __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L5; + goto __pyx_L3; } /*else*/ { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":141 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":143 * else: * # TODO: Serialize with defalt() like simplejson. * raise TypeError, "can't serialize %r" % (o,) # <<<<<<<<<<<<<< * - * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): + * def pack(self, obj, flush=True): */ - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_7)); __Pyx_INCREF(__pyx_v_o); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_o); __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_8 = PyNumber_Remainder(__pyx_kp_3, ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyNumber_Remainder(__pyx_kp_4, ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; __Pyx_Raise(__pyx_builtin_TypeError, __pyx_t_8, 0); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_L5:; + __pyx_L3:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -1271,8 +1320,8 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("msgpack.Packer.pack"); - __pyx_r = NULL; + __Pyx_AddTraceback("msgpack.Packer.__pack"); + __pyx_r = 0; __pyx_L0:; __Pyx_DECREF(__pyx_v_k); __Pyx_DECREF(__pyx_v_v); @@ -1282,9 +1331,121 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject return __pyx_r; } -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":143 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":145 * raise TypeError, "can't serialize %r" % (o,) * + * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< + * self.__pack(obj) + * if flush: + */ + +static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_obj = 0; + PyObject *__pyx_v_flush = 0; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + static PyObject **__pyx_pyargnames[] = {&__pyx_kp_obj,&__pyx_kp_flush,0}; + __Pyx_SetupRefcountContext("pack"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[2] = {0,0}; + values[1] = __pyx_k_1; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_obj); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 1) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_flush); + if (unlikely(value)) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_obj = values[0]; + __pyx_v_flush = values[1]; + } else { + __pyx_v_flush = __pyx_k_1; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: __pyx_v_flush = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: __pyx_v_obj = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("pack", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack.Packer.pack"); + return NULL; + __pyx_L4_argument_unpacking_done:; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":146 + * + * def pack(self, obj, flush=True): + * self.__pack(obj) # <<<<<<<<<<<<<< + * if flush: + * self.flush() + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_7msgpack_Packer *)((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->__pyx_vtab)->__pack(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self), __pyx_v_obj); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":147 + * def pack(self, obj, flush=True): + * self.__pack(obj) + * if flush: # <<<<<<<<<<<<<< + * self.flush() + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_flush); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":148 + * self.__pack(obj) + * if flush: + * self.flush() # <<<<<<<<<<<<<< + * + * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L6; + } + __pyx_L6:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack.Packer.pack"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":150 + * self.flush() + * * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): # <<<<<<<<<<<<<< * if packer.length + l > packer.allocated: * if packer.length > 0: @@ -1298,7 +1459,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p PyObject *__pyx_t_4 = NULL; __Pyx_SetupRefcountContext("_packer_write"); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":144 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":151 * * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): * if packer.length + l > packer.allocated: # <<<<<<<<<<<<<< @@ -1308,7 +1469,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p __pyx_t_1 = ((__pyx_v_packer->length + __pyx_v_l) > __pyx_v_packer->allocated); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":145 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":152 * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): * if packer.length + l > packer.allocated: * if packer.length > 0: # <<<<<<<<<<<<<< @@ -1318,23 +1479,23 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p __pyx_t_1 = (__pyx_v_packer->length > 0); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":146 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":153 * if packer.length + l > packer.allocated: * if packer.length > 0: * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) # <<<<<<<<<<<<<< * if l > 64: * packer.strm.write(PyString_FromStringAndSize(b, l)) */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyString_FromStringAndSize(__pyx_v_packer->buff, __pyx_v_packer->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyString_FromStringAndSize(__pyx_v_packer->buff, __pyx_v_packer->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_4)); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; @@ -1343,7 +1504,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p } __pyx_L4:; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":147 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":154 * if packer.length > 0: * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) * if l > 64: # <<<<<<<<<<<<<< @@ -1353,29 +1514,29 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p __pyx_t_1 = (__pyx_v_l > 64); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":148 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":155 * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) * if l > 64: * packer.strm.write(PyString_FromStringAndSize(b, l)) # <<<<<<<<<<<<<< * packer.length = 0 * else: */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyString_FromStringAndSize(__pyx_v_b, __pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyString_FromStringAndSize(__pyx_v_b, __pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":149 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":156 * if l > 64: * packer.strm.write(PyString_FromStringAndSize(b, l)) * packer.length = 0 # <<<<<<<<<<<<<< @@ -1387,7 +1548,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p } /*else*/ { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":151 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":158 * packer.length = 0 * else: * memcpy(packer.buff, b, l) # <<<<<<<<<<<<<< @@ -1396,7 +1557,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p */ memcpy(__pyx_v_packer->buff, __pyx_v_b, __pyx_v_l); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":152 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":159 * else: * memcpy(packer.buff, b, l) * packer.length = l # <<<<<<<<<<<<<< @@ -1410,7 +1571,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p } /*else*/ { - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":154 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":161 * packer.length = l * else: * memcpy(packer.buff + packer.length, b, l) # <<<<<<<<<<<<<< @@ -1419,7 +1580,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p */ memcpy((__pyx_v_packer->buff + __pyx_v_packer->length), __pyx_v_b, __pyx_v_l); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":155 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":162 * else: * memcpy(packer.buff + packer.length, b, l) * packer.length += l # <<<<<<<<<<<<<< @@ -1430,7 +1591,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p } __pyx_L3:; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":156 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":163 * memcpy(packer.buff + packer.length, b, l) * packer.length += l * return 0 # <<<<<<<<<<<<<< @@ -1453,7 +1614,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p return __pyx_r; } -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":158 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":165 * return 0 * * def pack(object o, object stream): # <<<<<<<<<<<<<< @@ -1491,11 +1652,11 @@ static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_ar values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_stream); if (likely(values[1])) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } __pyx_v_o = values[0]; __pyx_v_stream = values[1]; @@ -1507,62 +1668,62 @@ static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_ar } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("msgpack.pack"); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":159 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":166 * * def pack(object o, object stream): * packer = Packer(stream) # <<<<<<<<<<<<<< * packer.pack(o) * packer.flush() */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_v_stream); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stream); __Pyx_GIVEREF(__pyx_v_stream); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_v_packer); __pyx_v_packer = __pyx_t_2; __pyx_t_2 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":160 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":167 * def pack(object o, object stream): * packer = Packer(stream) * packer.pack(o) # <<<<<<<<<<<<<< * packer.flush() * */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_v_o); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":161 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":168 * packer = Packer(stream) * packer.pack(o) * packer.flush() # <<<<<<<<<<<<<< * * def packs(object o): */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -1582,7 +1743,7 @@ static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_ar return __pyx_r; } -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":163 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":170 * packer.flush() * * def packs(object o): # <<<<<<<<<<<<<< @@ -1604,76 +1765,76 @@ static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v __pyx_v_buf = Py_None; __Pyx_INCREF(Py_None); __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":164 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":171 * * def packs(object o): * buf = StringIO() # <<<<<<<<<<<<<< * packer = Packer(buf) * packer.pack(o) */ - __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_StringIO); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_StringIO); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_1); - __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_1); __pyx_1 = 0; __Pyx_DECREF(__pyx_v_buf); __pyx_v_buf = __pyx_t_1; __pyx_t_1 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":165 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":172 * def packs(object o): * buf = StringIO() * packer = Packer(buf) # <<<<<<<<<<<<<< * packer.pack(o) * packer.flush() */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_v_buf); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_buf); __Pyx_GIVEREF(__pyx_v_buf); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_v_packer); __pyx_v_packer = __pyx_t_2; __pyx_t_2 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":166 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":173 * buf = StringIO() * packer = Packer(buf) * packer.pack(o) # <<<<<<<<<<<<<< * packer.flush() * return buf.getvalue() */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_v_o); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":167 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":174 * packer = Packer(buf) * packer.pack(o) * packer.flush() # <<<<<<<<<<<<<< * return buf.getvalue() * */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":168 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":175 * packer.pack(o) * packer.flush() * return buf.getvalue() # <<<<<<<<<<<<<< @@ -1681,9 +1842,9 @@ static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v * cdef extern from "unpack.h": */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_getvalue); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_getvalue); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_3; @@ -1707,7 +1868,7 @@ static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v return __pyx_r; } -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":179 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":186 * * * def unpacks(object packed_bytes): # <<<<<<<<<<<<<< @@ -1728,17 +1889,17 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx __Pyx_SetupRefcountContext("unpacks"); __pyx_self = __pyx_self; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":181 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":188 * def unpacks(object packed_bytes): * """Unpack packed_bytes to object. Returns unpacked object.""" * cdef const_char_ptr p = packed_bytes # <<<<<<<<<<<<<< * cdef template_context ctx * cdef size_t off = 0 */ - __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_packed_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_packed_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_p = __pyx_t_1; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":183 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":190 * cdef const_char_ptr p = packed_bytes * cdef template_context ctx * cdef size_t off = 0 # <<<<<<<<<<<<<< @@ -1747,7 +1908,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx */ __pyx_v_off = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":184 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":191 * cdef template_context ctx * cdef size_t off = 0 * template_init(&ctx) # <<<<<<<<<<<<<< @@ -1756,17 +1917,17 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx */ template_init((&__pyx_v_ctx)); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":185 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":192 * cdef size_t off = 0 * template_init(&ctx) * template_execute(&ctx, p, len(packed_bytes), &off) # <<<<<<<<<<<<<< * return template_data(&ctx) * */ - __pyx_t_2 = PyObject_Length(__pyx_v_packed_bytes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Length(__pyx_v_packed_bytes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} template_execute((&__pyx_v_ctx), __pyx_v_p, __pyx_t_2, (&__pyx_v_off)); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":186 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":193 * template_init(&ctx) * template_execute(&ctx, p, len(packed_bytes), &off) * return template_data(&ctx) # <<<<<<<<<<<<<< @@ -1774,7 +1935,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx * def unpack(object stream): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = template_data((&__pyx_v_ctx)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = template_data((&__pyx_v_ctx)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; @@ -1792,7 +1953,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx return __pyx_r; } -/* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":188 +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":195 * return template_data(&ctx) * * def unpack(object stream): # <<<<<<<<<<<<<< @@ -1812,23 +1973,23 @@ static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_ __pyx_self = __pyx_self; __pyx_v_packed = Py_None; __Pyx_INCREF(Py_None); - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":190 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":197 * def unpack(object stream): * """unpack from stream.""" * packed = stream.read() # <<<<<<<<<<<<<< * return unpacks(packed) * */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_v_packed); __pyx_v_packed = __pyx_t_2; __pyx_t_2 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":191 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":198 * """unpack from stream.""" * packed = stream.read() * return unpacks(packed) # <<<<<<<<<<<<<< @@ -1836,14 +1997,14 @@ static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_ * cdef class Unpacker: */ __Pyx_XDECREF(__pyx_r); - __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_packed); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_packed); __Pyx_GIVEREF(__pyx_v_packed); - __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_1); __pyx_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; @@ -1865,12 +2026,14 @@ static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_ __Pyx_FinishRefcountContext(); return __pyx_r; } +static struct __pyx_vtabstruct_7msgpack_Packer __pyx_vtable_7msgpack_Packer; static PyObject *__pyx_tp_new_7msgpack_Packer(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_7msgpack_Packer *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; p = ((struct __pyx_obj_7msgpack_Packer *)o); + p->__pyx_vtab = __pyx_vtabptr_7msgpack_Packer; p->strm = Py_None; Py_INCREF(Py_None); return o; } @@ -1900,10 +2063,11 @@ static int __pyx_tp_clear_7msgpack_Packer(PyObject *o) { } static struct PyMethodDef __pyx_methods_7msgpack_Packer[] = { + {__Pyx_NAMESTR("__del__"), (PyCFunction)__pyx_pf_7msgpack_6Packer___del__, METH_NOARGS, __Pyx_DOCSTR(0)}, {__Pyx_NAMESTR("flush"), (PyCFunction)__pyx_pf_7msgpack_6Packer_flush, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_flush)}, {__Pyx_NAMESTR("pack_list"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_list, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_list)}, {__Pyx_NAMESTR("pack_dict"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_dict, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_dict)}, - {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; @@ -2240,6 +2404,7 @@ static struct PyModuleDef __pyx_moduledef = { static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1}, {&__pyx_kp___init__, __pyx_k___init__, sizeof(__pyx_k___init__), 1, 1, 1}, + {&__pyx_kp___del__, __pyx_k___del__, sizeof(__pyx_k___del__), 1, 1, 1}, {&__pyx_kp_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 1, 1, 1}, {&__pyx_kp_pack_list, __pyx_k_pack_list, sizeof(__pyx_k_pack_list), 1, 1, 1}, {&__pyx_kp_pack_dict, __pyx_k_pack_dict, sizeof(__pyx_k_pack_dict), 1, 1, 1}, @@ -2248,6 +2413,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_strm, __pyx_k_strm, sizeof(__pyx_k_strm), 1, 1, 1}, {&__pyx_kp_size, __pyx_k_size, sizeof(__pyx_k_size), 1, 1, 1}, {&__pyx_kp_len, __pyx_k_len, sizeof(__pyx_k_len), 1, 1, 1}, + {&__pyx_kp_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 1, 1, 1}, {&__pyx_kp_o, __pyx_k_o, sizeof(__pyx_k_o), 1, 1, 1}, {&__pyx_kp_stream, __pyx_k_stream, sizeof(__pyx_k_stream), 1, 1, 1}, {&__pyx_kp_packed_bytes, __pyx_k_packed_bytes, sizeof(__pyx_k_packed_bytes), 1, 1, 1}, @@ -2256,19 +2422,19 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_staticmethod, __pyx_k_staticmethod, sizeof(__pyx_k_staticmethod), 1, 1, 1}, {&__pyx_kp_unpacks, __pyx_k_unpacks, sizeof(__pyx_k_unpacks), 1, 1, 1}, {&__pyx_kp_write, __pyx_k_write, sizeof(__pyx_k_write), 1, 1, 1}, - {&__pyx_kp_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 1, 0}, + {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 1, 0}, {&__pyx_kp_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 1, 1, 1}, {&__pyx_kp_iteritems, __pyx_k_iteritems, sizeof(__pyx_k_iteritems), 1, 1, 1}, {&__pyx_kp_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 1, 1, 1}, {&__pyx_kp_getvalue, __pyx_k_getvalue, sizeof(__pyx_k_getvalue), 1, 1, 1}, {&__pyx_kp_read, __pyx_k_read, sizeof(__pyx_k_read), 1, 1, 1}, - {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 0}, {&__pyx_kp_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 0}, + {&__pyx_kp_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 0}, {0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_staticmethod = __Pyx_GetName(__pyx_b, __pyx_kp_staticmethod); if (!__pyx_builtin_staticmethod) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_kp_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_staticmethod = __Pyx_GetName(__pyx_b, __pyx_kp_staticmethod); if (!__pyx_builtin_staticmethod) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_kp_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -2337,17 +2503,24 @@ PyMODINIT_FUNC PyInit_msgpack(void) /*--- Global init code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ + __pyx_vtabptr_7msgpack_Packer = &__pyx_vtable_7msgpack_Packer; + #if PY_MAJOR_VERSION >= 3 + __pyx_vtable_7msgpack_Packer.__pack = (PyObject *(*)(struct __pyx_obj_7msgpack_Packer *, PyObject *))__pyx_f_7msgpack_6Packer___pack; + #else + *(void(**)(void))&__pyx_vtable_7msgpack_Packer.__pack = (void(*)(void))__pyx_f_7msgpack_6Packer___pack; + #endif if (PyType_Ready(&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_7msgpack_Packer.tp_dict, __pyx_vtabptr_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Packer", (PyObject *)&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_7msgpack_Packer = &__pyx_type_7msgpack_Packer; - if (PyType_Ready(&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Unpacker", (PyObject *)&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Unpacker", (PyObject *)&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_7msgpack_Unpacker = &__pyx_type_7msgpack_Unpacker; /*--- Type import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":3 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":3 * # coding: utf-8 * * from cStringIO import StringIO # <<<<<<<<<<<<<< @@ -2368,7 +2541,7 @@ PyMODINIT_FUNC PyInit_msgpack(void) __Pyx_DECREF(__pyx_2); __pyx_2 = 0; __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":37 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":37 * * * cdef int BUFF_SIZE=2*1024 # <<<<<<<<<<<<<< @@ -2377,22 +2550,35 @@ PyMODINIT_FUNC PyInit_msgpack(void) */ __pyx_v_7msgpack_BUFF_SIZE = 2048; - /* "/home/inada-n/work/msgpack.py/python/msgpack.pyx":195 + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":145 + * raise TypeError, "can't serialize %r" % (o,) + * + * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< + * self.__pack(obj) + * if flush: + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_k_1 = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_k_1); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":202 * cdef class Unpacker: * """Do nothing. This function is for symmetric to Packer""" * unpack = staticmethod(unpacks) # <<<<<<<<<<<<<< */ - __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_1); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_1); __Pyx_GIVEREF(__pyx_1); __pyx_1 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_staticmethod, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_staticmethod, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_7msgpack_Unpacker->tp_dict, __pyx_kp_unpack, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem((PyObject *)__pyx_ptype_7msgpack_Unpacker->tp_dict, __pyx_kp_unpack, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_7msgpack_Unpacker); goto __pyx_L0; @@ -3037,6 +3223,25 @@ static void __Pyx_WriteUnraisable(const char *name) { } } +static int __Pyx_SetVtable(PyObject *dict, void *vtable) { + PyObject *pycobj = 0; + int result; + + pycobj = PyCObject_FromVoidPtr(vtable, 0); + if (!pycobj) + goto bad; + if (PyDict_SetItemString(dict, "__pyx_vtable__", pycobj) < 0) + goto bad; + result = 0; + goto done; + +bad: + result = -1; +done: + Py_XDECREF(pycobj); + return result; +} + #include "compile.h" #include "frameobject.h" #include "traceback.h" diff --git a/python/msgpack.pyx b/python/msgpack.pyx index 8b2006a..f24f403 100644 --- a/python/msgpack.pyx +++ b/python/msgpack.pyx @@ -59,6 +59,8 @@ cdef class Packer: msgpack_packer_init(&self.pk, self, _packer_write) + def __del__(self): + free(self.buff); def flush(self): """Flash local buffer and output stream if it has 'flush()' method.""" @@ -98,7 +100,7 @@ cdef class Packer: """ msgpack_pack_map(&self.pk, len) - def pack(self, object o): + cdef __pack(self, object o): cdef long long intval cdef double fval cdef char* rawval @@ -140,6 +142,11 @@ cdef class Packer: # TODO: Serialize with defalt() like simplejson. 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): if packer.length + l > packer.allocated: if packer.length > 0: -- cgit v1.2.1 From a1fb1507d45d27f0c08e8d39054987ed6dcaf9e7 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 10 Jun 2009 10:45:07 +0900 Subject: Refactor include path. --- python/MANIFEST | 8 ++++---- python/include | 1 + python/msgpack | 1 - python/setup.py | 7 ++++++- 4 files changed, 11 insertions(+), 6 deletions(-) create mode 120000 python/include delete mode 120000 python/msgpack (limited to 'python') diff --git a/python/MANIFEST b/python/MANIFEST index c7dd3a3..dc042ae 100644 --- a/python/MANIFEST +++ b/python/MANIFEST @@ -2,7 +2,7 @@ msgpack.c setup.py pack.h unpack.h -msgpack/pack_define.h -msgpack/pack_template.h -msgpack/unpack_define.h -msgpack/unpack_template.h +include/msgpack/pack_define.h +include/msgpack/pack_template.h +include/msgpack/unpack_define.h +include/msgpack/unpack_template.h diff --git a/python/include b/python/include new file mode 120000 index 0000000..a96aa0e --- /dev/null +++ b/python/include @@ -0,0 +1 @@ +.. \ No newline at end of file diff --git a/python/msgpack b/python/msgpack deleted file mode 120000 index 430db49..0000000 --- a/python/msgpack +++ /dev/null @@ -1 +0,0 @@ -../msgpack \ No newline at end of file diff --git a/python/setup.py b/python/setup.py index e5651a0..65ca412 100644 --- a/python/setup.py +++ b/python/setup.py @@ -1,8 +1,13 @@ from distutils.core import setup, Extension +import os version = '0.0.1' -msgpack_mod = Extension('msgpack', sources=['msgpack.c']) +PACKAGE_ROOT = os.getcwdu() +INCLUDE_PATH = os.path.join(PACKAGE_ROOT, 'include') +msgpack_mod = Extension('msgpack', + sources=['msgpack.c'], + include_dirs=[INCLUDE_PATH]) desc = 'MessagePack serializer/desirializer.' long_desc = desc + """ -- cgit v1.2.1 From 3a9f74e79c3d1912d8c0c1ad4d1478c611caba0a Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 10 Jun 2009 10:58:09 +0900 Subject: Make msgpack package instead of module. --- python/MANIFEST | 4 +- python/msgpack.c | 3438 ------------------------------------------- python/msgpack.pyx | 202 --- python/msgpack/__init__.py | 3 + python/msgpack/_msgpack.pyx | 202 +++ python/msgpack/pack.h | 121 ++ python/msgpack/unpack.h | 122 ++ python/pack.h | 121 -- python/setup.py | 6 +- python/unpack.h | 122 -- 10 files changed, 454 insertions(+), 3887 deletions(-) delete mode 100644 python/msgpack.c delete mode 100644 python/msgpack.pyx create mode 100644 python/msgpack/__init__.py create mode 100644 python/msgpack/_msgpack.pyx create mode 100644 python/msgpack/pack.h create mode 100644 python/msgpack/unpack.h delete mode 100644 python/pack.h delete mode 100644 python/unpack.h (limited to 'python') diff --git a/python/MANIFEST b/python/MANIFEST index dc042ae..f2da7da 100644 --- a/python/MANIFEST +++ b/python/MANIFEST @@ -1,7 +1,7 @@ msgpack.c setup.py -pack.h -unpack.h +msgpack/pack.h +msgpack/unpack.h include/msgpack/pack_define.h include/msgpack/pack_template.h include/msgpack/unpack_define.h diff --git a/python/msgpack.c b/python/msgpack.c deleted file mode 100644 index 821f65b..0000000 --- a/python/msgpack.c +++ /dev/null @@ -1,3438 +0,0 @@ -/* Generated by Cython 0.11.2 on Tue Jun 9 13:10:11 2009 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#include "structmember.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#endif -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif -#if PY_VERSION_HEX < 0x02040000 - #define METH_COEXIST 0 - #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) -#endif -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) PyInt_AsLong(o) - #define PyNumber_Index(o) PyNumber_Int(o) - #define PyIndex_Check(o) PyNumber_Check(o) -#endif -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - -#endif -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" -#endif -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyString_Type PyBytes_Type - #define PyString_CheckExact PyBytes_CheckExact - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define PyBytes_Type PyString_Type -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func) -#endif -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif - #ifndef __fastcall - #define __fastcall - #endif -#else - #define _USE_MATH_DEFINES -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif -#ifdef __cplusplus -#define __PYX_EXTERN_C extern "C" -#else -#define __PYX_EXTERN_C extern -#endif -#include -#define __PYX_HAVE_API__msgpack -#include "stdlib.h" -#include "string.h" -#include "pack.h" -#include "unpack.h" -#define __PYX_USE_C99_COMPLEX defined(_Complex_I) - - -#ifdef __GNUC__ -#define INLINE __inline__ -#elif _WIN32 -#define INLINE __inline -#else -#define INLINE -#endif - -typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char is_identifier;} __Pyx_StringTabEntry; /*proto*/ - - - -static int __pyx_skip_dispatch = 0; - - -/* Type Conversion Predeclarations */ - -#if PY_MAJOR_VERSION < 3 -#define __Pyx_PyBytes_FromString PyString_FromString -#define __Pyx_PyBytes_FromStringAndSize PyString_FromStringAndSize -#define __Pyx_PyBytes_AsString PyString_AsString -#else -#define __Pyx_PyBytes_FromString PyBytes_FromString -#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize -#define __Pyx_PyBytes_AsString PyBytes_AsString -#endif - -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -#if !defined(T_PYSSIZET) -#if PY_VERSION_HEX < 0x02050000 -#define T_PYSSIZET T_INT -#elif !defined(T_LONGLONG) -#define T_PYSSIZET \ - ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \ - ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1)) -#else -#define T_PYSSIZET \ - ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \ - ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : \ - ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1))) -#endif -#endif - -#if !defined(T_SIZET) -#if !defined(T_ULONGLONG) -#define T_SIZET \ - ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \ - ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1)) -#else -#define T_SIZET \ - ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \ - ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : \ - ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1))) -#endif -#endif - -static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) - - -#ifdef __GNUC__ -/* Test for GCC > 2.95 */ -#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) -#else /* __GNUC__ > 2 ... */ -#define likely(x) (x) -#define unlikely(x) (x) -#endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ -#define likely(x) (x) -#define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; -static const char **__pyx_f; - - -#ifdef CYTHON_REFNANNY -typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*NewContext)(const char*, int, const char*); - void (*FinishContext)(void**); -} __Pyx_RefnannyAPIStruct; -static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL; -#define __Pyx_ImportRefcountAPI(name) (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI") -#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r) -#define __Pyx_SetupRefcountContext(name) void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__) -#define __Pyx_FinishRefcountContext() __Pyx_Refnanny->FinishContext(&__pyx_refchk) -#else -#define __Pyx_INCREF(r) Py_INCREF(r) -#define __Pyx_DECREF(r) Py_DECREF(r) -#define __Pyx_GOTREF(r) -#define __Pyx_GIVEREF(r) -#define __Pyx_XDECREF(r) Py_XDECREF(r) -#define __Pyx_SetupRefcountContext(name) -#define __Pyx_FinishRefcountContext() -#endif /* CYTHON_REFNANNY */ -#define __Pyx_XGIVEREF(r) if((r) == NULL) ; else __Pyx_GIVEREF(r) -#define __Pyx_XGOTREF(r) if((r) == NULL) ; else __Pyx_GOTREF(r) - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, PyObject* kw_name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); - -static INLINE void __Pyx_RaiseTooManyValuesError(void); - -static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/ -static int __Pyx_EndUnpack(PyObject *); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ - -static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/ - -static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static void __Pyx_WriteUnraisable(const char *name); /*proto*/ - -static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ - -static void __Pyx_AddTraceback(const char *funcname); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ - -/* Type declarations */ - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":39 - * cdef int BUFF_SIZE=2*1024 - * - * cdef class Packer: # <<<<<<<<<<<<<< - * """Packer that pack data into strm. - * - */ - -struct __pyx_obj_7msgpack_Packer { - PyObject_HEAD - struct __pyx_vtabstruct_7msgpack_Packer *__pyx_vtab; - char *buff; - unsigned int length; - unsigned int allocated; - struct msgpack_packer pk; - PyObject *strm; -}; - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":200 - * return unpacks(packed) - * - * cdef class Unpacker: # <<<<<<<<<<<<<< - * """Do nothing. This function is for symmetric to Packer""" - * unpack = staticmethod(unpacks) - */ - -struct __pyx_obj_7msgpack_Unpacker { - PyObject_HEAD -}; - - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":39 - * cdef int BUFF_SIZE=2*1024 - * - * cdef class Packer: # <<<<<<<<<<<<<< - * """Packer that pack data into strm. - * - */ - -struct __pyx_vtabstruct_7msgpack_Packer { - PyObject *(*__pack)(struct __pyx_obj_7msgpack_Packer *, PyObject *); -}; -static struct __pyx_vtabstruct_7msgpack_Packer *__pyx_vtabptr_7msgpack_Packer; -/* Module declarations from msgpack */ - -static PyTypeObject *__pyx_ptype_7msgpack_Packer = 0; -static PyTypeObject *__pyx_ptype_7msgpack_Unpacker = 0; -static int __pyx_v_7msgpack_BUFF_SIZE; -static PyObject *__pyx_k_1 = 0; -static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *, const char*, unsigned int); /*proto*/ -#define __Pyx_MODULE_NAME "msgpack" -int __pyx_module_is_main_msgpack = 0; - -/* Implementation of msgpack */ -static char __pyx_k___main__[] = "__main__"; -static PyObject *__pyx_kp___main__; -static char __pyx_k___init__[] = "__init__"; -static PyObject *__pyx_kp___init__; -static char __pyx_k___del__[] = "__del__"; -static PyObject *__pyx_kp___del__; -static char __pyx_k_flush[] = "flush"; -static PyObject *__pyx_kp_flush; -static char __pyx_k_pack_list[] = "pack_list"; -static PyObject *__pyx_kp_pack_list; -static char __pyx_k_pack_dict[] = "pack_dict"; -static PyObject *__pyx_kp_pack_dict; -static char __pyx_k_pack[] = "pack"; -static PyObject *__pyx_kp_pack; -static char __pyx_k_unpack[] = "unpack"; -static PyObject *__pyx_kp_unpack; -static char __pyx_k_strm[] = "strm"; -static PyObject *__pyx_kp_strm; -static char __pyx_k_size[] = "size"; -static PyObject *__pyx_kp_size; -static char __pyx_k_len[] = "len"; -static PyObject *__pyx_kp_len; -static char __pyx_k_obj[] = "obj"; -static PyObject *__pyx_kp_obj; -static char __pyx_k_o[] = "o"; -static PyObject *__pyx_kp_o; -static char __pyx_k_stream[] = "stream"; -static PyObject *__pyx_kp_stream; -static char __pyx_k_packed_bytes[] = "packed_bytes"; -static PyObject *__pyx_kp_packed_bytes; -static char __pyx_k_cStringIO[] = "cStringIO"; -static PyObject *__pyx_kp_cStringIO; -static char __pyx_k_StringIO[] = "StringIO"; -static PyObject *__pyx_kp_StringIO; -static char __pyx_k_staticmethod[] = "staticmethod"; -static PyObject *__pyx_kp_staticmethod; -static char __pyx_k_unpacks[] = "unpacks"; -static PyObject *__pyx_kp_unpacks; -static char __pyx_k_write[] = "write"; -static PyObject *__pyx_kp_write; -static char __pyx_k_2[] = "flush"; -static PyObject *__pyx_kp_2; -static char __pyx_k_encode[] = "encode"; -static PyObject *__pyx_kp_encode; -static char __pyx_k_iteritems[] = "iteritems"; -static PyObject *__pyx_kp_iteritems; -static char __pyx_k_TypeError[] = "TypeError"; -static PyObject *__pyx_kp_TypeError; -static char __pyx_k_getvalue[] = "getvalue"; -static PyObject *__pyx_kp_getvalue; -static char __pyx_k_read[] = "read"; -static PyObject *__pyx_kp_read; -static PyObject *__pyx_builtin_staticmethod; -static PyObject *__pyx_builtin_TypeError; -static PyObject *__pyx_kp_3; -static PyObject *__pyx_kp_4; -static char __pyx_k_3[] = "utf-8"; -static char __pyx_k_4[] = "can't serialize %r"; - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":51 - * cdef object strm - * - * def __init__(self, strm, int size=0): # <<<<<<<<<<<<<< - * if size <= 0: - * size = BUFF_SIZE - */ - -static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_strm = 0; - int __pyx_v_size; - int __pyx_r; - int __pyx_t_1; - static PyObject **__pyx_pyargnames[] = {&__pyx_kp_strm,&__pyx_kp_size,0}; - __Pyx_SetupRefcountContext("__init__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_strm); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 1) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_size); - if (unlikely(value)) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_strm = values[0]; - if (values[1]) { - __pyx_v_size = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_size = 0; - } - } else { - __pyx_v_size = 0; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: __pyx_v_size = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - case 1: __pyx_v_strm = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("msgpack.Packer.__init__"); - return -1; - __pyx_L4_argument_unpacking_done:; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":52 - * - * def __init__(self, strm, int size=0): - * if size <= 0: # <<<<<<<<<<<<<< - * size = BUFF_SIZE - * - */ - __pyx_t_1 = (__pyx_v_size <= 0); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":53 - * def __init__(self, strm, int size=0): - * if size <= 0: - * size = BUFF_SIZE # <<<<<<<<<<<<<< - * - * self.strm = strm - */ - __pyx_v_size = __pyx_v_7msgpack_BUFF_SIZE; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":55 - * size = BUFF_SIZE - * - * self.strm = strm # <<<<<<<<<<<<<< - * self.buff = malloc(size) - * self.allocated = size - */ - __Pyx_INCREF(__pyx_v_strm); - __Pyx_GIVEREF(__pyx_v_strm); - __Pyx_GOTREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); - __Pyx_DECREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm = __pyx_v_strm; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":56 - * - * self.strm = strm - * self.buff = malloc(size) # <<<<<<<<<<<<<< - * self.allocated = size - * self.length = 0 - */ - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff = ((char *)malloc(__pyx_v_size)); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":57 - * self.strm = strm - * self.buff = malloc(size) - * self.allocated = size # <<<<<<<<<<<<<< - * self.length = 0 - * - */ - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->allocated = __pyx_v_size; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":58 - * self.buff = malloc(size) - * self.allocated = size - * self.length = 0 # <<<<<<<<<<<<<< - * - * msgpack_packer_init(&self.pk, self, _packer_write) - */ - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":60 - * self.length = 0 - * - * msgpack_packer_init(&self.pk, self, _packer_write) # <<<<<<<<<<<<<< - * - * def __del__(self): - */ - msgpack_packer_init((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), ((void *)__pyx_v_self), ((int (*)(void *, const char*, unsigned int))__pyx_f_7msgpack__packer_write)); - - __pyx_r = 0; - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":62 - * msgpack_packer_init(&self.pk, self, _packer_write) - * - * def __del__(self): # <<<<<<<<<<<<<< - * free(self.buff); - * - */ - -static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObject *unused); /*proto*/ -static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObject *unused) { - PyObject *__pyx_r = NULL; - __Pyx_SetupRefcountContext("__del__"); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":63 - * - * def __del__(self): - * free(self.buff); # <<<<<<<<<<<<<< - * - * def flush(self): - */ - free(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":65 - * free(self.buff); - * - * def flush(self): # <<<<<<<<<<<<<< - * """Flash local buffer and output stream if it has 'flush()' method.""" - * if self.length > 0: - */ - -static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObject *unused); /*proto*/ -static char __pyx_doc_7msgpack_6Packer_flush[] = "Flash local buffer and output stream if it has 'flush()' method."; -static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObject *unused) { - PyObject *__pyx_r = NULL; - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_SetupRefcountContext("flush"); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":67 - * def flush(self): - * """Flash local buffer and output stream if it has 'flush()' method.""" - * if self.length > 0: # <<<<<<<<<<<<<< - * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) - * self.length = 0 - */ - __pyx_t_1 = (((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length > 0); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":68 - * """Flash local buffer and output stream if it has 'flush()' method.""" - * if self.length > 0: - * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) # <<<<<<<<<<<<<< - * self.length = 0 - * if hasattr(self.strm, 'flush'): - */ - __pyx_t_2 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyString_FromStringAndSize(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff, ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":69 - * if self.length > 0: - * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) - * self.length = 0 # <<<<<<<<<<<<<< - * if hasattr(self.strm, 'flush'): - * self.strm.flush() - */ - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":70 - * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) - * self.length = 0 - * if hasattr(self.strm, 'flush'): # <<<<<<<<<<<<<< - * self.strm.flush() - * - */ - __pyx_t_1 = PyObject_HasAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_2); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":71 - * self.length = 0 - * if hasattr(self.strm, 'flush'): - * self.strm.flush() # <<<<<<<<<<<<<< - * - * def pack_list(self, len): - */ - __pyx_t_3 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L6; - } - __pyx_L6:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("msgpack.Packer.flush"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":73 - * self.strm.flush() - * - * def pack_list(self, len): # <<<<<<<<<<<<<< - * """Start packing sequential objects. - * - */ - -static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyObject *__pyx_v_len); /*proto*/ -static char __pyx_doc_7msgpack_6Packer_pack_list[] = "Start packing sequential objects.\n\n Example:\n\n packer.pack_list(2)\n packer.pack('foo')\n packer.pack('bar')\n\n This code is same as below code:\n\n packer.pack(['foo', 'bar'])\n "; -static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyObject *__pyx_v_len) { - PyObject *__pyx_r = NULL; - size_t __pyx_t_1; - __Pyx_SetupRefcountContext("pack_list"); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":86 - * packer.pack(['foo', 'bar']) - * """ - * msgpack_pack_array(&self.pk, len) # <<<<<<<<<<<<<< - * - * def pack_dict(self, len): - */ - __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_array((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("msgpack.Packer.pack_list"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":88 - * msgpack_pack_array(&self.pk, len) - * - * def pack_dict(self, len): # <<<<<<<<<<<<<< - * """Start packing key-value objects. - * - */ - -static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_len); /*proto*/ -static char __pyx_doc_7msgpack_6Packer_pack_dict[] = "Start packing key-value objects.\n\n Example:\n\n packer.pack_dict(1)\n packer.pack('foo')\n packer.pack('bar')\n\n This code is same as below code:\n\n packer.pack({'foo', 'bar'})\n "; -static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_len) { - PyObject *__pyx_r = NULL; - size_t __pyx_t_1; - __Pyx_SetupRefcountContext("pack_dict"); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":101 - * packer.pack({'foo', 'bar'}) - * """ - * msgpack_pack_map(&self.pk, len) # <<<<<<<<<<<<<< - * - * cdef __pack(self, object o): - */ - __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_map((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("msgpack.Packer.pack_dict"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":103 - * msgpack_pack_map(&self.pk, len) - * - * cdef __pack(self, object o): # <<<<<<<<<<<<<< - * cdef long long intval - * cdef double fval - */ - -static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Packer *__pyx_v_self, PyObject *__pyx_v_o) { - PY_LONG_LONG __pyx_v_intval; - double __pyx_v_fval; - char *__pyx_v_rawval; - PyObject *__pyx_v_k; - PyObject *__pyx_v_v; - PyObject *__pyx_r = NULL; - PyObject *__pyx_1 = 0; - PyObject *__pyx_2 = 0; - PyObject *__pyx_3 = 0; - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PY_LONG_LONG __pyx_t_3; - char *__pyx_t_4; - Py_ssize_t __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; - int __pyx_t_10; - __Pyx_SetupRefcountContext("__pack"); - __Pyx_INCREF(__pyx_v_o); - __pyx_v_k = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_v = Py_None; __Pyx_INCREF(Py_None); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":108 - * cdef char* rawval - * - * if o is None: # <<<<<<<<<<<<<< - * msgpack_pack_nil(&self.pk) - * elif o is True: - */ - __pyx_t_1 = (__pyx_v_o == Py_None); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":109 - * - * if o is None: - * msgpack_pack_nil(&self.pk) # <<<<<<<<<<<<<< - * elif o is True: - * msgpack_pack_true(&self.pk) - */ - msgpack_pack_nil((&__pyx_v_self->pk)); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":110 - * if o is None: - * msgpack_pack_nil(&self.pk) - * elif o is True: # <<<<<<<<<<<<<< - * msgpack_pack_true(&self.pk) - * elif o is False: - */ - __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = (__pyx_v_o == __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":111 - * msgpack_pack_nil(&self.pk) - * elif o is True: - * msgpack_pack_true(&self.pk) # <<<<<<<<<<<<<< - * elif o is False: - * msgpack_pack_false(&self.pk) - */ - msgpack_pack_true((&__pyx_v_self->pk)); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":112 - * elif o is True: - * msgpack_pack_true(&self.pk) - * elif o is False: # <<<<<<<<<<<<<< - * msgpack_pack_false(&self.pk) - * elif isinstance(o, long): - */ - __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = (__pyx_v_o == __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":113 - * msgpack_pack_true(&self.pk) - * elif o is False: - * msgpack_pack_false(&self.pk) # <<<<<<<<<<<<<< - * elif isinstance(o, long): - * intval = o - */ - msgpack_pack_false((&__pyx_v_self->pk)); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":114 - * elif o is False: - * msgpack_pack_false(&self.pk) - * elif isinstance(o, long): # <<<<<<<<<<<<<< - * intval = o - * msgpack_pack_long_long(&self.pk, intval) - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyLong_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":115 - * msgpack_pack_false(&self.pk) - * elif isinstance(o, long): - * intval = o # <<<<<<<<<<<<<< - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, int): - */ - __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_intval = __pyx_t_3; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":116 - * elif isinstance(o, long): - * intval = o - * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< - * elif isinstance(o, int): - * intval = o - */ - msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_intval); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":117 - * intval = o - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, int): # <<<<<<<<<<<<<< - * intval = o - * msgpack_pack_long_long(&self.pk, intval) - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyInt_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":118 - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, int): - * intval = o # <<<<<<<<<<<<<< - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, float): - */ - __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_intval = __pyx_t_3; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":119 - * elif isinstance(o, int): - * intval = o - * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< - * elif isinstance(o, float): - * fval = 9 - */ - msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_intval); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":120 - * intval = o - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, float): # <<<<<<<<<<<<<< - * fval = 9 - * msgpack_pack_double(&self.pk, fval) - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyFloat_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":121 - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, float): - * fval = 9 # <<<<<<<<<<<<<< - * msgpack_pack_double(&self.pk, fval) - * elif isinstance(o, str): - */ - __pyx_v_fval = 9; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":122 - * elif isinstance(o, float): - * fval = 9 - * msgpack_pack_double(&self.pk, fval) # <<<<<<<<<<<<<< - * elif isinstance(o, str): - * rawval = o - */ - msgpack_pack_double((&__pyx_v_self->pk), __pyx_v_fval); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":123 - * fval = 9 - * msgpack_pack_double(&self.pk, fval) - * elif isinstance(o, str): # <<<<<<<<<<<<<< - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyString_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":124 - * msgpack_pack_double(&self.pk, fval) - * elif isinstance(o, str): - * rawval = o # <<<<<<<<<<<<<< - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - */ - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_rawval = __pyx_t_4; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":125 - * elif isinstance(o, str): - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, unicode): - */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_5); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":126 - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< - * elif isinstance(o, unicode): - * o = o.encode('utf-8') - */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_5); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":127 - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, unicode): # <<<<<<<<<<<<<< - * o = o.encode('utf-8') - * rawval = o - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyUnicode_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":128 - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, unicode): - * o = o.encode('utf-8') # <<<<<<<<<<<<<< - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_6)); - __Pyx_INCREF(__pyx_kp_3); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_kp_3); - __Pyx_GIVEREF(__pyx_kp_3); - __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_v_o); - __pyx_v_o = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":129 - * elif isinstance(o, unicode): - * o = o.encode('utf-8') - * rawval = o # <<<<<<<<<<<<<< - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - */ - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_rawval = __pyx_t_4; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":130 - * o = o.encode('utf-8') - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, dict): - */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_5); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":131 - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< - * elif isinstance(o, dict): - * msgpack_pack_map(&self.pk, len(o)) - */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_5); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":132 - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, dict): # <<<<<<<<<<<<<< - * msgpack_pack_map(&self.pk, len(o)) - * for k,v in o.iteritems(): - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyDict_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":133 - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, dict): - * msgpack_pack_map(&self.pk, len(o)) # <<<<<<<<<<<<<< - * for k,v in o.iteritems(): - * self.pack(k) - */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_map((&__pyx_v_self->pk), __pyx_t_5); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":134 - * elif isinstance(o, dict): - * msgpack_pack_map(&self.pk, len(o)) - * for k,v in o.iteritems(): # <<<<<<<<<<<<<< - * self.pack(k) - * self.pack(v) - */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_iteritems); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) { - __pyx_t_5 = 0; __pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); - } else { - __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - for (;;) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; - } else if (likely(PyTuple_CheckExact(__pyx_t_7))) { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; - } else { - __pyx_t_6 = PyIter_Next(__pyx_t_7); - if (!__pyx_t_6) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - break; - } - __Pyx_GOTREF(__pyx_t_6); - } - if (PyTuple_CheckExact(__pyx_t_6) && likely(PyTuple_GET_SIZE(__pyx_t_6) == 2)) { - PyObject* tuple = __pyx_t_6; - __pyx_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_2); - __pyx_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(__pyx_v_k); - __pyx_v_k = __pyx_2; - __pyx_2 = 0; - __Pyx_DECREF(__pyx_v_v); - __pyx_v_v = __pyx_3; - __pyx_3 = 0; - } else { - __pyx_1 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_2 = __Pyx_UnpackItem(__pyx_1, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_2); - __pyx_3 = __Pyx_UnpackItem(__pyx_1, 1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_3); - if (__Pyx_EndUnpack(__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - __Pyx_DECREF(__pyx_v_k); - __pyx_v_k = __pyx_2; - __pyx_2 = 0; - __Pyx_DECREF(__pyx_v_v); - __pyx_v_v = __pyx_3; - __pyx_3 = 0; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":135 - * msgpack_pack_map(&self.pk, len(o)) - * for k,v in o.iteritems(): - * self.pack(k) # <<<<<<<<<<<<<< - * self.pack(v) - * elif isinstance(o, tuple) or isinstance(o, list): - */ - __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_INCREF(__pyx_v_k); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k); - __Pyx_GIVEREF(__pyx_v_k); - __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":136 - * for k,v in o.iteritems(): - * self.pack(k) - * self.pack(v) # <<<<<<<<<<<<<< - * elif isinstance(o, tuple) or isinstance(o, list): - * msgpack_pack_array(&self.pk, len(o)) - */ - __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_INCREF(__pyx_v_v); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); - __Pyx_GIVEREF(__pyx_v_v); - __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":137 - * self.pack(k) - * self.pack(v) - * elif isinstance(o, tuple) or isinstance(o, list): # <<<<<<<<<<<<<< - * msgpack_pack_array(&self.pk, len(o)) - * for v in o: - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyTuple_Type))); - if (!__pyx_t_1) { - __pyx_t_9 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyList_Type))); - __pyx_t_10 = __pyx_t_9; - } else { - __pyx_t_10 = __pyx_t_1; - } - if (__pyx_t_10) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":138 - * self.pack(v) - * elif isinstance(o, tuple) or isinstance(o, list): - * msgpack_pack_array(&self.pk, len(o)) # <<<<<<<<<<<<<< - * for v in o: - * self.pack(v) - */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_array((&__pyx_v_self->pk), __pyx_t_5); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":139 - * elif isinstance(o, tuple) or isinstance(o, list): - * msgpack_pack_array(&self.pk, len(o)) - * for v in o: # <<<<<<<<<<<<<< - * self.pack(v) - * else: - */ - if (PyList_CheckExact(__pyx_v_o) || PyTuple_CheckExact(__pyx_v_o)) { - __pyx_t_5 = 0; __pyx_t_7 = __pyx_v_o; __Pyx_INCREF(__pyx_t_7); - } else { - __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - } - for (;;) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; - } else if (likely(PyTuple_CheckExact(__pyx_t_7))) { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; - } else { - __pyx_t_6 = PyIter_Next(__pyx_t_7); - if (!__pyx_t_6) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - break; - } - __Pyx_GOTREF(__pyx_t_6); - } - __Pyx_DECREF(__pyx_v_v); - __pyx_v_v = __pyx_t_6; - __pyx_t_6 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":140 - * msgpack_pack_array(&self.pk, len(o)) - * for v in o: - * self.pack(v) # <<<<<<<<<<<<<< - * else: - * # TODO: Serialize with defalt() like simplejson. - */ - __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_INCREF(__pyx_v_v); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); - __Pyx_GIVEREF(__pyx_v_v); - __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L3; - } - /*else*/ { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":143 - * else: - * # TODO: Serialize with defalt() like simplejson. - * raise TypeError, "can't serialize %r" % (o,) # <<<<<<<<<<<<<< - * - * def pack(self, obj, flush=True): - */ - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_7)); - __Pyx_INCREF(__pyx_v_o); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_o); - __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_8 = PyNumber_Remainder(__pyx_kp_4, ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_builtin_TypeError, __pyx_t_8, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_1); - __Pyx_XDECREF(__pyx_2); - __Pyx_XDECREF(__pyx_3); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_AddTraceback("msgpack.Packer.__pack"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_k); - __Pyx_DECREF(__pyx_v_v); - __Pyx_DECREF(__pyx_v_o); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":145 - * raise TypeError, "can't serialize %r" % (o,) - * - * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< - * self.__pack(obj) - * if flush: - */ - -static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_obj = 0; - PyObject *__pyx_v_flush = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_kp_obj,&__pyx_kp_flush,0}; - __Pyx_SetupRefcountContext("pack"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - values[1] = __pyx_k_1; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_obj); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 1) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_flush); - if (unlikely(value)) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_obj = values[0]; - __pyx_v_flush = values[1]; - } else { - __pyx_v_flush = __pyx_k_1; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: __pyx_v_flush = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: __pyx_v_obj = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("pack", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("msgpack.Packer.pack"); - return NULL; - __pyx_L4_argument_unpacking_done:; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":146 - * - * def pack(self, obj, flush=True): - * self.__pack(obj) # <<<<<<<<<<<<<< - * if flush: - * self.flush() - */ - __pyx_t_1 = ((struct __pyx_vtabstruct_7msgpack_Packer *)((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->__pyx_vtab)->__pack(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self), __pyx_v_obj); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":147 - * def pack(self, obj, flush=True): - * self.__pack(obj) - * if flush: # <<<<<<<<<<<<<< - * self.flush() - * - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_flush); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":148 - * self.__pack(obj) - * if flush: - * self.flush() # <<<<<<<<<<<<<< - * - * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L6; - } - __pyx_L6:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("msgpack.Packer.pack"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":150 - * self.flush() - * - * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): # <<<<<<<<<<<<<< - * if packer.length + l > packer.allocated: - * if packer.length > 0: - */ - -static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__pyx_v_packer, const char* __pyx_v_b, unsigned int __pyx_v_l) { - int __pyx_r; - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_SetupRefcountContext("_packer_write"); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":151 - * - * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): - * if packer.length + l > packer.allocated: # <<<<<<<<<<<<<< - * if packer.length > 0: - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - */ - __pyx_t_1 = ((__pyx_v_packer->length + __pyx_v_l) > __pyx_v_packer->allocated); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":152 - * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): - * if packer.length + l > packer.allocated: - * if packer.length > 0: # <<<<<<<<<<<<<< - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - * if l > 64: - */ - __pyx_t_1 = (__pyx_v_packer->length > 0); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":153 - * if packer.length + l > packer.allocated: - * if packer.length > 0: - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) # <<<<<<<<<<<<<< - * if l > 64: - * packer.strm.write(PyString_FromStringAndSize(b, l)) - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyString_FromStringAndSize(__pyx_v_packer->buff, __pyx_v_packer->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":154 - * if packer.length > 0: - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - * if l > 64: # <<<<<<<<<<<<<< - * packer.strm.write(PyString_FromStringAndSize(b, l)) - * packer.length = 0 - */ - __pyx_t_1 = (__pyx_v_l > 64); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":155 - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - * if l > 64: - * packer.strm.write(PyString_FromStringAndSize(b, l)) # <<<<<<<<<<<<<< - * packer.length = 0 - * else: - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyString_FromStringAndSize(__pyx_v_b, __pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":156 - * if l > 64: - * packer.strm.write(PyString_FromStringAndSize(b, l)) - * packer.length = 0 # <<<<<<<<<<<<<< - * else: - * memcpy(packer.buff, b, l) - */ - __pyx_v_packer->length = 0; - goto __pyx_L5; - } - /*else*/ { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":158 - * packer.length = 0 - * else: - * memcpy(packer.buff, b, l) # <<<<<<<<<<<<<< - * packer.length = l - * else: - */ - memcpy(__pyx_v_packer->buff, __pyx_v_b, __pyx_v_l); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":159 - * else: - * memcpy(packer.buff, b, l) - * packer.length = l # <<<<<<<<<<<<<< - * else: - * memcpy(packer.buff + packer.length, b, l) - */ - __pyx_v_packer->length = __pyx_v_l; - } - __pyx_L5:; - goto __pyx_L3; - } - /*else*/ { - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":161 - * packer.length = l - * else: - * memcpy(packer.buff + packer.length, b, l) # <<<<<<<<<<<<<< - * packer.length += l - * return 0 - */ - memcpy((__pyx_v_packer->buff + __pyx_v_packer->length), __pyx_v_b, __pyx_v_l); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":162 - * else: - * memcpy(packer.buff + packer.length, b, l) - * packer.length += l # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_v_packer->length += __pyx_v_l; - } - __pyx_L3:; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":163 - * memcpy(packer.buff + packer.length, b, l) - * packer.length += l - * return 0 # <<<<<<<<<<<<<< - * - * def pack(object o, object stream): - */ - __pyx_r = 0; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_WriteUnraisable("msgpack._packer_write"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":165 - * return 0 - * - * def pack(object o, object stream): # <<<<<<<<<<<<<< - * packer = Packer(stream) - * packer.pack(o) - */ - -static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_o = 0; - PyObject *__pyx_v_stream = 0; - PyObject *__pyx_v_packer; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_kp_o,&__pyx_kp_stream,0}; - __Pyx_SetupRefcountContext("pack"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_o); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_stream); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_o = values[0]; - __pyx_v_stream = values[1]; - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_o = PyTuple_GET_ITEM(__pyx_args, 0); - __pyx_v_stream = PyTuple_GET_ITEM(__pyx_args, 1); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("msgpack.pack"); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":166 - * - * def pack(object o, object stream): - * packer = Packer(stream) # <<<<<<<<<<<<<< - * packer.pack(o) - * packer.flush() - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_v_stream); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stream); - __Pyx_GIVEREF(__pyx_v_stream); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_packer); - __pyx_v_packer = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":167 - * def pack(object o, object stream): - * packer = Packer(stream) - * packer.pack(o) # <<<<<<<<<<<<<< - * packer.flush() - * - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_v_o); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); - __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":168 - * packer = Packer(stream) - * packer.pack(o) - * packer.flush() # <<<<<<<<<<<<<< - * - * def packs(object o): - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("msgpack.pack"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_packer); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":170 - * packer.flush() - * - * def packs(object o): # <<<<<<<<<<<<<< - * buf = StringIO() - * packer = Packer(buf) - */ - -static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v_o); /*proto*/ -static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v_o) { - PyObject *__pyx_v_buf; - PyObject *__pyx_v_packer; - PyObject *__pyx_r = NULL; - PyObject *__pyx_1 = 0; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_SetupRefcountContext("packs"); - __pyx_self = __pyx_self; - __pyx_v_buf = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":171 - * - * def packs(object o): - * buf = StringIO() # <<<<<<<<<<<<<< - * packer = Packer(buf) - * packer.pack(o) - */ - __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_StringIO); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - __Pyx_DECREF(__pyx_v_buf); - __pyx_v_buf = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":172 - * def packs(object o): - * buf = StringIO() - * packer = Packer(buf) # <<<<<<<<<<<<<< - * packer.pack(o) - * packer.flush() - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_v_buf); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_buf); - __Pyx_GIVEREF(__pyx_v_buf); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_packer); - __pyx_v_packer = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":173 - * buf = StringIO() - * packer = Packer(buf) - * packer.pack(o) # <<<<<<<<<<<<<< - * packer.flush() - * return buf.getvalue() - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_v_o); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); - __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":174 - * packer = Packer(buf) - * packer.pack(o) - * packer.flush() # <<<<<<<<<<<<<< - * return buf.getvalue() - * - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":175 - * packer.pack(o) - * packer.flush() - * return buf.getvalue() # <<<<<<<<<<<<<< - * - * cdef extern from "unpack.h": - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_getvalue); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_1); - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("msgpack.packs"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_buf); - __Pyx_DECREF(__pyx_v_packer); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":186 - * - * - * def unpacks(object packed_bytes): # <<<<<<<<<<<<<< - * """Unpack packed_bytes to object. Returns unpacked object.""" - * cdef const_char_ptr p = packed_bytes - */ - -static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx_v_packed_bytes); /*proto*/ -static char __pyx_doc_7msgpack_unpacks[] = "Unpack packed_bytes to object. Returns unpacked object."; -static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx_v_packed_bytes) { - const char* __pyx_v_p; - template_context __pyx_v_ctx; - size_t __pyx_v_off; - PyObject *__pyx_r = NULL; - const char* __pyx_t_1; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_SetupRefcountContext("unpacks"); - __pyx_self = __pyx_self; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":188 - * def unpacks(object packed_bytes): - * """Unpack packed_bytes to object. Returns unpacked object.""" - * cdef const_char_ptr p = packed_bytes # <<<<<<<<<<<<<< - * cdef template_context ctx - * cdef size_t off = 0 - */ - __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_packed_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_p = __pyx_t_1; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":190 - * cdef const_char_ptr p = packed_bytes - * cdef template_context ctx - * cdef size_t off = 0 # <<<<<<<<<<<<<< - * template_init(&ctx) - * template_execute(&ctx, p, len(packed_bytes), &off) - */ - __pyx_v_off = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":191 - * cdef template_context ctx - * cdef size_t off = 0 - * template_init(&ctx) # <<<<<<<<<<<<<< - * template_execute(&ctx, p, len(packed_bytes), &off) - * return template_data(&ctx) - */ - template_init((&__pyx_v_ctx)); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":192 - * cdef size_t off = 0 - * template_init(&ctx) - * template_execute(&ctx, p, len(packed_bytes), &off) # <<<<<<<<<<<<<< - * return template_data(&ctx) - * - */ - __pyx_t_2 = PyObject_Length(__pyx_v_packed_bytes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - template_execute((&__pyx_v_ctx), __pyx_v_p, __pyx_t_2, (&__pyx_v_off)); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":193 - * template_init(&ctx) - * template_execute(&ctx, p, len(packed_bytes), &off) - * return template_data(&ctx) # <<<<<<<<<<<<<< - * - * def unpack(object stream): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = template_data((&__pyx_v_ctx)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("msgpack.unpacks"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":195 - * return template_data(&ctx) - * - * def unpack(object stream): # <<<<<<<<<<<<<< - * """unpack from stream.""" - * packed = stream.read() - */ - -static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_v_stream); /*proto*/ -static char __pyx_doc_7msgpack_unpack[] = "unpack from stream."; -static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_v_stream) { - PyObject *__pyx_v_packed; - PyObject *__pyx_r = NULL; - PyObject *__pyx_1 = 0; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_SetupRefcountContext("unpack"); - __pyx_self = __pyx_self; - __pyx_v_packed = Py_None; __Pyx_INCREF(Py_None); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":197 - * def unpack(object stream): - * """unpack from stream.""" - * packed = stream.read() # <<<<<<<<<<<<<< - * return unpacks(packed) - * - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_packed); - __pyx_v_packed = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":198 - * """unpack from stream.""" - * packed = stream.read() - * return unpacks(packed) # <<<<<<<<<<<<<< - * - * cdef class Unpacker: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_INCREF(__pyx_v_packed); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_packed); - __Pyx_GIVEREF(__pyx_v_packed); - __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_1); - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("msgpack.unpack"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_packed); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} -static struct __pyx_vtabstruct_7msgpack_Packer __pyx_vtable_7msgpack_Packer; - -static PyObject *__pyx_tp_new_7msgpack_Packer(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_7msgpack_Packer *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_7msgpack_Packer *)o); - p->__pyx_vtab = __pyx_vtabptr_7msgpack_Packer; - p->strm = Py_None; Py_INCREF(Py_None); - return o; -} - -static void __pyx_tp_dealloc_7msgpack_Packer(PyObject *o) { - struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; - Py_XDECREF(p->strm); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_7msgpack_Packer(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; - if (p->strm) { - e = (*v)(p->strm, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_7msgpack_Packer(PyObject *o) { - struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; - PyObject* tmp; - tmp = ((PyObject*)p->strm); - p->strm = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static struct PyMethodDef __pyx_methods_7msgpack_Packer[] = { - {__Pyx_NAMESTR("__del__"), (PyCFunction)__pyx_pf_7msgpack_6Packer___del__, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("flush"), (PyCFunction)__pyx_pf_7msgpack_6Packer_flush, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_flush)}, - {__Pyx_NAMESTR("pack_list"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_list, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_list)}, - {__Pyx_NAMESTR("pack_dict"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_dict, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_dict)}, - {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Packer = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_Packer = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_Packer = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Packer = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_7msgpack_Packer = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("msgpack.Packer"), /*tp_name*/ - sizeof(struct __pyx_obj_7msgpack_Packer), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_7msgpack_Packer, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &__pyx_tp_as_number_Packer, /*tp_as_number*/ - &__pyx_tp_as_sequence_Packer, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Packer, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Packer, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - __Pyx_DOCSTR("Packer that pack data into strm.\n\n strm must have `write(bytes)` method.\n size specifies local buffer size.\n "), /*tp_doc*/ - __pyx_tp_traverse_7msgpack_Packer, /*tp_traverse*/ - __pyx_tp_clear_7msgpack_Packer, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_7msgpack_Packer, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - __pyx_pf_7msgpack_6Packer___init__, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_7msgpack_Packer, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ -}; - -static PyObject *__pyx_tp_new_7msgpack_Unpacker(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - return o; -} - -static void __pyx_tp_dealloc_7msgpack_Unpacker(PyObject *o) { - (*Py_TYPE(o)->tp_free)(o); -} - -static struct PyMethodDef __pyx_methods_7msgpack_Unpacker[] = { - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Unpacker = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else - 0, /*nb_long*/ - #endif - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_Unpacker = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_Unpacker = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Unpacker = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_7msgpack_Unpacker = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("msgpack.Unpacker"), /*tp_name*/ - sizeof(struct __pyx_obj_7msgpack_Unpacker), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_7msgpack_Unpacker, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &__pyx_tp_as_number_Unpacker, /*tp_as_number*/ - &__pyx_tp_as_sequence_Unpacker, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Unpacker, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Unpacker, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ - __Pyx_DOCSTR("Do nothing. This function is for symmetric to Packer"), /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_7msgpack_Unpacker, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_7msgpack_Unpacker, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ -}; - -static struct PyMethodDef __pyx_methods[] = { - {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_pack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("packs"), (PyCFunction)__pyx_pf_7msgpack_packs, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("unpacks"), (PyCFunction)__pyx_pf_7msgpack_unpacks, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_unpacks)}, - {__Pyx_NAMESTR("unpack"), (PyCFunction)__pyx_pf_7msgpack_unpack, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_unpack)}, - {0, 0, 0, 0} -}; - -static void __pyx_init_filenames(void); /*proto*/ - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - __Pyx_NAMESTR("msgpack"), - 0, /* m_doc */ - -1, /* m_size */ - __pyx_methods /* m_methods */, - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1}, - {&__pyx_kp___init__, __pyx_k___init__, sizeof(__pyx_k___init__), 1, 1, 1}, - {&__pyx_kp___del__, __pyx_k___del__, sizeof(__pyx_k___del__), 1, 1, 1}, - {&__pyx_kp_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 1, 1, 1}, - {&__pyx_kp_pack_list, __pyx_k_pack_list, sizeof(__pyx_k_pack_list), 1, 1, 1}, - {&__pyx_kp_pack_dict, __pyx_k_pack_dict, sizeof(__pyx_k_pack_dict), 1, 1, 1}, - {&__pyx_kp_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 1, 1, 1}, - {&__pyx_kp_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 1, 1, 1}, - {&__pyx_kp_strm, __pyx_k_strm, sizeof(__pyx_k_strm), 1, 1, 1}, - {&__pyx_kp_size, __pyx_k_size, sizeof(__pyx_k_size), 1, 1, 1}, - {&__pyx_kp_len, __pyx_k_len, sizeof(__pyx_k_len), 1, 1, 1}, - {&__pyx_kp_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 1, 1, 1}, - {&__pyx_kp_o, __pyx_k_o, sizeof(__pyx_k_o), 1, 1, 1}, - {&__pyx_kp_stream, __pyx_k_stream, sizeof(__pyx_k_stream), 1, 1, 1}, - {&__pyx_kp_packed_bytes, __pyx_k_packed_bytes, sizeof(__pyx_k_packed_bytes), 1, 1, 1}, - {&__pyx_kp_cStringIO, __pyx_k_cStringIO, sizeof(__pyx_k_cStringIO), 1, 1, 1}, - {&__pyx_kp_StringIO, __pyx_k_StringIO, sizeof(__pyx_k_StringIO), 1, 1, 1}, - {&__pyx_kp_staticmethod, __pyx_k_staticmethod, sizeof(__pyx_k_staticmethod), 1, 1, 1}, - {&__pyx_kp_unpacks, __pyx_k_unpacks, sizeof(__pyx_k_unpacks), 1, 1, 1}, - {&__pyx_kp_write, __pyx_k_write, sizeof(__pyx_k_write), 1, 1, 1}, - {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 1, 0}, - {&__pyx_kp_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 1, 1, 1}, - {&__pyx_kp_iteritems, __pyx_k_iteritems, sizeof(__pyx_k_iteritems), 1, 1, 1}, - {&__pyx_kp_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 1, 1, 1}, - {&__pyx_kp_getvalue, __pyx_k_getvalue, sizeof(__pyx_k_getvalue), 1, 1, 1}, - {&__pyx_kp_read, __pyx_k_read, sizeof(__pyx_k_read), 1, 1, 1}, - {&__pyx_kp_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 0}, - {&__pyx_kp_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 0}, - {0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_staticmethod = __Pyx_GetName(__pyx_b, __pyx_kp_staticmethod); if (!__pyx_builtin_staticmethod) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_kp_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - return 0; - __pyx_L1_error:; - return -1; -} - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initmsgpack(void); /*proto*/ -PyMODINIT_FUNC initmsgpack(void) -#else -PyMODINIT_FUNC PyInit_msgpack(void); /*proto*/ -PyMODINIT_FUNC PyInit_msgpack(void) -#endif -{ - PyObject *__pyx_1 = 0; - PyObject *__pyx_2 = 0; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - #ifdef CYTHON_REFNANNY - void* __pyx_refchk = NULL; - __Pyx_Refnanny = __Pyx_ImportRefcountAPI("refnanny"); - if (!__Pyx_Refnanny) { - PyErr_Clear(); - __Pyx_Refnanny = __Pyx_ImportRefcountAPI("Cython.Runtime.refnanny"); - if (!__Pyx_Refnanny) - Py_FatalError("failed to import refnanny module"); - } - __pyx_refchk = __Pyx_Refnanny->NewContext("PyMODINIT_FUNC PyInit_msgpack(void)", __LINE__, __FILE__); - #endif - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Library function declarations ---*/ - __pyx_init_filenames(); - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Module creation code ---*/ - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("msgpack"), __pyx_methods, 0, 0, PYTHON_API_VERSION); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - #if PY_MAJOR_VERSION < 3 - Py_INCREF(__pyx_m); - #endif - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); - if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - if (__pyx_module_is_main_msgpack) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } - /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_skip_dispatch = 0; - /*--- Global init code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - __pyx_vtabptr_7msgpack_Packer = &__pyx_vtable_7msgpack_Packer; - #if PY_MAJOR_VERSION >= 3 - __pyx_vtable_7msgpack_Packer.__pack = (PyObject *(*)(struct __pyx_obj_7msgpack_Packer *, PyObject *))__pyx_f_7msgpack_6Packer___pack; - #else - *(void(**)(void))&__pyx_vtable_7msgpack_Packer.__pack = (void(*)(void))__pyx_f_7msgpack_6Packer___pack; - #endif - if (PyType_Ready(&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_7msgpack_Packer.tp_dict, __pyx_vtabptr_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Packer", (PyObject *)&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_7msgpack_Packer = &__pyx_type_7msgpack_Packer; - if (PyType_Ready(&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Unpacker", (PyObject *)&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_7msgpack_Unpacker = &__pyx_type_7msgpack_Unpacker; - /*--- Type import code ---*/ - /*--- Function import code ---*/ - /*--- Execution code ---*/ - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":3 - * # coding: utf-8 - * - * from cStringIO import StringIO # <<<<<<<<<<<<<< - * - * cdef extern from "Python.h": - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_kp_StringIO); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_StringIO); - __Pyx_GIVEREF(__pyx_kp_StringIO); - __pyx_1 = __Pyx_Import(__pyx_kp_cStringIO, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_StringIO); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_2); - if (PyObject_SetAttr(__pyx_m, __pyx_kp_StringIO, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_2); __pyx_2 = 0; - __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":37 - * - * - * cdef int BUFF_SIZE=2*1024 # <<<<<<<<<<<<<< - * - * cdef class Packer: - */ - __pyx_v_7msgpack_BUFF_SIZE = 2048; - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":145 - * raise TypeError, "can't serialize %r" % (o,) - * - * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< - * self.__pack(obj) - * if flush: - */ - __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_k_1 = __pyx_t_1; - __pyx_t_1 = 0; - __Pyx_GIVEREF(__pyx_k_1); - - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":202 - * cdef class Unpacker: - * """Do nothing. This function is for symmetric to Packer""" - * unpack = staticmethod(unpacks) # <<<<<<<<<<<<<< - */ - __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_1); - __Pyx_GIVEREF(__pyx_1); - __pyx_1 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_staticmethod, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_7msgpack_Unpacker->tp_dict, __pyx_kp_unpack, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyType_Modified(__pyx_ptype_7msgpack_Unpacker); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_1); - __Pyx_XDECREF(__pyx_2); - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("msgpack"); - Py_DECREF(__pyx_m); __pyx_m = 0; - __pyx_L0:; - __Pyx_FinishRefcountContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else - return __pyx_m; - #endif -} - -static const char *__pyx_filenames[] = { - "msgpack.pyx", -}; - -/* Runtime support code */ - -static void __pyx_init_filenames(void) { - __pyx_f = __pyx_filenames; -} - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, - PyObject* kw_name) -{ - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION >= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AS_STRING(kw_name)); - #endif -} - -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *number, *more_or_less; - - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - number = (num_expected == 1) ? "" : "s"; - PyErr_Format(PyExc_TypeError, - #if PY_VERSION_HEX < 0x02050000 - "%s() takes %s %d positional argument%s (%d given)", - #else - "%s() takes %s %zd positional argument%s (%zd given)", - #endif - func_name, more_or_less, num_expected, number, num_found); -} - -static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - } else { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { - #else - if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) { - #endif - goto invalid_keyword_type; - } else { - for (name = first_kw_arg; *name; name++) { - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) break; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) break; - #endif - } - if (*name) { - values[name-argnames] = value; - } else { - /* unexpected keyword found */ - for (name=argnames; name != first_kw_arg; name++) { - if (**name == key) goto arg_passed_twice; - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) goto arg_passed_twice; - #endif - } - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; - } else { - goto invalid_keyword; - } - } - } - } - } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, **name); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif -bad: - return -1; -} - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) { - PyObject *__import__ = 0; - PyObject *empty_list = 0; - PyObject *module = 0; - PyObject *global_dict = 0; - PyObject *empty_dict = 0; - PyObject *list; - __import__ = __Pyx_GetAttrString(__pyx_b, "__import__"); - if (!__import__) - goto bad; - if (from_list) - list = from_list; - else { - empty_list = PyList_New(0); - if (!empty_list) - goto bad; - list = empty_list; - } - global_dict = PyModule_GetDict(__pyx_m); - if (!global_dict) - goto bad; - empty_dict = PyDict_New(); - if (!empty_dict) - goto bad; - module = PyObject_CallFunctionObjArgs(__import__, - name, global_dict, empty_dict, list, NULL); -bad: - Py_XDECREF(empty_list); - Py_XDECREF(__import__); - Py_XDECREF(empty_dict); - return module; -} - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) - PyErr_SetObject(PyExc_NameError, name); - return result; -} - -static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { - PyErr_Format(PyExc_ValueError, - #if PY_VERSION_HEX < 0x02050000 - "need more than %d value%s to unpack", (int)index, - #else - "need more than %zd value%s to unpack", index, - #endif - (index == 1) ? "" : "s"); -} - -static INLINE void __Pyx_RaiseTooManyValuesError(void) { - PyErr_SetString(PyExc_ValueError, "too many values to unpack"); -} - -static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) { - PyObject *item; - if (!(item = PyIter_Next(iter))) { - if (!PyErr_Occurred()) { - __Pyx_RaiseNeedMoreValuesError(index); - } - } - return item; -} - -static int __Pyx_EndUnpack(PyObject *iter) { - PyObject *item; - if ((item = PyIter_Next(iter))) { - Py_DECREF(item); - __Pyx_RaiseTooManyValuesError(); - return -1; - } - else if (!PyErr_Occurred()) - return 0; - else - return -1; -} - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { - Py_XINCREF(type); - Py_XINCREF(value); - Py_XINCREF(tb); - /* First, check the traceback argument, replacing None with NULL. */ - if (tb == Py_None) { - Py_DECREF(tb); - tb = 0; - } - else if (tb != NULL && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - /* Next, replace a missing value with None */ - if (value == NULL) { - value = Py_None; - Py_INCREF(value); - } - #if PY_VERSION_HEX < 0x02050000 - if (!PyClass_Check(type)) - #else - if (!PyType_Check(type)) - #endif - { - /* Raising an instance. The value should be a dummy. */ - if (value != Py_None) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - /* Normalize to raise , */ - Py_DECREF(value); - value = type; - #if PY_VERSION_HEX < 0x02050000 - if (PyInstance_Check(type)) { - type = (PyObject*) ((PyInstanceObject*)type)->in_class; - Py_INCREF(type); - } - else { - type = 0; - PyErr_SetString(PyExc_TypeError, - "raise: exception must be an old-style class or instance"); - goto raise_error; - } - #else - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - #endif - } - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} - -static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - -#if PY_MAJOR_VERSION >= 3 - /* Note: this is a temporary work-around to prevent crashes in Python 3.0 */ - if ((tstate->exc_type != NULL) & (tstate->exc_type != Py_None)) { - tmp_type = tstate->exc_type; - tmp_value = tstate->exc_value; - tmp_tb = tstate->exc_traceback; - PyErr_NormalizeException(&type, &value, &tb); - PyErr_NormalizeException(&tmp_type, &tmp_value, &tmp_tb); - tstate->exc_type = 0; - tstate->exc_value = 0; - tstate->exc_traceback = 0; - PyException_SetContext(value, tmp_value); - Py_DECREF(tmp_type); - Py_XDECREF(tmp_tb); - } -#endif - - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -} - -static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -} - - -static INLINE int __Pyx_StrEq(const char *s1, const char *s2) { - while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } - return *s1 == *s2; -} - -static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (unsigned char)-1; - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned char"); - return (unsigned char)-1; - } - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to unsigned char"); - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (unsigned short)-1; - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned short"); - return (unsigned short)-1; - } - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to unsigned short"); - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (unsigned int)-1; - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned int"); - return (unsigned int)-1; - } - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to unsigned int"); - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (char)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to char"); - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (short)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to short"); - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (int)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to int"); - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (signed char)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to signed char"); - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (signed short)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to signed short"); - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (signed int)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to signed int"); - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return PyLong_AsUnsignedLong(x); - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return PyLong_AsUnsignedLongLong(x); - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE long __Pyx_PyInt_AsLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - return (long)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - return PyLong_AsLong(x); - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - return PyLong_AsLongLong(x); - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - return (signed long)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - return PyLong_AsLong(x); - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - return PyLong_AsLongLong(x); - } else { - signed PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static void __Pyx_WriteUnraisable(const char *name) { - PyObject *old_exc, *old_val, *old_tb; - PyObject *ctx; - __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); - #if PY_MAJOR_VERSION < 3 - ctx = PyString_FromString(name); - #else - ctx = PyUnicode_FromString(name); - #endif - __Pyx_ErrRestore(old_exc, old_val, old_tb); - if (!ctx) { - PyErr_WriteUnraisable(Py_None); - } else { - PyErr_WriteUnraisable(ctx); - Py_DECREF(ctx); - } -} - -static int __Pyx_SetVtable(PyObject *dict, void *vtable) { - PyObject *pycobj = 0; - int result; - - pycobj = PyCObject_FromVoidPtr(vtable, 0); - if (!pycobj) - goto bad; - if (PyDict_SetItemString(dict, "__pyx_vtable__", pycobj) < 0) - goto bad; - result = 0; - goto done; - -bad: - result = -1; -done: - Py_XDECREF(pycobj); - return result; -} - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" - -static void __Pyx_AddTraceback(const char *funcname) { - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - PyObject *py_globals = 0; - PyObject *empty_string = 0; - PyCodeObject *py_code = 0; - PyFrameObject *py_frame = 0; - - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(__pyx_filename); - #else - py_srcfile = PyUnicode_FromString(__pyx_filename); - #endif - if (!py_srcfile) goto bad; - if (__pyx_clineno) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - #if PY_MAJOR_VERSION < 3 - empty_string = PyString_FromStringAndSize("", 0); - #else - empty_string = PyBytes_FromStringAndSize("", 0); - #endif - if (!empty_string) goto bad; - py_code = PyCode_New( - 0, /*int argcount,*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*int kwonlyargcount,*/ - #endif - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - empty_string, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - __pyx_lineno, /*int firstlineno,*/ - empty_string /*PyObject *lnotab*/ - ); - if (!py_code) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = __pyx_lineno; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - Py_XDECREF(empty_string); - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode && (!t->is_identifier)) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_identifier || (t->is_unicode && t->intern)) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->is_unicode) { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} - -/* Type Conversion Functions */ - -static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - if (x == Py_True) return 1; - else if ((x == Py_False) | (x == Py_None)) return 0; - else return PyObject_IsTrue(x); -} - -static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { - PyNumberMethods *m; - const char *name = NULL; - PyObject *res = NULL; -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(x) || PyLong_Check(x)) -#else - if (PyLong_Check(x)) -#endif - return Py_INCREF(x), x; - m = Py_TYPE(x)->tp_as_number; -#if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } - else if (m && m->nb_long) { - name = "long"; - res = PyNumber_Long(x); - } -#else - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Long(x); - } -#endif - if (res) { -#if PY_VERSION_HEX < 0x03000000 - if (!PyInt_Check(res) && !PyLong_Check(res)) { -#else - if (!PyLong_Check(res)) { -#endif - PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; - } - } - else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "an integer is required"); - } - return res; -} - -static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { - Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); - if (!x) return -1; - ival = PyInt_AsSsize_t(x); - Py_DECREF(x); - return ival; -} - -static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif -} - -static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { - return (size_t)-1; - } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} - - diff --git a/python/msgpack.pyx b/python/msgpack.pyx deleted file mode 100644 index f24f403..0000000 --- a/python/msgpack.pyx +++ /dev/null @@ -1,202 +0,0 @@ -# coding: utf-8 - -from cStringIO import StringIO - -cdef extern from "Python.h": - ctypedef char* const_char_ptr "const char*" - ctypedef struct PyObject - cdef object PyString_FromStringAndSize(const_char_ptr b, Py_ssize_t len) - -cdef extern from "stdlib.h": - void* malloc(int) - void free(void*) - -cdef extern from "string.h": - int memcpy(char*dst, char*src, unsigned int size) - -cdef extern from "pack.h": - ctypedef int (*msgpack_packer_write)(void* data, const_char_ptr buf, unsigned int len) - - struct msgpack_packer: - void *data - msgpack_packer_write callback - - void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) - void msgpack_pack_int(msgpack_packer* pk, int d) - void msgpack_pack_nil(msgpack_packer* pk) - void msgpack_pack_true(msgpack_packer* pk) - void msgpack_pack_false(msgpack_packer* pk) - void msgpack_pack_long_long(msgpack_packer* pk, long long d) - void msgpack_pack_double(msgpack_packer* pk, double d) - void msgpack_pack_array(msgpack_packer* pk, size_t l) - void msgpack_pack_map(msgpack_packer* pk, size_t l) - void msgpack_pack_raw(msgpack_packer* pk, size_t l) - void msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) - - -cdef int BUFF_SIZE=2*1024 - -cdef class Packer: - """Packer that pack data into strm. - - strm must have `write(bytes)` method. - size specifies local buffer size. - """ - cdef char* buff - cdef unsigned int length - cdef unsigned int allocated - cdef msgpack_packer pk - cdef object strm - - def __init__(self, strm, int size=0): - if size <= 0: - size = BUFF_SIZE - - self.strm = strm - self.buff = malloc(size) - self.allocated = size - self.length = 0 - - msgpack_packer_init(&self.pk, self, _packer_write) - - def __del__(self): - free(self.buff); - - def flush(self): - """Flash local buffer and output stream if it has 'flush()' method.""" - if self.length > 0: - self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) - self.length = 0 - if hasattr(self.strm, 'flush'): - self.strm.flush() - - def pack_list(self, len): - """Start packing sequential objects. - - Example: - - packer.pack_list(2) - packer.pack('foo') - packer.pack('bar') - - This code is same as below code: - - packer.pack(['foo', 'bar']) - """ - msgpack_pack_array(&self.pk, len) - - def pack_dict(self, len): - """Start packing key-value objects. - - Example: - - packer.pack_dict(1) - packer.pack('foo') - packer.pack('bar') - - This code is same as below code: - - packer.pack({'foo', 'bar'}) - """ - msgpack_pack_map(&self.pk, len) - - cdef __pack(self, object o): - cdef long long intval - cdef double fval - cdef char* rawval - - if o is None: - msgpack_pack_nil(&self.pk) - elif o is True: - msgpack_pack_true(&self.pk) - elif o is False: - msgpack_pack_false(&self.pk) - elif isinstance(o, long): - intval = o - msgpack_pack_long_long(&self.pk, intval) - elif isinstance(o, int): - intval = o - msgpack_pack_long_long(&self.pk, intval) - elif isinstance(o, float): - fval = 9 - msgpack_pack_double(&self.pk, fval) - elif isinstance(o, str): - rawval = o - msgpack_pack_raw(&self.pk, len(o)) - msgpack_pack_raw_body(&self.pk, rawval, len(o)) - elif isinstance(o, unicode): - o = o.encode('utf-8') - rawval = o - msgpack_pack_raw(&self.pk, len(o)) - msgpack_pack_raw_body(&self.pk, rawval, len(o)) - elif isinstance(o, dict): - msgpack_pack_map(&self.pk, len(o)) - for k,v in o.iteritems(): - self.pack(k) - self.pack(v) - elif isinstance(o, tuple) or isinstance(o, list): - msgpack_pack_array(&self.pk, len(o)) - for v in o: - self.pack(v) - else: - # TODO: Serialize with defalt() like simplejson. - 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): - if packer.length + l > packer.allocated: - if packer.length > 0: - packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - if l > 64: - packer.strm.write(PyString_FromStringAndSize(b, l)) - packer.length = 0 - else: - memcpy(packer.buff, b, l) - packer.length = l - else: - memcpy(packer.buff + packer.length, b, l) - packer.length += l - return 0 - -def pack(object o, object stream): - packer = Packer(stream) - packer.pack(o) - packer.flush() - -def packs(object o): - buf = StringIO() - packer = Packer(buf) - packer.pack(o) - packer.flush() - return buf.getvalue() - -cdef extern from "unpack.h": - ctypedef struct template_context: - pass - int template_execute(template_context* ctx, const_char_ptr data, - size_t len, size_t* off) - void template_init(template_context* ctx) - object template_data(template_context* ctx) - - -def unpacks(object packed_bytes): - """Unpack packed_bytes to object. Returns unpacked object.""" - cdef const_char_ptr p = packed_bytes - cdef template_context ctx - cdef size_t off = 0 - template_init(&ctx) - template_execute(&ctx, p, len(packed_bytes), &off) - return template_data(&ctx) - -def unpack(object stream): - """unpack from stream.""" - packed = stream.read() - return unpacks(packed) - -cdef class Unpacker: - """Do nothing. This function is for symmetric to Packer""" - unpack = staticmethod(unpacks) diff --git a/python/msgpack/__init__.py b/python/msgpack/__init__.py new file mode 100644 index 0000000..797b29c --- /dev/null +++ b/python/msgpack/__init__.py @@ -0,0 +1,3 @@ +# coding: utf-8 +from _msgpack import * + diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx new file mode 100644 index 0000000..f24f403 --- /dev/null +++ b/python/msgpack/_msgpack.pyx @@ -0,0 +1,202 @@ +# coding: utf-8 + +from cStringIO import StringIO + +cdef extern from "Python.h": + ctypedef char* const_char_ptr "const char*" + ctypedef struct PyObject + cdef object PyString_FromStringAndSize(const_char_ptr b, Py_ssize_t len) + +cdef extern from "stdlib.h": + void* malloc(int) + void free(void*) + +cdef extern from "string.h": + int memcpy(char*dst, char*src, unsigned int size) + +cdef extern from "pack.h": + ctypedef int (*msgpack_packer_write)(void* data, const_char_ptr buf, unsigned int len) + + struct msgpack_packer: + void *data + msgpack_packer_write callback + + void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) + void msgpack_pack_int(msgpack_packer* pk, int d) + void msgpack_pack_nil(msgpack_packer* pk) + void msgpack_pack_true(msgpack_packer* pk) + void msgpack_pack_false(msgpack_packer* pk) + void msgpack_pack_long_long(msgpack_packer* pk, long long d) + void msgpack_pack_double(msgpack_packer* pk, double d) + void msgpack_pack_array(msgpack_packer* pk, size_t l) + void msgpack_pack_map(msgpack_packer* pk, size_t l) + void msgpack_pack_raw(msgpack_packer* pk, size_t l) + void msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) + + +cdef int BUFF_SIZE=2*1024 + +cdef class Packer: + """Packer that pack data into strm. + + strm must have `write(bytes)` method. + size specifies local buffer size. + """ + cdef char* buff + cdef unsigned int length + cdef unsigned int allocated + cdef msgpack_packer pk + cdef object strm + + def __init__(self, strm, int size=0): + if size <= 0: + size = BUFF_SIZE + + self.strm = strm + self.buff = malloc(size) + self.allocated = size + self.length = 0 + + msgpack_packer_init(&self.pk, self, _packer_write) + + def __del__(self): + free(self.buff); + + def flush(self): + """Flash local buffer and output stream if it has 'flush()' method.""" + if self.length > 0: + self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) + self.length = 0 + if hasattr(self.strm, 'flush'): + self.strm.flush() + + def pack_list(self, len): + """Start packing sequential objects. + + Example: + + packer.pack_list(2) + packer.pack('foo') + packer.pack('bar') + + This code is same as below code: + + packer.pack(['foo', 'bar']) + """ + msgpack_pack_array(&self.pk, len) + + def pack_dict(self, len): + """Start packing key-value objects. + + Example: + + packer.pack_dict(1) + packer.pack('foo') + packer.pack('bar') + + This code is same as below code: + + packer.pack({'foo', 'bar'}) + """ + msgpack_pack_map(&self.pk, len) + + cdef __pack(self, object o): + cdef long long intval + cdef double fval + cdef char* rawval + + if o is None: + msgpack_pack_nil(&self.pk) + elif o is True: + msgpack_pack_true(&self.pk) + elif o is False: + msgpack_pack_false(&self.pk) + elif isinstance(o, long): + intval = o + msgpack_pack_long_long(&self.pk, intval) + elif isinstance(o, int): + intval = o + msgpack_pack_long_long(&self.pk, intval) + elif isinstance(o, float): + fval = 9 + msgpack_pack_double(&self.pk, fval) + elif isinstance(o, str): + rawval = o + msgpack_pack_raw(&self.pk, len(o)) + msgpack_pack_raw_body(&self.pk, rawval, len(o)) + elif isinstance(o, unicode): + o = o.encode('utf-8') + rawval = o + msgpack_pack_raw(&self.pk, len(o)) + msgpack_pack_raw_body(&self.pk, rawval, len(o)) + elif isinstance(o, dict): + msgpack_pack_map(&self.pk, len(o)) + for k,v in o.iteritems(): + self.pack(k) + self.pack(v) + elif isinstance(o, tuple) or isinstance(o, list): + msgpack_pack_array(&self.pk, len(o)) + for v in o: + self.pack(v) + else: + # TODO: Serialize with defalt() like simplejson. + 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): + if packer.length + l > packer.allocated: + if packer.length > 0: + packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + if l > 64: + packer.strm.write(PyString_FromStringAndSize(b, l)) + packer.length = 0 + else: + memcpy(packer.buff, b, l) + packer.length = l + else: + memcpy(packer.buff + packer.length, b, l) + packer.length += l + return 0 + +def pack(object o, object stream): + packer = Packer(stream) + packer.pack(o) + packer.flush() + +def packs(object o): + buf = StringIO() + packer = Packer(buf) + packer.pack(o) + packer.flush() + return buf.getvalue() + +cdef extern from "unpack.h": + ctypedef struct template_context: + pass + int template_execute(template_context* ctx, const_char_ptr data, + size_t len, size_t* off) + void template_init(template_context* ctx) + object template_data(template_context* ctx) + + +def unpacks(object packed_bytes): + """Unpack packed_bytes to object. Returns unpacked object.""" + cdef const_char_ptr p = packed_bytes + cdef template_context ctx + cdef size_t off = 0 + template_init(&ctx) + template_execute(&ctx, p, len(packed_bytes), &off) + return template_data(&ctx) + +def unpack(object stream): + """unpack from stream.""" + packed = stream.read() + return unpacks(packed) + +cdef class Unpacker: + """Do nothing. This function is for symmetric to Packer""" + unpack = staticmethod(unpacks) diff --git a/python/msgpack/pack.h b/python/msgpack/pack.h new file mode 100644 index 0000000..f3935fb --- /dev/null +++ b/python/msgpack/pack.h @@ -0,0 +1,121 @@ +/* + * MessagePack for Python packing routine + * + * Copyright (C) 2009 Naoki INADA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if _MSC_VER +typedef signed char uint8_t; +typedef unsigned char uint8_t; +typedef short int16_t; +typedef unsigned short uint16_t; +typedef int int32_t; +typedef unsigned int uint32_t; +typedef long long int64_t; +typedef unsigned long long uint64_t; +#else +#include +#endif + +#include +#include +#include "msgpack/pack_define.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef int (*msgpack_packer_write)(void* data, const char* buf, unsigned int len); + +typedef struct msgpack_packer { + void* data; + msgpack_packer_write callback; +} msgpack_packer; + +static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback); + +static inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback); +static inline void msgpack_packer_free(msgpack_packer* pk); + +static inline int msgpack_pack_short(msgpack_packer* pk, short d); +static inline int msgpack_pack_int(msgpack_packer* pk, int d); +static inline int msgpack_pack_long(msgpack_packer* pk, long d); +static inline int msgpack_pack_long_long(msgpack_packer* pk, long long d); +static inline int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d); +static inline int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d); +static inline int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d); +static inline int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d); + +static inline int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d); +static inline int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d); +static inline int msgpack_pack_uint32(msgpack_packer* pk, uint32_t d); +static inline int msgpack_pack_uint64(msgpack_packer* pk, uint64_t d); +static inline int msgpack_pack_int8(msgpack_packer* pk, int8_t d); +static inline int msgpack_pack_int16(msgpack_packer* pk, int16_t d); +static inline int msgpack_pack_int32(msgpack_packer* pk, int32_t d); +static inline int msgpack_pack_int64(msgpack_packer* pk, int64_t d); + +static inline int msgpack_pack_float(msgpack_packer* pk, float d); +static inline int msgpack_pack_double(msgpack_packer* pk, double d); + +static inline int msgpack_pack_nil(msgpack_packer* pk); +static inline int msgpack_pack_true(msgpack_packer* pk); +static inline int msgpack_pack_false(msgpack_packer* pk); + +static inline int msgpack_pack_array(msgpack_packer* pk, unsigned int n); + +static inline int msgpack_pack_map(msgpack_packer* pk, unsigned int n); + +static inline int msgpack_pack_raw(msgpack_packer* pk, size_t l); +static inline int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l); + + + +#define msgpack_pack_inline_func(name) \ + static inline int msgpack_pack ## name + +#define msgpack_pack_inline_func_cint(name) \ + static inline int msgpack_pack ## name + +#define msgpack_pack_user msgpack_packer* + +#define msgpack_pack_append_buffer(user, buf, len) \ + return (*(user)->callback)((user)->data, (const char*)buf, len) + +#include "msgpack/pack_template.h" + +static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) +{ + pk->data = data; + pk->callback = callback; +} + +static inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback) +{ + msgpack_packer* pk = (msgpack_packer*)calloc(1, sizeof(msgpack_packer)); + if(!pk) { return NULL; } + msgpack_packer_init(pk, data, callback); + return pk; +} + +static inline void msgpack_packer_free(msgpack_packer* pk) +{ + free(pk); +} + + +#ifdef __cplusplus +} +#endif diff --git a/python/msgpack/unpack.h b/python/msgpack/unpack.h new file mode 100644 index 0000000..e51557f --- /dev/null +++ b/python/msgpack/unpack.h @@ -0,0 +1,122 @@ +/* + * MessagePack for Python unpacking routine + * + * Copyright (C) 2009 Naoki INADA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "msgpack/unpack_define.h" + +typedef struct { + int reserved; +} unpack_user; + + +#define msgpack_unpack_struct(name) \ + struct template ## name + +#define msgpack_unpack_func(ret, name) \ + static inline ret template ## name + +#define msgpack_unpack_callback(name) \ + template_callback ## name + +#define msgpack_unpack_object PyObject* + +#define msgpack_unpack_user unpack_user + + +struct template_context; +typedef struct template_context template_context; + +static inline msgpack_unpack_object template_callback_root(unpack_user* u) +{ return NULL; } + +static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong((long)d); return 0; } + +static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong((long)d); return 0; } + +static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_unpack_object* o) +{ + if (d >= 0x80000000UL) { + *o = PyLong_FromUnsignedLongLong((unsigned long long)d); + } else { + *o = PyInt_FromLong((long)d); + } + return 0; +} + +static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o) +{ *o = PyLong_FromUnsignedLongLong(d); return 0; } + +static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong(d); return 0; } + +static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong(d); return 0; } + +static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_unpack_object* o) +{ *o = PyInt_FromLong(d); return 0; } + +static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o) +{ *o = PyLong_FromLongLong(d); return 0; } + +static inline int template_callback_float(unpack_user* u, float d, msgpack_unpack_object* o) +{ *o = PyFloat_FromDouble((double)d); return 0; } + +static inline int template_callback_double(unpack_user* u, double d, msgpack_unpack_object* o) +{ *o = PyFloat_FromDouble(d); return 0; } + +static inline int template_callback_nil(unpack_user* u, msgpack_unpack_object* o) +{ Py_INCREF(Py_None); *o = Py_None; return 0; } + +static inline int template_callback_true(unpack_user* u, msgpack_unpack_object* o) +{ Py_INCREF(Py_True); *o = Py_True; return 0; } + +static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* o) +{ Py_INCREF(Py_False); *o = Py_False; return 0; } + +static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o) +{ + /* TODO: use PyList_New(n). */ + *o = PyList_New(0); + return 0; +} + +static inline int template_callback_array_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object o) +{ + PyList_Append(*c, o); + return 0; +} + +static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o) +{ + *o = PyDict_New(); + return 0; +} + +static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v) +{ + PyDict_SetItem(*c, k, v); + return 0; +} + +static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) +{ + *o = PyString_FromStringAndSize(p, l); + return 0; +} + +#include "msgpack/unpack_template.h" diff --git a/python/pack.h b/python/pack.h deleted file mode 100644 index f3935fb..0000000 --- a/python/pack.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * MessagePack for Python packing routine - * - * Copyright (C) 2009 Naoki INADA - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#if _MSC_VER -typedef signed char uint8_t; -typedef unsigned char uint8_t; -typedef short int16_t; -typedef unsigned short uint16_t; -typedef int int32_t; -typedef unsigned int uint32_t; -typedef long long int64_t; -typedef unsigned long long uint64_t; -#else -#include -#endif - -#include -#include -#include "msgpack/pack_define.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef int (*msgpack_packer_write)(void* data, const char* buf, unsigned int len); - -typedef struct msgpack_packer { - void* data; - msgpack_packer_write callback; -} msgpack_packer; - -static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback); - -static inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback); -static inline void msgpack_packer_free(msgpack_packer* pk); - -static inline int msgpack_pack_short(msgpack_packer* pk, short d); -static inline int msgpack_pack_int(msgpack_packer* pk, int d); -static inline int msgpack_pack_long(msgpack_packer* pk, long d); -static inline int msgpack_pack_long_long(msgpack_packer* pk, long long d); -static inline int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d); -static inline int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d); -static inline int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d); -static inline int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d); - -static inline int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d); -static inline int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d); -static inline int msgpack_pack_uint32(msgpack_packer* pk, uint32_t d); -static inline int msgpack_pack_uint64(msgpack_packer* pk, uint64_t d); -static inline int msgpack_pack_int8(msgpack_packer* pk, int8_t d); -static inline int msgpack_pack_int16(msgpack_packer* pk, int16_t d); -static inline int msgpack_pack_int32(msgpack_packer* pk, int32_t d); -static inline int msgpack_pack_int64(msgpack_packer* pk, int64_t d); - -static inline int msgpack_pack_float(msgpack_packer* pk, float d); -static inline int msgpack_pack_double(msgpack_packer* pk, double d); - -static inline int msgpack_pack_nil(msgpack_packer* pk); -static inline int msgpack_pack_true(msgpack_packer* pk); -static inline int msgpack_pack_false(msgpack_packer* pk); - -static inline int msgpack_pack_array(msgpack_packer* pk, unsigned int n); - -static inline int msgpack_pack_map(msgpack_packer* pk, unsigned int n); - -static inline int msgpack_pack_raw(msgpack_packer* pk, size_t l); -static inline int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l); - - - -#define msgpack_pack_inline_func(name) \ - static inline int msgpack_pack ## name - -#define msgpack_pack_inline_func_cint(name) \ - static inline int msgpack_pack ## name - -#define msgpack_pack_user msgpack_packer* - -#define msgpack_pack_append_buffer(user, buf, len) \ - return (*(user)->callback)((user)->data, (const char*)buf, len) - -#include "msgpack/pack_template.h" - -static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) -{ - pk->data = data; - pk->callback = callback; -} - -static inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback) -{ - msgpack_packer* pk = (msgpack_packer*)calloc(1, sizeof(msgpack_packer)); - if(!pk) { return NULL; } - msgpack_packer_init(pk, data, callback); - return pk; -} - -static inline void msgpack_packer_free(msgpack_packer* pk) -{ - free(pk); -} - - -#ifdef __cplusplus -} -#endif diff --git a/python/setup.py b/python/setup.py index 65ca412..56b3faa 100644 --- a/python/setup.py +++ b/python/setup.py @@ -1,12 +1,13 @@ from distutils.core import setup, Extension +from Cython.Distutils import build_ext import os version = '0.0.1' PACKAGE_ROOT = os.getcwdu() INCLUDE_PATH = os.path.join(PACKAGE_ROOT, 'include') -msgpack_mod = Extension('msgpack', - sources=['msgpack.c'], +msgpack_mod = Extension('msgpack._msgpack', + sources=['msgpack/_msgpack.pyx'], include_dirs=[INCLUDE_PATH]) desc = 'MessagePack serializer/desirializer.' @@ -28,6 +29,7 @@ setup(name='msgpack', author='Naoki INADA', author_email='songofacandy@gmail.com', version=version, + cmdclass={'build_ext': build_ext}, ext_modules=[msgpack_mod], description=desc, long_description=long_desc, diff --git a/python/unpack.h b/python/unpack.h deleted file mode 100644 index e51557f..0000000 --- a/python/unpack.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * MessagePack for Python unpacking routine - * - * Copyright (C) 2009 Naoki INADA - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "msgpack/unpack_define.h" - -typedef struct { - int reserved; -} unpack_user; - - -#define msgpack_unpack_struct(name) \ - struct template ## name - -#define msgpack_unpack_func(ret, name) \ - static inline ret template ## name - -#define msgpack_unpack_callback(name) \ - template_callback ## name - -#define msgpack_unpack_object PyObject* - -#define msgpack_unpack_user unpack_user - - -struct template_context; -typedef struct template_context template_context; - -static inline msgpack_unpack_object template_callback_root(unpack_user* u) -{ return NULL; } - -static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong((long)d); return 0; } - -static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong((long)d); return 0; } - -static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_unpack_object* o) -{ - if (d >= 0x80000000UL) { - *o = PyLong_FromUnsignedLongLong((unsigned long long)d); - } else { - *o = PyInt_FromLong((long)d); - } - return 0; -} - -static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o) -{ *o = PyLong_FromUnsignedLongLong(d); return 0; } - -static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong(d); return 0; } - -static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong(d); return 0; } - -static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong(d); return 0; } - -static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o) -{ *o = PyLong_FromLongLong(d); return 0; } - -static inline int template_callback_float(unpack_user* u, float d, msgpack_unpack_object* o) -{ *o = PyFloat_FromDouble((double)d); return 0; } - -static inline int template_callback_double(unpack_user* u, double d, msgpack_unpack_object* o) -{ *o = PyFloat_FromDouble(d); return 0; } - -static inline int template_callback_nil(unpack_user* u, msgpack_unpack_object* o) -{ Py_INCREF(Py_None); *o = Py_None; return 0; } - -static inline int template_callback_true(unpack_user* u, msgpack_unpack_object* o) -{ Py_INCREF(Py_True); *o = Py_True; return 0; } - -static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* o) -{ Py_INCREF(Py_False); *o = Py_False; return 0; } - -static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o) -{ - /* TODO: use PyList_New(n). */ - *o = PyList_New(0); - return 0; -} - -static inline int template_callback_array_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object o) -{ - PyList_Append(*c, o); - return 0; -} - -static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o) -{ - *o = PyDict_New(); - return 0; -} - -static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v) -{ - PyDict_SetItem(*c, k, v); - return 0; -} - -static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) -{ - *o = PyString_FromStringAndSize(p, l); - return 0; -} - -#include "msgpack/unpack_template.h" -- cgit v1.2.1 From e814986b4ec017ab124dcf16496a6fefa65a9876 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 10 Jun 2009 13:33:42 +0900 Subject: Fix document miss. --- python/msgpack/_msgpack.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index f24f403..7c07cde 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -79,7 +79,7 @@ cdef class Packer: packer.pack('foo') packer.pack('bar') - This code is same as below code: + This is same to: packer.pack(['foo', 'bar']) """ @@ -94,9 +94,9 @@ cdef class Packer: packer.pack('foo') packer.pack('bar') - This code is same as below code: + This is same to: - packer.pack({'foo', 'bar'}) + packer.pack({'foo': 'bar'}) """ msgpack_pack_map(&self.pk, len) -- cgit v1.2.1 From 6184e17a42c89993e445a668169a76cd5bcad046 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Tue, 16 Jun 2009 01:56:04 +0900 Subject: Increase stack size. --- python/unpack.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'python') diff --git a/python/unpack.h b/python/unpack.h index e51557f..c98c19a 100644 --- a/python/unpack.h +++ b/python/unpack.h @@ -15,6 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +#define MSGPACK_MAX_STACK_SIZE (1024) #include "msgpack/unpack_define.h" typedef struct { -- cgit v1.2.1 From 4d6e9ffaa2f1626e38fbc7ab5d08578213295a65 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Tue, 16 Jun 2009 01:58:07 +0900 Subject: Fix can't pack float values. --- python/msgpack.c | 212 +++++++++++++++++++++++++++-------------------------- python/msgpack.pyx | 2 +- 2 files changed, 108 insertions(+), 106 deletions(-) (limited to 'python') diff --git a/python/msgpack.c b/python/msgpack.c index 821f65b..7e5c21f 100644 --- a/python/msgpack.c +++ b/python/msgpack.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.2 on Tue Jun 9 13:10:11 2009 */ +/* Generated by Cython 0.11.2 on Tue Jun 16 01:57:05 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -800,13 +800,14 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack int __pyx_t_1; PyObject *__pyx_t_2 = NULL; PY_LONG_LONG __pyx_t_3; - char *__pyx_t_4; - Py_ssize_t __pyx_t_5; - PyObject *__pyx_t_6 = NULL; + double __pyx_t_4; + char *__pyx_t_5; + Py_ssize_t __pyx_t_6; PyObject *__pyx_t_7 = NULL; PyObject *__pyx_t_8 = NULL; - int __pyx_t_9; + PyObject *__pyx_t_9 = NULL; int __pyx_t_10; + int __pyx_t_11; __Pyx_SetupRefcountContext("__pack"); __Pyx_INCREF(__pyx_v_o); __pyx_v_k = Py_None; __Pyx_INCREF(Py_None); @@ -937,7 +938,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * intval = o * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< * elif isinstance(o, float): - * fval = 9 + * fval = o */ msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_intval); goto __pyx_L3; @@ -947,7 +948,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * intval = o * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, float): # <<<<<<<<<<<<<< - * fval = 9 + * fval = o * msgpack_pack_double(&self.pk, fval) */ __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyFloat_Type))); @@ -956,15 +957,16 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack /* "/home/inada-n/work/msgpack/python/msgpack.pyx":121 * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, float): - * fval = 9 # <<<<<<<<<<<<<< + * fval = o # <<<<<<<<<<<<<< * msgpack_pack_double(&self.pk, fval) * elif isinstance(o, str): */ - __pyx_v_fval = 9; + __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_v_o); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_fval = __pyx_t_4; /* "/home/inada-n/work/msgpack/python/msgpack.pyx":122 * elif isinstance(o, float): - * fval = 9 + * fval = o * msgpack_pack_double(&self.pk, fval) # <<<<<<<<<<<<<< * elif isinstance(o, str): * rawval = o @@ -974,7 +976,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack } /* "/home/inada-n/work/msgpack/python/msgpack.pyx":123 - * fval = 9 + * fval = o * msgpack_pack_double(&self.pk, fval) * elif isinstance(o, str): # <<<<<<<<<<<<<< * rawval = o @@ -990,8 +992,8 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) */ - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_rawval = __pyx_t_4; + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_rawval = __pyx_t_5; /* "/home/inada-n/work/msgpack/python/msgpack.pyx":125 * elif isinstance(o, str): @@ -1000,8 +1002,8 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, unicode): */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_5); + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_6); /* "/home/inada-n/work/msgpack/python/msgpack.pyx":126 * rawval = o @@ -1010,8 +1012,8 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * elif isinstance(o, unicode): * o = o.encode('utf-8') */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_5); + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_6); goto __pyx_L3; } @@ -1034,18 +1036,18 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack */ __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_6)); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_7)); __Pyx_INCREF(__pyx_kp_3); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_kp_3); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_kp_3); __Pyx_GIVEREF(__pyx_kp_3); - __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_v_o); - __pyx_v_o = __pyx_t_7; - __pyx_t_7 = 0; + __pyx_v_o = __pyx_t_8; + __pyx_t_8 = 0; /* "/home/inada-n/work/msgpack/python/msgpack.pyx":129 * elif isinstance(o, unicode): @@ -1054,8 +1056,8 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) */ - __pyx_t_4 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_rawval = __pyx_t_4; + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_rawval = __pyx_t_5; /* "/home/inada-n/work/msgpack/python/msgpack.pyx":130 * o = o.encode('utf-8') @@ -1064,8 +1066,8 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, dict): */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_5); + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_6); /* "/home/inada-n/work/msgpack/python/msgpack.pyx":131 * rawval = o @@ -1074,8 +1076,8 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * elif isinstance(o, dict): * msgpack_pack_map(&self.pk, len(o)) */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_5); + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_6); goto __pyx_L3; } @@ -1096,8 +1098,8 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * for k,v in o.iteritems(): * self.pack(k) */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_map((&__pyx_v_self->pk), __pyx_t_5); + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_map((&__pyx_v_self->pk), __pyx_t_6); /* "/home/inada-n/work/msgpack/python/msgpack.pyx":134 * elif isinstance(o, dict): @@ -1106,38 +1108,38 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * self.pack(k) * self.pack(v) */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_iteritems); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_iteritems); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __pyx_t_6 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) { - __pyx_t_5 = 0; __pyx_t_7 = __pyx_t_6; __Pyx_INCREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyList_CheckExact(__pyx_t_7) || PyTuple_CheckExact(__pyx_t_7)) { + __pyx_t_6 = 0; __pyx_t_8 = __pyx_t_7; __Pyx_INCREF(__pyx_t_8); } else { - __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); } - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; for (;;) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; - } else if (likely(PyTuple_CheckExact(__pyx_t_7))) { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; + if (likely(PyList_CheckExact(__pyx_t_8))) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_8)) break; + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; + } else if (likely(PyTuple_CheckExact(__pyx_t_8))) { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; } else { - __pyx_t_6 = PyIter_Next(__pyx_t_7); - if (!__pyx_t_6) { + __pyx_t_7 = PyIter_Next(__pyx_t_8); + if (!__pyx_t_7) { if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; } - __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); } - if (PyTuple_CheckExact(__pyx_t_6) && likely(PyTuple_GET_SIZE(__pyx_t_6) == 2)) { - PyObject* tuple = __pyx_t_6; + if (PyTuple_CheckExact(__pyx_t_7) && likely(PyTuple_GET_SIZE(__pyx_t_7) == 2)) { + PyObject* tuple = __pyx_t_7; __pyx_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_2); __pyx_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_3); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_v_k); __pyx_v_k = __pyx_2; __pyx_2 = 0; @@ -1145,9 +1147,9 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_v_v = __pyx_3; __pyx_3 = 0; } else { - __pyx_1 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_1); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_2 = __Pyx_UnpackItem(__pyx_1, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_2); __pyx_3 = __Pyx_UnpackItem(__pyx_1, 1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -1169,18 +1171,18 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * self.pack(v) * elif isinstance(o, tuple) or isinstance(o, list): */ - __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_k); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k); __Pyx_GIVEREF(__pyx_v_k); - __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; /* "/home/inada-n/work/msgpack/python/msgpack.pyx":136 * for k,v in o.iteritems(): @@ -1189,20 +1191,20 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * elif isinstance(o, tuple) or isinstance(o, list): * msgpack_pack_array(&self.pk, len(o)) */ - __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_v); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); __Pyx_GIVEREF(__pyx_v_v); - __pyx_t_6 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L3; } @@ -1215,12 +1217,12 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack */ __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyTuple_Type))); if (!__pyx_t_1) { - __pyx_t_9 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyList_Type))); - __pyx_t_10 = __pyx_t_9; + __pyx_t_10 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyList_Type))); + __pyx_t_11 = __pyx_t_10; } else { - __pyx_t_10 = __pyx_t_1; + __pyx_t_11 = __pyx_t_1; } - if (__pyx_t_10) { + if (__pyx_t_11) { /* "/home/inada-n/work/msgpack/python/msgpack.pyx":138 * self.pack(v) @@ -1229,8 +1231,8 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * for v in o: * self.pack(v) */ - __pyx_t_5 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_array((&__pyx_v_self->pk), __pyx_t_5); + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_array((&__pyx_v_self->pk), __pyx_t_6); /* "/home/inada-n/work/msgpack/python/msgpack.pyx":139 * elif isinstance(o, tuple) or isinstance(o, list): @@ -1240,29 +1242,29 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * else: */ if (PyList_CheckExact(__pyx_v_o) || PyTuple_CheckExact(__pyx_v_o)) { - __pyx_t_5 = 0; __pyx_t_7 = __pyx_v_o; __Pyx_INCREF(__pyx_t_7); + __pyx_t_6 = 0; __pyx_t_8 = __pyx_v_o; __Pyx_INCREF(__pyx_t_8); } else { - __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); } for (;;) { - if (likely(PyList_CheckExact(__pyx_t_7))) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break; - __pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; - } else if (likely(PyTuple_CheckExact(__pyx_t_7))) { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break; - __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; + if (likely(PyList_CheckExact(__pyx_t_8))) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_8)) break; + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; + } else if (likely(PyTuple_CheckExact(__pyx_t_8))) { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; } else { - __pyx_t_6 = PyIter_Next(__pyx_t_7); - if (!__pyx_t_6) { + __pyx_t_7 = PyIter_Next(__pyx_t_8); + if (!__pyx_t_7) { if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} break; } - __Pyx_GOTREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_t_7); } __Pyx_DECREF(__pyx_v_v); - __pyx_v_v = __pyx_t_6; - __pyx_t_6 = 0; + __pyx_v_v = __pyx_t_7; + __pyx_t_7 = 0; /* "/home/inada-n/work/msgpack/python/msgpack.pyx":140 * msgpack_pack_array(&self.pk, len(o)) @@ -1271,20 +1273,20 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * else: * # TODO: Serialize with defalt() like simplejson. */ - __pyx_t_6 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_v_v); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); __Pyx_GIVEREF(__pyx_v_v); - __pyx_t_8 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; goto __pyx_L3; } /*else*/ { @@ -1296,16 +1298,16 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack * * def pack(self, obj, flush=True): */ - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_7)); + __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_8)); __Pyx_INCREF(__pyx_v_o); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_o); __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_8 = PyNumber_Remainder(__pyx_kp_4, ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_Raise(__pyx_builtin_TypeError, __pyx_t_8, 0); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_9 = PyNumber_Remainder(__pyx_kp_4, ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_Raise(__pyx_builtin_TypeError, __pyx_t_9, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; @@ -1317,9 +1319,9 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __Pyx_XDECREF(__pyx_2); __Pyx_XDECREF(__pyx_3); __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("msgpack.Packer.__pack"); __pyx_r = 0; __pyx_L0:; diff --git a/python/msgpack.pyx b/python/msgpack.pyx index f24f403..aa4006b 100644 --- a/python/msgpack.pyx +++ b/python/msgpack.pyx @@ -118,7 +118,7 @@ cdef class Packer: intval = o msgpack_pack_long_long(&self.pk, intval) elif isinstance(o, float): - fval = 9 + fval = o msgpack_pack_double(&self.pk, fval) elif isinstance(o, str): rawval = o -- cgit v1.2.1 From 2475187c7d7dc32d3abf825f97f9d7acaaa58e47 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 17 Jun 2009 13:45:08 +0900 Subject: Fix refcount leak and optimize list initialization. --- python/msgpack.c | 229 +++++++++++++++++++++++++------------------------------ python/setup.py | 2 +- python/unpack.h | 45 ++++++++--- 3 files changed, 142 insertions(+), 134 deletions(-) (limited to 'python') diff --git a/python/msgpack.c b/python/msgpack.c index 7e5c21f..ed0ac7e 100644 --- a/python/msgpack.c +++ b/python/msgpack.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.2 on Tue Jun 16 01:57:05 2009 */ +/* Generated by Cython 0.11.1 on Wed Jun 17 13:44:30 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -103,9 +103,6 @@ #ifndef __cdecl #define __cdecl #endif - #ifndef __fastcall - #define __fastcall - #endif #else #define _USE_MATH_DEFINES #endif @@ -136,7 +133,6 @@ #include "string.h" #include "pack.h" #include "unpack.h" -#define __PYX_USE_C99_COMPLEX defined(_Complex_I) #ifdef __GNUC__ @@ -228,7 +224,6 @@ static const char * __pyx_cfilenm= __FILE__; static const char *__pyx_filename; static const char **__pyx_f; - #ifdef CYTHON_REFNANNY typedef struct { void (*INCREF)(void*, PyObject*, int); @@ -325,7 +320,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Type declarations */ -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":39 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":39 * cdef int BUFF_SIZE=2*1024 * * cdef class Packer: # <<<<<<<<<<<<<< @@ -343,7 +338,7 @@ struct __pyx_obj_7msgpack_Packer { PyObject *strm; }; -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":200 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":200 * return unpacks(packed) * * cdef class Unpacker: # <<<<<<<<<<<<<< @@ -356,7 +351,7 @@ struct __pyx_obj_7msgpack_Unpacker { }; -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":39 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":39 * cdef int BUFF_SIZE=2*1024 * * cdef class Packer: # <<<<<<<<<<<<<< @@ -375,12 +370,10 @@ static PyTypeObject *__pyx_ptype_7msgpack_Unpacker = 0; static int __pyx_v_7msgpack_BUFF_SIZE; static PyObject *__pyx_k_1 = 0; static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *, const char*, unsigned int); /*proto*/ -#define __Pyx_MODULE_NAME "msgpack" -int __pyx_module_is_main_msgpack = 0; + +const char *__pyx_modulename = "msgpack"; /* Implementation of msgpack */ -static char __pyx_k___main__[] = "__main__"; -static PyObject *__pyx_kp___main__; static char __pyx_k___init__[] = "__init__"; static PyObject *__pyx_kp___init__; static char __pyx_k___del__[] = "__del__"; @@ -438,7 +431,7 @@ static PyObject *__pyx_kp_4; static char __pyx_k_3[] = "utf-8"; static char __pyx_k_4[] = "can't serialize %r"; -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":51 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":51 * cdef object strm * * def __init__(self, strm, int size=0): # <<<<<<<<<<<<<< @@ -500,7 +493,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * return -1; __pyx_L4_argument_unpacking_done:; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":52 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":52 * * def __init__(self, strm, int size=0): * if size <= 0: # <<<<<<<<<<<<<< @@ -510,7 +503,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * __pyx_t_1 = (__pyx_v_size <= 0); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":53 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":53 * def __init__(self, strm, int size=0): * if size <= 0: * size = BUFF_SIZE # <<<<<<<<<<<<<< @@ -522,7 +515,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * } __pyx_L6:; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":55 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":55 * size = BUFF_SIZE * * self.strm = strm # <<<<<<<<<<<<<< @@ -535,7 +528,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * __Pyx_DECREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm = __pyx_v_strm; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":56 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":56 * * self.strm = strm * self.buff = malloc(size) # <<<<<<<<<<<<<< @@ -544,7 +537,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * */ ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff = ((char *)malloc(__pyx_v_size)); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":57 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":57 * self.strm = strm * self.buff = malloc(size) * self.allocated = size # <<<<<<<<<<<<<< @@ -553,7 +546,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * */ ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->allocated = __pyx_v_size; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":58 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":58 * self.buff = malloc(size) * self.allocated = size * self.length = 0 # <<<<<<<<<<<<<< @@ -562,7 +555,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * */ ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":60 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":60 * self.length = 0 * * msgpack_packer_init(&self.pk, self, _packer_write) # <<<<<<<<<<<<<< @@ -576,7 +569,7 @@ static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject * return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":62 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":62 * msgpack_packer_init(&self.pk, self, _packer_write) * * def __del__(self): # <<<<<<<<<<<<<< @@ -589,7 +582,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObj PyObject *__pyx_r = NULL; __Pyx_SetupRefcountContext("__del__"); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":63 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":63 * * def __del__(self): * free(self.buff); # <<<<<<<<<<<<<< @@ -604,7 +597,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObj return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":65 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":65 * free(self.buff); * * def flush(self): # <<<<<<<<<<<<<< @@ -622,7 +615,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec PyObject *__pyx_t_4 = NULL; __Pyx_SetupRefcountContext("flush"); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":67 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":67 * def flush(self): * """Flash local buffer and output stream if it has 'flush()' method.""" * if self.length > 0: # <<<<<<<<<<<<<< @@ -632,7 +625,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec __pyx_t_1 = (((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length > 0); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":68 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":68 * """Flash local buffer and output stream if it has 'flush()' method.""" * if self.length > 0: * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) # <<<<<<<<<<<<<< @@ -654,7 +647,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":69 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":69 * if self.length > 0: * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) * self.length = 0 # <<<<<<<<<<<<<< @@ -666,7 +659,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec } __pyx_L5:; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":70 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":70 * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) * self.length = 0 * if hasattr(self.strm, 'flush'): # <<<<<<<<<<<<<< @@ -676,7 +669,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec __pyx_t_1 = PyObject_HasAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_2); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":71 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":71 * self.length = 0 * if hasattr(self.strm, 'flush'): * self.strm.flush() # <<<<<<<<<<<<<< @@ -707,7 +700,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObjec return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":73 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":73 * self.strm.flush() * * def pack_list(self, len): # <<<<<<<<<<<<<< @@ -722,7 +715,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyO size_t __pyx_t_1; __Pyx_SetupRefcountContext("pack_list"); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":86 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":86 * packer.pack(['foo', 'bar']) * """ * msgpack_pack_array(&self.pk, len) # <<<<<<<<<<<<<< @@ -743,7 +736,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyO return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":88 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":88 * msgpack_pack_array(&self.pk, len) * * def pack_dict(self, len): # <<<<<<<<<<<<<< @@ -758,7 +751,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyO size_t __pyx_t_1; __Pyx_SetupRefcountContext("pack_dict"); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":101 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":101 * packer.pack({'foo', 'bar'}) * """ * msgpack_pack_map(&self.pk, len) # <<<<<<<<<<<<<< @@ -779,7 +772,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyO return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":103 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":103 * msgpack_pack_map(&self.pk, len) * * cdef __pack(self, object o): # <<<<<<<<<<<<<< @@ -813,7 +806,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_v_k = Py_None; __Pyx_INCREF(Py_None); __pyx_v_v = Py_None; __Pyx_INCREF(Py_None); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":108 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":108 * cdef char* rawval * * if o is None: # <<<<<<<<<<<<<< @@ -823,7 +816,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_1 = (__pyx_v_o == Py_None); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":109 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":109 * * if o is None: * msgpack_pack_nil(&self.pk) # <<<<<<<<<<<<<< @@ -834,7 +827,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack goto __pyx_L3; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":110 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":110 * if o is None: * msgpack_pack_nil(&self.pk) * elif o is True: # <<<<<<<<<<<<<< @@ -847,7 +840,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":111 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":111 * msgpack_pack_nil(&self.pk) * elif o is True: * msgpack_pack_true(&self.pk) # <<<<<<<<<<<<<< @@ -858,7 +851,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack goto __pyx_L3; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":112 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":112 * elif o is True: * msgpack_pack_true(&self.pk) * elif o is False: # <<<<<<<<<<<<<< @@ -871,7 +864,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":113 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":113 * msgpack_pack_true(&self.pk) * elif o is False: * msgpack_pack_false(&self.pk) # <<<<<<<<<<<<<< @@ -882,7 +875,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack goto __pyx_L3; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":114 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":114 * elif o is False: * msgpack_pack_false(&self.pk) * elif isinstance(o, long): # <<<<<<<<<<<<<< @@ -892,7 +885,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyLong_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":115 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":115 * msgpack_pack_false(&self.pk) * elif isinstance(o, long): * intval = o # <<<<<<<<<<<<<< @@ -902,7 +895,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_intval = __pyx_t_3; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":116 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":116 * elif isinstance(o, long): * intval = o * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< @@ -913,7 +906,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack goto __pyx_L3; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":117 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":117 * intval = o * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, int): # <<<<<<<<<<<<<< @@ -923,7 +916,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyInt_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":118 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":118 * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, int): * intval = o # <<<<<<<<<<<<<< @@ -933,7 +926,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_intval = __pyx_t_3; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":119 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":119 * elif isinstance(o, int): * intval = o * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< @@ -944,7 +937,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack goto __pyx_L3; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":120 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":120 * intval = o * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, float): # <<<<<<<<<<<<<< @@ -954,7 +947,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyFloat_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":121 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":121 * msgpack_pack_long_long(&self.pk, intval) * elif isinstance(o, float): * fval = o # <<<<<<<<<<<<<< @@ -964,7 +957,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_v_o); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_fval = __pyx_t_4; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":122 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":122 * elif isinstance(o, float): * fval = o * msgpack_pack_double(&self.pk, fval) # <<<<<<<<<<<<<< @@ -975,7 +968,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack goto __pyx_L3; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":123 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":123 * fval = o * msgpack_pack_double(&self.pk, fval) * elif isinstance(o, str): # <<<<<<<<<<<<<< @@ -985,7 +978,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyString_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":124 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":124 * msgpack_pack_double(&self.pk, fval) * elif isinstance(o, str): * rawval = o # <<<<<<<<<<<<<< @@ -995,7 +988,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_rawval = __pyx_t_5; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":125 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":125 * elif isinstance(o, str): * rawval = o * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< @@ -1005,7 +998,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_6); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":126 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":126 * rawval = o * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< @@ -1017,7 +1010,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack goto __pyx_L3; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":127 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":127 * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, unicode): # <<<<<<<<<<<<<< @@ -1027,7 +1020,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyUnicode_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":128 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":128 * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, unicode): * o = o.encode('utf-8') # <<<<<<<<<<<<<< @@ -1049,7 +1042,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_v_o = __pyx_t_8; __pyx_t_8 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":129 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":129 * elif isinstance(o, unicode): * o = o.encode('utf-8') * rawval = o # <<<<<<<<<<<<<< @@ -1059,7 +1052,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_rawval = __pyx_t_5; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":130 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":130 * o = o.encode('utf-8') * rawval = o * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< @@ -1069,7 +1062,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_6); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":131 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":131 * rawval = o * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< @@ -1081,7 +1074,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack goto __pyx_L3; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":132 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":132 * msgpack_pack_raw(&self.pk, len(o)) * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, dict): # <<<<<<<<<<<<<< @@ -1091,7 +1084,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyDict_Type))); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":133 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":133 * msgpack_pack_raw_body(&self.pk, rawval, len(o)) * elif isinstance(o, dict): * msgpack_pack_map(&self.pk, len(o)) # <<<<<<<<<<<<<< @@ -1101,7 +1094,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} msgpack_pack_map((&__pyx_v_self->pk), __pyx_t_6); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":134 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":134 * elif isinstance(o, dict): * msgpack_pack_map(&self.pk, len(o)) * for k,v in o.iteritems(): # <<<<<<<<<<<<<< @@ -1164,7 +1157,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_3 = 0; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":135 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":135 * msgpack_pack_map(&self.pk, len(o)) * for k,v in o.iteritems(): * self.pack(k) # <<<<<<<<<<<<<< @@ -1184,7 +1177,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":136 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":136 * for k,v in o.iteritems(): * self.pack(k) * self.pack(v) # <<<<<<<<<<<<<< @@ -1208,7 +1201,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack goto __pyx_L3; } - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":137 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":137 * self.pack(k) * self.pack(v) * elif isinstance(o, tuple) or isinstance(o, list): # <<<<<<<<<<<<<< @@ -1224,7 +1217,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack } if (__pyx_t_11) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":138 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":138 * self.pack(v) * elif isinstance(o, tuple) or isinstance(o, list): * msgpack_pack_array(&self.pk, len(o)) # <<<<<<<<<<<<<< @@ -1234,7 +1227,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} msgpack_pack_array((&__pyx_v_self->pk), __pyx_t_6); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":139 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":139 * elif isinstance(o, tuple) or isinstance(o, list): * msgpack_pack_array(&self.pk, len(o)) * for v in o: # <<<<<<<<<<<<<< @@ -1266,7 +1259,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack __pyx_v_v = __pyx_t_7; __pyx_t_7 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":140 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":140 * msgpack_pack_array(&self.pk, len(o)) * for v in o: * self.pack(v) # <<<<<<<<<<<<<< @@ -1291,7 +1284,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack } /*else*/ { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":143 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":143 * else: * # TODO: Serialize with defalt() like simplejson. * raise TypeError, "can't serialize %r" % (o,) # <<<<<<<<<<<<<< @@ -1333,7 +1326,7 @@ static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Pack return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":145 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":145 * raise TypeError, "can't serialize %r" % (o,) * * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< @@ -1394,7 +1387,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject return NULL; __pyx_L4_argument_unpacking_done:; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":146 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":146 * * def pack(self, obj, flush=True): * self.__pack(obj) # <<<<<<<<<<<<<< @@ -1405,7 +1398,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":147 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":147 * def pack(self, obj, flush=True): * self.__pack(obj) * if flush: # <<<<<<<<<<<<<< @@ -1415,7 +1408,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_flush); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_2) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":148 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":148 * self.__pack(obj) * if flush: * self.flush() # <<<<<<<<<<<<<< @@ -1445,7 +1438,7 @@ static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":150 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":150 * self.flush() * * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): # <<<<<<<<<<<<<< @@ -1461,7 +1454,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p PyObject *__pyx_t_4 = NULL; __Pyx_SetupRefcountContext("_packer_write"); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":151 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":151 * * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): * if packer.length + l > packer.allocated: # <<<<<<<<<<<<<< @@ -1471,7 +1464,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p __pyx_t_1 = ((__pyx_v_packer->length + __pyx_v_l) > __pyx_v_packer->allocated); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":152 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":152 * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): * if packer.length + l > packer.allocated: * if packer.length > 0: # <<<<<<<<<<<<<< @@ -1481,7 +1474,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p __pyx_t_1 = (__pyx_v_packer->length > 0); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":153 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":153 * if packer.length + l > packer.allocated: * if packer.length > 0: * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) # <<<<<<<<<<<<<< @@ -1506,7 +1499,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p } __pyx_L4:; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":154 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":154 * if packer.length > 0: * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) * if l > 64: # <<<<<<<<<<<<<< @@ -1516,7 +1509,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p __pyx_t_1 = (__pyx_v_l > 64); if (__pyx_t_1) { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":155 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":155 * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) * if l > 64: * packer.strm.write(PyString_FromStringAndSize(b, l)) # <<<<<<<<<<<<<< @@ -1538,7 +1531,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":156 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":156 * if l > 64: * packer.strm.write(PyString_FromStringAndSize(b, l)) * packer.length = 0 # <<<<<<<<<<<<<< @@ -1550,7 +1543,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p } /*else*/ { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":158 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":158 * packer.length = 0 * else: * memcpy(packer.buff, b, l) # <<<<<<<<<<<<<< @@ -1559,7 +1552,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p */ memcpy(__pyx_v_packer->buff, __pyx_v_b, __pyx_v_l); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":159 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":159 * else: * memcpy(packer.buff, b, l) * packer.length = l # <<<<<<<<<<<<<< @@ -1573,7 +1566,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p } /*else*/ { - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":161 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":161 * packer.length = l * else: * memcpy(packer.buff + packer.length, b, l) # <<<<<<<<<<<<<< @@ -1582,7 +1575,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p */ memcpy((__pyx_v_packer->buff + __pyx_v_packer->length), __pyx_v_b, __pyx_v_l); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":162 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":162 * else: * memcpy(packer.buff + packer.length, b, l) * packer.length += l # <<<<<<<<<<<<<< @@ -1593,7 +1586,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p } __pyx_L3:; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":163 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":163 * memcpy(packer.buff + packer.length, b, l) * packer.length += l * return 0 # <<<<<<<<<<<<<< @@ -1616,7 +1609,7 @@ static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__p return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":165 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":165 * return 0 * * def pack(object o, object stream): # <<<<<<<<<<<<<< @@ -1677,7 +1670,7 @@ static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_ar __pyx_L4_argument_unpacking_done:; __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":166 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":166 * * def pack(object o, object stream): * packer = Packer(stream) # <<<<<<<<<<<<<< @@ -1696,7 +1689,7 @@ static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_ar __pyx_v_packer = __pyx_t_2; __pyx_t_2 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":167 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":167 * def pack(object o, object stream): * packer = Packer(stream) * packer.pack(o) # <<<<<<<<<<<<<< @@ -1716,7 +1709,7 @@ static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_ar __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":168 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":168 * packer = Packer(stream) * packer.pack(o) * packer.flush() # <<<<<<<<<<<<<< @@ -1745,7 +1738,7 @@ static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_ar return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":170 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":170 * packer.flush() * * def packs(object o): # <<<<<<<<<<<<<< @@ -1767,7 +1760,7 @@ static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v __pyx_v_buf = Py_None; __Pyx_INCREF(Py_None); __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":171 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":171 * * def packs(object o): * buf = StringIO() # <<<<<<<<<<<<<< @@ -1783,7 +1776,7 @@ static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v __pyx_v_buf = __pyx_t_1; __pyx_t_1 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":172 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":172 * def packs(object o): * buf = StringIO() * packer = Packer(buf) # <<<<<<<<<<<<<< @@ -1802,7 +1795,7 @@ static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v __pyx_v_packer = __pyx_t_2; __pyx_t_2 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":173 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":173 * buf = StringIO() * packer = Packer(buf) * packer.pack(o) # <<<<<<<<<<<<<< @@ -1822,7 +1815,7 @@ static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":174 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":174 * packer = Packer(buf) * packer.pack(o) * packer.flush() # <<<<<<<<<<<<<< @@ -1836,7 +1829,7 @@ static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":175 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":175 * packer.pack(o) * packer.flush() * return buf.getvalue() # <<<<<<<<<<<<<< @@ -1870,7 +1863,7 @@ static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":186 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":186 * * * def unpacks(object packed_bytes): # <<<<<<<<<<<<<< @@ -1891,7 +1884,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx __Pyx_SetupRefcountContext("unpacks"); __pyx_self = __pyx_self; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":188 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":188 * def unpacks(object packed_bytes): * """Unpack packed_bytes to object. Returns unpacked object.""" * cdef const_char_ptr p = packed_bytes # <<<<<<<<<<<<<< @@ -1901,7 +1894,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_packed_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_p = __pyx_t_1; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":190 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":190 * cdef const_char_ptr p = packed_bytes * cdef template_context ctx * cdef size_t off = 0 # <<<<<<<<<<<<<< @@ -1910,7 +1903,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx */ __pyx_v_off = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":191 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":191 * cdef template_context ctx * cdef size_t off = 0 * template_init(&ctx) # <<<<<<<<<<<<<< @@ -1919,7 +1912,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx */ template_init((&__pyx_v_ctx)); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":192 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":192 * cdef size_t off = 0 * template_init(&ctx) * template_execute(&ctx, p, len(packed_bytes), &off) # <<<<<<<<<<<<<< @@ -1929,7 +1922,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx __pyx_t_2 = PyObject_Length(__pyx_v_packed_bytes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} template_execute((&__pyx_v_ctx), __pyx_v_p, __pyx_t_2, (&__pyx_v_off)); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":193 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":193 * template_init(&ctx) * template_execute(&ctx, p, len(packed_bytes), &off) * return template_data(&ctx) # <<<<<<<<<<<<<< @@ -1955,7 +1948,7 @@ static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx return __pyx_r; } -/* "/home/inada-n/work/msgpack/python/msgpack.pyx":195 +/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":195 * return template_data(&ctx) * * def unpack(object stream): # <<<<<<<<<<<<<< @@ -1975,7 +1968,7 @@ static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_ __pyx_self = __pyx_self; __pyx_v_packed = Py_None; __Pyx_INCREF(Py_None); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":197 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":197 * def unpack(object stream): * """unpack from stream.""" * packed = stream.read() # <<<<<<<<<<<<<< @@ -1991,7 +1984,7 @@ static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_ __pyx_v_packed = __pyx_t_2; __pyx_t_2 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":198 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":198 * """unpack from stream.""" * packed = stream.read() * return unpacks(packed) # <<<<<<<<<<<<<< @@ -2097,11 +2090,7 @@ static PyNumberMethods __pyx_tp_as_number_Packer = { 0, /*nb_coerce*/ #endif 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else 0, /*nb_long*/ - #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ @@ -2257,11 +2246,7 @@ static PyNumberMethods __pyx_tp_as_number_Unpacker = { 0, /*nb_coerce*/ #endif 0, /*nb_int*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*reserved*/ - #else 0, /*nb_long*/ - #endif 0, /*nb_float*/ #if PY_MAJOR_VERSION < 3 0, /*nb_oct*/ @@ -2404,7 +2389,6 @@ static struct PyModuleDef __pyx_moduledef = { #endif static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1}, {&__pyx_kp___init__, __pyx_k___init__, sizeof(__pyx_k___init__), 1, 1, 1}, {&__pyx_kp___del__, __pyx_k___del__, sizeof(__pyx_k___del__), 1, 1, 1}, {&__pyx_kp_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 1, 1, 1}, @@ -2496,9 +2480,6 @@ PyMODINIT_FUNC PyInit_msgpack(void) __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - if (__pyx_module_is_main_msgpack) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - } /*--- Builtin init code ---*/ if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_skip_dispatch = 0; @@ -2522,7 +2503,7 @@ PyMODINIT_FUNC PyInit_msgpack(void) /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":3 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":3 * # coding: utf-8 * * from cStringIO import StringIO # <<<<<<<<<<<<<< @@ -2543,7 +2524,7 @@ PyMODINIT_FUNC PyInit_msgpack(void) __Pyx_DECREF(__pyx_2); __pyx_2 = 0; __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":37 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":37 * * * cdef int BUFF_SIZE=2*1024 # <<<<<<<<<<<<<< @@ -2552,7 +2533,7 @@ PyMODINIT_FUNC PyInit_msgpack(void) */ __pyx_v_7msgpack_BUFF_SIZE = 2048; - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":145 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":145 * raise TypeError, "can't serialize %r" % (o,) * * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< @@ -2565,7 +2546,7 @@ PyMODINIT_FUNC PyInit_msgpack(void) __pyx_t_1 = 0; __Pyx_GIVEREF(__pyx_k_1); - /* "/home/inada-n/work/msgpack/python/msgpack.pyx":202 + /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":202 * cdef class Unpacker: * """Do nothing. This function is for symmetric to Packer""" * unpack = staticmethod(unpacks) # <<<<<<<<<<<<<< @@ -3368,14 +3349,14 @@ static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { return Py_INCREF(x), x; m = Py_TYPE(x)->tp_as_number; #if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } - else if (m && m->nb_long) { + if (m && m->nb_long) { name = "long"; res = PyNumber_Long(x); } + else if (m && m->nb_int) { + name = "int"; + res = PyNumber_Int(x); + } #else if (m && m->nb_int) { name = "int"; diff --git a/python/setup.py b/python/setup.py index e5651a0..4bb8693 100644 --- a/python/setup.py +++ b/python/setup.py @@ -2,7 +2,7 @@ from distutils.core import setup, Extension version = '0.0.1' -msgpack_mod = Extension('msgpack', sources=['msgpack.c']) +msgpack_mod = Extension('msgpack', sources=['msgpack.c'], extra_compile_args=["-O3"]) desc = 'MessagePack serializer/desirializer.' long_desc = desc + """ diff --git a/python/unpack.h b/python/unpack.h index c98c19a..3e99123 100644 --- a/python/unpack.h +++ b/python/unpack.h @@ -20,7 +20,8 @@ #include "msgpack/unpack_define.h" typedef struct { - int reserved; + struct {unsigned int size, last} array_stack[MSGPACK_MAX_STACK_SIZE]; + int array_current; } unpack_user; @@ -42,7 +43,10 @@ struct template_context; typedef struct template_context template_context; static inline msgpack_unpack_object template_callback_root(unpack_user* u) -{ return NULL; } +{ + u->array_current = -1; + return NULL; +} static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_unpack_object* o) { *o = PyInt_FromLong((long)d); return 0; } @@ -52,8 +56,8 @@ static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_u static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_unpack_object* o) { - if (d >= 0x80000000UL) { - *o = PyLong_FromUnsignedLongLong((unsigned long long)d); + if (d > LONG_MAX) { + *o = PyLong_FromUnsignedLong((unsigned long)d); } else { *o = PyInt_FromLong((long)d); } @@ -92,14 +96,32 @@ 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) { - /* TODO: use PyList_New(n). */ - *o = PyList_New(0); + if (n > 0) { + int cur = ++u->array_current; + u->array_stack[cur].size = n; + u->array_stack[cur].last = 0; + *o = PyList_New(n); + } + else { + *o = PyList_New(0); + } return 0; } static inline int template_callback_array_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object o) { - PyList_Append(*c, o); + int cur = u->array_current; + int n = u->array_stack[cur].size; + int last = u->array_stack[cur].last; + + PyList_SetItem(*c, last, o); + last++; + if (last >= n) { + u->array_current--; + } + else { + u->array_stack[cur].last = last; + } return 0; } @@ -112,13 +134,18 @@ static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_ static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v) { PyDict_SetItem(*c, k, v); - return 0; + Py_DECREF(k); + Py_DECREF(v); + return 0; } static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) { *o = PyString_FromStringAndSize(p, l); - return 0; + if (l < 16) { // without foundation + PyString_InternInPlace(o); + } + return 0; } #include "msgpack/unpack_template.h" -- cgit v1.2.1 From 0d14239c2197b616196a535c9aeb818da1040e9d Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 22 Jun 2009 09:51:24 +0900 Subject: Optimize to parsing data that has a number of same short raw field. --- python/msgpack.c | 3421 --------------------------------------------------- python/msgpack.cpp | 3440 ++++++++++++++++++++++++++++++++++++++++++++++++++++ python/setup.py | 2 +- python/unpack.h | 38 +- 4 files changed, 3474 insertions(+), 3427 deletions(-) delete mode 100644 python/msgpack.c create mode 100644 python/msgpack.cpp (limited to 'python') diff --git a/python/msgpack.c b/python/msgpack.c deleted file mode 100644 index ed0ac7e..0000000 --- a/python/msgpack.c +++ /dev/null @@ -1,3421 +0,0 @@ -/* Generated by Cython 0.11.1 on Wed Jun 17 13:44:30 2009 */ - -#define PY_SSIZE_T_CLEAN -#include "Python.h" -#include "structmember.h" -#ifndef Py_PYTHON_H - #error Python headers needed to compile C extensions, please install development version of Python. -#endif -#ifndef PY_LONG_LONG - #define PY_LONG_LONG LONG_LONG -#endif -#ifndef DL_EXPORT - #define DL_EXPORT(t) t -#endif -#if PY_VERSION_HEX < 0x02040000 - #define METH_COEXIST 0 - #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) -#endif -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) PyInt_AsLong(o) - #define PyNumber_Index(o) PyNumber_Int(o) - #define PyIndex_Check(o) PyNumber_Check(o) -#endif -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - -#endif -#if PY_MAJOR_VERSION < 3 - #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" -#else - #define __Pyx_BUILTIN_MODULE_NAME "builtins" -#endif -#if PY_MAJOR_VERSION >= 3 - #define Py_TPFLAGS_CHECKTYPES 0 - #define Py_TPFLAGS_HAVE_INDEX 0 -#endif -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) - #define Py_TPFLAGS_HAVE_NEWBUFFER 0 -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyBaseString_Type PyUnicode_Type - #define PyString_Type PyBytes_Type - #define PyString_CheckExact PyBytes_CheckExact - #define PyInt_Type PyLong_Type - #define PyInt_Check(op) PyLong_Check(op) - #define PyInt_CheckExact(op) PyLong_CheckExact(op) - #define PyInt_FromString PyLong_FromString - #define PyInt_FromUnicode PyLong_FromUnicode - #define PyInt_FromLong PyLong_FromLong - #define PyInt_FromSize_t PyLong_FromSize_t - #define PyInt_FromSsize_t PyLong_FromSsize_t - #define PyInt_AsLong PyLong_AsLong - #define PyInt_AS_LONG PyLong_AS_LONG - #define PyInt_AsSsize_t PyLong_AsSsize_t - #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask - #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) -#else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define PyBytes_Type PyString_Type -#endif -#if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func) -#endif -#if !defined(WIN32) && !defined(MS_WINDOWS) - #ifndef __stdcall - #define __stdcall - #endif - #ifndef __cdecl - #define __cdecl - #endif -#else - #define _USE_MATH_DEFINES -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) -#else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) -#else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif -#ifdef __cplusplus -#define __PYX_EXTERN_C extern "C" -#else -#define __PYX_EXTERN_C extern -#endif -#include -#define __PYX_HAVE_API__msgpack -#include "stdlib.h" -#include "string.h" -#include "pack.h" -#include "unpack.h" - - -#ifdef __GNUC__ -#define INLINE __inline__ -#elif _WIN32 -#define INLINE __inline -#else -#define INLINE -#endif - -typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char is_identifier;} __Pyx_StringTabEntry; /*proto*/ - - - -static int __pyx_skip_dispatch = 0; - - -/* Type Conversion Predeclarations */ - -#if PY_MAJOR_VERSION < 3 -#define __Pyx_PyBytes_FromString PyString_FromString -#define __Pyx_PyBytes_FromStringAndSize PyString_FromStringAndSize -#define __Pyx_PyBytes_AsString PyString_AsString -#else -#define __Pyx_PyBytes_FromString PyBytes_FromString -#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize -#define __Pyx_PyBytes_AsString PyBytes_AsString -#endif - -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) -static INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); - -#if !defined(T_PYSSIZET) -#if PY_VERSION_HEX < 0x02050000 -#define T_PYSSIZET T_INT -#elif !defined(T_LONGLONG) -#define T_PYSSIZET \ - ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \ - ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1)) -#else -#define T_PYSSIZET \ - ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \ - ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : \ - ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1))) -#endif -#endif - -#if !defined(T_SIZET) -#if !defined(T_ULONGLONG) -#define T_SIZET \ - ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \ - ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1)) -#else -#define T_SIZET \ - ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \ - ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : \ - ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1))) -#endif -#endif - -static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); -static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); - -#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) - - -#ifdef __GNUC__ -/* Test for GCC > 2.95 */ -#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) -#else /* __GNUC__ > 2 ... */ -#define likely(x) (x) -#define unlikely(x) (x) -#endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ -#define likely(x) (x) -#define unlikely(x) (x) -#endif /* __GNUC__ */ - -static PyObject *__pyx_m; -static PyObject *__pyx_b; -static PyObject *__pyx_empty_tuple; -static int __pyx_lineno; -static int __pyx_clineno = 0; -static const char * __pyx_cfilenm= __FILE__; -static const char *__pyx_filename; -static const char **__pyx_f; - -#ifdef CYTHON_REFNANNY -typedef struct { - void (*INCREF)(void*, PyObject*, int); - void (*DECREF)(void*, PyObject*, int); - void (*GOTREF)(void*, PyObject*, int); - void (*GIVEREF)(void*, PyObject*, int); - void* (*NewContext)(const char*, int, const char*); - void (*FinishContext)(void**); -} __Pyx_RefnannyAPIStruct; -static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL; -#define __Pyx_ImportRefcountAPI(name) (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI") -#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__) -#define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r) -#define __Pyx_SetupRefcountContext(name) void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__) -#define __Pyx_FinishRefcountContext() __Pyx_Refnanny->FinishContext(&__pyx_refchk) -#else -#define __Pyx_INCREF(r) Py_INCREF(r) -#define __Pyx_DECREF(r) Py_DECREF(r) -#define __Pyx_GOTREF(r) -#define __Pyx_GIVEREF(r) -#define __Pyx_XDECREF(r) Py_XDECREF(r) -#define __Pyx_SetupRefcountContext(name) -#define __Pyx_FinishRefcountContext() -#endif /* CYTHON_REFNANNY */ -#define __Pyx_XGIVEREF(r) if((r) == NULL) ; else __Pyx_GIVEREF(r) -#define __Pyx_XGOTREF(r) if((r) == NULL) ; else __Pyx_GOTREF(r) - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, PyObject* kw_name); /*proto*/ - -static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, - Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ - -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ - -static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); - -static INLINE void __Pyx_RaiseTooManyValuesError(void); - -static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/ -static int __Pyx_EndUnpack(PyObject *); /*proto*/ - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ - -static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ - -static INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/ - -static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); - -static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); - -static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); - -static INLINE char __Pyx_PyInt_AsChar(PyObject *); - -static INLINE short __Pyx_PyInt_AsShort(PyObject *); - -static INLINE int __Pyx_PyInt_AsInt(PyObject *); - -static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); - -static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); - -static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); - -static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); - -static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); - -static INLINE long __Pyx_PyInt_AsLong(PyObject *); - -static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); - -static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); - -static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); - -static void __Pyx_WriteUnraisable(const char *name); /*proto*/ - -static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ - -static void __Pyx_AddTraceback(const char *funcname); /*proto*/ - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ - -/* Type declarations */ - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":39 - * cdef int BUFF_SIZE=2*1024 - * - * cdef class Packer: # <<<<<<<<<<<<<< - * """Packer that pack data into strm. - * - */ - -struct __pyx_obj_7msgpack_Packer { - PyObject_HEAD - struct __pyx_vtabstruct_7msgpack_Packer *__pyx_vtab; - char *buff; - unsigned int length; - unsigned int allocated; - struct msgpack_packer pk; - PyObject *strm; -}; - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":200 - * return unpacks(packed) - * - * cdef class Unpacker: # <<<<<<<<<<<<<< - * """Do nothing. This function is for symmetric to Packer""" - * unpack = staticmethod(unpacks) - */ - -struct __pyx_obj_7msgpack_Unpacker { - PyObject_HEAD -}; - - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":39 - * cdef int BUFF_SIZE=2*1024 - * - * cdef class Packer: # <<<<<<<<<<<<<< - * """Packer that pack data into strm. - * - */ - -struct __pyx_vtabstruct_7msgpack_Packer { - PyObject *(*__pack)(struct __pyx_obj_7msgpack_Packer *, PyObject *); -}; -static struct __pyx_vtabstruct_7msgpack_Packer *__pyx_vtabptr_7msgpack_Packer; -/* Module declarations from msgpack */ - -static PyTypeObject *__pyx_ptype_7msgpack_Packer = 0; -static PyTypeObject *__pyx_ptype_7msgpack_Unpacker = 0; -static int __pyx_v_7msgpack_BUFF_SIZE; -static PyObject *__pyx_k_1 = 0; -static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *, const char*, unsigned int); /*proto*/ - -const char *__pyx_modulename = "msgpack"; - -/* Implementation of msgpack */ -static char __pyx_k___init__[] = "__init__"; -static PyObject *__pyx_kp___init__; -static char __pyx_k___del__[] = "__del__"; -static PyObject *__pyx_kp___del__; -static char __pyx_k_flush[] = "flush"; -static PyObject *__pyx_kp_flush; -static char __pyx_k_pack_list[] = "pack_list"; -static PyObject *__pyx_kp_pack_list; -static char __pyx_k_pack_dict[] = "pack_dict"; -static PyObject *__pyx_kp_pack_dict; -static char __pyx_k_pack[] = "pack"; -static PyObject *__pyx_kp_pack; -static char __pyx_k_unpack[] = "unpack"; -static PyObject *__pyx_kp_unpack; -static char __pyx_k_strm[] = "strm"; -static PyObject *__pyx_kp_strm; -static char __pyx_k_size[] = "size"; -static PyObject *__pyx_kp_size; -static char __pyx_k_len[] = "len"; -static PyObject *__pyx_kp_len; -static char __pyx_k_obj[] = "obj"; -static PyObject *__pyx_kp_obj; -static char __pyx_k_o[] = "o"; -static PyObject *__pyx_kp_o; -static char __pyx_k_stream[] = "stream"; -static PyObject *__pyx_kp_stream; -static char __pyx_k_packed_bytes[] = "packed_bytes"; -static PyObject *__pyx_kp_packed_bytes; -static char __pyx_k_cStringIO[] = "cStringIO"; -static PyObject *__pyx_kp_cStringIO; -static char __pyx_k_StringIO[] = "StringIO"; -static PyObject *__pyx_kp_StringIO; -static char __pyx_k_staticmethod[] = "staticmethod"; -static PyObject *__pyx_kp_staticmethod; -static char __pyx_k_unpacks[] = "unpacks"; -static PyObject *__pyx_kp_unpacks; -static char __pyx_k_write[] = "write"; -static PyObject *__pyx_kp_write; -static char __pyx_k_2[] = "flush"; -static PyObject *__pyx_kp_2; -static char __pyx_k_encode[] = "encode"; -static PyObject *__pyx_kp_encode; -static char __pyx_k_iteritems[] = "iteritems"; -static PyObject *__pyx_kp_iteritems; -static char __pyx_k_TypeError[] = "TypeError"; -static PyObject *__pyx_kp_TypeError; -static char __pyx_k_getvalue[] = "getvalue"; -static PyObject *__pyx_kp_getvalue; -static char __pyx_k_read[] = "read"; -static PyObject *__pyx_kp_read; -static PyObject *__pyx_builtin_staticmethod; -static PyObject *__pyx_builtin_TypeError; -static PyObject *__pyx_kp_3; -static PyObject *__pyx_kp_4; -static char __pyx_k_3[] = "utf-8"; -static char __pyx_k_4[] = "can't serialize %r"; - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":51 - * cdef object strm - * - * def __init__(self, strm, int size=0): # <<<<<<<<<<<<<< - * if size <= 0: - * size = BUFF_SIZE - */ - -static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_strm = 0; - int __pyx_v_size; - int __pyx_r; - int __pyx_t_1; - static PyObject **__pyx_pyargnames[] = {&__pyx_kp_strm,&__pyx_kp_size,0}; - __Pyx_SetupRefcountContext("__init__"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_strm); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 1) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_size); - if (unlikely(value)) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_strm = values[0]; - if (values[1]) { - __pyx_v_size = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } else { - __pyx_v_size = 0; - } - } else { - __pyx_v_size = 0; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: __pyx_v_size = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - case 1: __pyx_v_strm = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("msgpack.Packer.__init__"); - return -1; - __pyx_L4_argument_unpacking_done:; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":52 - * - * def __init__(self, strm, int size=0): - * if size <= 0: # <<<<<<<<<<<<<< - * size = BUFF_SIZE - * - */ - __pyx_t_1 = (__pyx_v_size <= 0); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":53 - * def __init__(self, strm, int size=0): - * if size <= 0: - * size = BUFF_SIZE # <<<<<<<<<<<<<< - * - * self.strm = strm - */ - __pyx_v_size = __pyx_v_7msgpack_BUFF_SIZE; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":55 - * size = BUFF_SIZE - * - * self.strm = strm # <<<<<<<<<<<<<< - * self.buff = malloc(size) - * self.allocated = size - */ - __Pyx_INCREF(__pyx_v_strm); - __Pyx_GIVEREF(__pyx_v_strm); - __Pyx_GOTREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); - __Pyx_DECREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm = __pyx_v_strm; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":56 - * - * self.strm = strm - * self.buff = malloc(size) # <<<<<<<<<<<<<< - * self.allocated = size - * self.length = 0 - */ - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff = ((char *)malloc(__pyx_v_size)); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":57 - * self.strm = strm - * self.buff = malloc(size) - * self.allocated = size # <<<<<<<<<<<<<< - * self.length = 0 - * - */ - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->allocated = __pyx_v_size; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":58 - * self.buff = malloc(size) - * self.allocated = size - * self.length = 0 # <<<<<<<<<<<<<< - * - * msgpack_packer_init(&self.pk, self, _packer_write) - */ - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":60 - * self.length = 0 - * - * msgpack_packer_init(&self.pk, self, _packer_write) # <<<<<<<<<<<<<< - * - * def __del__(self): - */ - msgpack_packer_init((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), ((void *)__pyx_v_self), ((int (*)(void *, const char*, unsigned int))__pyx_f_7msgpack__packer_write)); - - __pyx_r = 0; - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":62 - * msgpack_packer_init(&self.pk, self, _packer_write) - * - * def __del__(self): # <<<<<<<<<<<<<< - * free(self.buff); - * - */ - -static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObject *unused); /*proto*/ -static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObject *unused) { - PyObject *__pyx_r = NULL; - __Pyx_SetupRefcountContext("__del__"); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":63 - * - * def __del__(self): - * free(self.buff); # <<<<<<<<<<<<<< - * - * def flush(self): - */ - free(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":65 - * free(self.buff); - * - * def flush(self): # <<<<<<<<<<<<<< - * """Flash local buffer and output stream if it has 'flush()' method.""" - * if self.length > 0: - */ - -static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObject *unused); /*proto*/ -static char __pyx_doc_7msgpack_6Packer_flush[] = "Flash local buffer and output stream if it has 'flush()' method."; -static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObject *unused) { - PyObject *__pyx_r = NULL; - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_SetupRefcountContext("flush"); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":67 - * def flush(self): - * """Flash local buffer and output stream if it has 'flush()' method.""" - * if self.length > 0: # <<<<<<<<<<<<<< - * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) - * self.length = 0 - */ - __pyx_t_1 = (((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length > 0); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":68 - * """Flash local buffer and output stream if it has 'flush()' method.""" - * if self.length > 0: - * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) # <<<<<<<<<<<<<< - * self.length = 0 - * if hasattr(self.strm, 'flush'): - */ - __pyx_t_2 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyString_FromStringAndSize(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff, ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":69 - * if self.length > 0: - * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) - * self.length = 0 # <<<<<<<<<<<<<< - * if hasattr(self.strm, 'flush'): - * self.strm.flush() - */ - ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; - goto __pyx_L5; - } - __pyx_L5:; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":70 - * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) - * self.length = 0 - * if hasattr(self.strm, 'flush'): # <<<<<<<<<<<<<< - * self.strm.flush() - * - */ - __pyx_t_1 = PyObject_HasAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_2); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":71 - * self.length = 0 - * if hasattr(self.strm, 'flush'): - * self.strm.flush() # <<<<<<<<<<<<<< - * - * def pack_list(self, len): - */ - __pyx_t_3 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - goto __pyx_L6; - } - __pyx_L6:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("msgpack.Packer.flush"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":73 - * self.strm.flush() - * - * def pack_list(self, len): # <<<<<<<<<<<<<< - * """Start packing sequential objects. - * - */ - -static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyObject *__pyx_v_len); /*proto*/ -static char __pyx_doc_7msgpack_6Packer_pack_list[] = "Start packing sequential objects.\n\n Example:\n\n packer.pack_list(2)\n packer.pack('foo')\n packer.pack('bar')\n\n This code is same as below code:\n\n packer.pack(['foo', 'bar'])\n "; -static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyObject *__pyx_v_len) { - PyObject *__pyx_r = NULL; - size_t __pyx_t_1; - __Pyx_SetupRefcountContext("pack_list"); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":86 - * packer.pack(['foo', 'bar']) - * """ - * msgpack_pack_array(&self.pk, len) # <<<<<<<<<<<<<< - * - * def pack_dict(self, len): - */ - __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_array((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("msgpack.Packer.pack_list"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":88 - * msgpack_pack_array(&self.pk, len) - * - * def pack_dict(self, len): # <<<<<<<<<<<<<< - * """Start packing key-value objects. - * - */ - -static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_len); /*proto*/ -static char __pyx_doc_7msgpack_6Packer_pack_dict[] = "Start packing key-value objects.\n\n Example:\n\n packer.pack_dict(1)\n packer.pack('foo')\n packer.pack('bar')\n\n This code is same as below code:\n\n packer.pack({'foo', 'bar'})\n "; -static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_len) { - PyObject *__pyx_r = NULL; - size_t __pyx_t_1; - __Pyx_SetupRefcountContext("pack_dict"); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":101 - * packer.pack({'foo', 'bar'}) - * """ - * msgpack_pack_map(&self.pk, len) # <<<<<<<<<<<<<< - * - * cdef __pack(self, object o): - */ - __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_map((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("msgpack.Packer.pack_dict"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":103 - * msgpack_pack_map(&self.pk, len) - * - * cdef __pack(self, object o): # <<<<<<<<<<<<<< - * cdef long long intval - * cdef double fval - */ - -static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Packer *__pyx_v_self, PyObject *__pyx_v_o) { - PY_LONG_LONG __pyx_v_intval; - double __pyx_v_fval; - char *__pyx_v_rawval; - PyObject *__pyx_v_k; - PyObject *__pyx_v_v; - PyObject *__pyx_r = NULL; - PyObject *__pyx_1 = 0; - PyObject *__pyx_2 = 0; - PyObject *__pyx_3 = 0; - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PY_LONG_LONG __pyx_t_3; - double __pyx_t_4; - char *__pyx_t_5; - Py_ssize_t __pyx_t_6; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - int __pyx_t_10; - int __pyx_t_11; - __Pyx_SetupRefcountContext("__pack"); - __Pyx_INCREF(__pyx_v_o); - __pyx_v_k = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_v = Py_None; __Pyx_INCREF(Py_None); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":108 - * cdef char* rawval - * - * if o is None: # <<<<<<<<<<<<<< - * msgpack_pack_nil(&self.pk) - * elif o is True: - */ - __pyx_t_1 = (__pyx_v_o == Py_None); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":109 - * - * if o is None: - * msgpack_pack_nil(&self.pk) # <<<<<<<<<<<<<< - * elif o is True: - * msgpack_pack_true(&self.pk) - */ - msgpack_pack_nil((&__pyx_v_self->pk)); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":110 - * if o is None: - * msgpack_pack_nil(&self.pk) - * elif o is True: # <<<<<<<<<<<<<< - * msgpack_pack_true(&self.pk) - * elif o is False: - */ - __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = (__pyx_v_o == __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":111 - * msgpack_pack_nil(&self.pk) - * elif o is True: - * msgpack_pack_true(&self.pk) # <<<<<<<<<<<<<< - * elif o is False: - * msgpack_pack_false(&self.pk) - */ - msgpack_pack_true((&__pyx_v_self->pk)); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":112 - * elif o is True: - * msgpack_pack_true(&self.pk) - * elif o is False: # <<<<<<<<<<<<<< - * msgpack_pack_false(&self.pk) - * elif isinstance(o, long): - */ - __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = (__pyx_v_o == __pyx_t_2); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":113 - * msgpack_pack_true(&self.pk) - * elif o is False: - * msgpack_pack_false(&self.pk) # <<<<<<<<<<<<<< - * elif isinstance(o, long): - * intval = o - */ - msgpack_pack_false((&__pyx_v_self->pk)); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":114 - * elif o is False: - * msgpack_pack_false(&self.pk) - * elif isinstance(o, long): # <<<<<<<<<<<<<< - * intval = o - * msgpack_pack_long_long(&self.pk, intval) - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyLong_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":115 - * msgpack_pack_false(&self.pk) - * elif isinstance(o, long): - * intval = o # <<<<<<<<<<<<<< - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, int): - */ - __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_intval = __pyx_t_3; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":116 - * elif isinstance(o, long): - * intval = o - * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< - * elif isinstance(o, int): - * intval = o - */ - msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_intval); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":117 - * intval = o - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, int): # <<<<<<<<<<<<<< - * intval = o - * msgpack_pack_long_long(&self.pk, intval) - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyInt_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":118 - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, int): - * intval = o # <<<<<<<<<<<<<< - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, float): - */ - __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_intval = __pyx_t_3; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":119 - * elif isinstance(o, int): - * intval = o - * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< - * elif isinstance(o, float): - * fval = o - */ - msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_intval); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":120 - * intval = o - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, float): # <<<<<<<<<<<<<< - * fval = o - * msgpack_pack_double(&self.pk, fval) - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyFloat_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":121 - * msgpack_pack_long_long(&self.pk, intval) - * elif isinstance(o, float): - * fval = o # <<<<<<<<<<<<<< - * msgpack_pack_double(&self.pk, fval) - * elif isinstance(o, str): - */ - __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_v_o); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_fval = __pyx_t_4; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":122 - * elif isinstance(o, float): - * fval = o - * msgpack_pack_double(&self.pk, fval) # <<<<<<<<<<<<<< - * elif isinstance(o, str): - * rawval = o - */ - msgpack_pack_double((&__pyx_v_self->pk), __pyx_v_fval); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":123 - * fval = o - * msgpack_pack_double(&self.pk, fval) - * elif isinstance(o, str): # <<<<<<<<<<<<<< - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyString_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":124 - * msgpack_pack_double(&self.pk, fval) - * elif isinstance(o, str): - * rawval = o # <<<<<<<<<<<<<< - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - */ - __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_rawval = __pyx_t_5; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":125 - * elif isinstance(o, str): - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, unicode): - */ - __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_6); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":126 - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< - * elif isinstance(o, unicode): - * o = o.encode('utf-8') - */ - __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_6); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":127 - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, unicode): # <<<<<<<<<<<<<< - * o = o.encode('utf-8') - * rawval = o - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyUnicode_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":128 - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, unicode): - * o = o.encode('utf-8') # <<<<<<<<<<<<<< - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_7)); - __Pyx_INCREF(__pyx_kp_3); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_kp_3); - __Pyx_GIVEREF(__pyx_kp_3); - __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_v_o); - __pyx_v_o = __pyx_t_8; - __pyx_t_8 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":129 - * elif isinstance(o, unicode): - * o = o.encode('utf-8') - * rawval = o # <<<<<<<<<<<<<< - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - */ - __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_rawval = __pyx_t_5; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":130 - * o = o.encode('utf-8') - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, dict): - */ - __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_6); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":131 - * rawval = o - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< - * elif isinstance(o, dict): - * msgpack_pack_map(&self.pk, len(o)) - */ - __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_6); - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":132 - * msgpack_pack_raw(&self.pk, len(o)) - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, dict): # <<<<<<<<<<<<<< - * msgpack_pack_map(&self.pk, len(o)) - * for k,v in o.iteritems(): - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyDict_Type))); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":133 - * msgpack_pack_raw_body(&self.pk, rawval, len(o)) - * elif isinstance(o, dict): - * msgpack_pack_map(&self.pk, len(o)) # <<<<<<<<<<<<<< - * for k,v in o.iteritems(): - * self.pack(k) - */ - __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_map((&__pyx_v_self->pk), __pyx_t_6); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":134 - * elif isinstance(o, dict): - * msgpack_pack_map(&self.pk, len(o)) - * for k,v in o.iteritems(): # <<<<<<<<<<<<<< - * self.pack(k) - * self.pack(v) - */ - __pyx_t_8 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_iteritems); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - if (PyList_CheckExact(__pyx_t_7) || PyTuple_CheckExact(__pyx_t_7)) { - __pyx_t_6 = 0; __pyx_t_8 = __pyx_t_7; __Pyx_INCREF(__pyx_t_8); - } else { - __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - } - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - for (;;) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_8)) break; - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; - } else if (likely(PyTuple_CheckExact(__pyx_t_8))) { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; - } else { - __pyx_t_7 = PyIter_Next(__pyx_t_8); - if (!__pyx_t_7) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - if (PyTuple_CheckExact(__pyx_t_7) && likely(PyTuple_GET_SIZE(__pyx_t_7) == 2)) { - PyObject* tuple = __pyx_t_7; - __pyx_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_2); - __pyx_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_3); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(__pyx_v_k); - __pyx_v_k = __pyx_2; - __pyx_2 = 0; - __Pyx_DECREF(__pyx_v_v); - __pyx_v_v = __pyx_3; - __pyx_3 = 0; - } else { - __pyx_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_2 = __Pyx_UnpackItem(__pyx_1, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_2); - __pyx_3 = __Pyx_UnpackItem(__pyx_1, 1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_3); - if (__Pyx_EndUnpack(__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - __Pyx_DECREF(__pyx_v_k); - __pyx_v_k = __pyx_2; - __pyx_2 = 0; - __Pyx_DECREF(__pyx_v_v); - __pyx_v_v = __pyx_3; - __pyx_3 = 0; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":135 - * msgpack_pack_map(&self.pk, len(o)) - * for k,v in o.iteritems(): - * self.pack(k) # <<<<<<<<<<<<<< - * self.pack(v) - * elif isinstance(o, tuple) or isinstance(o, list): - */ - __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_INCREF(__pyx_v_k); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k); - __Pyx_GIVEREF(__pyx_v_k); - __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":136 - * for k,v in o.iteritems(): - * self.pack(k) - * self.pack(v) # <<<<<<<<<<<<<< - * elif isinstance(o, tuple) or isinstance(o, list): - * msgpack_pack_array(&self.pk, len(o)) - */ - __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_INCREF(__pyx_v_v); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); - __Pyx_GIVEREF(__pyx_v_v); - __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L3; - } - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":137 - * self.pack(k) - * self.pack(v) - * elif isinstance(o, tuple) or isinstance(o, list): # <<<<<<<<<<<<<< - * msgpack_pack_array(&self.pk, len(o)) - * for v in o: - */ - __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyTuple_Type))); - if (!__pyx_t_1) { - __pyx_t_10 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyList_Type))); - __pyx_t_11 = __pyx_t_10; - } else { - __pyx_t_11 = __pyx_t_1; - } - if (__pyx_t_11) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":138 - * self.pack(v) - * elif isinstance(o, tuple) or isinstance(o, list): - * msgpack_pack_array(&self.pk, len(o)) # <<<<<<<<<<<<<< - * for v in o: - * self.pack(v) - */ - __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - msgpack_pack_array((&__pyx_v_self->pk), __pyx_t_6); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":139 - * elif isinstance(o, tuple) or isinstance(o, list): - * msgpack_pack_array(&self.pk, len(o)) - * for v in o: # <<<<<<<<<<<<<< - * self.pack(v) - * else: - */ - if (PyList_CheckExact(__pyx_v_o) || PyTuple_CheckExact(__pyx_v_o)) { - __pyx_t_6 = 0; __pyx_t_8 = __pyx_v_o; __Pyx_INCREF(__pyx_t_8); - } else { - __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - } - for (;;) { - if (likely(PyList_CheckExact(__pyx_t_8))) { - if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_8)) break; - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; - } else if (likely(PyTuple_CheckExact(__pyx_t_8))) { - if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_8)) break; - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; - } else { - __pyx_t_7 = PyIter_Next(__pyx_t_8); - if (!__pyx_t_7) { - if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - break; - } - __Pyx_GOTREF(__pyx_t_7); - } - __Pyx_DECREF(__pyx_v_v); - __pyx_v_v = __pyx_t_7; - __pyx_t_7 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":140 - * msgpack_pack_array(&self.pk, len(o)) - * for v in o: - * self.pack(v) # <<<<<<<<<<<<<< - * else: - * # TODO: Serialize with defalt() like simplejson. - */ - __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_INCREF(__pyx_v_v); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); - __Pyx_GIVEREF(__pyx_v_v); - __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - } - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - goto __pyx_L3; - } - /*else*/ { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":143 - * else: - * # TODO: Serialize with defalt() like simplejson. - * raise TypeError, "can't serialize %r" % (o,) # <<<<<<<<<<<<<< - * - * def pack(self, obj, flush=True): - */ - __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_8)); - __Pyx_INCREF(__pyx_v_o); - PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_o); - __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_9 = PyNumber_Remainder(__pyx_kp_4, ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; - __Pyx_Raise(__pyx_builtin_TypeError, __pyx_t_9, 0); - __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_1); - __Pyx_XDECREF(__pyx_2); - __Pyx_XDECREF(__pyx_3); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("msgpack.Packer.__pack"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_k); - __Pyx_DECREF(__pyx_v_v); - __Pyx_DECREF(__pyx_v_o); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":145 - * raise TypeError, "can't serialize %r" % (o,) - * - * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< - * self.__pack(obj) - * if flush: - */ - -static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_obj = 0; - PyObject *__pyx_v_flush = 0; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_kp_obj,&__pyx_kp_flush,0}; - __Pyx_SetupRefcountContext("pack"); - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - values[1] = __pyx_k_1; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_obj); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 1) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_flush); - if (unlikely(value)) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_obj = values[0]; - __pyx_v_flush = values[1]; - } else { - __pyx_v_flush = __pyx_k_1; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: __pyx_v_flush = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: __pyx_v_obj = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("pack", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("msgpack.Packer.pack"); - return NULL; - __pyx_L4_argument_unpacking_done:; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":146 - * - * def pack(self, obj, flush=True): - * self.__pack(obj) # <<<<<<<<<<<<<< - * if flush: - * self.flush() - */ - __pyx_t_1 = ((struct __pyx_vtabstruct_7msgpack_Packer *)((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->__pyx_vtab)->__pack(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self), __pyx_v_obj); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":147 - * def pack(self, obj, flush=True): - * self.__pack(obj) - * if flush: # <<<<<<<<<<<<<< - * self.flush() - * - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_flush); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":148 - * self.__pack(obj) - * if flush: - * self.flush() # <<<<<<<<<<<<<< - * - * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L6; - } - __pyx_L6:; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("msgpack.Packer.pack"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":150 - * self.flush() - * - * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): # <<<<<<<<<<<<<< - * if packer.length + l > packer.allocated: - * if packer.length > 0: - */ - -static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__pyx_v_packer, const char* __pyx_v_b, unsigned int __pyx_v_l) { - int __pyx_r; - int __pyx_t_1; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - __Pyx_SetupRefcountContext("_packer_write"); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":151 - * - * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): - * if packer.length + l > packer.allocated: # <<<<<<<<<<<<<< - * if packer.length > 0: - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - */ - __pyx_t_1 = ((__pyx_v_packer->length + __pyx_v_l) > __pyx_v_packer->allocated); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":152 - * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): - * if packer.length + l > packer.allocated: - * if packer.length > 0: # <<<<<<<<<<<<<< - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - * if l > 64: - */ - __pyx_t_1 = (__pyx_v_packer->length > 0); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":153 - * if packer.length + l > packer.allocated: - * if packer.length > 0: - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) # <<<<<<<<<<<<<< - * if l > 64: - * packer.strm.write(PyString_FromStringAndSize(b, l)) - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyString_FromStringAndSize(__pyx_v_packer->buff, __pyx_v_packer->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L4; - } - __pyx_L4:; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":154 - * if packer.length > 0: - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - * if l > 64: # <<<<<<<<<<<<<< - * packer.strm.write(PyString_FromStringAndSize(b, l)) - * packer.length = 0 - */ - __pyx_t_1 = (__pyx_v_l > 64); - if (__pyx_t_1) { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":155 - * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - * if l > 64: - * packer.strm.write(PyString_FromStringAndSize(b, l)) # <<<<<<<<<<<<<< - * packer.length = 0 - * else: - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyString_FromStringAndSize(__pyx_v_b, __pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":156 - * if l > 64: - * packer.strm.write(PyString_FromStringAndSize(b, l)) - * packer.length = 0 # <<<<<<<<<<<<<< - * else: - * memcpy(packer.buff, b, l) - */ - __pyx_v_packer->length = 0; - goto __pyx_L5; - } - /*else*/ { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":158 - * packer.length = 0 - * else: - * memcpy(packer.buff, b, l) # <<<<<<<<<<<<<< - * packer.length = l - * else: - */ - memcpy(__pyx_v_packer->buff, __pyx_v_b, __pyx_v_l); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":159 - * else: - * memcpy(packer.buff, b, l) - * packer.length = l # <<<<<<<<<<<<<< - * else: - * memcpy(packer.buff + packer.length, b, l) - */ - __pyx_v_packer->length = __pyx_v_l; - } - __pyx_L5:; - goto __pyx_L3; - } - /*else*/ { - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":161 - * packer.length = l - * else: - * memcpy(packer.buff + packer.length, b, l) # <<<<<<<<<<<<<< - * packer.length += l - * return 0 - */ - memcpy((__pyx_v_packer->buff + __pyx_v_packer->length), __pyx_v_b, __pyx_v_l); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":162 - * else: - * memcpy(packer.buff + packer.length, b, l) - * packer.length += l # <<<<<<<<<<<<<< - * return 0 - * - */ - __pyx_v_packer->length += __pyx_v_l; - } - __pyx_L3:; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":163 - * memcpy(packer.buff + packer.length, b, l) - * packer.length += l - * return 0 # <<<<<<<<<<<<<< - * - * def pack(object o, object stream): - */ - __pyx_r = 0; - goto __pyx_L0; - - __pyx_r = 0; - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_WriteUnraisable("msgpack._packer_write"); - __pyx_r = 0; - __pyx_L0:; - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":165 - * return 0 - * - * def pack(object o, object stream): # <<<<<<<<<<<<<< - * packer = Packer(stream) - * packer.pack(o) - */ - -static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_o = 0; - PyObject *__pyx_v_stream = 0; - PyObject *__pyx_v_packer; - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - static PyObject **__pyx_pyargnames[] = {&__pyx_kp_o,&__pyx_kp_stream,0}; - __Pyx_SetupRefcountContext("pack"); - __pyx_self = __pyx_self; - if (unlikely(__pyx_kwds)) { - Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); - PyObject* values[2] = {0,0}; - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_o); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_stream); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - __pyx_v_o = values[0]; - __pyx_v_stream = values[1]; - } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { - goto __pyx_L5_argtuple_error; - } else { - __pyx_v_o = PyTuple_GET_ITEM(__pyx_args, 0); - __pyx_v_stream = PyTuple_GET_ITEM(__pyx_args, 1); - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("msgpack.pack"); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":166 - * - * def pack(object o, object stream): - * packer = Packer(stream) # <<<<<<<<<<<<<< - * packer.pack(o) - * packer.flush() - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_v_stream); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stream); - __Pyx_GIVEREF(__pyx_v_stream); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_packer); - __pyx_v_packer = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":167 - * def pack(object o, object stream): - * packer = Packer(stream) - * packer.pack(o) # <<<<<<<<<<<<<< - * packer.flush() - * - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_v_o); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); - __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":168 - * packer = Packer(stream) - * packer.pack(o) - * packer.flush() # <<<<<<<<<<<<<< - * - * def packs(object o): - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("msgpack.pack"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_packer); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":170 - * packer.flush() - * - * def packs(object o): # <<<<<<<<<<<<<< - * buf = StringIO() - * packer = Packer(buf) - */ - -static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v_o); /*proto*/ -static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v_o) { - PyObject *__pyx_v_buf; - PyObject *__pyx_v_packer; - PyObject *__pyx_r = NULL; - PyObject *__pyx_1 = 0; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - __Pyx_SetupRefcountContext("packs"); - __pyx_self = __pyx_self; - __pyx_v_buf = Py_None; __Pyx_INCREF(Py_None); - __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":171 - * - * def packs(object o): - * buf = StringIO() # <<<<<<<<<<<<<< - * packer = Packer(buf) - * packer.pack(o) - */ - __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_StringIO); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - __Pyx_DECREF(__pyx_v_buf); - __pyx_v_buf = __pyx_t_1; - __pyx_t_1 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":172 - * def packs(object o): - * buf = StringIO() - * packer = Packer(buf) # <<<<<<<<<<<<<< - * packer.pack(o) - * packer.flush() - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_v_buf); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_buf); - __Pyx_GIVEREF(__pyx_v_buf); - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_packer); - __pyx_v_packer = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":173 - * buf = StringIO() - * packer = Packer(buf) - * packer.pack(o) # <<<<<<<<<<<<<< - * packer.flush() - * return buf.getvalue() - */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_v_o); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); - __Pyx_GIVEREF(__pyx_v_o); - __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":174 - * packer = Packer(buf) - * packer.pack(o) - * packer.flush() # <<<<<<<<<<<<<< - * return buf.getvalue() - * - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":175 - * packer.pack(o) - * packer.flush() - * return buf.getvalue() # <<<<<<<<<<<<<< - * - * cdef extern from "unpack.h": - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_getvalue); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_1); - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("msgpack.packs"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_buf); - __Pyx_DECREF(__pyx_v_packer); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":186 - * - * - * def unpacks(object packed_bytes): # <<<<<<<<<<<<<< - * """Unpack packed_bytes to object. Returns unpacked object.""" - * cdef const_char_ptr p = packed_bytes - */ - -static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx_v_packed_bytes); /*proto*/ -static char __pyx_doc_7msgpack_unpacks[] = "Unpack packed_bytes to object. Returns unpacked object."; -static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx_v_packed_bytes) { - const char* __pyx_v_p; - template_context __pyx_v_ctx; - size_t __pyx_v_off; - PyObject *__pyx_r = NULL; - const char* __pyx_t_1; - Py_ssize_t __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - __Pyx_SetupRefcountContext("unpacks"); - __pyx_self = __pyx_self; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":188 - * def unpacks(object packed_bytes): - * """Unpack packed_bytes to object. Returns unpacked object.""" - * cdef const_char_ptr p = packed_bytes # <<<<<<<<<<<<<< - * cdef template_context ctx - * cdef size_t off = 0 - */ - __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_packed_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_p = __pyx_t_1; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":190 - * cdef const_char_ptr p = packed_bytes - * cdef template_context ctx - * cdef size_t off = 0 # <<<<<<<<<<<<<< - * template_init(&ctx) - * template_execute(&ctx, p, len(packed_bytes), &off) - */ - __pyx_v_off = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":191 - * cdef template_context ctx - * cdef size_t off = 0 - * template_init(&ctx) # <<<<<<<<<<<<<< - * template_execute(&ctx, p, len(packed_bytes), &off) - * return template_data(&ctx) - */ - template_init((&__pyx_v_ctx)); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":192 - * cdef size_t off = 0 - * template_init(&ctx) - * template_execute(&ctx, p, len(packed_bytes), &off) # <<<<<<<<<<<<<< - * return template_data(&ctx) - * - */ - __pyx_t_2 = PyObject_Length(__pyx_v_packed_bytes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - template_execute((&__pyx_v_ctx), __pyx_v_p, __pyx_t_2, (&__pyx_v_off)); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":193 - * template_init(&ctx) - * template_execute(&ctx, p, len(packed_bytes), &off) - * return template_data(&ctx) # <<<<<<<<<<<<<< - * - * def unpack(object stream): - */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = template_data((&__pyx_v_ctx)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("msgpack.unpacks"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} - -/* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":195 - * return template_data(&ctx) - * - * def unpack(object stream): # <<<<<<<<<<<<<< - * """unpack from stream.""" - * packed = stream.read() - */ - -static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_v_stream); /*proto*/ -static char __pyx_doc_7msgpack_unpack[] = "unpack from stream."; -static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_v_stream) { - PyObject *__pyx_v_packed; - PyObject *__pyx_r = NULL; - PyObject *__pyx_1 = 0; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - __Pyx_SetupRefcountContext("unpack"); - __pyx_self = __pyx_self; - __pyx_v_packed = Py_None; __Pyx_INCREF(Py_None); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":197 - * def unpack(object stream): - * """unpack from stream.""" - * packed = stream.read() # <<<<<<<<<<<<<< - * return unpacks(packed) - * - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_v_packed); - __pyx_v_packed = __pyx_t_2; - __pyx_t_2 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":198 - * """unpack from stream.""" - * packed = stream.read() - * return unpacks(packed) # <<<<<<<<<<<<<< - * - * cdef class Unpacker: - */ - __Pyx_XDECREF(__pyx_r); - __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __Pyx_INCREF(__pyx_v_packed); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_packed); - __Pyx_GIVEREF(__pyx_v_packed); - __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_1); - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("msgpack.unpack"); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(__pyx_v_packed); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_FinishRefcountContext(); - return __pyx_r; -} -static struct __pyx_vtabstruct_7msgpack_Packer __pyx_vtable_7msgpack_Packer; - -static PyObject *__pyx_tp_new_7msgpack_Packer(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_7msgpack_Packer *p; - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - p = ((struct __pyx_obj_7msgpack_Packer *)o); - p->__pyx_vtab = __pyx_vtabptr_7msgpack_Packer; - p->strm = Py_None; Py_INCREF(Py_None); - return o; -} - -static void __pyx_tp_dealloc_7msgpack_Packer(PyObject *o) { - struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; - Py_XDECREF(p->strm); - (*Py_TYPE(o)->tp_free)(o); -} - -static int __pyx_tp_traverse_7msgpack_Packer(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; - if (p->strm) { - e = (*v)(p->strm, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_7msgpack_Packer(PyObject *o) { - struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; - PyObject* tmp; - tmp = ((PyObject*)p->strm); - p->strm = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static struct PyMethodDef __pyx_methods_7msgpack_Packer[] = { - {__Pyx_NAMESTR("__del__"), (PyCFunction)__pyx_pf_7msgpack_6Packer___del__, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("flush"), (PyCFunction)__pyx_pf_7msgpack_6Packer_flush, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_flush)}, - {__Pyx_NAMESTR("pack_list"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_list, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_list)}, - {__Pyx_NAMESTR("pack_dict"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_dict, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_dict)}, - {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Packer = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - 0, /*nb_long*/ - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_Packer = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_Packer = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Packer = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_7msgpack_Packer = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("msgpack.Packer"), /*tp_name*/ - sizeof(struct __pyx_obj_7msgpack_Packer), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_7msgpack_Packer, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &__pyx_tp_as_number_Packer, /*tp_as_number*/ - &__pyx_tp_as_sequence_Packer, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Packer, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Packer, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - __Pyx_DOCSTR("Packer that pack data into strm.\n\n strm must have `write(bytes)` method.\n size specifies local buffer size.\n "), /*tp_doc*/ - __pyx_tp_traverse_7msgpack_Packer, /*tp_traverse*/ - __pyx_tp_clear_7msgpack_Packer, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_7msgpack_Packer, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - __pyx_pf_7msgpack_6Packer___init__, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_7msgpack_Packer, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ -}; - -static PyObject *__pyx_tp_new_7msgpack_Unpacker(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o = (*t->tp_alloc)(t, 0); - if (!o) return 0; - return o; -} - -static void __pyx_tp_dealloc_7msgpack_Unpacker(PyObject *o) { - (*Py_TYPE(o)->tp_free)(o); -} - -static struct PyMethodDef __pyx_methods_7msgpack_Unpacker[] = { - {0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Unpacker = { - 0, /*nb_add*/ - 0, /*nb_subtract*/ - 0, /*nb_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_divide*/ - #endif - 0, /*nb_remainder*/ - 0, /*nb_divmod*/ - 0, /*nb_power*/ - 0, /*nb_negative*/ - 0, /*nb_positive*/ - 0, /*nb_absolute*/ - 0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_coerce*/ - #endif - 0, /*nb_int*/ - 0, /*nb_long*/ - 0, /*nb_float*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_oct*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*nb_hex*/ - #endif - 0, /*nb_inplace_add*/ - 0, /*nb_inplace_subtract*/ - 0, /*nb_inplace_multiply*/ - #if PY_MAJOR_VERSION < 3 - 0, /*nb_inplace_divide*/ - #endif - 0, /*nb_inplace_remainder*/ - 0, /*nb_inplace_power*/ - 0, /*nb_inplace_lshift*/ - 0, /*nb_inplace_rshift*/ - 0, /*nb_inplace_and*/ - 0, /*nb_inplace_xor*/ - 0, /*nb_inplace_or*/ - 0, /*nb_floor_divide*/ - 0, /*nb_true_divide*/ - 0, /*nb_inplace_floor_divide*/ - 0, /*nb_inplace_true_divide*/ - #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) - 0, /*nb_index*/ - #endif -}; - -static PySequenceMethods __pyx_tp_as_sequence_Unpacker = { - 0, /*sq_length*/ - 0, /*sq_concat*/ - 0, /*sq_repeat*/ - 0, /*sq_item*/ - 0, /*sq_slice*/ - 0, /*sq_ass_item*/ - 0, /*sq_ass_slice*/ - 0, /*sq_contains*/ - 0, /*sq_inplace_concat*/ - 0, /*sq_inplace_repeat*/ -}; - -static PyMappingMethods __pyx_tp_as_mapping_Unpacker = { - 0, /*mp_length*/ - 0, /*mp_subscript*/ - 0, /*mp_ass_subscript*/ -}; - -static PyBufferProcs __pyx_tp_as_buffer_Unpacker = { - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getreadbuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getwritebuffer*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getsegcount*/ - #endif - #if PY_MAJOR_VERSION < 3 - 0, /*bf_getcharbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_getbuffer*/ - #endif - #if PY_VERSION_HEX >= 0x02060000 - 0, /*bf_releasebuffer*/ - #endif -}; - -PyTypeObject __pyx_type_7msgpack_Unpacker = { - PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("msgpack.Unpacker"), /*tp_name*/ - sizeof(struct __pyx_obj_7msgpack_Unpacker), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - __pyx_tp_dealloc_7msgpack_Unpacker, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - &__pyx_tp_as_number_Unpacker, /*tp_as_number*/ - &__pyx_tp_as_sequence_Unpacker, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Unpacker, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Unpacker, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ - __Pyx_DOCSTR("Do nothing. This function is for symmetric to Packer"), /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - __pyx_methods_7msgpack_Unpacker, /*tp_methods*/ - 0, /*tp_members*/ - 0, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - __pyx_tp_new_7msgpack_Unpacker, /*tp_new*/ - 0, /*tp_free*/ - 0, /*tp_is_gc*/ - 0, /*tp_bases*/ - 0, /*tp_mro*/ - 0, /*tp_cache*/ - 0, /*tp_subclasses*/ - 0, /*tp_weaklist*/ -}; - -static struct PyMethodDef __pyx_methods[] = { - {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_pack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("packs"), (PyCFunction)__pyx_pf_7msgpack_packs, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("unpacks"), (PyCFunction)__pyx_pf_7msgpack_unpacks, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_unpacks)}, - {__Pyx_NAMESTR("unpack"), (PyCFunction)__pyx_pf_7msgpack_unpack, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_unpack)}, - {0, 0, 0, 0} -}; - -static void __pyx_init_filenames(void); /*proto*/ - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef __pyx_moduledef = { - PyModuleDef_HEAD_INIT, - __Pyx_NAMESTR("msgpack"), - 0, /* m_doc */ - -1, /* m_size */ - __pyx_methods /* m_methods */, - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ -}; -#endif - -static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp___init__, __pyx_k___init__, sizeof(__pyx_k___init__), 1, 1, 1}, - {&__pyx_kp___del__, __pyx_k___del__, sizeof(__pyx_k___del__), 1, 1, 1}, - {&__pyx_kp_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 1, 1, 1}, - {&__pyx_kp_pack_list, __pyx_k_pack_list, sizeof(__pyx_k_pack_list), 1, 1, 1}, - {&__pyx_kp_pack_dict, __pyx_k_pack_dict, sizeof(__pyx_k_pack_dict), 1, 1, 1}, - {&__pyx_kp_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 1, 1, 1}, - {&__pyx_kp_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 1, 1, 1}, - {&__pyx_kp_strm, __pyx_k_strm, sizeof(__pyx_k_strm), 1, 1, 1}, - {&__pyx_kp_size, __pyx_k_size, sizeof(__pyx_k_size), 1, 1, 1}, - {&__pyx_kp_len, __pyx_k_len, sizeof(__pyx_k_len), 1, 1, 1}, - {&__pyx_kp_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 1, 1, 1}, - {&__pyx_kp_o, __pyx_k_o, sizeof(__pyx_k_o), 1, 1, 1}, - {&__pyx_kp_stream, __pyx_k_stream, sizeof(__pyx_k_stream), 1, 1, 1}, - {&__pyx_kp_packed_bytes, __pyx_k_packed_bytes, sizeof(__pyx_k_packed_bytes), 1, 1, 1}, - {&__pyx_kp_cStringIO, __pyx_k_cStringIO, sizeof(__pyx_k_cStringIO), 1, 1, 1}, - {&__pyx_kp_StringIO, __pyx_k_StringIO, sizeof(__pyx_k_StringIO), 1, 1, 1}, - {&__pyx_kp_staticmethod, __pyx_k_staticmethod, sizeof(__pyx_k_staticmethod), 1, 1, 1}, - {&__pyx_kp_unpacks, __pyx_k_unpacks, sizeof(__pyx_k_unpacks), 1, 1, 1}, - {&__pyx_kp_write, __pyx_k_write, sizeof(__pyx_k_write), 1, 1, 1}, - {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 1, 0}, - {&__pyx_kp_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 1, 1, 1}, - {&__pyx_kp_iteritems, __pyx_k_iteritems, sizeof(__pyx_k_iteritems), 1, 1, 1}, - {&__pyx_kp_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 1, 1, 1}, - {&__pyx_kp_getvalue, __pyx_k_getvalue, sizeof(__pyx_k_getvalue), 1, 1, 1}, - {&__pyx_kp_read, __pyx_k_read, sizeof(__pyx_k_read), 1, 1, 1}, - {&__pyx_kp_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 0}, - {&__pyx_kp_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 0}, - {0, 0, 0, 0, 0, 0} -}; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_staticmethod = __Pyx_GetName(__pyx_b, __pyx_kp_staticmethod); if (!__pyx_builtin_staticmethod) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_kp_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - return 0; - __pyx_L1_error:; - return -1; -} - -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - return 0; - __pyx_L1_error:; - return -1; -} - -#if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initmsgpack(void); /*proto*/ -PyMODINIT_FUNC initmsgpack(void) -#else -PyMODINIT_FUNC PyInit_msgpack(void); /*proto*/ -PyMODINIT_FUNC PyInit_msgpack(void) -#endif -{ - PyObject *__pyx_1 = 0; - PyObject *__pyx_2 = 0; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - #ifdef CYTHON_REFNANNY - void* __pyx_refchk = NULL; - __Pyx_Refnanny = __Pyx_ImportRefcountAPI("refnanny"); - if (!__Pyx_Refnanny) { - PyErr_Clear(); - __Pyx_Refnanny = __Pyx_ImportRefcountAPI("Cython.Runtime.refnanny"); - if (!__Pyx_Refnanny) - Py_FatalError("failed to import refnanny module"); - } - __pyx_refchk = __Pyx_Refnanny->NewContext("PyMODINIT_FUNC PyInit_msgpack(void)", __LINE__, __FILE__); - #endif - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Library function declarations ---*/ - __pyx_init_filenames(); - /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ - PyEval_InitThreads(); - #endif - #endif - /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Module creation code ---*/ - #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("msgpack"), __pyx_methods, 0, 0, PYTHON_API_VERSION); - #else - __pyx_m = PyModule_Create(&__pyx_moduledef); - #endif - if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - #if PY_MAJOR_VERSION < 3 - Py_INCREF(__pyx_m); - #endif - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); - if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_skip_dispatch = 0; - /*--- Global init code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - __pyx_vtabptr_7msgpack_Packer = &__pyx_vtable_7msgpack_Packer; - #if PY_MAJOR_VERSION >= 3 - __pyx_vtable_7msgpack_Packer.__pack = (PyObject *(*)(struct __pyx_obj_7msgpack_Packer *, PyObject *))__pyx_f_7msgpack_6Packer___pack; - #else - *(void(**)(void))&__pyx_vtable_7msgpack_Packer.__pack = (void(*)(void))__pyx_f_7msgpack_6Packer___pack; - #endif - if (PyType_Ready(&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetVtable(__pyx_type_7msgpack_Packer.tp_dict, __pyx_vtabptr_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Packer", (PyObject *)&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_7msgpack_Packer = &__pyx_type_7msgpack_Packer; - if (PyType_Ready(&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Unpacker", (PyObject *)&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_7msgpack_Unpacker = &__pyx_type_7msgpack_Unpacker; - /*--- Type import code ---*/ - /*--- Function import code ---*/ - /*--- Execution code ---*/ - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":3 - * # coding: utf-8 - * - * from cStringIO import StringIO # <<<<<<<<<<<<<< - * - * cdef extern from "Python.h": - */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __Pyx_INCREF(__pyx_kp_StringIO); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_StringIO); - __Pyx_GIVEREF(__pyx_kp_StringIO); - __pyx_1 = __Pyx_Import(__pyx_kp_cStringIO, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_StringIO); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_2); - if (PyObject_SetAttr(__pyx_m, __pyx_kp_StringIO, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_2); __pyx_2 = 0; - __Pyx_DECREF(__pyx_1); __pyx_1 = 0; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":37 - * - * - * cdef int BUFF_SIZE=2*1024 # <<<<<<<<<<<<<< - * - * cdef class Packer: - */ - __pyx_v_7msgpack_BUFF_SIZE = 2048; - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":145 - * raise TypeError, "can't serialize %r" % (o,) - * - * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< - * self.__pack(obj) - * if flush: - */ - __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_k_1 = __pyx_t_1; - __pyx_t_1 = 0; - __Pyx_GIVEREF(__pyx_k_1); - - /* "/home/inada-n/work/msgpack/msgpack-py/python/msgpack.pyx":202 - * cdef class Unpacker: - * """Do nothing. This function is for symmetric to Packer""" - * unpack = staticmethod(unpacks) # <<<<<<<<<<<<<< - */ - __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_1); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_1); - __Pyx_GIVEREF(__pyx_1); - __pyx_1 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_staticmethod, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (PyDict_SetItem((PyObject *)__pyx_ptype_7msgpack_Unpacker->tp_dict, __pyx_kp_unpack, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - PyType_Modified(__pyx_ptype_7msgpack_Unpacker); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_1); - __Pyx_XDECREF(__pyx_2); - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("msgpack"); - Py_DECREF(__pyx_m); __pyx_m = 0; - __pyx_L0:; - __Pyx_FinishRefcountContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else - return __pyx_m; - #endif -} - -static const char *__pyx_filenames[] = { - "msgpack.pyx", -}; - -/* Runtime support code */ - -static void __pyx_init_filenames(void) { - __pyx_f = __pyx_filenames; -} - -static void __Pyx_RaiseDoubleKeywordsError( - const char* func_name, - PyObject* kw_name) -{ - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION >= 3 - "%s() got multiple values for keyword argument '%U'", func_name, kw_name); - #else - "%s() got multiple values for keyword argument '%s'", func_name, - PyString_AS_STRING(kw_name)); - #endif -} - -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *number, *more_or_less; - - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; - } - if (exact) { - more_or_less = "exactly"; - } - number = (num_expected == 1) ? "" : "s"; - PyErr_Format(PyExc_TypeError, - #if PY_VERSION_HEX < 0x02050000 - "%s() takes %s %d positional argument%s (%d given)", - #else - "%s() takes %s %zd positional argument%s (%zd given)", - #endif - func_name, more_or_less, num_expected, number, num_found); -} - -static int __Pyx_ParseOptionalKeywords( - PyObject *kwds, - PyObject **argnames[], - PyObject *kwds2, - PyObject *values[], - Py_ssize_t num_pos_args, - const char* function_name) -{ - PyObject *key = 0, *value = 0; - Py_ssize_t pos = 0; - PyObject*** name; - PyObject*** first_kw_arg = argnames + num_pos_args; - - while (PyDict_Next(kwds, &pos, &key, &value)) { - name = first_kw_arg; - while (*name && (**name != key)) name++; - if (*name) { - values[name-argnames] = value; - } else { - #if PY_MAJOR_VERSION < 3 - if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { - #else - if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) { - #endif - goto invalid_keyword_type; - } else { - for (name = first_kw_arg; *name; name++) { - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) break; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) break; - #endif - } - if (*name) { - values[name-argnames] = value; - } else { - /* unexpected keyword found */ - for (name=argnames; name != first_kw_arg; name++) { - if (**name == key) goto arg_passed_twice; - #if PY_MAJOR_VERSION >= 3 - if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && - PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; - #else - if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && - _PyString_Eq(**name, key)) goto arg_passed_twice; - #endif - } - if (kwds2) { - if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; - } else { - goto invalid_keyword; - } - } - } - } - } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, **name); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%s() got an unexpected keyword argument '%s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif -bad: - return -1; -} - -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) { - PyObject *__import__ = 0; - PyObject *empty_list = 0; - PyObject *module = 0; - PyObject *global_dict = 0; - PyObject *empty_dict = 0; - PyObject *list; - __import__ = __Pyx_GetAttrString(__pyx_b, "__import__"); - if (!__import__) - goto bad; - if (from_list) - list = from_list; - else { - empty_list = PyList_New(0); - if (!empty_list) - goto bad; - list = empty_list; - } - global_dict = PyModule_GetDict(__pyx_m); - if (!global_dict) - goto bad; - empty_dict = PyDict_New(); - if (!empty_dict) - goto bad; - module = PyObject_CallFunctionObjArgs(__import__, - name, global_dict, empty_dict, list, NULL); -bad: - Py_XDECREF(empty_list); - Py_XDECREF(__import__); - Py_XDECREF(empty_dict); - return module; -} - -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) - PyErr_SetObject(PyExc_NameError, name); - return result; -} - -static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { - PyErr_Format(PyExc_ValueError, - #if PY_VERSION_HEX < 0x02050000 - "need more than %d value%s to unpack", (int)index, - #else - "need more than %zd value%s to unpack", index, - #endif - (index == 1) ? "" : "s"); -} - -static INLINE void __Pyx_RaiseTooManyValuesError(void) { - PyErr_SetString(PyExc_ValueError, "too many values to unpack"); -} - -static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) { - PyObject *item; - if (!(item = PyIter_Next(iter))) { - if (!PyErr_Occurred()) { - __Pyx_RaiseNeedMoreValuesError(index); - } - } - return item; -} - -static int __Pyx_EndUnpack(PyObject *iter) { - PyObject *item; - if ((item = PyIter_Next(iter))) { - Py_DECREF(item); - __Pyx_RaiseTooManyValuesError(); - return -1; - } - else if (!PyErr_Occurred()) - return 0; - else - return -1; -} - -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { - Py_XINCREF(type); - Py_XINCREF(value); - Py_XINCREF(tb); - /* First, check the traceback argument, replacing None with NULL. */ - if (tb == Py_None) { - Py_DECREF(tb); - tb = 0; - } - else if (tb != NULL && !PyTraceBack_Check(tb)) { - PyErr_SetString(PyExc_TypeError, - "raise: arg 3 must be a traceback or None"); - goto raise_error; - } - /* Next, replace a missing value with None */ - if (value == NULL) { - value = Py_None; - Py_INCREF(value); - } - #if PY_VERSION_HEX < 0x02050000 - if (!PyClass_Check(type)) - #else - if (!PyType_Check(type)) - #endif - { - /* Raising an instance. The value should be a dummy. */ - if (value != Py_None) { - PyErr_SetString(PyExc_TypeError, - "instance exception may not have a separate value"); - goto raise_error; - } - /* Normalize to raise , */ - Py_DECREF(value); - value = type; - #if PY_VERSION_HEX < 0x02050000 - if (PyInstance_Check(type)) { - type = (PyObject*) ((PyInstanceObject*)type)->in_class; - Py_INCREF(type); - } - else { - type = 0; - PyErr_SetString(PyExc_TypeError, - "raise: exception must be an old-style class or instance"); - goto raise_error; - } - #else - type = (PyObject*) Py_TYPE(type); - Py_INCREF(type); - if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { - PyErr_SetString(PyExc_TypeError, - "raise: exception class must be a subclass of BaseException"); - goto raise_error; - } - #endif - } - __Pyx_ErrRestore(type, value, tb); - return; -raise_error: - Py_XDECREF(value); - Py_XDECREF(type); - Py_XDECREF(tb); - return; -} - -static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { - PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); - -#if PY_MAJOR_VERSION >= 3 - /* Note: this is a temporary work-around to prevent crashes in Python 3.0 */ - if ((tstate->exc_type != NULL) & (tstate->exc_type != Py_None)) { - tmp_type = tstate->exc_type; - tmp_value = tstate->exc_value; - tmp_tb = tstate->exc_traceback; - PyErr_NormalizeException(&type, &value, &tb); - PyErr_NormalizeException(&tmp_type, &tmp_value, &tmp_tb); - tstate->exc_type = 0; - tstate->exc_value = 0; - tstate->exc_traceback = 0; - PyException_SetContext(value, tmp_value); - Py_DECREF(tmp_type); - Py_XDECREF(tmp_tb); - } -#endif - - tmp_type = tstate->curexc_type; - tmp_value = tstate->curexc_value; - tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = type; - tstate->curexc_value = value; - tstate->curexc_traceback = tb; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -} - -static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { - PyThreadState *tstate = PyThreadState_GET(); - *type = tstate->curexc_type; - *value = tstate->curexc_value; - *tb = tstate->curexc_traceback; - - tstate->curexc_type = 0; - tstate->curexc_value = 0; - tstate->curexc_traceback = 0; -} - - -static INLINE int __Pyx_StrEq(const char *s1, const char *s2) { - while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } - return *s1 == *s2; -} - -static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { - if (sizeof(unsigned char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned char)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (unsigned char)-1; - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned char"); - return (unsigned char)-1; - } - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to unsigned char"); - return (unsigned char)-1; - } - return (unsigned char)val; - } - return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); -} - -static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { - if (sizeof(unsigned short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned short)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (unsigned short)-1; - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned short"); - return (unsigned short)-1; - } - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to unsigned short"); - return (unsigned short)-1; - } - return (unsigned short)val; - } - return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); -} - -static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { - if (sizeof(unsigned int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(unsigned int)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (unsigned int)-1; - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned int"); - return (unsigned int)-1; - } - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to unsigned int"); - return (unsigned int)-1; - } - return (unsigned int)val; - } - return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); -} - -static INLINE char __Pyx_PyInt_AsChar(PyObject* x) { - if (sizeof(char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(char)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (char)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to char"); - return (char)-1; - } - return (char)val; - } - return (char)__Pyx_PyInt_AsLong(x); -} - -static INLINE short __Pyx_PyInt_AsShort(PyObject* x) { - if (sizeof(short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(short)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (short)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to short"); - return (short)-1; - } - return (short)val; - } - return (short)__Pyx_PyInt_AsLong(x); -} - -static INLINE int __Pyx_PyInt_AsInt(PyObject* x) { - if (sizeof(int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(int)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (int)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to int"); - return (int)-1; - } - return (int)val; - } - return (int)__Pyx_PyInt_AsLong(x); -} - -static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { - if (sizeof(signed char) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed char)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (signed char)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to signed char"); - return (signed char)-1; - } - return (signed char)val; - } - return (signed char)__Pyx_PyInt_AsSignedLong(x); -} - -static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { - if (sizeof(signed short) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed short)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (signed short)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to signed short"); - return (signed short)-1; - } - return (signed short)val; - } - return (signed short)__Pyx_PyInt_AsSignedLong(x); -} - -static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { - if (sizeof(signed int) < sizeof(long)) { - long val = __Pyx_PyInt_AsLong(x); - if (unlikely(val != (long)(signed int)val)) { - if (unlikely(val == -1 && PyErr_Occurred())) - return (signed int)-1; - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to signed int"); - return (signed int)-1; - } - return (signed int)val; - } - return (signed int)__Pyx_PyInt_AsSignedLong(x); -} - -static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return (unsigned long)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - return (unsigned long)-1; - } - return PyLong_AsUnsignedLong(x); - } else { - unsigned long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned long)-1; - val = __Pyx_PyInt_AsUnsignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - if (unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return (unsigned PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned PY_LONG_LONG"); - return (unsigned PY_LONG_LONG)-1; - } - return PyLong_AsUnsignedLongLong(x); - } else { - unsigned PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (unsigned PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsUnsignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE long __Pyx_PyInt_AsLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - return (long)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - return PyLong_AsLong(x); - } else { - long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (long)-1; - val = __Pyx_PyInt_AsLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - return (PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - return PyLong_AsLongLong(x); - } else { - PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - return (signed long)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - return PyLong_AsLong(x); - } else { - signed long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed long)-1; - val = __Pyx_PyInt_AsSignedLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { -#if PY_VERSION_HEX < 0x03000000 - if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { - long val = PyInt_AS_LONG(x); - return (signed PY_LONG_LONG)val; - } else -#endif - if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { - return PyLong_AsLongLong(x); - } else { - signed PY_LONG_LONG val; - PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (signed PY_LONG_LONG)-1; - val = __Pyx_PyInt_AsSignedLongLong(tmp); - Py_DECREF(tmp); - return val; - } -} - -static void __Pyx_WriteUnraisable(const char *name) { - PyObject *old_exc, *old_val, *old_tb; - PyObject *ctx; - __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); - #if PY_MAJOR_VERSION < 3 - ctx = PyString_FromString(name); - #else - ctx = PyUnicode_FromString(name); - #endif - __Pyx_ErrRestore(old_exc, old_val, old_tb); - if (!ctx) { - PyErr_WriteUnraisable(Py_None); - } else { - PyErr_WriteUnraisable(ctx); - Py_DECREF(ctx); - } -} - -static int __Pyx_SetVtable(PyObject *dict, void *vtable) { - PyObject *pycobj = 0; - int result; - - pycobj = PyCObject_FromVoidPtr(vtable, 0); - if (!pycobj) - goto bad; - if (PyDict_SetItemString(dict, "__pyx_vtable__", pycobj) < 0) - goto bad; - result = 0; - goto done; - -bad: - result = -1; -done: - Py_XDECREF(pycobj); - return result; -} - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" - -static void __Pyx_AddTraceback(const char *funcname) { - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - PyObject *py_globals = 0; - PyObject *empty_string = 0; - PyCodeObject *py_code = 0; - PyFrameObject *py_frame = 0; - - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(__pyx_filename); - #else - py_srcfile = PyUnicode_FromString(__pyx_filename); - #endif - if (!py_srcfile) goto bad; - if (__pyx_clineno) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - #if PY_MAJOR_VERSION < 3 - empty_string = PyString_FromStringAndSize("", 0); - #else - empty_string = PyBytes_FromStringAndSize("", 0); - #endif - if (!empty_string) goto bad; - py_code = PyCode_New( - 0, /*int argcount,*/ - #if PY_MAJOR_VERSION >= 3 - 0, /*int kwonlyargcount,*/ - #endif - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - empty_string, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - __pyx_lineno, /*int firstlineno,*/ - empty_string /*PyObject *lnotab*/ - ); - if (!py_code) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = __pyx_lineno; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - Py_XDECREF(empty_string); - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { - while (t->p) { - #if PY_MAJOR_VERSION < 3 - if (t->is_unicode && (!t->is_identifier)) { - *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); - } else if (t->intern) { - *t->p = PyString_InternFromString(t->s); - } else { - *t->p = PyString_FromStringAndSize(t->s, t->n - 1); - } - #else /* Python 3+ has unicode identifiers */ - if (t->is_identifier || (t->is_unicode && t->intern)) { - *t->p = PyUnicode_InternFromString(t->s); - } else if (t->is_unicode) { - *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); - } else { - *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); - } - #endif - if (!*t->p) - return -1; - ++t; - } - return 0; -} - -/* Type Conversion Functions */ - -static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - if (x == Py_True) return 1; - else if ((x == Py_False) | (x == Py_None)) return 0; - else return PyObject_IsTrue(x); -} - -static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { - PyNumberMethods *m; - const char *name = NULL; - PyObject *res = NULL; -#if PY_VERSION_HEX < 0x03000000 - if (PyInt_Check(x) || PyLong_Check(x)) -#else - if (PyLong_Check(x)) -#endif - return Py_INCREF(x), x; - m = Py_TYPE(x)->tp_as_number; -#if PY_VERSION_HEX < 0x03000000 - if (m && m->nb_long) { - name = "long"; - res = PyNumber_Long(x); - } - else if (m && m->nb_int) { - name = "int"; - res = PyNumber_Int(x); - } -#else - if (m && m->nb_int) { - name = "int"; - res = PyNumber_Long(x); - } -#endif - if (res) { -#if PY_VERSION_HEX < 0x03000000 - if (!PyInt_Check(res) && !PyLong_Check(res)) { -#else - if (!PyLong_Check(res)) { -#endif - PyErr_Format(PyExc_TypeError, - "__%s__ returned non-%s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; - } - } - else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "an integer is required"); - } - return res; -} - -static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { - Py_ssize_t ival; - PyObject* x = PyNumber_Index(b); - if (!x) return -1; - ival = PyInt_AsSsize_t(x); - Py_DECREF(x); - return ival; -} - -static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif -} - -static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { - unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); - if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { - return (size_t)-1; - } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { - PyErr_SetString(PyExc_OverflowError, - "value too large to convert to size_t"); - return (size_t)-1; - } - return (size_t)val; -} - - diff --git a/python/msgpack.cpp b/python/msgpack.cpp new file mode 100644 index 0000000..760f0c0 --- /dev/null +++ b/python/msgpack.cpp @@ -0,0 +1,3440 @@ +/* Generated by Cython 0.11.2 on Mon Jun 22 02:56:08 2009 */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#include "structmember.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#if PY_VERSION_HEX < 0x02040000 + #define METH_COEXIST 0 + #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) +#endif +#if PY_VERSION_HEX < 0x02050000 + typedef int Py_ssize_t; + #define PY_SSIZE_T_MAX INT_MAX + #define PY_SSIZE_T_MIN INT_MIN + #define PY_FORMAT_SIZE_T "" + #define PyInt_FromSsize_t(z) PyInt_FromLong(z) + #define PyInt_AsSsize_t(o) PyInt_AsLong(o) + #define PyNumber_Index(o) PyNumber_Int(o) + #define PyIndex_Check(o) PyNumber_Check(o) +#endif +#if PY_VERSION_HEX < 0x02060000 + #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) + #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) + #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) + #define PyVarObject_HEAD_INIT(type, size) \ + PyObject_HEAD_INIT(type) size, + #define PyType_Modified(t) + + typedef struct { + void *buf; + PyObject *obj; + Py_ssize_t len; + Py_ssize_t itemsize; + int readonly; + int ndim; + char *format; + Py_ssize_t *shape; + Py_ssize_t *strides; + Py_ssize_t *suboffsets; + void *internal; + } Py_buffer; + + #define PyBUF_SIMPLE 0 + #define PyBUF_WRITABLE 0x0001 + #define PyBUF_FORMAT 0x0004 + #define PyBUF_ND 0x0008 + #define PyBUF_STRIDES (0x0010 | PyBUF_ND) + #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) + #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) + #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) + #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) + +#endif +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" +#endif +#if PY_MAJOR_VERSION >= 3 + #define Py_TPFLAGS_CHECKTYPES 0 + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyString_Type PyBytes_Type + #define PyString_CheckExact PyBytes_CheckExact + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define PyBytes_Type PyString_Type +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyMethod_New(func, self, klass) PyInstanceMethod_New(func) +#endif +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#else + #define _USE_MATH_DEFINES +#endif +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) +#else + #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) + #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) + #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) +#endif +#if PY_VERSION_HEX < 0x02050000 + #define __Pyx_NAMESTR(n) ((char *)(n)) + #define __Pyx_DOCSTR(n) ((char *)(n)) +#else + #define __Pyx_NAMESTR(n) (n) + #define __Pyx_DOCSTR(n) (n) +#endif +#ifdef __cplusplus +#define __PYX_EXTERN_C extern "C" +#else +#define __PYX_EXTERN_C extern +#endif +#include +#define __PYX_HAVE_API__msgpack +#include "stdlib.h" +#include "string.h" +#include "pack.h" +#include "unpack.h" +#define __PYX_USE_C99_COMPLEX defined(_Complex_I) + + +#ifdef __GNUC__ +#define INLINE __inline__ +#elif _WIN32 +#define INLINE __inline +#else +#define INLINE +#endif + +typedef struct {PyObject **p; char *s; long n; char is_unicode; char intern; char is_identifier;} __Pyx_StringTabEntry; /*proto*/ + + + +static int __pyx_skip_dispatch = 0; + + +/* Type Conversion Predeclarations */ + +#if PY_MAJOR_VERSION < 3 +#define __Pyx_PyBytes_FromString PyString_FromString +#define __Pyx_PyBytes_FromStringAndSize PyString_FromStringAndSize +#define __Pyx_PyBytes_AsString PyString_AsString +#else +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +#define __Pyx_PyBytes_AsString PyBytes_AsString +#endif + +#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) +static INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); + +#if !defined(T_PYSSIZET) +#if PY_VERSION_HEX < 0x02050000 +#define T_PYSSIZET T_INT +#elif !defined(T_LONGLONG) +#define T_PYSSIZET \ + ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \ + ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : -1)) +#else +#define T_PYSSIZET \ + ((sizeof(Py_ssize_t) == sizeof(int)) ? T_INT : \ + ((sizeof(Py_ssize_t) == sizeof(long)) ? T_LONG : \ + ((sizeof(Py_ssize_t) == sizeof(PY_LONG_LONG)) ? T_LONGLONG : -1))) +#endif +#endif + +#if !defined(T_SIZET) +#if !defined(T_ULONGLONG) +#define T_SIZET \ + ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \ + ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : -1)) +#else +#define T_SIZET \ + ((sizeof(size_t) == sizeof(unsigned int)) ? T_UINT : \ + ((sizeof(size_t) == sizeof(unsigned long)) ? T_ULONG : \ + ((sizeof(size_t) == sizeof(unsigned PY_LONG_LONG)) ? T_ULONGLONG : -1))) +#endif +#endif + +static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); + +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) + + +#ifdef __GNUC__ +/* Test for GCC > 2.95 */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) +#else /* __GNUC__ > 2 ... */ +#define likely(x) (x) +#define unlikely(x) (x) +#endif /* __GNUC__ > 2 ... */ +#else /* __GNUC__ */ +#define likely(x) (x) +#define unlikely(x) (x) +#endif /* __GNUC__ */ + +static PyObject *__pyx_m; +static PyObject *__pyx_b; +static PyObject *__pyx_empty_tuple; +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm= __FILE__; +static const char *__pyx_filename; +static const char **__pyx_f; + + +#ifdef CYTHON_REFNANNY +typedef struct { + void (*INCREF)(void*, PyObject*, int); + void (*DECREF)(void*, PyObject*, int); + void (*GOTREF)(void*, PyObject*, int); + void (*GIVEREF)(void*, PyObject*, int); + void* (*NewContext)(const char*, int, const char*); + void (*FinishContext)(void**); +} __Pyx_RefnannyAPIStruct; +static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL; +#define __Pyx_ImportRefcountAPI(name) (__Pyx_RefnannyAPIStruct *) PyCObject_Import((char *)name, (char *)"RefnannyAPI") +#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (PyObject *)(r), __LINE__) +#define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r) +#define __Pyx_SetupRefcountContext(name) void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__, __FILE__) +#define __Pyx_FinishRefcountContext() __Pyx_Refnanny->FinishContext(&__pyx_refchk) +#else +#define __Pyx_INCREF(r) Py_INCREF(r) +#define __Pyx_DECREF(r) Py_DECREF(r) +#define __Pyx_GOTREF(r) +#define __Pyx_GIVEREF(r) +#define __Pyx_XDECREF(r) Py_XDECREF(r) +#define __Pyx_SetupRefcountContext(name) +#define __Pyx_FinishRefcountContext() +#endif /* CYTHON_REFNANNY */ +#define __Pyx_XGIVEREF(r) if((r) == NULL) ; else __Pyx_GIVEREF(r) +#define __Pyx_XGOTREF(r) if((r) == NULL) ; else __Pyx_GOTREF(r) + +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, PyObject* kw_name); /*proto*/ + +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/ + +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, const char* function_name); /*proto*/ + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +static INLINE void __Pyx_RaiseTooManyValuesError(void); + +static PyObject *__Pyx_UnpackItem(PyObject *, Py_ssize_t index); /*proto*/ +static int __Pyx_EndUnpack(PyObject *); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ + +static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/ + +static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); + +static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); + +static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); + +static INLINE char __Pyx_PyInt_AsChar(PyObject *); + +static INLINE short __Pyx_PyInt_AsShort(PyObject *); + +static INLINE int __Pyx_PyInt_AsInt(PyObject *); + +static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); + +static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); + +static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); + +static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); + +static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); + +static INLINE long __Pyx_PyInt_AsLong(PyObject *); + +static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); + +static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); + +static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); + +static void __Pyx_WriteUnraisable(const char *name); /*proto*/ + +static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ + +static void __Pyx_AddTraceback(const char *funcname); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ + +/* Type declarations */ + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":39 + * cdef int BUFF_SIZE=2*1024 + * + * cdef class Packer: # <<<<<<<<<<<<<< + * """Packer that pack data into strm. + * + */ + +struct __pyx_obj_7msgpack_Packer { + PyObject_HEAD + struct __pyx_vtabstruct_7msgpack_Packer *__pyx_vtab; + char *buff; + unsigned int length; + unsigned int allocated; + struct msgpack_packer pk; + PyObject *strm; +}; + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":200 + * return unpacks(packed) + * + * cdef class Unpacker: # <<<<<<<<<<<<<< + * """Do nothing. This function is for symmetric to Packer""" + * unpack = staticmethod(unpacks) + */ + +struct __pyx_obj_7msgpack_Unpacker { + PyObject_HEAD +}; + + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":39 + * cdef int BUFF_SIZE=2*1024 + * + * cdef class Packer: # <<<<<<<<<<<<<< + * """Packer that pack data into strm. + * + */ + +struct __pyx_vtabstruct_7msgpack_Packer { + PyObject *(*__pack)(struct __pyx_obj_7msgpack_Packer *, PyObject *); +}; +static struct __pyx_vtabstruct_7msgpack_Packer *__pyx_vtabptr_7msgpack_Packer; +/* Module declarations from msgpack */ + +static PyTypeObject *__pyx_ptype_7msgpack_Packer = 0; +static PyTypeObject *__pyx_ptype_7msgpack_Unpacker = 0; +static int __pyx_v_7msgpack_BUFF_SIZE; +static PyObject *__pyx_k_1 = 0; +static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *, const char*, unsigned int); /*proto*/ +#define __Pyx_MODULE_NAME "msgpack" +int __pyx_module_is_main_msgpack = 0; + +/* Implementation of msgpack */ +static char __pyx_k___main__[] = "__main__"; +static PyObject *__pyx_kp___main__; +static char __pyx_k___init__[] = "__init__"; +static PyObject *__pyx_kp___init__; +static char __pyx_k___del__[] = "__del__"; +static PyObject *__pyx_kp___del__; +static char __pyx_k_flush[] = "flush"; +static PyObject *__pyx_kp_flush; +static char __pyx_k_pack_list[] = "pack_list"; +static PyObject *__pyx_kp_pack_list; +static char __pyx_k_pack_dict[] = "pack_dict"; +static PyObject *__pyx_kp_pack_dict; +static char __pyx_k_pack[] = "pack"; +static PyObject *__pyx_kp_pack; +static char __pyx_k_unpack[] = "unpack"; +static PyObject *__pyx_kp_unpack; +static char __pyx_k_strm[] = "strm"; +static PyObject *__pyx_kp_strm; +static char __pyx_k_size[] = "size"; +static PyObject *__pyx_kp_size; +static char __pyx_k_len[] = "len"; +static PyObject *__pyx_kp_len; +static char __pyx_k_obj[] = "obj"; +static PyObject *__pyx_kp_obj; +static char __pyx_k_o[] = "o"; +static PyObject *__pyx_kp_o; +static char __pyx_k_stream[] = "stream"; +static PyObject *__pyx_kp_stream; +static char __pyx_k_packed_bytes[] = "packed_bytes"; +static PyObject *__pyx_kp_packed_bytes; +static char __pyx_k_cStringIO[] = "cStringIO"; +static PyObject *__pyx_kp_cStringIO; +static char __pyx_k_StringIO[] = "StringIO"; +static PyObject *__pyx_kp_StringIO; +static char __pyx_k_staticmethod[] = "staticmethod"; +static PyObject *__pyx_kp_staticmethod; +static char __pyx_k_unpacks[] = "unpacks"; +static PyObject *__pyx_kp_unpacks; +static char __pyx_k_write[] = "write"; +static PyObject *__pyx_kp_write; +static char __pyx_k_2[] = "flush"; +static PyObject *__pyx_kp_2; +static char __pyx_k_encode[] = "encode"; +static PyObject *__pyx_kp_encode; +static char __pyx_k_iteritems[] = "iteritems"; +static PyObject *__pyx_kp_iteritems; +static char __pyx_k_TypeError[] = "TypeError"; +static PyObject *__pyx_kp_TypeError; +static char __pyx_k_getvalue[] = "getvalue"; +static PyObject *__pyx_kp_getvalue; +static char __pyx_k_read[] = "read"; +static PyObject *__pyx_kp_read; +static PyObject *__pyx_builtin_staticmethod; +static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_kp_3; +static PyObject *__pyx_kp_4; +static char __pyx_k_3[] = "utf-8"; +static char __pyx_k_4[] = "can't serialize %r"; + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":51 + * cdef object strm + * + * def __init__(self, strm, int size=0): # <<<<<<<<<<<<<< + * if size <= 0: + * size = BUFF_SIZE + */ + +static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pf_7msgpack_6Packer___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_strm = 0; + int __pyx_v_size; + int __pyx_r; + int __pyx_t_1; + static PyObject **__pyx_pyargnames[] = {&__pyx_kp_strm,&__pyx_kp_size,0}; + __Pyx_SetupRefcountContext("__init__"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[2] = {0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_strm); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 1) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_size); + if (unlikely(value)) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_strm = values[0]; + if (values[1]) { + __pyx_v_size = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_size = 0; + } + } else { + __pyx_v_size = 0; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: __pyx_v_size = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_size == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + case 1: __pyx_v_strm = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack.Packer.__init__"); + return -1; + __pyx_L4_argument_unpacking_done:; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":52 + * + * def __init__(self, strm, int size=0): + * if size <= 0: # <<<<<<<<<<<<<< + * size = BUFF_SIZE + * + */ + __pyx_t_1 = (__pyx_v_size <= 0); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":53 + * def __init__(self, strm, int size=0): + * if size <= 0: + * size = BUFF_SIZE # <<<<<<<<<<<<<< + * + * self.strm = strm + */ + __pyx_v_size = __pyx_v_7msgpack_BUFF_SIZE; + goto __pyx_L6; + } + __pyx_L6:; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":55 + * size = BUFF_SIZE + * + * self.strm = strm # <<<<<<<<<<<<<< + * self.buff = malloc(size) + * self.allocated = size + */ + __Pyx_INCREF(__pyx_v_strm); + __Pyx_GIVEREF(__pyx_v_strm); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm); + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm = __pyx_v_strm; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":56 + * + * self.strm = strm + * self.buff = malloc(size) # <<<<<<<<<<<<<< + * self.allocated = size + * self.length = 0 + */ + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff = ((char *)malloc(__pyx_v_size)); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":57 + * self.strm = strm + * self.buff = malloc(size) + * self.allocated = size # <<<<<<<<<<<<<< + * self.length = 0 + * + */ + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->allocated = __pyx_v_size; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":58 + * self.buff = malloc(size) + * self.allocated = size + * self.length = 0 # <<<<<<<<<<<<<< + * + * msgpack_packer_init(&self.pk, self, _packer_write) + */ + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":60 + * self.length = 0 + * + * msgpack_packer_init(&self.pk, self, _packer_write) # <<<<<<<<<<<<<< + * + * def __del__(self): + */ + msgpack_packer_init((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), ((void *)__pyx_v_self), ((int (*)(void *, const char*, unsigned int))__pyx_f_7msgpack__packer_write)); + + __pyx_r = 0; + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":62 + * msgpack_packer_init(&self.pk, self, _packer_write) + * + * def __del__(self): # <<<<<<<<<<<<<< + * free(self.buff); + * + */ + +static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObject *unused); /*proto*/ +static PyObject *__pyx_pf_7msgpack_6Packer___del__(PyObject *__pyx_v_self, PyObject *unused) { + PyObject *__pyx_r = NULL; + __Pyx_SetupRefcountContext("__del__"); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":63 + * + * def __del__(self): + * free(self.buff); # <<<<<<<<<<<<<< + * + * def flush(self): + */ + free(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":65 + * free(self.buff); + * + * def flush(self): # <<<<<<<<<<<<<< + * """Flash local buffer and output stream if it has 'flush()' method.""" + * if self.length > 0: + */ + +static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObject *unused); /*proto*/ +static char __pyx_doc_7msgpack_6Packer_flush[] = "Flash local buffer and output stream if it has 'flush()' method."; +static PyObject *__pyx_pf_7msgpack_6Packer_flush(PyObject *__pyx_v_self, PyObject *unused) { + PyObject *__pyx_r = NULL; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_SetupRefcountContext("flush"); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":67 + * def flush(self): + * """Flash local buffer and output stream if it has 'flush()' method.""" + * if self.length > 0: # <<<<<<<<<<<<<< + * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) + * self.length = 0 + */ + __pyx_t_1 = (((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length > 0); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":68 + * """Flash local buffer and output stream if it has 'flush()' method.""" + * if self.length > 0: + * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) # <<<<<<<<<<<<<< + * self.length = 0 + * if hasattr(self.strm, 'flush'): + */ + __pyx_t_2 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyString_FromStringAndSize(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->buff, ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":69 + * if self.length > 0: + * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) + * self.length = 0 # <<<<<<<<<<<<<< + * if hasattr(self.strm, 'flush'): + * self.strm.flush() + */ + ((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->length = 0; + goto __pyx_L5; + } + __pyx_L5:; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":70 + * self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) + * self.length = 0 + * if hasattr(self.strm, 'flush'): # <<<<<<<<<<<<<< + * self.strm.flush() + * + */ + __pyx_t_1 = PyObject_HasAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_2); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":71 + * self.length = 0 + * if hasattr(self.strm, 'flush'): + * self.strm.flush() # <<<<<<<<<<<<<< + * + * def pack_list(self, len): + */ + __pyx_t_3 = PyObject_GetAttr(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->strm, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L6; + } + __pyx_L6:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("msgpack.Packer.flush"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":73 + * self.strm.flush() + * + * def pack_list(self, len): # <<<<<<<<<<<<<< + * """Start packing sequential objects. + * + */ + +static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyObject *__pyx_v_len); /*proto*/ +static char __pyx_doc_7msgpack_6Packer_pack_list[] = "Start packing sequential objects.\n\n Example:\n\n packer.pack_list(2)\n packer.pack('foo')\n packer.pack('bar')\n\n This code is same as below code:\n\n packer.pack(['foo', 'bar'])\n "; +static PyObject *__pyx_pf_7msgpack_6Packer_pack_list(PyObject *__pyx_v_self, PyObject *__pyx_v_len) { + PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + __Pyx_SetupRefcountContext("pack_list"); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":86 + * packer.pack(['foo', 'bar']) + * """ + * msgpack_pack_array(&self.pk, len) # <<<<<<<<<<<<<< + * + * def pack_dict(self, len): + */ + __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_array((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("msgpack.Packer.pack_list"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":88 + * msgpack_pack_array(&self.pk, len) + * + * def pack_dict(self, len): # <<<<<<<<<<<<<< + * """Start packing key-value objects. + * + */ + +static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_len); /*proto*/ +static char __pyx_doc_7msgpack_6Packer_pack_dict[] = "Start packing key-value objects.\n\n Example:\n\n packer.pack_dict(1)\n packer.pack('foo')\n packer.pack('bar')\n\n This code is same as below code:\n\n packer.pack({'foo', 'bar'})\n "; +static PyObject *__pyx_pf_7msgpack_6Packer_pack_dict(PyObject *__pyx_v_self, PyObject *__pyx_v_len) { + PyObject *__pyx_r = NULL; + size_t __pyx_t_1; + __Pyx_SetupRefcountContext("pack_dict"); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":101 + * packer.pack({'foo', 'bar'}) + * """ + * msgpack_pack_map(&self.pk, len) # <<<<<<<<<<<<<< + * + * cdef __pack(self, object o): + */ + __pyx_t_1 = __Pyx_PyInt_AsSize_t(__pyx_v_len); if (unlikely((__pyx_t_1 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_map((&((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->pk), __pyx_t_1); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("msgpack.Packer.pack_dict"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":103 + * msgpack_pack_map(&self.pk, len) + * + * cdef __pack(self, object o): # <<<<<<<<<<<<<< + * cdef long long intval + * cdef double fval + */ + +static PyObject *__pyx_f_7msgpack_6Packer___pack(struct __pyx_obj_7msgpack_Packer *__pyx_v_self, PyObject *__pyx_v_o) { + PY_LONG_LONG __pyx_v_intval; + double __pyx_v_fval; + char *__pyx_v_rawval; + PyObject *__pyx_v_k; + PyObject *__pyx_v_v; + PyObject *__pyx_r = NULL; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PY_LONG_LONG __pyx_t_3; + double __pyx_t_4; + char *__pyx_t_5; + Py_ssize_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + int __pyx_t_11; + __Pyx_SetupRefcountContext("__pack"); + __Pyx_INCREF(__pyx_v_o); + __pyx_v_k = Py_None; __Pyx_INCREF(Py_None); + __pyx_v_v = Py_None; __Pyx_INCREF(Py_None); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":108 + * cdef char* rawval + * + * if o is None: # <<<<<<<<<<<<<< + * msgpack_pack_nil(&self.pk) + * elif o is True: + */ + __pyx_t_1 = (__pyx_v_o == Py_None); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":109 + * + * if o is None: + * msgpack_pack_nil(&self.pk) # <<<<<<<<<<<<<< + * elif o is True: + * msgpack_pack_true(&self.pk) + */ + msgpack_pack_nil((&__pyx_v_self->pk)); + goto __pyx_L3; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":110 + * if o is None: + * msgpack_pack_nil(&self.pk) + * elif o is True: # <<<<<<<<<<<<<< + * msgpack_pack_true(&self.pk) + * elif o is False: + */ + __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = (__pyx_v_o == __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":111 + * msgpack_pack_nil(&self.pk) + * elif o is True: + * msgpack_pack_true(&self.pk) # <<<<<<<<<<<<<< + * elif o is False: + * msgpack_pack_false(&self.pk) + */ + msgpack_pack_true((&__pyx_v_self->pk)); + goto __pyx_L3; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":112 + * elif o is True: + * msgpack_pack_true(&self.pk) + * elif o is False: # <<<<<<<<<<<<<< + * msgpack_pack_false(&self.pk) + * elif isinstance(o, long): + */ + __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = (__pyx_v_o == __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":113 + * msgpack_pack_true(&self.pk) + * elif o is False: + * msgpack_pack_false(&self.pk) # <<<<<<<<<<<<<< + * elif isinstance(o, long): + * intval = o + */ + msgpack_pack_false((&__pyx_v_self->pk)); + goto __pyx_L3; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":114 + * elif o is False: + * msgpack_pack_false(&self.pk) + * elif isinstance(o, long): # <<<<<<<<<<<<<< + * intval = o + * msgpack_pack_long_long(&self.pk, intval) + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyLong_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":115 + * msgpack_pack_false(&self.pk) + * elif isinstance(o, long): + * intval = o # <<<<<<<<<<<<<< + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, int): + */ + __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_intval = __pyx_t_3; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":116 + * elif isinstance(o, long): + * intval = o + * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< + * elif isinstance(o, int): + * intval = o + */ + msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_intval); + goto __pyx_L3; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":117 + * intval = o + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, int): # <<<<<<<<<<<<<< + * intval = o + * msgpack_pack_long_long(&self.pk, intval) + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyInt_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":118 + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, int): + * intval = o # <<<<<<<<<<<<<< + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, float): + */ + __pyx_t_3 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_intval = __pyx_t_3; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":119 + * elif isinstance(o, int): + * intval = o + * msgpack_pack_long_long(&self.pk, intval) # <<<<<<<<<<<<<< + * elif isinstance(o, float): + * fval = o + */ + msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_intval); + goto __pyx_L3; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":120 + * intval = o + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, float): # <<<<<<<<<<<<<< + * fval = o + * msgpack_pack_double(&self.pk, fval) + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyFloat_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":121 + * msgpack_pack_long_long(&self.pk, intval) + * elif isinstance(o, float): + * fval = o # <<<<<<<<<<<<<< + * msgpack_pack_double(&self.pk, fval) + * elif isinstance(o, str): + */ + __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_v_o); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_fval = __pyx_t_4; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":122 + * elif isinstance(o, float): + * fval = o + * msgpack_pack_double(&self.pk, fval) # <<<<<<<<<<<<<< + * elif isinstance(o, str): + * rawval = o + */ + msgpack_pack_double((&__pyx_v_self->pk), __pyx_v_fval); + goto __pyx_L3; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":123 + * fval = o + * msgpack_pack_double(&self.pk, fval) + * elif isinstance(o, str): # <<<<<<<<<<<<<< + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyString_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":124 + * msgpack_pack_double(&self.pk, fval) + * elif isinstance(o, str): + * rawval = o # <<<<<<<<<<<<<< + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + */ + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_rawval = __pyx_t_5; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":125 + * elif isinstance(o, str): + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, unicode): + */ + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_6); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":126 + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< + * elif isinstance(o, unicode): + * o = o.encode('utf-8') + */ + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_6); + goto __pyx_L3; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":127 + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, unicode): # <<<<<<<<<<<<<< + * o = o.encode('utf-8') + * rawval = o + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyUnicode_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":128 + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, unicode): + * o = o.encode('utf-8') # <<<<<<<<<<<<<< + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_7)); + __Pyx_INCREF(__pyx_kp_3); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_kp_3); + __Pyx_GIVEREF(__pyx_kp_3); + __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_v_o); + __pyx_v_o = __pyx_t_8; + __pyx_t_8 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":129 + * elif isinstance(o, unicode): + * o = o.encode('utf-8') + * rawval = o # <<<<<<<<<<<<<< + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + */ + __pyx_t_5 = __Pyx_PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_rawval = __pyx_t_5; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":130 + * o = o.encode('utf-8') + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, dict): + */ + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_6); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":131 + * rawval = o + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< + * elif isinstance(o, dict): + * msgpack_pack_map(&self.pk, len(o)) + */ + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_6); + goto __pyx_L3; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":132 + * msgpack_pack_raw(&self.pk, len(o)) + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, dict): # <<<<<<<<<<<<<< + * msgpack_pack_map(&self.pk, len(o)) + * for k,v in o.iteritems(): + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyDict_Type))); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":133 + * msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif isinstance(o, dict): + * msgpack_pack_map(&self.pk, len(o)) # <<<<<<<<<<<<<< + * for k,v in o.iteritems(): + * self.pack(k) + */ + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_map((&__pyx_v_self->pk), __pyx_t_6); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":134 + * elif isinstance(o, dict): + * msgpack_pack_map(&self.pk, len(o)) + * for k,v in o.iteritems(): # <<<<<<<<<<<<<< + * self.pack(k) + * self.pack(v) + */ + __pyx_t_8 = PyObject_GetAttr(__pyx_v_o, __pyx_kp_iteritems); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PyList_CheckExact(__pyx_t_7) || PyTuple_CheckExact(__pyx_t_7)) { + __pyx_t_6 = 0; __pyx_t_8 = __pyx_t_7; __Pyx_INCREF(__pyx_t_8); + } else { + __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + for (;;) { + if (likely(PyList_CheckExact(__pyx_t_8))) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_8)) break; + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; + } else if (likely(PyTuple_CheckExact(__pyx_t_8))) { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; + } else { + __pyx_t_7 = PyIter_Next(__pyx_t_8); + if (!__pyx_t_7) { + if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + if (PyTuple_CheckExact(__pyx_t_7) && likely(PyTuple_GET_SIZE(__pyx_t_7) == 2)) { + PyObject* tuple = __pyx_t_7; + __pyx_2 = PyTuple_GET_ITEM(tuple, 0); __Pyx_INCREF(__pyx_2); + __pyx_3 = PyTuple_GET_ITEM(tuple, 1); __Pyx_INCREF(__pyx_3); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_v_k); + __pyx_v_k = __pyx_2; + __pyx_2 = 0; + __Pyx_DECREF(__pyx_v_v); + __pyx_v_v = __pyx_3; + __pyx_3 = 0; + } else { + __pyx_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_2 = __Pyx_UnpackItem(__pyx_1, 0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + __pyx_3 = __Pyx_UnpackItem(__pyx_1, 1); if (unlikely(!__pyx_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_3); + if (__Pyx_EndUnpack(__pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; + __Pyx_DECREF(__pyx_v_k); + __pyx_v_k = __pyx_2; + __pyx_2 = 0; + __Pyx_DECREF(__pyx_v_v); + __pyx_v_v = __pyx_3; + __pyx_3 = 0; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":135 + * msgpack_pack_map(&self.pk, len(o)) + * for k,v in o.iteritems(): + * self.pack(k) # <<<<<<<<<<<<<< + * self.pack(v) + * elif isinstance(o, tuple) or isinstance(o, list): + */ + __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_v_k); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k); + __Pyx_GIVEREF(__pyx_v_k); + __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":136 + * for k,v in o.iteritems(): + * self.pack(k) + * self.pack(v) # <<<<<<<<<<<<<< + * elif isinstance(o, tuple) or isinstance(o, list): + * msgpack_pack_array(&self.pk, len(o)) + */ + __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_v_v); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); + __Pyx_GIVEREF(__pyx_v_v); + __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L3; + } + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":137 + * self.pack(k) + * self.pack(v) + * elif isinstance(o, tuple) or isinstance(o, list): # <<<<<<<<<<<<<< + * msgpack_pack_array(&self.pk, len(o)) + * for v in o: + */ + __pyx_t_1 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyTuple_Type))); + if (!__pyx_t_1) { + __pyx_t_10 = PyObject_TypeCheck(__pyx_v_o, ((PyTypeObject *)((PyObject*)&PyList_Type))); + __pyx_t_11 = __pyx_t_10; + } else { + __pyx_t_11 = __pyx_t_1; + } + if (__pyx_t_11) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":138 + * self.pack(v) + * elif isinstance(o, tuple) or isinstance(o, list): + * msgpack_pack_array(&self.pk, len(o)) # <<<<<<<<<<<<<< + * for v in o: + * self.pack(v) + */ + __pyx_t_6 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + msgpack_pack_array((&__pyx_v_self->pk), __pyx_t_6); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":139 + * elif isinstance(o, tuple) or isinstance(o, list): + * msgpack_pack_array(&self.pk, len(o)) + * for v in o: # <<<<<<<<<<<<<< + * self.pack(v) + * else: + */ + if (PyList_CheckExact(__pyx_v_o) || PyTuple_CheckExact(__pyx_v_o)) { + __pyx_t_6 = 0; __pyx_t_8 = __pyx_v_o; __Pyx_INCREF(__pyx_t_8); + } else { + __pyx_t_6 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + } + for (;;) { + if (likely(PyList_CheckExact(__pyx_t_8))) { + if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_8)) break; + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; + } else if (likely(PyTuple_CheckExact(__pyx_t_8))) { + if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_8)) break; + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; + } else { + __pyx_t_7 = PyIter_Next(__pyx_t_8); + if (!__pyx_t_7) { + if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_DECREF(__pyx_v_v); + __pyx_v_v = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":140 + * msgpack_pack_array(&self.pk, len(o)) + * for v in o: + * self.pack(v) # <<<<<<<<<<<<<< + * else: + * # TODO: Serialize with defalt() like simplejson. + */ + __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_kp_pack); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_v_v); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_v); + __Pyx_GIVEREF(__pyx_v_v); + __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":143 + * else: + * # TODO: Serialize with defalt() like simplejson. + * raise TypeError, "can't serialize %r" % (o,) # <<<<<<<<<<<<<< + * + * def pack(self, obj, flush=True): + */ + __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_8)); + __Pyx_INCREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + __pyx_t_9 = PyNumber_Remainder(__pyx_kp_4, ((PyObject *)__pyx_t_8)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; + __Pyx_Raise(__pyx_builtin_TypeError, __pyx_t_9, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_2); + __Pyx_XDECREF(__pyx_3); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_AddTraceback("msgpack.Packer.__pack"); + __pyx_r = 0; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_k); + __Pyx_DECREF(__pyx_v_v); + __Pyx_DECREF(__pyx_v_o); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":145 + * raise TypeError, "can't serialize %r" % (o,) + * + * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< + * self.__pack(obj) + * if flush: + */ + +static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pf_7msgpack_6Packer_pack(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_obj = 0; + PyObject *__pyx_v_flush = 0; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + static PyObject **__pyx_pyargnames[] = {&__pyx_kp_obj,&__pyx_kp_flush,0}; + __Pyx_SetupRefcountContext("pack"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[2] = {0,0}; + values[1] = __pyx_k_1; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_obj); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 1) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_kp_flush); + if (unlikely(value)) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_obj = values[0]; + __pyx_v_flush = values[1]; + } else { + __pyx_v_flush = __pyx_k_1; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: __pyx_v_flush = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: __pyx_v_obj = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("pack", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack.Packer.pack"); + return NULL; + __pyx_L4_argument_unpacking_done:; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":146 + * + * def pack(self, obj, flush=True): + * self.__pack(obj) # <<<<<<<<<<<<<< + * if flush: + * self.flush() + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_7msgpack_Packer *)((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self)->__pyx_vtab)->__pack(((struct __pyx_obj_7msgpack_Packer *)__pyx_v_self), __pyx_v_obj); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":147 + * def pack(self, obj, flush=True): + * self.__pack(obj) + * if flush: # <<<<<<<<<<<<<< + * self.flush() + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_flush); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":148 + * self.__pack(obj) + * if flush: + * self.flush() # <<<<<<<<<<<<<< + * + * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_self, __pyx_kp_flush); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L6; + } + __pyx_L6:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack.Packer.pack"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":150 + * self.flush() + * + * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): # <<<<<<<<<<<<<< + * if packer.length + l > packer.allocated: + * if packer.length > 0: + */ + +static int __pyx_f_7msgpack__packer_write(struct __pyx_obj_7msgpack_Packer *__pyx_v_packer, const char* __pyx_v_b, unsigned int __pyx_v_l) { + int __pyx_r; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + __Pyx_SetupRefcountContext("_packer_write"); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":151 + * + * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): + * if packer.length + l > packer.allocated: # <<<<<<<<<<<<<< + * if packer.length > 0: + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + */ + __pyx_t_1 = ((__pyx_v_packer->length + __pyx_v_l) > __pyx_v_packer->allocated); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":152 + * cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): + * if packer.length + l > packer.allocated: + * if packer.length > 0: # <<<<<<<<<<<<<< + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + * if l > 64: + */ + __pyx_t_1 = (__pyx_v_packer->length > 0); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":153 + * if packer.length + l > packer.allocated: + * if packer.length > 0: + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) # <<<<<<<<<<<<<< + * if l > 64: + * packer.strm.write(PyString_FromStringAndSize(b, l)) + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyString_FromStringAndSize(__pyx_v_packer->buff, __pyx_v_packer->length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L4; + } + __pyx_L4:; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":154 + * if packer.length > 0: + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + * if l > 64: # <<<<<<<<<<<<<< + * packer.strm.write(PyString_FromStringAndSize(b, l)) + * packer.length = 0 + */ + __pyx_t_1 = (__pyx_v_l > 64); + if (__pyx_t_1) { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":155 + * packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) + * if l > 64: + * packer.strm.write(PyString_FromStringAndSize(b, l)) # <<<<<<<<<<<<<< + * packer.length = 0 + * else: + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer->strm, __pyx_kp_write); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyString_FromStringAndSize(__pyx_v_b, __pyx_v_l); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":156 + * if l > 64: + * packer.strm.write(PyString_FromStringAndSize(b, l)) + * packer.length = 0 # <<<<<<<<<<<<<< + * else: + * memcpy(packer.buff, b, l) + */ + __pyx_v_packer->length = 0; + goto __pyx_L5; + } + /*else*/ { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":158 + * packer.length = 0 + * else: + * memcpy(packer.buff, b, l) # <<<<<<<<<<<<<< + * packer.length = l + * else: + */ + memcpy(__pyx_v_packer->buff, __pyx_v_b, __pyx_v_l); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":159 + * else: + * memcpy(packer.buff, b, l) + * packer.length = l # <<<<<<<<<<<<<< + * else: + * memcpy(packer.buff + packer.length, b, l) + */ + __pyx_v_packer->length = __pyx_v_l; + } + __pyx_L5:; + goto __pyx_L3; + } + /*else*/ { + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":161 + * packer.length = l + * else: + * memcpy(packer.buff + packer.length, b, l) # <<<<<<<<<<<<<< + * packer.length += l + * return 0 + */ + memcpy((__pyx_v_packer->buff + __pyx_v_packer->length), __pyx_v_b, __pyx_v_l); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":162 + * else: + * memcpy(packer.buff + packer.length, b, l) + * packer.length += l # <<<<<<<<<<<<<< + * return 0 + * + */ + __pyx_v_packer->length += __pyx_v_l; + } + __pyx_L3:; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":163 + * memcpy(packer.buff + packer.length, b, l) + * packer.length += l + * return 0 # <<<<<<<<<<<<<< + * + * def pack(object o, object stream): + */ + __pyx_r = 0; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_WriteUnraisable("msgpack._packer_write"); + __pyx_r = 0; + __pyx_L0:; + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":165 + * return 0 + * + * def pack(object o, object stream): # <<<<<<<<<<<<<< + * packer = Packer(stream) + * packer.pack(o) + */ + +static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pf_7msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_o = 0; + PyObject *__pyx_v_stream = 0; + PyObject *__pyx_v_packer; + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + static PyObject **__pyx_pyargnames[] = {&__pyx_kp_o,&__pyx_kp_stream,0}; + __Pyx_SetupRefcountContext("pack"); + __pyx_self = __pyx_self; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[2] = {0,0}; + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_kp_o); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_kp_stream); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_o = values[0]; + __pyx_v_stream = values[1]; + } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { + goto __pyx_L5_argtuple_error; + } else { + __pyx_v_o = PyTuple_GET_ITEM(__pyx_args, 0); + __pyx_v_stream = PyTuple_GET_ITEM(__pyx_args, 1); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("pack", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack.pack"); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":166 + * + * def pack(object o, object stream): + * packer = Packer(stream) # <<<<<<<<<<<<<< + * packer.pack(o) + * packer.flush() + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_v_stream); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_stream); + __Pyx_GIVEREF(__pyx_v_stream); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_packer); + __pyx_v_packer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":167 + * def pack(object o, object stream): + * packer = Packer(stream) + * packer.pack(o) # <<<<<<<<<<<<<< + * packer.flush() + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":168 + * packer = Packer(stream) + * packer.pack(o) + * packer.flush() # <<<<<<<<<<<<<< + * + * def packs(object o): + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack.pack"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_packer); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":170 + * packer.flush() + * + * def packs(object o): # <<<<<<<<<<<<<< + * buf = StringIO() + * packer = Packer(buf) + */ + +static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v_o); /*proto*/ +static PyObject *__pyx_pf_7msgpack_packs(PyObject *__pyx_self, PyObject *__pyx_v_o) { + PyObject *__pyx_v_buf; + PyObject *__pyx_v_packer; + PyObject *__pyx_r = NULL; + PyObject *__pyx_1 = 0; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + __Pyx_SetupRefcountContext("packs"); + __pyx_self = __pyx_self; + __pyx_v_buf = Py_None; __Pyx_INCREF(Py_None); + __pyx_v_packer = Py_None; __Pyx_INCREF(Py_None); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":171 + * + * def packs(object o): + * buf = StringIO() # <<<<<<<<<<<<<< + * packer = Packer(buf) + * packer.pack(o) + */ + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_StringIO); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; + __Pyx_DECREF(__pyx_v_buf); + __pyx_v_buf = __pyx_t_1; + __pyx_t_1 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":172 + * def packs(object o): + * buf = StringIO() + * packer = Packer(buf) # <<<<<<<<<<<<<< + * packer.pack(o) + * packer.flush() + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_v_buf); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_buf); + __Pyx_GIVEREF(__pyx_v_buf); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_Packer)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_packer); + __pyx_v_packer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":173 + * buf = StringIO() + * packer = Packer(buf) + * packer.pack(o) # <<<<<<<<<<<<<< + * packer.flush() + * return buf.getvalue() + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":174 + * packer = Packer(buf) + * packer.pack(o) + * packer.flush() # <<<<<<<<<<<<<< + * return buf.getvalue() + * + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_packer, __pyx_kp_flush); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":175 + * packer.pack(o) + * packer.flush() + * return buf.getvalue() # <<<<<<<<<<<<<< + * + * cdef extern from "unpack.h": + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyObject_GetAttr(__pyx_v_buf, __pyx_kp_getvalue); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack.packs"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_buf); + __Pyx_DECREF(__pyx_v_packer); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":186 + * + * + * def unpacks(object packed_bytes): # <<<<<<<<<<<<<< + * """Unpack packed_bytes to object. Returns unpacked object.""" + * cdef const_char_ptr p = packed_bytes + */ + +static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx_v_packed_bytes); /*proto*/ +static char __pyx_doc_7msgpack_unpacks[] = "Unpack packed_bytes to object. Returns unpacked object."; +static PyObject *__pyx_pf_7msgpack_unpacks(PyObject *__pyx_self, PyObject *__pyx_v_packed_bytes) { + const char* __pyx_v_p; + template_context __pyx_v_ctx; + size_t __pyx_v_off; + PyObject *__pyx_r = NULL; + const char* __pyx_t_1; + Py_ssize_t __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_SetupRefcountContext("unpacks"); + __pyx_self = __pyx_self; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":188 + * def unpacks(object packed_bytes): + * """Unpack packed_bytes to object. Returns unpacked object.""" + * cdef const_char_ptr p = packed_bytes # <<<<<<<<<<<<<< + * cdef template_context ctx + * cdef size_t off = 0 + */ + __pyx_t_1 = __Pyx_PyBytes_AsString(__pyx_v_packed_bytes); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_p = __pyx_t_1; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":190 + * cdef const_char_ptr p = packed_bytes + * cdef template_context ctx + * cdef size_t off = 0 # <<<<<<<<<<<<<< + * template_init(&ctx) + * template_execute(&ctx, p, len(packed_bytes), &off) + */ + __pyx_v_off = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":191 + * cdef template_context ctx + * cdef size_t off = 0 + * template_init(&ctx) # <<<<<<<<<<<<<< + * template_execute(&ctx, p, len(packed_bytes), &off) + * return template_data(&ctx) + */ + template_init((&__pyx_v_ctx)); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":192 + * cdef size_t off = 0 + * template_init(&ctx) + * template_execute(&ctx, p, len(packed_bytes), &off) # <<<<<<<<<<<<<< + * return template_data(&ctx) + * + */ + __pyx_t_2 = PyObject_Length(__pyx_v_packed_bytes); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + template_execute((&__pyx_v_ctx), __pyx_v_p, __pyx_t_2, (&__pyx_v_off)); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":193 + * template_init(&ctx) + * template_execute(&ctx, p, len(packed_bytes), &off) + * return template_data(&ctx) # <<<<<<<<<<<<<< + * + * def unpack(object stream): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = template_data((&__pyx_v_ctx)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack.unpacks"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} + +/* "/home/inada-n/work/msgpack/python/msgpack.pyx":195 + * return template_data(&ctx) + * + * def unpack(object stream): # <<<<<<<<<<<<<< + * """unpack from stream.""" + * packed = stream.read() + */ + +static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_v_stream); /*proto*/ +static char __pyx_doc_7msgpack_unpack[] = "unpack from stream."; +static PyObject *__pyx_pf_7msgpack_unpack(PyObject *__pyx_self, PyObject *__pyx_v_stream) { + PyObject *__pyx_v_packed; + PyObject *__pyx_r = NULL; + PyObject *__pyx_1 = 0; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_SetupRefcountContext("unpack"); + __pyx_self = __pyx_self; + __pyx_v_packed = Py_None; __Pyx_INCREF(Py_None); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":197 + * def unpack(object stream): + * """unpack from stream.""" + * packed = stream.read() # <<<<<<<<<<<<<< + * return unpacks(packed) + * + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_stream, __pyx_kp_read); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_v_packed); + __pyx_v_packed = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":198 + * """unpack from stream.""" + * packed = stream.read() + * return unpacks(packed) # <<<<<<<<<<<<<< + * + * cdef class Unpacker: + */ + __Pyx_XDECREF(__pyx_r); + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __Pyx_INCREF(__pyx_v_packed); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_packed); + __Pyx_GIVEREF(__pyx_v_packed); + __pyx_t_1 = PyObject_Call(__pyx_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 198; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("msgpack.unpack"); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_packed); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_FinishRefcountContext(); + return __pyx_r; +} +static struct __pyx_vtabstruct_7msgpack_Packer __pyx_vtable_7msgpack_Packer; + +static PyObject *__pyx_tp_new_7msgpack_Packer(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_7msgpack_Packer *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_7msgpack_Packer *)o); + p->__pyx_vtab = __pyx_vtabptr_7msgpack_Packer; + p->strm = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_7msgpack_Packer(PyObject *o) { + struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; + Py_XDECREF(p->strm); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_7msgpack_Packer(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; + if (p->strm) { + e = (*v)(p->strm, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_7msgpack_Packer(PyObject *o) { + struct __pyx_obj_7msgpack_Packer *p = (struct __pyx_obj_7msgpack_Packer *)o; + PyObject* tmp; + tmp = ((PyObject*)p->strm); + p->strm = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static struct PyMethodDef __pyx_methods_7msgpack_Packer[] = { + {__Pyx_NAMESTR("__del__"), (PyCFunction)__pyx_pf_7msgpack_6Packer___del__, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("flush"), (PyCFunction)__pyx_pf_7msgpack_6Packer_flush, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_flush)}, + {__Pyx_NAMESTR("pack_list"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_list, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_list)}, + {__Pyx_NAMESTR("pack_dict"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack_dict, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_6Packer_pack_dict)}, + {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_6Packer_pack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Packer = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*reserved*/ + #else + 0, /*nb_long*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_Packer = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_Packer = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Packer = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +PyTypeObject __pyx_type_7msgpack_Packer = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("msgpack.Packer"), /*tp_name*/ + sizeof(struct __pyx_obj_7msgpack_Packer), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_7msgpack_Packer, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &__pyx_tp_as_number_Packer, /*tp_as_number*/ + &__pyx_tp_as_sequence_Packer, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Packer, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Packer, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("Packer that pack data into strm.\n\n strm must have `write(bytes)` method.\n size specifies local buffer size.\n "), /*tp_doc*/ + __pyx_tp_traverse_7msgpack_Packer, /*tp_traverse*/ + __pyx_tp_clear_7msgpack_Packer, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_7msgpack_Packer, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pf_7msgpack_6Packer___init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_7msgpack_Packer, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ +}; + +static PyObject *__pyx_tp_new_7msgpack_Unpacker(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_7msgpack_Unpacker(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static struct PyMethodDef __pyx_methods_7msgpack_Unpacker[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Unpacker = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*reserved*/ + #else + 0, /*nb_long*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if (PY_MAJOR_VERSION >= 3) || (Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX) + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_Unpacker = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_Unpacker = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Unpacker = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +PyTypeObject __pyx_type_7msgpack_Unpacker = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("msgpack.Unpacker"), /*tp_name*/ + sizeof(struct __pyx_obj_7msgpack_Unpacker), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_7msgpack_Unpacker, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + &__pyx_tp_as_number_Unpacker, /*tp_as_number*/ + &__pyx_tp_as_sequence_Unpacker, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Unpacker, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Unpacker, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_NEWBUFFER, /*tp_flags*/ + __Pyx_DOCSTR("Do nothing. This function is for symmetric to Packer"), /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_7msgpack_Unpacker, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_7msgpack_Unpacker, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ +}; + +static struct PyMethodDef __pyx_methods[] = { + {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_pack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("packs"), (PyCFunction)__pyx_pf_7msgpack_packs, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("unpacks"), (PyCFunction)__pyx_pf_7msgpack_unpacks, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_unpacks)}, + {__Pyx_NAMESTR("unpack"), (PyCFunction)__pyx_pf_7msgpack_unpack, METH_O, __Pyx_DOCSTR(__pyx_doc_7msgpack_unpack)}, + {0, 0, 0, 0} +}; + +static void __pyx_init_filenames(void); /*proto*/ + +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef __pyx_moduledef = { + PyModuleDef_HEAD_INIT, + __Pyx_NAMESTR("msgpack"), + 0, /* m_doc */ + -1, /* m_size */ + __pyx_methods /* m_methods */, + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ +}; +#endif + +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp___main__, __pyx_k___main__, sizeof(__pyx_k___main__), 1, 1, 1}, + {&__pyx_kp___init__, __pyx_k___init__, sizeof(__pyx_k___init__), 1, 1, 1}, + {&__pyx_kp___del__, __pyx_k___del__, sizeof(__pyx_k___del__), 1, 1, 1}, + {&__pyx_kp_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 1, 1, 1}, + {&__pyx_kp_pack_list, __pyx_k_pack_list, sizeof(__pyx_k_pack_list), 1, 1, 1}, + {&__pyx_kp_pack_dict, __pyx_k_pack_dict, sizeof(__pyx_k_pack_dict), 1, 1, 1}, + {&__pyx_kp_pack, __pyx_k_pack, sizeof(__pyx_k_pack), 1, 1, 1}, + {&__pyx_kp_unpack, __pyx_k_unpack, sizeof(__pyx_k_unpack), 1, 1, 1}, + {&__pyx_kp_strm, __pyx_k_strm, sizeof(__pyx_k_strm), 1, 1, 1}, + {&__pyx_kp_size, __pyx_k_size, sizeof(__pyx_k_size), 1, 1, 1}, + {&__pyx_kp_len, __pyx_k_len, sizeof(__pyx_k_len), 1, 1, 1}, + {&__pyx_kp_obj, __pyx_k_obj, sizeof(__pyx_k_obj), 1, 1, 1}, + {&__pyx_kp_o, __pyx_k_o, sizeof(__pyx_k_o), 1, 1, 1}, + {&__pyx_kp_stream, __pyx_k_stream, sizeof(__pyx_k_stream), 1, 1, 1}, + {&__pyx_kp_packed_bytes, __pyx_k_packed_bytes, sizeof(__pyx_k_packed_bytes), 1, 1, 1}, + {&__pyx_kp_cStringIO, __pyx_k_cStringIO, sizeof(__pyx_k_cStringIO), 1, 1, 1}, + {&__pyx_kp_StringIO, __pyx_k_StringIO, sizeof(__pyx_k_StringIO), 1, 1, 1}, + {&__pyx_kp_staticmethod, __pyx_k_staticmethod, sizeof(__pyx_k_staticmethod), 1, 1, 1}, + {&__pyx_kp_unpacks, __pyx_k_unpacks, sizeof(__pyx_k_unpacks), 1, 1, 1}, + {&__pyx_kp_write, __pyx_k_write, sizeof(__pyx_k_write), 1, 1, 1}, + {&__pyx_kp_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 1, 0}, + {&__pyx_kp_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 1, 1, 1}, + {&__pyx_kp_iteritems, __pyx_k_iteritems, sizeof(__pyx_k_iteritems), 1, 1, 1}, + {&__pyx_kp_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 1, 1, 1}, + {&__pyx_kp_getvalue, __pyx_k_getvalue, sizeof(__pyx_k_getvalue), 1, 1, 1}, + {&__pyx_kp_read, __pyx_k_read, sizeof(__pyx_k_read), 1, 1, 1}, + {&__pyx_kp_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 0}, + {&__pyx_kp_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 0}, + {0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_staticmethod = __Pyx_GetName(__pyx_b, __pyx_kp_staticmethod); if (!__pyx_builtin_staticmethod) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_kp_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + return 0; + __pyx_L1_error:; + return -1; +} + +#if PY_MAJOR_VERSION < 3 +PyMODINIT_FUNC initmsgpack(void); /*proto*/ +PyMODINIT_FUNC initmsgpack(void) +#else +PyMODINIT_FUNC PyInit_msgpack(void); /*proto*/ +PyMODINIT_FUNC PyInit_msgpack(void) +#endif +{ + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + #ifdef CYTHON_REFNANNY + void* __pyx_refchk = NULL; + __Pyx_Refnanny = __Pyx_ImportRefcountAPI("refnanny"); + if (!__Pyx_Refnanny) { + PyErr_Clear(); + __Pyx_Refnanny = __Pyx_ImportRefcountAPI("Cython.Runtime.refnanny"); + if (!__Pyx_Refnanny) + Py_FatalError("failed to import refnanny module"); + } + __pyx_refchk = __Pyx_Refnanny->NewContext("PyMODINIT_FUNC PyInit_msgpack(void)", __LINE__, __FILE__); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Library function declarations ---*/ + __pyx_init_filenames(); + /*--- Threads initialization code ---*/ + #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + #ifdef WITH_THREAD /* Python build with threading support? */ + PyEval_InitThreads(); + #endif + #endif + /*--- Initialize various global constants etc. ---*/ + if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Module creation code ---*/ + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4(__Pyx_NAMESTR("msgpack"), __pyx_methods, 0, 0, PYTHON_API_VERSION); + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + #endif + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + #if PY_MAJOR_VERSION < 3 + Py_INCREF(__pyx_m); + #endif + __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (__pyx_module_is_main_msgpack) { + if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + } + /*--- Builtin init code ---*/ + if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_skip_dispatch = 0; + /*--- Global init code ---*/ + /*--- Function export code ---*/ + /*--- Type init code ---*/ + __pyx_vtabptr_7msgpack_Packer = &__pyx_vtable_7msgpack_Packer; + #if PY_MAJOR_VERSION >= 3 + __pyx_vtable_7msgpack_Packer.__pack = (PyObject *(*)(struct __pyx_obj_7msgpack_Packer *, PyObject *))__pyx_f_7msgpack_6Packer___pack; + #else + *(void(**)(void))&__pyx_vtable_7msgpack_Packer.__pack = (void(*)(void))__pyx_f_7msgpack_6Packer___pack; + #endif + if (PyType_Ready(&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_7msgpack_Packer.tp_dict, __pyx_vtabptr_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Packer", (PyObject *)&__pyx_type_7msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_7msgpack_Packer = &__pyx_type_7msgpack_Packer; + if (PyType_Ready(&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Unpacker", (PyObject *)&__pyx_type_7msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_7msgpack_Unpacker = &__pyx_type_7msgpack_Unpacker; + /*--- Type import code ---*/ + /*--- Function import code ---*/ + /*--- Execution code ---*/ + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":3 + * # coding: utf-8 + * + * from cStringIO import StringIO # <<<<<<<<<<<<<< + * + * cdef extern from "Python.h": + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_INCREF(__pyx_kp_StringIO); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_StringIO); + __Pyx_GIVEREF(__pyx_kp_StringIO); + __pyx_1 = __Pyx_Import(__pyx_kp_cStringIO, ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_2 = PyObject_GetAttr(__pyx_1, __pyx_kp_StringIO); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_2); + if (PyObject_SetAttr(__pyx_m, __pyx_kp_StringIO, __pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_2); __pyx_2 = 0; + __Pyx_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":37 + * + * + * cdef int BUFF_SIZE=2*1024 # <<<<<<<<<<<<<< + * + * cdef class Packer: + */ + __pyx_v_7msgpack_BUFF_SIZE = 2048; + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":145 + * raise TypeError, "can't serialize %r" % (o,) + * + * def pack(self, obj, flush=True): # <<<<<<<<<<<<<< + * self.__pack(obj) + * if flush: + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_k_1 = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_GIVEREF(__pyx_k_1); + + /* "/home/inada-n/work/msgpack/python/msgpack.pyx":202 + * cdef class Unpacker: + * """Do nothing. This function is for symmetric to Packer""" + * unpack = staticmethod(unpacks) # <<<<<<<<<<<<<< + */ + __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_kp_unpacks); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_1); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_1); + __Pyx_GIVEREF(__pyx_1); + __pyx_1 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_staticmethod, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + if (PyDict_SetItem((PyObject *)__pyx_ptype_7msgpack_Unpacker->tp_dict, __pyx_kp_unpack, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_7msgpack_Unpacker); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_1); + __Pyx_XDECREF(__pyx_2); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("msgpack"); + Py_DECREF(__pyx_m); __pyx_m = 0; + __pyx_L0:; + __Pyx_FinishRefcountContext(); + #if PY_MAJOR_VERSION < 3 + return; + #else + return __pyx_m; + #endif +} + +static const char *__pyx_filenames[] = { + "msgpack.pyx", +}; + +/* Runtime support code */ + +static void __pyx_init_filenames(void) { + __pyx_f = __pyx_filenames; +} + +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, + PyObject* kw_name) +{ + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION >= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AS_STRING(kw_name)); + #endif +} + +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *number, *more_or_less; + + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + number = (num_expected == 1) ? "" : "s"; + PyErr_Format(PyExc_TypeError, + #if PY_VERSION_HEX < 0x02050000 + "%s() takes %s %d positional argument%s (%d given)", + #else + "%s() takes %s %zd positional argument%s (%zd given)", + #endif + func_name, more_or_less, num_expected, number, num_found); +} + +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + + while (PyDict_Next(kwds, &pos, &key, &value)) { + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; + } else { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key))) { + #else + if (unlikely(!PyUnicode_CheckExact(key)) && unlikely(!PyUnicode_Check(key))) { + #endif + goto invalid_keyword_type; + } else { + for (name = first_kw_arg; *name; name++) { + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) break; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) break; + #endif + } + if (*name) { + values[name-argnames] = value; + } else { + /* unexpected keyword found */ + for (name=argnames; name != first_kw_arg; name++) { + if (**name == key) goto arg_passed_twice; + #if PY_MAJOR_VERSION >= 3 + if (PyUnicode_GET_SIZE(**name) == PyUnicode_GET_SIZE(key) && + PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice; + #else + if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) && + _PyString_Eq(**name, key)) goto arg_passed_twice; + #endif + } + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + } + } + } + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, **name); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%s() got an unexpected keyword argument '%s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) { + PyObject *__import__ = 0; + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + __import__ = __Pyx_GetAttrString(__pyx_b, "__import__"); + if (!__import__) + goto bad; + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + module = PyObject_CallFunctionObjArgs(__import__, + name, global_dict, empty_dict, list, NULL); +bad: + Py_XDECREF(empty_list); + Py_XDECREF(__import__); + Py_XDECREF(empty_dict); + return module; +} + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { + PyObject *result; + result = PyObject_GetAttr(dict, name); + if (!result) + PyErr_SetObject(PyExc_NameError, name); + return result; +} + +static INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + #if PY_VERSION_HEX < 0x02050000 + "need more than %d value%s to unpack", (int)index, + #else + "need more than %zd value%s to unpack", index, + #endif + (index == 1) ? "" : "s"); +} + +static INLINE void __Pyx_RaiseTooManyValuesError(void) { + PyErr_SetString(PyExc_ValueError, "too many values to unpack"); +} + +static PyObject *__Pyx_UnpackItem(PyObject *iter, Py_ssize_t index) { + PyObject *item; + if (!(item = PyIter_Next(iter))) { + if (!PyErr_Occurred()) { + __Pyx_RaiseNeedMoreValuesError(index); + } + } + return item; +} + +static int __Pyx_EndUnpack(PyObject *iter) { + PyObject *item; + if ((item = PyIter_Next(iter))) { + Py_DECREF(item); + __Pyx_RaiseTooManyValuesError(); + return -1; + } + else if (!PyErr_Occurred()) + return 0; + else + return -1; +} + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { + Py_XINCREF(type); + Py_XINCREF(value); + Py_XINCREF(tb); + /* First, check the traceback argument, replacing None with NULL. */ + if (tb == Py_None) { + Py_DECREF(tb); + tb = 0; + } + else if (tb != NULL && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + /* Next, replace a missing value with None */ + if (value == NULL) { + value = Py_None; + Py_INCREF(value); + } + #if PY_VERSION_HEX < 0x02050000 + if (!PyClass_Check(type)) + #else + if (!PyType_Check(type)) + #endif + { + /* Raising an instance. The value should be a dummy. */ + if (value != Py_None) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + /* Normalize to raise , */ + Py_DECREF(value); + value = type; + #if PY_VERSION_HEX < 0x02050000 + if (PyInstance_Check(type)) { + type = (PyObject*) ((PyInstanceObject*)type)->in_class; + Py_INCREF(type); + } + else { + type = 0; + PyErr_SetString(PyExc_TypeError, + "raise: exception must be an old-style class or instance"); + goto raise_error; + } + #else + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + #endif + } + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} + +static INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + +#if PY_MAJOR_VERSION >= 3 + /* Note: this is a temporary work-around to prevent crashes in Python 3.0 */ + if ((tstate->exc_type != NULL) & (tstate->exc_type != Py_None)) { + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + PyErr_NormalizeException(&type, &value, &tb); + PyErr_NormalizeException(&tmp_type, &tmp_value, &tmp_tb); + tstate->exc_type = 0; + tstate->exc_value = 0; + tstate->exc_traceback = 0; + PyException_SetContext(value, tmp_value); + Py_DECREF(tmp_type); + Py_XDECREF(tmp_tb); + } +#endif + + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +} + +static INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { + PyThreadState *tstate = PyThreadState_GET(); + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +} + + +static INLINE int __Pyx_StrEq(const char *s1, const char *s2) { + while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } + return *s1 == *s2; +} + +static INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { + if (sizeof(unsigned char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned char)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (unsigned char)-1; + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned char"); + return (unsigned char)-1; + } + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to unsigned char"); + return (unsigned char)-1; + } + return (unsigned char)val; + } + return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); +} + +static INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { + if (sizeof(unsigned short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned short)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (unsigned short)-1; + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned short"); + return (unsigned short)-1; + } + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to unsigned short"); + return (unsigned short)-1; + } + return (unsigned short)val; + } + return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); +} + +static INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { + if (sizeof(unsigned int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(unsigned int)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (unsigned int)-1; + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned int"); + return (unsigned int)-1; + } + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to unsigned int"); + return (unsigned int)-1; + } + return (unsigned int)val; + } + return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); +} + +static INLINE char __Pyx_PyInt_AsChar(PyObject* x) { + if (sizeof(char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(char)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (char)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to char"); + return (char)-1; + } + return (char)val; + } + return (char)__Pyx_PyInt_AsLong(x); +} + +static INLINE short __Pyx_PyInt_AsShort(PyObject* x) { + if (sizeof(short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(short)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (short)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to short"); + return (short)-1; + } + return (short)val; + } + return (short)__Pyx_PyInt_AsLong(x); +} + +static INLINE int __Pyx_PyInt_AsInt(PyObject* x) { + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (int)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { + if (sizeof(signed char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed char)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (signed char)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to signed char"); + return (signed char)-1; + } + return (signed char)val; + } + return (signed char)__Pyx_PyInt_AsSignedLong(x); +} + +static INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { + if (sizeof(signed short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed short)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (signed short)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to signed short"); + return (signed short)-1; + } + return (signed short)val; + } + return (signed short)__Pyx_PyInt_AsSignedLong(x); +} + +static INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { + if (sizeof(signed int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(signed int)val)) { + if (unlikely(val == -1 && PyErr_Occurred())) + return (signed int)-1; + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to signed int"); + return (signed int)-1; + } + return (signed int)val; + } + return (signed int)__Pyx_PyInt_AsSignedLong(x); +} + +static INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return (unsigned long)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return PyLong_AsUnsignedLong(x); + } else { + unsigned long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned long)-1; + val = __Pyx_PyInt_AsUnsignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return (unsigned PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned PY_LONG_LONG"); + return (unsigned PY_LONG_LONG)-1; + } + return PyLong_AsUnsignedLongLong(x); + } else { + unsigned PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (unsigned PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsUnsignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE long __Pyx_PyInt_AsLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + return (long)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + return PyLong_AsLong(x); + } else { + long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (long)-1; + val = __Pyx_PyInt_AsLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + return (PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + return PyLong_AsLongLong(x); + } else { + PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + return (signed long)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + return PyLong_AsLong(x); + } else { + signed long val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed long)-1; + val = __Pyx_PyInt_AsSignedLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + return (signed PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) { + return PyLong_AsLongLong(x); + } else { + signed PY_LONG_LONG val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (signed PY_LONG_LONG)-1; + val = __Pyx_PyInt_AsSignedLongLong(tmp); + Py_DECREF(tmp); + return val; + } +} + +static void __Pyx_WriteUnraisable(const char *name) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +} + +static int __Pyx_SetVtable(PyObject *dict, void *vtable) { + PyObject *pycobj = 0; + int result; + + pycobj = PyCObject_FromVoidPtr(vtable, 0); + if (!pycobj) + goto bad; + if (PyDict_SetItemString(dict, "__pyx_vtable__", pycobj) < 0) + goto bad; + result = 0; + goto done; + +bad: + result = -1; +done: + Py_XDECREF(pycobj); + return result; +} + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" + +static void __Pyx_AddTraceback(const char *funcname) { + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + PyObject *py_globals = 0; + PyObject *empty_string = 0; + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(__pyx_filename); + #else + py_srcfile = PyUnicode_FromString(__pyx_filename); + #endif + if (!py_srcfile) goto bad; + if (__pyx_clineno) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, __pyx_clineno); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_globals = PyModule_GetDict(__pyx_m); + if (!py_globals) goto bad; + #if PY_MAJOR_VERSION < 3 + empty_string = PyString_FromStringAndSize("", 0); + #else + empty_string = PyBytes_FromStringAndSize("", 0); + #endif + if (!empty_string) goto bad; + py_code = PyCode_New( + 0, /*int argcount,*/ + #if PY_MAJOR_VERSION >= 3 + 0, /*int kwonlyargcount,*/ + #endif + 0, /*int nlocals,*/ + 0, /*int stacksize,*/ + 0, /*int flags,*/ + empty_string, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + __pyx_lineno, /*int firstlineno,*/ + empty_string /*PyObject *lnotab*/ + ); + if (!py_code) goto bad; + py_frame = PyFrame_New( + PyThreadState_GET(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + py_globals, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + py_frame->f_lineno = __pyx_lineno; + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + Py_XDECREF(empty_string); + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION < 3 + if (t->is_unicode && (!t->is_identifier)) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + #else /* Python 3+ has unicode identifiers */ + if (t->is_identifier || (t->is_unicode && t->intern)) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->is_unicode) { + *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1); + } else { + *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1); + } + #endif + if (!*t->p) + return -1; + ++t; + } + return 0; +} + +/* Type Conversion Functions */ + +static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + if (x == Py_True) return 1; + else if ((x == Py_False) | (x == Py_None)) return 0; + else return PyObject_IsTrue(x); +} + +static INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { + PyNumberMethods *m; + const char *name = NULL; + PyObject *res = NULL; +#if PY_VERSION_HEX < 0x03000000 + if (PyInt_Check(x) || PyLong_Check(x)) +#else + if (PyLong_Check(x)) +#endif + return Py_INCREF(x), x; + m = Py_TYPE(x)->tp_as_number; +#if PY_VERSION_HEX < 0x03000000 + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = PyNumber_Long(x); + } +#else + if (m && m->nb_int) { + name = "int"; + res = PyNumber_Long(x); + } +#endif + if (res) { +#if PY_VERSION_HEX < 0x03000000 + if (!PyInt_Check(res) && !PyLong_Check(res)) { +#else + if (!PyLong_Check(res)) { +#endif + PyErr_Format(PyExc_TypeError, + "__%s__ returned non-%s (type %.200s)", + name, name, Py_TYPE(res)->tp_name); + Py_DECREF(res); + return NULL; + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} + +static INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject* x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} + +static INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { +#if PY_VERSION_HEX < 0x02050000 + if (ival <= LONG_MAX) + return PyInt_FromLong((long)ival); + else { + unsigned char *bytes = (unsigned char *) &ival; + int one = 1; int little = (int)*(unsigned char*)&one; + return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); + } +#else + return PyInt_FromSize_t(ival); +#endif +} + +static INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) { + unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x); + if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) { + return (size_t)-1; + } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) { + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to size_t"); + return (size_t)-1; + } + return (size_t)val; +} + + diff --git a/python/setup.py b/python/setup.py index 4bb8693..f4c84dc 100644 --- a/python/setup.py +++ b/python/setup.py @@ -2,7 +2,7 @@ from distutils.core import setup, Extension version = '0.0.1' -msgpack_mod = Extension('msgpack', sources=['msgpack.c'], extra_compile_args=["-O3"]) +msgpack_mod = Extension('msgpack', sources=['msgpack.cpp']) desc = 'MessagePack serializer/desirializer.' long_desc = desc + """ diff --git a/python/unpack.h b/python/unpack.h index 3e99123..694e816 100644 --- a/python/unpack.h +++ b/python/unpack.h @@ -16,12 +16,28 @@ * limitations under the License. */ +#include +#include + #define MSGPACK_MAX_STACK_SIZE (1024) #include "msgpack/unpack_define.h" -typedef struct { - struct {unsigned int size, last} array_stack[MSGPACK_MAX_STACK_SIZE]; +using namespace std; + +typedef struct unpack_user { + struct array_stack_type{unsigned int size, last;}; + array_stack_type array_stack[MSGPACK_MAX_STACK_SIZE]; int array_current; + + map str_cache; + + ~unpack_user() { + map::iterator it, itend; + itend = str_cache.end(); + for (it = str_cache.begin(); it != itend; ++it) { + Py_DECREF(it->second); + } + } } unpack_user; @@ -141,9 +157,21 @@ static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_obje static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) { - *o = PyString_FromStringAndSize(p, l); - if (l < 16) { // without foundation - PyString_InternInPlace(o); + if (l < 16) { + string s(p, l); + map::iterator it = u->str_cache.find(s); + if (it != u->str_cache.end()) { + *o = it->second; + Py_INCREF(*o); + } + else { + *o = PyString_FromStringAndSize(p, l); + Py_INCREF(*o); + u->str_cache[s] = *o; + } + } + else { + *o = PyString_FromStringAndSize(p, l); } return 0; } -- cgit v1.2.1 From 075081a521c8287759847f1aa846b88fef1f0046 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 22 Jun 2009 14:28:04 +0900 Subject: Fix manifest. --- python/MANIFEST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/MANIFEST b/python/MANIFEST index dc042ae..dd0c7d2 100644 --- a/python/MANIFEST +++ b/python/MANIFEST @@ -1,4 +1,4 @@ -msgpack.c +msgpack.cpp setup.py pack.h unpack.h -- cgit v1.2.1 From 87f5df1503e70efd2bb9e9565259f1ed37a45933 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 22 Jun 2009 15:59:02 +0900 Subject: Use std::stack. --- python/msgpack/unpack.h | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'python') diff --git a/python/msgpack/unpack.h b/python/msgpack/unpack.h index 694e816..daeb54c 100644 --- a/python/msgpack/unpack.h +++ b/python/msgpack/unpack.h @@ -18,17 +18,21 @@ #include #include +#include #define MSGPACK_MAX_STACK_SIZE (1024) #include "msgpack/unpack_define.h" using namespace std; -typedef struct unpack_user { - struct array_stack_type{unsigned int size, last;}; - array_stack_type array_stack[MSGPACK_MAX_STACK_SIZE]; - int array_current; - +struct array_context { + unsigned int size; + unsigned int last; + stack_item(unsigned int size) : size(size), last(0) + {} +}; +struct unpack_user { + stack array_stack; map str_cache; ~unpack_user() { @@ -38,7 +42,7 @@ typedef struct unpack_user { Py_DECREF(it->second); } } -} unpack_user; +}; #define msgpack_unpack_struct(name) \ @@ -60,7 +64,6 @@ typedef struct template_context template_context; static inline msgpack_unpack_object template_callback_root(unpack_user* u) { - u->array_current = -1; return NULL; } @@ -113,9 +116,7 @@ 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) { if (n > 0) { - int cur = ++u->array_current; - u->array_stack[cur].size = n; - u->array_stack[cur].last = 0; + u->array_stack.push(stack_item(n)); *o = PyList_New(n); } else { @@ -126,17 +127,13 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac static inline int template_callback_array_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object o) { - int cur = u->array_current; - int n = u->array_stack[cur].size; - int last = u->array_stack[cur].last; + unsigned int n = u->array_stack.top().size; + unsigned int &last = u->array_stack.top().last; PyList_SetItem(*c, last, o); last++; if (last >= n) { - u->array_current--; - } - else { - u->array_stack[cur].last = last; + u->array_stack.pop(); } return 0; } -- cgit v1.2.1 From 46d7c656214073cde4c458c7cf1eb03e2d33dbd9 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 22 Jun 2009 19:49:02 +0900 Subject: Fix compile error. --- python/msgpack/pack.h | 12 ------------ python/msgpack/unpack.h | 4 ++-- 2 files changed, 2 insertions(+), 14 deletions(-) (limited to 'python') diff --git a/python/msgpack/pack.h b/python/msgpack/pack.h index f3935fb..544950b 100644 --- a/python/msgpack/pack.h +++ b/python/msgpack/pack.h @@ -15,18 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#if _MSC_VER -typedef signed char uint8_t; -typedef unsigned char uint8_t; -typedef short int16_t; -typedef unsigned short uint16_t; -typedef int int32_t; -typedef unsigned int uint32_t; -typedef long long int64_t; -typedef unsigned long long uint64_t; -#else -#include -#endif #include #include diff --git a/python/msgpack/unpack.h b/python/msgpack/unpack.h index daeb54c..b753493 100644 --- a/python/msgpack/unpack.h +++ b/python/msgpack/unpack.h @@ -28,7 +28,7 @@ using namespace std; struct array_context { unsigned int size; unsigned int last; - stack_item(unsigned int size) : size(size), last(0) + array_context(unsigned int size) : size(size), last(0) {} }; struct unpack_user { @@ -116,7 +116,7 @@ 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) { if (n > 0) { - u->array_stack.push(stack_item(n)); + u->array_stack.push(array_context(n)); *o = PyList_New(n); } else { -- cgit v1.2.1 From 7d5f04917ea4986db096ad647b36ce509583ae5c Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 22 Jun 2009 19:55:46 +0900 Subject: Update manifest. --- python/MANIFEST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python') diff --git a/python/MANIFEST b/python/MANIFEST index 8b21b4c..6983a33 100644 --- a/python/MANIFEST +++ b/python/MANIFEST @@ -1,7 +1,7 @@ -msgpack.cpp setup.py msgpack/pack.h msgpack/unpack.h +msgpack/_msgpack.pyx include/msgpack/pack_define.h include/msgpack/pack_template.h include/msgpack/unpack_define.h -- cgit v1.2.1 From b8e5b918a3c76da04fc1e5653b94dd99bf0b83c6 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 22 Jun 2009 22:50:05 +0900 Subject: Update manifest. --- python/MANIFEST | 1 + 1 file changed, 1 insertion(+) (limited to 'python') diff --git a/python/MANIFEST b/python/MANIFEST index 6983a33..1fe22ec 100644 --- a/python/MANIFEST +++ b/python/MANIFEST @@ -2,6 +2,7 @@ setup.py msgpack/pack.h msgpack/unpack.h msgpack/_msgpack.pyx +msgpack/__init__.py include/msgpack/pack_define.h include/msgpack/pack_template.h include/msgpack/unpack_define.h -- cgit v1.2.1 From 99d0a41ec6a6169456dcfe64cd6972520a768b71 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 24 Jun 2009 01:13:22 +0900 Subject: Fix setup script bug. --- python/setup.py | 1 + 1 file changed, 1 insertion(+) (limited to 'python') diff --git a/python/setup.py b/python/setup.py index eb897f2..1cbc24e 100644 --- a/python/setup.py +++ b/python/setup.py @@ -32,6 +32,7 @@ setup(name='msgpack', version=version, cmdclass={'build_ext': build_ext}, ext_modules=[msgpack_mod], + packages=['msgpack'], description=desc, long_description=long_desc, ) -- cgit v1.2.1 From dd53b141ef6d2495d0cc14c8949180a74ae3caf6 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 24 Jun 2009 01:13:39 +0900 Subject: Remove unneccessary value. --- python/msgpack/unpack.h | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'python') diff --git a/python/msgpack/unpack.h b/python/msgpack/unpack.h index b753493..12702d8 100644 --- a/python/msgpack/unpack.h +++ b/python/msgpack/unpack.h @@ -25,14 +25,8 @@ using namespace std; -struct array_context { - unsigned int size; - unsigned int last; - array_context(unsigned int size) : size(size), last(0) - {} -}; struct unpack_user { - stack array_stack; + stack array_stack; map str_cache; ~unpack_user() { @@ -116,7 +110,7 @@ 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) { if (n > 0) { - u->array_stack.push(array_context(n)); + u->array_stack.push(0); *o = PyList_New(n); } else { @@ -127,12 +121,12 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac static inline int template_callback_array_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object o) { - unsigned int n = u->array_stack.top().size; - unsigned int &last = u->array_stack.top().last; - - PyList_SetItem(*c, last, o); + unsigned int &last = u->array_stack.top(); + PyList_SET_ITEM(*c, last, o); last++; - if (last >= n) { + + Py_ssize_t len = PyList_GET_SIZE(*c); + if (last >= len) { u->array_stack.pop(); } return 0; -- cgit v1.2.1 From 3fd28d07928c51cb563f35d9dddb0c7867ac9875 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 24 Jun 2009 01:38:48 +0900 Subject: Remove duplicated values. --- python/include | 1 - python/msgpack/pack.h | 4 +- python/msgpack/pack_define.h | 26 ++ python/msgpack/pack_template.h | 741 +++++++++++++++++++++++++++++++++++++++ python/msgpack/unpack.h | 53 +-- python/msgpack/unpack_define.h | 129 +++++++ python/msgpack/unpack_template.h | 363 +++++++++++++++++++ 7 files changed, 1276 insertions(+), 41 deletions(-) delete mode 120000 python/include create mode 100644 python/msgpack/pack_define.h create mode 100644 python/msgpack/pack_template.h create mode 100644 python/msgpack/unpack_define.h create mode 100644 python/msgpack/unpack_template.h (limited to 'python') diff --git a/python/include b/python/include deleted file mode 120000 index a96aa0e..0000000 --- a/python/include +++ /dev/null @@ -1 +0,0 @@ -.. \ No newline at end of file diff --git a/python/msgpack/pack.h b/python/msgpack/pack.h index 544950b..9bd6b68 100644 --- a/python/msgpack/pack.h +++ b/python/msgpack/pack.h @@ -18,7 +18,7 @@ #include #include -#include "msgpack/pack_define.h" +#include "pack_define.h" #ifdef __cplusplus extern "C" { @@ -82,7 +82,7 @@ static inline int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_ #define msgpack_pack_append_buffer(user, buf, len) \ return (*(user)->callback)((user)->data, (const char*)buf, len) -#include "msgpack/pack_template.h" +#include "pack_template.h" static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) { diff --git a/python/msgpack/pack_define.h b/python/msgpack/pack_define.h new file mode 100644 index 0000000..33408e5 --- /dev/null +++ b/python/msgpack/pack_define.h @@ -0,0 +1,26 @@ +/* + * MessagePack unpacking routine template + * + * Copyright (C) 2008-2009 FURUHASHI Sadayuki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MSGPACK_PACK_DEFINE_H__ +#define MSGPACK_PACK_DEFINE_H__ + +#include +#include +#include + +#endif /* msgpack/pack_define.h */ + diff --git a/python/msgpack/pack_template.h b/python/msgpack/pack_template.h new file mode 100644 index 0000000..aa620f5 --- /dev/null +++ b/python/msgpack/pack_template.h @@ -0,0 +1,741 @@ +/* + * MessagePack packing routine template + * + * Copyright (C) 2008-2009 FURUHASHI Sadayuki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define __LITTLE_ENDIAN__ +#elif __BYTE_ORDER == __BIG_ENDIAN +#define __BIG_ENDIAN__ +#endif +#endif + + +#ifdef __LITTLE_ENDIAN__ + +#define STORE8_BE8(d) \ + ((uint8_t*)&d)[0] + + +#define STORE16_BE8(d) \ + ((uint8_t*)&d)[0] + +#define STORE16_BE16(d) \ + ((uint8_t*)&d)[1], ((uint8_t*)&d)[0] + + +#define STORE32_BE8(d) \ + ((uint8_t*)&d)[0] + +#define STORE32_BE16(d) \ + ((uint8_t*)&d)[1], ((uint8_t*)&d)[0] + +#define STORE32_BE32(d) \ + ((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0] + + +#define STORE64_BE8(d) \ + ((uint8_t*)&d)[0] + +#define STORE64_BE16(d) \ + ((uint8_t*)&d)[1], ((uint8_t*)&d)[0] + +#define STORE64_BE32(d) \ + ((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0] + +#define STORE64_BE64(d) \ + ((uint8_t*)&d)[7], ((uint8_t*)&d)[6], ((uint8_t*)&d)[5], ((uint8_t*)&d)[4], \ + ((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0] + + +#elif __BIG_ENDIAN__ + +#define STORE8_BE8(d) \ + ((uint8_t*)&d)[0] + + +#define STORE16_BE8(d) \ + ((uint8_t*)&d)[1] + +#define STORE16_BE16(d) \ + ((uint8_t*)&d)[0], ((uint8_t*)&d)[1] + + +#define STORE32_BE8(d) \ + ((uint8_t*)&d)[3] + +#define STORE32_BE16(d) \ + ((uint8_t*)&d)[2], ((uint8_t*)&d)[3] + +#define STORE32_BE32(d) \ + ((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3] + + +#define STORE64_BE8(d) \ + ((uint8_t*)&d)[7] + +#define STORE64_BE16(d) \ + ((uint8_t*)&d)[6], ((uint8_t*)&d)[7] + +#define STORE64_BE32(d) \ + ((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7] + +#define STORE64_BE64(d) \ + ((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3], \ + ((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7] + +#endif + +#ifndef msgpack_pack_inline_func +#error msgpack_pack_inline_func template is not defined +#endif + +#ifndef msgpack_pack_user +#error msgpack_pack_user type is not defined +#endif + +#ifndef msgpack_pack_append_buffer +#error msgpack_pack_append_buffer callback is not defined +#endif + + +/* + * Integer + */ + +#define msgpack_pack_real_uint8(x, d) \ +do { \ + if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \ + } else { \ + /* unsigned 8 */ \ + const unsigned char buf[2] = {0xcc, STORE8_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ +} while(0) + +#define msgpack_pack_real_uint16(x, d) \ +do { \ + if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \ + } else if(d < (1<<8)) { \ + /* unsigned 8 */ \ + const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else { \ + /* unsigned 16 */ \ + const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \ + msgpack_pack_append_buffer(x, buf, 3); \ + } \ +} while(0) + +#define msgpack_pack_real_uint32(x, d) \ +do { \ + if(d < (1<<8)) { \ + if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \ + } else { \ + /* unsigned 8 */ \ + const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } else { \ + if(d < (1<<16)) { \ + /* unsigned 16 */ \ + const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* unsigned 32 */ \ + const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \ + msgpack_pack_append_buffer(x, buf, 5); \ + } \ + } \ +} while(0) + +#define msgpack_pack_real_uint64(x, d) \ +do { \ + if(d < (1ULL<<8)) { \ + if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \ + } else { \ + /* unsigned 8 */ \ + const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } else { \ + if(d < (1ULL<<16)) { \ + /* signed 16 */ \ + const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else if(d < (1ULL<<32)) { \ + /* signed 32 */ \ + const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \ + msgpack_pack_append_buffer(x, buf, 5); \ + } else { \ + /* signed 64 */ \ + const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \ + msgpack_pack_append_buffer(x, buf, 9); \ + } \ + } \ +} while(0) + +#define msgpack_pack_real_int8(x, d) \ +do { \ + if(d < -(1<<5)) { \ + /* signed 8 */ \ + const unsigned char buf[2] = {0xd0, STORE8_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \ + } \ +} while(0) + +#define msgpack_pack_real_int16(x, d) \ +do { \ + if(d < -(1<<5)) { \ + if(d < -(1<<7)) { \ + /* signed 16 */ \ + const unsigned char buf[3] = {0xd1, STORE16_BE16(d)}; \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* signed 8 */ \ + const unsigned char buf[2] = {0xd0, STORE16_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } else if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \ + } else { \ + if(d < (1<<8)) { \ + /* unsigned 8 */ \ + const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else { \ + /* unsigned 16 */ \ + const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \ + msgpack_pack_append_buffer(x, buf, 3); \ + } \ + } \ +} while(0) + +#define msgpack_pack_real_int32(x, d) \ +do { \ + if(d < -(1<<5)) { \ + if(d < -(1<<15)) { \ + /* signed 32 */ \ + const unsigned char buf[5] = {0xd2, STORE32_BE32(d)}; \ + msgpack_pack_append_buffer(x, buf, 5); \ + } else if(d < -(1<<7)) { \ + /* signed 16 */ \ + const unsigned char buf[3] = {0xd1, STORE32_BE16(d)}; \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* signed 8 */ \ + const unsigned char buf[2] = {0xd0, STORE32_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } else if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \ + } else { \ + if(d < (1<<8)) { \ + /* unsigned 8 */ \ + const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else if(d < (1<<16)) { \ + /* unsigned 16 */ \ + const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* unsigned 32 */ \ + const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \ + msgpack_pack_append_buffer(x, buf, 5); \ + } \ + } \ +} while(0) + +#define msgpack_pack_real_int64(x, d) \ +do { \ + if(d < -(1LL<<5)) { \ + if(d < -(1LL<<15)) { \ + if(d < -(1LL<<31)) { \ + /* signed 64 */ \ + const unsigned char buf[9] = {0xd3, STORE64_BE64(d)}; \ + msgpack_pack_append_buffer(x, buf, 9); \ + } else { \ + /* signed 32 */ \ + const unsigned char buf[5] = {0xd2, STORE64_BE32(d)}; \ + msgpack_pack_append_buffer(x, buf, 5); \ + } \ + } else { \ + if(d < -(1<<7)) { \ + /* signed 16 */ \ + const unsigned char buf[3] = {0xd1, STORE64_BE16(d)}; \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* signed 8 */ \ + const unsigned char buf[2] = {0xd0, STORE64_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } \ + } else if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \ + } else { \ + if(d < (1LL<<16)) { \ + if(d < (1<<8)) { \ + /* unsigned 8 */ \ + const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else { \ + /* unsigned 16 */ \ + const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \ + msgpack_pack_append_buffer(x, buf, 3); \ + } \ + } else { \ + if(d < (1LL<<32)) { \ + /* unsigned 32 */ \ + const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \ + msgpack_pack_append_buffer(x, buf, 5); \ + } else { \ + /* unsigned 64 */ \ + const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \ + msgpack_pack_append_buffer(x, buf, 9); \ + } \ + } \ + } \ +} while(0) + + +#ifdef msgpack_pack_inline_func_fastint + +msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d) +{ + const unsigned char buf[2] = {0xcc, STORE8_BE8(d)}; + msgpack_pack_append_buffer(x, buf, 2); +} + +msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d) +{ + const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; + msgpack_pack_append_buffer(x, buf, 3); +} + +msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d) +{ + const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; + msgpack_pack_append_buffer(x, buf, 5); +} + +msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d) +{ + const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; + msgpack_pack_append_buffer(x, buf, 9); +} + +msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d) +{ + const unsigned char buf[2] = {0xd0, STORE8_BE8(d)}; + msgpack_pack_append_buffer(x, buf, 2); +} + +msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d) +{ + const unsigned char buf[3] = {0xd1, STORE16_BE16(d)}; + msgpack_pack_append_buffer(x, buf, 3); +} + +msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d) +{ + const unsigned char buf[5] = {0xd2, STORE32_BE32(d)}; + msgpack_pack_append_buffer(x, buf, 5); +} + +msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d) +{ + const unsigned char buf[9] = {0xd3, STORE64_BE64(d)}; + msgpack_pack_append_buffer(x, buf, 9); +} + +#undef msgpack_pack_inline_func_fastint +#endif + + +msgpack_pack_inline_func(_uint8)(msgpack_pack_user x, uint8_t d) +{ + msgpack_pack_real_uint8(x, d); +} + +msgpack_pack_inline_func(_uint16)(msgpack_pack_user x, uint16_t d) +{ + msgpack_pack_real_uint16(x, d); +} + +msgpack_pack_inline_func(_uint32)(msgpack_pack_user x, uint32_t d) +{ + msgpack_pack_real_uint32(x, d); +} + +msgpack_pack_inline_func(_uint64)(msgpack_pack_user x, uint64_t d) +{ + msgpack_pack_real_uint64(x, d); +} + +msgpack_pack_inline_func(_int8)(msgpack_pack_user x, int8_t d) +{ + msgpack_pack_real_int8(x, d); +} + +msgpack_pack_inline_func(_int16)(msgpack_pack_user x, int16_t d) +{ + msgpack_pack_real_int16(x, d); +} + +msgpack_pack_inline_func(_int32)(msgpack_pack_user x, int32_t d) +{ + msgpack_pack_real_int32(x, d); +} + +msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d) +{ + msgpack_pack_real_int64(x, d); +} + + +#ifdef msgpack_pack_inline_func_cint + +msgpack_pack_inline_func_cint(_short)(msgpack_pack_user x, short d) +{ +#if defined(SIZEOF_SHORT) || defined(SHRT_MAX) +#if SIZEOF_SHORT == 2 || SHRT_MAX == 0x7fff + msgpack_pack_real_int16(x, d); +#elif SIZEOF_SHORT == 4 || SHRT_MAX == 0x7fffffff + msgpack_pack_real_int32(x, d); +#else + msgpack_pack_real_int64(x, d); +#endif +#else +if(sizeof(short) == 2) { + msgpack_pack_real_int16(x, d); +} else if(sizeof(short) == 4) { + msgpack_pack_real_int32(x, d); +} else { + msgpack_pack_real_int64(x, d); +} +#endif +} + +msgpack_pack_inline_func_cint(_int)(msgpack_pack_user x, int d) +{ +#if defined(SIZEOF_INT) || defined(INT_MAX) +#if SIZEOF_INT == 2 || INT_MAX == 0x7fff + msgpack_pack_real_int16(x, d); +#elif SIZEOF_INT == 4 || INT_MAX == 0x7fffffff + msgpack_pack_real_int32(x, d); +#else + msgpack_pack_real_int64(x, d); +#endif +#else +if(sizeof(int) == 2) { + msgpack_pack_real_int16(x, d); +} else if(sizeof(int) == 4) { + msgpack_pack_real_int32(x, d); +} else { + msgpack_pack_real_int64(x, d); +} +#endif +} + +msgpack_pack_inline_func_cint(_long)(msgpack_pack_user x, long d) +{ +#if defined(SIZEOF_LONG) || defined(LONG_MAX) +#if SIZEOF_LONG == 2 || LONG_MAX == 0x7fffL + msgpack_pack_real_int16(x, d); +#elif SIZEOF_LONG == 4 || LONG_MAX == 0x7fffffffL + msgpack_pack_real_int32(x, d); +#else + msgpack_pack_real_int64(x, d); +#endif +#else +if(sizeof(long) == 2) { + msgpack_pack_real_int16(x, d); +} else if(sizeof(long) == 4) { + msgpack_pack_real_int32(x, d); +} else { + msgpack_pack_real_int64(x, d); +} +#endif +} + +msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d) +{ +#if defined(SIZEOF_LONG_LONG) || defined(LLONG_MAX) +#if SIZEOF_LONG_LONG == 2 || LLONG_MAX == 0x7fffL + msgpack_pack_real_int16(x, d); +#elif SIZEOF_LONG_LONG == 4 || LLONG_MAX == 0x7fffffffL + msgpack_pack_real_int32(x, d); +#else + msgpack_pack_real_int64(x, d); +#endif +#else +if(sizeof(long long) == 2) { + msgpack_pack_real_int16(x, d); +} else if(sizeof(long long) == 4) { + msgpack_pack_real_int32(x, d); +} else { + msgpack_pack_real_int64(x, d); +} +#endif +} + +msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d) +{ +#if defined(SIZEOF_SHORT) || defined(USHRT_MAX) +#if SIZEOF_SHORT == 2 || USHRT_MAX == 0xffffU + msgpack_pack_real_uint16(x, d); +#elif SIZEOF_SHORT == 4 || USHRT_MAX == 0xffffffffU + msgpack_pack_real_uint32(x, d); +#else + msgpack_pack_real_uint64(x, d); +#endif +#else +if(sizeof(unsigned short) == 2) { + msgpack_pack_real_uint16(x, d); +} else if(sizeof(unsigned short) == 4) { + msgpack_pack_real_uint32(x, d); +} else { + msgpack_pack_real_uint64(x, d); +} +#endif +} + +msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d) +{ +#if defined(SIZEOF_INT) || defined(UINT_MAX) +#if SIZEOF_INT == 2 || UINT_MAX == 0xffffU + msgpack_pack_real_uint16(x, d); +#elif SIZEOF_INT == 4 || UINT_MAX == 0xffffffffU + msgpack_pack_real_uint32(x, d); +#else + msgpack_pack_real_uint64(x, d); +#endif +#else +if(sizeof(unsigned int) == 2) { + msgpack_pack_real_uint16(x, d); +} else if(sizeof(unsigned int) == 4) { + msgpack_pack_real_uint32(x, d); +} else { + msgpack_pack_real_uint64(x, d); +} +#endif +} + +msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d) +{ +#if defined(SIZEOF_LONG) || defined(ULONG_MAX) +#if SIZEOF_LONG == 2 || ULONG_MAX == 0xffffUL + msgpack_pack_real_uint16(x, d); +#elif SIZEOF_LONG == 4 || ULONG_MAX == 0xffffffffUL + msgpack_pack_real_uint32(x, d); +#else + msgpack_pack_real_uint64(x, d); +#endif +#else +if(sizeof(unsigned int) == 2) { + msgpack_pack_real_uint16(x, d); +} else if(sizeof(unsigned int) == 4) { + msgpack_pack_real_uint32(x, d); +} else { + msgpack_pack_real_uint64(x, d); +} +#endif +} + +msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d) +{ +#if defined(SIZEOF_LONG_LONG) || defined(ULLONG_MAX) +#if SIZEOF_LONG_LONG == 2 || ULLONG_MAX == 0xffffUL + msgpack_pack_real_uint16(x, d); +#elif SIZEOF_LONG_LONG == 4 || ULLONG_MAX == 0xffffffffUL + msgpack_pack_real_uint32(x, d); +#else + msgpack_pack_real_uint64(x, d); +#endif +#else +if(sizeof(unsigned long long) == 2) { + msgpack_pack_real_uint16(x, d); +} else if(sizeof(unsigned long long) == 4) { + msgpack_pack_real_uint32(x, d); +} else { + msgpack_pack_real_uint64(x, d); +} +#endif +} + +#undef msgpack_pack_inline_func_cint +#endif + + + +/* + * Float + */ + +msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d) +{ + union { char buf[4]; uint32_t num; } f; + *((float*)&f.buf) = d; // FIXME + const unsigned char buf[5] = {0xca, STORE32_BE32(f.num)}; + msgpack_pack_append_buffer(x, buf, 5); +} + +msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d) +{ + union { char buf[8]; uint64_t num; } f; + *((double*)&f.buf) = d; // FIXME + const unsigned char buf[9] = {0xcb, STORE64_BE64(f.num)}; + msgpack_pack_append_buffer(x, buf, 9); +} + + +/* + * Nil + */ + +msgpack_pack_inline_func(_nil)(msgpack_pack_user x) +{ + static const unsigned char d = 0xc0; + msgpack_pack_append_buffer(x, &d, 1); +} + + +/* + * Boolean + */ + +msgpack_pack_inline_func(_true)(msgpack_pack_user x) +{ + static const unsigned char d = 0xc3; + msgpack_pack_append_buffer(x, &d, 1); +} + +msgpack_pack_inline_func(_false)(msgpack_pack_user x) +{ + static const unsigned char d = 0xc2; + msgpack_pack_append_buffer(x, &d, 1); +} + + +/* + * Array + */ + +msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n) +{ + if(n < 16) { + unsigned char d = 0x90 | n; + msgpack_pack_append_buffer(x, &d, 1); + } else if(n < 65536) { + uint16_t d = (uint16_t)n; + unsigned char buf[3] = {0xdc, STORE16_BE16(d)}; + msgpack_pack_append_buffer(x, buf, 3); + } else { + uint32_t d = (uint32_t)n; + unsigned char buf[5] = {0xdd, STORE32_BE32(d)}; + msgpack_pack_append_buffer(x, buf, 5); + } +} + + +/* + * Map + */ + +msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n) +{ + if(n < 16) { + unsigned char d = 0x80 | n; + msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); + } else if(n < 65536) { + uint16_t d = (uint16_t)n; + unsigned char buf[3] = {0xde, STORE16_BE16(d)}; + msgpack_pack_append_buffer(x, buf, 3); + } else { + uint32_t d = (uint32_t)n; + unsigned char buf[5] = {0xdf, STORE32_BE32(d)}; + msgpack_pack_append_buffer(x, buf, 5); + } +} + + +/* + * Raw + */ + +msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l) +{ + if(l < 32) { + unsigned char d = 0xa0 | l; + msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); + } else if(l < 65536) { + uint16_t d = (uint16_t)l; + unsigned char buf[3] = {0xda, STORE16_BE16(d)}; + msgpack_pack_append_buffer(x, buf, 3); + } else { + uint32_t d = (uint32_t)l; + unsigned char buf[5] = {0xdb, STORE32_BE32(d)}; + msgpack_pack_append_buffer(x, buf, 5); + } +} + +msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l) +{ + msgpack_pack_append_buffer(x, (const unsigned char*)b, l); +} + +#undef msgpack_pack_inline_func +#undef msgpack_pack_user +#undef msgpack_pack_append_buffer + +#undef STORE8_BE8 + +#undef STORE16_BE8 +#undef STORE16_BE16 + +#undef STORE32_BE8 +#undef STORE32_BE16 +#undef STORE32_BE32 + +#undef STORE64_BE8 +#undef STORE64_BE16 +#undef STORE64_BE32 +#undef STORE64_BE64 + +#undef msgpack_pack_real_uint8 +#undef msgpack_pack_real_uint16 +#undef msgpack_pack_real_uint32 +#undef msgpack_pack_real_uint64 +#undef msgpack_pack_real_int8 +#undef msgpack_pack_real_int16 +#undef msgpack_pack_real_int32 +#undef msgpack_pack_real_int64 + diff --git a/python/msgpack/unpack.h b/python/msgpack/unpack.h index 12702d8..cc48d9c 100644 --- a/python/msgpack/unpack.h +++ b/python/msgpack/unpack.h @@ -21,18 +21,18 @@ #include #define MSGPACK_MAX_STACK_SIZE (1024) -#include "msgpack/unpack_define.h" +#include "unpack_define.h" using namespace std; +typedef map str_cach_t; struct unpack_user { - stack array_stack; - map str_cache; + str_cach_t strcache; ~unpack_user() { - map::iterator it, itend; - itend = str_cache.end(); - for (it = str_cache.begin(); it != itend; ++it) { + str_cach_t::iterator it, itend; + itend = strcache.end(); + for (it = strcache.begin(); it != itend; ++it) { Py_DECREF(it->second); } } @@ -108,35 +108,13 @@ static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* { Py_INCREF(Py_False); *o = Py_False; return 0; } static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o) -{ - if (n > 0) { - u->array_stack.push(0); - *o = PyList_New(n); - } - else { - *o = PyList_New(0); - } - return 0; -} - -static inline int template_callback_array_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object o) -{ - unsigned int &last = u->array_stack.top(); - PyList_SET_ITEM(*c, last, o); - last++; +{ *o = PyList_New(n); return 0; } - Py_ssize_t len = PyList_GET_SIZE(*c); - if (last >= len) { - u->array_stack.pop(); - } - return 0; -} +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; } static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o) -{ - *o = PyDict_New(); - return 0; -} +{ *o = PyDict_New(); return 0; } static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v) { @@ -150,16 +128,15 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha { if (l < 16) { string s(p, l); - map::iterator it = u->str_cache.find(s); - if (it != u->str_cache.end()) { + str_cach_t ::iterator it = u->strcache.find(s); + if (it != u->strcache.end()) { *o = it->second; - Py_INCREF(*o); } else { *o = PyString_FromStringAndSize(p, l); - Py_INCREF(*o); - u->str_cache[s] = *o; + u->strcache[s] = *o; } + Py_INCREF(*o); } else { *o = PyString_FromStringAndSize(p, l); @@ -167,4 +144,4 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha return 0; } -#include "msgpack/unpack_template.h" +#include "unpack_template.h" diff --git a/python/msgpack/unpack_define.h b/python/msgpack/unpack_define.h new file mode 100644 index 0000000..63668c2 --- /dev/null +++ b/python/msgpack/unpack_define.h @@ -0,0 +1,129 @@ +/* + * MessagePack unpacking routine template + * + * Copyright (C) 2008-2009 FURUHASHI Sadayuki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MSGPACK_UNPACK_DEFINE_H__ +#define MSGPACK_UNPACK_DEFINE_H__ + +#include +#include +#include +#include +#include +#ifndef __WIN32__ +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef MSGPACK_MAX_STACK_SIZE +#define MSGPACK_MAX_STACK_SIZE 16 +#endif + + +#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define __LITTLE_ENDIAN__ +#elif __BYTE_ORDER == __BIG_ENDIAN +#define __BIG_ENDIAN__ +#endif +#endif + +#define msgpack_betoh16(x) ntohs(x) +#define msgpack_betoh32(x) ntohl(x) + +#ifdef __LITTLE_ENDIAN__ +#if defined(__bswap_64) +# define msgpack_betoh64(x) __bswap_64(x) +#elif defined(__DARWIN_OSSwapInt64) +# define msgpack_betoh64(x) __DARWIN_OSSwapInt64(x) +#else +static inline uint64_t msgpack_betoh64(uint64_t x) { + return ((x << 56) & 0xff00000000000000ULL ) | + ((x << 40) & 0x00ff000000000000ULL ) | + ((x << 24) & 0x0000ff0000000000ULL ) | + ((x << 8) & 0x000000ff00000000ULL ) | + ((x >> 8) & 0x00000000ff000000ULL ) | + ((x >> 24) & 0x0000000000ff0000ULL ) | + ((x >> 40) & 0x000000000000ff00ULL ) | + ((x >> 56) & 0x00000000000000ffULL ) ; +} +#endif +#else +#define msgpack_betoh64(x) (x) +#endif + + +typedef enum { + CS_HEADER = 0x00, // nil + + //CS_ = 0x01, + //CS_ = 0x02, // false + //CS_ = 0x03, // true + + //CS_ = 0x04, + //CS_ = 0x05, + //CS_ = 0x06, + //CS_ = 0x07, + + //CS_ = 0x08, + //CS_ = 0x09, + CS_FLOAT = 0x0a, + CS_DOUBLE = 0x0b, + CS_UINT_8 = 0x0c, + CS_UINT_16 = 0x0d, + CS_UINT_32 = 0x0e, + CS_UINT_64 = 0x0f, + CS_INT_8 = 0x10, + CS_INT_16 = 0x11, + CS_INT_32 = 0x12, + CS_INT_64 = 0x13, + + //CS_ = 0x14, + //CS_ = 0x15, + //CS_BIG_INT_16 = 0x16, + //CS_BIG_INT_32 = 0x17, + //CS_BIG_FLOAT_16 = 0x18, + //CS_BIG_FLOAT_32 = 0x19, + CS_RAW_16 = 0x1a, + CS_RAW_32 = 0x1b, + CS_ARRAY_16 = 0x1c, + CS_ARRAY_32 = 0x1d, + CS_MAP_16 = 0x1e, + CS_MAP_32 = 0x1f, + + //ACS_BIG_INT_VALUE, + //ACS_BIG_FLOAT_VALUE, + ACS_RAW_VALUE, +} msgpack_unpack_state; + + +typedef enum { + CT_ARRAY_ITEM, + CT_MAP_KEY, + CT_MAP_VALUE, +} msgpack_container_type; + + +#ifdef __cplusplus +} +#endif + +#endif /* msgpack/unpack_define.h */ + diff --git a/python/msgpack/unpack_template.h b/python/msgpack/unpack_template.h new file mode 100644 index 0000000..db33368 --- /dev/null +++ b/python/msgpack/unpack_template.h @@ -0,0 +1,363 @@ +/* + * MessagePack unpacking routine template + * + * Copyright (C) 2008-2009 FURUHASHI Sadayuki + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef msgpack_unpack_func +#error msgpack_unpack_func template is not defined +#endif + +#ifndef msgpack_unpack_callback +#error msgpack_unpack_callback template is not defined +#endif + +#ifndef msgpack_unpack_struct +#error msgpack_unpack_struct template is not defined +#endif + +#ifndef msgpack_unpack_struct_decl +#define msgpack_unpack_struct_decl(name) msgpack_unpack_struct(name) +#endif + +#ifndef msgpack_unpack_object +#error msgpack_unpack_object type is not defined +#endif + +#ifndef msgpack_unpack_user +#error msgpack_unpack_user type is not defined +#endif + + +msgpack_unpack_struct_decl(_stack) { + msgpack_unpack_object obj; + size_t curr; + size_t count; + unsigned int ct; + msgpack_unpack_object map_key; +}; + +msgpack_unpack_struct_decl(_context) { + msgpack_unpack_user user; + unsigned int cs; + unsigned int trail; + unsigned int top; + msgpack_unpack_struct(_stack) stack[MSGPACK_MAX_STACK_SIZE]; +}; + + +msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx) +{ + ctx->cs = CS_HEADER; + ctx->trail = 0; + ctx->top = 0; + ctx->stack[0].obj = msgpack_unpack_callback(_root)(&ctx->user); +} + +msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* ctx) +{ + return (ctx)->stack[0].obj; +} + + +msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off) +{ + assert(len >= *off); + + const unsigned char* p = (unsigned char*)data + *off; + const unsigned char* const pe = (unsigned char*)data + len; + const void* n = NULL; + + unsigned int trail = ctx->trail; + unsigned int cs = ctx->cs; + unsigned int top = ctx->top; + msgpack_unpack_struct(_stack)* stack = ctx->stack; + msgpack_unpack_user* user = &ctx->user; + + msgpack_unpack_object obj; + msgpack_unpack_struct(_stack)* c = NULL; + + int ret; + +#define push_simple_value(func) \ + if(msgpack_unpack_callback(func)(user, &obj) < 0) { goto _failed; } \ + goto _push +#define push_fixed_value(func, arg) \ + if(msgpack_unpack_callback(func)(user, arg, &obj) < 0) { goto _failed; } \ + goto _push +#define push_variable_value(func, base, pos, len) \ + if(msgpack_unpack_callback(func)(user, \ + (const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \ + goto _push + +#define again_fixed_trail(_cs, trail_len) \ + trail = trail_len; \ + cs = _cs; \ + goto _fixed_trail_again +#define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \ + trail = trail_len; \ + if(trail == 0) { goto ifzero; } \ + cs = _cs; \ + goto _fixed_trail_again + +#define start_container(func, count_, ct_) \ + if(msgpack_unpack_callback(func)(user, count_, &stack[top].obj) < 0) { goto _failed; } \ + if((count_) == 0) { obj = stack[top].obj; goto _push; } \ + if(top >= MSGPACK_MAX_STACK_SIZE) { goto _failed; } \ + stack[top].ct = ct_; \ + stack[top].curr = 0; \ + stack[top].count = count_; \ + /*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \ + /*printf("stack push %d\n", top);*/ \ + ++top; \ + goto _header_again + +#define NEXT_CS(p) \ + ((unsigned int)*p & 0x1f) + +#define PTR_CAST_8(ptr) (*(uint8_t*)ptr) +#define PTR_CAST_16(ptr) msgpack_betoh16(*(uint16_t*)ptr) +#define PTR_CAST_32(ptr) msgpack_betoh32(*(uint32_t*)ptr) +#define PTR_CAST_64(ptr) msgpack_betoh64(*(uint64_t*)ptr) + + if(p == pe) { goto _out; } + do { + switch(cs) { + case CS_HEADER: + switch(*p) { + case 0x00 ... 0x7f: // Positive Fixnum + push_fixed_value(_uint8, *(uint8_t*)p); + case 0xe0 ... 0xff: // Negative Fixnum + push_fixed_value(_int8, *(int8_t*)p); + case 0xc0 ... 0xdf: // Variable + switch(*p) { + case 0xc0: // nil + push_simple_value(_nil); + //case 0xc1: // string + // again_terminal_trail(NEXT_CS(p), p+1); + case 0xc2: // false + push_simple_value(_false); + case 0xc3: // true + push_simple_value(_true); + //case 0xc4: + //case 0xc5: + //case 0xc6: + //case 0xc7: + //case 0xc8: + //case 0xc9: + case 0xca: // float + case 0xcb: // double + case 0xcc: // unsigned int 8 + case 0xcd: // unsigned int 16 + case 0xce: // unsigned int 32 + case 0xcf: // unsigned int 64 + case 0xd0: // signed int 8 + case 0xd1: // signed int 16 + case 0xd2: // signed int 32 + case 0xd3: // signed int 64 + again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03)); + //case 0xd4: + //case 0xd5: + //case 0xd6: // big integer 16 + //case 0xd7: // big integer 32 + //case 0xd8: // big float 16 + //case 0xd9: // big float 32 + case 0xda: // raw 16 + case 0xdb: // raw 32 + case 0xdc: // array 16 + case 0xdd: // array 32 + case 0xde: // map 16 + case 0xdf: // map 32 + again_fixed_trail(NEXT_CS(p), 2 << (((unsigned int)*p) & 0x01)); + default: + goto _failed; + } + case 0xa0 ... 0xbf: // FixRaw + again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero); + case 0x90 ... 0x9f: // FixArray + start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM); + case 0x80 ... 0x8f: // FixMap + start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY); + + default: + goto _failed; + } + // end CS_HEADER + + + _fixed_trail_again: + ++p; + + default: + if((size_t)(pe - p) < trail) { goto _out; } + n = p; p += trail - 1; + switch(cs) { + //case CS_ + //case CS_ + case CS_FLOAT: { + union { uint32_t num; char buf[4]; } f; + f.num = PTR_CAST_32(n); // FIXME + push_fixed_value(_float, *((float*)f.buf)); } + case CS_DOUBLE: { + union { uint64_t num; char buf[8]; } f; + f.num = PTR_CAST_64(n); // FIXME + push_fixed_value(_double, *((double*)f.buf)); } + case CS_UINT_8: + push_fixed_value(_uint8, (uint8_t)PTR_CAST_8(n)); + case CS_UINT_16: + push_fixed_value(_uint16, (uint16_t)PTR_CAST_16(n)); + case CS_UINT_32: + push_fixed_value(_uint32, (uint32_t)PTR_CAST_32(n)); + case CS_UINT_64: + push_fixed_value(_uint64, (uint64_t)PTR_CAST_64(n)); + + case CS_INT_8: + push_fixed_value(_int8, (int8_t)PTR_CAST_8(n)); + case CS_INT_16: + push_fixed_value(_int16, (int16_t)PTR_CAST_16(n)); + case CS_INT_32: + push_fixed_value(_int32, (int32_t)PTR_CAST_32(n)); + case CS_INT_64: + push_fixed_value(_int64, (int64_t)PTR_CAST_64(n)); + + //case CS_ + //case CS_ + //case CS_BIG_INT_16: + // again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, (uint16_t)PTR_CAST_16(n), _big_int_zero); + //case CS_BIG_INT_32: + // again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, (uint32_t)PTR_CAST_32(n), _big_int_zero); + //case ACS_BIG_INT_VALUE: + //_big_int_zero: + // // FIXME + // push_variable_value(_big_int, data, n, trail); + + //case CS_BIG_FLOAT_16: + // again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint16_t)PTR_CAST_16(n), _big_float_zero); + //case CS_BIG_FLOAT_32: + // again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint32_t)PTR_CAST_32(n), _big_float_zero); + //case ACS_BIG_FLOAT_VALUE: + //_big_float_zero: + // // FIXME + // push_variable_value(_big_float, data, n, trail); + + case CS_RAW_16: + again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint16_t)PTR_CAST_16(n), _raw_zero); + case CS_RAW_32: + again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint32_t)PTR_CAST_32(n), _raw_zero); + case ACS_RAW_VALUE: + _raw_zero: + push_variable_value(_raw, data, n, trail); + + case CS_ARRAY_16: + start_container(_array, (uint16_t)PTR_CAST_16(n), CT_ARRAY_ITEM); + case CS_ARRAY_32: + /* FIXME security guard */ + start_container(_array, (uint32_t)PTR_CAST_32(n), CT_ARRAY_ITEM); + + case CS_MAP_16: + start_container(_map, (uint16_t)PTR_CAST_16(n), CT_MAP_KEY); + case CS_MAP_32: + /* FIXME security guard */ + start_container(_map, (uint32_t)PTR_CAST_32(n), CT_MAP_KEY); + + default: + goto _failed; + } + } + +_push: + if(top == 0) { goto _finish; } + c = &stack[top-1]; + switch(c->ct) { + case CT_ARRAY_ITEM: + if(msgpack_unpack_callback(_array_item)(user, c->curr, &c->obj, obj) < 0) { goto _failed; } + if(++c->curr == c->count) { + obj = c->obj; + --top; + /*printf("stack pop %d\n", top);*/ + goto _push; + } + goto _header_again; + case CT_MAP_KEY: + c->map_key = obj; + c->ct = CT_MAP_VALUE; + goto _header_again; + case CT_MAP_VALUE: + if(msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj) < 0) { goto _failed; } + if(--c->count == 0) { + obj = c->obj; + --top; + /*printf("stack pop %d\n", top);*/ + goto _push; + } + c->ct = CT_MAP_KEY; + goto _header_again; + + default: + goto _failed; + } + +_header_again: + cs = CS_HEADER; + ++p; + } while(p != pe); + goto _out; + + +_finish: + stack[0].obj = obj; + ++p; + ret = 1; + /*printf("-- finish --\n"); */ + goto _end; + +_failed: + /*printf("** FAILED **\n"); */ + ret = -1; + goto _end; + +_out: + ret = 0; + goto _end; + +_end: + ctx->cs = cs; + ctx->trail = trail; + ctx->top = top; + *off = p - (const unsigned char*)data; + + return ret; +} + + +#undef msgpack_unpack_func +#undef msgpack_unpack_callback +#undef msgpack_unpack_struct +#undef msgpack_unpack_object +#undef msgpack_unpack_user + +#undef push_simple_value +#undef push_fixed_value +#undef push_variable_value +#undef again_fixed_trail +#undef again_fixed_trail_if_zero +#undef start_container + +#undef NEXT_CS +#undef PTR_CAST_8 +#undef PTR_CAST_16 +#undef PTR_CAST_32 +#undef PTR_CAST_64 + -- cgit v1.2.1 From f61b282886bb9d7f7932fbcbe2affee06d150a5f Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 24 Jun 2009 01:54:47 +0900 Subject: Reduce memory footprint. --- python/msgpack/unpack.h | 6 ++---- python/msgpack/unpack_template.h | 7 +++++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'python') diff --git a/python/msgpack/unpack.h b/python/msgpack/unpack.h index cc48d9c..12afb99 100644 --- a/python/msgpack/unpack.h +++ b/python/msgpack/unpack.h @@ -23,9 +23,7 @@ #define MSGPACK_MAX_STACK_SIZE (1024) #include "unpack_define.h" -using namespace std; - -typedef map str_cach_t; +typedef std::map str_cach_t; struct unpack_user { str_cach_t strcache; @@ -127,7 +125,7 @@ static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_obje static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) { if (l < 16) { - string s(p, l); + std::string s(p, l); str_cach_t ::iterator it = u->strcache.find(s); if (it != u->strcache.end()) { *o = it->second; diff --git a/python/msgpack/unpack_template.h b/python/msgpack/unpack_template.h index db33368..c960c3a 100644 --- a/python/msgpack/unpack_template.h +++ b/python/msgpack/unpack_template.h @@ -43,10 +43,13 @@ msgpack_unpack_struct_decl(_stack) { msgpack_unpack_object obj; - size_t curr; size_t count; unsigned int ct; - msgpack_unpack_object map_key; + + union { + size_t curr; + msgpack_unpack_object map_key; + }; }; msgpack_unpack_struct_decl(_context) { -- cgit v1.2.1 From 5d4189306ae0b6ea23e9410d34434b41aee384b3 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 24 Jun 2009 04:25:05 +0900 Subject: Check return value of c-api. --- python/msgpack/unpack.h | 118 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 26 deletions(-) (limited to 'python') diff --git a/python/msgpack/unpack.h b/python/msgpack/unpack.h index 12afb99..e30b72a 100644 --- a/python/msgpack/unpack.h +++ b/python/msgpack/unpack.h @@ -59,42 +59,84 @@ static inline msgpack_unpack_object template_callback_root(unpack_user* u) return NULL; } +static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_unpack_object* o) +{ + PyObject *p = PyInt_FromLong((long)d); + if (!p) + return -1; + *o = p; + return 0; +} static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong((long)d); return 0; } +{ + return template_callback_uint16(u, d, o); +} -static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong((long)d); return 0; } static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_unpack_object* o) { + PyObject *p; if (d > LONG_MAX) { - *o = PyLong_FromUnsignedLong((unsigned long)d); + p = PyLong_FromUnsignedLong((unsigned long)d); } else { - *o = PyInt_FromLong((long)d); + p = PyInt_FromLong((long)d); } + if (!p) + return -1; + *o = p; return 0; } static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o) -{ *o = PyLong_FromUnsignedLongLong(d); return 0; } +{ + PyObject *p = PyLong_FromUnsignedLongLong(d); + if (!p) + return -1; + *o = p; + return 0; +} -static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong(d); return 0; } +static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_unpack_object* o) +{ + PyObject *p = PyInt_FromLong(d); + if (!p) + return -1; + *o = p; + return 0; +} static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong(d); return 0; } +{ + return template_callback_int32(u, d, o); +} -static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_unpack_object* o) -{ *o = PyInt_FromLong(d); return 0; } +static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_object* o) +{ + return template_callback_int32(u, d, o); +} static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o) -{ *o = PyLong_FromLongLong(d); return 0; } - -static inline int template_callback_float(unpack_user* u, float d, msgpack_unpack_object* o) -{ *o = PyFloat_FromDouble((double)d); return 0; } +{ + PyObject *p = PyLong_FromLongLong(d); + if (!p) + return -1; + *o = p; + return 0; +} static inline int template_callback_double(unpack_user* u, double d, msgpack_unpack_object* o) -{ *o = PyFloat_FromDouble(d); return 0; } +{ + PyObject *p = PyFloat_FromDouble(d); + if (!p) + return -1; + *o = p; + return 0; +} + +static inline int template_callback_float(unpack_user* u, float d, msgpack_unpack_object* o) +{ + return template_callback_double(u, d, o); +} static inline int template_callback_nil(unpack_user* u, msgpack_unpack_object* o) { Py_INCREF(Py_None); *o = Py_None; return 0; } @@ -106,40 +148,64 @@ static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* { Py_INCREF(Py_False); *o = Py_False; return 0; } static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o) -{ *o = PyList_New(n); return 0; } +{ + PyObject *p = PyList_New(n); + if (!p) + return -1; + *o = p; + return 0; +} 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; } static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o) -{ *o = PyDict_New(); return 0; } +{ + PyObject *p = PyDict_New(); + if (!p) + return -1; + *o = p; + return 0; +} static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v) { - PyDict_SetItem(*c, k, v); - Py_DECREF(k); - Py_DECREF(v); - return 0; + if (PyDict_SetItem(*c, k, v) == 0) { + Py_DECREF(k); + Py_DECREF(v); + return 0; + } + return -1; } static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) { + PyObject *py; if (l < 16) { std::string s(p, l); str_cach_t ::iterator it = u->strcache.find(s); if (it != u->strcache.end()) { *o = it->second; + Py_INCREF(*o); + return 0; } else { - *o = PyString_FromStringAndSize(p, l); + py = PyString_FromStringAndSize(p, l); + if (!py) + return -1; + *o = py; + Py_INCREF(*o); u->strcache[s] = *o; + return 0; } - Py_INCREF(*o); } else { - *o = PyString_FromStringAndSize(p, l); + py = PyString_FromStringAndSize(p, l); + if (!py) + return -1; + *o = py; + return 0; } - return 0; } #include "unpack_template.h" -- cgit v1.2.1 From 1581acfd142b68ad4ddf56fbce6c7760f1a2e920 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 24 Jun 2009 14:33:36 +0900 Subject: Make setup.py executable. --- python/setup.py | 3 +++ 1 file changed, 3 insertions(+) mode change 100644 => 100755 python/setup.py (limited to 'python') diff --git a/python/setup.py b/python/setup.py old mode 100644 new mode 100755 index 1cbc24e..e0e0ac2 --- a/python/setup.py +++ b/python/setup.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# coding: utf-8 + from distutils.core import setup, Extension from Cython.Distutils import build_ext import os -- cgit v1.2.1 From 479263989b02693f0e449ee591ca58ed84fd904b Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 24 Jun 2009 14:58:02 +0900 Subject: Stop unnecessary caching. --- python/msgpack/unpack.h | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) (limited to 'python') diff --git a/python/msgpack/unpack.h b/python/msgpack/unpack.h index e30b72a..dd23130 100644 --- a/python/msgpack/unpack.h +++ b/python/msgpack/unpack.h @@ -16,24 +16,10 @@ * limitations under the License. */ -#include -#include -#include - #define MSGPACK_MAX_STACK_SIZE (1024) #include "unpack_define.h" -typedef std::map str_cach_t; struct unpack_user { - str_cach_t strcache; - - ~unpack_user() { - str_cach_t::iterator it, itend; - itend = strcache.end(); - for (it = strcache.begin(); it != itend; ++it) { - Py_DECREF(it->second); - } - } }; @@ -181,31 +167,11 @@ static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_obje static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o) { PyObject *py; - if (l < 16) { - std::string s(p, l); - str_cach_t ::iterator it = u->strcache.find(s); - if (it != u->strcache.end()) { - *o = it->second; - Py_INCREF(*o); - return 0; - } - else { - py = PyString_FromStringAndSize(p, l); - if (!py) - return -1; - *o = py; - Py_INCREF(*o); - u->strcache[s] = *o; - return 0; - } - } - else { - py = PyString_FromStringAndSize(p, l); - if (!py) - return -1; - *o = py; - return 0; - } + py = PyString_FromStringAndSize(p, l); + if (!py) + return -1; + *o = py; + return 0; } #include "unpack_template.h" -- cgit v1.2.1 From 3c3df3133c6f6320a03ebcaef546ab9c2c53154d Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Fri, 26 Jun 2009 14:10:20 +0900 Subject: Implement streaming deserializer. --- python/msgpack/_msgpack.pyx | 162 ++++++++++++++++++++++++++++++++++++++++---- python/test_sequnpack.py | 36 ++++++++++ 2 files changed, 183 insertions(+), 15 deletions(-) create mode 100644 python/test_sequnpack.py (limited to 'python') diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index cbdcfc5..c37f8ba 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -6,13 +6,16 @@ cdef extern from "Python.h": ctypedef char* const_char_ptr "const char*" ctypedef struct PyObject cdef object PyString_FromStringAndSize(const_char_ptr b, Py_ssize_t len) + char* PyString_AsString(object o) cdef extern from "stdlib.h": - void* malloc(int) + void* malloc(size_t) + void* realloc(void*, size_t) void free(void*) cdef extern from "string.h": - int memcpy(char*dst, char*src, unsigned int size) + void* memcpy(char* dst, char* src, size_t size) + void* memmove(char* dst, char* src, size_t size) cdef extern from "pack.h": ctypedef int (*msgpack_packer_write)(void* data, const_char_ptr buf, unsigned int len) @@ -34,8 +37,6 @@ cdef extern from "pack.h": void msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) -cdef int BUFF_SIZE=2*1024 - cdef class Packer: """Packer that pack data into strm. @@ -48,10 +49,7 @@ cdef class Packer: cdef msgpack_packer pk cdef object strm - def __init__(self, strm, int size=0): - if size <= 0: - size = BUFF_SIZE - + def __init__(self, strm, int size=4*1024): self.strm = strm self.buff = malloc(size) self.allocated = size @@ -147,6 +145,8 @@ cdef class Packer: if flush: self.flush() + close = flush + cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): if packer.length + l > packer.allocated: if packer.length > 0: @@ -163,20 +163,28 @@ cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): return 0 def pack(object o, object stream): + u"""pack o and write to stream).""" packer = Packer(stream) packer.pack(o) packer.flush() -def packs(object o): +def packb(object o): + u"""pack o and return packed bytes.""" buf = StringIO() packer = Packer(buf) packer.pack(o) packer.flush() return buf.getvalue() +packs = packb + cdef extern from "unpack.h": ctypedef struct template_context: - pass + PyObject* obj + size_t count + unsigned int ct + PyObject* key + int template_execute(template_context* ctx, const_char_ptr data, size_t len, size_t* off) void template_init(template_context* ctx) @@ -188,15 +196,139 @@ def unpacks(object packed_bytes): cdef const_char_ptr p = packed_bytes cdef template_context ctx cdef size_t off = 0 + cdef int ret template_init(&ctx) - template_execute(&ctx, p, len(packed_bytes), &off) - return template_data(&ctx) + ret = template_execute(&ctx, p, len(packed_bytes), &off) + if ret == 1: + return template_data(&ctx) + else: + return None def unpack(object stream): """unpack from stream.""" packed = stream.read() return unpacks(packed) -cdef class Unpacker: - """Do nothing. This function is for symmetric to Packer""" - unpack = staticmethod(unpacks) +cdef class UnpackIterator(object): + cdef object unpacker + + def __init__(self, unpacker): + self.unpacker = unpacker + + def __next__(self): + return self.unpacker.unpack() + + def __iter__(self): + return self + +cdef class Unpacker(object): + """Unpacker(file_like=None, read_size=4096) + + Streaming unpacker. + file_like must have read(n) method. + read_size is used like file_like.read(read_size) + + If file_like is None, you can feed() bytes. feed() is useful + for unpack from non-blocking stream. + + exsample 1: + unpacker = Unpacker(afile) + for o in unpacker: + do_something(o) + + example 2: + unpacker = Unpacker() + while 1: + buf = astream.read() + unpacker.feed(buf) + for o in unpacker: + do_something(o) + """ + + cdef template_context ctx + cdef char* buf + cdef size_t buf_size, buf_head, buf_tail + cdef object file_like + cdef int read_size + cdef object waiting_bytes + + def __init__(self, file_like=None, int read_size=4096): + self.file_like = file_like + self.read_size = read_size + self.waiting_bytes = [] + self.buf = malloc(read_size) + self.buf_size = read_size + self.buf_head = 0 + self.buf_tail = 0 + template_init(&self.ctx) + + def feed(self, next_bytes): + if not isinstance(next_bytes, str): + raise ValueError, "Argument must be bytes object" + self.waiting_bytes.append(next_bytes) + + cdef append_buffer(self): + cdef char* buf = self.buf + cdef Py_ssize_t tail = self.buf_tail + cdef Py_ssize_t l + + for b in self.waiting_bytes: + l = len(b) + memcpy(buf + tail, PyString_AsString(b), l) + tail += l + self.buf_tail = tail + del self.waiting_bytes[:] + + # prepare self.buf + cdef fill_buffer(self): + cdef Py_ssize_t add_size + + if self.file_like is not None: + self.waiting_bytes.append(self.file_like.read(self.read_size)) + + if not self.waiting_bytes: + return + + add_size = 0 + for b in self.waiting_bytes: + add_size += len(b) + + cdef char* buf = self.buf + cdef size_t head = self.buf_head + cdef size_t tail = self.buf_tail + cdef size_t size = self.buf_size + + if self.buf_tail + add_size <= self.buf_size: + # do nothing. + pass + if self.buf_tail - self.buf_head + add_size < self.buf_size: + # move to front. + memmove(buf, buf + head, tail - head) + tail -= head + head = 0 + else: + # expand buffer + size = tail + add_size + buf = realloc(buf, size) + + self.buf = buf + self.buf_head = head + self.buf_tail = tail + self.buf_size = size + + self.append_buffer() + + cpdef unpack(self): + """unpack one object""" + cdef int ret + self.fill_buffer() + ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head) + if ret == 1: + return template_data(&self.ctx) + elif ret == 0: + raise StopIteration, "No more unpack data." + else: + raise ValueError, "Unpack failed." + + def __iter__(self): + return UnpackIterator(self) diff --git a/python/test_sequnpack.py b/python/test_sequnpack.py new file mode 100644 index 0000000..789ccd2 --- /dev/null +++ b/python/test_sequnpack.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# coding: utf-8 + +from __future__ import unicode_literals, print_function + +from msgpack import Unpacker + +def test_foobar(): + unpacker = Unpacker(read_size=3) + unpacker.feed(b'foobar') + assert unpacker.unpack() == ord('f') + assert unpacker.unpack() == ord('o') + assert unpacker.unpack() == ord('o') + assert unpacker.unpack() == ord('b') + assert unpacker.unpack() == ord('a') + assert unpacker.unpack() == ord('r') + try: + o = unpacker.unpack() + print("Oops!", o) + assert 0 + except StopIteration: + assert 1 + else: + assert 0 + unpacker.feed(b'foo') + unpacker.feed(b'bar') + + k = 0 + for o, e in zip(unpacker, b'foobarbaz'): + assert o == ord(e) + k += 1 + assert k == len(b'foobar') + +if __name__ == '__main__': + test_foobar() + -- cgit v1.2.1 From a345131aaa4a87c2e917913eae053a8382fd4e67 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Sat, 27 Jun 2009 12:03:00 +0900 Subject: Add: README --- python/README | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 python/README (limited to 'python') diff --git a/python/README b/python/README new file mode 100644 index 0000000..12a27b2 --- /dev/null +++ b/python/README @@ -0,0 +1,31 @@ +=========================== +MessagePack Python Binding +=========================== + +:author: Naoki INADA +:version: 0.0.1 +:date: 2009-06-27 + +HOW TO USE +----------- +You can read document in docstring after `import msgpack` + + +INSTALL +--------- +Cython_ is required to build the binding. + +.. _Cython: http://www.cython.org/ + +Posix +'''''' +You can install msgpack in common way. + + $ python setup.py install + +Windows +'''''''' +MessagePack requires gcc currently. So you need to prepare +MinGW GCC. + + $ python setup.py install -c mingw -- cgit v1.2.1 From fa2efcdb5ba8a5cca141f7882271abb8ea697caa Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Sat, 27 Jun 2009 12:04:11 +0900 Subject: Rename test files. --- python/test/test_format.py | 64 +++++++++++++++++++++++++++++++++++++++++++ python/test/test_sequnpack.py | 36 ++++++++++++++++++++++++ python/test_sequnpack.py | 36 ------------------------ python/testformat.py | 64 ------------------------------------------- 4 files changed, 100 insertions(+), 100 deletions(-) create mode 100644 python/test/test_format.py create mode 100644 python/test/test_sequnpack.py delete mode 100644 python/test_sequnpack.py delete mode 100644 python/testformat.py (limited to 'python') diff --git a/python/test/test_format.py b/python/test/test_format.py new file mode 100644 index 0000000..a00123c --- /dev/null +++ b/python/test/test_format.py @@ -0,0 +1,64 @@ +from unittest import TestCase, main +from msgpack import packs, unpacks + +class TestFormat(TestCase): + def __check(self, obj, expected_packed): + packed = packs(obj) + self.assertEqual(packed, expected_packed) + unpacked = unpacks(packed) + self.assertEqual(unpacked, obj) + + def testSimpleValues(self): + self.__check(None, '\xc0') + self.__check(True, '\xc3') + self.__check(False, '\xc2') + self.__check( + [None, False, True], + '\x93\xc0\xc2\xc3' + ) + + def testFixnum(self): + self.__check( + [[0,64,127], [-32,-16,-1]], + "\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff" + ) + + def testFixArray(self): + self.__check( + [[],[[None]]], + "\x92\x90\x91\x91\xc0" + ) + + def testFixRaw(self): + self.__check( + ["", "a", "bc", "def"], + "\x94\xa0\xa1a\xa2bc\xa3def" + ) + pass + + def testFixMap(self): + self.__check( + {False: {None: None}, True:{None:{}}}, + "\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80" + ) + pass + + +class TestUnpack(TestCase): + def __check(self, packed, obj): + self.assertEqual(unpacks(packed), obj) + + def testuint(self): + self.__check( + "\x99\xcc\x00\xcc\x80\xcc\xff\xcd\x00\x00\xcd\x80\x00" + "\xcd\xff\xff\xce\x00\x00\x00\x00\xce\x80\x00\x00\x00" + "\xce\xff\xff\xff\xff", + [0, 128, 255, 0, 32768, 65535, 0, + 2147483648, 4294967295], + ) + + + + +if __name__ == '__main__': + main() diff --git a/python/test/test_sequnpack.py b/python/test/test_sequnpack.py new file mode 100644 index 0000000..789ccd2 --- /dev/null +++ b/python/test/test_sequnpack.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# coding: utf-8 + +from __future__ import unicode_literals, print_function + +from msgpack import Unpacker + +def test_foobar(): + unpacker = Unpacker(read_size=3) + unpacker.feed(b'foobar') + assert unpacker.unpack() == ord('f') + assert unpacker.unpack() == ord('o') + assert unpacker.unpack() == ord('o') + assert unpacker.unpack() == ord('b') + assert unpacker.unpack() == ord('a') + assert unpacker.unpack() == ord('r') + try: + o = unpacker.unpack() + print("Oops!", o) + assert 0 + except StopIteration: + assert 1 + else: + assert 0 + unpacker.feed(b'foo') + unpacker.feed(b'bar') + + k = 0 + for o, e in zip(unpacker, b'foobarbaz'): + assert o == ord(e) + k += 1 + assert k == len(b'foobar') + +if __name__ == '__main__': + test_foobar() + diff --git a/python/test_sequnpack.py b/python/test_sequnpack.py deleted file mode 100644 index 789ccd2..0000000 --- a/python/test_sequnpack.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -from __future__ import unicode_literals, print_function - -from msgpack import Unpacker - -def test_foobar(): - unpacker = Unpacker(read_size=3) - unpacker.feed(b'foobar') - assert unpacker.unpack() == ord('f') - assert unpacker.unpack() == ord('o') - assert unpacker.unpack() == ord('o') - assert unpacker.unpack() == ord('b') - assert unpacker.unpack() == ord('a') - assert unpacker.unpack() == ord('r') - try: - o = unpacker.unpack() - print("Oops!", o) - assert 0 - except StopIteration: - assert 1 - else: - assert 0 - unpacker.feed(b'foo') - unpacker.feed(b'bar') - - k = 0 - for o, e in zip(unpacker, b'foobarbaz'): - assert o == ord(e) - k += 1 - assert k == len(b'foobar') - -if __name__ == '__main__': - test_foobar() - diff --git a/python/testformat.py b/python/testformat.py deleted file mode 100644 index a00123c..0000000 --- a/python/testformat.py +++ /dev/null @@ -1,64 +0,0 @@ -from unittest import TestCase, main -from msgpack import packs, unpacks - -class TestFormat(TestCase): - def __check(self, obj, expected_packed): - packed = packs(obj) - self.assertEqual(packed, expected_packed) - unpacked = unpacks(packed) - self.assertEqual(unpacked, obj) - - def testSimpleValues(self): - self.__check(None, '\xc0') - self.__check(True, '\xc3') - self.__check(False, '\xc2') - self.__check( - [None, False, True], - '\x93\xc0\xc2\xc3' - ) - - def testFixnum(self): - self.__check( - [[0,64,127], [-32,-16,-1]], - "\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff" - ) - - def testFixArray(self): - self.__check( - [[],[[None]]], - "\x92\x90\x91\x91\xc0" - ) - - def testFixRaw(self): - self.__check( - ["", "a", "bc", "def"], - "\x94\xa0\xa1a\xa2bc\xa3def" - ) - pass - - def testFixMap(self): - self.__check( - {False: {None: None}, True:{None:{}}}, - "\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80" - ) - pass - - -class TestUnpack(TestCase): - def __check(self, packed, obj): - self.assertEqual(unpacks(packed), obj) - - def testuint(self): - self.__check( - "\x99\xcc\x00\xcc\x80\xcc\xff\xcd\x00\x00\xcd\x80\x00" - "\xcd\xff\xff\xce\x00\x00\x00\x00\xce\x80\x00\x00\x00" - "\xce\xff\xff\xff\xff", - [0, 128, 255, 0, 32768, 65535, 0, - 2147483648, 4294967295], - ) - - - - -if __name__ == '__main__': - main() -- cgit v1.2.1 From 1b07b61c048f749c7a5e505617b0e59974f81077 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Sun, 28 Jun 2009 21:24:02 +0900 Subject: Ues more suitable type when packing. --- python/msgpack/_msgpack.pyx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'python') diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index c37f8ba..cde5313 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -7,6 +7,8 @@ cdef extern from "Python.h": ctypedef struct PyObject cdef object PyString_FromStringAndSize(const_char_ptr b, Py_ssize_t len) char* PyString_AsString(object o) + int PyMapping_Check(object o) + int PySequence_Check(object o) cdef extern from "stdlib.h": void* malloc(size_t) @@ -37,7 +39,7 @@ cdef extern from "pack.h": void msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) -cdef class Packer: +cdef class Packer(object): """Packer that pack data into strm. strm must have `write(bytes)` method. @@ -99,7 +101,8 @@ cdef class Packer: msgpack_pack_map(&self.pk, len) cdef __pack(self, object o): - cdef long long intval + cdef long long llval + cdef long longval cdef double fval cdef char* rawval @@ -110,11 +113,11 @@ cdef class Packer: elif o is False: msgpack_pack_false(&self.pk) elif isinstance(o, long): - intval = o - msgpack_pack_long_long(&self.pk, intval) + llval = o + msgpack_pack_long_long(&self.pk, llval) elif isinstance(o, int): - intval = o - msgpack_pack_long_long(&self.pk, intval) + longval = o + msgpack_pack_long_long(&self.pk, longval) elif isinstance(o, float): fval = o msgpack_pack_double(&self.pk, fval) @@ -127,12 +130,12 @@ cdef class Packer: rawval = o msgpack_pack_raw(&self.pk, len(o)) msgpack_pack_raw_body(&self.pk, rawval, len(o)) - elif isinstance(o, dict): + elif PyMapping_Check(o): msgpack_pack_map(&self.pk, len(o)) for k,v in o.iteritems(): self.pack(k) self.pack(v) - elif isinstance(o, tuple) or isinstance(o, list): + elif PySequence_Check(o): msgpack_pack_array(&self.pk, len(o)) for v in o: self.pack(v) -- cgit v1.2.1 From 3e396ef146940ada28fc8b154189ae9bb206babc Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Sun, 28 Jun 2009 21:24:16 +0900 Subject: Don't use C++. --- python/msgpack/unpack.h | 4 ++-- python/setup.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/msgpack/unpack.h b/python/msgpack/unpack.h index dd23130..40058d0 100644 --- a/python/msgpack/unpack.h +++ b/python/msgpack/unpack.h @@ -19,8 +19,8 @@ #define MSGPACK_MAX_STACK_SIZE (1024) #include "unpack_define.h" -struct unpack_user { -}; +typedef struct unpack_user { +} unpack_user; #define msgpack_unpack_struct(name) \ diff --git a/python/setup.py b/python/setup.py index e0e0ac2..faadb33 100755 --- a/python/setup.py +++ b/python/setup.py @@ -10,7 +10,6 @@ version = '0.0.1dev' PACKAGE_ROOT = os.getcwdu() INCLUDE_PATH = os.path.join(PACKAGE_ROOT, 'include') msgpack_mod = Extension('msgpack._msgpack', - language="c++", sources=['msgpack/_msgpack.pyx'], include_dirs=[INCLUDE_PATH]) -- cgit v1.2.1 From 0b33a634a668a478ee86f2c3d9d29c6be85afa6b Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 29 Jun 2009 08:23:27 +0900 Subject: Update test_format. --- python/README | 7 +++ python/test/test_format.py | 110 ++++++++++++++++++++++++--------------------- 2 files changed, 67 insertions(+), 50 deletions(-) (limited to 'python') diff --git a/python/README b/python/README index 12a27b2..243def2 100644 --- a/python/README +++ b/python/README @@ -29,3 +29,10 @@ MessagePack requires gcc currently. So you need to prepare MinGW GCC. $ python setup.py install -c mingw + +TEST +---- +MessagePack uses nosetest for testing. +Run test with following command: + + $ nosetests test diff --git a/python/test/test_format.py b/python/test/test_format.py index a00123c..009a764 100644 --- a/python/test/test_format.py +++ b/python/test/test_format.py @@ -1,64 +1,74 @@ -from unittest import TestCase, main -from msgpack import packs, unpacks +#!/usr/bin/env python +# coding: utf-8 -class TestFormat(TestCase): - def __check(self, obj, expected_packed): - packed = packs(obj) - self.assertEqual(packed, expected_packed) - unpacked = unpacks(packed) - self.assertEqual(unpacked, obj) +from nose import main +from nose.tools import * +from msgpack import unpacks - def testSimpleValues(self): - self.__check(None, '\xc0') - self.__check(True, '\xc3') - self.__check(False, '\xc2') - self.__check( - [None, False, True], - '\x93\xc0\xc2\xc3' - ) +def check(src, should): + assert_equal(unpacks(src), should) - def testFixnum(self): - self.__check( - [[0,64,127], [-32,-16,-1]], - "\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff" - ) - - def testFixArray(self): - self.__check( - [[],[[None]]], - "\x92\x90\x91\x91\xc0" - ) +def testSimpleValue(): + check("\x93\xc0\xc2\xc3", + [None, False, True]) - def testFixRaw(self): - self.__check( - ["", "a", "bc", "def"], - "\x94\xa0\xa1a\xa2bc\xa3def" - ) - pass +def testFixnum(): + check("\x92\x93\x00\x40\x7f\x93\xe0\xf0\xff", + [[0,64,127], [-32,-16,-1]] + ) - def testFixMap(self): - self.__check( - {False: {None: None}, True:{None:{}}}, - "\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80" - ) - pass +def testFixArray(): + check("\x92\x90\x91\x91\xc0", + [[],[[None]]], + ) +def testFixRaw(): + check("\x94\xa0\xa1a\xa2bc\xa3def", + ["", "a", "bc", "def"], + ) -class TestUnpack(TestCase): - def __check(self, packed, obj): - self.assertEqual(unpacks(packed), obj) +def testFixMap(): + check( + "\x82\xc2\x81\xc0\xc0\xc3\x81\xc0\x80", + {False: {None: None}, True:{None:{}}}, + ) - def testuint(self): - self.__check( - "\x99\xcc\x00\xcc\x80\xcc\xff\xcd\x00\x00\xcd\x80\x00" - "\xcd\xff\xff\xce\x00\x00\x00\x00\xce\x80\x00\x00\x00" - "\xce\xff\xff\xff\xff", - [0, 128, 255, 0, 32768, 65535, 0, - 2147483648, 4294967295], - ) +def testUnsignedInt(): + check( + "\x99\xcc\x00\xcc\x80\xcc\xff\xcd\x00\x00\xcd\x80\x00" + "\xcd\xff\xff\xce\x00\x00\x00\x00\xce\x80\x00\x00\x00" + "\xce\xff\xff\xff\xff", + [0, 128, 255, 0, 32768, 65535, 0, 2147483648, 4294967295], + ) +def testSignedInt(): + check("\x99\xd0\x00\xd0\x80\xd0\xff\xd1\x00\x00\xd1\x80\x00" + "\xd1\xff\xff\xd2\x00\x00\x00\x00\xd2\x80\x00\x00\x00" + "\xd2\xff\xff\xff\xff", + [0, -128, -1, 0, -32768, -1, 0, -2147483648, -1]) +def testRaw(): + check("\x96\xda\x00\x00\xda\x00\x01a\xda\x00\x02ab\xdb\x00\x00" + "\x00\x00\xdb\x00\x00\x00\x01a\xdb\x00\x00\x00\x02ab", + ["", "a", "ab", "", "a", "ab"]) +def testArray(): + check("\x96\xdc\x00\x00\xdc\x00\x01\xc0\xdc\x00\x02\xc2\xc3\xdd\x00" + "\x00\x00\x00\xdd\x00\x00\x00\x01\xc0\xdd\x00\x00\x00\x02" + "\xc2\xc3", + [[], [None], [False,True], [], [None], [False,True]]) + +def testMap(): + check( + "\x96" + "\xde\x00\x00" + "\xde\x00\x01\xc0\xc2" + "\xde\x00\x02\xc0\xc2\xc3\xc2" + "\xdf\x00\x00\x00\x00" + "\xdf\x00\x00\x00\x01\xc0\xc2" + "\xdf\x00\x00\x00\x02\xc0\xc2\xc3\xc2", + [{}, {None: False}, {True: False, None: False}, {}, + {None: False}, {True: False, None: False}]) if __name__ == '__main__': main() -- cgit v1.2.1 From 257270c1ebc5bb6ac6c60e47130e2a577ffb6714 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 29 Jun 2009 08:23:49 +0900 Subject: Refactor packing code. --- python/msgpack/_msgpack.pyx | 14 +++++++------- python/msgpack/pack.h | 17 ----------------- 2 files changed, 7 insertions(+), 24 deletions(-) (limited to 'python') diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index cde5313..279fdf5 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -31,6 +31,7 @@ cdef extern from "pack.h": void msgpack_pack_nil(msgpack_packer* pk) void msgpack_pack_true(msgpack_packer* pk) void msgpack_pack_false(msgpack_packer* pk) + void msgpack_pack_long(msgpack_packer* pk, long d) void msgpack_pack_long_long(msgpack_packer* pk, long long d) void msgpack_pack_double(msgpack_packer* pk, double d) void msgpack_pack_array(msgpack_packer* pk, size_t l) @@ -60,7 +61,7 @@ cdef class Packer(object): msgpack_packer_init(&self.pk, self, _packer_write) def __del__(self): - free(self.buff); + free(self.buff) def flush(self): """Flash local buffer and output stream if it has 'flush()' method.""" @@ -117,7 +118,7 @@ cdef class Packer(object): msgpack_pack_long_long(&self.pk, llval) elif isinstance(o, int): longval = o - msgpack_pack_long_long(&self.pk, longval) + msgpack_pack_long(&self.pk, longval) elif isinstance(o, float): fval = o msgpack_pack_double(&self.pk, fval) @@ -133,12 +134,12 @@ cdef class Packer(object): elif PyMapping_Check(o): msgpack_pack_map(&self.pk, len(o)) for k,v in o.iteritems(): - self.pack(k) - self.pack(v) + self.__pack(k) + self.__pack(v) elif PySequence_Check(o): msgpack_pack_array(&self.pk, len(o)) for v in o: - self.pack(v) + self.__pack(v) else: # TODO: Serialize with defalt() like simplejson. raise TypeError, "can't serialize %r" % (o,) @@ -154,7 +155,7 @@ cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): if packer.length + l > packer.allocated: if packer.length > 0: packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - if l > 64: + if l > packer.allocated/4: packer.strm.write(PyString_FromStringAndSize(b, l)) packer.length = 0 else: @@ -176,7 +177,6 @@ def packb(object o): buf = StringIO() packer = Packer(buf) packer.pack(o) - packer.flush() return buf.getvalue() packs = packb diff --git a/python/msgpack/pack.h b/python/msgpack/pack.h index 9bd6b68..cdac819 100644 --- a/python/msgpack/pack.h +++ b/python/msgpack/pack.h @@ -34,9 +34,6 @@ typedef struct msgpack_packer { static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback); -static inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback); -static inline void msgpack_packer_free(msgpack_packer* pk); - static inline int msgpack_pack_short(msgpack_packer* pk, short d); static inline int msgpack_pack_int(msgpack_packer* pk, int d); static inline int msgpack_pack_long(msgpack_packer* pk, long d); @@ -90,20 +87,6 @@ static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_p pk->callback = callback; } -static inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback) -{ - msgpack_packer* pk = (msgpack_packer*)calloc(1, sizeof(msgpack_packer)); - if(!pk) { return NULL; } - msgpack_packer_init(pk, data, callback); - return pk; -} - -static inline void msgpack_packer_free(msgpack_packer* pk) -{ - free(pk); -} - - #ifdef __cplusplus } #endif -- cgit v1.2.1 From fe2421275d1e0809a9658dbaa5b31fc535bcf32a Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 29 Jun 2009 09:31:43 +0900 Subject: Add some test cases. --- python/test/test_case.py | 101 +++++++++++++++++++++++++++++++++++++++++++++++ python/test/test_pack.py | 28 +++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 python/test/test_case.py create mode 100644 python/test/test_pack.py (limited to 'python') diff --git a/python/test/test_case.py b/python/test/test_case.py new file mode 100644 index 0000000..3fafd8b --- /dev/null +++ b/python/test/test_case.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python +# coding: utf-8 + +from nose import main +from nose.tools import * +from msgpack import packs, unpacks + +def check(length, obj): + v = packs(obj) + assert_equal(len(v), length) + assert_equal(unpacks(v), obj) + +def test_1(): + for o in [None, True, False, 0, 1, (1 << 6), (1 << 7) - 1, -1, + -((1<<5)-1), -(1<<5)]: + check(1, o) + +def test_2(): + for o in [1 << 7, (1 << 8) - 1, + -((1<<5)+1), -(1<<7) + ]: + check(2, o) + +def test_3(): + for o in [1 << 8, (1 << 16) - 1, + -((1<<7)+1), -(1<<15)]: + check(3, o) + +def test_5(): + for o in [1 << 16, (1 << 32) - 1, + -((1<<15)+1), -(1<<31)]: + check(5, o) + +def test_9(): + for o in [1 << 32, (1 << 64) - 1, + -((1<<31)+1), -(1<<63), + 1.0, 0.1, -0.1, -1.0]: + check(9, o) + + +def check_raw(overhead, num): + check(num + overhead, " " * num) + +def test_fixraw(): + check_raw(1, 0) + check_raw(1, (1<<5) - 1) + +def test_raw16(): + check_raw(3, 1<<5) + check_raw(3, (1<<16) - 1) + +def test_raw32(): + check_raw(5, 1<<16) + + +def check_array(overhead, num): + check(num + overhead, [None] * num) + +def test_fixarray(): + check_array(1, 0) + check_array(1, (1 << 4) - 1) + +def test_array16(): + check_array(3, 1 << 4) + check_array(3, (1<<16)-1) + +def test_array32(): + check_array(5, (1<<16)) + + +def match(obj, buf): + assert_equal(packs(obj), buf) + assert_equal(unpacks(buf), obj) + +def test_match(): + cases = [ + (None, '\xc0'), + (False, '\xc2'), + (True, '\xc3'), + (0, '\x00'), + (127, '\x7f'), + (128, '\xcc\x80'), + (256, '\xcd\x01\x00'), + (-1, '\xff'), + (-33, '\xd0\xdf'), + (-129, '\xd1\xff\x7f'), + ({1:1}, '\x81\x01\x01'), + (1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"), + ([], '\x90'), + (range(15),"\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"), + (range(16),"\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"), + ({}, '\x80'), + (dict([(x,x) for x in range(15)]), "\x8f\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x04\x04\x0a\x0a"), + (dict([(x,x) for x in range(16)]), "\xde\x00\x10\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x0f\x0f\x04\x04\x0a\x0a"), + ] + + for v, p in cases: + match(v, p) + +if __name__ == '__main__': + main() diff --git a/python/test/test_pack.py b/python/test/test_pack.py new file mode 100644 index 0000000..86badb5 --- /dev/null +++ b/python/test/test_pack.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# coding: utf-8 + +from nose import main +from nose.tools import * + +from msgpack import packs, unpacks + +def check(data): + re = unpacks(packs(data)) + assert_equal(re, data) + +def testPack(): + test_data = [ + 0, 1, 127, 128, 255, 256, 65535, 65536, + -1, -32, -33, -128, -129, -32768, -32769, + 1.0, + "", "a", "a"*31, "a"*32, + None, True, False, + [], [[]], [[], None], + {None: 0}, + (1<<23), + ] + for td in test_data: + check(td) + +if __name__ == '__main__': + main() -- cgit v1.2.1 From 9015bd4ecfe7c30aef47d7c3c6fbc6fd4219eae0 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 29 Jun 2009 10:09:04 +0900 Subject: Fix error on packing unsigned long long. --- python/msgpack/_msgpack.pyx | 34 +++++++++++++++++++++------------- python/test/test_case.py | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'python') diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index 279fdf5..e1c497b 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -9,6 +9,8 @@ cdef extern from "Python.h": char* PyString_AsString(object o) int PyMapping_Check(object o) int PySequence_Check(object o) + long long PyLong_AsLongLong(object o) + unsigned long long PyLong_AsUnsignedLongLong(object o) cdef extern from "stdlib.h": void* malloc(size_t) @@ -27,17 +29,18 @@ cdef extern from "pack.h": msgpack_packer_write callback void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) - void msgpack_pack_int(msgpack_packer* pk, int d) - void msgpack_pack_nil(msgpack_packer* pk) - void msgpack_pack_true(msgpack_packer* pk) - void msgpack_pack_false(msgpack_packer* pk) - void msgpack_pack_long(msgpack_packer* pk, long d) - void msgpack_pack_long_long(msgpack_packer* pk, long long d) - void msgpack_pack_double(msgpack_packer* pk, double d) - void msgpack_pack_array(msgpack_packer* pk, size_t l) - void msgpack_pack_map(msgpack_packer* pk, size_t l) - void msgpack_pack_raw(msgpack_packer* pk, size_t l) - void msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) + int msgpack_pack_int(msgpack_packer* pk, int d) + int msgpack_pack_nil(msgpack_packer* pk) + int msgpack_pack_true(msgpack_packer* pk) + int msgpack_pack_false(msgpack_packer* pk) + int msgpack_pack_long(msgpack_packer* pk, long d) + int msgpack_pack_long_long(msgpack_packer* pk, long long d) + int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d) + int msgpack_pack_double(msgpack_packer* pk, double d) + int msgpack_pack_array(msgpack_packer* pk, size_t l) + int msgpack_pack_map(msgpack_packer* pk, size_t l) + int msgpack_pack_raw(msgpack_packer* pk, size_t l) + int msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) cdef class Packer(object): @@ -103,6 +106,7 @@ cdef class Packer(object): cdef __pack(self, object o): cdef long long llval + cdef unsigned long long ullval cdef long longval cdef double fval cdef char* rawval @@ -114,8 +118,12 @@ cdef class Packer(object): elif o is False: msgpack_pack_false(&self.pk) elif isinstance(o, long): - llval = o - msgpack_pack_long_long(&self.pk, llval) + if o > 0: + ullval = PyLong_AsUnsignedLongLong(o) + msgpack_pack_unsigned_long_long(&self.pk, ullval) + else: + llval = PyLong_AsLongLong(o) + msgpack_pack_long_long(&self.pk, llval) elif isinstance(o, int): longval = o msgpack_pack_long(&self.pk, longval) diff --git a/python/test/test_case.py b/python/test/test_case.py index 3fafd8b..997027a 100644 --- a/python/test/test_case.py +++ b/python/test/test_case.py @@ -7,7 +7,7 @@ from msgpack import packs, unpacks def check(length, obj): v = packs(obj) - assert_equal(len(v), length) + assert_equal(len(v), length, "%r length should be %r but get %r" % (obj, length, len(v))) assert_equal(unpacks(v), obj) def test_1(): -- cgit v1.2.1 From b5010c71a9810515db1aa82d2e7eebf2ee4f474f Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 29 Jun 2009 11:21:28 +0900 Subject: Fix tests. --- python/Makefile | 7 +++++++ python/test/test_case.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 python/Makefile (limited to 'python') diff --git a/python/Makefile b/python/Makefile new file mode 100644 index 0000000..5f16fae --- /dev/null +++ b/python/Makefile @@ -0,0 +1,7 @@ +all: + python setup.py build + python setup.py sdist + +.PHONY: test +test: + nosetests test diff --git a/python/test/test_case.py b/python/test/test_case.py index 997027a..d754fb0 100644 --- a/python/test/test_case.py +++ b/python/test/test_case.py @@ -90,8 +90,8 @@ def test_match(): (range(15),"\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"), (range(16),"\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"), ({}, '\x80'), - (dict([(x,x) for x in range(15)]), "\x8f\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x04\x04\x0a\x0a"), - (dict([(x,x) for x in range(16)]), "\xde\x00\x10\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x0f\x0f\x04\x04\x0a\x0a"), + (dict([(x,x) for x in range(15)]), '\x8f\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e'), + (dict([(x,x) for x in range(16)]), '\xde\x00\x10\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\x05\x05\x06\x06\x07\x07\x08\x08\t\t\n\n\x0b\x0b\x0c\x0c\r\r\x0e\x0e\x0f\x0f'), ] for v, p in cases: -- cgit v1.2.1 From d4317fdc853c7dbe3bc57718dc009cb8b0a2b351 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Tue, 30 Jun 2009 23:03:33 +0900 Subject: Some optimization on packing. --- python/Makefile | 1 + python/msgpack/_msgpack.pyx | 69 +++++++++++++++------------------------------ python/msgpack/pack.h | 29 ++++++++++--------- 3 files changed, 40 insertions(+), 59 deletions(-) (limited to 'python') diff --git a/python/Makefile b/python/Makefile index 5f16fae..d90789a 100644 --- a/python/Makefile +++ b/python/Makefile @@ -1,4 +1,5 @@ all: + python setup.py build_ext -i -f python setup.py build python setup.py sdist diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index e1c497b..26222aa 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -1,16 +1,23 @@ # coding: utf-8 -from cStringIO import StringIO +import cStringIO cdef extern from "Python.h": ctypedef char* const_char_ptr "const char*" ctypedef struct PyObject cdef object PyString_FromStringAndSize(const_char_ptr b, Py_ssize_t len) + PyObject* Py_True + PyObject* Py_False char* PyString_AsString(object o) int PyMapping_Check(object o) int PySequence_Check(object o) long long PyLong_AsLongLong(object o) unsigned long long PyLong_AsUnsignedLongLong(object o) + int PyLong_Check(object o) + int PyInt_Check(object o) + int PyFloat_Check(object o) + int PyString_Check(object o) + int PyUnicode_Check(object o) cdef extern from "stdlib.h": void* malloc(size_t) @@ -22,13 +29,9 @@ cdef extern from "string.h": void* memmove(char* dst, char* src, size_t size) cdef extern from "pack.h": - ctypedef int (*msgpack_packer_write)(void* data, const_char_ptr buf, unsigned int len) - struct msgpack_packer: - void *data - msgpack_packer_write callback + PyObject* writer - void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) int msgpack_pack_int(msgpack_packer* pk, int d) int msgpack_pack_nil(msgpack_packer* pk) int msgpack_pack_true(msgpack_packer* pk) @@ -49,28 +52,17 @@ cdef class Packer(object): strm must have `write(bytes)` method. size specifies local buffer size. """ - cdef char* buff - cdef unsigned int length - cdef unsigned int allocated cdef msgpack_packer pk cdef object strm + cdef object writer - def __init__(self, strm, int size=4*1024): - self.strm = strm - self.buff = malloc(size) - self.allocated = size - self.length = 0 - - msgpack_packer_init(&self.pk, self, _packer_write) - - def __del__(self): - free(self.buff) + def __init__(self, strm_, int size=4*1024): + self.strm = strm_ + self.writer = strm_.write + self.pk.writer = self.writer def flush(self): """Flash local buffer and output stream if it has 'flush()' method.""" - if self.length > 0: - self.strm.write(PyString_FromStringAndSize(self.buff, self.length)) - self.length = 0 if hasattr(self.strm, 'flush'): self.strm.flush() @@ -113,28 +105,28 @@ cdef class Packer(object): if o is None: msgpack_pack_nil(&self.pk) - elif o is True: + elif o == Py_True: msgpack_pack_true(&self.pk) - elif o is False: + elif o == Py_False: msgpack_pack_false(&self.pk) - elif isinstance(o, long): + elif PyLong_Check(o): if o > 0: ullval = PyLong_AsUnsignedLongLong(o) msgpack_pack_unsigned_long_long(&self.pk, ullval) else: llval = PyLong_AsLongLong(o) msgpack_pack_long_long(&self.pk, llval) - elif isinstance(o, int): + elif PyInt_Check(o): longval = o msgpack_pack_long(&self.pk, longval) - elif isinstance(o, float): + elif PyFloat_Check(o): fval = o msgpack_pack_double(&self.pk, fval) - elif isinstance(o, str): + elif PyString_Check(o): rawval = o msgpack_pack_raw(&self.pk, len(o)) msgpack_pack_raw_body(&self.pk, rawval, len(o)) - elif isinstance(o, unicode): + elif PyUnicode_Check(o): o = o.encode('utf-8') rawval = o msgpack_pack_raw(&self.pk, len(o)) @@ -152,28 +144,13 @@ cdef class Packer(object): # TODO: Serialize with defalt() like simplejson. raise TypeError, "can't serialize %r" % (o,) - def pack(self, obj, flush=True): + def pack(self, object obj, flush=True): self.__pack(obj) if flush: self.flush() close = flush -cdef int _packer_write(Packer packer, const_char_ptr b, unsigned int l): - if packer.length + l > packer.allocated: - if packer.length > 0: - packer.strm.write(PyString_FromStringAndSize(packer.buff, packer.length)) - if l > packer.allocated/4: - packer.strm.write(PyString_FromStringAndSize(b, l)) - packer.length = 0 - else: - memcpy(packer.buff, b, l) - packer.length = l - else: - memcpy(packer.buff + packer.length, b, l) - packer.length += l - return 0 - def pack(object o, object stream): u"""pack o and write to stream).""" packer = Packer(stream) @@ -182,7 +159,7 @@ def pack(object o, object stream): def packb(object o): u"""pack o and return packed bytes.""" - buf = StringIO() + buf = cStringIO.StringIO() packer = Packer(buf) packer.pack(o) return buf.getvalue() diff --git a/python/msgpack/pack.h b/python/msgpack/pack.h index cdac819..ea97601 100644 --- a/python/msgpack/pack.h +++ b/python/msgpack/pack.h @@ -24,15 +24,11 @@ extern "C" { #endif - -typedef int (*msgpack_packer_write)(void* data, const char* buf, unsigned int len); - typedef struct msgpack_packer { - void* data; - msgpack_packer_write callback; + PyObject* writer; } msgpack_packer; -static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback); +typedef struct Packer Packer; static inline int msgpack_pack_short(msgpack_packer* pk, short d); static inline int msgpack_pack_int(msgpack_packer* pk, int d); @@ -66,7 +62,20 @@ static inline int msgpack_pack_map(msgpack_packer* pk, unsigned int n); static inline int msgpack_pack_raw(msgpack_packer* pk, size_t l); static inline int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l); +static inline int msgpack_pack_write(msgpack_packer* pk, const char *data, size_t l) +{ + PyObject *buf, *ret; + + buf = PyBuffer_FromMemory((void*)data, l); + //buf = PyString_FromStringAndSize(data, l); + if (buf == NULL) return -1; + ret = PyObject_CallFunctionObjArgs(pk->writer, buf, NULL); + Py_DECREF(buf); + if (ret == NULL) return -1; + Py_DECREF(ret); + return 0; +} #define msgpack_pack_inline_func(name) \ static inline int msgpack_pack ## name @@ -77,16 +86,10 @@ static inline int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_ #define msgpack_pack_user msgpack_packer* #define msgpack_pack_append_buffer(user, buf, len) \ - return (*(user)->callback)((user)->data, (const char*)buf, len) + return msgpack_pack_write(user, (const char*)buf, len) #include "pack_template.h" -static inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) -{ - pk->data = data; - pk->callback = callback; -} - #ifdef __cplusplus } #endif -- cgit v1.2.1 From 03942a1b9020b00bf47e93b7d5ec606e8160c054 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 1 Jul 2009 00:57:46 +0900 Subject: Major speedup on packing. --- python/msgpack/_msgpack.pyx | 60 ++++++++++++++++----------------------------- python/msgpack/pack.h | 29 +++++++++++++--------- 2 files changed, 39 insertions(+), 50 deletions(-) (limited to 'python') diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index 26222aa..9d766c5 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -18,6 +18,7 @@ cdef extern from "Python.h": int PyFloat_Check(object o) int PyString_Check(object o) int PyUnicode_Check(object o) + object PyBuffer_FromMemory(const_char_ptr b, Py_ssize_t len) cdef extern from "stdlib.h": void* malloc(size_t) @@ -30,7 +31,9 @@ cdef extern from "string.h": cdef extern from "pack.h": struct msgpack_packer: - PyObject* writer + char* buf + size_t length + size_t buf_size int msgpack_pack_int(msgpack_packer* pk, int d) int msgpack_pack_nil(msgpack_packer* pk) @@ -56,45 +59,16 @@ cdef class Packer(object): cdef object strm cdef object writer - def __init__(self, strm_, int size=4*1024): - self.strm = strm_ - self.writer = strm_.write - self.pk.writer = self.writer + def __init__(self, strm): + self.strm = strm - def flush(self): - """Flash local buffer and output stream if it has 'flush()' method.""" - if hasattr(self.strm, 'flush'): - self.strm.flush() - - def pack_list(self, len): - """Start packing sequential objects. - - Example: - - packer.pack_list(2) - packer.pack('foo') - packer.pack('bar') - - This is same to: - - packer.pack(['foo', 'bar']) - """ - msgpack_pack_array(&self.pk, len) + cdef int buf_size = 1024*1024 + self.pk.buf = malloc(buf_size); + self.pk.buf_size = buf_size + self.pk.length = 0 - def pack_dict(self, len): - """Start packing key-value objects. - - Example: - - packer.pack_dict(1) - packer.pack('foo') - packer.pack('bar') - - This is same to: - - packer.pack({'foo': 'bar'}) - """ - msgpack_pack_map(&self.pk, len) + def __del__(self): + free(self.pk.buf); cdef __pack(self, object o): cdef long long llval @@ -144,11 +118,19 @@ cdef class Packer(object): # TODO: Serialize with defalt() like simplejson. raise TypeError, "can't serialize %r" % (o,) - def pack(self, object obj, flush=True): + def pack(self, object obj, object flush=True): self.__pack(obj) + buf = PyBuffer_FromMemory(self.pk.buf, self.pk.length) + self.pk.length = 0 + self.strm.write(buf) if flush: self.flush() + def flush(self): + """Flash local buffer and output stream if it has 'flush()' method.""" + if hasattr(self.strm, 'flush'): + self.strm.flush() + close = flush def pack(object o, object stream): diff --git a/python/msgpack/pack.h b/python/msgpack/pack.h index ea97601..d7e0867 100644 --- a/python/msgpack/pack.h +++ b/python/msgpack/pack.h @@ -25,7 +25,9 @@ extern "C" { #endif typedef struct msgpack_packer { - PyObject* writer; + char *buf; + size_t length; + size_t buf_size; } msgpack_packer; typedef struct Packer Packer; @@ -64,16 +66,21 @@ static inline int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_ static inline int msgpack_pack_write(msgpack_packer* pk, const char *data, size_t l) { - PyObject *buf, *ret; - - buf = PyBuffer_FromMemory((void*)data, l); - //buf = PyString_FromStringAndSize(data, l); - if (buf == NULL) return -1; - - ret = PyObject_CallFunctionObjArgs(pk->writer, buf, NULL); - Py_DECREF(buf); - if (ret == NULL) return -1; - Py_DECREF(ret); + char* buf = pk->buf; + size_t bs = pk->buf_size; + size_t len = pk->length; + + if (len + l > bs) { + bs = (len + l) * 2; + buf = realloc(pk->buf, bs); + if (!buf) return -1; + } + memcpy(buf + len, data, l); + len += l; + + pk->buf = buf; + pk->buf_size = bs; + pk->length = len; return 0; } -- cgit v1.2.1 From 78db826a75d9f091f2175ace5f2cd9cb81c0f115 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Wed, 1 Jul 2009 20:55:24 +0900 Subject: Fix memory leak. Remove stream packing feature. Add errorcheck in packing. --- python/msgpack/_msgpack.pyx | 135 +++++++++++++++++++++++--------------------- python/msgpack/pack.h | 2 +- 2 files changed, 73 insertions(+), 64 deletions(-) (limited to 'python') diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index 9d766c5..c455394 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -5,20 +5,22 @@ import cStringIO cdef extern from "Python.h": ctypedef char* const_char_ptr "const char*" ctypedef struct PyObject + cdef object PyString_FromStringAndSize(const_char_ptr b, Py_ssize_t len) - PyObject* Py_True - PyObject* Py_False - char* PyString_AsString(object o) - int PyMapping_Check(object o) - int PySequence_Check(object o) - long long PyLong_AsLongLong(object o) - unsigned long long PyLong_AsUnsignedLongLong(object o) - int PyLong_Check(object o) - int PyInt_Check(object o) - int PyFloat_Check(object o) - int PyString_Check(object o) - int PyUnicode_Check(object o) - object PyBuffer_FromMemory(const_char_ptr b, Py_ssize_t len) + cdef PyObject* Py_True + cdef PyObject* Py_False + + cdef char* PyString_AsString(object o) + cdef long long PyLong_AsLongLong(object o) + cdef unsigned long long PyLong_AsUnsignedLongLong(object o) + + cdef int PyMapping_Check(object o) + cdef int PySequence_Check(object o) + cdef int PyLong_Check(object o) + cdef int PyInt_Check(object o) + cdef int PyFloat_Check(object o) + cdef int PyString_Check(object o) + cdef int PyUnicode_Check(object o) cdef extern from "stdlib.h": void* malloc(size_t) @@ -50,101 +52,101 @@ cdef extern from "pack.h": cdef class Packer(object): - """Packer that pack data into strm. + """MessagePack Packer + + usage: - strm must have `write(bytes)` method. - size specifies local buffer size. + packer = Packer() + astream.write(packer.pack(a)) + astream.write(packer.pack(b)) """ cdef msgpack_packer pk - cdef object strm - cdef object writer - - def __init__(self, strm): - self.strm = strm + def __cinit__(self): cdef int buf_size = 1024*1024 self.pk.buf = malloc(buf_size); self.pk.buf_size = buf_size self.pk.length = 0 - def __del__(self): + def __dealloc__(self): free(self.pk.buf); - cdef __pack(self, object o): + cdef int __pack(self, object o): cdef long long llval cdef unsigned long long ullval cdef long longval cdef double fval cdef char* rawval + cdef int ret if o is None: - msgpack_pack_nil(&self.pk) + ret = msgpack_pack_nil(&self.pk) elif o == Py_True: - msgpack_pack_true(&self.pk) + ret = msgpack_pack_true(&self.pk) elif o == Py_False: - msgpack_pack_false(&self.pk) + ret = msgpack_pack_false(&self.pk) elif PyLong_Check(o): if o > 0: ullval = PyLong_AsUnsignedLongLong(o) - msgpack_pack_unsigned_long_long(&self.pk, ullval) + ret = msgpack_pack_unsigned_long_long(&self.pk, ullval) else: llval = PyLong_AsLongLong(o) - msgpack_pack_long_long(&self.pk, llval) + ret = msgpack_pack_long_long(&self.pk, llval) elif PyInt_Check(o): longval = o - msgpack_pack_long(&self.pk, longval) + ret = msgpack_pack_long(&self.pk, longval) elif PyFloat_Check(o): fval = o - msgpack_pack_double(&self.pk, fval) + ret = msgpack_pack_double(&self.pk, fval) elif PyString_Check(o): rawval = o - msgpack_pack_raw(&self.pk, len(o)) - msgpack_pack_raw_body(&self.pk, rawval, len(o)) + ret = msgpack_pack_raw(&self.pk, len(o)) + if ret == 0: + ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) elif PyUnicode_Check(o): o = o.encode('utf-8') rawval = o - msgpack_pack_raw(&self.pk, len(o)) - msgpack_pack_raw_body(&self.pk, rawval, len(o)) + ret = msgpack_pack_raw(&self.pk, len(o)) + if ret == 0: + ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) elif PyMapping_Check(o): - msgpack_pack_map(&self.pk, len(o)) - for k,v in o.iteritems(): - self.__pack(k) - self.__pack(v) + ret = msgpack_pack_map(&self.pk, len(o)) + if ret == 0: + for k,v in o.iteritems(): + ret = self.__pack(k) + if ret != 0: break + ret = self.__pack(v) + if ret != 0: break elif PySequence_Check(o): - msgpack_pack_array(&self.pk, len(o)) - for v in o: - self.__pack(v) + ret = msgpack_pack_array(&self.pk, len(o)) + if ret == 0: + for v in o: + ret = self.__pack(v) + if ret != 0: break else: # TODO: Serialize with defalt() like simplejson. raise TypeError, "can't serialize %r" % (o,) + return ret - def pack(self, object obj, object flush=True): - self.__pack(obj) - buf = PyBuffer_FromMemory(self.pk.buf, self.pk.length) + def pack(self, object obj): + cdef int ret + ret = self.__pack(obj) + if ret: + raise TypeError + buf = PyString_FromStringAndSize(self.pk.buf, self.pk.length) self.pk.length = 0 - self.strm.write(buf) - if flush: - self.flush() - - def flush(self): - """Flash local buffer and output stream if it has 'flush()' method.""" - if hasattr(self.strm, 'flush'): - self.strm.flush() + return buf - close = flush def pack(object o, object stream): - u"""pack o and write to stream).""" - packer = Packer(stream) - packer.pack(o) - packer.flush() + """pack a object `o` and write it to stream).""" + packer = Packer() + stream.write(packer.pack(o)) def packb(object o): - u"""pack o and return packed bytes.""" - buf = cStringIO.StringIO() - packer = Packer(buf) - packer.pack(o) - return buf.getvalue() + """pack o and return packed bytes.""" + packer = Packer() + return packer.pack(o) packs = packb @@ -222,7 +224,14 @@ cdef class Unpacker(object): cdef int read_size cdef object waiting_bytes - def __init__(self, file_like=None, int read_size=4096): + def __cinit__(self): + self.buf = NULL + + def __dealloc__(self): + if self.buf: + free(self.buf); + + def __init__(self, file_like=None, int read_size=1024*1024): self.file_like = file_like self.read_size = read_size self.waiting_bytes = [] diff --git a/python/msgpack/pack.h b/python/msgpack/pack.h index d7e0867..58f021e 100644 --- a/python/msgpack/pack.h +++ b/python/msgpack/pack.h @@ -72,7 +72,7 @@ static inline int msgpack_pack_write(msgpack_packer* pk, const char *data, size_ if (len + l > bs) { bs = (len + l) * 2; - buf = realloc(pk->buf, bs); + buf = realloc(buf, bs); if (!buf) return -1; } memcpy(buf + len, data, l); -- cgit v1.2.1 From 979efbb9501e14d43e2def8a80992494690a9d39 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Thu, 9 Jul 2009 13:41:04 +0900 Subject: Support MinGW. --- python/msgpack/unpack_define.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'python') diff --git a/python/msgpack/unpack_define.h b/python/msgpack/unpack_define.h index 63668c2..d997569 100644 --- a/python/msgpack/unpack_define.h +++ b/python/msgpack/unpack_define.h @@ -45,8 +45,21 @@ extern "C" { #endif #endif +#ifdef __WIN32__ +static inline uint16_t msgpack_betoh16(uint16_t x) { + return ((x << 8) & 0xff00U) | + ((x >> 8) & 0x00ffU); +} +static inline uint32_t msgpack_betoh32(uint32_t x) { + return ((x << 24) & 0xff000000UL ) | + ((x << 8) & 0x00ff0000UL ) | + ((x >> 8) & 0x0000ff00UL ) | + ((x >> 24) & 0x000000ffUL ); +} +#else #define msgpack_betoh16(x) ntohs(x) #define msgpack_betoh32(x) ntohl(x) +#endif #ifdef __LITTLE_ENDIAN__ #if defined(__bswap_64) -- cgit v1.2.1 From 900785e1aa2e031a4496f8c2a30bb95d0c950b9b Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Sun, 12 Jul 2009 09:29:11 +0900 Subject: Clean up --- python/README | 6 +++--- python/msgpack/_msgpack.pyx | 6 ++++-- python/setup.py | 17 +++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) (limited to 'python') diff --git a/python/README b/python/README index 243def2..6b98982 100644 --- a/python/README +++ b/python/README @@ -13,11 +13,11 @@ You can read document in docstring after `import msgpack` INSTALL --------- -Cython_ is required to build the binding. +Cython_ is required to build msgpack. .. _Cython: http://www.cython.org/ -Posix +posix '''''' You can install msgpack in common way. @@ -28,7 +28,7 @@ Windows MessagePack requires gcc currently. So you need to prepare MinGW GCC. - $ python setup.py install -c mingw + $ python setup.py install -c mingw32 TEST ---- diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index c455394..b407b92 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -163,7 +163,7 @@ cdef extern from "unpack.h": object template_data(template_context* ctx) -def unpacks(object packed_bytes): +def unpackb(object packed_bytes): """Unpack packed_bytes to object. Returns unpacked object.""" cdef const_char_ptr p = packed_bytes cdef template_context ctx @@ -176,10 +176,12 @@ def unpacks(object packed_bytes): else: return None +unpacks = unpackb + def unpack(object stream): """unpack from stream.""" packed = stream.read() - return unpacks(packed) + return unpackb(packed) cdef class UnpackIterator(object): cdef object unpacker diff --git a/python/setup.py b/python/setup.py index faadb33..fa8cb3a 100755 --- a/python/setup.py +++ b/python/setup.py @@ -7,18 +7,14 @@ import os version = '0.0.1dev' -PACKAGE_ROOT = os.getcwdu() -INCLUDE_PATH = os.path.join(PACKAGE_ROOT, 'include') msgpack_mod = Extension('msgpack._msgpack', - sources=['msgpack/_msgpack.pyx'], - include_dirs=[INCLUDE_PATH]) + sources=['msgpack/_msgpack.pyx'] + ) -desc = 'MessagePack serializer/desirializer.' +desc = 'MessagePack (de)serializer.' long_desc = desc + """ -Python binding of MessagePack_. - -This package is under development. +MessagePack_ (de)serializer for Python. .. _MessagePack: http://msgpack.sourceforge.jp/ @@ -37,4 +33,9 @@ setup(name='msgpack', packages=['msgpack'], description=desc, long_description=long_desc, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + ] ) -- cgit v1.2.1 From e5c49dae13b26f2155dffffbc4e9915badbcecfb Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Sun, 12 Jul 2009 20:02:21 +0900 Subject: Release 0.1.0 --- python/README | 4 ++-- python/msgpack/_msgpack.pyx | 12 ++++++------ python/setup.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'python') diff --git a/python/README b/python/README index 6b98982..2b2ebe9 100644 --- a/python/README +++ b/python/README @@ -3,8 +3,8 @@ MessagePack Python Binding =========================== :author: Naoki INADA -:version: 0.0.1 -:date: 2009-06-27 +:version: 0.1.0 +:date: 2009-07-12 HOW TO USE ----------- diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index b407b92..7990a18 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -139,7 +139,7 @@ cdef class Packer(object): def pack(object o, object stream): - """pack a object `o` and write it to stream).""" + """pack an object `o` and write it to stream).""" packer = Packer() stream.write(packer.pack(o)) @@ -164,7 +164,7 @@ cdef extern from "unpack.h": def unpackb(object packed_bytes): - """Unpack packed_bytes to object. Returns unpacked object.""" + """Unpack packed_bytes to object. Returns an unpacked object.""" cdef const_char_ptr p = packed_bytes cdef template_context ctx cdef size_t off = 0 @@ -179,7 +179,7 @@ def unpackb(object packed_bytes): unpacks = unpackb def unpack(object stream): - """unpack from stream.""" + """unpack an object from stream.""" packed = stream.read() return unpackb(packed) @@ -196,14 +196,14 @@ cdef class UnpackIterator(object): return self cdef class Unpacker(object): - """Unpacker(file_like=None, read_size=4096) + """Unpacker(file_like=None, read_size=1024*1024) Streaming unpacker. file_like must have read(n) method. read_size is used like file_like.read(read_size) - If file_like is None, you can feed() bytes. feed() is useful - for unpack from non-blocking stream. + If file_like is None, you can ``feed()`` bytes. ``feed()`` is + useful for unpacking from non-blocking stream. exsample 1: unpacker = Unpacker(afile) diff --git a/python/setup.py b/python/setup.py index fa8cb3a..255e0db 100755 --- a/python/setup.py +++ b/python/setup.py @@ -5,7 +5,7 @@ from distutils.core import setup, Extension from Cython.Distutils import build_ext import os -version = '0.0.1dev' +version = '0.1.0' msgpack_mod = Extension('msgpack._msgpack', sources=['msgpack/_msgpack.pyx'] -- cgit v1.2.1 From 294e3fe7ab01ef9273b364b0d3d9df4e9b275158 Mon Sep 17 00:00:00 2001 From: Naoki INADA Date: Mon, 13 Jul 2009 14:27:57 +0900 Subject: Add setup script for distribution. --- python/setup.py | 7 ++++--- python/setup_dev.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100755 python/setup_dev.py (limited to 'python') diff --git a/python/setup.py b/python/setup.py index 255e0db..c0d121b 100755 --- a/python/setup.py +++ b/python/setup.py @@ -2,13 +2,14 @@ # coding: utf-8 from distutils.core import setup, Extension -from Cython.Distutils import build_ext +#from Cython.Distutils import build_ext import os version = '0.1.0' msgpack_mod = Extension('msgpack._msgpack', - sources=['msgpack/_msgpack.pyx'] + #sources=['msgpack/_msgpack.pyx'] + sources=['msgpack/_msgpack.c'] ) desc = 'MessagePack (de)serializer.' @@ -28,7 +29,7 @@ setup(name='msgpack', author='Naoki INADA', author_email='songofacandy@gmail.com', version=version, - cmdclass={'build_ext': build_ext}, + #cmdclass={'build_ext': build_ext}, ext_modules=[msgpack_mod], packages=['msgpack'], description=desc, diff --git a/python/setup_dev.py b/python/setup_dev.py new file mode 100755 index 0000000..255e0db --- /dev/null +++ b/python/setup_dev.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# coding: utf-8 + +from distutils.core import setup, Extension +from Cython.Distutils import build_ext +import os + +version = '0.1.0' + +msgpack_mod = Extension('msgpack._msgpack', + sources=['msgpack/_msgpack.pyx'] + ) + +desc = 'MessagePack (de)serializer.' +long_desc = desc + """ + +MessagePack_ (de)serializer for Python. + +.. _MessagePack: http://msgpack.sourceforge.jp/ + +What's MessagePack? (from http://msgpack.sourceforge.jp/) + + MessagePack is a binary-based efficient data interchange format that is + focused on high performance. It is like JSON, but very fast and small. +""" + +setup(name='msgpack', + author='Naoki INADA', + author_email='songofacandy@gmail.com', + version=version, + cmdclass={'build_ext': build_ext}, + ext_modules=[msgpack_mod], + packages=['msgpack'], + description=desc, + long_description=long_desc, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + ] + ) -- cgit v1.2.1