[pypy-commit] cffi default: Avoid a combination where we end up with two incompatible "typedef xxx

arigo pypy.commits at gmail.com
Sat Aug 6 16:13:57 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r2735:d9c892b5a64b
Date: 2016-08-06 22:16 +0200
http://bitbucket.org/cffi/cffi/changeset/d9c892b5a64b/

Log:	Avoid a combination where we end up with two incompatible "typedef
	xxx _Bool;"

diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h
--- a/cffi/_cffi_include.h
+++ b/cffi/_cffi_include.h
@@ -42,7 +42,9 @@
 #  include <stdint.h>
 # endif
 # if _MSC_VER < 1800   /* MSVC < 2013 */
-   typedef unsigned char _Bool;
+#  ifndef __cplusplus
+    typedef unsigned char _Bool;
+#  endif
 # endif
 #else
 # include <stdint.h>
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
@@ -1919,6 +1919,18 @@
     lib = verify(ffi, "test_bool_in_cpp", "char f(void) { return 2; }")
     assert lib.f() == 1
 
+def test_bool_in_cpp_2():
+    ffi = FFI()
+    ffi.cdef('int add(int a, int b);')
+    lib = verify(ffi, "test_bool_bug_cpp", '''
+        typedef bool _Bool;  /* there is a Windows header with this line */
+        int add(int a, int b)
+        {
+            return a + b;
+        }''', source_extension='.cpp')
+    c = lib.add(2, 3)
+    assert c == 5
+
 def test_struct_field_opaque():
     ffi = FFI()
     ffi.cdef("struct a { struct b b; };")


More information about the pypy-commit mailing list