Author: Armin Rigo <[email protected]>
Branch: stmgc-c4
Changeset: r65109:d39a80a156da
Date: 2013-06-29 23:00 +0200
http://bitbucket.org/pypy/pypy/changeset/d39a80a156da/

Log:    Implement stmcb_size().

diff --git a/rpython/memory/gc/stmgc.py b/rpython/memory/gc/stmgc.py
--- a/rpython/memory/gc/stmgc.py
+++ b/rpython/memory/gc/stmgc.py
@@ -23,20 +23,6 @@
 
     TRANSLATION_PARAMS = {}
 
-    def __init__(self, config, **kwds):
-        MovingGCBase.__init__(self, config, **kwds)
-
-        def stmcb_size(obj):
-            typeid = self.get_type_id(obj)
-            size = self.fixed_size(typeid)
-            if self.is_varsize(typeid):
-                lenofs = self.varsize_offset_to_length(typeid)
-                length = (obj + lenofs).signed[0]
-                size += self.varsize_item_sizes(typeid) * length
-            return size
-
-        
-
     def get_type_id(self, obj):
         return llop.stm_get_tid(llgroup.HALFWORD, obj)
 
diff --git a/rpython/memory/gctransform/framework.py 
b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -219,6 +219,7 @@
             return annhelper.graph2const(graph)
         self._getfn = getfn
 
+        self.autoregister_ptrs = []
         self.frameworkgc_setup_ptr = getfn(frameworkgc_setup, [],
                                            annmodel.s_None)
         # for tests
diff --git a/rpython/memory/gctransform/stmframework.py 
b/rpython/memory/gctransform/stmframework.py
--- a/rpython/memory/gctransform/stmframework.py
+++ b/rpython/memory/gctransform/stmframework.py
@@ -4,6 +4,20 @@
 
 class StmFrameworkGCTransformer(BaseFrameworkGCTransformer):
 
+    def _declare_functions(self, GCClass, getfn, s_gc, s_typeid16):
+        from rpython.annotator import model as annmodel
+        from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+        BaseFrameworkGCTransformer._declare_functions(self, GCClass, getfn,
+                                                      s_gc, s_typeid16)
+        gc = self.gcdata.gc
+        #
+        def pypy_stmcb_size(obj):
+            return gc.get_size(obj)
+        pypy_stmcb_size.c_name = "pypy_stmcb_size"
+        self.autoregister_ptrs.append(
+            getfn(pypy_stmcb_size, [annmodel.SomeAddress()],
+                  annmodel.SomeInteger()))
+
     def build_root_walker(self):
         return StmRootWalker(self)
 
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -590,6 +590,7 @@
     OP_STM_PUSH_ROOT = _OP_STM
     OP_STM_POP_ROOT_INTO = _OP_STM
     OP_STM_ALLOCATE = _OP_STM
+    OP_STM_GET_TID = _OP_STM
 
 
     def OP_PTR_NONZERO(self, op):
diff --git a/rpython/translator/c/gc.py b/rpython/translator/c/gc.py
--- a/rpython/translator/c/gc.py
+++ b/rpython/translator/c/gc.py
@@ -345,6 +345,8 @@
         return FrameworkGcRuntimeTypeInfo_OpaqueNode
 
     def gc_startup_code(self):
+        for c_fnptr in self.db.gctransformer.autoregister_ptrs:
+            self.db.get(c_fnptr.value)
         fnptr = self.db.gctransformer.frameworkgc_setup_ptr.value
         yield '%s();' % (self.db.get(fnptr),)
 
diff --git a/rpython/translator/stm/funcgen.py 
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -85,6 +85,11 @@
     result = funcgen.expr(op.result)
     return '%s = stm_allocate(%s, %s);' % (result, arg0, arg1)
 
+def stm_get_tid(funcgen, op):
+    arg0 = funcgen.expr(op.args[0])
+    result = funcgen.expr(op.result)
+    return '%s = stm_get_tid((gcptr)%s);' % (result, arg0)
+
 
 def op_stm(funcgen, op):
     func = globals()[op.opname]
diff --git a/rpython/translator/stm/stmgcintf.py 
b/rpython/translator/stm/stmgcintf.py
--- a/rpython/translator/stm/stmgcintf.py
+++ b/rpython/translator/stm/stmgcintf.py
@@ -6,6 +6,14 @@
 cdir = os.path.abspath(os.path.join(cdir2, '..', 'stm'))
 
 separate_source = '''
+#include "src_stm/stmgc.h"
+
+extern Signed pypy_stmcb_size(void*);
+
+inline size_t stmcb_size(gcptr obj) {
+    return pypy_stmcb_size(obj);
+}
+
 #include "src_stm/stmgc.c"
 '''
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to