[pypy-svn] r50978 - in pypy/dist/pypy/rpython/lltypesystem: . test

fijal at codespeak.net fijal at codespeak.net
Thu Jan 24 17:25:22 CET 2008


Author: fijal
Date: Thu Jan 24 17:25:22 2008
New Revision: 50978

Modified:
   pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
   pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
Kill obscurity (not sure if wchar is always the size of unsigned short)


Modified: pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py	Thu Jan 24 17:25:22 2008
@@ -41,7 +41,7 @@
         rffi.LONGLONG:   ctypes.c_longlong,
         rffi.ULONGLONG:  ctypes.c_ulonglong,
         rffi.SIZE_T:     ctypes.c_size_t,
-        lltype.UniChar:  ctypes.c_wchar,
+        lltype.UniChar:  ctypes.c_ushort,
         })
 
 def build_ctypes_struct(S, delayed_builders, max_n=None):
@@ -234,14 +234,9 @@
     carray = cls._malloc(container.getlength())
     add_storage(container, _array_mixin, carray)
     if not isinstance(ARRAY.OF, lltype.ContainerType):
-        # XXX obscure case when array.items is not modifiable
-        if isinstance(carray.items, unicode):
-            carray.items = u''.join([container.items[i] for i in
-                                     range(container.getlength())])
-        else:
-            for i in range(container.getlength()):
-                item_value = container.items[i]    # fish fish
-                carray.items[i] = lltype2ctypes(item_value)
+        for i in range(container.getlength()):
+            item_value = container.items[i]    # fish fish
+            carray.items[i] = lltype2ctypes(item_value)
         remove_regular_array_content(container)
     else:
         assert isinstance(ARRAY.OF, lltype.Struct)

Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	Thu Jan 24 17:25:22 2008
@@ -21,6 +21,7 @@
         assert lltype2ctypes(5) == 5
         assert lltype2ctypes('?') == ord('?')
         assert lltype2ctypes('\xE0') == 0xE0
+        assert lltype2ctypes(unichr(1234)) == 1234
         assert ctypes2lltype(lltype.Signed, 5) == 5
         assert ctypes2lltype(lltype.Char, ord('a')) == 'a'
         assert ctypes2lltype(lltype.UniChar, ord(u'x')) == u'x'
@@ -144,14 +145,15 @@
 
     def test_unicharp(self):
         SP = rffi.CArrayPtr(lltype.UniChar)
-        s = lltype.malloc(SP.TO, 3, flavor='raw')
+        s = lltype.malloc(SP.TO, 4, flavor='raw')
         s[0] = u'x'
         s[1] = u'y'
         s[2] = u'z'
+        s[3] = u'\x00'
         sc = lltype2ctypes(s, normalize=False)
-        assert sc.contents.items[0] == u'x'
-        assert sc.contents.items[1] == u'y'
-        assert sc.contents.items[2] == u'z'
+        assert sc.contents.items[0] == ord(u'x')
+        assert sc.contents.items[1] == ord(u'y')
+        assert sc.contents.items[2] == ord(u'z')
         assert not hasattr(sc.contents, 'length')
         lltype.free(s, flavor='raw')
         assert not ALLOCATED



More information about the Pypy-commit mailing list