diff --git a/salt/__init__.py b/salt/__init__.py index a83f3a9dd0..c04cd46ca2 100755 --- a/salt/__init__.py +++ b/salt/__init__.py @@ -10,10 +10,13 @@ import optparse import os import sys -# Import salt libs -import salt.config -import salt.utils.verify - +# Import salt libs, the try block bypasses an issue at build time so that c +# modules don't cause the build to fail +try: + import salt.config + import salt.utils.verify +except ImportError: + pass def verify_env(dirs): ''' diff --git a/salt/client.py b/salt/client.py index 178fa0c11f..9d760127a2 100644 --- a/salt/client.py +++ b/salt/client.py @@ -26,7 +26,6 @@ The data structure needs to be: # small, and only start with the ability to execute salt commands locally. # This means that the primary client to build is, the LocalClient -import cPickle as pickle import datetime import glob import os @@ -72,6 +71,7 @@ class LocalClient(object): ''' def __init__(self, c_path='/etc/salt/master'): self.opts = salt.config.master_config(c_path) + self.serial = salt.payload.Serial(self.opts) self.key = self.__read_master_key() def __read_master_key(self): @@ -200,7 +200,7 @@ class LocalClient(object): continue while fn_ not in ret: try: - ret[fn_] = pickle.load(open(retp, 'r')) + ret[fn_] = self.serial.load(open(retp, 'r')) except: pass if ret and start == 999999999999: @@ -239,10 +239,10 @@ class LocalClient(object): continue while fn_ not in ret: try: - ret_data = pickle.load(open(retp, 'r')) + ret_data = self.serial.load(open(retp, 'r')) ret[fn_] = {'ret': ret_data} if os.path.isfile(outp): - ret[fn_]['out'] = pickle.load(open(outp, 'r')) + ret[fn_]['out'] = self.serial.load(open(outp, 'r')) except: pass if ret and start == 999999999999: @@ -269,7 +269,7 @@ class LocalClient(object): loadp = os.path.join(jid_dir, '.load.p') if os.path.isfile(loadp): try: - load = pickle.load(open(loadp, 'r')) + load = self.serial.load(open(loadp, 'r')) if load['fun'] == cmd: # We found a match! Add the return values ret[jid] = {} @@ -278,7 +278,7 @@ class LocalClient(object): retp = os.path.join(host_dir, 'return.p') if not os.path.isfile(retp): continue - ret[jid][host] = pickle.load(open(retp)) + ret[jid][host] = self.serial.load(open(retp)) except: continue else: @@ -370,7 +370,7 @@ class LocalClient(object): payload = None for ind in range(100): try: - payload = salt.payload.unpackage( + payload = self.serial.loads( socket.recv( zmq.NOBLOCK ) diff --git a/salt/config.py b/salt/config.py index 12fef53725..6239ea7b3c 100644 --- a/salt/config.py +++ b/salt/config.py @@ -136,6 +136,7 @@ def master_config(path): 'log_granular_levels': {}, 'cluster_masters': [], 'cluster_mode': 'paranoid', + 'serial': 'msgpack', } load_config(opts, path, 'SALT_MASTER_CONFIG') diff --git a/salt/crypt.py b/salt/crypt.py index 859e0515d8..8f931d305a 100644 --- a/salt/crypt.py +++ b/salt/crypt.py @@ -5,7 +5,6 @@ authenticating peers ''' # Import python libs -import cPickle as pickle import hashlib import hmac import logging @@ -98,6 +97,7 @@ class Auth(object): ''' def __init__(self, opts): self.opts = opts + self.serial = salt.payload.Serial(self.opts) self.rsa_path = os.path.join(self.opts['pki_dir'], 'minion.pem') if 'syndic_master' in self.opts: self.mpub = 'syndic_master.pub' @@ -188,9 +188,9 @@ class Auth(object): context = zmq.Context() socket = context.socket(zmq.REQ) socket.connect(self.opts['master_uri']) - payload = salt.payload.package(self.minion_sign_in_payload()) + payload = self.serial.dumps(self.minion_sign_in_payload()) socket.send(payload) - payload = salt.payload.unpackage(socket.recv()) + payload = self.serial.loads(socket.recv()) if 'load' in payload: if 'ret' in payload['load']: if not payload['load']['ret']: @@ -244,9 +244,10 @@ class Crypticle(object): AES_BLOCK_SIZE = 16 SIG_SIZE = hashlib.sha256().digest_size - def __init__(self, key_string, key_size=192): + def __init__(self, opts, key_string, key_size=192): self.keys = self.extract_keys(key_string, key_size) self.key_size = key_size + self.serial = salt.payload.Serial(opts) @classmethod def generate_key_string(cls, key_size=192): @@ -288,21 +289,21 @@ class Crypticle(object): data = cypher.decrypt(data) return data[:-ord(data[-1])] - def dumps(self, obj, pickler=pickle): + def dumps(self, obj): ''' - pickle and encrypt a python object + Serialize and encrypt a python object ''' - return self.encrypt(self.PICKLE_PAD + pickler.dumps(obj)) + return self.encrypt(self.PICKLE_PAD + self.serial.dumps(obj)) - def loads(self, data, pickler=pickle): + def loads(self, data): ''' - decrypt and un-pickle a python object + Decrypt and un-serialize a python object ''' data = self.decrypt(data) # simple integrity check to verify that we got meaningful data if not data.startswith(self.PICKLE_PAD): return {} - return pickler.loads(data[len(self.PICKLE_PAD):]) + return self.serial.loads(data[len(self.PICKLE_PAD):]) class SAuth(Auth): @@ -326,7 +327,7 @@ class SAuth(Auth): print 'Failed to authenticate with the master, verify that this'\ + ' minion\'s public key has been accepted on the salt master' sys.exit(2) - return Crypticle(creds['aes']) + return Crypticle(self.opts, creds['aes']) def gen_token(self, clear_tok): ''' diff --git a/salt/master.py b/salt/master.py index 1dc71aecb8..f2a3569d88 100644 --- a/salt/master.py +++ b/salt/master.py @@ -4,7 +4,6 @@ involves preparing the three listeners and the workers needed by the master. ''' # Import python modules -import cPickle as pickle import datetime import hashlib import logging @@ -29,20 +28,21 @@ import salt.utils log = logging.getLogger(__name__) -def prep_jid(cachedir, load): +def prep_jid(opts, load): ''' Parses the job return directory, generates a job id and sets up the job id directory. ''' + serial = salt.payload.Serial(opts) jid_root = os.path.join(cachedir, 'jobs') jid = "{0:%Y%m%d%H%M%S%f}".format(datetime.datetime.now()) jid_dir = os.path.join(jid_root, jid) if not os.path.isdir(jid_dir): os.makedirs(jid_dir) - pickle.dump(load, open(os.path.join(jid_dir, '.load.p'), 'w+')) + serial.dump(load, open(os.path.join(jid_dir, '.load.p'), 'w+')) else: - return prep_jid(load) + return prep_jid(cachedir, load) return jid @@ -63,7 +63,7 @@ class SMaster(object): ''' Return the crypticle used for AES ''' - return salt.crypt.Crypticle(self.opts['aes']) + return salt.crypt.Crypticle(self.opts, self.opts['aes']) def __prep_key(self): ''' @@ -230,6 +230,7 @@ class MWorker(multiprocessing.Process): clear_funcs): multiprocessing.Process.__init__(self) self.opts = opts + self.serial = salt.payload.Serial(opts) self.crypticle = crypticle self.aes_funcs = aes_funcs self.clear_funcs = clear_funcs @@ -248,8 +249,8 @@ class MWorker(multiprocessing.Process): while True: package = socket.recv() - payload = salt.payload.unpackage(package) - ret = salt.payload.package(self._handle_payload(payload)) + payload = self.serial.loads(package) + ret = self.serial.dumps(self._handle_payload(payload)) socket.send(ret) def _handle_payload(self, payload): @@ -257,6 +258,11 @@ class MWorker(multiprocessing.Process): The _handle_payload method is the key method used to figure out what needs to be done with communication to the server ''' + try: + key = payload['enc'] + load = payload['load'] + except KeyError: + return '' return {'aes': self._handle_aes, 'pub': self._handle_pub, 'clear': self._handle_clear}[payload['enc']](payload['load']) @@ -303,6 +309,7 @@ class AESFuncs(object): # def __init__(self, opts, crypticle): self.opts = opts + self.serial = salt.payload.Serial(opts) self.crypticle = crypticle # Make a client self.local = salt.client.LocalClient(self.opts['conf_file']) @@ -425,10 +432,10 @@ class AESFuncs(object): hn_dir = os.path.join(jid_dir, load['id']) if not os.path.isdir(hn_dir): os.makedirs(hn_dir) - pickle.dump(load['return'], + self.serial.dump(load['return'], open(os.path.join(hn_dir, 'return.p'), 'w+')) if 'out' in load: - pickle.dump(load['out'], + self.serial.dump(load['out'], open(os.path.join(hn_dir, 'out.p'), 'w+')) def _syndic_return(self, load): @@ -498,7 +505,7 @@ class AESFuncs(object): if not good: return {} # Set up the publication payload - jid = prep_jid(self.opts['cachedir'], clear_load) + jid = prep_jid(self.opts, clear_load) payload = {'enc': 'aes'} load = { 'fun': clear_load['fun'], @@ -523,7 +530,7 @@ class AESFuncs(object): os.path.join(self.opts['sock_dir'], 'publish_pull.ipc') ) pub_sock.connect(pull_uri) - pub_sock.send(salt.payload.package(payload)) + pub_sock.send(self.serial.dumps(payload)) # Run the client get_returns method return self.local.get_returns( jid, @@ -562,6 +569,7 @@ class ClearFuncs(object): # _auth def __init__(self, opts, key, master_key, crypticle): self.opts = opts + self.serial = salt.payload.Serial(opts) self.key = key self.master_key = master_key self.crypticle = crypticle @@ -608,7 +616,7 @@ class ClearFuncs(object): # 1. Verify that the key we are receiving matches the stored key # 2. Store the key if it is not there # 3. make an rsa key with the pub key - # 4. encrypt the aes key as an encrypted pickle + # 4. encrypt the aes key as an encrypted salt.payload # 5. package the return and return it log.info('Authentication request from %(id)s', load) pubfn = os.path.join(self.opts['pki_dir'], @@ -696,7 +704,7 @@ class ClearFuncs(object): if not os.path.isdir(jid_dir): os.makedirs(jid_dir) # Save the invocation information - pickle.dump(clear_load, open(os.path.join(jid_dir, '.load.p'), 'w+')) + self.serial.dump(clear_load, open(os.path.join(jid_dir, '.load.p'), 'w+')) # Set up the payload payload = {'enc': 'aes'} load = { @@ -718,6 +726,6 @@ class ClearFuncs(object): os.path.join(self.opts['sock_dir'], 'publish_pull.ipc') ) pub_sock.connect(pull_uri) - pub_sock.send(salt.payload.package(payload)) + pub_sock.send(self.serial.dumps(payload)) return {'enc': 'clear', 'load': {'jid': clear_load['jid']}} diff --git a/salt/minion.py b/salt/minion.py index 9946c401ff..834b5dda0d 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -25,6 +25,7 @@ import salt.loader import salt.modules import salt.returners import salt.utils +import salt.payload log = logging.getLogger(__name__) @@ -77,6 +78,7 @@ class Minion(object): Pass in the options dict ''' self.opts = opts + self.serial = salt.payload.Serial(self.opts) self.mod_opts = self.__prep_mod_opts() self.functions, self.returners = self.__load_modules() self.matcher = Matcher(self.opts, self.functions) @@ -290,7 +292,7 @@ class Minion(object): except KeyError: pass payload['load'] = self.crypticle.dumps(load) - socket.send_pyobj(payload) + socket.send(self.serial.dumps(payload)) return socket.recv() def authenticate(self): @@ -311,7 +313,7 @@ class Minion(object): time.sleep(10) self.aes = creds['aes'] self.publish_port = creds['publish_port'] - self.crypticle = salt.crypt.Crypticle(self.aes) + self.crypticle = salt.crypt.Crypticle(self.opts, self.aes) def passive_refresh(self): ''' @@ -349,7 +351,7 @@ class Minion(object): while True: payload = None try: - payload = socket.recv_pyobj(1) + payload = self.serial.loads(socket.recv(1)) self._handle_payload(payload) last = time.time() except: @@ -369,7 +371,7 @@ class Minion(object): while True: payload = None try: - payload = socket.recv_pyobj(1) + payload = self.serial(socket.recv(1)) self._handle_payload(payload) except: pass @@ -579,6 +581,7 @@ class FileClient(object): ''' def __init__(self, opts): self.opts = opts + self.serial = salt.payload.Serial(self.opts) self.auth = salt.crypt.SAuth(opts) self.socket = self.__get_socket() @@ -623,8 +626,8 @@ class FileClient(object): else: load['loc'] = fn_.tell() payload['load'] = self.auth.crypticle.dumps(load) - self.socket.send_pyobj(payload) - data = self.auth.crypticle.loads(self.socket.recv_pyobj()) + self.socket.send(self.serial.dumps(payload)) + data = self.auth.crypticle.loads(self.serial.loads(self.socket.recv())) if not data['data']: break if not fn_: @@ -686,8 +689,8 @@ class FileClient(object): load = {'env': env, 'cmd': '_file_list'} payload['load'] = self.auth.crypticle.dumps(load) - self.socket.send_pyobj(payload) - return self.auth.crypticle.loads(self.socket.recv_pyobj()) + self.socket.send(self.serial.dumps(payload)) + return self.auth.crypticle.loads(self.serial.loads(self.socket.recv())) def hash_file(self, path, env='base'): ''' @@ -701,8 +704,8 @@ class FileClient(object): 'env': env, 'cmd': '_file_hash'} payload['load'] = self.auth.crypticle.dumps(load) - self.socket.send_pyobj(payload) - return self.auth.crypticle.loads(self.socket.recv_pyobj()) + self.socket.send(self.serial.dumps(payload)) + return self.auth.crypticle.loads(self.serial.loads(self.socket.recv())) def list_env(self, path, env='base'): ''' @@ -712,8 +715,8 @@ class FileClient(object): load = {'env': env, 'cmd': '_file_list'} payload['load'] = self.auth.crypticle.dumps(load) - self.socket.send_pyobj(payload) - return self.auth.crypticle.loads(self.socket.recv_pyobj()) + self.socket.send(self.serial.dumps(payload)) + return self.auth.crypticle.loads(self.serial.loads(self.socket.recv())) def get_state(self, sls, env): ''' @@ -736,5 +739,5 @@ class FileClient(object): payload = {'enc': 'aes'} load = {'cmd': '_master_opts'} payload['load'] = self.auth.crypticle.dumps(load) - self.socket.send_pyobj(payload) - return self.auth.crypticle.loads(self.socket.recv_pyobj()) + self.socket.send(self.serial.dumps(payload)) + return self.auth.crypticle.loads(self.serial.loads(self.socket.recv())) diff --git a/salt/modules/publish.py b/salt/modules/publish.py index d48369c041..a0b6121277 100644 --- a/salt/modules/publish.py +++ b/salt/modules/publish.py @@ -5,6 +5,7 @@ Publish a command from a minion to a target import zmq import salt.crypt +import salt.payload def _get_socket(): @@ -35,6 +36,7 @@ def publish(tgt, fun, arg=None, expr_form='glob', returner=''): salt system.example.com publish.publish '*' cmd.run 'ls -la /tmp' ''' + serial = salt.payload.Serial(__opts__) if fun == 'publish.publish': # Need to log something here return {} @@ -55,5 +57,5 @@ def publish(tgt, fun, arg=None, expr_form='glob', returner=''): 'id': __opts__['id']} payload['load'] = auth.crypticle.dumps(load) socket = _get_socket() - socket.send_pyobj(payload) - return auth.crypticle.loads(socket.recv_pyobj()) + socket.send(serial.dumps(payload)) + return auth.crypticle.loads(serial.loads(socket.recv())) diff --git a/salt/msgpack/COPYING b/salt/msgpack/COPYING new file mode 100644 index 0000000000..f067af3aae --- /dev/null +++ b/salt/msgpack/COPYING @@ -0,0 +1,14 @@ +Copyright (C) 2008-2011 INADA Naoki + + 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. + diff --git a/salt/msgpack/__init__.py b/salt/msgpack/__init__.py new file mode 100644 index 0000000000..2474e497af --- /dev/null +++ b/salt/msgpack/__init__.py @@ -0,0 +1,11 @@ +# coding: utf-8 +from salt.msgpack.__version__ import * +from salt.msgpack._msgpack import * + +# alias for compatibility to simplejson/marshal/pickle. +load = unpack +loads = unpackb + +dump = pack +dumps = packb + diff --git a/salt/msgpack/__version__.py b/salt/msgpack/__version__.py new file mode 100644 index 0000000000..8e4f9c3d33 --- /dev/null +++ b/salt/msgpack/__version__.py @@ -0,0 +1 @@ +version = (0, 1, 10) diff --git a/salt/msgpack/_msgpack.c b/salt/msgpack/_msgpack.c new file mode 100644 index 0000000000..3e2657d18f --- /dev/null +++ b/salt/msgpack/_msgpack.c @@ -0,0 +1,6856 @@ +/* Generated by Cython 0.15 on Mon Aug 22 02:13:14 2011 */ + +#define PY_SSIZE_T_CLEAN +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#else + +#include /* For offsetof */ +#ifndef offsetof +#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif + +#if !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif + +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif + +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif + +#if PY_VERSION_HEX < 0x02040000 + #define METH_COEXIST 0 + #define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) + #define PyDict_Contains(d,o) PySequence_Contains(d,o) +#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) __Pyx_PyInt_AsInt(o) + #define PyNumber_Index(o) PyNumber_Int(o) + #define PyIndex_Check(o) PyNumber_Check(o) + #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) +#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 PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define PyBytesObject PyStringObject + #define PyBytes_Type PyString_Type + #define PyBytes_Check PyString_Check + #define PyBytes_CheckExact PyString_CheckExact + #define PyBytes_FromString PyString_FromString + #define PyBytes_FromStringAndSize PyString_FromStringAndSize + #define PyBytes_FromFormat PyString_FromFormat + #define PyBytes_DecodeEscape PyString_DecodeEscape + #define PyBytes_AsString PyString_AsString + #define PyBytes_AsStringAndSize PyString_AsStringAndSize + #define PyBytes_Size PyString_Size + #define PyBytes_AS_STRING PyString_AS_STRING + #define PyBytes_GET_SIZE PyString_GET_SIZE + #define PyBytes_Repr PyString_Repr + #define PyBytes_Concat PyString_Concat + #define PyBytes_ConcatAndDel PyString_ConcatAndDel +#endif + +#if PY_VERSION_HEX < 0x02060000 + #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) + #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) +#endif + +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) + +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #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 +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif + +#if PY_VERSION_HEX < 0x03020000 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t PyInt_AsLong +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t +#endif + + +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif + +#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) + #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) + #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) + #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) +#else + #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ + (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ + (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ + (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) + #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ + (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ + (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ + (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) + #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ + (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ + (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ + (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) +#endif + +#if PY_MAJOR_VERSION >= 3 + #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) +#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 + +#ifndef __PYX_EXTERN_C + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#if defined(WIN32) || defined(MS_WINDOWS) +#define _USE_MATH_DEFINES +#endif +#include +#define __PYX_HAVE__msgpack___msgpack +#define __PYX_HAVE_API__msgpack___msgpack +#include "stdio.h" +#include "pythread.h" +#include "stdlib.h" +#include "string.h" +#include "pack.h" +#include "unpack.h" +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#ifdef PYREX_WITHOUT_ASSERTIONS +#define CYTHON_WITHOUT_ASSERTIONS +#endif + + +/* inline attribute */ +#ifndef CYTHON_INLINE + #if defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +/* unused attribute */ +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || defined(__INTEL_COMPILER) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif + +typedef struct {PyObject **p; char *s; const long n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ + + +/* Type Conversion Predeclarations */ + +#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s) +#define __Pyx_PyBytes_AsUString(s) ((unsigned char*) PyBytes_AsString(s)) + +#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) +#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); + +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static CYTHON_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 PyObject *__pyx_empty_bytes; +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[] = { + "_msgpack.pyx", + "bool.pxd", + "complex.pxd", +}; + +/*--- Type declarations ---*/ +struct __pyx_obj_7msgpack_8_msgpack_Unpacker; +struct __pyx_obj_7msgpack_8_msgpack_Packer; +struct __pyx_opt_args_7msgpack_8_msgpack_6Packer__pack; + +/* "msgpack/_msgpack.pyx":84 + * free(self.pk.buf); + * + * cdef int _pack(self, object o, int nest_limit=DEFAULT_RECURSE_LIMIT) except -1: # <<<<<<<<<<<<<< + * cdef long long llval + * cdef unsigned long long ullval + */ +struct __pyx_opt_args_7msgpack_8_msgpack_6Packer__pack { + int __pyx_n; + int nest_limit; +}; + +/* "msgpack/_msgpack.pyx":249 + * object_hook=object_hook, list_hook=list_hook, encoding=encoding, unicode_errors=unicode_errors) + * + * cdef class Unpacker(object): # <<<<<<<<<<<<<< + * """Unpacker(read_size=1024*1024) + * + */ +struct __pyx_obj_7msgpack_8_msgpack_Unpacker { + PyObject_HEAD + struct __pyx_vtabstruct_7msgpack_8_msgpack_Unpacker *__pyx_vtab; + template_context ctx; + char *buf; + size_t buf_size; + size_t buf_head; + size_t buf_tail; + PyObject *file_like; + PyObject *file_like_read; + Py_ssize_t read_size; + int use_list; + PyObject *object_hook; + PyObject *_bencoding; + PyObject *_berrors; + char *encoding; + char *unicode_errors; +}; + + +/* "msgpack/_msgpack.pyx":37 + * cdef int DEFAULT_RECURSE_LIMIT=511 + * + * cdef class Packer(object): # <<<<<<<<<<<<<< + * """MessagePack Packer + * + */ +struct __pyx_obj_7msgpack_8_msgpack_Packer { + PyObject_HEAD + struct __pyx_vtabstruct_7msgpack_8_msgpack_Packer *__pyx_vtab; + struct msgpack_packer pk; + PyObject *_default; + PyObject *_bencoding; + PyObject *_berrors; + char *encoding; + char *unicode_errors; +}; + + + +/* "msgpack/_msgpack.pyx":249 + * object_hook=object_hook, list_hook=list_hook, encoding=encoding, unicode_errors=unicode_errors) + * + * cdef class Unpacker(object): # <<<<<<<<<<<<<< + * """Unpacker(read_size=1024*1024) + * + */ + +struct __pyx_vtabstruct_7msgpack_8_msgpack_Unpacker { + PyObject *(*append_buffer)(struct __pyx_obj_7msgpack_8_msgpack_Unpacker *, void *, Py_ssize_t); + PyObject *(*fill_buffer)(struct __pyx_obj_7msgpack_8_msgpack_Unpacker *); + PyObject *(*unpack)(struct __pyx_obj_7msgpack_8_msgpack_Unpacker *, int __pyx_skip_dispatch); +}; +static struct __pyx_vtabstruct_7msgpack_8_msgpack_Unpacker *__pyx_vtabptr_7msgpack_8_msgpack_Unpacker; + + +/* "msgpack/_msgpack.pyx":37 + * cdef int DEFAULT_RECURSE_LIMIT=511 + * + * cdef class Packer(object): # <<<<<<<<<<<<<< + * """MessagePack Packer + * + */ + +struct __pyx_vtabstruct_7msgpack_8_msgpack_Packer { + int (*_pack)(struct __pyx_obj_7msgpack_8_msgpack_Packer *, PyObject *, struct __pyx_opt_args_7msgpack_8_msgpack_6Packer__pack *__pyx_optional_args); +}; +static struct __pyx_vtabstruct_7msgpack_8_msgpack_Packer *__pyx_vtabptr_7msgpack_8_msgpack_Packer; + +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif + +#if 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* (*SetupContext)(const char*, int, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/ + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; + #define __Pyx_RefNannySetupContext(name) __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) + #define __Pyx_RefNannyFinishContext() __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) + #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name) + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif /* CYTHON_REFNANNY */ + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *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 CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, + const char* function_name, int kw_allowed); /*proto*/ + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/ + +static void __Pyx_RaiseDoubleKeywordsError( + const char* func_name, PyObject* kw_name); /*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 CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); + +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); + +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/ + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/ + +static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *); + +static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *); + +static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *); + +static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *); + +static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *); + +static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *); + +static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *); + +static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *); + +static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *); + +static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *); + +static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *); + +static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *); + +static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *); + +static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *); + +static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *); + +static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *); + +static int __Pyx_check_binary_version(void); + +static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ + +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); /*proto*/ + +static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ + +static void __Pyx_AddTraceback(const char *funcname, int __pyx_clineno, + int __pyx_lineno, const char *__pyx_filename); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ + +/* Module declarations from 'cpython.version' */ + +/* Module declarations from 'cpython.ref' */ + +/* Module declarations from 'cpython.exc' */ + +/* Module declarations from 'cpython.module' */ + +/* Module declarations from 'cpython.mem' */ + +/* Module declarations from 'cpython.tuple' */ + +/* Module declarations from 'cpython.list' */ + +/* Module declarations from 'libc.stdio' */ + +/* Module declarations from 'cpython.object' */ + +/* Module declarations from 'cpython.sequence' */ + +/* Module declarations from 'cpython.mapping' */ + +/* Module declarations from 'cpython.iterator' */ + +/* Module declarations from 'cpython.type' */ + +/* Module declarations from 'cpython.number' */ + +/* Module declarations from 'cpython.int' */ + +/* Module declarations from '__builtin__' */ + +/* Module declarations from 'cpython.bool' */ +static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0; + +/* Module declarations from 'cpython.long' */ + +/* Module declarations from 'cpython.float' */ + +/* Module declarations from '__builtin__' */ + +/* Module declarations from 'cpython.complex' */ +static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; + +/* Module declarations from 'cpython.string' */ + +/* Module declarations from 'cpython.unicode' */ + +/* Module declarations from 'cpython.dict' */ + +/* Module declarations from 'cpython.instance' */ + +/* Module declarations from 'cpython.function' */ + +/* Module declarations from 'cpython.method' */ + +/* Module declarations from 'cpython.weakref' */ + +/* Module declarations from 'cpython.getargs' */ + +/* Module declarations from 'cpython.pythread' */ + +/* Module declarations from 'cpython.pystate' */ + +/* Module declarations from 'cpython.cobject' */ + +/* Module declarations from 'cpython.oldbuffer' */ + +/* Module declarations from 'cpython.set' */ + +/* Module declarations from 'cpython.buffer' */ + +/* Module declarations from 'cpython.bytes' */ + +/* Module declarations from 'cpython.pycapsule' */ + +/* Module declarations from 'cpython' */ + +/* Module declarations from 'libc.stdlib' */ + +/* Module declarations from 'libc.string' */ + +/* Module declarations from 'msgpack._msgpack' */ +static PyTypeObject *__pyx_ptype_7msgpack_8_msgpack_Packer = 0; +static PyTypeObject *__pyx_ptype_7msgpack_8_msgpack_Unpacker = 0; +static int __pyx_v_7msgpack_8_msgpack_DEFAULT_RECURSE_LIMIT; +#define __Pyx_MODULE_NAME "msgpack._msgpack" +int __pyx_module_is_main_msgpack___msgpack = 0; + +/* Implementation of 'msgpack._msgpack' */ +static PyObject *__pyx_builtin_MemoryError; +static PyObject *__pyx_builtin_TypeError; +static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_AssertionError; +static PyObject *__pyx_builtin_StopIteration; +static char __pyx_k_1[] = "Unable to allocate internal buffer."; +static char __pyx_k_3[] = "utf-8"; +static char __pyx_k_4[] = "default must be a callable."; +static char __pyx_k_9[] = "Too deep."; +static char __pyx_k_11[] = "Can't encode utf-8 no encoding is specified"; +static char __pyx_k_13[] = "can't serialize %r"; +static char __pyx_k_16[] = "object_hook must be a callable."; +static char __pyx_k_18[] = "list_hook must be a callable."; +static char __pyx_k_20[] = "`file_like.read` must be a callable."; +static char __pyx_k_27[] = "unpacker.feed() is not be able to use with`file_like`."; +static char __pyx_k_29[] = "Unable to enlarge internal buffer."; +static char __pyx_k_31[] = "No more unpack data."; +static char __pyx_k_33[] = "Unpack failed: error = %d"; +static char __pyx_k_34[] = "msgpack._msgpack"; +static char __pyx_k__o[] = "o"; +static char __pyx_k__gc[] = "gc"; +static char __pyx_k__pack[] = "pack"; +static char __pyx_k__read[] = "read"; +static char __pyx_k__ascii[] = "ascii"; +static char __pyx_k__dumps[] = "dumps"; +static char __pyx_k__loads[] = "loads"; +static char __pyx_k__packb[] = "packb"; +static char __pyx_k__packs[] = "packs"; +static char __pyx_k__write[] = "write"; +static char __pyx_k__enable[] = "enable"; +static char __pyx_k__encode[] = "encode"; +static char __pyx_k__packed[] = "packed"; +static char __pyx_k__stream[] = "stream"; +static char __pyx_k__strict[] = "strict"; +static char __pyx_k__unpack[] = "unpack"; +static char __pyx_k__default[] = "default"; +static char __pyx_k__disable[] = "disable"; +static char __pyx_k__unpackb[] = "unpackb"; +static char __pyx_k__unpacks[] = "unpacks"; +static char __pyx_k____main__[] = "__main__"; +static char __pyx_k____test__[] = "__test__"; +static char __pyx_k__encoding[] = "encoding"; +static char __pyx_k__use_list[] = "use_list"; +static char __pyx_k__TypeError[] = "TypeError"; +static char __pyx_k__file_like[] = "file_like"; +static char __pyx_k__list_hook[] = "list_hook"; +static char __pyx_k__read_size[] = "read_size"; +static char __pyx_k__ValueError[] = "ValueError"; +static char __pyx_k___gc_enable[] = "_gc_enable"; +static char __pyx_k__MemoryError[] = "MemoryError"; +static char __pyx_k___gc_disable[] = "_gc_disable"; +static char __pyx_k__object_hook[] = "object_hook"; +static char __pyx_k__StopIteration[] = "StopIteration"; +static char __pyx_k__AssertionError[] = "AssertionError"; +static char __pyx_k__unicode_errors[] = "unicode_errors"; +static PyObject *__pyx_kp_s_1; +static PyObject *__pyx_kp_s_11; +static PyObject *__pyx_kp_s_13; +static PyObject *__pyx_kp_s_16; +static PyObject *__pyx_kp_s_18; +static PyObject *__pyx_kp_s_20; +static PyObject *__pyx_kp_s_27; +static PyObject *__pyx_kp_s_29; +static PyObject *__pyx_kp_s_3; +static PyObject *__pyx_kp_s_31; +static PyObject *__pyx_kp_s_33; +static PyObject *__pyx_n_s_34; +static PyObject *__pyx_kp_s_4; +static PyObject *__pyx_kp_s_9; +static PyObject *__pyx_n_s__AssertionError; +static PyObject *__pyx_n_s__MemoryError; +static PyObject *__pyx_n_s__StopIteration; +static PyObject *__pyx_n_s__TypeError; +static PyObject *__pyx_n_s__ValueError; +static PyObject *__pyx_n_s____main__; +static PyObject *__pyx_n_s____test__; +static PyObject *__pyx_n_s___gc_disable; +static PyObject *__pyx_n_s___gc_enable; +static PyObject *__pyx_n_s__ascii; +static PyObject *__pyx_n_s__default; +static PyObject *__pyx_n_s__disable; +static PyObject *__pyx_n_s__dumps; +static PyObject *__pyx_n_s__enable; +static PyObject *__pyx_n_s__encode; +static PyObject *__pyx_n_s__encoding; +static PyObject *__pyx_n_s__file_like; +static PyObject *__pyx_n_s__gc; +static PyObject *__pyx_n_s__list_hook; +static PyObject *__pyx_n_s__loads; +static PyObject *__pyx_n_s__o; +static PyObject *__pyx_n_s__object_hook; +static PyObject *__pyx_n_s__pack; +static PyObject *__pyx_n_s__packb; +static PyObject *__pyx_n_s__packed; +static PyObject *__pyx_n_s__packs; +static PyObject *__pyx_n_s__read; +static PyObject *__pyx_n_s__read_size; +static PyObject *__pyx_n_s__stream; +static PyObject *__pyx_n_s__strict; +static PyObject *__pyx_n_s__unicode_errors; +static PyObject *__pyx_n_s__unpack; +static PyObject *__pyx_n_s__unpackb; +static PyObject *__pyx_n_s__unpacks; +static PyObject *__pyx_n_s__use_list; +static PyObject *__pyx_n_s__write; +static PyObject *__pyx_int_0; +static int __pyx_k_8; +static PyObject *__pyx_k_tuple_2; +static PyObject *__pyx_k_tuple_5; +static PyObject *__pyx_k_tuple_6; +static PyObject *__pyx_k_tuple_7; +static PyObject *__pyx_k_tuple_10; +static PyObject *__pyx_k_tuple_12; +static PyObject *__pyx_k_tuple_14; +static PyObject *__pyx_k_tuple_15; +static PyObject *__pyx_k_tuple_17; +static PyObject *__pyx_k_tuple_19; +static PyObject *__pyx_k_tuple_21; +static PyObject *__pyx_k_tuple_22; +static PyObject *__pyx_k_tuple_23; +static PyObject *__pyx_k_tuple_24; +static PyObject *__pyx_k_tuple_25; +static PyObject *__pyx_k_tuple_26; +static PyObject *__pyx_k_tuple_28; +static PyObject *__pyx_k_tuple_30; +static PyObject *__pyx_k_tuple_32; + +/* "msgpack/_msgpack.pyx":53 + * cdef char *unicode_errors + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * cdef int buf_size = 1024*1024 + * self.pk.buf = malloc(buf_size); + */ + +static int __pyx_pf_7msgpack_8_msgpack_6Packer___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pf_7msgpack_8_msgpack_6Packer___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_v_buf_size; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__"); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + + /* "msgpack/_msgpack.pyx":54 + * + * def __cinit__(self): + * cdef int buf_size = 1024*1024 # <<<<<<<<<<<<<< + * self.pk.buf = malloc(buf_size); + * if self.pk.buf == NULL: + */ + __pyx_v_buf_size = 1048576; + + /* "msgpack/_msgpack.pyx":55 + * def __cinit__(self): + * cdef int buf_size = 1024*1024 + * self.pk.buf = malloc(buf_size); # <<<<<<<<<<<<<< + * if self.pk.buf == NULL: + * raise MemoryError("Unable to allocate internal buffer.") + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->pk.buf = ((char *)malloc(__pyx_v_buf_size)); + + /* "msgpack/_msgpack.pyx":56 + * cdef int buf_size = 1024*1024 + * self.pk.buf = malloc(buf_size); + * if self.pk.buf == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("Unable to allocate internal buffer.") + * self.pk.buf_size = buf_size + */ + __pyx_t_1 = (((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->pk.buf == NULL); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":57 + * self.pk.buf = malloc(buf_size); + * if self.pk.buf == NULL: + * raise MemoryError("Unable to allocate internal buffer.") # <<<<<<<<<<<<<< + * self.pk.buf_size = buf_size + * self.pk.length = 0 + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "msgpack/_msgpack.pyx":58 + * if self.pk.buf == NULL: + * raise MemoryError("Unable to allocate internal buffer.") + * self.pk.buf_size = buf_size # <<<<<<<<<<<<<< + * self.pk.length = 0 + * + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->pk.buf_size = __pyx_v_buf_size; + + /* "msgpack/_msgpack.pyx":59 + * raise MemoryError("Unable to allocate internal buffer.") + * self.pk.buf_size = buf_size + * self.pk.length = 0 # <<<<<<<<<<<<<< + * + * def __init__(self, default=None, encoding='utf-8', unicode_errors='strict'): + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->pk.length = 0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("msgpack._msgpack.Packer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":61 + * self.pk.length = 0 + * + * def __init__(self, default=None, encoding='utf-8', unicode_errors='strict'): # <<<<<<<<<<<<<< + * if default is not None: + * if not PyCallable_Check(default): + */ + +static int __pyx_pf_7msgpack_8_msgpack_6Packer_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pf_7msgpack_8_msgpack_6Packer_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_default = 0; + PyObject *__pyx_v_encoding = 0; + PyObject *__pyx_v_unicode_errors = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__default,&__pyx_n_s__encoding,&__pyx_n_s__unicode_errors,0}; + __Pyx_RefNannySetupContext("__init__"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[3] = {0,0,0}; + values[0] = ((PyObject *)Py_None); + values[1] = ((PyObject *)__pyx_kp_s_3); + values[2] = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + 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: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__default); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__encoding); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__unicode_errors); + if (value) { values[2] = 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 = 61; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_default = values[0]; + __pyx_v_encoding = values[1]; + __pyx_v_unicode_errors = values[2]; + } else { + __pyx_v_default = ((PyObject *)Py_None); + __pyx_v_encoding = ((PyObject *)__pyx_kp_s_3); + __pyx_v_unicode_errors = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 3: __pyx_v_unicode_errors = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: __pyx_v_encoding = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: __pyx_v_default = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack._msgpack.Packer.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + + /* "msgpack/_msgpack.pyx":62 + * + * def __init__(self, default=None, encoding='utf-8', unicode_errors='strict'): + * if default is not None: # <<<<<<<<<<<<<< + * if not PyCallable_Check(default): + * raise TypeError("default must be a callable.") + */ + __pyx_t_1 = (__pyx_v_default != Py_None); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":63 + * def __init__(self, default=None, encoding='utf-8', unicode_errors='strict'): + * if default is not None: + * if not PyCallable_Check(default): # <<<<<<<<<<<<<< + * raise TypeError("default must be a callable.") + * self._default = default + */ + __pyx_t_1 = (!PyCallable_Check(__pyx_v_default)); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":64 + * if default is not None: + * if not PyCallable_Check(default): + * raise TypeError("default must be a callable.") # <<<<<<<<<<<<<< + * self._default = default + * if encoding is None: + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_5), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L7; + } + __pyx_L7:; + goto __pyx_L6; + } + __pyx_L6:; + + /* "msgpack/_msgpack.pyx":65 + * if not PyCallable_Check(default): + * raise TypeError("default must be a callable.") + * self._default = default # <<<<<<<<<<<<<< + * if encoding is None: + * self.encoding = NULL + */ + __Pyx_INCREF(__pyx_v_default); + __Pyx_GIVEREF(__pyx_v_default); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_default); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_default); + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_default = __pyx_v_default; + + /* "msgpack/_msgpack.pyx":66 + * raise TypeError("default must be a callable.") + * self._default = default + * if encoding is None: # <<<<<<<<<<<<<< + * self.encoding = NULL + * self.unicode_errors = NULL + */ + __pyx_t_1 = (__pyx_v_encoding == Py_None); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":67 + * self._default = default + * if encoding is None: + * self.encoding = NULL # <<<<<<<<<<<<<< + * self.unicode_errors = NULL + * else: + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->encoding = NULL; + + /* "msgpack/_msgpack.pyx":68 + * if encoding is None: + * self.encoding = NULL + * self.unicode_errors = NULL # <<<<<<<<<<<<<< + * else: + * if isinstance(encoding, unicode): + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->unicode_errors = NULL; + goto __pyx_L8; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":70 + * self.unicode_errors = NULL + * else: + * if isinstance(encoding, unicode): # <<<<<<<<<<<<<< + * self._bencoding = encoding.encode('ascii') + * else: + */ + __pyx_t_2 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_encoding, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":71 + * else: + * if isinstance(encoding, unicode): + * self._bencoding = encoding.encode('ascii') # <<<<<<<<<<<<<< + * else: + * self._bencoding = encoding + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_encoding, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_6), NULL); 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_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_bencoding); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_bencoding); + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_bencoding = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L9; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":73 + * self._bencoding = encoding.encode('ascii') + * else: + * self._bencoding = encoding # <<<<<<<<<<<<<< + * self.encoding = PyBytes_AsString(self._bencoding) + * if isinstance(unicode_errors, unicode): + */ + __Pyx_INCREF(__pyx_v_encoding); + __Pyx_GIVEREF(__pyx_v_encoding); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_bencoding); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_bencoding); + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_bencoding = __pyx_v_encoding; + } + __pyx_L9:; + + /* "msgpack/_msgpack.pyx":74 + * else: + * self._bencoding = encoding + * self.encoding = PyBytes_AsString(self._bencoding) # <<<<<<<<<<<<<< + * if isinstance(unicode_errors, unicode): + * self._berrors = unicode_errors.encode('ascii') + */ + __pyx_t_3 = ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_bencoding; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = PyBytes_AsString(__pyx_t_3); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->encoding = __pyx_t_4; + + /* "msgpack/_msgpack.pyx":75 + * self._bencoding = encoding + * self.encoding = PyBytes_AsString(self._bencoding) + * if isinstance(unicode_errors, unicode): # <<<<<<<<<<<<<< + * self._berrors = unicode_errors.encode('ascii') + * else: + */ + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_unicode_errors, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":76 + * self.encoding = PyBytes_AsString(self._bencoding) + * if isinstance(unicode_errors, unicode): + * self._berrors = unicode_errors.encode('ascii') # <<<<<<<<<<<<<< + * else: + * self._berrors = unicode_errors + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_unicode_errors, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_berrors); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_berrors); + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_berrors = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L10; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":78 + * self._berrors = unicode_errors.encode('ascii') + * else: + * self._berrors = unicode_errors # <<<<<<<<<<<<<< + * self.unicode_errors = PyBytes_AsString(self._berrors) + * + */ + __Pyx_INCREF(__pyx_v_unicode_errors); + __Pyx_GIVEREF(__pyx_v_unicode_errors); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_berrors); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_berrors); + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_berrors = __pyx_v_unicode_errors; + } + __pyx_L10:; + + /* "msgpack/_msgpack.pyx":79 + * else: + * self._berrors = unicode_errors + * self.unicode_errors = PyBytes_AsString(self._berrors) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_t_2 = ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->_berrors; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_4 = PyBytes_AsString(__pyx_t_2); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->unicode_errors = __pyx_t_4; + } + __pyx_L8:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack._msgpack.Packer.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":81 + * self.unicode_errors = PyBytes_AsString(self._berrors) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.pk.buf); + * + */ + +static void __pyx_pf_7msgpack_8_msgpack_6Packer_2__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pf_7msgpack_8_msgpack_6Packer_2__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__"); + + /* "msgpack/_msgpack.pyx":82 + * + * def __dealloc__(self): + * free(self.pk.buf); # <<<<<<<<<<<<<< + * + * cdef int _pack(self, object o, int nest_limit=DEFAULT_RECURSE_LIMIT) except -1: + */ + free(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->pk.buf); + + __Pyx_RefNannyFinishContext(); +} + +/* "msgpack/_msgpack.pyx":84 + * free(self.pk.buf); + * + * cdef int _pack(self, object o, int nest_limit=DEFAULT_RECURSE_LIMIT) except -1: # <<<<<<<<<<<<<< + * cdef long long llval + * cdef unsigned long long ullval + */ + +static int __pyx_f_7msgpack_8_msgpack_6Packer__pack(struct __pyx_obj_7msgpack_8_msgpack_Packer *__pyx_v_self, PyObject *__pyx_v_o, struct __pyx_opt_args_7msgpack_8_msgpack_6Packer__pack *__pyx_optional_args) { + int __pyx_v_nest_limit = __pyx_k_8; + PY_LONG_LONG __pyx_v_llval; + unsigned PY_LONG_LONG __pyx_v_ullval; + long __pyx_v_longval; + double __pyx_v_fval; + char *__pyx_v_rawval; + int __pyx_v_ret; + PyObject *__pyx_v_d = 0; + PyObject *__pyx_v_k = NULL; + PyObject *__pyx_v_v = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + unsigned PY_LONG_LONG __pyx_t_3; + PY_LONG_LONG __pyx_t_4; + long __pyx_t_5; + double __pyx_t_6; + char *__pyx_t_7; + Py_ssize_t __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *(*__pyx_t_10)(PyObject *); + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *(*__pyx_t_14)(PyObject *); + int __pyx_t_15; + struct __pyx_opt_args_7msgpack_8_msgpack_6Packer__pack __pyx_t_16; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("_pack"); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_nest_limit = __pyx_optional_args->nest_limit; + } + } + __Pyx_INCREF(__pyx_v_o); + + /* "msgpack/_msgpack.pyx":93 + * cdef dict d + * + * if nest_limit < 0: # <<<<<<<<<<<<<< + * raise ValueError("Too deep.") + * + */ + __pyx_t_1 = (__pyx_v_nest_limit < 0); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":94 + * + * if nest_limit < 0: + * raise ValueError("Too deep.") # <<<<<<<<<<<<<< + * + * if o is None: + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "msgpack/_msgpack.pyx":96 + * raise ValueError("Too deep.") + * + * if o is None: # <<<<<<<<<<<<<< + * ret = msgpack_pack_nil(&self.pk) + * elif isinstance(o, bool): + */ + __pyx_t_1 = (__pyx_v_o == Py_None); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":97 + * + * if o is None: + * ret = msgpack_pack_nil(&self.pk) # <<<<<<<<<<<<<< + * elif isinstance(o, bool): + * if o: + */ + __pyx_v_ret = msgpack_pack_nil((&__pyx_v_self->pk)); + goto __pyx_L4; + } + + /* "msgpack/_msgpack.pyx":98 + * if o is None: + * ret = msgpack_pack_nil(&self.pk) + * elif isinstance(o, bool): # <<<<<<<<<<<<<< + * if o: + * ret = msgpack_pack_true(&self.pk) + */ + __pyx_t_2 = ((PyObject *)((PyObject*)__pyx_ptype_7cpython_4bool_bool)); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_o, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":99 + * ret = msgpack_pack_nil(&self.pk) + * elif isinstance(o, bool): + * if o: # <<<<<<<<<<<<<< + * ret = msgpack_pack_true(&self.pk) + * else: + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_o); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":100 + * elif isinstance(o, bool): + * if o: + * ret = msgpack_pack_true(&self.pk) # <<<<<<<<<<<<<< + * else: + * ret = msgpack_pack_false(&self.pk) + */ + __pyx_v_ret = msgpack_pack_true((&__pyx_v_self->pk)); + goto __pyx_L5; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":102 + * ret = msgpack_pack_true(&self.pk) + * else: + * ret = msgpack_pack_false(&self.pk) # <<<<<<<<<<<<<< + * elif PyLong_Check(o): + * if o > 0: + */ + __pyx_v_ret = msgpack_pack_false((&__pyx_v_self->pk)); + } + __pyx_L5:; + goto __pyx_L4; + } + + /* "msgpack/_msgpack.pyx":103 + * else: + * ret = msgpack_pack_false(&self.pk) + * elif PyLong_Check(o): # <<<<<<<<<<<<<< + * if o > 0: + * ullval = o + */ + __pyx_t_1 = PyLong_Check(__pyx_v_o); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":104 + * ret = msgpack_pack_false(&self.pk) + * elif PyLong_Check(o): + * if o > 0: # <<<<<<<<<<<<<< + * ullval = o + * ret = msgpack_pack_unsigned_long_long(&self.pk, ullval) + */ + __pyx_t_2 = PyObject_RichCompare(__pyx_v_o, __pyx_int_0, Py_GT); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":105 + * elif PyLong_Check(o): + * if o > 0: + * ullval = o # <<<<<<<<<<<<<< + * ret = msgpack_pack_unsigned_long_long(&self.pk, ullval) + * else: + */ + __pyx_t_3 = __Pyx_PyInt_AsUnsignedLongLong(__pyx_v_o); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ullval = __pyx_t_3; + + /* "msgpack/_msgpack.pyx":106 + * if o > 0: + * ullval = o + * ret = msgpack_pack_unsigned_long_long(&self.pk, ullval) # <<<<<<<<<<<<<< + * else: + * llval = o + */ + __pyx_v_ret = msgpack_pack_unsigned_long_long((&__pyx_v_self->pk), __pyx_v_ullval); + goto __pyx_L6; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":108 + * ret = msgpack_pack_unsigned_long_long(&self.pk, ullval) + * else: + * llval = o # <<<<<<<<<<<<<< + * ret = msgpack_pack_long_long(&self.pk, llval) + * elif PyInt_Check(o): + */ + __pyx_t_4 = __Pyx_PyInt_AsLongLong(__pyx_v_o); if (unlikely((__pyx_t_4 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_llval = __pyx_t_4; + + /* "msgpack/_msgpack.pyx":109 + * else: + * llval = o + * ret = msgpack_pack_long_long(&self.pk, llval) # <<<<<<<<<<<<<< + * elif PyInt_Check(o): + * longval = o + */ + __pyx_v_ret = msgpack_pack_long_long((&__pyx_v_self->pk), __pyx_v_llval); + } + __pyx_L6:; + goto __pyx_L4; + } + + /* "msgpack/_msgpack.pyx":110 + * llval = o + * ret = msgpack_pack_long_long(&self.pk, llval) + * elif PyInt_Check(o): # <<<<<<<<<<<<<< + * longval = o + * ret = msgpack_pack_long(&self.pk, longval) + */ + __pyx_t_1 = PyInt_Check(__pyx_v_o); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":111 + * ret = msgpack_pack_long_long(&self.pk, llval) + * elif PyInt_Check(o): + * longval = o # <<<<<<<<<<<<<< + * ret = msgpack_pack_long(&self.pk, longval) + * elif PyFloat_Check(o): + */ + __pyx_t_5 = __Pyx_PyInt_AsLong(__pyx_v_o); if (unlikely((__pyx_t_5 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_longval = __pyx_t_5; + + /* "msgpack/_msgpack.pyx":112 + * elif PyInt_Check(o): + * longval = o + * ret = msgpack_pack_long(&self.pk, longval) # <<<<<<<<<<<<<< + * elif PyFloat_Check(o): + * fval = o + */ + __pyx_v_ret = msgpack_pack_long((&__pyx_v_self->pk), __pyx_v_longval); + goto __pyx_L4; + } + + /* "msgpack/_msgpack.pyx":113 + * longval = o + * ret = msgpack_pack_long(&self.pk, longval) + * elif PyFloat_Check(o): # <<<<<<<<<<<<<< + * fval = o + * ret = msgpack_pack_double(&self.pk, fval) + */ + __pyx_t_1 = PyFloat_Check(__pyx_v_o); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":114 + * ret = msgpack_pack_long(&self.pk, longval) + * elif PyFloat_Check(o): + * fval = o # <<<<<<<<<<<<<< + * ret = msgpack_pack_double(&self.pk, fval) + * elif PyBytes_Check(o): + */ + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_v_o); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_fval = __pyx_t_6; + + /* "msgpack/_msgpack.pyx":115 + * elif PyFloat_Check(o): + * fval = o + * ret = msgpack_pack_double(&self.pk, fval) # <<<<<<<<<<<<<< + * elif PyBytes_Check(o): + * rawval = o + */ + __pyx_v_ret = msgpack_pack_double((&__pyx_v_self->pk), __pyx_v_fval); + goto __pyx_L4; + } + + /* "msgpack/_msgpack.pyx":116 + * fval = o + * ret = msgpack_pack_double(&self.pk, fval) + * elif PyBytes_Check(o): # <<<<<<<<<<<<<< + * rawval = o + * ret = msgpack_pack_raw(&self.pk, len(o)) + */ + __pyx_t_1 = PyBytes_Check(__pyx_v_o); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":117 + * ret = msgpack_pack_double(&self.pk, fval) + * elif PyBytes_Check(o): + * rawval = o # <<<<<<<<<<<<<< + * ret = msgpack_pack_raw(&self.pk, len(o)) + * if ret == 0: + */ + __pyx_t_7 = PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_rawval = __pyx_t_7; + + /* "msgpack/_msgpack.pyx":118 + * elif PyBytes_Check(o): + * rawval = o + * ret = msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< + * if ret == 0: + * ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) + */ + __pyx_t_8 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_8); + + /* "msgpack/_msgpack.pyx":119 + * rawval = 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): + */ + __pyx_t_1 = (__pyx_v_ret == 0); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":120 + * 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): + * if not self.encoding: + */ + __pyx_t_8 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_8); + goto __pyx_L7; + } + __pyx_L7:; + goto __pyx_L4; + } + + /* "msgpack/_msgpack.pyx":121 + * if ret == 0: + * ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif PyUnicode_Check(o): # <<<<<<<<<<<<<< + * if not self.encoding: + * raise TypeError("Can't encode utf-8 no encoding is specified") + */ + __pyx_t_1 = PyUnicode_Check(__pyx_v_o); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":122 + * ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif PyUnicode_Check(o): + * if not self.encoding: # <<<<<<<<<<<<<< + * raise TypeError("Can't encode utf-8 no encoding is specified") + * o = PyUnicode_AsEncodedString(o, self.encoding, self.unicode_errors) + */ + __pyx_t_1 = (!(__pyx_v_self->encoding != 0)); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":123 + * elif PyUnicode_Check(o): + * if not self.encoding: + * raise TypeError("Can't encode utf-8 no encoding is specified") # <<<<<<<<<<<<<< + * o = PyUnicode_AsEncodedString(o, self.encoding, self.unicode_errors) + * rawval = o + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_12), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L8; + } + __pyx_L8:; + + /* "msgpack/_msgpack.pyx":124 + * if not self.encoding: + * raise TypeError("Can't encode utf-8 no encoding is specified") + * o = PyUnicode_AsEncodedString(o, self.encoding, self.unicode_errors) # <<<<<<<<<<<<<< + * rawval = o + * ret = msgpack_pack_raw(&self.pk, len(o)) + */ + __pyx_t_2 = PyUnicode_AsEncodedString(__pyx_v_o, __pyx_v_self->encoding, __pyx_v_self->unicode_errors); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_v_o); + __pyx_v_o = __pyx_t_2; + __pyx_t_2 = 0; + + /* "msgpack/_msgpack.pyx":125 + * raise TypeError("Can't encode utf-8 no encoding is specified") + * o = PyUnicode_AsEncodedString(o, self.encoding, self.unicode_errors) + * rawval = o # <<<<<<<<<<<<<< + * ret = msgpack_pack_raw(&self.pk, len(o)) + * if ret == 0: + */ + __pyx_t_7 = PyBytes_AsString(__pyx_v_o); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_rawval = __pyx_t_7; + + /* "msgpack/_msgpack.pyx":126 + * o = PyUnicode_AsEncodedString(o, self.encoding, self.unicode_errors) + * rawval = o + * ret = msgpack_pack_raw(&self.pk, len(o)) # <<<<<<<<<<<<<< + * if ret == 0: + * ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) + */ + __pyx_t_8 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = msgpack_pack_raw((&__pyx_v_self->pk), __pyx_t_8); + + /* "msgpack/_msgpack.pyx":127 + * rawval = o + * ret = msgpack_pack_raw(&self.pk, len(o)) + * if ret == 0: # <<<<<<<<<<<<<< + * ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif PyDict_Check(o): + */ + __pyx_t_1 = (__pyx_v_ret == 0); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":128 + * ret = msgpack_pack_raw(&self.pk, len(o)) + * if ret == 0: + * ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) # <<<<<<<<<<<<<< + * elif PyDict_Check(o): + * d = o + */ + __pyx_t_8 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = msgpack_pack_raw_body((&__pyx_v_self->pk), __pyx_v_rawval, __pyx_t_8); + goto __pyx_L9; + } + __pyx_L9:; + goto __pyx_L4; + } + + /* "msgpack/_msgpack.pyx":129 + * if ret == 0: + * ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif PyDict_Check(o): # <<<<<<<<<<<<<< + * d = o + * ret = msgpack_pack_map(&self.pk, len(d)) + */ + __pyx_t_1 = PyDict_Check(__pyx_v_o); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":130 + * ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) + * elif PyDict_Check(o): + * d = o # <<<<<<<<<<<<<< + * ret = msgpack_pack_map(&self.pk, len(d)) + * if ret == 0: + */ + if (!(likely(PyDict_CheckExact(__pyx_v_o))||((__pyx_v_o) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected dict, got %.200s", Py_TYPE(__pyx_v_o)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_o); + __pyx_v_d = ((PyObject*)__pyx_v_o); + + /* "msgpack/_msgpack.pyx":131 + * elif PyDict_Check(o): + * d = o + * ret = msgpack_pack_map(&self.pk, len(d)) # <<<<<<<<<<<<<< + * if ret == 0: + * for k,v in d.items(): + */ + if (unlikely(((PyObject *)__pyx_v_d) == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_8 = PyDict_Size(((PyObject *)__pyx_v_d)); + __pyx_v_ret = msgpack_pack_map((&__pyx_v_self->pk), __pyx_t_8); + + /* "msgpack/_msgpack.pyx":132 + * d = o + * ret = msgpack_pack_map(&self.pk, len(d)) + * if ret == 0: # <<<<<<<<<<<<<< + * for k,v in d.items(): + * ret = self._pack(k, nest_limit-1) + */ + __pyx_t_1 = (__pyx_v_ret == 0); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":133 + * ret = msgpack_pack_map(&self.pk, len(d)) + * if ret == 0: + * for k,v in d.items(): # <<<<<<<<<<<<<< + * ret = self._pack(k, nest_limit-1) + * if ret != 0: break + */ + if (unlikely(((PyObject *)__pyx_v_d) == Py_None)) { + PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "items"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_2 = PyDict_Items(__pyx_v_d); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_9 = __pyx_t_2; __Pyx_INCREF(__pyx_t_9); __pyx_t_8 = 0; + __pyx_t_10 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (PyList_CheckExact(__pyx_t_9)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_9)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (PyTuple_CheckExact(__pyx_t_9)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_9)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_10(__pyx_t_9); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { + PyObject* sequence = __pyx_t_2; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) { + if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 2)) { + if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_11 = PyList_GET_ITEM(sequence, 0); + __pyx_t_12 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_13 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_14 = Py_TYPE(__pyx_t_13)->tp_iternext; + index = 0; __pyx_t_11 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_11)) goto __pyx_L13_unpacking_failed; + __Pyx_GOTREF(__pyx_t_11); + index = 1; __pyx_t_12 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_12)) goto __pyx_L13_unpacking_failed; + __Pyx_GOTREF(__pyx_t_12); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L14_unpacking_done; + __pyx_L13_unpacking_failed:; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_L14_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_k); + __pyx_v_k = __pyx_t_11; + __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_v_v); + __pyx_v_v = __pyx_t_12; + __pyx_t_12 = 0; + + /* "msgpack/_msgpack.pyx":134 + * if ret == 0: + * for k,v in d.items(): + * ret = self._pack(k, nest_limit-1) # <<<<<<<<<<<<<< + * if ret != 0: break + * ret = self._pack(v, nest_limit-1) + */ + __pyx_t_16.__pyx_n = 1; + __pyx_t_16.nest_limit = (__pyx_v_nest_limit - 1); + __pyx_t_15 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Packer *)__pyx_v_self->__pyx_vtab)->_pack(__pyx_v_self, __pyx_v_k, &__pyx_t_16); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = __pyx_t_15; + + /* "msgpack/_msgpack.pyx":135 + * for k,v in d.items(): + * ret = self._pack(k, nest_limit-1) + * if ret != 0: break # <<<<<<<<<<<<<< + * ret = self._pack(v, nest_limit-1) + * if ret != 0: break + */ + __pyx_t_1 = (__pyx_v_ret != 0); + if (__pyx_t_1) { + goto __pyx_L12_break; + goto __pyx_L15; + } + __pyx_L15:; + + /* "msgpack/_msgpack.pyx":136 + * ret = self._pack(k, nest_limit-1) + * if ret != 0: break + * ret = self._pack(v, nest_limit-1) # <<<<<<<<<<<<<< + * if ret != 0: break + * elif PySequence_Check(o): + */ + __pyx_t_16.__pyx_n = 1; + __pyx_t_16.nest_limit = (__pyx_v_nest_limit - 1); + __pyx_t_15 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Packer *)__pyx_v_self->__pyx_vtab)->_pack(__pyx_v_self, __pyx_v_v, &__pyx_t_16); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = __pyx_t_15; + + /* "msgpack/_msgpack.pyx":137 + * if ret != 0: break + * ret = self._pack(v, nest_limit-1) + * if ret != 0: break # <<<<<<<<<<<<<< + * elif PySequence_Check(o): + * ret = msgpack_pack_array(&self.pk, len(o)) + */ + __pyx_t_1 = (__pyx_v_ret != 0); + if (__pyx_t_1) { + goto __pyx_L12_break; + goto __pyx_L16; + } + __pyx_L16:; + } + __pyx_L12_break:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L10; + } + __pyx_L10:; + goto __pyx_L4; + } + + /* "msgpack/_msgpack.pyx":138 + * ret = self._pack(v, nest_limit-1) + * if ret != 0: break + * elif PySequence_Check(o): # <<<<<<<<<<<<<< + * ret = msgpack_pack_array(&self.pk, len(o)) + * if ret == 0: + */ + __pyx_t_1 = PySequence_Check(__pyx_v_o); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":139 + * if ret != 0: break + * elif PySequence_Check(o): + * ret = msgpack_pack_array(&self.pk, len(o)) # <<<<<<<<<<<<<< + * if ret == 0: + * for v in o: + */ + __pyx_t_8 = PyObject_Length(__pyx_v_o); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = msgpack_pack_array((&__pyx_v_self->pk), __pyx_t_8); + + /* "msgpack/_msgpack.pyx":140 + * elif PySequence_Check(o): + * ret = msgpack_pack_array(&self.pk, len(o)) + * if ret == 0: # <<<<<<<<<<<<<< + * for v in o: + * ret = self._pack(v, nest_limit-1) + */ + __pyx_t_1 = (__pyx_v_ret == 0); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":141 + * ret = msgpack_pack_array(&self.pk, len(o)) + * if ret == 0: + * for v in o: # <<<<<<<<<<<<<< + * ret = self._pack(v, nest_limit-1) + * if ret != 0: break + */ + if (PyList_CheckExact(__pyx_v_o) || PyTuple_CheckExact(__pyx_v_o)) { + __pyx_t_9 = __pyx_v_o; __Pyx_INCREF(__pyx_t_9); __pyx_t_8 = 0; + __pyx_t_10 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext; + } + for (;;) { + if (PyList_CheckExact(__pyx_t_9)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_9)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (PyTuple_CheckExact(__pyx_t_9)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_9)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_10(__pyx_t_9); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_v); + __pyx_v_v = __pyx_t_2; + __pyx_t_2 = 0; + + /* "msgpack/_msgpack.pyx":142 + * if ret == 0: + * for v in o: + * ret = self._pack(v, nest_limit-1) # <<<<<<<<<<<<<< + * if ret != 0: break + * elif self._default: + */ + __pyx_t_16.__pyx_n = 1; + __pyx_t_16.nest_limit = (__pyx_v_nest_limit - 1); + __pyx_t_15 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Packer *)__pyx_v_self->__pyx_vtab)->_pack(__pyx_v_self, __pyx_v_v, &__pyx_t_16); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = __pyx_t_15; + + /* "msgpack/_msgpack.pyx":143 + * for v in o: + * ret = self._pack(v, nest_limit-1) + * if ret != 0: break # <<<<<<<<<<<<<< + * elif self._default: + * o = self._default(o) + */ + __pyx_t_1 = (__pyx_v_ret != 0); + if (__pyx_t_1) { + goto __pyx_L19_break; + goto __pyx_L20; + } + __pyx_L20:; + } + __pyx_L19_break:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L17; + } + __pyx_L17:; + goto __pyx_L4; + } + + /* "msgpack/_msgpack.pyx":144 + * ret = self._pack(v, nest_limit-1) + * if ret != 0: break + * elif self._default: # <<<<<<<<<<<<<< + * o = self._default(o) + * ret = self._pack(o, nest_limit-1) + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->_default); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":145 + * if ret != 0: break + * elif self._default: + * o = self._default(o) # <<<<<<<<<<<<<< + * ret = self._pack(o, nest_limit-1) + * else: + */ + __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_INCREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + __pyx_t_2 = PyObject_Call(__pyx_v_self->_default, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_v_o); + __pyx_v_o = __pyx_t_2; + __pyx_t_2 = 0; + + /* "msgpack/_msgpack.pyx":146 + * elif self._default: + * o = self._default(o) + * ret = self._pack(o, nest_limit-1) # <<<<<<<<<<<<<< + * else: + * raise TypeError("can't serialize %r" % (o,)) + */ + __pyx_t_16.__pyx_n = 1; + __pyx_t_16.nest_limit = (__pyx_v_nest_limit - 1); + __pyx_t_15 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Packer *)__pyx_v_self->__pyx_vtab)->_pack(__pyx_v_self, __pyx_v_o, &__pyx_t_16); if (unlikely(__pyx_t_15 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = __pyx_t_15; + goto __pyx_L4; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":148 + * ret = self._pack(o, nest_limit-1) + * else: + * raise TypeError("can't serialize %r" % (o,)) # <<<<<<<<<<<<<< + * return ret + * + */ + __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)); + __Pyx_INCREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_13), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_9)); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __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, ((PyObject *)__pyx_t_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); + __pyx_t_9 = 0; + __pyx_t_9 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_9, 0, 0, 0); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L4:; + + /* "msgpack/_msgpack.pyx":149 + * else: + * raise TypeError("can't serialize %r" % (o,)) + * return ret # <<<<<<<<<<<<<< + * + * def pack(self, object obj): + */ + __pyx_r = __pyx_v_ret; + goto __pyx_L0; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_AddTraceback("msgpack._msgpack.Packer._pack", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_d); + __Pyx_XDECREF(__pyx_v_k); + __Pyx_XDECREF(__pyx_v_v); + __Pyx_XDECREF(__pyx_v_o); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":151 + * return ret + * + * def pack(self, object obj): # <<<<<<<<<<<<<< + * cdef int ret + * ret = self._pack(obj, DEFAULT_RECURSE_LIMIT) + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_6Packer_3pack(PyObject *__pyx_v_self, PyObject *__pyx_v_obj); /*proto*/ +static PyObject *__pyx_pf_7msgpack_8_msgpack_6Packer_3pack(PyObject *__pyx_v_self, PyObject *__pyx_v_obj) { + int __pyx_v_ret; + PyObject *__pyx_v_buf = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + struct __pyx_opt_args_7msgpack_8_msgpack_6Packer__pack __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("pack"); + + /* "msgpack/_msgpack.pyx":153 + * def pack(self, object obj): + * cdef int ret + * ret = self._pack(obj, DEFAULT_RECURSE_LIMIT) # <<<<<<<<<<<<<< + * if ret: + * raise TypeError + */ + __pyx_t_2.__pyx_n = 1; + __pyx_t_2.nest_limit = __pyx_v_7msgpack_8_msgpack_DEFAULT_RECURSE_LIMIT; + __pyx_t_1 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Packer *)((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->__pyx_vtab)->_pack(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self), __pyx_v_obj, &__pyx_t_2); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = __pyx_t_1; + + /* "msgpack/_msgpack.pyx":154 + * cdef int ret + * ret = self._pack(obj, DEFAULT_RECURSE_LIMIT) + * if ret: # <<<<<<<<<<<<<< + * raise TypeError + * buf = PyBytes_FromStringAndSize(self.pk.buf, self.pk.length) + */ + if (__pyx_v_ret) { + + /* "msgpack/_msgpack.pyx":155 + * ret = self._pack(obj, DEFAULT_RECURSE_LIMIT) + * if ret: + * raise TypeError # <<<<<<<<<<<<<< + * buf = PyBytes_FromStringAndSize(self.pk.buf, self.pk.length) + * self.pk.length = 0 + */ + __Pyx_Raise(__pyx_builtin_TypeError, 0, 0, 0); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "msgpack/_msgpack.pyx":156 + * if ret: + * raise TypeError + * buf = PyBytes_FromStringAndSize(self.pk.buf, self.pk.length) # <<<<<<<<<<<<<< + * self.pk.length = 0 + * return buf + */ + __pyx_t_3 = ((PyObject *)PyBytes_FromStringAndSize(((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->pk.buf, ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->pk.length)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_v_buf = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + + /* "msgpack/_msgpack.pyx":157 + * raise TypeError + * buf = PyBytes_FromStringAndSize(self.pk.buf, self.pk.length) + * self.pk.length = 0 # <<<<<<<<<<<<<< + * return buf + * + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)__pyx_v_self)->pk.length = 0; + + /* "msgpack/_msgpack.pyx":158 + * buf = PyBytes_FromStringAndSize(self.pk.buf, self.pk.length) + * self.pk.length = 0 + * return buf # <<<<<<<<<<<<<< + * + * + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_buf)); + __pyx_r = ((PyObject *)__pyx_v_buf); + 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._msgpack.Packer.pack", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_buf); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":161 + * + * + * def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors='strict'): # <<<<<<<<<<<<<< + * """pack an object `o` and write it to stream).""" + * packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7msgpack_8_msgpack_pack[] = "pack an object `o` and write it to stream)."; +static PyMethodDef __pyx_mdef_7msgpack_8_msgpack_pack = {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_8_msgpack_pack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7msgpack_8_msgpack_pack)}; +static PyObject *__pyx_pf_7msgpack_8_msgpack_pack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_o = 0; + PyObject *__pyx_v_stream = 0; + PyObject *__pyx_v_default = 0; + PyObject *__pyx_v_encoding = 0; + PyObject *__pyx_v_unicode_errors = 0; + PyObject *__pyx_v_packer = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__o,&__pyx_n_s__stream,&__pyx_n_s__default,&__pyx_n_s__encoding,&__pyx_n_s__unicode_errors,0}; + __Pyx_RefNannySetupContext("pack"); + __pyx_self = __pyx_self; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[5] = {0,0,0,0,0}; + values[2] = ((PyObject *)Py_None); + values[3] = ((PyObject *)__pyx_kp_s_3); + values[4] = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + 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_n_s__o); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__stream); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("pack", 0, 2, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__default); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__encoding); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__unicode_errors); + if (value) { values[4] = 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 = 161; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_o = values[0]; + __pyx_v_stream = values[1]; + __pyx_v_default = values[2]; + __pyx_v_encoding = values[3]; + __pyx_v_unicode_errors = values[4]; + } else { + __pyx_v_default = ((PyObject *)Py_None); + __pyx_v_encoding = ((PyObject *)__pyx_kp_s_3); + __pyx_v_unicode_errors = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: + __pyx_v_unicode_errors = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: + __pyx_v_encoding = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: + __pyx_v_default = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: + __pyx_v_stream = PyTuple_GET_ITEM(__pyx_args, 1); + __pyx_v_o = 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, 2, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack._msgpack.pack", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + + /* "msgpack/_msgpack.pyx":163 + * def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors='strict'): + * """pack an object `o` and write it to stream).""" + * packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) # <<<<<<<<<<<<<< + * stream.write(packer.pack(o)) + * + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__default), __pyx_v_default) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), __pyx_v_encoding) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__unicode_errors), __pyx_v_unicode_errors) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyEval_CallObjectWithKeywords(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_8_msgpack_Packer)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_packer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "msgpack/_msgpack.pyx":164 + * """pack an object `o` and write it to stream).""" + * packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) + * stream.write(packer.pack(o)) # <<<<<<<<<<<<<< + * + * def packb(object o, default=None, encoding='utf-8', unicode_errors='strict'): + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_stream, __pyx_n_s__write); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_GetAttr(__pyx_v_packer, __pyx_n_s__pack); 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_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __Pyx_INCREF(__pyx_v_o); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o); + __Pyx_GIVEREF(__pyx_v_o); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; + __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 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_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("msgpack._msgpack.pack", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_packer); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":166 + * stream.write(packer.pack(o)) + * + * def packb(object o, default=None, encoding='utf-8', unicode_errors='strict'): # <<<<<<<<<<<<<< + * """pack o and return packed bytes.""" + * packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_1packb(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7msgpack_8_msgpack_1packb[] = "pack o and return packed bytes."; +static PyMethodDef __pyx_mdef_7msgpack_8_msgpack_1packb = {__Pyx_NAMESTR("packb"), (PyCFunction)__pyx_pf_7msgpack_8_msgpack_1packb, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7msgpack_8_msgpack_1packb)}; +static PyObject *__pyx_pf_7msgpack_8_msgpack_1packb(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_o = 0; + PyObject *__pyx_v_default = 0; + PyObject *__pyx_v_encoding = 0; + PyObject *__pyx_v_unicode_errors = 0; + PyObject *__pyx_v_packer = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__o,&__pyx_n_s__default,&__pyx_n_s__encoding,&__pyx_n_s__unicode_errors,0}; + __Pyx_RefNannySetupContext("packb"); + __pyx_self = __pyx_self; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[4] = {0,0,0,0}; + values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)__pyx_kp_s_3); + values[3] = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + 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_n_s__o); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__default); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__encoding); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__unicode_errors); + if (value) { values[3] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "packb") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_o = values[0]; + __pyx_v_default = values[1]; + __pyx_v_encoding = values[2]; + __pyx_v_unicode_errors = values[3]; + } else { + __pyx_v_default = ((PyObject *)Py_None); + __pyx_v_encoding = ((PyObject *)__pyx_kp_s_3); + __pyx_v_unicode_errors = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 4: __pyx_v_unicode_errors = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: __pyx_v_encoding = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: __pyx_v_default = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: __pyx_v_o = 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("packb", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack._msgpack.packb", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + + /* "msgpack/_msgpack.pyx":168 + * def packb(object o, default=None, encoding='utf-8', unicode_errors='strict'): + * """pack o and return packed bytes.""" + * packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) # <<<<<<<<<<<<<< + * return packer.pack(o) + * + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__default), __pyx_v_default) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), __pyx_v_encoding) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__unicode_errors), __pyx_v_unicode_errors) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyEval_CallObjectWithKeywords(((PyObject *)((PyObject*)__pyx_ptype_7msgpack_8_msgpack_Packer)), ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_packer = __pyx_t_2; + __pyx_t_2 = 0; + + /* "msgpack/_msgpack.pyx":169 + * """pack o and return packed bytes.""" + * packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) + * return packer.pack(o) # <<<<<<<<<<<<<< + * + * dumps = packs = packb + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = PyObject_GetAttr(__pyx_v_packer, __pyx_n_s__pack); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __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 = 169; __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 = 169; __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_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_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack._msgpack.packb", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_packer); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":194 + * + * + * def unpackb(object packed, object object_hook=None, object list_hook=None, bint use_list=0, encoding=None, unicode_errors="strict"): # <<<<<<<<<<<<<< + * """Unpack packed_bytes to object. Returns an unpacked object.""" + * cdef template_context ctx + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_2unpackb(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7msgpack_8_msgpack_2unpackb[] = "Unpack packed_bytes to object. Returns an unpacked object."; +static PyMethodDef __pyx_mdef_7msgpack_8_msgpack_2unpackb = {__Pyx_NAMESTR("unpackb"), (PyCFunction)__pyx_pf_7msgpack_8_msgpack_2unpackb, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7msgpack_8_msgpack_2unpackb)}; +static PyObject *__pyx_pf_7msgpack_8_msgpack_2unpackb(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_packed = 0; + PyObject *__pyx_v_object_hook = 0; + PyObject *__pyx_v_list_hook = 0; + int __pyx_v_use_list; + PyObject *__pyx_v_encoding = 0; + PyObject *__pyx_v_unicode_errors = 0; + template_context __pyx_v_ctx; + size_t __pyx_v_off; + int __pyx_v_ret; + char *__pyx_v_buf; + Py_ssize_t __pyx_v_buf_len; + void *__pyx_v_enc; + void *__pyx_v_err; + PyObject *__pyx_v_bencoding = NULL; + PyObject *__pyx_v_berrors = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + char *__pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__packed,&__pyx_n_s__object_hook,&__pyx_n_s__list_hook,&__pyx_n_s__use_list,&__pyx_n_s__encoding,&__pyx_n_s__unicode_errors,0}; + __Pyx_RefNannySetupContext("unpackb"); + __pyx_self = __pyx_self; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[6] = {0,0,0,0,0,0}; + values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); + values[4] = ((PyObject *)Py_None); + values[5] = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + 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_n_s__packed); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__object_hook); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__list_hook); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_list); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__encoding); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__unicode_errors); + if (value) { values[5] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "unpackb") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_packed = values[0]; + __pyx_v_object_hook = values[1]; + __pyx_v_list_hook = values[2]; + if (values[3]) { + __pyx_v_use_list = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_use_list == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_use_list = ((int)0); + } + __pyx_v_encoding = values[4]; + __pyx_v_unicode_errors = values[5]; + } else { + __pyx_v_object_hook = ((PyObject *)Py_None); + __pyx_v_list_hook = ((PyObject *)Py_None); + __pyx_v_use_list = ((int)0); + __pyx_v_encoding = ((PyObject *)Py_None); + __pyx_v_unicode_errors = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: __pyx_v_unicode_errors = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: __pyx_v_encoding = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: __pyx_v_use_list = __Pyx_PyObject_IsTrue(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_use_list == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + case 3: __pyx_v_list_hook = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: __pyx_v_object_hook = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: __pyx_v_packed = 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("unpackb", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack._msgpack.unpackb", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + + /* "msgpack/_msgpack.pyx":197 + * """Unpack packed_bytes to object. Returns an unpacked object.""" + * cdef template_context ctx + * cdef size_t off = 0 # <<<<<<<<<<<<<< + * cdef int ret + * + */ + __pyx_v_off = 0; + + /* "msgpack/_msgpack.pyx":202 + * cdef char* buf + * cdef Py_ssize_t buf_len + * PyObject_AsReadBuffer(packed, &buf, &buf_len) # <<<<<<<<<<<<<< + * + * if encoding is None: + */ + __pyx_t_1 = PyObject_AsReadBuffer(__pyx_v_packed, ((const void* *)(&__pyx_v_buf)), (&__pyx_v_buf_len)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "msgpack/_msgpack.pyx":204 + * PyObject_AsReadBuffer(packed, &buf, &buf_len) + * + * if encoding is None: # <<<<<<<<<<<<<< + * enc = NULL + * err = NULL + */ + __pyx_t_2 = (__pyx_v_encoding == Py_None); + if (__pyx_t_2) { + + /* "msgpack/_msgpack.pyx":205 + * + * if encoding is None: + * enc = NULL # <<<<<<<<<<<<<< + * err = NULL + * else: + */ + __pyx_v_enc = NULL; + + /* "msgpack/_msgpack.pyx":206 + * if encoding is None: + * enc = NULL + * err = NULL # <<<<<<<<<<<<<< + * else: + * if isinstance(encoding, unicode): + */ + __pyx_v_err = NULL; + goto __pyx_L6; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":208 + * err = NULL + * else: + * if isinstance(encoding, unicode): # <<<<<<<<<<<<<< + * bencoding = encoding.encode('ascii') + * else: + */ + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_encoding, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_2) { + + /* "msgpack/_msgpack.pyx":209 + * else: + * if isinstance(encoding, unicode): + * bencoding = encoding.encode('ascii') # <<<<<<<<<<<<<< + * else: + * bencoding = encoding + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_encoding, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_14), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_bencoding = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L7; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":211 + * bencoding = encoding.encode('ascii') + * else: + * bencoding = encoding # <<<<<<<<<<<<<< + * if isinstance(unicode_errors, unicode): + * berrors = unicode_errors.encode('ascii') + */ + __Pyx_INCREF(__pyx_v_encoding); + __pyx_v_bencoding = __pyx_v_encoding; + } + __pyx_L7:; + + /* "msgpack/_msgpack.pyx":212 + * else: + * bencoding = encoding + * if isinstance(unicode_errors, unicode): # <<<<<<<<<<<<<< + * berrors = unicode_errors.encode('ascii') + * else: + */ + __pyx_t_4 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_4); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_unicode_errors, __pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { + + /* "msgpack/_msgpack.pyx":213 + * bencoding = encoding + * if isinstance(unicode_errors, unicode): + * berrors = unicode_errors.encode('ascii') # <<<<<<<<<<<<<< + * else: + * berrors = unicode_errors + */ + __pyx_t_4 = PyObject_GetAttr(__pyx_v_unicode_errors, __pyx_n_s__encode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_berrors = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L8; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":215 + * berrors = unicode_errors.encode('ascii') + * else: + * berrors = unicode_errors # <<<<<<<<<<<<<< + * enc = PyBytes_AsString(bencoding) + * err = PyBytes_AsString(berrors) + */ + __Pyx_INCREF(__pyx_v_unicode_errors); + __pyx_v_berrors = __pyx_v_unicode_errors; + } + __pyx_L8:; + + /* "msgpack/_msgpack.pyx":216 + * else: + * berrors = unicode_errors + * enc = PyBytes_AsString(bencoding) # <<<<<<<<<<<<<< + * err = PyBytes_AsString(berrors) + * + */ + __pyx_t_5 = PyBytes_AsString(__pyx_v_bencoding); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_enc = __pyx_t_5; + + /* "msgpack/_msgpack.pyx":217 + * berrors = unicode_errors + * enc = PyBytes_AsString(bencoding) + * err = PyBytes_AsString(berrors) # <<<<<<<<<<<<<< + * + * template_init(&ctx) + */ + __pyx_t_5 = PyBytes_AsString(__pyx_v_berrors); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_err = __pyx_t_5; + } + __pyx_L6:; + + /* "msgpack/_msgpack.pyx":219 + * err = PyBytes_AsString(berrors) + * + * template_init(&ctx) # <<<<<<<<<<<<<< + * ctx.user.use_list = use_list + * ctx.user.object_hook = ctx.user.list_hook = NULL + */ + template_init((&__pyx_v_ctx)); + + /* "msgpack/_msgpack.pyx":220 + * + * template_init(&ctx) + * ctx.user.use_list = use_list # <<<<<<<<<<<<<< + * ctx.user.object_hook = ctx.user.list_hook = NULL + * ctx.user.encoding = enc + */ + __pyx_v_ctx.user.use_list = __pyx_v_use_list; + + /* "msgpack/_msgpack.pyx":221 + * template_init(&ctx) + * ctx.user.use_list = use_list + * ctx.user.object_hook = ctx.user.list_hook = NULL # <<<<<<<<<<<<<< + * ctx.user.encoding = enc + * ctx.user.unicode_errors = err + */ + __pyx_v_ctx.user.object_hook = NULL; + __pyx_v_ctx.user.list_hook = NULL; + + /* "msgpack/_msgpack.pyx":222 + * ctx.user.use_list = use_list + * ctx.user.object_hook = ctx.user.list_hook = NULL + * ctx.user.encoding = enc # <<<<<<<<<<<<<< + * ctx.user.unicode_errors = err + * if object_hook is not None: + */ + __pyx_v_ctx.user.encoding = __pyx_v_enc; + + /* "msgpack/_msgpack.pyx":223 + * ctx.user.object_hook = ctx.user.list_hook = NULL + * ctx.user.encoding = enc + * ctx.user.unicode_errors = err # <<<<<<<<<<<<<< + * if object_hook is not None: + * if not PyCallable_Check(object_hook): + */ + __pyx_v_ctx.user.unicode_errors = __pyx_v_err; + + /* "msgpack/_msgpack.pyx":224 + * ctx.user.encoding = enc + * ctx.user.unicode_errors = err + * if object_hook is not None: # <<<<<<<<<<<<<< + * if not PyCallable_Check(object_hook): + * raise TypeError("object_hook must be a callable.") + */ + __pyx_t_2 = (__pyx_v_object_hook != Py_None); + if (__pyx_t_2) { + + /* "msgpack/_msgpack.pyx":225 + * ctx.user.unicode_errors = err + * if object_hook is not None: + * if not PyCallable_Check(object_hook): # <<<<<<<<<<<<<< + * raise TypeError("object_hook must be a callable.") + * ctx.user.object_hook = object_hook + */ + __pyx_t_2 = (!PyCallable_Check(__pyx_v_object_hook)); + if (__pyx_t_2) { + + /* "msgpack/_msgpack.pyx":226 + * if object_hook is not None: + * if not PyCallable_Check(object_hook): + * raise TypeError("object_hook must be a callable.") # <<<<<<<<<<<<<< + * ctx.user.object_hook = object_hook + * if list_hook is not None: + */ + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L10; + } + __pyx_L10:; + + /* "msgpack/_msgpack.pyx":227 + * if not PyCallable_Check(object_hook): + * raise TypeError("object_hook must be a callable.") + * ctx.user.object_hook = object_hook # <<<<<<<<<<<<<< + * if list_hook is not None: + * if not PyCallable_Check(list_hook): + */ + __pyx_v_ctx.user.object_hook = ((PyObject *)__pyx_v_object_hook); + goto __pyx_L9; + } + __pyx_L9:; + + /* "msgpack/_msgpack.pyx":228 + * raise TypeError("object_hook must be a callable.") + * ctx.user.object_hook = object_hook + * if list_hook is not None: # <<<<<<<<<<<<<< + * if not PyCallable_Check(list_hook): + * raise TypeError("list_hook must be a callable.") + */ + __pyx_t_2 = (__pyx_v_list_hook != Py_None); + if (__pyx_t_2) { + + /* "msgpack/_msgpack.pyx":229 + * ctx.user.object_hook = object_hook + * if list_hook is not None: + * if not PyCallable_Check(list_hook): # <<<<<<<<<<<<<< + * raise TypeError("list_hook must be a callable.") + * ctx.user.list_hook = list_hook + */ + __pyx_t_2 = (!PyCallable_Check(__pyx_v_list_hook)); + if (__pyx_t_2) { + + /* "msgpack/_msgpack.pyx":230 + * if list_hook is not None: + * if not PyCallable_Check(list_hook): + * raise TypeError("list_hook must be a callable.") # <<<<<<<<<<<<<< + * ctx.user.list_hook = list_hook + * _gc_disable() + */ + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L12; + } + __pyx_L12:; + + /* "msgpack/_msgpack.pyx":231 + * if not PyCallable_Check(list_hook): + * raise TypeError("list_hook must be a callable.") + * ctx.user.list_hook = list_hook # <<<<<<<<<<<<<< + * _gc_disable() + * try: + */ + __pyx_v_ctx.user.list_hook = ((PyObject *)__pyx_v_list_hook); + goto __pyx_L11; + } + __pyx_L11:; + + /* "msgpack/_msgpack.pyx":232 + * raise TypeError("list_hook must be a callable.") + * ctx.user.list_hook = list_hook + * _gc_disable() # <<<<<<<<<<<<<< + * try: + * ret = template_execute(&ctx, buf, buf_len, &off) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s___gc_disable); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 232; __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 = 232; __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; + + /* "msgpack/_msgpack.pyx":233 + * ctx.user.list_hook = list_hook + * _gc_disable() + * try: # <<<<<<<<<<<<<< + * ret = template_execute(&ctx, buf, buf_len, &off) + * finally: + */ + /*try:*/ { + + /* "msgpack/_msgpack.pyx":234 + * _gc_disable() + * try: + * ret = template_execute(&ctx, buf, buf_len, &off) # <<<<<<<<<<<<<< + * finally: + * _gc_enable() + */ + __pyx_t_1 = template_execute((&__pyx_v_ctx), __pyx_v_buf, __pyx_v_buf_len, (&__pyx_v_off)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L14;} + __pyx_v_ret = __pyx_t_1; + } + + /* "msgpack/_msgpack.pyx":236 + * ret = template_execute(&ctx, buf, buf_len, &off) + * finally: + * _gc_enable() # <<<<<<<<<<<<<< + * if ret == 1: + * return template_data(&ctx) + */ + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L15; + __pyx_L14: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L15; + } + __pyx_L15:; + __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s___gc_enable); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L16_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L16_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L17; + __pyx_L16_error:; + if (__pyx_why == 4) { + Py_XDECREF(__pyx_exc_type); + Py_XDECREF(__pyx_exc_value); + Py_XDECREF(__pyx_exc_tb); + } + goto __pyx_L1_error; + __pyx_L17:; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } + + /* "msgpack/_msgpack.pyx":237 + * finally: + * _gc_enable() + * if ret == 1: # <<<<<<<<<<<<<< + * return template_data(&ctx) + * else: + */ + __pyx_t_2 = (__pyx_v_ret == 1); + if (__pyx_t_2) { + + /* "msgpack/_msgpack.pyx":238 + * _gc_enable() + * if ret == 1: + * return template_data(&ctx) # <<<<<<<<<<<<<< + * else: + * return None + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = template_data((&__pyx_v_ctx)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + goto __pyx_L18; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":240 + * return template_data(&ctx) + * else: + * return None # <<<<<<<<<<<<<< + * + * loads = unpacks = unpackb + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(Py_None); + __pyx_r = Py_None; + goto __pyx_L0; + } + __pyx_L18:; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("msgpack._msgpack.unpackb", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_bencoding); + __Pyx_XDECREF(__pyx_v_berrors); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":244 + * loads = unpacks = unpackb + * + * def unpack(object stream, object object_hook=None, object list_hook=None, bint use_list=0, encoding=None, unicode_errors="strict"): # <<<<<<<<<<<<<< + * """unpack an object from stream.""" + * return unpackb(stream.read(), use_list=use_list, + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_3unpack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7msgpack_8_msgpack_3unpack[] = "unpack an object from stream."; +static PyMethodDef __pyx_mdef_7msgpack_8_msgpack_3unpack = {__Pyx_NAMESTR("unpack"), (PyCFunction)__pyx_pf_7msgpack_8_msgpack_3unpack, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7msgpack_8_msgpack_3unpack)}; +static PyObject *__pyx_pf_7msgpack_8_msgpack_3unpack(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_stream = 0; + PyObject *__pyx_v_object_hook = 0; + PyObject *__pyx_v_list_hook = 0; + int __pyx_v_use_list; + PyObject *__pyx_v_encoding = 0; + PyObject *__pyx_v_unicode_errors = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__stream,&__pyx_n_s__object_hook,&__pyx_n_s__list_hook,&__pyx_n_s__use_list,&__pyx_n_s__encoding,&__pyx_n_s__unicode_errors,0}; + __Pyx_RefNannySetupContext("unpack"); + __pyx_self = __pyx_self; + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[6] = {0,0,0,0,0,0}; + values[1] = ((PyObject *)Py_None); + values[2] = ((PyObject *)Py_None); + values[4] = ((PyObject *)Py_None); + values[5] = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + 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_n_s__stream); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__object_hook); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__list_hook); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_list); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__encoding); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__unicode_errors); + if (value) { values[5] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "unpack") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_stream = values[0]; + __pyx_v_object_hook = values[1]; + __pyx_v_list_hook = values[2]; + if (values[3]) { + __pyx_v_use_list = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_use_list == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_use_list = ((int)0); + } + __pyx_v_encoding = values[4]; + __pyx_v_unicode_errors = values[5]; + } else { + __pyx_v_object_hook = ((PyObject *)Py_None); + __pyx_v_list_hook = ((PyObject *)Py_None); + __pyx_v_use_list = ((int)0); + __pyx_v_encoding = ((PyObject *)Py_None); + __pyx_v_unicode_errors = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: __pyx_v_unicode_errors = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: __pyx_v_encoding = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: __pyx_v_use_list = __Pyx_PyObject_IsTrue(PyTuple_GET_ITEM(__pyx_args, 3)); if (unlikely((__pyx_v_use_list == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + case 3: __pyx_v_list_hook = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: __pyx_v_object_hook = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: __pyx_v_stream = 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("unpack", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack._msgpack.unpack", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + + /* "msgpack/_msgpack.pyx":246 + * def unpack(object stream, object object_hook=None, object list_hook=None, bint use_list=0, encoding=None, unicode_errors="strict"): + * """unpack an object from stream.""" + * return unpackb(stream.read(), use_list=use_list, # <<<<<<<<<<<<<< + * object_hook=object_hook, list_hook=list_hook, encoding=encoding, unicode_errors=unicode_errors) + * + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__unpackb); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_v_stream, __pyx_n_s__read); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_use_list); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__use_list), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "msgpack/_msgpack.pyx":247 + * """unpack an object from stream.""" + * return unpackb(stream.read(), use_list=use_list, + * object_hook=object_hook, list_hook=list_hook, encoding=encoding, unicode_errors=unicode_errors) # <<<<<<<<<<<<<< + * + * cdef class Unpacker(object): + */ + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__object_hook), __pyx_v_object_hook) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__list_hook), __pyx_v_list_hook) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__encoding), __pyx_v_encoding) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__unicode_errors), __pyx_v_unicode_errors) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L0; + + __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_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("msgpack._msgpack.unpack", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":276 + * cdef char *unicode_errors + * + * def __cinit__(self): # <<<<<<<<<<<<<< + * self.buf = NULL + * + */ + +static int __pyx_pf_7msgpack_8_msgpack_8Unpacker___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pf_7msgpack_8_msgpack_8Unpacker___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__"); + if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) { + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;} + if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1; + + /* "msgpack/_msgpack.pyx":277 + * + * def __cinit__(self): + * self.buf = NULL # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->buf = NULL; + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":279 + * self.buf = NULL + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * free(self.buf); + * self.buf = NULL; + */ + +static void __pyx_pf_7msgpack_8_msgpack_8Unpacker_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pf_7msgpack_8_msgpack_8Unpacker_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__"); + + /* "msgpack/_msgpack.pyx":280 + * + * def __dealloc__(self): + * free(self.buf); # <<<<<<<<<<<<<< + * self.buf = NULL; + * + */ + free(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->buf); + + /* "msgpack/_msgpack.pyx":281 + * def __dealloc__(self): + * free(self.buf); + * self.buf = NULL; # <<<<<<<<<<<<<< + * + * def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=0, + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->buf = NULL; + + __Pyx_RefNannyFinishContext(); +} + +/* "msgpack/_msgpack.pyx":283 + * self.buf = NULL; + * + * def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=0, # <<<<<<<<<<<<<< + * object object_hook=None, object list_hook=None, + * encoding=None, unicode_errors='strict'): + */ + +static int __pyx_pf_7msgpack_8_msgpack_8Unpacker_2__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pf_7msgpack_8_msgpack_8Unpacker_2__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_file_like = 0; + Py_ssize_t __pyx_v_read_size; + int __pyx_v_use_list; + PyObject *__pyx_v_object_hook = 0; + PyObject *__pyx_v_list_hook = 0; + PyObject *__pyx_v_encoding = 0; + PyObject *__pyx_v_unicode_errors = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__file_like,&__pyx_n_s__read_size,&__pyx_n_s__use_list,&__pyx_n_s__object_hook,&__pyx_n_s__list_hook,&__pyx_n_s__encoding,&__pyx_n_s__unicode_errors,0}; + __Pyx_RefNannySetupContext("__init__"); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args = PyDict_Size(__pyx_kwds); + PyObject* values[7] = {0,0,0,0,0,0,0}; + values[0] = ((PyObject *)Py_None); + + /* "msgpack/_msgpack.pyx":284 + * + * def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=0, + * object object_hook=None, object list_hook=None, # <<<<<<<<<<<<<< + * encoding=None, unicode_errors='strict'): + * if read_size == 0: + */ + values[3] = ((PyObject *)Py_None); + values[4] = ((PyObject *)Py_None); + + /* "msgpack/_msgpack.pyx":285 + * def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=0, + * object object_hook=None, object list_hook=None, + * encoding=None, unicode_errors='strict'): # <<<<<<<<<<<<<< + * if read_size == 0: + * read_size = 1024*1024 + */ + values[5] = ((PyObject *)Py_None); + values[6] = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + 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: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__file_like); + if (value) { values[0] = value; kw_args--; } + } + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__read_size); + if (value) { values[1] = value; kw_args--; } + } + case 2: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__use_list); + if (value) { values[2] = value; kw_args--; } + } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__object_hook); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__list_hook); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__encoding); + if (value) { values[5] = value; kw_args--; } + } + case 6: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__unicode_errors); + if (value) { values[6] = 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 = 283; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + __pyx_v_file_like = values[0]; + if (values[1]) { + __pyx_v_read_size = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_read_size == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_read_size = ((Py_ssize_t)0); + } + if (values[2]) { + __pyx_v_use_list = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_use_list == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } else { + __pyx_v_use_list = ((int)0); + } + __pyx_v_object_hook = values[3]; + __pyx_v_list_hook = values[4]; + __pyx_v_encoding = values[5]; + __pyx_v_unicode_errors = values[6]; + } else { + + /* "msgpack/_msgpack.pyx":283 + * self.buf = NULL; + * + * def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=0, # <<<<<<<<<<<<<< + * object object_hook=None, object list_hook=None, + * encoding=None, unicode_errors='strict'): + */ + __pyx_v_file_like = ((PyObject *)Py_None); + __pyx_v_read_size = ((Py_ssize_t)0); + __pyx_v_use_list = ((int)0); + + /* "msgpack/_msgpack.pyx":284 + * + * def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=0, + * object object_hook=None, object list_hook=None, # <<<<<<<<<<<<<< + * encoding=None, unicode_errors='strict'): + * if read_size == 0: + */ + __pyx_v_object_hook = ((PyObject *)Py_None); + __pyx_v_list_hook = ((PyObject *)Py_None); + + /* "msgpack/_msgpack.pyx":285 + * def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=0, + * object object_hook=None, object list_hook=None, + * encoding=None, unicode_errors='strict'): # <<<<<<<<<<<<<< + * if read_size == 0: + * read_size = 1024*1024 + */ + __pyx_v_encoding = ((PyObject *)Py_None); + __pyx_v_unicode_errors = ((PyObject *)__pyx_n_s__strict); + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 7: __pyx_v_unicode_errors = PyTuple_GET_ITEM(__pyx_args, 6); + case 6: __pyx_v_encoding = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: __pyx_v_list_hook = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: __pyx_v_object_hook = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: __pyx_v_use_list = __Pyx_PyObject_IsTrue(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_use_list == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + case 2: __pyx_v_read_size = __Pyx_PyIndex_AsSsize_t(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_read_size == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + case 1: __pyx_v_file_like = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("msgpack._msgpack.Unpacker.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + + /* "msgpack/_msgpack.pyx":286 + * object object_hook=None, object list_hook=None, + * encoding=None, unicode_errors='strict'): + * if read_size == 0: # <<<<<<<<<<<<<< + * read_size = 1024*1024 + * self.use_list = use_list + */ + __pyx_t_1 = (__pyx_v_read_size == 0); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":287 + * encoding=None, unicode_errors='strict'): + * if read_size == 0: + * read_size = 1024*1024 # <<<<<<<<<<<<<< + * self.use_list = use_list + * self.file_like = file_like + */ + __pyx_v_read_size = 1048576; + goto __pyx_L6; + } + __pyx_L6:; + + /* "msgpack/_msgpack.pyx":288 + * if read_size == 0: + * read_size = 1024*1024 + * self.use_list = use_list # <<<<<<<<<<<<<< + * self.file_like = file_like + * if file_like: + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->use_list = __pyx_v_use_list; + + /* "msgpack/_msgpack.pyx":289 + * read_size = 1024*1024 + * self.use_list = use_list + * self.file_like = file_like # <<<<<<<<<<<<<< + * if file_like: + * self.file_like_read = file_like.read + */ + __Pyx_INCREF(__pyx_v_file_like); + __Pyx_GIVEREF(__pyx_v_file_like); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->file_like); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->file_like); + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->file_like = __pyx_v_file_like; + + /* "msgpack/_msgpack.pyx":290 + * self.use_list = use_list + * self.file_like = file_like + * if file_like: # <<<<<<<<<<<<<< + * self.file_like_read = file_like.read + * if not PyCallable_Check(self.file_like_read): + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_file_like); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":291 + * self.file_like = file_like + * if file_like: + * self.file_like_read = file_like.read # <<<<<<<<<<<<<< + * if not PyCallable_Check(self.file_like_read): + * raise ValueError("`file_like.read` must be a callable.") + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_file_like, __pyx_n_s__read); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->file_like_read); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->file_like_read); + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->file_like_read = __pyx_t_2; + __pyx_t_2 = 0; + + /* "msgpack/_msgpack.pyx":292 + * if file_like: + * self.file_like_read = file_like.read + * if not PyCallable_Check(self.file_like_read): # <<<<<<<<<<<<<< + * raise ValueError("`file_like.read` must be a callable.") + * self.read_size = read_size + */ + __pyx_t_2 = ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->file_like_read; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = (!PyCallable_Check(__pyx_t_2)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":293 + * self.file_like_read = file_like.read + * if not PyCallable_Check(self.file_like_read): + * raise ValueError("`file_like.read` must be a callable.") # <<<<<<<<<<<<<< + * self.read_size = read_size + * self.buf = malloc(read_size) + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L8; + } + __pyx_L8:; + goto __pyx_L7; + } + __pyx_L7:; + + /* "msgpack/_msgpack.pyx":294 + * if not PyCallable_Check(self.file_like_read): + * raise ValueError("`file_like.read` must be a callable.") + * self.read_size = read_size # <<<<<<<<<<<<<< + * self.buf = malloc(read_size) + * if self.buf == NULL: + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->read_size = __pyx_v_read_size; + + /* "msgpack/_msgpack.pyx":295 + * raise ValueError("`file_like.read` must be a callable.") + * self.read_size = read_size + * self.buf = malloc(read_size) # <<<<<<<<<<<<<< + * if self.buf == NULL: + * raise MemoryError("Unable to allocate internal buffer.") + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->buf = ((char *)malloc(__pyx_v_read_size)); + + /* "msgpack/_msgpack.pyx":296 + * self.read_size = read_size + * self.buf = malloc(read_size) + * if self.buf == NULL: # <<<<<<<<<<<<<< + * raise MemoryError("Unable to allocate internal buffer.") + * self.buf_size = read_size + */ + __pyx_t_1 = (((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->buf == NULL); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":297 + * self.buf = malloc(read_size) + * if self.buf == NULL: + * raise MemoryError("Unable to allocate internal buffer.") # <<<<<<<<<<<<<< + * self.buf_size = read_size + * self.buf_head = 0 + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L9; + } + __pyx_L9:; + + /* "msgpack/_msgpack.pyx":298 + * if self.buf == NULL: + * raise MemoryError("Unable to allocate internal buffer.") + * self.buf_size = read_size # <<<<<<<<<<<<<< + * self.buf_head = 0 + * self.buf_tail = 0 + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->buf_size = __pyx_v_read_size; + + /* "msgpack/_msgpack.pyx":299 + * raise MemoryError("Unable to allocate internal buffer.") + * self.buf_size = read_size + * self.buf_head = 0 # <<<<<<<<<<<<<< + * self.buf_tail = 0 + * template_init(&self.ctx) + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->buf_head = 0; + + /* "msgpack/_msgpack.pyx":300 + * self.buf_size = read_size + * self.buf_head = 0 + * self.buf_tail = 0 # <<<<<<<<<<<<<< + * template_init(&self.ctx) + * self.ctx.user.use_list = use_list + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->buf_tail = 0; + + /* "msgpack/_msgpack.pyx":301 + * self.buf_head = 0 + * self.buf_tail = 0 + * template_init(&self.ctx) # <<<<<<<<<<<<<< + * self.ctx.user.use_list = use_list + * self.ctx.user.object_hook = self.ctx.user.list_hook = NULL + */ + template_init((&((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx)); + + /* "msgpack/_msgpack.pyx":302 + * self.buf_tail = 0 + * template_init(&self.ctx) + * self.ctx.user.use_list = use_list # <<<<<<<<<<<<<< + * self.ctx.user.object_hook = self.ctx.user.list_hook = NULL + * if object_hook is not None: + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx.user.use_list = __pyx_v_use_list; + + /* "msgpack/_msgpack.pyx":303 + * template_init(&self.ctx) + * self.ctx.user.use_list = use_list + * self.ctx.user.object_hook = self.ctx.user.list_hook = NULL # <<<<<<<<<<<<<< + * if object_hook is not None: + * if not PyCallable_Check(object_hook): + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx.user.object_hook = ((PyObject *)NULL); + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx.user.list_hook = ((PyObject *)NULL); + + /* "msgpack/_msgpack.pyx":304 + * self.ctx.user.use_list = use_list + * self.ctx.user.object_hook = self.ctx.user.list_hook = NULL + * if object_hook is not None: # <<<<<<<<<<<<<< + * if not PyCallable_Check(object_hook): + * raise TypeError("object_hook must be a callable.") + */ + __pyx_t_1 = (__pyx_v_object_hook != Py_None); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":305 + * self.ctx.user.object_hook = self.ctx.user.list_hook = NULL + * if object_hook is not None: + * if not PyCallable_Check(object_hook): # <<<<<<<<<<<<<< + * raise TypeError("object_hook must be a callable.") + * self.ctx.user.object_hook = object_hook + */ + __pyx_t_1 = (!PyCallable_Check(__pyx_v_object_hook)); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":306 + * if object_hook is not None: + * if not PyCallable_Check(object_hook): + * raise TypeError("object_hook must be a callable.") # <<<<<<<<<<<<<< + * self.ctx.user.object_hook = object_hook + * if list_hook is not None: + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L11; + } + __pyx_L11:; + + /* "msgpack/_msgpack.pyx":307 + * if not PyCallable_Check(object_hook): + * raise TypeError("object_hook must be a callable.") + * self.ctx.user.object_hook = object_hook # <<<<<<<<<<<<<< + * if list_hook is not None: + * if not PyCallable_Check(list_hook): + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx.user.object_hook = ((PyObject *)__pyx_v_object_hook); + goto __pyx_L10; + } + __pyx_L10:; + + /* "msgpack/_msgpack.pyx":308 + * raise TypeError("object_hook must be a callable.") + * self.ctx.user.object_hook = object_hook + * if list_hook is not None: # <<<<<<<<<<<<<< + * if not PyCallable_Check(list_hook): + * raise TypeError("list_hook must be a callable.") + */ + __pyx_t_1 = (__pyx_v_list_hook != Py_None); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":309 + * self.ctx.user.object_hook = object_hook + * if list_hook is not None: + * if not PyCallable_Check(list_hook): # <<<<<<<<<<<<<< + * raise TypeError("list_hook must be a callable.") + * self.ctx.user.list_hook = list_hook + */ + __pyx_t_1 = (!PyCallable_Check(__pyx_v_list_hook)); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":310 + * if list_hook is not None: + * if not PyCallable_Check(list_hook): + * raise TypeError("list_hook must be a callable.") # <<<<<<<<<<<<<< + * self.ctx.user.list_hook = list_hook + * if encoding is None: + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L13; + } + __pyx_L13:; + + /* "msgpack/_msgpack.pyx":311 + * if not PyCallable_Check(list_hook): + * raise TypeError("list_hook must be a callable.") + * self.ctx.user.list_hook = list_hook # <<<<<<<<<<<<<< + * if encoding is None: + * self.ctx.user.encoding = NULL + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx.user.list_hook = ((PyObject *)__pyx_v_list_hook); + goto __pyx_L12; + } + __pyx_L12:; + + /* "msgpack/_msgpack.pyx":312 + * raise TypeError("list_hook must be a callable.") + * self.ctx.user.list_hook = list_hook + * if encoding is None: # <<<<<<<<<<<<<< + * self.ctx.user.encoding = NULL + * self.ctx.user.unicode_errors = NULL + */ + __pyx_t_1 = (__pyx_v_encoding == Py_None); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":313 + * self.ctx.user.list_hook = list_hook + * if encoding is None: + * self.ctx.user.encoding = NULL # <<<<<<<<<<<<<< + * self.ctx.user.unicode_errors = NULL + * else: + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx.user.encoding = NULL; + + /* "msgpack/_msgpack.pyx":314 + * if encoding is None: + * self.ctx.user.encoding = NULL + * self.ctx.user.unicode_errors = NULL # <<<<<<<<<<<<<< + * else: + * if isinstance(encoding, unicode): + */ + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx.user.unicode_errors = NULL; + goto __pyx_L14; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":316 + * self.ctx.user.unicode_errors = NULL + * else: + * if isinstance(encoding, unicode): # <<<<<<<<<<<<<< + * self._bencoding = encoding.encode('ascii') + * else: + */ + __pyx_t_2 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_2); + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_encoding, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":317 + * else: + * if isinstance(encoding, unicode): + * self._bencoding = encoding.encode('ascii') # <<<<<<<<<<<<<< + * else: + * self._bencoding = encoding + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_encoding, __pyx_n_s__encode); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GIVEREF(__pyx_t_3); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_bencoding); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_bencoding); + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_bencoding = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L15; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":319 + * self._bencoding = encoding.encode('ascii') + * else: + * self._bencoding = encoding # <<<<<<<<<<<<<< + * self.ctx.user.encoding = PyBytes_AsString(self._bencoding) + * if isinstance(unicode_errors, unicode): + */ + __Pyx_INCREF(__pyx_v_encoding); + __Pyx_GIVEREF(__pyx_v_encoding); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_bencoding); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_bencoding); + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_bencoding = __pyx_v_encoding; + } + __pyx_L15:; + + /* "msgpack/_msgpack.pyx":320 + * else: + * self._bencoding = encoding + * self.ctx.user.encoding = PyBytes_AsString(self._bencoding) # <<<<<<<<<<<<<< + * if isinstance(unicode_errors, unicode): + * self._berrors = unicode_errors.encode('ascii') + */ + __pyx_t_3 = ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_bencoding; + __Pyx_INCREF(__pyx_t_3); + __pyx_t_4 = PyBytes_AsString(__pyx_t_3); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx.user.encoding = __pyx_t_4; + + /* "msgpack/_msgpack.pyx":321 + * self._bencoding = encoding + * self.ctx.user.encoding = PyBytes_AsString(self._bencoding) + * if isinstance(unicode_errors, unicode): # <<<<<<<<<<<<<< + * self._berrors = unicode_errors.encode('ascii') + * else: + */ + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_unicode_errors, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":322 + * self.ctx.user.encoding = PyBytes_AsString(self._bencoding) + * if isinstance(unicode_errors, unicode): + * self._berrors = unicode_errors.encode('ascii') # <<<<<<<<<<<<<< + * else: + * self._berrors = unicode_errors + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_unicode_errors, __pyx_n_s__encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_berrors); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_berrors); + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_berrors = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L16; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":324 + * self._berrors = unicode_errors.encode('ascii') + * else: + * self._berrors = unicode_errors # <<<<<<<<<<<<<< + * self.ctx.user.unicode_errors = PyBytes_AsString(self._berrors) + * + */ + __Pyx_INCREF(__pyx_v_unicode_errors); + __Pyx_GIVEREF(__pyx_v_unicode_errors); + __Pyx_GOTREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_berrors); + __Pyx_DECREF(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_berrors); + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_berrors = __pyx_v_unicode_errors; + } + __pyx_L16:; + + /* "msgpack/_msgpack.pyx":325 + * else: + * self._berrors = unicode_errors + * self.ctx.user.unicode_errors = PyBytes_AsString(self._berrors) # <<<<<<<<<<<<<< + * + * def feed(self, object next_bytes): + */ + __pyx_t_2 = ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->_berrors; + __Pyx_INCREF(__pyx_t_2); + __pyx_t_4 = PyBytes_AsString(__pyx_t_2); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->ctx.user.unicode_errors = __pyx_t_4; + } + __pyx_L14:; + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("msgpack._msgpack.Unpacker.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":327 + * self.ctx.user.unicode_errors = PyBytes_AsString(self._berrors) + * + * def feed(self, object next_bytes): # <<<<<<<<<<<<<< + * cdef char* buf + * cdef Py_ssize_t buf_len + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_8Unpacker_3feed(PyObject *__pyx_v_self, PyObject *__pyx_v_next_bytes); /*proto*/ +static PyObject *__pyx_pf_7msgpack_8_msgpack_8Unpacker_3feed(PyObject *__pyx_v_self, PyObject *__pyx_v_next_bytes) { + char *__pyx_v_buf; + Py_ssize_t __pyx_v_buf_len; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("feed"); + + /* "msgpack/_msgpack.pyx":330 + * cdef char* buf + * cdef Py_ssize_t buf_len + * if self.file_like is not None: # <<<<<<<<<<<<<< + * raise AssertionError( + * "unpacker.feed() is not be able to use with`file_like`.") + */ + __pyx_t_1 = (((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->file_like != Py_None); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":331 + * cdef Py_ssize_t buf_len + * if self.file_like is not None: + * raise AssertionError( # <<<<<<<<<<<<<< + * "unpacker.feed() is not be able to use with`file_like`.") + * PyObject_AsReadBuffer(next_bytes, &buf, &buf_len) + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_AssertionError, ((PyObject *)__pyx_k_tuple_28), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "msgpack/_msgpack.pyx":333 + * raise AssertionError( + * "unpacker.feed() is not be able to use with`file_like`.") + * PyObject_AsReadBuffer(next_bytes, &buf, &buf_len) # <<<<<<<<<<<<<< + * self.append_buffer(buf, buf_len) + * + */ + __pyx_t_3 = PyObject_AsReadBuffer(__pyx_v_next_bytes, ((const void* *)(&__pyx_v_buf)), (&__pyx_v_buf_len)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 333; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "msgpack/_msgpack.pyx":334 + * "unpacker.feed() is not be able to use with`file_like`.") + * PyObject_AsReadBuffer(next_bytes, &buf, &buf_len) + * self.append_buffer(buf, buf_len) # <<<<<<<<<<<<<< + * + * cdef append_buffer(self, void* _buf, Py_ssize_t _buf_len): + */ + __pyx_t_2 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Unpacker *)((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->__pyx_vtab)->append_buffer(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self), __pyx_v_buf, __pyx_v_buf_len); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 334; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("msgpack._msgpack.Unpacker.feed", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":336 + * self.append_buffer(buf, buf_len) + * + * cdef append_buffer(self, void* _buf, Py_ssize_t _buf_len): # <<<<<<<<<<<<<< + * cdef: + * char* buf = self.buf + */ + +static PyObject *__pyx_f_7msgpack_8_msgpack_8Unpacker_append_buffer(struct __pyx_obj_7msgpack_8_msgpack_Unpacker *__pyx_v_self, void *__pyx_v__buf, Py_ssize_t __pyx_v__buf_len) { + char *__pyx_v_buf; + size_t __pyx_v_head; + size_t __pyx_v_tail; + size_t __pyx_v_buf_size; + size_t __pyx_v_new_size; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("append_buffer"); + + /* "msgpack/_msgpack.pyx":338 + * cdef append_buffer(self, void* _buf, Py_ssize_t _buf_len): + * cdef: + * char* buf = self.buf # <<<<<<<<<<<<<< + * size_t head = self.buf_head + * size_t tail = self.buf_tail + */ + __pyx_v_buf = __pyx_v_self->buf; + + /* "msgpack/_msgpack.pyx":339 + * cdef: + * char* buf = self.buf + * size_t head = self.buf_head # <<<<<<<<<<<<<< + * size_t tail = self.buf_tail + * size_t buf_size = self.buf_size + */ + __pyx_v_head = __pyx_v_self->buf_head; + + /* "msgpack/_msgpack.pyx":340 + * char* buf = self.buf + * size_t head = self.buf_head + * size_t tail = self.buf_tail # <<<<<<<<<<<<<< + * size_t buf_size = self.buf_size + * size_t new_size + */ + __pyx_v_tail = __pyx_v_self->buf_tail; + + /* "msgpack/_msgpack.pyx":341 + * size_t head = self.buf_head + * size_t tail = self.buf_tail + * size_t buf_size = self.buf_size # <<<<<<<<<<<<<< + * size_t new_size + * + */ + __pyx_v_buf_size = __pyx_v_self->buf_size; + + /* "msgpack/_msgpack.pyx":344 + * size_t new_size + * + * if tail + _buf_len > buf_size: # <<<<<<<<<<<<<< + * if ((tail - head) + _buf_len)*2 < buf_size: + * # move to front. + */ + __pyx_t_1 = ((__pyx_v_tail + __pyx_v__buf_len) > __pyx_v_buf_size); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":345 + * + * if tail + _buf_len > buf_size: + * if ((tail - head) + _buf_len)*2 < buf_size: # <<<<<<<<<<<<<< + * # move to front. + * memmove(buf, buf + head, tail - head) + */ + __pyx_t_1 = ((((__pyx_v_tail - __pyx_v_head) + __pyx_v__buf_len) * 2) < __pyx_v_buf_size); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":347 + * if ((tail - head) + _buf_len)*2 < buf_size: + * # move to front. + * memmove(buf, buf + head, tail - head) # <<<<<<<<<<<<<< + * tail -= head + * head = 0 + */ + memmove(__pyx_v_buf, (__pyx_v_buf + __pyx_v_head), (__pyx_v_tail - __pyx_v_head)); + + /* "msgpack/_msgpack.pyx":348 + * # move to front. + * memmove(buf, buf + head, tail - head) + * tail -= head # <<<<<<<<<<<<<< + * head = 0 + * else: + */ + __pyx_v_tail = (__pyx_v_tail - __pyx_v_head); + + /* "msgpack/_msgpack.pyx":349 + * memmove(buf, buf + head, tail - head) + * tail -= head + * head = 0 # <<<<<<<<<<<<<< + * else: + * # expand buffer. + */ + __pyx_v_head = 0; + goto __pyx_L4; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":352 + * else: + * # expand buffer. + * new_size = tail + _buf_len # <<<<<<<<<<<<<< + * if new_size < buf_size*2: + * new_size = buf_size*2 + */ + __pyx_v_new_size = (__pyx_v_tail + __pyx_v__buf_len); + + /* "msgpack/_msgpack.pyx":353 + * # expand buffer. + * new_size = tail + _buf_len + * if new_size < buf_size*2: # <<<<<<<<<<<<<< + * new_size = buf_size*2 + * buf = realloc(buf, new_size) + */ + __pyx_t_1 = (__pyx_v_new_size < (__pyx_v_buf_size * 2)); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":354 + * new_size = tail + _buf_len + * if new_size < buf_size*2: + * new_size = buf_size*2 # <<<<<<<<<<<<<< + * buf = realloc(buf, new_size) + * if buf == NULL: + */ + __pyx_v_new_size = (__pyx_v_buf_size * 2); + goto __pyx_L5; + } + __pyx_L5:; + + /* "msgpack/_msgpack.pyx":355 + * if new_size < buf_size*2: + * new_size = buf_size*2 + * buf = realloc(buf, new_size) # <<<<<<<<<<<<<< + * if buf == NULL: + * # self.buf still holds old buffer and will be freed during + */ + __pyx_v_buf = ((char *)realloc(__pyx_v_buf, __pyx_v_new_size)); + + /* "msgpack/_msgpack.pyx":356 + * new_size = buf_size*2 + * buf = realloc(buf, new_size) + * if buf == NULL: # <<<<<<<<<<<<<< + * # self.buf still holds old buffer and will be freed during + * # obj destruction + */ + __pyx_t_1 = (__pyx_v_buf == NULL); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":359 + * # self.buf still holds old buffer and will be freed during + * # obj destruction + * raise MemoryError("Unable to enlarge internal buffer.") # <<<<<<<<<<<<<< + * buf_size = new_size + * + */ + __pyx_t_2 = PyObject_Call(__pyx_builtin_MemoryError, ((PyObject *)__pyx_k_tuple_30), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L6; + } + __pyx_L6:; + + /* "msgpack/_msgpack.pyx":360 + * # obj destruction + * raise MemoryError("Unable to enlarge internal buffer.") + * buf_size = new_size # <<<<<<<<<<<<<< + * + * memcpy(buf + tail, (_buf), _buf_len) + */ + __pyx_v_buf_size = __pyx_v_new_size; + } + __pyx_L4:; + goto __pyx_L3; + } + __pyx_L3:; + + /* "msgpack/_msgpack.pyx":362 + * buf_size = new_size + * + * memcpy(buf + tail, (_buf), _buf_len) # <<<<<<<<<<<<<< + * self.buf = buf + * self.buf_head = head + */ + memcpy((__pyx_v_buf + __pyx_v_tail), ((char *)__pyx_v__buf), __pyx_v__buf_len); + + /* "msgpack/_msgpack.pyx":363 + * + * memcpy(buf + tail, (_buf), _buf_len) + * self.buf = buf # <<<<<<<<<<<<<< + * self.buf_head = head + * self.buf_size = buf_size + */ + __pyx_v_self->buf = __pyx_v_buf; + + /* "msgpack/_msgpack.pyx":364 + * memcpy(buf + tail, (_buf), _buf_len) + * self.buf = buf + * self.buf_head = head # <<<<<<<<<<<<<< + * self.buf_size = buf_size + * self.buf_tail = tail + _buf_len + */ + __pyx_v_self->buf_head = __pyx_v_head; + + /* "msgpack/_msgpack.pyx":365 + * self.buf = buf + * self.buf_head = head + * self.buf_size = buf_size # <<<<<<<<<<<<<< + * self.buf_tail = tail + _buf_len + * + */ + __pyx_v_self->buf_size = __pyx_v_buf_size; + + /* "msgpack/_msgpack.pyx":366 + * self.buf_head = head + * self.buf_size = buf_size + * self.buf_tail = tail + _buf_len # <<<<<<<<<<<<<< + * + * # prepare self.buf from file_like + */ + __pyx_v_self->buf_tail = (__pyx_v_tail + __pyx_v__buf_len); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("msgpack._msgpack.Unpacker.append_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":369 + * + * # prepare self.buf from file_like + * cdef fill_buffer(self): # <<<<<<<<<<<<<< + * if self.file_like is not None: + * next_bytes = self.file_like_read(self.read_size) + */ + +static PyObject *__pyx_f_7msgpack_8_msgpack_8Unpacker_fill_buffer(struct __pyx_obj_7msgpack_8_msgpack_Unpacker *__pyx_v_self) { + PyObject *__pyx_v_next_bytes = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + Py_ssize_t __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("fill_buffer"); + + /* "msgpack/_msgpack.pyx":370 + * # prepare self.buf from file_like + * cdef fill_buffer(self): + * if self.file_like is not None: # <<<<<<<<<<<<<< + * next_bytes = self.file_like_read(self.read_size) + * if next_bytes: + */ + __pyx_t_1 = (__pyx_v_self->file_like != Py_None); + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":371 + * cdef fill_buffer(self): + * if self.file_like is not None: + * next_bytes = self.file_like_read(self.read_size) # <<<<<<<<<<<<<< + * if next_bytes: + * self.append_buffer(PyBytes_AsString(next_bytes), + */ + __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->read_size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_v_self->file_like_read, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __pyx_v_next_bytes = __pyx_t_2; + __pyx_t_2 = 0; + + /* "msgpack/_msgpack.pyx":372 + * if self.file_like is not None: + * next_bytes = self.file_like_read(self.read_size) + * if next_bytes: # <<<<<<<<<<<<<< + * self.append_buffer(PyBytes_AsString(next_bytes), + * PyBytes_Size(next_bytes)) + */ + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_next_bytes); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 372; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_1) { + + /* "msgpack/_msgpack.pyx":373 + * next_bytes = self.file_like_read(self.read_size) + * if next_bytes: + * self.append_buffer(PyBytes_AsString(next_bytes), # <<<<<<<<<<<<<< + * PyBytes_Size(next_bytes)) + * else: + */ + __pyx_t_4 = PyBytes_AsString(__pyx_v_next_bytes); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "msgpack/_msgpack.pyx":374 + * if next_bytes: + * self.append_buffer(PyBytes_AsString(next_bytes), + * PyBytes_Size(next_bytes)) # <<<<<<<<<<<<<< + * else: + * self.file_like = None + */ + __pyx_t_5 = PyBytes_Size(__pyx_v_next_bytes); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 374; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Unpacker *)__pyx_v_self->__pyx_vtab)->append_buffer(__pyx_v_self, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 373; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L4; + } + /*else*/ { + + /* "msgpack/_msgpack.pyx":376 + * PyBytes_Size(next_bytes)) + * else: + * self.file_like = None # <<<<<<<<<<<<<< + * + * cpdef unpack(self): + */ + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->file_like); + __Pyx_DECREF(__pyx_v_self->file_like); + __pyx_v_self->file_like = Py_None; + } + __pyx_L4:; + goto __pyx_L3; + } + __pyx_L3:; + + __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_AddTraceback("msgpack._msgpack.Unpacker.fill_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_next_bytes); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":378 + * self.file_like = None + * + * cpdef unpack(self): # <<<<<<<<<<<<<< + * """unpack one object""" + * cdef int ret + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_8Unpacker_4unpack(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_f_7msgpack_8_msgpack_8Unpacker_unpack(struct __pyx_obj_7msgpack_8_msgpack_Unpacker *__pyx_v_self, int __pyx_skip_dispatch) { + int __pyx_v_ret; + PyObject *__pyx_v_o = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("unpack"); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overriden in Python */ + else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_self), __pyx_n_s__unpack); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (void *)&__pyx_pf_7msgpack_8_msgpack_8Unpacker_4unpack)) { + __Pyx_XDECREF(__pyx_r); + __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 = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + + /* "msgpack/_msgpack.pyx":381 + * """unpack one object""" + * cdef int ret + * while 1: # <<<<<<<<<<<<<< + * _gc_disable() + * ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head) + */ + while (1) { + if (!1) break; + + /* "msgpack/_msgpack.pyx":382 + * cdef int ret + * while 1: + * _gc_disable() # <<<<<<<<<<<<<< + * ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head) + * _gc_enable() + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s___gc_disable); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __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 = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "msgpack/_msgpack.pyx":383 + * while 1: + * _gc_disable() + * ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head) # <<<<<<<<<<<<<< + * _gc_enable() + * if ret == 1: + */ + __pyx_t_3 = template_execute((&__pyx_v_self->ctx), __pyx_v_self->buf, __pyx_v_self->buf_tail, (&__pyx_v_self->buf_head)); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 383; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = __pyx_t_3; + + /* "msgpack/_msgpack.pyx":384 + * _gc_disable() + * ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head) + * _gc_enable() # <<<<<<<<<<<<<< + * if ret == 1: + * o = template_data(&self.ctx) + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s___gc_enable); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 384; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":389 + * template_init(&self.ctx) + * return o + * elif ret == 0: # <<<<<<<<<<<<<< + * if self.file_like is not None: + * self.fill_buffer() + */ + switch (__pyx_v_ret) { + + /* "msgpack/_msgpack.pyx":385 + * ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head) + * _gc_enable() + * if ret == 1: # <<<<<<<<<<<<<< + * o = template_data(&self.ctx) + * template_init(&self.ctx) + */ + case 1: + + /* "msgpack/_msgpack.pyx":386 + * _gc_enable() + * if ret == 1: + * o = template_data(&self.ctx) # <<<<<<<<<<<<<< + * template_init(&self.ctx) + * return o + */ + __pyx_t_1 = template_data((&__pyx_v_self->ctx)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_o = __pyx_t_1; + __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":387 + * if ret == 1: + * o = template_data(&self.ctx) + * template_init(&self.ctx) # <<<<<<<<<<<<<< + * return o + * elif ret == 0: + */ + template_init((&__pyx_v_self->ctx)); + + /* "msgpack/_msgpack.pyx":388 + * o = template_data(&self.ctx) + * template_init(&self.ctx) + * return o # <<<<<<<<<<<<<< + * elif ret == 0: + * if self.file_like is not None: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_o); + __pyx_r = __pyx_v_o; + goto __pyx_L0; + break; + + /* "msgpack/_msgpack.pyx":389 + * template_init(&self.ctx) + * return o + * elif ret == 0: # <<<<<<<<<<<<<< + * if self.file_like is not None: + * self.fill_buffer() + */ + case 0: + + /* "msgpack/_msgpack.pyx":390 + * return o + * elif ret == 0: + * if self.file_like is not None: # <<<<<<<<<<<<<< + * self.fill_buffer() + * continue + */ + __pyx_t_4 = (__pyx_v_self->file_like != Py_None); + if (__pyx_t_4) { + + /* "msgpack/_msgpack.pyx":391 + * elif ret == 0: + * if self.file_like is not None: + * self.fill_buffer() # <<<<<<<<<<<<<< + * continue + * raise StopIteration("No more unpack data.") + */ + __pyx_t_1 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Unpacker *)__pyx_v_self->__pyx_vtab)->fill_buffer(__pyx_v_self); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":392 + * if self.file_like is not None: + * self.fill_buffer() + * continue # <<<<<<<<<<<<<< + * raise StopIteration("No more unpack data.") + * else: + */ + goto __pyx_L3_continue; + goto __pyx_L5; + } + __pyx_L5:; + + /* "msgpack/_msgpack.pyx":393 + * self.fill_buffer() + * continue + * raise StopIteration("No more unpack data.") # <<<<<<<<<<<<<< + * else: + * raise ValueError("Unpack failed: error = %d" % (ret,)) + */ + __pyx_t_1 = PyObject_Call(__pyx_builtin_StopIteration, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + break; + default: + + /* "msgpack/_msgpack.pyx":395 + * raise StopIteration("No more unpack data.") + * else: + * raise ValueError("Unpack failed: error = %d" % (ret,)) # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __pyx_t_1 = PyInt_FromLong(__pyx_v_ret); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_33), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + break; + } + __pyx_L3_continue:; + } + + __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_AddTraceback("msgpack._msgpack.Unpacker.unpack", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_o); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":378 + * self.file_like = None + * + * cpdef unpack(self): # <<<<<<<<<<<<<< + * """unpack one object""" + * cdef int ret + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_8Unpacker_4unpack(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static char __pyx_doc_7msgpack_8_msgpack_8Unpacker_4unpack[] = "unpack one object"; +static PyObject *__pyx_pf_7msgpack_8_msgpack_8Unpacker_4unpack(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("unpack"); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Unpacker *)((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->__pyx_vtab)->unpack(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 378; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_t_1); + __Pyx_AddTraceback("msgpack._msgpack.Unpacker.unpack", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":397 + * raise ValueError("Unpack failed: error = %d" % (ret,)) + * + * def __iter__(self): # <<<<<<<<<<<<<< + * return self + * + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_8Unpacker_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pf_7msgpack_8_msgpack_8Unpacker_5__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__"); + + /* "msgpack/_msgpack.pyx":398 + * + * def __iter__(self): + * return self # <<<<<<<<<<<<<< + * + * def __next__(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self); + __pyx_r = __pyx_v_self; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "msgpack/_msgpack.pyx":400 + * return self + * + * def __next__(self): # <<<<<<<<<<<<<< + * return self.unpack() + * + */ + +static PyObject *__pyx_pf_7msgpack_8_msgpack_8Unpacker_6__next__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pf_7msgpack_8_msgpack_8Unpacker_6__next__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__next__"); + + /* "msgpack/_msgpack.pyx":401 + * + * def __next__(self): + * return self.unpack() # <<<<<<<<<<<<<< + * + * # for debug. + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = ((struct __pyx_vtabstruct_7msgpack_8_msgpack_Unpacker *)((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self)->__pyx_vtab)->unpack(((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)__pyx_v_self), 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __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_t_1); + __Pyx_AddTraceback("msgpack._msgpack.Unpacker.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static struct __pyx_vtabstruct_7msgpack_8_msgpack_Packer __pyx_vtable_7msgpack_8_msgpack_Packer; + +static PyObject *__pyx_tp_new_7msgpack_8_msgpack_Packer(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_7msgpack_8_msgpack_Packer *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_7msgpack_8_msgpack_Packer *)o); + p->__pyx_vtab = __pyx_vtabptr_7msgpack_8_msgpack_Packer; + p->_default = Py_None; Py_INCREF(Py_None); + p->_bencoding = Py_None; Py_INCREF(Py_None); + p->_berrors = Py_None; Py_INCREF(Py_None); + if (__pyx_pf_7msgpack_8_msgpack_6Packer___cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_7msgpack_8_msgpack_Packer(PyObject *o) { + struct __pyx_obj_7msgpack_8_msgpack_Packer *p = (struct __pyx_obj_7msgpack_8_msgpack_Packer *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pf_7msgpack_8_msgpack_6Packer_2__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(p->_default); + Py_XDECREF(p->_bencoding); + Py_XDECREF(p->_berrors); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_7msgpack_8_msgpack_Packer(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_7msgpack_8_msgpack_Packer *p = (struct __pyx_obj_7msgpack_8_msgpack_Packer *)o; + if (p->_default) { + e = (*v)(p->_default, a); if (e) return e; + } + if (p->_bencoding) { + e = (*v)(p->_bencoding, a); if (e) return e; + } + if (p->_berrors) { + e = (*v)(p->_berrors, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_7msgpack_8_msgpack_Packer(PyObject *o) { + struct __pyx_obj_7msgpack_8_msgpack_Packer *p = (struct __pyx_obj_7msgpack_8_msgpack_Packer *)o; + PyObject* tmp; + tmp = ((PyObject*)p->_default); + p->_default = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_bencoding); + p->_bencoding = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_berrors); + p->_berrors = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_7msgpack_8_msgpack_Packer[] = { + {__Pyx_NAMESTR("pack"), (PyCFunction)__pyx_pf_7msgpack_8_msgpack_6Packer_3pack, 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, /*nb_long*/ + #else + 0, /*reserved*/ + #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_VERSION_HEX >= 0x02050000 + 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 +}; + +static PyTypeObject __pyx_type_7msgpack_8_msgpack_Packer = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("msgpack._msgpack.Packer"), /*tp_name*/ + sizeof(struct __pyx_obj_7msgpack_8_msgpack_Packer), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_7msgpack_8_msgpack_Packer, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 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_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("MessagePack Packer\n\n usage:\n\n packer = Packer()\n astream.write(packer.pack(a))\n astream.write(packer.pack(b))\n "), /*tp_doc*/ + __pyx_tp_traverse_7msgpack_8_msgpack_Packer, /*tp_traverse*/ + __pyx_tp_clear_7msgpack_8_msgpack_Packer, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_7msgpack_8_msgpack_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_8_msgpack_6Packer_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_7msgpack_8_msgpack_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*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; +static struct __pyx_vtabstruct_7msgpack_8_msgpack_Unpacker __pyx_vtable_7msgpack_8_msgpack_Unpacker; + +static PyObject *__pyx_tp_new_7msgpack_8_msgpack_Unpacker(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_7msgpack_8_msgpack_Unpacker *p; + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + p = ((struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)o); + p->__pyx_vtab = __pyx_vtabptr_7msgpack_8_msgpack_Unpacker; + p->file_like = Py_None; Py_INCREF(Py_None); + p->file_like_read = Py_None; Py_INCREF(Py_None); + p->object_hook = Py_None; Py_INCREF(Py_None); + p->_bencoding = Py_None; Py_INCREF(Py_None); + p->_berrors = Py_None; Py_INCREF(Py_None); + if (__pyx_pf_7msgpack_8_msgpack_8Unpacker___cinit__(o, __pyx_empty_tuple, NULL) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_7msgpack_8_msgpack_Unpacker(PyObject *o) { + struct __pyx_obj_7msgpack_8_msgpack_Unpacker *p = (struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pf_7msgpack_8_msgpack_8Unpacker_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(p->file_like); + Py_XDECREF(p->file_like_read); + Py_XDECREF(p->object_hook); + Py_XDECREF(p->_bencoding); + Py_XDECREF(p->_berrors); + (*Py_TYPE(o)->tp_free)(o); +} + +static int __pyx_tp_traverse_7msgpack_8_msgpack_Unpacker(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_7msgpack_8_msgpack_Unpacker *p = (struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)o; + if (p->file_like) { + e = (*v)(p->file_like, a); if (e) return e; + } + if (p->file_like_read) { + e = (*v)(p->file_like_read, a); if (e) return e; + } + if (p->object_hook) { + e = (*v)(p->object_hook, a); if (e) return e; + } + if (p->_bencoding) { + e = (*v)(p->_bencoding, a); if (e) return e; + } + if (p->_berrors) { + e = (*v)(p->_berrors, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_7msgpack_8_msgpack_Unpacker(PyObject *o) { + struct __pyx_obj_7msgpack_8_msgpack_Unpacker *p = (struct __pyx_obj_7msgpack_8_msgpack_Unpacker *)o; + PyObject* tmp; + tmp = ((PyObject*)p->file_like); + p->file_like = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->file_like_read); + p->file_like_read = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->object_hook); + p->object_hook = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_bencoding); + p->_bencoding = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->_berrors); + p->_berrors = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_7msgpack_8_msgpack_Unpacker[] = { + {__Pyx_NAMESTR("feed"), (PyCFunction)__pyx_pf_7msgpack_8_msgpack_8Unpacker_3feed, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("unpack"), (PyCFunction)__pyx_pf_7msgpack_8_msgpack_8Unpacker_4unpack, METH_NOARGS, __Pyx_DOCSTR(__pyx_doc_7msgpack_8_msgpack_8Unpacker_4unpack)}, + {__Pyx_NAMESTR("__next__"), (PyCFunction)__pyx_pf_7msgpack_8_msgpack_8Unpacker_6__next__, METH_NOARGS|METH_COEXIST, __Pyx_DOCSTR(0)}, + {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, /*nb_long*/ + #else + 0, /*reserved*/ + #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_VERSION_HEX >= 0x02050000 + 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 +}; + +static PyTypeObject __pyx_type_7msgpack_8_msgpack_Unpacker = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("msgpack._msgpack.Unpacker"), /*tp_name*/ + sizeof(struct __pyx_obj_7msgpack_8_msgpack_Unpacker), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_7msgpack_8_msgpack_Unpacker, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 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_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + __Pyx_DOCSTR("Unpacker(read_size=1024*1024)\n\n Streaming unpacker.\n read_size is used like file_like.read(read_size)\n\n example:\n unpacker = Unpacker()\n while 1:\n buf = astream.read()\n unpacker.feed(buf)\n for o in unpacker:\n do_something(o)\n "), /*tp_doc*/ + __pyx_tp_traverse_7msgpack_8_msgpack_Unpacker, /*tp_traverse*/ + __pyx_tp_clear_7msgpack_8_msgpack_Unpacker, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pf_7msgpack_8_msgpack_8Unpacker_5__iter__, /*tp_iter*/ + __pyx_pf_7msgpack_8_msgpack_8Unpacker_6__next__, /*tp_iternext*/ + __pyx_methods_7msgpack_8_msgpack_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*/ + __pyx_pf_7msgpack_8_msgpack_8Unpacker_2__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_7msgpack_8_msgpack_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*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +#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_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0}, + {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, + {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, + {&__pyx_kp_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 0}, + {&__pyx_kp_s_18, __pyx_k_18, sizeof(__pyx_k_18), 0, 0, 1, 0}, + {&__pyx_kp_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 0}, + {&__pyx_kp_s_27, __pyx_k_27, sizeof(__pyx_k_27), 0, 0, 1, 0}, + {&__pyx_kp_s_29, __pyx_k_29, sizeof(__pyx_k_29), 0, 0, 1, 0}, + {&__pyx_kp_s_3, __pyx_k_3, sizeof(__pyx_k_3), 0, 0, 1, 0}, + {&__pyx_kp_s_31, __pyx_k_31, sizeof(__pyx_k_31), 0, 0, 1, 0}, + {&__pyx_kp_s_33, __pyx_k_33, sizeof(__pyx_k_33), 0, 0, 1, 0}, + {&__pyx_n_s_34, __pyx_k_34, sizeof(__pyx_k_34), 0, 0, 1, 1}, + {&__pyx_kp_s_4, __pyx_k_4, sizeof(__pyx_k_4), 0, 0, 1, 0}, + {&__pyx_kp_s_9, __pyx_k_9, sizeof(__pyx_k_9), 0, 0, 1, 0}, + {&__pyx_n_s__AssertionError, __pyx_k__AssertionError, sizeof(__pyx_k__AssertionError), 0, 0, 1, 1}, + {&__pyx_n_s__MemoryError, __pyx_k__MemoryError, sizeof(__pyx_k__MemoryError), 0, 0, 1, 1}, + {&__pyx_n_s__StopIteration, __pyx_k__StopIteration, sizeof(__pyx_k__StopIteration), 0, 0, 1, 1}, + {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, + {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, + {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, + {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1}, + {&__pyx_n_s___gc_disable, __pyx_k___gc_disable, sizeof(__pyx_k___gc_disable), 0, 0, 1, 1}, + {&__pyx_n_s___gc_enable, __pyx_k___gc_enable, sizeof(__pyx_k___gc_enable), 0, 0, 1, 1}, + {&__pyx_n_s__ascii, __pyx_k__ascii, sizeof(__pyx_k__ascii), 0, 0, 1, 1}, + {&__pyx_n_s__default, __pyx_k__default, sizeof(__pyx_k__default), 0, 0, 1, 1}, + {&__pyx_n_s__disable, __pyx_k__disable, sizeof(__pyx_k__disable), 0, 0, 1, 1}, + {&__pyx_n_s__dumps, __pyx_k__dumps, sizeof(__pyx_k__dumps), 0, 0, 1, 1}, + {&__pyx_n_s__enable, __pyx_k__enable, sizeof(__pyx_k__enable), 0, 0, 1, 1}, + {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1}, + {&__pyx_n_s__encoding, __pyx_k__encoding, sizeof(__pyx_k__encoding), 0, 0, 1, 1}, + {&__pyx_n_s__file_like, __pyx_k__file_like, sizeof(__pyx_k__file_like), 0, 0, 1, 1}, + {&__pyx_n_s__gc, __pyx_k__gc, sizeof(__pyx_k__gc), 0, 0, 1, 1}, + {&__pyx_n_s__list_hook, __pyx_k__list_hook, sizeof(__pyx_k__list_hook), 0, 0, 1, 1}, + {&__pyx_n_s__loads, __pyx_k__loads, sizeof(__pyx_k__loads), 0, 0, 1, 1}, + {&__pyx_n_s__o, __pyx_k__o, sizeof(__pyx_k__o), 0, 0, 1, 1}, + {&__pyx_n_s__object_hook, __pyx_k__object_hook, sizeof(__pyx_k__object_hook), 0, 0, 1, 1}, + {&__pyx_n_s__pack, __pyx_k__pack, sizeof(__pyx_k__pack), 0, 0, 1, 1}, + {&__pyx_n_s__packb, __pyx_k__packb, sizeof(__pyx_k__packb), 0, 0, 1, 1}, + {&__pyx_n_s__packed, __pyx_k__packed, sizeof(__pyx_k__packed), 0, 0, 1, 1}, + {&__pyx_n_s__packs, __pyx_k__packs, sizeof(__pyx_k__packs), 0, 0, 1, 1}, + {&__pyx_n_s__read, __pyx_k__read, sizeof(__pyx_k__read), 0, 0, 1, 1}, + {&__pyx_n_s__read_size, __pyx_k__read_size, sizeof(__pyx_k__read_size), 0, 0, 1, 1}, + {&__pyx_n_s__stream, __pyx_k__stream, sizeof(__pyx_k__stream), 0, 0, 1, 1}, + {&__pyx_n_s__strict, __pyx_k__strict, sizeof(__pyx_k__strict), 0, 0, 1, 1}, + {&__pyx_n_s__unicode_errors, __pyx_k__unicode_errors, sizeof(__pyx_k__unicode_errors), 0, 0, 1, 1}, + {&__pyx_n_s__unpack, __pyx_k__unpack, sizeof(__pyx_k__unpack), 0, 0, 1, 1}, + {&__pyx_n_s__unpackb, __pyx_k__unpackb, sizeof(__pyx_k__unpackb), 0, 0, 1, 1}, + {&__pyx_n_s__unpacks, __pyx_k__unpacks, sizeof(__pyx_k__unpacks), 0, 0, 1, 1}, + {&__pyx_n_s__use_list, __pyx_k__use_list, sizeof(__pyx_k__use_list), 0, 0, 1, 1}, + {&__pyx_n_s__write, __pyx_k__write, sizeof(__pyx_k__write), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} +}; +static int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_MemoryError = __Pyx_GetName(__pyx_b, __pyx_n_s__MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_AssertionError = __Pyx_GetName(__pyx_b, __pyx_n_s__AssertionError); if (!__pyx_builtin_AssertionError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_StopIteration = __Pyx_GetName(__pyx_b, __pyx_n_s__StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + return 0; + __pyx_L1_error:; + return -1; +} + +static int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants"); + + /* "msgpack/_msgpack.pyx":57 + * self.pk.buf = malloc(buf_size); + * if self.pk.buf == NULL: + * raise MemoryError("Unable to allocate internal buffer.") # <<<<<<<<<<<<<< + * self.pk.buf_size = buf_size + * self.pk.length = 0 + */ + __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_2)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); + PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2)); + + /* "msgpack/_msgpack.pyx":64 + * if default is not None: + * if not PyCallable_Check(default): + * raise TypeError("default must be a callable.") # <<<<<<<<<<<<<< + * self._default = default + * if encoding is None: + */ + __pyx_k_tuple_5 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_5)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_4)); + PyTuple_SET_ITEM(__pyx_k_tuple_5, 0, ((PyObject *)__pyx_kp_s_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_4)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_5)); + + /* "msgpack/_msgpack.pyx":71 + * else: + * if isinstance(encoding, unicode): + * self._bencoding = encoding.encode('ascii') # <<<<<<<<<<<<<< + * else: + * self._bencoding = encoding + */ + __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_6)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii)); + PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); + + /* "msgpack/_msgpack.pyx":76 + * self.encoding = PyBytes_AsString(self._bencoding) + * if isinstance(unicode_errors, unicode): + * self._berrors = unicode_errors.encode('ascii') # <<<<<<<<<<<<<< + * else: + * self._berrors = unicode_errors + */ + __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_7)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii)); + PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7)); + + /* "msgpack/_msgpack.pyx":94 + * + * if nest_limit < 0: + * raise ValueError("Too deep.") # <<<<<<<<<<<<<< + * + * if o is None: + */ + __pyx_k_tuple_10 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_10)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_9)); + PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, ((PyObject *)__pyx_kp_s_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10)); + + /* "msgpack/_msgpack.pyx":123 + * elif PyUnicode_Check(o): + * if not self.encoding: + * raise TypeError("Can't encode utf-8 no encoding is specified") # <<<<<<<<<<<<<< + * o = PyUnicode_AsEncodedString(o, self.encoding, self.unicode_errors) + * rawval = o + */ + __pyx_k_tuple_12 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_12)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_11)); + PyTuple_SET_ITEM(__pyx_k_tuple_12, 0, ((PyObject *)__pyx_kp_s_11)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_11)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_12)); + + /* "msgpack/_msgpack.pyx":209 + * else: + * if isinstance(encoding, unicode): + * bencoding = encoding.encode('ascii') # <<<<<<<<<<<<<< + * else: + * bencoding = encoding + */ + __pyx_k_tuple_14 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_14)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii)); + PyTuple_SET_ITEM(__pyx_k_tuple_14, 0, ((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_14)); + + /* "msgpack/_msgpack.pyx":213 + * bencoding = encoding + * if isinstance(unicode_errors, unicode): + * berrors = unicode_errors.encode('ascii') # <<<<<<<<<<<<<< + * else: + * berrors = unicode_errors + */ + __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_15)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii)); + PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15)); + + /* "msgpack/_msgpack.pyx":226 + * if object_hook is not None: + * if not PyCallable_Check(object_hook): + * raise TypeError("object_hook must be a callable.") # <<<<<<<<<<<<<< + * ctx.user.object_hook = object_hook + * if list_hook is not None: + */ + __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_17)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_16)); + PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, ((PyObject *)__pyx_kp_s_16)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17)); + + /* "msgpack/_msgpack.pyx":230 + * if list_hook is not None: + * if not PyCallable_Check(list_hook): + * raise TypeError("list_hook must be a callable.") # <<<<<<<<<<<<<< + * ctx.user.list_hook = list_hook + * _gc_disable() + */ + __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_19)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_18)); + PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_kp_s_18)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_18)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); + + /* "msgpack/_msgpack.pyx":293 + * self.file_like_read = file_like.read + * if not PyCallable_Check(self.file_like_read): + * raise ValueError("`file_like.read` must be a callable.") # <<<<<<<<<<<<<< + * self.read_size = read_size + * self.buf = malloc(read_size) + */ + __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_21)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_20)); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_20)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_20)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); + + /* "msgpack/_msgpack.pyx":297 + * self.buf = malloc(read_size) + * if self.buf == NULL: + * raise MemoryError("Unable to allocate internal buffer.") # <<<<<<<<<<<<<< + * self.buf_size = read_size + * self.buf_head = 0 + */ + __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_22)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); + PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_kp_s_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); + + /* "msgpack/_msgpack.pyx":306 + * if object_hook is not None: + * if not PyCallable_Check(object_hook): + * raise TypeError("object_hook must be a callable.") # <<<<<<<<<<<<<< + * self.ctx.user.object_hook = object_hook + * if list_hook is not None: + */ + __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 306; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_23)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_16)); + PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_16)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23)); + + /* "msgpack/_msgpack.pyx":310 + * if list_hook is not None: + * if not PyCallable_Check(list_hook): + * raise TypeError("list_hook must be a callable.") # <<<<<<<<<<<<<< + * self.ctx.user.list_hook = list_hook + * if encoding is None: + */ + __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_24)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_18)); + PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_kp_s_18)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_18)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); + + /* "msgpack/_msgpack.pyx":317 + * else: + * if isinstance(encoding, unicode): + * self._bencoding = encoding.encode('ascii') # <<<<<<<<<<<<<< + * else: + * self._bencoding = encoding + */ + __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_25)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii)); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); + + /* "msgpack/_msgpack.pyx":322 + * self.ctx.user.encoding = PyBytes_AsString(self._bencoding) + * if isinstance(unicode_errors, unicode): + * self._berrors = unicode_errors.encode('ascii') # <<<<<<<<<<<<<< + * else: + * self._berrors = unicode_errors + */ + __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 322; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_26)); + __Pyx_INCREF(((PyObject *)__pyx_n_s__ascii)); + PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ascii)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26)); + + /* "msgpack/_msgpack.pyx":331 + * cdef Py_ssize_t buf_len + * if self.file_like is not None: + * raise AssertionError( # <<<<<<<<<<<<<< + * "unpacker.feed() is not be able to use with`file_like`.") + * PyObject_AsReadBuffer(next_bytes, &buf, &buf_len) + */ + __pyx_k_tuple_28 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 331; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_28)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_27)); + PyTuple_SET_ITEM(__pyx_k_tuple_28, 0, ((PyObject *)__pyx_kp_s_27)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_27)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28)); + + /* "msgpack/_msgpack.pyx":359 + * # self.buf still holds old buffer and will be freed during + * # obj destruction + * raise MemoryError("Unable to enlarge internal buffer.") # <<<<<<<<<<<<<< + * buf_size = new_size + * + */ + __pyx_k_tuple_30 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_30)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_29)); + PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, ((PyObject *)__pyx_kp_s_29)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_29)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30)); + + /* "msgpack/_msgpack.pyx":393 + * self.fill_buffer() + * continue + * raise StopIteration("No more unpack data.") # <<<<<<<<<<<<<< + * else: + * raise ValueError("Unpack failed: error = %d" % (ret,)) + */ + __pyx_k_tuple_32 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_32)); + __Pyx_INCREF(((PyObject *)__pyx_kp_s_31)); + PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_kp_s_31)); + __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32)); + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + 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;}; + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_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 init_msgpack(void); /*proto*/ +PyMODINIT_FUNC init_msgpack(void) +#else +PyMODINIT_FUNC PyInit__msgpack(void); /*proto*/ +PyMODINIT_FUNC PyInit__msgpack(void) +#endif +{ + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + __Pyx_RefNannyDeclarations + #if CYTHON_REFNANNY + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); + if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); + } + #endif + __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__msgpack(void)"); + if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __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;} + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #ifdef __pyx_binding_PyCFunctionType_USED + if (__pyx_binding_PyCFunctionType_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif + /*--- Library function declarations ---*/ + /*--- 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 + /*--- 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;}; + /*--- 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;} + if (__pyx_module_is_main_msgpack___msgpack) { + if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____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;} + /*--- Constants init code ---*/ + if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Global init code ---*/ + /*--- Variable export code ---*/ + /*--- Function export code ---*/ + /*--- Type init code ---*/ + __pyx_vtabptr_7msgpack_8_msgpack_Packer = &__pyx_vtable_7msgpack_8_msgpack_Packer; + __pyx_vtable_7msgpack_8_msgpack_Packer._pack = (int (*)(struct __pyx_obj_7msgpack_8_msgpack_Packer *, PyObject *, struct __pyx_opt_args_7msgpack_8_msgpack_6Packer__pack *__pyx_optional_args))__pyx_f_7msgpack_8_msgpack_6Packer__pack; + if (PyType_Ready(&__pyx_type_7msgpack_8_msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_7msgpack_8_msgpack_Packer.tp_dict, __pyx_vtabptr_7msgpack_8_msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Packer", (PyObject *)&__pyx_type_7msgpack_8_msgpack_Packer) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_7msgpack_8_msgpack_Packer = &__pyx_type_7msgpack_8_msgpack_Packer; + __pyx_vtabptr_7msgpack_8_msgpack_Unpacker = &__pyx_vtable_7msgpack_8_msgpack_Unpacker; + __pyx_vtable_7msgpack_8_msgpack_Unpacker.append_buffer = (PyObject *(*)(struct __pyx_obj_7msgpack_8_msgpack_Unpacker *, void *, Py_ssize_t))__pyx_f_7msgpack_8_msgpack_8Unpacker_append_buffer; + __pyx_vtable_7msgpack_8_msgpack_Unpacker.fill_buffer = (PyObject *(*)(struct __pyx_obj_7msgpack_8_msgpack_Unpacker *))__pyx_f_7msgpack_8_msgpack_8Unpacker_fill_buffer; + __pyx_vtable_7msgpack_8_msgpack_Unpacker.unpack = (PyObject *(*)(struct __pyx_obj_7msgpack_8_msgpack_Unpacker *, int __pyx_skip_dispatch))__pyx_f_7msgpack_8_msgpack_8Unpacker_unpack; + if (PyType_Ready(&__pyx_type_7msgpack_8_msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_7msgpack_8_msgpack_Unpacker.tp_dict, __pyx_vtabptr_7msgpack_8_msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Unpacker", (PyObject *)&__pyx_type_7msgpack_8_msgpack_Unpacker) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_7msgpack_8_msgpack_Unpacker = &__pyx_type_7msgpack_8_msgpack_Unpacker; + /*--- Type import code ---*/ + __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*--- Variable import code ---*/ + /*--- Function import code ---*/ + /*--- Execution code ---*/ + + /* "msgpack/_msgpack.pyx":12 + * from libc.stdlib cimport * + * from libc.string cimport * + * import gc # <<<<<<<<<<<<<< + * _gc_disable = gc.disable + * _gc_enable = gc.enable + */ + __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__gc), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__gc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":13 + * from libc.string cimport * + * import gc + * _gc_disable = gc.disable # <<<<<<<<<<<<<< + * _gc_enable = gc.enable + * + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__gc); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__disable); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PyObject_SetAttr(__pyx_m, __pyx_n_s___gc_disable, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "msgpack/_msgpack.pyx":14 + * import gc + * _gc_disable = gc.disable + * _gc_enable = gc.enable # <<<<<<<<<<<<<< + * + * cdef extern from "pack.h": + */ + __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__gc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__enable); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyObject_SetAttr(__pyx_m, __pyx_n_s___gc_enable, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":35 + * int msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) + * + * cdef int DEFAULT_RECURSE_LIMIT=511 # <<<<<<<<<<<<<< + * + * cdef class Packer(object): + */ + __pyx_v_7msgpack_8_msgpack_DEFAULT_RECURSE_LIMIT = 511; + + /* "msgpack/_msgpack.pyx":84 + * free(self.pk.buf); + * + * cdef int _pack(self, object o, int nest_limit=DEFAULT_RECURSE_LIMIT) except -1: # <<<<<<<<<<<<<< + * cdef long long llval + * cdef unsigned long long ullval + */ + __pyx_k_8 = __pyx_v_7msgpack_8_msgpack_DEFAULT_RECURSE_LIMIT; + + /* "msgpack/_msgpack.pyx":161 + * + * + * def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors='strict'): # <<<<<<<<<<<<<< + * """pack an object `o` and write it to stream).""" + * packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7msgpack_8_msgpack_pack, NULL, __pyx_n_s_34); 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); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__pack, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":166 + * stream.write(packer.pack(o)) + * + * def packb(object o, default=None, encoding='utf-8', unicode_errors='strict'): # <<<<<<<<<<<<<< + * """pack o and return packed bytes.""" + * packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7msgpack_8_msgpack_1packb, NULL, __pyx_n_s_34); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__packb, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":171 + * return packer.pack(o) + * + * dumps = packs = packb # <<<<<<<<<<<<<< + * + * cdef extern from "unpack.h": + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__packb); 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); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__dumps, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__packs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":194 + * + * + * def unpackb(object packed, object object_hook=None, object list_hook=None, bint use_list=0, encoding=None, unicode_errors="strict"): # <<<<<<<<<<<<<< + * """Unpack packed_bytes to object. Returns an unpacked object.""" + * cdef template_context ctx + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7msgpack_8_msgpack_2unpackb, NULL, __pyx_n_s_34); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__unpackb, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":242 + * return None + * + * loads = unpacks = unpackb # <<<<<<<<<<<<<< + * + * def unpack(object stream, object object_hook=None, object list_hook=None, bint use_list=0, encoding=None, unicode_errors="strict"): + */ + __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__unpackb); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__loads, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__unpacks, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":244 + * loads = unpacks = unpackb + * + * def unpack(object stream, object object_hook=None, object list_hook=None, bint use_list=0, encoding=None, unicode_errors="strict"): # <<<<<<<<<<<<<< + * """unpack an object from stream.""" + * return unpackb(stream.read(), use_list=use_list, + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7msgpack_8_msgpack_3unpack, NULL, __pyx_n_s_34); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__unpack, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "msgpack/_msgpack.pyx":1 + * # coding: utf-8 # <<<<<<<<<<<<<< + * + * from cpython cimport * + */ + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + if (__pyx_m) { + __Pyx_AddTraceback("init msgpack._msgpack", __pyx_clineno, __pyx_lineno, __pyx_filename); + Py_DECREF(__pyx_m); __pyx_m = 0; + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init msgpack._msgpack"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if PY_MAJOR_VERSION < 3 + return; + #else + return __pyx_m; + #endif +} + +/* Runtime support code */ + +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule((char *)modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif /* CYTHON_REFNANNY */ + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { + PyObject *result; + result = PyObject_GetAttr(dict, name); + if (!result) { + if (dict != __pyx_b) { + PyErr_Clear(); + result = PyObject_GetAttr(__pyx_b, name); + } + if (!result) { + PyErr_SetObject(PyExc_NameError, name); + } + } + return result; +} + +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 *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"; + } + PyErr_Format(PyExc_TypeError, + "%s() takes %s %"PY_FORMAT_SIZE_T"d positional argument%s (%"PY_FORMAT_SIZE_T"d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +static CYTHON_INLINE int __Pyx_CheckKeywordStrings( + PyObject *kwdict, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; + while (PyDict_Next(kwdict, &pos, &key, 0)) { + #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; + } + if ((!kw_allowed) && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%s() keywords must be strings", function_name); + return 0; +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 + return 0; +} + +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyThreadState *tstate = PyThreadState_GET(); + + 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 CYTHON_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; +} + + +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + /* cause is unused */ + 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; +} + +#else /* Python 3+ */ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (!PyExceptionClass_Check(type)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + + if (cause) { + PyObject *fixed_cause; + if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } + else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } + else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + if (!value) { + value = PyObject_CallObject(type, NULL); + } + PyException_SetCause(value, fixed_cause); + } + + PyErr_SetObject(type, value); + + if (tb) { + PyThreadState *tstate = PyThreadState_GET(); + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } + } + +bad: + return; +} +#endif + +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 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 CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { + PyErr_Format(PyExc_ValueError, + "need more than %"PY_FORMAT_SIZE_T"d value%s to unpack", + index, (index == 1) ? "" : "s"); +} + +static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { + PyErr_Format(PyExc_ValueError, + "too many values to unpack (expected %"PY_FORMAT_SIZE_T"d)", expected); +} + +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { + if (unlikely(retval)) { + Py_DECREF(retval); + __Pyx_RaiseTooManyValuesError(expected); + return -1; + } else if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) { + PyErr_Clear(); + return 0; + } else { + return -1; + } + } + return 0; +} + +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) { + PyObject *py_import = 0; + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + py_import = __Pyx_GetAttrString(__pyx_b, "__import__"); + if (!py_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; + #if PY_VERSION_HEX >= 0x02050000 + { + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, NULL); + Py_DECREF(py_level); + } + #else + if (level>0) { + PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4."); + goto bad; + } + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, NULL); + #endif +bad: + Py_XDECREF(empty_list); + Py_XDECREF(py_import); + Py_XDECREF(empty_dict); + return module; +} + +static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) { + const unsigned char neg_one = (unsigned char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + 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())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned char" : + "value too large to convert to unsigned char"); + } + return (unsigned char)-1; + } + return (unsigned char)val; + } + return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) { + const unsigned short neg_one = (unsigned short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + 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())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned short" : + "value too large to convert to unsigned short"); + } + return (unsigned short)-1; + } + return (unsigned short)val; + } + return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) { + const unsigned int neg_one = (unsigned int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + 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())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to unsigned int" : + "value too large to convert to unsigned int"); + } + return (unsigned int)-1; + } + return (unsigned int)val; + } + return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x); +} + +static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) { + const char neg_one = (char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(char) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(char)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to char" : + "value too large to convert to char"); + } + return (char)-1; + } + return (char)val; + } + return (char)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) { + const short neg_one = (short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(short) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(short)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to short" : + "value too large to convert to short"); + } + return (short)-1; + } + return (short)val; + } + return (short)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) { + const int neg_one = (int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to int" : + "value too large to convert to int"); + } + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) { + const signed char neg_one = (signed char)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + 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())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed char" : + "value too large to convert to signed char"); + } + return (signed char)-1; + } + return (signed char)val; + } + return (signed char)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) { + const signed short neg_one = (signed short)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + 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())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed short" : + "value too large to convert to signed short"); + } + return (signed short)-1; + } + return (signed short)val; + } + return (signed short)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) { + const signed int neg_one = (signed int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + 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())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to signed int" : + "value too large to convert to signed int"); + } + return (signed int)-1; + } + return (signed int)val; + } + return (signed int)__Pyx_PyInt_AsSignedLong(x); +} + +static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) { + const int neg_one = (int)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (sizeof(int) < sizeof(long)) { + long val = __Pyx_PyInt_AsLong(x); + if (unlikely(val != (long)(int)val)) { + if (!unlikely(val == -1 && PyErr_Occurred())) { + PyErr_SetString(PyExc_OverflowError, + (is_unsigned && unlikely(val < 0)) ? + "can't convert negative value to int" : + "value too large to convert to int"); + } + return (int)-1; + } + return (int)val; + } + return (int)__Pyx_PyInt_AsLong(x); +} + +static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) { + const unsigned long neg_one = (unsigned long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && 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_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned long"); + return (unsigned long)-1; + } + return (unsigned long)PyLong_AsUnsignedLong(x); + } else { + return (unsigned long)PyLong_AsLong(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 CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) { + const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && 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_Check(x))) { + if (is_unsigned) { + 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 (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + } else { + return (unsigned PY_LONG_LONG)PyLong_AsLongLong(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 CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) { + const long neg_one = (long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long)-1; + } + return (long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long)-1; + } + return (long)PyLong_AsUnsignedLong(x); + } else { + return (long)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 CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) { + const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG)-1; + } + return (PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to PY_LONG_LONG"); + return (PY_LONG_LONG)-1; + } + return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + } else { + return (PY_LONG_LONG)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 CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) { + const signed long neg_one = (signed long)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed long"); + return (signed long)-1; + } + return (signed long)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed long"); + return (signed long)-1; + } + return (signed long)PyLong_AsUnsignedLong(x); + } else { + return (signed long)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 CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) { + const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; +#if PY_VERSION_HEX < 0x03000000 + if (likely(PyInt_Check(x))) { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed PY_LONG_LONG"); + return (signed PY_LONG_LONG)-1; + } + return (signed PY_LONG_LONG)val; + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to signed PY_LONG_LONG"); + return (signed PY_LONG_LONG)-1; + } + return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x); + } else { + return (signed PY_LONG_LONG)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 int __Pyx_check_binary_version(void) { + char ctversion[4], rtversion[4]; + PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); + PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion()); + if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compiletime version %s of module '%.100s' " + "does not match runtime version %s", + ctversion, __Pyx_MODULE_NAME, rtversion); + #if PY_VERSION_HEX < 0x02050000 + return PyErr_Warn(NULL, message); + #else + return PyErr_WarnEx(NULL, message, 1); + #endif + } + return 0; +} + +static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) + PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); +#endif + if (!ob) + goto bad; + if (PyDict_SetItemString(dict, "__pyx_vtable__", ob) < 0) + goto bad; + Py_DECREF(ob); + return 0; +bad: + Py_XDECREF(ob); + return -1; +} + +#ifndef __PYX_HAVE_RT_ImportType +#define __PYX_HAVE_RT_ImportType +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, + size_t size, int strict) +{ + PyObject *py_module = 0; + PyObject *result = 0; + PyObject *py_name = 0; + char warning[200]; + + py_module = __Pyx_ImportModule(module_name); + if (!py_module) + goto bad; + #if PY_MAJOR_VERSION < 3 + py_name = PyString_FromString(class_name); + #else + py_name = PyUnicode_FromString(class_name); + #endif + if (!py_name) + goto bad; + result = PyObject_GetAttr(py_module, py_name); + Py_DECREF(py_name); + py_name = 0; + Py_DECREF(py_module); + py_module = 0; + if (!result) + goto bad; + if (!PyType_Check(result)) { + PyErr_Format(PyExc_TypeError, + "%s.%s is not a type object", + module_name, class_name); + goto bad; + } + if (!strict && ((PyTypeObject *)result)->tp_basicsize > (Py_ssize_t)size) { + PyOS_snprintf(warning, sizeof(warning), + "%s.%s size changed, may indicate binary incompatibility", + module_name, class_name); + #if PY_VERSION_HEX < 0x02050000 + if (PyErr_Warn(NULL, warning) < 0) goto bad; + #else + if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; + #endif + } + else if (((PyTypeObject *)result)->tp_basicsize != (Py_ssize_t)size) { + PyErr_Format(PyExc_ValueError, + "%s.%s has the wrong size, try recompiling", + module_name, class_name); + goto bad; + } + return (PyTypeObject *)result; +bad: + Py_XDECREF(py_module); + Py_XDECREF(result); + return NULL; +} +#endif + +#ifndef __PYX_HAVE_RT_ImportModule +#define __PYX_HAVE_RT_ImportModule +static PyObject *__Pyx_ImportModule(const char *name) { + PyObject *py_name = 0; + PyObject *py_module = 0; + + #if PY_MAJOR_VERSION < 3 + py_name = PyString_FromString(name); + #else + py_name = PyUnicode_FromString(name); + #endif + if (!py_name) + goto bad; + py_module = PyImport_Import(py_name); + Py_DECREF(py_name); + return py_module; +bad: + Py_XDECREF(py_name); + return 0; +} +#endif + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" + +static void __Pyx_AddTraceback(const char *funcname, int __pyx_clineno, + int __pyx_lineno, const char *__pyx_filename) { + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + PyObject *py_globals = 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; + 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,*/ + __pyx_empty_bytes, /*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,*/ + __pyx_empty_bytes /*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(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->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_unicode | t->is_str) { + if (t->intern) { + *t->p = PyUnicode_InternFromString(t->s); + } else if (t->encoding) { + *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL); + } else { + *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 CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} + +static CYTHON_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 CYTHON_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 CYTHON_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 CYTHON_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; +} + + +#endif /* Py_PYTHON_H */ diff --git a/salt/msgpack/_msgpack.pyx b/salt/msgpack/_msgpack.pyx new file mode 100644 index 0000000000..5a83ea062d --- /dev/null +++ b/salt/msgpack/_msgpack.pyx @@ -0,0 +1,408 @@ +# coding: utf-8 + +from cpython cimport * +cdef extern from "Python.h": + ctypedef char* const_char_ptr "const char*" + ctypedef char* const_void_ptr "const void*" + ctypedef struct PyObject + cdef int PyObject_AsReadBuffer(object o, const_void_ptr* buff, Py_ssize_t* buf_len) except -1 + +from libc.stdlib cimport * +from libc.string cimport * +import gc +_gc_disable = gc.disable +_gc_enable = gc.enable + +cdef extern from "pack.h": + struct msgpack_packer: + 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) + 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 int DEFAULT_RECURSE_LIMIT=511 + +cdef class Packer(object): + """MessagePack Packer + + usage: + + packer = Packer() + astream.write(packer.pack(a)) + astream.write(packer.pack(b)) + """ + cdef msgpack_packer pk + cdef object _default + cdef object _bencoding + cdef object _berrors + cdef char *encoding + cdef char *unicode_errors + + def __cinit__(self): + cdef int buf_size = 1024*1024 + self.pk.buf = malloc(buf_size); + if self.pk.buf == NULL: + raise MemoryError("Unable to allocate internal buffer.") + self.pk.buf_size = buf_size + self.pk.length = 0 + + def __init__(self, default=None, encoding='utf-8', unicode_errors='strict'): + if default is not None: + if not PyCallable_Check(default): + raise TypeError("default must be a callable.") + self._default = default + if encoding is None: + self.encoding = NULL + self.unicode_errors = NULL + else: + if isinstance(encoding, unicode): + self._bencoding = encoding.encode('ascii') + else: + self._bencoding = encoding + self.encoding = PyBytes_AsString(self._bencoding) + if isinstance(unicode_errors, unicode): + self._berrors = unicode_errors.encode('ascii') + else: + self._berrors = unicode_errors + self.unicode_errors = PyBytes_AsString(self._berrors) + + def __dealloc__(self): + free(self.pk.buf); + + cdef int _pack(self, object o, int nest_limit=DEFAULT_RECURSE_LIMIT) except -1: + cdef long long llval + cdef unsigned long long ullval + cdef long longval + cdef double fval + cdef char* rawval + cdef int ret + cdef dict d + + if nest_limit < 0: + raise ValueError("Too deep.") + + if o is None: + ret = msgpack_pack_nil(&self.pk) + elif isinstance(o, bool): + if o: + ret = msgpack_pack_true(&self.pk) + else: + ret = msgpack_pack_false(&self.pk) + elif PyLong_Check(o): + if o > 0: + ullval = o + ret = msgpack_pack_unsigned_long_long(&self.pk, ullval) + else: + llval = o + ret = msgpack_pack_long_long(&self.pk, llval) + elif PyInt_Check(o): + longval = o + ret = msgpack_pack_long(&self.pk, longval) + elif PyFloat_Check(o): + fval = o + ret = msgpack_pack_double(&self.pk, fval) + elif PyBytes_Check(o): + rawval = 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): + if not self.encoding: + raise TypeError("Can't encode utf-8 no encoding is specified") + o = PyUnicode_AsEncodedString(o, self.encoding, self.unicode_errors) + rawval = o + ret = msgpack_pack_raw(&self.pk, len(o)) + if ret == 0: + ret = msgpack_pack_raw_body(&self.pk, rawval, len(o)) + elif PyDict_Check(o): + d = o + ret = msgpack_pack_map(&self.pk, len(d)) + if ret == 0: + for k,v in d.items(): + ret = self._pack(k, nest_limit-1) + if ret != 0: break + ret = self._pack(v, nest_limit-1) + if ret != 0: break + elif PySequence_Check(o): + ret = msgpack_pack_array(&self.pk, len(o)) + if ret == 0: + for v in o: + ret = self._pack(v, nest_limit-1) + if ret != 0: break + elif self._default: + o = self._default(o) + ret = self._pack(o, nest_limit-1) + else: + raise TypeError("can't serialize %r" % (o,)) + return ret + + def pack(self, object obj): + cdef int ret + ret = self._pack(obj, DEFAULT_RECURSE_LIMIT) + if ret: + raise TypeError + buf = PyBytes_FromStringAndSize(self.pk.buf, self.pk.length) + self.pk.length = 0 + return buf + + +def pack(object o, object stream, default=None, encoding='utf-8', unicode_errors='strict'): + """pack an object `o` and write it to stream).""" + packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) + stream.write(packer.pack(o)) + +def packb(object o, default=None, encoding='utf-8', unicode_errors='strict'): + """pack o and return packed bytes.""" + packer = Packer(default=default, encoding=encoding, unicode_errors=unicode_errors) + return packer.pack(o) + +dumps = packs = packb + +cdef extern from "unpack.h": + ctypedef struct msgpack_user: + int use_list + PyObject* object_hook + PyObject* list_hook + char *encoding + char *unicode_errors + + ctypedef struct template_context: + msgpack_user user + 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) except -1 + void template_init(template_context* ctx) + object template_data(template_context* ctx) + + +def unpackb(object packed, object object_hook=None, object list_hook=None, bint use_list=0, encoding=None, unicode_errors="strict"): + """Unpack packed_bytes to object. Returns an unpacked object.""" + cdef template_context ctx + cdef size_t off = 0 + cdef int ret + + cdef char* buf + cdef Py_ssize_t buf_len + PyObject_AsReadBuffer(packed, &buf, &buf_len) + + if encoding is None: + enc = NULL + err = NULL + else: + if isinstance(encoding, unicode): + bencoding = encoding.encode('ascii') + else: + bencoding = encoding + if isinstance(unicode_errors, unicode): + berrors = unicode_errors.encode('ascii') + else: + berrors = unicode_errors + enc = PyBytes_AsString(bencoding) + err = PyBytes_AsString(berrors) + + template_init(&ctx) + ctx.user.use_list = use_list + ctx.user.object_hook = ctx.user.list_hook = NULL + ctx.user.encoding = enc + ctx.user.unicode_errors = err + if object_hook is not None: + if not PyCallable_Check(object_hook): + raise TypeError("object_hook must be a callable.") + ctx.user.object_hook = object_hook + if list_hook is not None: + if not PyCallable_Check(list_hook): + raise TypeError("list_hook must be a callable.") + ctx.user.list_hook = list_hook + _gc_disable() + try: + ret = template_execute(&ctx, buf, buf_len, &off) + finally: + _gc_enable() + if ret == 1: + return template_data(&ctx) + else: + return None + +loads = unpacks = unpackb + +def unpack(object stream, object object_hook=None, object list_hook=None, bint use_list=0, encoding=None, unicode_errors="strict"): + """unpack an object from stream.""" + return unpackb(stream.read(), use_list=use_list, + object_hook=object_hook, list_hook=list_hook, encoding=encoding, unicode_errors=unicode_errors) + +cdef class Unpacker(object): + """Unpacker(read_size=1024*1024) + + Streaming unpacker. + read_size is used like file_like.read(read_size) + + example: + 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 object file_like_read + cdef Py_ssize_t read_size + cdef bint use_list + cdef object object_hook + cdef object _bencoding + cdef object _berrors + cdef char *encoding + cdef char *unicode_errors + + def __cinit__(self): + self.buf = NULL + + def __dealloc__(self): + free(self.buf); + self.buf = NULL; + + def __init__(self, file_like=None, Py_ssize_t read_size=0, bint use_list=0, + object object_hook=None, object list_hook=None, + encoding=None, unicode_errors='strict'): + if read_size == 0: + read_size = 1024*1024 + self.use_list = use_list + self.file_like = file_like + if file_like: + self.file_like_read = file_like.read + if not PyCallable_Check(self.file_like_read): + raise ValueError("`file_like.read` must be a callable.") + self.read_size = read_size + self.buf = malloc(read_size) + if self.buf == NULL: + raise MemoryError("Unable to allocate internal buffer.") + self.buf_size = read_size + self.buf_head = 0 + self.buf_tail = 0 + template_init(&self.ctx) + self.ctx.user.use_list = use_list + self.ctx.user.object_hook = self.ctx.user.list_hook = NULL + if object_hook is not None: + if not PyCallable_Check(object_hook): + raise TypeError("object_hook must be a callable.") + self.ctx.user.object_hook = object_hook + if list_hook is not None: + if not PyCallable_Check(list_hook): + raise TypeError("list_hook must be a callable.") + self.ctx.user.list_hook = list_hook + if encoding is None: + self.ctx.user.encoding = NULL + self.ctx.user.unicode_errors = NULL + else: + if isinstance(encoding, unicode): + self._bencoding = encoding.encode('ascii') + else: + self._bencoding = encoding + self.ctx.user.encoding = PyBytes_AsString(self._bencoding) + if isinstance(unicode_errors, unicode): + self._berrors = unicode_errors.encode('ascii') + else: + self._berrors = unicode_errors + self.ctx.user.unicode_errors = PyBytes_AsString(self._berrors) + + def feed(self, object next_bytes): + cdef char* buf + cdef Py_ssize_t buf_len + if self.file_like is not None: + raise AssertionError( + "unpacker.feed() is not be able to use with`file_like`.") + PyObject_AsReadBuffer(next_bytes, &buf, &buf_len) + self.append_buffer(buf, buf_len) + + cdef append_buffer(self, void* _buf, Py_ssize_t _buf_len): + cdef: + char* buf = self.buf + size_t head = self.buf_head + size_t tail = self.buf_tail + size_t buf_size = self.buf_size + size_t new_size + + if tail + _buf_len > buf_size: + if ((tail - head) + _buf_len)*2 < buf_size: + # move to front. + memmove(buf, buf + head, tail - head) + tail -= head + head = 0 + else: + # expand buffer. + new_size = tail + _buf_len + if new_size < buf_size*2: + new_size = buf_size*2 + buf = realloc(buf, new_size) + if buf == NULL: + # self.buf still holds old buffer and will be freed during + # obj destruction + raise MemoryError("Unable to enlarge internal buffer.") + buf_size = new_size + + memcpy(buf + tail, (_buf), _buf_len) + self.buf = buf + self.buf_head = head + self.buf_size = buf_size + self.buf_tail = tail + _buf_len + + # prepare self.buf from file_like + cdef fill_buffer(self): + if self.file_like is not None: + next_bytes = self.file_like_read(self.read_size) + if next_bytes: + self.append_buffer(PyBytes_AsString(next_bytes), + PyBytes_Size(next_bytes)) + else: + self.file_like = None + + cpdef unpack(self): + """unpack one object""" + cdef int ret + while 1: + _gc_disable() + ret = template_execute(&self.ctx, self.buf, self.buf_tail, &self.buf_head) + _gc_enable() + if ret == 1: + o = template_data(&self.ctx) + template_init(&self.ctx) + return o + elif ret == 0: + if self.file_like is not None: + self.fill_buffer() + continue + raise StopIteration("No more unpack data.") + else: + raise ValueError("Unpack failed: error = %d" % (ret,)) + + def __iter__(self): + return self + + def __next__(self): + return self.unpack() + + # for debug. + #def _buf(self): + # return PyString_FromStringAndSize(self.buf, self.buf_tail) + + #def _off(self): + # return self.buf_head diff --git a/salt/msgpack/pack.h b/salt/msgpack/pack.h new file mode 100644 index 0000000000..2ae95d17fd --- /dev/null +++ b/salt/msgpack/pack.h @@ -0,0 +1,103 @@ +/* + * 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. + */ + +#include +#include +#include "sysdep.h" +#include "pack_define.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct msgpack_packer { + char *buf; + size_t length; + size_t buf_size; +} msgpack_packer; + +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); +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); + +static inline int msgpack_pack_write(msgpack_packer* pk, const char *data, size_t l) +{ + 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(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; +} + +#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 msgpack_pack_write(user, (const char*)buf, len) + +#include "pack_template.h" + +#ifdef __cplusplus +} +#endif diff --git a/salt/msgpack/pack_define.h b/salt/msgpack/pack_define.h new file mode 100644 index 0000000000..f72391b7ad --- /dev/null +++ b/salt/msgpack/pack_define.h @@ -0,0 +1,25 @@ +/* + * 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 "sysdep.h" +#include + +#endif /* msgpack/pack_define.h */ + diff --git a/salt/msgpack/pack_template.h b/salt/msgpack/pack_template.h new file mode 100644 index 0000000000..de148bf646 --- /dev/null +++ b/salt/msgpack/pack_template.h @@ -0,0 +1,686 @@ +/* + * 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. + */ + +#ifdef __LITTLE_ENDIAN__ +#define TAKE8_8(d) ((uint8_t*)&d)[0] +#define TAKE8_16(d) ((uint8_t*)&d)[0] +#define TAKE8_32(d) ((uint8_t*)&d)[0] +#define TAKE8_64(d) ((uint8_t*)&d)[0] +#elif __BIG_ENDIAN__ +#define TAKE8_8(d) ((uint8_t*)&d)[0] +#define TAKE8_16(d) ((uint8_t*)&d)[1] +#define TAKE8_32(d) ((uint8_t*)&d)[3] +#define TAKE8_64(d) ((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, &TAKE8_8(d), 1); \ + } else { \ + /* unsigned 8 */ \ + unsigned char buf[2] = {0xcc, TAKE8_8(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, &TAKE8_16(d), 1); \ + } else if(d < (1<<8)) { \ + /* unsigned 8 */ \ + unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else { \ + /* unsigned 16 */ \ + unsigned char buf[3]; \ + buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_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, &TAKE8_32(d), 1); \ + } else { \ + /* unsigned 8 */ \ + unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } else { \ + if(d < (1<<16)) { \ + /* unsigned 16 */ \ + unsigned char buf[3]; \ + buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* unsigned 32 */ \ + unsigned char buf[5]; \ + buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_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, &TAKE8_64(d), 1); \ + } else { \ + /* unsigned 8 */ \ + unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } else { \ + if(d < (1ULL<<16)) { \ + /* signed 16 */ \ + unsigned char buf[3]; \ + buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else if(d < (1ULL<<32)) { \ + /* signed 32 */ \ + unsigned char buf[5]; \ + buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ + msgpack_pack_append_buffer(x, buf, 5); \ + } else { \ + /* signed 64 */ \ + unsigned char buf[9]; \ + buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_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 */ \ + unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \ + } \ +} while(0) + +#define msgpack_pack_real_int16(x, d) \ +do { \ + if(d < -(1<<5)) { \ + if(d < -(1<<7)) { \ + /* signed 16 */ \ + unsigned char buf[3]; \ + buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* signed 8 */ \ + unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } else if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \ + } else { \ + if(d < (1<<8)) { \ + /* unsigned 8 */ \ + unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else { \ + /* unsigned 16 */ \ + unsigned char buf[3]; \ + buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_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 */ \ + unsigned char buf[5]; \ + buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ + msgpack_pack_append_buffer(x, buf, 5); \ + } else if(d < -(1<<7)) { \ + /* signed 16 */ \ + unsigned char buf[3]; \ + buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* signed 8 */ \ + unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } else if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \ + } else { \ + if(d < (1<<8)) { \ + /* unsigned 8 */ \ + unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else if(d < (1<<16)) { \ + /* unsigned 16 */ \ + unsigned char buf[3]; \ + buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* unsigned 32 */ \ + unsigned char buf[5]; \ + buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_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 */ \ + unsigned char buf[9]; \ + buf[0] = 0xd3; *(uint64_t*)&buf[1] = _msgpack_be64(d); \ + msgpack_pack_append_buffer(x, buf, 9); \ + } else { \ + /* signed 32 */ \ + unsigned char buf[5]; \ + buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ + msgpack_pack_append_buffer(x, buf, 5); \ + } \ + } else { \ + if(d < -(1<<7)) { \ + /* signed 16 */ \ + unsigned char buf[3]; \ + buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ + msgpack_pack_append_buffer(x, buf, 3); \ + } else { \ + /* signed 8 */ \ + unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } \ + } \ + } else if(d < (1<<7)) { \ + /* fixnum */ \ + msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \ + } else { \ + if(d < (1LL<<16)) { \ + if(d < (1<<8)) { \ + /* unsigned 8 */ \ + unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \ + msgpack_pack_append_buffer(x, buf, 2); \ + } else { \ + /* unsigned 16 */ \ + unsigned char buf[3]; \ + buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \ + msgpack_pack_append_buffer(x, buf, 3); \ + } \ + } else { \ + if(d < (1LL<<32)) { \ + /* unsigned 32 */ \ + unsigned char buf[5]; \ + buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \ + msgpack_pack_append_buffer(x, buf, 5); \ + } else { \ + /* unsigned 64 */ \ + unsigned char buf[9]; \ + buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_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) +{ + unsigned char buf[2] = {0xcc, TAKE8_8(d)}; + msgpack_pack_append_buffer(x, buf, 2); +} + +msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d) +{ + unsigned char buf[3]; + buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); + msgpack_pack_append_buffer(x, buf, 3); +} + +msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d) +{ + unsigned char buf[5]; + buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); + msgpack_pack_append_buffer(x, buf, 5); +} + +msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d) +{ + unsigned char buf[9]; + buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d); + msgpack_pack_append_buffer(x, buf, 9); +} + +msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d) +{ + unsigned char buf[2] = {0xd0, TAKE8_8(d)}; + msgpack_pack_append_buffer(x, buf, 2); +} + +msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d) +{ + unsigned char buf[3]; + buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); + msgpack_pack_append_buffer(x, buf, 3); +} + +msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d) +{ + unsigned char buf[5]; + buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); + msgpack_pack_append_buffer(x, buf, 5); +} + +msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d) +{ + unsigned char buf[9]; + buf[0] = 0xd3; *(uint64_t*)&buf[1] = _msgpack_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 + unsigned char buf[5]; + buf[0] = 0xca; *(uint32_t*)&buf[1] = _msgpack_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 + unsigned char buf[9]; + buf[0] = 0xcb; *(uint64_t*)&buf[1] = _msgpack_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) { + unsigned char buf[3]; + buf[0] = 0xdc; *(uint16_t*)&buf[1] = _msgpack_be16(n); + msgpack_pack_append_buffer(x, buf, 3); + } else { + unsigned char buf[5]; + buf[0] = 0xdd; *(uint32_t*)&buf[1] = _msgpack_be32(n); + 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, &TAKE8_8(d), 1); + } else if(n < 65536) { + unsigned char buf[3]; + buf[0] = 0xde; *(uint16_t*)&buf[1] = _msgpack_be16(n); + msgpack_pack_append_buffer(x, buf, 3); + } else { + unsigned char buf[5]; + buf[0] = 0xdf; *(uint32_t*)&buf[1] = _msgpack_be32(n); + 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, &TAKE8_8(d), 1); + } else if(l < 65536) { + unsigned char buf[3]; + buf[0] = 0xda; *(uint16_t*)&buf[1] = _msgpack_be16(l); + msgpack_pack_append_buffer(x, buf, 3); + } else { + unsigned char buf[5]; + buf[0] = 0xdb; *(uint32_t*)&buf[1] = _msgpack_be32(l); + 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 TAKE8_8 +#undef TAKE8_16 +#undef TAKE8_32 +#undef TAKE8_64 + +#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/salt/msgpack/sysdep.h b/salt/msgpack/sysdep.h new file mode 100644 index 0000000000..106158ea14 --- /dev/null +++ b/salt/msgpack/sysdep.h @@ -0,0 +1,94 @@ +/* + * MessagePack system dependencies + * + * 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_SYSDEP_H__ +#define MSGPACK_SYSDEP_H__ + + +#ifdef _MSC_VER +typedef __int8 int8_t; +typedef unsigned __int8 uint8_t; +typedef __int16 int16_t; +typedef unsigned __int16 uint16_t; +typedef __int32 int32_t; +typedef unsigned __int32 uint32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +#include +#include +#include +#endif + + +#ifdef _WIN32 +typedef long _msgpack_atomic_counter_t; +#define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr) +#define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr) +#else +typedef unsigned int _msgpack_atomic_counter_t; +#define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1) +#define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1) +#endif + + +#ifdef _WIN32 +#include +#else +#include /* __BYTE_ORDER */ +#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 + +#ifdef __LITTLE_ENDIAN__ + +#define _msgpack_be16(x) ntohs(x) +#define _msgpack_be32(x) ntohl(x) + +#if defined(_byteswap_uint64) +# define _msgpack_be64(x) (_byteswap_uint64(x)) +#elif defined(bswap_64) +# define _msgpack_be64(x) bswap_64(x) +#elif defined(__DARWIN_OSSwapInt64) +# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x) +#else +#define _msgpack_be64(x) \ + ( ((((uint64_t)x) << 56) & 0xff00000000000000ULL ) | \ + ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \ + ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \ + ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \ + ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \ + ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \ + ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \ + ((((uint64_t)x) >> 56) & 0x00000000000000ffULL ) ) +#endif + +#else +#define _msgpack_be16(x) (x) +#define _msgpack_be32(x) (x) +#define _msgpack_be64(x) (x) +#endif + + +#endif /* msgpack/sysdep.h */ + diff --git a/salt/msgpack/unpack.h b/salt/msgpack/unpack.h new file mode 100644 index 0000000000..0586ca86bc --- /dev/null +++ b/salt/msgpack/unpack.h @@ -0,0 +1,213 @@ +/* + * 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. + */ + +#define MSGPACK_MAX_STACK_SIZE (1024) +#include "unpack_define.h" + +typedef struct unpack_user { + int use_list; + PyObject *object_hook; + PyObject *list_hook; + const char *encoding; + const char *unicode_errors; +} 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_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) +{ + return template_callback_uint16(u, d, o); +} + + +static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_unpack_object* o) +{ + PyObject *p; + if (d > LONG_MAX) { + p = PyLong_FromUnsignedLong((unsigned long)d); + } else { + 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) +{ + PyObject *p = PyLong_FromUnsignedLongLong(d); + if (!p) + return -1; + *o = p; + 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) +{ + return template_callback_int32(u, d, o); +} + +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) +{ + 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) +{ + 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; } + +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) +{ + PyObject *p = u->use_list ? PyList_New(n) : PyTuple_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) +{ + if (u->use_list) + PyList_SET_ITEM(*c, current, o); + else + PyTuple_SET_ITEM(*c, current, o); + return 0; +} + +static inline int template_callback_array_end(unpack_user* u, msgpack_unpack_object* c) +{ + if (u->list_hook) { + PyObject *arglist = Py_BuildValue("(O)", *c); + *c = PyEval_CallObject(u->list_hook, arglist); + Py_DECREF(arglist); + } + return 0; +} + +static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o) +{ + 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) +{ + if (PyDict_SetItem(*c, k, v) == 0) { + Py_DECREF(k); + Py_DECREF(v); + return 0; + } + return -1; +} + +static inline int template_callback_map_end(unpack_user* u, msgpack_unpack_object* c) +{ + if (u->object_hook) { + PyObject *arglist = Py_BuildValue("(O)", *c); + *c = PyEval_CallObject(u->object_hook, arglist); + Py_DECREF(arglist); + } + return 0; +} + +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(u->encoding) { + py = PyUnicode_Decode(p, l, u->encoding, u->unicode_errors); + } else { + py = PyBytes_FromStringAndSize(p, l); + } + if (!py) + return -1; + *o = py; + return 0; +} + +#include "unpack_template.h" diff --git a/salt/msgpack/unpack_define.h b/salt/msgpack/unpack_define.h new file mode 100644 index 0000000000..63d90a8e54 --- /dev/null +++ b/salt/msgpack/unpack_define.h @@ -0,0 +1,92 @@ +/* + * 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 "sysdep.h" +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef MSGPACK_MAX_STACK_SIZE +#define MSGPACK_MAX_STACK_SIZE 16 +#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/salt/msgpack/unpack_template.h b/salt/msgpack/unpack_template.h new file mode 100644 index 0000000000..7a2288f1a7 --- /dev/null +++ b/salt/msgpack/unpack_template.h @@ -0,0 +1,385 @@ +/* + * 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 + +#ifndef USE_CASE_RANGE +#if !defined(_MSC_VER) +#define USE_CASE_RANGE +#endif +#endif + +msgpack_unpack_struct_decl(_stack) { + msgpack_unpack_object obj; + size_t count; + unsigned int ct; + + union { + size_t curr; + 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_be16(*(uint16_t*)ptr) +#define PTR_CAST_32(ptr) _msgpack_be32(*(uint32_t*)ptr) +#define PTR_CAST_64(ptr) _msgpack_be64(*(uint64_t*)ptr) + +#ifdef USE_CASE_RANGE +#define SWITCH_RANGE_BEGIN switch(*p) { +#define SWITCH_RANGE(FROM, TO) case FROM ... TO: +#define SWITCH_RANGE_DEFAULT default: +#define SWITCH_RANGE_END } +#else +#define SWITCH_RANGE_BEGIN { if(0) { +#define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) { +#define SWITCH_RANGE_DEFAULT } else { +#define SWITCH_RANGE_END } } +#endif + + if(p == pe) { goto _out; } + do { + switch(cs) { + case CS_HEADER: + SWITCH_RANGE_BEGIN + SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum + push_fixed_value(_uint8, *(uint8_t*)p); + SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum + push_fixed_value(_int8, *(int8_t*)p); + SWITCH_RANGE(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; + } + SWITCH_RANGE(0xa0, 0xbf) // FixRaw + again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero); + SWITCH_RANGE(0x90, 0x9f) // FixArray + start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM); + SWITCH_RANGE(0x80, 0x8f) // FixMap + start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY); + + SWITCH_RANGE_DEFAULT + goto _failed; + SWITCH_RANGE_END + // 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) { + msgpack_unpack_callback(_array_end)(user, &c->obj); + 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) { + msgpack_unpack_callback(_map_end)(user, &c->obj); + 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 + diff --git a/salt/payload.py b/salt/payload.py index d9d0b39e64..b671b52cbc 100644 --- a/salt/payload.py +++ b/salt/payload.py @@ -5,20 +5,22 @@ encrypted keys to general payload dynamics and packaging, these happen in here import cPickle as pickle +import salt.msgpack as msgpack -def package(payload, protocol=2): + +def package(payload): ''' - This method for now just wraps pickle.dumps, but it is here so that we can + This method for now just wraps msgpack.dumps, but it is here so that we can make the serialization a custom option in the future with ease. ''' - return pickle.dumps(payload, protocol) + return msgpack.dumps(payload) def unpackage(package_): ''' Unpackages a payload ''' - return pickle.loads(package_) + return msgpack.loads(package_) def format_payload(enc, **kwargs): @@ -32,3 +34,46 @@ def format_payload(enc, **kwargs): load[key] = kwargs[key] payload['load'] = load return package(payload) + +class Serial(object): + ''' + Create a serialization object, this object manages all message + serialization in Salt + ''' + def __init__(self, opts): + self.opts = opts + self.serial = self.opts.get('serial', 'msgpack') + + def loads(self, msg): + ''' + Run the correct loads serialization format + ''' + if self.serial == 'msgpack': + return msgpack.loads(msg) + elif self.serial == 'pickle': + try: + return pickle.loads(msg) + except: + return msgpack.loads(msg) + + def load(self, fn_): + ''' + Run the correct serialization to load a file + ''' + data = fn_.read() + return self.loads(data) + + def dumps(self, msg): + ''' + Run the correct dums serialization format + ''' + if self.serial == 'pickle': + return pickle.dumps(msg) + else: + return msgpack.dumps(msg) + + def dump(self, msg, fn_): + ''' + Serialize the correct data into the named file object + ''' + fn_.write(self.dumps(msg)) diff --git a/setup.py b/setup.py index fb4f36794b..82657604ba 100755 --- a/setup.py +++ b/setup.py @@ -3,16 +3,27 @@ The setup script for salt ''' +import os +import sys +from glob import glob +from distutils.core import setup, Extension +from distutils.command.sdist import sdist from distutils import log from distutils.cmd import Command from distutils.core import setup -from distutils.extension import Extension from distutils.sysconfig import get_python_lib, PREFIX -import os -import sys from salt import __version__ +try: + from Cython.Distutils import build_ext + import Cython.Compiler.Main as cython_compiler + have_cython = True +except ImportError: + from distutils.command.build_ext import build_ext + have_cython = False + + NAME = 'salt' VER = __version__ DESC = ('Portable, distributed, remote execution and ' @@ -27,6 +38,28 @@ if 'SYSCONFDIR' in os.environ: else: etc_path = os.path.join(os.path.dirname(PREFIX), 'etc') +# take care of extension modules. +if have_cython: + sources = ['salt/msgpack/_msgpack.pyx'] + + class Sdist(sdist): + def __init__(self, *args, **kwargs): + for src in glob('salt/msgpack/*.pyx'): + cython_compiler.compile(glob('msgpack/*.pyx'), + cython_compiler.default_options) + sdist.__init__(self, *args, **kwargs) +else: + sources = ['salt/msgpack/_msgpack.c'] + + Sdist = sdist + +libraries = ['ws2_32'] if sys.platform == 'win32' else [] + +msgpack_mod = Extension('salt.msgpack._msgpack', + sources=sources, + libraries=libraries, + ) + setup( name=NAME, version=VER, @@ -34,6 +67,8 @@ setup( author='Thomas S Hatch', author_email='thatch45@gmail.com', url='http://saltstack.org', + cmdclass={'build_ext': build_ext, 'sdist': Sdist}, + ext_modules=[msgpack_mod], classifiers=[ 'Programming Language :: Python', 'Programming Language :: Cython', @@ -59,6 +94,7 @@ setup( 'salt.runners', 'salt.states', 'salt.utils', + 'salt.msgpack', ], scripts=['scripts/salt-master', 'scripts/salt-minion',