summaryrefslogtreecommitdiff
path: root/cffi
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2018-01-08 11:03:58 +0100
committerArmin Rigo <arigo@tunes.org>2018-01-08 11:03:58 +0100
commit5783ccab8f1d2e5cddd31c2e4d79b02c19d80303 (patch)
treec80af76d3538886cc7c2b41d28fa036e5e053c8c /cffi
parentd75c603bd9a87d9bf2f9ff4a2260d8b657fa845d (diff)
downloadcffi-5783ccab8f1d2e5cddd31c2e4d79b02c19d80303.tar.gz
Issue #350: more mess on Windows with Py_LIMITED_API
Diffstat (limited to 'cffi')
-rw-r--r--cffi/_cffi_include.h33
1 files changed, 30 insertions, 3 deletions
diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h
index 4f8ef82..d460cef 100644
--- a/cffi/_cffi_include.h
+++ b/cffi/_cffi_include.h
@@ -7,11 +7,38 @@
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.
+
+ Issue #350: more mess: on Windows, 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.
*/
#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 _WIN32
+# if !defined(_DEBUG) && !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
+# 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 _DEBUG is not set"
+# endif
+# if defined(Py_TRACE_REFS)
+# error "pyconfig.h unexpectedly defines Py_TRACE_REFS"
+# endif
+# if defined(Py_REF_DEBUG)
+# error "pyconfig.h unexpectedly defines Py_REF_DEBUG"
+# endif
+# endif
+# else
+# include <pyconfig.h>
+# if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
+# define Py_LIMITED_API
+# endif
# endif
#endif