[pypy-svn] r63853 - in pypy/trunk/pypy/rpython: . test

afa at codespeak.net afa at codespeak.net
Wed Apr 8 17:42:22 CEST 2009


Author: afa
Date: Wed Apr  8 17:42:22 2009
New Revision: 63853

Modified:
   pypy/trunk/pypy/rpython/rmodel.py
   pypy/trunk/pypy/rpython/test/test_rdict.py
Log:
Allocate at least one item for the dummy ptr value.
This fixes the translation of dict({Signed: rffi.VOIDP})


Modified: pypy/trunk/pypy/rpython/rmodel.py
==============================================================================
--- pypy/trunk/pypy/rpython/rmodel.py	(original)
+++ pypy/trunk/pypy/rpython/rmodel.py	Wed Apr  8 17:42:22 2009
@@ -466,7 +466,7 @@
         except KeyError:
             # generate a dummy ptr to an immortal placeholder struct/array
             if TYPE._is_varsize():
-                p = lltype.malloc(TYPE, 0, immortal=True)
+                p = lltype.malloc(TYPE, 1, immortal=True)
             else:
                 p = lltype.malloc(TYPE, immortal=True)
             self.rtyper.cache_dummy_values[TYPE] = p

Modified: pypy/trunk/pypy/rpython/test/test_rdict.py
==============================================================================
--- pypy/trunk/pypy/rpython/test/test_rdict.py	(original)
+++ pypy/trunk/pypy/rpython/test/test_rdict.py	Wed Apr  8 17:42:22 2009
@@ -1,5 +1,5 @@
 from pypy.translator.translator import TranslationContext
-from pypy.rpython.lltypesystem import lltype 
+from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.rpython import rint
 from pypy.rpython.lltypesystem import rdict, rstr
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
@@ -776,6 +776,21 @@
 
         py.test.raises(TypeError, self.interpret, func, [0])
 
+    def test_dict_of_voidp(self):
+        def func():
+            d = {}
+            handle = lltype.nullptr(rffi.VOIDP.TO)
+            # Use a negative key, so the dict implementation uses
+            # the value as a marker for empty entries
+            d[-1] = handle
+            return len(d)
+
+        assert self.interpret(func, []) == 1
+        from pypy.translator.c.test.test_genc import compile
+        f = compile(func, [])
+        res = f()
+        assert res == 1
+
     # ____________________________________________________________
 
 



More information about the Pypy-commit mailing list