mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +00:00
parent
2b5f59166b
commit
d782464c91
10 changed files with 17 additions and 40 deletions
|
@ -45,7 +45,7 @@ install:
|
|||
|
||||
script:
|
||||
- python -c 'import sys; print(hex(sys.maxsize))'
|
||||
- python -c 'from msgpack import _msgpack'
|
||||
- python -c 'from msgpack import _cmsgpack'
|
||||
- pytest -v test
|
||||
- MSGPACK_PUREPYTHON=x pytest -v test
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ all: cython
|
|||
|
||||
.PHONY: cython
|
||||
cython:
|
||||
cython --cplus msgpack/_msgpack.pyx
|
||||
cython --cplus msgpack/_cmsgpack.pyx
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
|
|
|
@ -6,8 +6,9 @@ environment:
|
|||
|
||||
install:
|
||||
# We need wheel installed to build wheels
|
||||
- "%PYTHON%\\python.exe -m pip install -U pip"
|
||||
- "%PYTHON%\\python.exe -m pip install -U cython"
|
||||
- "%PYTHON%\\Scripts\\cython --cplus msgpack/_packer.pyx msgpack/_unpacker.pyx"
|
||||
- "%PYTHON%\\Scripts\\cython --cplus msgpack/_cmsgpack.pyx"
|
||||
|
||||
build: off
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ for V in cp36-cp36m cp35-cp35m cp27-cp27m cp27-cp27mu; do
|
|||
$PYBIN/pip install pytest
|
||||
pushd test # prevent importing msgpack package in current directory.
|
||||
$PYBIN/python -c 'import sys; print(hex(sys.maxsize))'
|
||||
$PYBIN/python -c 'from msgpack import _msgpack' # Ensure extension is available
|
||||
$PYBIN/python -c 'from msgpack import _cmsgpack' # Ensure extension is available
|
||||
$PYBIN/pytest -v .
|
||||
popd
|
||||
done
|
||||
|
|
|
@ -22,7 +22,7 @@ if os.environ.get('MSGPACK_PUREPYTHON'):
|
|||
from msgpack.fallback import Packer, unpackb, Unpacker
|
||||
else:
|
||||
try:
|
||||
from msgpack._msgpack import Packer, unpackb, Unpacker
|
||||
from msgpack._cmsgpack import Packer, unpackb, Unpacker
|
||||
except ImportError:
|
||||
from msgpack.fallback import Packer, unpackb, Unpacker
|
||||
|
||||
|
|
4
msgpack/_cmsgpack.pyx
Normal file
4
msgpack/_cmsgpack.pyx
Normal file
|
@ -0,0 +1,4 @@
|
|||
# coding: utf-8
|
||||
#cython: embedsignature=True, c_string_encoding=ascii, language_level=2
|
||||
include "_packer.pyx"
|
||||
include "_unpacker.pyx"
|
|
@ -1,4 +0,0 @@
|
|||
# coding: utf-8
|
||||
#cython: embedsignature=True, c_string_encoding=ascii
|
||||
include "_packer.pyx"
|
||||
include "_unpacker.pyx"
|
|
@ -1,9 +1,7 @@
|
|||
# coding: utf-8
|
||||
#cython: embedsignature=True, c_string_encoding=ascii
|
||||
|
||||
from cpython cimport *
|
||||
from cpython.version cimport PY_MAJOR_VERSION
|
||||
from cpython.exc cimport PyErr_WarnEx
|
||||
from cpython.bytearray cimport PyByteArray_Check, PyByteArray_CheckExact
|
||||
|
||||
from msgpack import ExtType
|
||||
|
||||
|
@ -11,8 +9,6 @@ from msgpack import ExtType
|
|||
cdef extern from "Python.h":
|
||||
|
||||
int PyMemoryView_Check(object obj)
|
||||
int PyByteArray_Check(object obj)
|
||||
int PyByteArray_CheckExact(object obj)
|
||||
char* PyUnicode_AsUTF8AndSize(object obj, Py_ssize_t *l) except NULL
|
||||
|
||||
|
||||
|
@ -204,7 +200,7 @@ cdef class Packer(object):
|
|||
elif PyBytesLike_CheckExact(o) if strict_types else PyBytesLike_Check(o):
|
||||
L = len(o)
|
||||
if L > ITEM_LIMIT:
|
||||
raise ValueError("%s is too large" % type(o).__name__)
|
||||
PyErr_Format(ValueError, b"%.200s object is too large", Py_TYPE(o).tp_name)
|
||||
rawval = o
|
||||
ret = msgpack_pack_bin(&self.pk, L)
|
||||
if ret == 0:
|
||||
|
@ -280,7 +276,7 @@ cdef class Packer(object):
|
|||
default_used = 1
|
||||
continue
|
||||
else:
|
||||
raise TypeError("can't serialize %r" % (o,))
|
||||
PyErr_Format(TypeError, b"can not serialize '%.200s' object", Py_TYPE(o).tp_name)
|
||||
return ret
|
||||
|
||||
cpdef pack(self, object obj):
|
||||
|
|
|
@ -1,26 +1,6 @@
|
|||
# coding: utf-8
|
||||
#cython: embedsignature=True, c_string_encoding=ascii
|
||||
|
||||
from cpython.version cimport PY_MAJOR_VERSION
|
||||
from cpython.bytes cimport (
|
||||
PyBytes_AsString,
|
||||
PyBytes_FromStringAndSize,
|
||||
PyBytes_Size,
|
||||
)
|
||||
from cpython.buffer cimport (
|
||||
Py_buffer,
|
||||
PyObject_CheckBuffer,
|
||||
PyObject_GetBuffer,
|
||||
PyBuffer_Release,
|
||||
PyBuffer_IsContiguous,
|
||||
PyBUF_READ,
|
||||
PyBUF_SIMPLE,
|
||||
PyBUF_FULL_RO,
|
||||
)
|
||||
from cpython.mem cimport PyMem_Malloc, PyMem_Free
|
||||
from cpython.object cimport PyCallable_Check
|
||||
from cpython.ref cimport Py_DECREF
|
||||
from cpython.exc cimport PyErr_WarnEx
|
||||
from cpython cimport *
|
||||
|
||||
cdef extern from "Python.h":
|
||||
ctypedef struct PyObject
|
||||
|
|
6
setup.py
6
setup.py
|
@ -68,7 +68,7 @@ if len(version) > 3 and version[3] != 'final':
|
|||
if have_cython:
|
||||
class Sdist(sdist):
|
||||
def __init__(self, *args, **kwargs):
|
||||
cythonize('msgpack/_msgpack.pyx')
|
||||
cythonize('msgpack/_cmsgpack.pyx')
|
||||
sdist.__init__(self, *args, **kwargs)
|
||||
else:
|
||||
Sdist = sdist
|
||||
|
@ -84,8 +84,8 @@ else:
|
|||
|
||||
ext_modules = []
|
||||
if not hasattr(sys, 'pypy_version_info'):
|
||||
ext_modules.append(Extension('msgpack._msgpack',
|
||||
sources=['msgpack/_msgpack.cpp'],
|
||||
ext_modules.append(Extension('msgpack._cmsgpack',
|
||||
sources=['msgpack/_cmsgpack.cpp'],
|
||||
libraries=libraries,
|
||||
include_dirs=['.'],
|
||||
define_macros=macros,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue