diff options
author | Armin Rigo <arigo@tunes.org> | 2016-07-19 08:40:36 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2016-07-19 08:40:36 +0200 |
commit | bbae5839c3c0ae7f1ee6792ef2e4adf63f9acbc2 (patch) | |
tree | 6f6400f29f4de22659b5f36bde5dd9b68191a4cf | |
parent | c09faaf402f0142ed6df0e1451d7458d50494596 (diff) | |
download | cffi-bbae5839c3c0ae7f1ee6792ef2e4adf63f9acbc2.tar.gz |
Use Py_LIMITED_API in the generated C extension modules, because doing
so seems easy. Still need to check if and how we have to produce the
actual .so files.
-rw-r--r-- | cffi/_cffi_include.h | 14 | ||||
-rw-r--r-- | cffi/recompiler.py | 10 | ||||
-rw-r--r-- | testing/cffi1/test_recompiler.py | 9 |
3 files changed, 11 insertions, 22 deletions
diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h index a72c132..6b73ca7 100644 --- a/cffi/_cffi_include.h +++ b/cffi/_cffi_include.h @@ -196,20 +196,6 @@ static PyObject *_cffi_init(const char *module_name, Py_ssize_t version, return NULL; } -_CFFI_UNUSED_FN -static PyObject **_cffi_unpack_args(PyObject *args_tuple, Py_ssize_t expected, - const char *fnname) -{ - if (PyTuple_GET_SIZE(args_tuple) != expected) { - PyErr_Format(PyExc_TypeError, - "%.150s() takes exactly %zd arguments (%zd given)", - fnname, expected, PyTuple_GET_SIZE(args_tuple)); - return NULL; - } - return &PyTuple_GET_ITEM(args_tuple, 0); /* pointer to the first item, - the others follow */ -} - /********** end CPython-specific section **********/ #else _CFFI_UNUSED_FN diff --git a/cffi/recompiler.py b/cffi/recompiler.py index b83fade..0aed988 100644 --- a/cffi/recompiler.py +++ b/cffi/recompiler.py @@ -275,6 +275,8 @@ class Recompiler: def write_c_source_to_f(self, f, preamble): self._f = f prnt = self._prnt + if self.ffi._embedding is None: + prnt('#define Py_LIMITED_API') # # first the '#include' (actually done by inlining the file's content) lines = self._rel_readlines('_cffi_include.h') @@ -683,13 +685,11 @@ class Recompiler: rng = range(len(tp.args)) for i in rng: prnt(' PyObject *arg%d;' % i) - prnt(' PyObject **aa;') prnt() - prnt(' aa = _cffi_unpack_args(args, %d, "%s");' % (len(rng), name)) - prnt(' if (aa == NULL)') + prnt(' if (!PyArg_UnpackTuple(args, "%s", %d, %d, %s))' % ( + name, len(rng), len(rng), + ', '.join(['&arg%d' % i for i in rng]))) prnt(' return NULL;') - for i in rng: - prnt(' arg%d = aa[%d];' % (i, i)) prnt() # for i, type in enumerate(tp.args): diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py index 4185cf4..1bd1da2 100644 --- a/testing/cffi1/test_recompiler.py +++ b/testing/cffi1/test_recompiler.py @@ -851,9 +851,12 @@ def test_unpack_args(): assert str(e2.value) == "foo0() takes no arguments (2 given)" assert str(e3.value) == "foo1() takes exactly one argument (0 given)" assert str(e4.value) == "foo1() takes exactly one argument (2 given)" - assert str(e5.value) == "foo2() takes exactly 2 arguments (0 given)" - assert str(e6.value) == "foo2() takes exactly 2 arguments (1 given)" - assert str(e7.value) == "foo2() takes exactly 2 arguments (3 given)" + assert str(e5.value) in ["foo2 expected 2 arguments, got 0", + "foo2() takes exactly 2 arguments (0 given)"] + assert str(e6.value) in ["foo2 expected 2 arguments, got 1", + "foo2() takes exactly 2 arguments (1 given)"] + assert str(e7.value) in ["foo2 expected 2 arguments, got 3", + "foo2() takes exactly 2 arguments (3 given)"] def test_address_of_function(): ffi = FFI() |