[pypy-commit] pypy ffistruct: more tests for pointers and strings

antocuni noreply at buildbot.pypy.org
Mon Nov 21 00:11:50 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r49591:b38d44f35469
Date: 2011-11-12 17:44 +0100
http://bitbucket.org/pypy/pypy/changeset/b38d44f35469/

Log:	more tests for pointers and strings

diff --git a/pypy/module/_ffi/test/test_type_converter.py b/pypy/module/_ffi/test/test_type_converter.py
--- a/pypy/module/_ffi/test/test_type_converter.py
+++ b/pypy/module/_ffi/test/test_type_converter.py
@@ -1,7 +1,7 @@
 import sys
 from pypy.conftest import gettestobjspace
 from pypy.rlib.rarithmetic import r_uint
-from pypy.module._ffi.interp_ffitype import app_types
+from pypy.module._ffi.interp_ffitype import app_types, descr_new_pointer
 from pypy.module._ffi.type_converter import FromAppLevelConverter, ToAppLevelConverter
 
 class DummyFromAppLevelConverter(FromAppLevelConverter):
@@ -55,9 +55,14 @@
         # pointers are "unsigned" at applevel, but signed at interp-level (for
         # no good reason, at interp-level Signed or Unsigned makes no
         # difference for passing bits around)
-        self.check(app_types.void_p, self.space.wrap(42), 42)
-        self.check(app_types.void_p, self.space.wrap(sys.maxint+1),
-                   -sys.maxint-1)
+        space = self.space
+        self.check(app_types.void_p, space.wrap(42), 42)
+        self.check(app_types.void_p, space.wrap(sys.maxint+1), -sys.maxint-1)
+        #
+        # typed pointers
+        w_ptr_sint = descr_new_pointer(space, None, app_types.sint)
+        self.check(w_ptr_sint, space.wrap(sys.maxint+1), -sys.maxint-1)
+
 
     def test__as_ffi_pointer_(self):
         space = self.space
@@ -74,3 +79,12 @@
         """)
         w_obj = space.call_function(w_MyPointerWrapper, space.wrap(42))
         self.check(app_types.void_p, w_obj, 42)
+
+    def test_strings(self):
+        # first, try automatic conversion from applevel
+        self.check(app_types.char_p, self.space.wrap('foo'), 'foo')
+        self.check(app_types.unichar_p, self.space.wrap(u'foo\u1234'), u'foo\u1234')    
+        self.check(app_types.unichar_p, self.space.wrap('foo'), u'foo')    
+        # then, try to pass explicit pointers
+        self.check(app_types.char_p, self.space.wrap(42), 42)
+        self.check(app_types.unichar_p, self.space.wrap(42), 42)        


More information about the pypy-commit mailing list