[pypy-svn] r50979 - in pypy/dist/pypy/module/_rawffi: . test

fijal at codespeak.net fijal at codespeak.net
Thu Jan 24 17:28:52 CET 2008


Author: fijal
Date: Thu Jan 24 17:28:51 2008
New Revision: 50979

Modified:
   pypy/dist/pypy/module/_rawffi/interp_rawffi.py
   pypy/dist/pypy/module/_rawffi/test/test__rawffi.py
Log:
* Support for wide chars
* Accept 'Z' as synonym to 'P'


Modified: pypy/dist/pypy/module/_rawffi/interp_rawffi.py
==============================================================================
--- pypy/dist/pypy/module/_rawffi/interp_rawffi.py	(original)
+++ pypy/dist/pypy/module/_rawffi/interp_rawffi.py	Thu Jan 24 17:28:51 2008
@@ -30,6 +30,7 @@
     'b' : ffi_type_schar,
     'B' : ffi_type_uchar,
     'h' : ffi_type_sshort,
+    'u' : ffi_type_ushort, # XXX alias for wide-character
     'H' : ffi_type_ushort,
     'i' : ffi_type_sint,
     'I' : ffi_type_uint,
@@ -45,6 +46,7 @@
     'P' : ffi_type_pointer,
     'z' : ffi_type_pointer,
     'O' : ffi_type_pointer,
+    'Z' : ffi_type_pointer,
 }
 TYPEMAP_PTR_LETTERS = "POsz"
 
@@ -55,6 +57,7 @@
 
 LL_TYPEMAP = {
     'c' : rffi.CHAR,
+    'u' : lltype.UniChar,
     'b' : rffi.SIGNEDCHAR,
     'B' : rffi.UCHAR,
     'h' : rffi.SHORT,
@@ -227,6 +230,13 @@
                 "Expected string of length one as character"))
         val = s[0]
         push_func(add_arg, argdesc, val)
+    elif letter == 'u':
+        s = space.unicode_w(w_arg)
+        if len(s) != 1:
+            raise OperationError(space.w_TypeError, w(
+                "Expected unicode string og length one as wide character"))
+        val = s[0]
+        push_func(add_arg, argdesc, val)
     else:
         for c in unroll_letters_for_numbers:
             if letter == c:
@@ -251,7 +261,7 @@
             elif c == 'v':
                 func(add_arg, argdesc, ll_type)
                 return space.w_None
-            elif c == 'q' or c == 'Q' or c == 'L' or c == 'c':
+            elif c == 'q' or c == 'Q' or c == 'L' or c == 'c' or c == 'u':
                 return space.wrap(func(add_arg, argdesc, ll_type))
             elif c == 'f' or c == 'd':
                 return space.wrap(float(func(add_arg, argdesc, ll_type)))

Modified: pypy/dist/pypy/module/_rawffi/test/test__rawffi.py
==============================================================================
--- pypy/dist/pypy/module/_rawffi/test/test__rawffi.py	(original)
+++ pypy/dist/pypy/module/_rawffi/test/test__rawffi.py	Thu Jan 24 17:28:51 2008
@@ -497,6 +497,14 @@
                                                                len(a))
         a.free()
 
+    def test_wide_char(self):
+        import _rawffi
+        A = _rawffi.Array('u')
+        a = A(1)
+        a[0] = u'x'
+        assert a[0] == u'x'
+        a.free()
+
     def test_truncate(self):
         import _rawffi, struct
         a = _rawffi.Array('b')(1)



More information about the Pypy-commit mailing list