Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r2707:c417e08b79b7
Date: 2016-06-05 22:01 +0200
http://bitbucket.org/cffi/cffi/changeset/c417e08b79b7/

Log:    Test and fix: the "bool" type in C++

diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h
--- a/cffi/_cffi_include.h
+++ b/cffi/_cffi_include.h
@@ -57,6 +57,12 @@
 # define _CFFI_UNUSED_FN  /* nothing */
 #endif
 
+#ifdef __cplusplus
+# ifndef _Bool
+#  define _Bool bool   /* semi-hackish: C++ has no _Bool; bool is builtin */
+# endif
+#endif
+
 /**********  CPython-specific section  **********/
 #ifndef PYPY_VERSION
 
diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -26,6 +26,10 @@
   *numbers* instead of *characters*.  (Now it is implemented with just
   a memcpy, of course, not actually iterating over the characters.)
 
+* C++: compiling the generated C code with C++ is supposed to work,
+  but failed if you make use the ``bool`` type (because that is rendered
+  as the C ``_Bool`` type, which doesn't exist in C++).
+
 
 v1.6
 ====
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
@@ -1908,3 +1908,10 @@
     assert ffi.list_types() == (['CFFIb', 'CFFIbb', 'CFFIbbb'],
                                 ['CFFIa', 'CFFIcc', 'CFFIccc'],
                                 ['CFFIaa', 'CFFIaaa', 'CFFIg'])
+
+def test_bool_in_cpp():
+    # this works when compiled as C, but in cffi < 1.7 it fails as C++
+    ffi = FFI()
+    ffi.cdef("bool f(void);")
+    lib = verify(ffi, "test_bool_in_cpp", "char f(void) { return 2; }")
+    assert lib.f() == 1
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to