diff options
author | Armin Rigo <arigo@tunes.org> | 2016-09-03 12:36:14 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2016-09-03 12:36:14 +0200 |
commit | 059c3f955d5f979ed28dd973dfce058355c814c0 (patch) | |
tree | 959d90c7244d419bbe8904df417513493352ae0e | |
parent | bbe653193b3d98a547e4bd0838b3ef6be80ca381 (diff) | |
download | cffi-059c3f955d5f979ed28dd973dfce058355c814c0.tar.gz |
If we say Py_LIMITED_API and we're compiling with a debug version of
CPython, "#include <Python.h>" crashes. Work around it the hard way.
-rw-r--r-- | cffi/_cffi_include.h | 16 | ||||
-rw-r--r-- | cffi/recompiler.py | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h index dee5e81..cd0219f 100644 --- a/cffi/_cffi_include.h +++ b/cffi/_cffi_include.h @@ -1,4 +1,20 @@ #define _CFFI_ + +/* We try to define Py_LIMITED_API before including Python.h. + + Mess: we can only define it if Py_DEBUG, Py_TRACE_REFS and + Py_REF_DEBUG are not defined. This is a best-effort approximation: + we can learn about Py_DEBUG from pyconfig.h, but it is unclear if + the same works for the other two macros. Py_DEBUG implies them, + but not the other way around. +*/ +#ifndef _CFFI_USE_EMBEDDING +# include <pyconfig.h> +# if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG) +# define Py_LIMITED_API +# endif +#endif + #include <Python.h> #ifdef __cplusplus extern "C" { diff --git a/cffi/recompiler.py b/cffi/recompiler.py index 8e66d1c..0bd0045 100644 --- a/cffi/recompiler.py +++ b/cffi/recompiler.py @@ -275,8 +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') + if self.ffi._embedding is not None: + prnt('#define _CFFI_USE_EMBEDDING') # # first the '#include' (actually done by inlining the file's content) lines = self._rel_readlines('_cffi_include.h') |