[pypy-svn] r31868 - in pypy/dist/pypy/rpython/rctypes: . test

arigo at codespeak.net arigo at codespeak.net
Thu Aug 31 11:49:12 CEST 2006


Author: arigo
Date: Thu Aug 31 11:49:09 2006
New Revision: 31868

Modified:
   pypy/dist/pypy/rpython/rctypes/avoid_p.py
   pypy/dist/pypy/rpython/rctypes/test/test_rvoid_p.py
Log:
issue249 resolved

Implement c_void_p(None) and c_void_p(<integer>).


Modified: pypy/dist/pypy/rpython/rctypes/avoid_p.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/avoid_p.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/avoid_p.py	Thu Aug 31 11:49:09 2006
@@ -18,12 +18,14 @@
         hop.exception_cannot_occur()
         v_result = r_void_p.allocate_instance(hop.llops)
         if hop.args_r:
-            raise NotImplementedError("cast_int_to_adr")
-##            from pypy.rpython.lltypesystem import lltype, llmemory
-##            [v_intadr] = hop.inputargs(lltype.Signed)   # xxx id-sized
-##            v_adr = hop.genop('cast_int_to_adr', [v_intadr],
-##                              resulttype = llmemory.Address)
-##            r_void_p.setvalue(hop.llops, v_result, v_adr)
+            if hop.args_s[0].is_constant() and hop.args_s[0].const is None:
+                pass # c_void_p(None) == c_void_p()
+            else:
+                from pypy.rpython.lltypesystem import lltype, llmemory
+                [v_intadr] = hop.inputargs(lltype.Signed)   # xxx id-sized
+                v_adr = hop.genop('cast_int_to_adr', [v_intadr],
+                                  resulttype = llmemory.Address)
+                r_void_p.setvalue(hop.llops, v_result, v_adr)
         return v_result
 
 

Modified: pypy/dist/pypy/rpython/rctypes/test/test_rvoid_p.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rvoid_p.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rvoid_p.py	Thu Aug 31 11:49:09 2006
@@ -70,6 +70,12 @@
             assert not c_void_p()
         interpret(func, [])
 
+    def test_None_argument(self):
+        def func():
+            return bool(c_void_p(None))
+        res = interpret(func, [])
+        assert res is False
+
     def test_convert_pointers(self):
         strlen = CFUNCTYPE(c_int, c_void_p)()
         strlen.__name__ = 'strlen'
@@ -111,12 +117,6 @@
         res = interpret(fn, [])
         assert lltype.typeOf(res) == lltype.Signed    # xxx
 
-##    def test_annotate_int2addr(self):   XXX cast_int_to_adr() not implemented
-##        def fn(n):
-##            return c_void_p(n)
-##        res = interpret(fn, [123])
-##        assert llmemory.cast_adr_to_int(res.c_data[0]) == 123
-
 class Test_compilation:
     def test_compile_c_char_p(self):
         def func():
@@ -145,3 +145,9 @@
         fn = compile(func, [int])
         assert fn(-42) == 42
         assert fn(71) == 71
+
+    def test_compile_int2addr(self):
+        def func(n):
+            return c_void_p(n).value
+        fn = compile(func, [int])
+        assert fn(123) == 123



More information about the Pypy-commit mailing list