summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2020-08-15 08:50:27 +0200
committerArmin Rigo <arigo@tunes.org>2020-08-15 08:50:27 +0200
commitba379eb06a1a9522cf212dc8f92d603b446a6538 (patch)
tree58be8e1c1b0909ed9c437e13dc04e75d2e56ff8a
parentbbc7fc539ddca2923b020533c811bac27da23355 (diff)
parentb3fd2323822ea82ecaf3d6e90c343a52e09da40b (diff)
downloadcffi-ba379eb06a1a9522cf212dc8f92d603b446a6538.tar.gz
update branch release-1.14 for 1.14.2
-rw-r--r--cffi/_cffi_include.h53
-rw-r--r--cffi/_embedding.h2
-rw-r--r--cffi/recompiler.py5
-rw-r--r--cffi/setuptools_ext.py8
-rw-r--r--doc/source/cdef.rst2
-rw-r--r--doc/source/embedding.rst2
-rw-r--r--doc/source/installation.rst30
-rw-r--r--doc/source/ref.rst4
-rw-r--r--doc/source/using.rst4
-rw-r--r--doc/source/whatsnew.rst40
-rw-r--r--testing/cffi1/test_recompiler.py4
11 files changed, 97 insertions, 57 deletions
diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h
index 3129150..e4c0a67 100644
--- a/cffi/_cffi_include.h
+++ b/cffi/_cffi_include.h
@@ -8,20 +8,49 @@
the same works for the other two macros. Py_DEBUG implies them,
but not the other way around.
- Issue #350 is still open: on Windows, the code here causes it to link
- with PYTHON36.DLL (for example) instead of PYTHON3.DLL. A fix was
- attempted in 164e526a5515 and 14ce6985e1c3, but reverted: virtualenv
- does not make PYTHON3.DLL available, and so the "correctly" compiled
- version would not run inside a virtualenv. We will re-apply the fix
- after virtualenv has been fixed for some time. For explanation, see
- issue #355. For a workaround if you want PYTHON3.DLL and don't worry
- about virtualenv, see issue #350. See also 'py_limited_api' in
- setuptools_ext.py.
+ The implementation is messy (issue #350): on Windows, with _MSC_VER,
+ we have to define Py_LIMITED_API even before including pyconfig.h.
+ In that case, we guess what pyconfig.h will do to the macros above,
+ and check our guess after the #include.
+
+ Note that on Windows, with CPython 3.x, you need >= 3.5 and virtualenv
+ version >= 16.0.0. With older versions of either, you don't get a
+ copy of PYTHON3.DLL in the virtualenv. We can't check the version of
+ CPython *before* we even include pyconfig.h. ffi.set_source() puts
+ a ``#define _CFFI_NO_LIMITED_API'' at the start of this file if it is
+ running on Windows < 3.5, as an attempt at fixing it, but that's
+ arguably wrong because it may not be the target version of Python.
+ Still better than nothing I guess. As another workaround, you can
+ remove the definition of Py_LIMITED_API here.
+
+ See also 'py_limited_api' in cffi/setuptools_ext.py.
*/
#if !defined(_CFFI_USE_EMBEDDING) && !defined(Py_LIMITED_API)
-# include <pyconfig.h>
-# if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
-# define Py_LIMITED_API
+# ifdef _MSC_VER
+# if !defined(_DEBUG) && !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG) && !defined(_CFFI_NO_LIMITED_API)
+# define Py_LIMITED_API
+# endif
+# include <pyconfig.h>
+ /* sanity-check: Py_LIMITED_API will cause crashes if any of these
+ are also defined. Normally, the Python file PC/pyconfig.h does not
+ cause any of these to be defined, with the exception that _DEBUG
+ causes Py_DEBUG. Double-check that. */
+# ifdef Py_LIMITED_API
+# if defined(Py_DEBUG)
+# error "pyconfig.h unexpectedly defines Py_DEBUG, but Py_LIMITED_API is set"
+# endif
+# if defined(Py_TRACE_REFS)
+# error "pyconfig.h unexpectedly defines Py_TRACE_REFS, but Py_LIMITED_API is set"
+# endif
+# if defined(Py_REF_DEBUG)
+# error "pyconfig.h unexpectedly defines Py_REF_DEBUG, but Py_LIMITED_API is set"
+# endif
+# endif
+# else
+# include <pyconfig.h>
+# if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG) && !defined(_CFFI_NO_LIMITED_API)
+# define Py_LIMITED_API
+# endif
# endif
#endif
diff --git a/cffi/_embedding.h b/cffi/_embedding.h
index b6fe359..0c2987c 100644
--- a/cffi/_embedding.h
+++ b/cffi/_embedding.h
@@ -246,7 +246,9 @@ static int _cffi_initialize_python(void)
goto done;
}
+#if PY_VERSION_HEX < 0x03080000
PyAPI_DATA(char *) _PyParser_TokenNames[]; /* from CPython */
+#endif
static int _cffi_carefully_make_gil(void)
{
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
index 1309572..1aeae5b 100644
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -7,6 +7,9 @@ VERSION_BASE = 0x2601
VERSION_EMBEDDED = 0x2701
VERSION_CHAR16CHAR32 = 0x2801
+USE_LIMITED_API = (sys.platform != 'win32' or sys.version_info < (3, 0) or
+ sys.version_info >= (3, 5))
+
class GlobalExpr:
def __init__(self, name, address, type_op, size=0, check_value=0):
@@ -283,6 +286,8 @@ class Recompiler:
prnt = self._prnt
if self.ffi._embedding is not None:
prnt('#define _CFFI_USE_EMBEDDING')
+ if not USE_LIMITED_API:
+ prnt('#define _CFFI_NO_LIMITED_API')
#
# first the '#include' (actually done by inlining the file's content)
lines = self._rel_readlines('_cffi_include.h')
diff --git a/cffi/setuptools_ext.py b/cffi/setuptools_ext.py
index df5a518..8fe3614 100644
--- a/cffi/setuptools_ext.py
+++ b/cffi/setuptools_ext.py
@@ -84,11 +84,13 @@ def _set_py_limited_api(Extension, kwds):
On Windows, with CPython <= 3.4, it's better not to use py_limited_api
because virtualenv *still* doesn't copy PYTHON3.DLL on these versions.
- For now we'll skip py_limited_api on all Windows versions to avoid an
- inconsistent mess.
+ Recently (2020) we started shipping only >= 3.5 wheels, though. So
+ we'll give it another try and set py_limited_api on Windows >= 3.5.
"""
+ from cffi import recompiler
+
if ('py_limited_api' not in kwds and not hasattr(sys, 'gettotalrefcount')
- and sys.platform != 'win32'):
+ and recompiler.USE_LIMITED_API):
import setuptools
try:
setuptools_major_version = int(setuptools.__version__.partition('.')[0])
diff --git a/doc/source/cdef.rst b/doc/source/cdef.rst
index dd56a7e..b1bbb8d 100644
--- a/doc/source/cdef.rst
+++ b/doc/source/cdef.rst
@@ -590,7 +590,7 @@ above`_ as primitive (so ``extern long long a[5];`` and ``extern int64_t a[5]``
different declarations). The reason for that is detailed in `a comment
about an issue.`__
-.. __: https://bitbucket.org/cffi/cffi/issues/265/cffi-doesnt-allow-creating-pointers-to#comment-28406958
+.. __: https://foss.heptapod.net/pypy/cffi/-/issues/265#note_50393
ffibuilder.compile() etc.: compiling out-of-line modules
diff --git a/doc/source/embedding.rst b/doc/source/embedding.rst
index 181249c..f26a0f2 100644
--- a/doc/source/embedding.rst
+++ b/doc/source/embedding.rst
@@ -380,7 +380,7 @@ inaccuracies in this paragraph or better ways to do things.)
``dlopen("libpythonX.Y.so", RTLD_LAZY|RTLD_GLOBAL)``, which will
force ``libpythonX.Y.so`` to be loaded first.
-.. __: https://bitbucket.org/cffi/cffi/issues/264/
+.. __: https://foss.heptapod.net/pypy/cffi/-/issues/264
Using multiple CFFI-made DLLs
diff --git a/doc/source/installation.rst b/doc/source/installation.rst
index 8dab03f..6b38cd2 100644
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -65,7 +65,7 @@ Download and Installation:
* ``python setup.py install`` or ``python setup_base.py install``
(should work out of the box on Linux or Windows; see below for
- `MacOS X`_ or `Windows 64`_.)
+ `MacOS X`_.)
* running the tests: ``py.test c/ testing/`` (if you didn't
install cffi yet, you need first ``python setup_base.py build_ext -f
@@ -82,9 +82,9 @@ Demos:
ultimate reference is given by the tests, notably
`testing/cffi1/test_verify1.py`_ and `testing/cffi0/backend_tests.py`_.
-.. _`demo`: https://bitbucket.org/cffi/cffi/src/default/demo
-.. _`testing/cffi1/test_verify1.py`: https://bitbucket.org/cffi/cffi/src/default/testing/cffi1/test_verify1.py
-.. _`testing/cffi0/backend_tests.py`: https://bitbucket.org/cffi/cffi/src/default/testing/cffi0/backend_tests.py
+.. _`demo`: https://foss.heptapod.net/pypy/cffi/-/tree/branch/default/demo
+.. _`testing/cffi1/test_verify1.py`: https://foss.heptapod.net/pypy/cffi/-/blob/branch/default/testing/cffi1/test_verify1.py
+.. _`testing/cffi0/backend_tests.py`: https://foss.heptapod.net/pypy/cffi/-/blob/branch/default/testing/cffi0/backend_tests.py
Platform-specific instructions
@@ -133,10 +133,10 @@ as described here_.
.. _here: http://superuser.com/questions/259278/python-2-6-1-pycrypto-2-3-pypi-package-broken-pipe-during-build
-Windows (regular 32-bit)
-++++++++++++++++++++++++
+Windows (32/64-bit)
++++++++++++++++++++
-Win32 works and is tested at least each official release.
+Win32 and Win64 work and are tested at least each official release.
The recommended C compiler compatible with Python 2.7 is this one:
http://www.microsoft.com/en-us/download/details.aspx?id=44266
@@ -150,22 +150,6 @@ For Python 3.4 and beyond:
https://www.visualstudio.com/en-us/downloads/visual-studio-2015-ctp-vs
-Windows 64
-++++++++++
-
-Win64 received very basic testing and we applied a few essential
-fixes in cffi 0.7. The comment above applies for Python 2.7 on
-Windows 64 as well. Please report any other issue.
-
-Note as usual that this is only about running the 64-bit version of
-Python on the 64-bit OS. If you're running the 32-bit version (the
-common case apparently), then you're running Win32 as far as we're
-concerned.
-
-.. _`issue 9`: https://bitbucket.org/cffi/cffi/issue/9
-.. _`Python issue 7546`: http://bugs.python.org/issue7546
-
-
Linux and OS/X: UCS2 versus UCS4
++++++++++++++++++++++++++++++++
diff --git a/doc/source/ref.rst b/doc/source/ref.rst
index 9aaed7a..1348ed6 100644
--- a/doc/source/ref.rst
+++ b/doc/source/ref.rst
@@ -459,7 +459,7 @@ destructors will be called in a random order. If you need a particular
order, see the discussion in `issue 340`__.
.. __: http://bugs.python.org/issue31105
-.. __: https://bitbucket.org/cffi/cffi/issues/340/resources-release-issues
+.. __: https://foss.heptapod.net/pypy/cffi/-/issues/340
.. _ffi-new-handle:
@@ -731,7 +731,7 @@ example::
raise IndexError("index too large!")
...
-.. __: https://bitbucket.org/cffi/cffi/issues/233/
+.. __: https://foss.heptapod.net/pypy/cffi/-/issues/233
.. _ffi-getctype:
diff --git a/doc/source/using.rst b/doc/source/using.rst
index beb3f92..fc65a4f 100644
--- a/doc/source/using.rst
+++ b/doc/source/using.rst
@@ -787,7 +787,7 @@ The ``extern "Python"`` functions cannot be variadic for now. This
may be implemented in the future. (`This demo`__ shows how to do it
anyway, but it is a bit lengthy.)
-.. __: https://bitbucket.org/cffi/cffi/src/default/demo/extern_python_varargs.py
+.. __: https://foss.heptapod.net/pypy/cffi/-/blob/branch/default/demo/extern_python_varargs.py
Each corresponding Python callback function is defined with the
``@ffi.def_extern()`` decorator. Be careful when writing this
@@ -896,7 +896,7 @@ ffi.callback() and the result is the same.
to refactor the involved code so that it no longer uses ``ffi.callback()``.
.. __: https://github.com/pyca/pyopenssl/issues/596
-.. __: https://bitbucket.org/cffi/cffi/issues/391/
+.. __: https://foss.heptapod.net/pypy/cffi/-/issues/391
.. __: https://bugzilla.redhat.com/show_bug.cgi?id=1249685
Warning: like ffi.new(), ffi.callback() returns a cdata that has
diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst
index 4b5199b..0658e0d 100644
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -3,6 +3,24 @@ What's New
======================
+v1.14.2
+=======
+
+* CPython 3 on Windows: we again try to compile with ``Py_LIMITED_API``
+ by default. This flag is not added if you run the compilation with
+ CPython 3.4, as it only works with CPython >= 3.5, but by now this
+ version of Python is quite old (and we no longer distribute cffi
+ wheels for it).
+
+ This may require that you upgrade ``virtualenv`` (requires version 16
+ or newer) or at least copy manually ``python3.dll`` into your existing
+ virtualenvs. For distributing wheels with your cffi modules, you may
+ also need to upgrade ``wheel`` to the just-released version 0.35.
+
+ You can manually disable ``Py_LIMITED_API`` by calling
+ ``ffi.set_source(..., py_limited_api=False)``.
+
+
v1.14.1
=======
@@ -55,7 +73,7 @@ v1.13.2
* re-release because the Linux wheels came with an attached version of libffi
that was very old and buggy (`issue #432`_).
-.. _`issue #432`: https://bitbucket.org/cffi/cffi/issues/432/
+.. _`issue #432`: https://foss.heptapod.net/pypy/cffi/-/issues/432
@@ -74,8 +92,8 @@ v1.13.1
* fixed `issue #427`_ where a multithreading mistake in the embedding logic
initialization code would cause deadlocks on CPython 3.7.
-.. _`issue #429`: https://bitbucket.org/cffi/cffi/issues/429/
-.. _`issue #427`: https://bitbucket.org/cffi/cffi/issues/427/
+.. _`issue #429`: https://foss.heptapod.net/pypy/cffi/-/issues/429
+.. _`issue #427`: https://foss.heptapod.net/pypy/cffi/-/issues/427
v1.13
@@ -173,7 +191,7 @@ v1.12
to 1 byte instead of 4).
.. __: cdef.html#pkgconfig
-.. _`issue #362`: https://bitbucket.org/cffi/cffi/issues/362/
+.. _`issue #362`: https://foss.heptapod.net/pypy/cffi/-/issues/362
v1.11.5
@@ -205,10 +223,10 @@ v1.11.5
concerned about virtualenv: pass ``define_macros=[("Py_LIMITED_API",
None)]`` as a keyword to the ``ffibuilder.set_source()`` call.
-.. _`Issue #345`: https://bitbucket.org/cffi/cffi/issues/345/
-.. _`Issue #350`: https://bitbucket.org/cffi/cffi/issues/350/
-.. _`Issue #358`: https://bitbucket.org/cffi/cffi/issues/358/
-.. _`Issue #357`: https://bitbucket.org/cffi/cffi/issues/357/
+.. _`Issue #345`: https://foss.heptapod.net/pypy/cffi/-/issues/345
+.. _`Issue #350`: https://foss.heptapod.net/pypy/cffi/-/issues/350
+.. _`Issue #358`: https://foss.heptapod.net/pypy/cffi/-/issues/358
+.. _`Issue #357`: https://foss.heptapod.net/pypy/cffi/-/issues/357
v1.11.4
@@ -221,7 +239,7 @@ v1.11.4
``foo.cp36-win32.pyd``, to make it clear that they are regular
CPython modules depending on ``python36.dll``.
-.. _`Issue #355`: https://bitbucket.org/cffi/cffi/issues/355/
+.. _`Issue #355`: https://foss.heptapod.net/pypy/cffi/-/issues/355
v1.11.3
@@ -310,9 +328,9 @@ v1.11
that are *slower* to call than the API mode does. For some reason it
is often thought to be faster. It is not!
-.. __: https://bitbucket.org/cffi/cffi/issues/321/cffi-191-segmentation-fault-during-self
+.. __: https://foss.heptapod.net/pypy/cffi/-/issues/321
.. __: ref.html#ffi-gc
-.. __: https://bitbucket.org/cffi/cffi/issues/320/improve-memory_pressure-management
+.. __: https://foss.heptapod.net/pypy/cffi/-/issues/320
.. __: http://bugs.python.org/issue31105
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
index 397270b..b35c3eb 100644
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -889,8 +889,8 @@ def test_unpack_args():
e7 = py.test.raises(TypeError, lib.foo2, 45, 46, 47)
def st1(s):
s = str(s)
- if s.startswith("_CFFI_test_unpack_args.CompiledLib."):
- s = s[len("_CFFI_test_unpack_args.CompiledLib."):]
+ if s.startswith("_CFFI_test_unpack_args.Lib."):
+ s = s[len("_CFFI_test_unpack_args.Lib."):]
return s
assert st1(e1.value) == "foo0() takes no arguments (1 given)"
assert st1(e2.value) == "foo0() takes no arguments (2 given)"