From 08c56d66f6eecb99850897dd3c4987dea01e6d44 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sun, 19 May 2013 01:13:21 +0900 Subject: Use --cplus for cythoning --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3fe278e..71be6af 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ doc: cd docs && make zip cython: - cython msgpack/*.pyx + cython --cplus msgpack/*.pyx python3: cython python3 setup.py build_ext -i -f -- cgit v1.2.1 From bbe86e7a925f113337f6e24d3ff24ddc30137dd6 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sun, 19 May 2013 12:30:23 +0900 Subject: Revert "Use new buffer interface." This reverts commit 085db7f8dca2b4e2497bfb291238cd3ff2d06e28. Conflicts: msgpack/_unpacker.pyx --- msgpack/_unpacker.pyx | 53 +++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx index 06806bd..2644f15 100644 --- a/msgpack/_unpacker.pyx +++ b/msgpack/_unpacker.pyx @@ -2,6 +2,10 @@ #cython: embedsignature=True from cpython cimport * +cdef extern from "Python.h": + 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 * @@ -15,8 +19,8 @@ from msgpack.exceptions import ( ) + cdef extern from "unpack.h": - ctypedef struct PyObject ctypedef struct msgpack_user: bint use_list PyObject* object_hook @@ -87,33 +91,32 @@ def unpackb(object packed, object object_hook=None, object list_hook=None, cdef size_t off = 0 cdef int ret - cdef Py_buffer buff + cdef char* buf + cdef Py_ssize_t buf_len cdef char* cenc = NULL cdef char* cerr = NULL - PyObject_GetBuffer(packed, &buff, PyBUF_SIMPLE) - try: - if encoding is not None: - if isinstance(encoding, unicode): - encoding = encoding.encode('ascii') - cenc = PyBytes_AsString(encoding) - - if unicode_errors is not None: - if isinstance(unicode_errors, unicode): - unicode_errors = unicode_errors.encode('ascii') - cerr = PyBytes_AsString(unicode_errors) - - init_ctx(&ctx, object_hook, object_pairs_hook, list_hook, use_list, cenc, cerr) - ret = unpack_construct(&ctx, buff.buf, buff.len, &off) - if ret == 1: - obj = unpack_data(&ctx) - if off < buff.len: - raise ExtraData(obj, PyBytes_FromStringAndSize(buff.buf+off, buff.len-off)) - return obj - else: - raise UnpackValueError("Unpack failed: error = %d" % (ret,)) - finally: - PyBuffer_Release(&buff) + PyObject_AsReadBuffer(packed, &buf, &buf_len) + + if encoding is not None: + if isinstance(encoding, unicode): + encoding = encoding.encode('ascii') + cenc = PyBytes_AsString(encoding) + + if unicode_errors is not None: + if isinstance(unicode_errors, unicode): + unicode_errors = unicode_errors.encode('ascii') + cerr = PyBytes_AsString(unicode_errors) + + init_ctx(&ctx, object_hook, object_pairs_hook, list_hook, use_list, cenc, cerr) + ret = unpack_construct(&ctx, buf, buf_len, &off) + if ret == 1: + obj = unpack_data(&ctx) + if off < buf_len: + raise ExtraData(obj, PyBytes_FromStringAndSize(buf+off, buf_len-off)) + return obj + else: + raise UnpackValueError("Unpack failed: error = %d" % (ret,)) def unpack(object stream, object object_hook=None, object list_hook=None, -- cgit v1.2.1 From 956f55ecdf3b98e8072b4073da650e9a8fa05e0b Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sun, 19 May 2013 12:32:33 +0900 Subject: Stop using const_void_ptr typedef. New Cython supports const natively. --- msgpack/_unpacker.pyx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx index 2644f15..9ff1085 100644 --- a/msgpack/_unpacker.pyx +++ b/msgpack/_unpacker.pyx @@ -3,9 +3,8 @@ from cpython cimport * cdef extern from "Python.h": - 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 + cdef int PyObject_AsReadBuffer(object o, const void* buff, Py_ssize_t* buf_len) except -1 from libc.stdlib cimport * from libc.string cimport * @@ -96,7 +95,7 @@ def unpackb(object packed, object object_hook=None, object list_hook=None, cdef char* cenc = NULL cdef char* cerr = NULL - PyObject_AsReadBuffer(packed, &buf, &buf_len) + PyObject_AsReadBuffer(packed, &buf, &buf_len) if encoding is not None: if isinstance(encoding, unicode): -- cgit v1.2.1