Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r2975:5f90dcd1ce55
Date: 2017-06-04 16:18 +0200
http://bitbucket.org/cffi/cffi/changeset/5f90dcd1ce55/

Log:    Didn't figure out how to cleanly define charN_t inside
        _cffi_include.h. So for now, don't.

diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h
--- a/cffi/_cffi_include.h
+++ b/cffi/_cffi_include.h
@@ -62,16 +62,11 @@
     typedef unsigned char _Bool;
 #  endif
 # endif
-# if _MSC_VER < 1900 || !defined(__cplusplus)   /* MSVC < 2015, or plain C */
-    typedef uint16_t char16_t;
-    typedef uint32_t char32_t;
-# endif
 #else
 # include <stdint.h>
 # if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
 #  include <alloca.h>
 # endif
-# include <uchar.h>
 #endif
 
 #ifdef __GNUC__
diff --git a/cffi/vengine_cpy.py b/cffi/vengine_cpy.py
--- a/cffi/vengine_cpy.py
+++ b/cffi/vengine_cpy.py
@@ -808,7 +808,8 @@
 #include <stddef.h>
 
 /* this block of #ifs should be kept exactly identical between
-   c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py */
+   c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py
+   and cffi/_cffi_include.h */
 #if defined(_MSC_VER)
 # include <malloc.h>   /* for alloca() */
 # if _MSC_VER < 1600   /* MSVC < 2010 */
@@ -842,11 +843,13 @@
 #  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>
-# if (defined (__SVR4) && defined (__sun)) || defined(_AIX)
+# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
 #  include <alloca.h>
 # endif
 #endif
diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py
--- a/cffi/vengine_gen.py
+++ b/cffi/vengine_gen.py
@@ -627,7 +627,8 @@
 #include <sys/types.h>   /* XXX for ssize_t on some platforms */
 
 /* this block of #ifs should be kept exactly identical between
-   c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py */
+   c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py
+   and cffi/_cffi_include.h */
 #if defined(_MSC_VER)
 # include <malloc.h>   /* for alloca() */
 # if _MSC_VER < 1600   /* MSVC < 2010 */
@@ -661,11 +662,13 @@
 #  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>
-# if (defined (__SVR4) && defined (__sun)) || defined(_AIX)
+# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
 #  include <alloca.h>
 # endif
 #endif
diff --git a/doc/source/ref.rst b/doc/source/ref.rst
--- a/doc/source/ref.rst
+++ b/doc/source/ref.rst
@@ -629,9 +629,9 @@
 |               | or another <cdata char>| length 1         | ``<``          |
 +---------------+------------------------+------------------+----------------+
 | ``wchar_t``,  | a unicode of length 1  | a unicode of     |                |
-| ``char16_t``, | (or maybe 2 if         | length 1         | int() `[8]`,   |
+| ``char16_t``, | (or maybe 2 if         | length 1         | int(),         |
 | ``char32_t``  | surrogates) or         | (or maybe 2 if   | bool(), ``<``  |
-|               | another similar <cdata>| surrogates)      |                |
+| `[8]`         | another similar <cdata>| surrogates)      |                |
 +---------------+------------------------+------------------+----------------+
 |  ``float``,   | a float or anything on | a Python float   | float(), int(),|
 |  ``double``   | which float() works    |                  | bool(), ``<``  |
@@ -774,12 +774,22 @@
    take directly as argument types or return type a complex type cannot
    be called by CFFI, unless they are directly using the API mode.
 
-`[8]` sign of ``wchar_t``, ``char16_t`` and ``char32_t``
+`[8]` ``wchar_t``, ``char16_t`` and ``char32_t``
 
    The ``wchar_t`` type has the same signedness as the underlying
    platform's.  For example, on Linux, it is a signed 32-bit integer.
    However, the types ``char16_t`` and ``char32_t`` (*new in version
-   1.11*) are always unsigned.
+   1.11*) are always unsigned.  **Warning:** for now, if you use
+   ``char16_t`` and ``char32_t`` with ``cdef()`` and ``set_source()``,
+   you have to make sure yourself that the types are declared by the C
+   source you provide to ``set_source()``.  They would be declared if
+   you ``#include`` a library that explicitly uses them, for example,
+   or when using C++11.  Otherwise, you need ``#include <uchar.h>`` on
+   Linux, or more generally something like ``typedef uint_least16_t
+   char16_t;``.  This is not done automatically by CFFI because
+   ``uchar.h`` is not standard across platforms, and writing a
+   ``typedef`` like above would crash if the type happens to be
+   already defined.
 
 .. _file:
 
diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst
--- a/doc/source/whatsnew.rst
+++ b/doc/source/whatsnew.rst
@@ -11,7 +11,9 @@
   when used as ``charN_t *`` or ``charN_t[]`` they represent a unicode
   string.  The difference with ``wchar_t`` is that they have a known,
   fixed size.  They should work at all places that used to work with
-  ``wchar_t`` (please report an issue if I missing something).
+  ``wchar_t`` (please report an issue if I missing something).  Note
+  that with ``set_source()``, you need to make sure that these types are
+  actually defined by the C source you provide (if used in ``cdef()``).
 
 * Support the C99 types ``float _Complex`` and ``double _Complex``.
   Note that libffi doesn't support them, which means that in the ABI
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
@@ -2265,6 +2265,11 @@
         char32_t foo_4bytes(char32_t);
     """)
     lib = verify(ffi, "test_char16_char32_type" + no_cpp * "_nocpp", """
+    #if !defined(__cplusplus) || __cplusplus < 201103L
+    typedef uint_least16_t char16_t;
+    typedef uint_least32_t char32_t;
+    #endif
+    
     char16_t foo_2bytes(char16_t a) { return (char16_t)(a + 42); }
     char32_t foo_4bytes(char32_t a) { return (char32_t)(a + 42); }
     """, no_cpp=no_cpp)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to