Author: Armin Rigo <[email protected]>
Branch: wchar_t
Changeset: r487:d8685cc0c8ec
Date: 2012-06-23 08:13 +0200
http://bitbucket.org/cffi/cffi/changeset/d8685cc0c8ec/

Log:    Let's say that wchar_t is unsigned if and only if it is 2 bytes.

diff --git a/c/_ffi_backend.c b/c/_ffi_backend.c
--- a/c/_ffi_backend.c
+++ b/c/_ffi_backend.c
@@ -27,7 +27,7 @@
 /* base type flag: exactly one of the following: */
 #define CT_PRIMITIVE_SIGNED   1    /* signed integer */
 #define CT_PRIMITIVE_UNSIGNED 2    /* unsigned integer */
-#define CT_PRIMITIVE_CHAR     4    /* char (and, later, wchar_t) */
+#define CT_PRIMITIVE_CHAR     4    /* char, wchar_t */
 #define CT_PRIMITIVE_FLOAT    8    /* float, double */
 #define CT_POINTER           16    /* pointer, excluding ptr-to-func */
 #define CT_ARRAY             32    /* array */
@@ -2170,7 +2170,8 @@
         { "ptrdiff_t",     sizeof(ptrdiff_t) },
         { "size_t",        sizeof(size_t) | UNSIGNED },
         { "ssize_t",       sizeof(ssize_t) },
-        /*{ "wchar_t",       sizeof(wchar_t) | UNSIGNED },*/
+        { "wchar_t",       sizeof(wchar_t) |
+                               (sizeof(wchar_t) < 4 ? UNSIGNED : 0 },
         { NULL }
     };
 #undef UNSIGNED
diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py
--- a/cffi/backend_ctypes.py
+++ b/cffi/backend_ctypes.py
@@ -223,7 +223,10 @@
                 result['size_t'] = size | UNSIGNED
                 result['ssize_t'] = size
             if size == ctypes.sizeof(ctypes.c_wchar):
-                result['wchar_t'] = size | UNSIGNED
+                if size < 4:
+                    result['wchar_t'] = size | UNSIGNED
+                else:
+                    result['wchar_t'] = size
         return result
 
     def load_library(self, path):
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -8,6 +8,8 @@
 SIZE_OF_PTR   = ctypes.sizeof(ctypes.c_void_p)
 SIZE_OF_WCHAR = ctypes.sizeof(ctypes.c_wchar)
 
+WCHAR_IS_UNSIGNED = (SIZE_OF_WCHAR < 4)
+
 
 class BackendTests:
 
@@ -41,7 +43,7 @@
         self._test_int_type(ffi, 'ptrdiff_t', SIZE_OF_PTR, False)
         self._test_int_type(ffi, 'size_t', SIZE_OF_PTR, True)
         self._test_int_type(ffi, 'ssize_t', SIZE_OF_PTR, False)
-        self._test_int_type(ffi, 'wchar_t', SIZE_OF_WCHAR, True)
+        self._test_int_type(ffi, 'wchar_t', SIZE_OF_WCHAR, WCHAR_IS_UNSIGNED)
 
     def _test_int_type(self, ffi, c_decl, size, unsigned):
         if unsigned:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to