[pypy-commit] cffi default: Defines the macro _CFFI_ before including Python.h.

arigo noreply at buildbot.pypy.org
Fri May 22 00:52:45 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r2081:830539fa4f81
Date: 2015-05-22 00:53 +0200
http://bitbucket.org/cffi/cffi/changeset/830539fa4f81/

Log:	Defines the macro _CFFI_ before including Python.h.

diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h
--- a/cffi/_cffi_include.h
+++ b/cffi/_cffi_include.h
@@ -1,3 +1,4 @@
+#define _CFFI_
 #include <Python.h>
 #ifdef __cplusplus
 extern "C" {
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -761,3 +761,18 @@
     py.test.raises(AttributeError, ffi.addressof, lib, 'unknown_var')
     py.test.raises(AttributeError, ffi.addressof, lib, "FOOBAR")
     assert ffi.addressof(lib, 'FetchRectBottom') == lib.FetchRectBottom
+
+def test_defines__CFFI_():
+    # Check that we define the macro _CFFI_ automatically.
+    # It should be done before including Python.h, so that PyPy's Python.h
+    # can check for it.
+    ffi = FFI()
+    ffi.cdef("""
+        #define CORRECT 1
+    """)
+    lib = verify(ffi, "test_defines__CFFI_", """
+    #ifdef _CFFI_
+    #    define CORRECT 1
+    #endif
+    """)
+    assert lib.CORRECT == 1


More information about the pypy-commit mailing list