[pypy-svn] r61571 - pypy/trunk/pypy/rpython/lltypesystem

afa at codespeak.net afa at codespeak.net
Fri Feb 6 11:28:37 CET 2009


Author: afa
Date: Fri Feb  6 11:28:35 2009
New Revision: 61571

Modified:
   pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
Log:
When extracting data from structs, ctypes automatically converts 
arrays of c_wchar into unicode strings.
Use another integer type instead, with the same size.


Modified: pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py	Fri Feb  6 11:28:35 2009
@@ -41,9 +41,16 @@
         rffi.LONGLONG:   ctypes.c_longlong,
         rffi.ULONGLONG:  ctypes.c_ulonglong,
         rffi.SIZE_T:     ctypes.c_size_t,
-        lltype.UniChar:  ctypes.c_wchar,
         })
 
+    # for unicode strings, do not use ctypes.c_wchar because ctypes
+    # automatically converts arrays into unicode strings.
+    # Pick the unsigned int that has the same size.
+    if ctypes.sizeof(ctypes.c_wchar) == ctypes.sizeof(ctypes.c_uint16):
+        _ctypes_cache[lltype.UniChar] = ctypes.c_uint16
+    else:
+        _ctypes_cache[lltype.UniChar] = ctypes.c_uint32
+
 def build_ctypes_struct(S, delayed_builders, max_n=None):
     def builder():
         # called a bit later to fill in _fields_



More information about the Pypy-commit mailing list