[pypy-svn] r76909 - in pypy/branch/gc-module/pypy: rpython/memory/gc rpython/memory/gctransform translator/c/test

arigo at codespeak.net arigo at codespeak.net
Tue Sep 7 11:29:06 CEST 2010


Author: arigo
Date: Tue Sep  7 11:29:04 2010
New Revision: 76909

Modified:
   pypy/branch/gc-module/pypy/rpython/memory/gc/base.py
   pypy/branch/gc-module/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/gc-module/pypy/translator/c/test/test_newgc.py
Log:
Translate rgc.get_rpy_typeid().


Modified: pypy/branch/gc-module/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/gc-module/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/gc-module/pypy/rpython/memory/gc/base.py	Tue Sep  7 11:29:04 2010
@@ -341,6 +341,11 @@
         # overridden in semispace.py and markcompact.py to also count the hash
         return self.get_size(llmemory.cast_ptr_to_adr(gcref))
 
+    def get_rpy_typeid(self, gcref):
+        from pypy.rlib.rarithmetic import intmask
+        typeid = self.get_type_id(llmemory.cast_ptr_to_adr(gcref))
+        return intmask(typeid)
+
     def is_rpy_instance(self, gcref):
         typeid = self.get_type_id(llmemory.cast_ptr_to_adr(gcref))
         return self.is_rpython_class(typeid)

Modified: pypy/branch/gc-module/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/gc-module/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/gc-module/pypy/rpython/memory/gctransform/framework.py	Tue Sep  7 11:29:04 2010
@@ -401,6 +401,10 @@
                                           [s_gc, s_gcref],
                                           annmodel.SomeInteger(),
                                           minimal_transform=False)
+        self.get_rpy_typeid_ptr = getfn(GCClass.get_rpy_typeid.im_func,
+                                        [s_gc, s_gcref],
+                                        annmodel.SomeInteger(),
+                                        minimal_transform=False)
         self.is_rpy_instance_ptr = getfn(GCClass.is_rpy_instance.im_func,
                                          [s_gc, s_gcref],
                                          annmodel.SomeBool(),
@@ -924,6 +928,14 @@
                   resultvar=hop.spaceop.result)
         self.pop_roots(hop, livevars)
 
+    def gct_gc_get_rpy_typeid(self, hop):
+        livevars = self.push_roots(hop)
+        [v_ptr] = hop.spaceop.args
+        hop.genop("direct_call",
+                  [self.get_rpy_typeid_ptr, self.c_const_gc, v_ptr],
+                  resultvar=hop.spaceop.result)
+        self.pop_roots(hop, livevars)
+
     def gct_gc_is_rpy_instance(self, hop):
         livevars = self.push_roots(hop)
         [v_ptr] = hop.spaceop.args

Modified: pypy/branch/gc-module/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/gc-module/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/branch/gc-module/pypy/translator/c/test/test_newgc.py	Tue Sep  7 11:29:04 2010
@@ -1034,6 +1034,35 @@
     def test_get_rpy_memory_usage(self):
         self.run("get_rpy_memory_usage")
 
+    def define_get_rpy_typeid(self):
+        U = lltype.GcStruct('U', ('x', lltype.Signed))
+        S = lltype.GcStruct('S', ('u', lltype.Ptr(U)))
+        A = lltype.GcArray(lltype.Ptr(S))
+
+        def fn():
+            s = lltype.malloc(S)
+            s.u = lltype.malloc(U)
+            a = lltype.malloc(A, 1000)
+            s2 = lltype.malloc(S)
+            gcref1 = lltype.cast_opaque_ptr(llmemory.GCREF, s)
+            int1 = rgc.get_rpy_typeid(gcref1)
+            gcref2 = lltype.cast_opaque_ptr(llmemory.GCREF, s.u)
+            int2 = rgc.get_rpy_typeid(gcref2)
+            gcref3 = lltype.cast_opaque_ptr(llmemory.GCREF, a)
+            int3 = rgc.get_rpy_typeid(gcref3)
+            gcref4 = lltype.cast_opaque_ptr(llmemory.GCREF, s2)
+            int4 = rgc.get_rpy_typeid(gcref4)
+            assert int1 != int2
+            assert int1 != int3
+            assert int2 != int3
+            assert int1 == int4
+            return 0
+
+        return fn
+
+    def test_get_rpy_typeid(self):
+        self.run("get_rpy_typeid")
+
 
 class TestSemiSpaceGC(TestUsingFramework, snippet.SemiSpaceGCTestDefines):
     gcpolicy = "semispace"



More information about the Pypy-commit mailing list