[pypy-svn] r16315 - pypy/dist/pypy/translator/c

pedronis at codespeak.net pedronis at codespeak.net
Tue Aug 23 19:00:26 CEST 2005


Author: pedronis
Date: Tue Aug 23 19:00:25 2005
New Revision: 16315

Modified:
   pypy/dist/pypy/translator/c/funcgen.py
   pypy/dist/pypy/translator/c/gc.py
Log:
finished factoring out refcounting logic into RefcountingPolicy in gc.py:

delegating malloc implementation

(cfbolz, pedronis)



Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Tue Aug 23 19:00:25 2005
@@ -475,12 +475,10 @@
         TYPE = self.lltypemap(op.result).TO
         typename = self.db.gettype(TYPE)
         eresult = self.expr(op.result)
-        result = ['OP_ZERO_MALLOC(sizeof(%s), %s, %s);' % (cdecl(typename, ''),
-                                                           eresult,
-                                                           err),
-                  '%s->%s = 0;' % (eresult, # xxx the incref is generically done on the results
-                                   self.db.gettypedefnode(TYPE).gcheader),
-                  ]
+        esize = 'sizeof(%s)' % cdecl(typename, '')
+
+        result = list(self.db.gcpolicy.zero_malloc(TYPE, esize, eresult, err))
+
         return '\t'.join(result)
 
     def OP_MALLOC_VARSIZE(self, op, err):
@@ -491,25 +489,24 @@
         if isinstance(TYPE, Struct):
             arfld = TYPE._arrayfld
             lenfld = "%s.length" % nodedef.c_struct_field_name(arfld)
-            TYPE = TYPE._flds[TYPE._arrayfld]
-        assert isinstance(TYPE, Array)
-        itemtypename = self.db.gettype(TYPE.OF)
+            VARPART = TYPE._flds[TYPE._arrayfld]
+        else:
+            VARPART = TYPE
+        assert isinstance(VARPART, Array)
+        itemtypename = self.db.gettype(VARPART.OF)
         elength = self.expr(op.args[1])
         eresult = self.expr(op.result)
-        if TYPE.OF == Void:    # strange
-            size = 'sizeof(%s)' % (cdecl(typename, ''),)
+        if VARPART.OF == Void:    # strange
+            esize = 'sizeof(%s)' % (cdecl(typename, ''),)
         else:
-            size = 'sizeof(%s)+((%s-1)*sizeof(%s))' % (cdecl(typename, ''),
+            esize = 'sizeof(%s)+((%s-1)*sizeof(%s))' % (cdecl(typename, ''),
                                                        elength,
                                                        cdecl(itemtypename, ''))
-        result = ['OP_ZERO_MALLOC(%s, %s, %s);' % (size,
-                                                   eresult,
-                                                   err),
+        result = list(self.db.gcpolicy.zero_malloc(TYPE, esize, eresult, err))
+        result.append(
                   '%s->%s = %s;' % (eresult, lenfld,
                                     elength),
-                  '%s->%s = 0;' % (eresult,             # xxx the incref is generically done on the results
-                                   nodedef.gcheader),
-                  ]
+                   )
         return '\t'.join(result)
 
     def OP_CAST_POINTER(self, op, err):

Modified: pypy/dist/pypy/translator/c/gc.py
==============================================================================
--- pypy/dist/pypy/translator/c/gc.py	(original)
+++ pypy/dist/pypy/translator/c/gc.py	Tue Aug 23 19:00:25 2005
@@ -208,3 +208,10 @@
             defnode.name,)
         node.name = defnode.gcinfo.static_deallocator
         node.ptrname = '((void (*)(void *)) %s)' % (node.name,)
+
+    # zero malloc impl
+
+    def zero_malloc(self, TYPE, esize, eresult, err):
+        yield  'OP_ZERO_MALLOC(%s, %s, %s);' % (esize,
+                                                eresult,
+                                                err)



More information about the Pypy-commit mailing list