Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r69930:9b817ede3084
Date: 2014-03-13 11:56 +0100
http://bitbucket.org/pypy/pypy/changeset/9b817ede3084/

Log:    (Remi, arigo) Prebuilt weakrefs.

diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -873,13 +873,28 @@
         h = database.gcpolicy.get_stm_prebuilt_hash(node.obj)
         print >> f, '\t%s,' % (name_signed(h, database),)
     print >> f, '};'
+    print >> f
+    print >> f, 'static int weakref_indices[] = {'
+    for i, (_, node) in enumerate(gclist):
+        if getattr(node, 'is_weakref', False):
+            print >> f, '\t%d,' % (i,)
+    print >> f, '\t-1'
+    print >> f, '};'
     print >> f, '''
 void pypy_stm_setup_prebuilt(void)
 {
     object_t **pp = rpy_prebuilt;
     long *ph = rpy_prebuilt_hashes;
-    for ( ; *pp; pp++, ph++) {
-        *pp = stm_setup_prebuilt(*pp);
+    int i = 0;
+    int *wri = weakref_indices;
+    for ( ; *pp; pp++, ph++, i++) {
+        if (i == *wri) {
+            *pp = stm_setup_prebuilt_weakref(*pp);
+            wri++;
+        }
+        else {
+            *pp = stm_setup_prebuilt(*pp);
+        }
         stm_set_prebuilt_identityhash(*pp, *ph);
     }
 
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -592,7 +592,7 @@
 class StructNode(ContainerNode):
     nodekind = 'struct'
     if USESLOTS:
-        __slots__ = ()
+        __slots__ = ('is_weakref',)
 
     def basename(self):
         T = self.getTYPE()
@@ -1029,7 +1029,9 @@
     wrapper = db.gcpolicy.convert_weakref_to(ptarget)
     container = wrapper._obj
     #obj._converted_weakref = container     # hack for genllvm :-/
-    return db.getcontainernode(container, _dont_write_c_code=False)
+    node = db.getcontainernode(container, _dont_write_c_code=False)
+    node.is_weakref = True
+    return node
 
 class GroupNode(ContainerNode):
     nodekind = 'group'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to