[pypy-svn] r16312 - pypy/dist/pypy/translator/c
pedronis at codespeak.net
pedronis at codespeak.net
Tue Aug 23 18:33:18 CEST 2005
Author: pedronis
Date: Tue Aug 23 18:33:15 2005
New Revision: 16312
Modified:
pypy/dist/pypy/translator/c/database.py
pypy/dist/pypy/translator/c/gc.py
pypy/dist/pypy/translator/c/node.py
Log:
more moving refcounting out
(cfbolz, pedronis)
Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py (original)
+++ pypy/dist/pypy/translator/c/database.py Tue Aug 23 18:33:15 2005
@@ -120,6 +120,7 @@
else:
raise Exception("don't know about %r" % (obj,))
+ """
def cincrefstmt(self, expr, T):
if isinstance(T, Ptr) and T._needsgc():
if expr == 'NULL': # hum
@@ -147,6 +148,7 @@
dealloc,
expr)
return ''
+"""
def complete(self):
i = 0
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 18:33:15 2005
@@ -1,5 +1,5 @@
from pypy.translator.c.support import cdecl
-from pypy.rpython.lltype import typeOf, Ptr, PyObject
+from pypy.rpython.lltype import typeOf, Ptr, PyObject, ContainerType
from pypy.rpython.lltype import getRuntimeTypeInfo
PyObjPtr = Ptr(PyObject)
@@ -74,6 +74,21 @@
result.append(decrefstmt)
result.append('}')
+ def generic_dealloc(self, expr, T):
+ db = self.db
+ if isinstance(T, Ptr) and T._needsgc():
+ line = self.pop_alive(expr, T)
+ if line:
+ yield line
+ elif isinstance(T, ContainerType):
+ defnode = db.gettypedefnode(T)
+ from pypy.translator.c.node import ExtTypeOpaqueDefNode
+ if isinstance(defnode, ExtTypeOpaqueDefNode):
+ yield 'RPyOpaqueDealloc_%s(&(%s));' % (defnode.T.tag, expr)
+ else:
+ for line in defnode.visitor_lines(expr, self.generic_dealloc):
+ yield line
+
def gcheader_field_name(self, defnode):
return 'refcount'
@@ -89,6 +104,12 @@
def common_gcheader_initializationexpr(self, defnode):
yield 'REFCOUNT_IMMORTAL,'
+ def deallocator_lines(self, defnode, prefix):
+ for line in defnode.visitor_lines(prefix, self.generic_dealloc):
+ yield line
+
+
+
# for structs
def prepare_nested_gcstruct(self, structdefnode, INNER):
@@ -118,7 +139,7 @@
gcinfo.rtti_query_funcptr_argtype = db.gettype(T)
else:
# is a deallocator really needed, or would it be empty?
- if list(structdefnode.deallocator_lines('')):
+ if list(self.deallocator_lines(structdefnode, '')):
gcinfo.static_deallocator = gcinfo.deallocator
else:
gcinfo.deallocator = None
@@ -127,15 +148,36 @@
struct_after_definition = common_after_definition
- def struct_implentationcode(self, structdefnode):
- pass
+ def struct_implementationcode(self, structdefnode):
+ if structdefnode.gcinfo:
+ gcinfo = structdefnode.gcinfo
+ if gcinfo.static_deallocator:
+ yield 'void %s(struct %s *p) {' % (gcinfo.static_deallocator,
+ structdefnode.name)
+ for line in self.deallocator_lines(structdefnode, '(*p)'):
+ yield '\t' + line
+ yield '\tOP_FREE(p);'
+ yield '}'
+ if gcinfo.deallocator and gcinfo.deallocator != gcinfo.static_deallocator:
+ yield 'void %s(struct %s *p) {' % (gcinfo.deallocator, structdefnode.name)
+ yield '\tvoid (*staticdealloc) (void *);'
+ # the refcount should be 0; temporarily bump it to 1
+ yield '\tp->%s = 1;' % (structdefnode.gcheader,)
+ # cast 'p' to the type expected by the rtti_query function
+ yield '\tstaticdealloc = %s((%s) p);' % (
+ gcinfo.rtti_query_funcptr,
+ cdecl(gcinfo.rtti_query_funcptr_argtype, ''))
+ yield '\tif (!--p->%s)' % (structdefnode.gcheader,)
+ yield '\t\tstaticdealloc(p);'
+ yield '}'
+
struct_gcheader_initialitionexpr = common_gcheader_initializationexpr
# for arrays
def array_setup(self, arraydefnode):
- if arraydefnode.gcheader and list(arraydefnode.deallocator_lines('')):
+ if arraydefnode.gcheader and list(self.deallocator_lines(arraydefnode, '')):
gcinfo = arraydefnode.gcinfo = RefcountingInfo()
gcinfo.deallocator = self.db.namespace.uniquename('dealloc_'+arraydefnode.barename)
@@ -144,7 +186,14 @@
array_after_definition = common_after_definition
def array_implementationcode(self, arraydefnode):
- pass
+ if arraydefnode.gcinfo:
+ gcinfo = arraydefnode.gcinfo
+ if gcinfo.deallocator:
+ yield 'void %s(struct %s *a) {' % (gcinfo.deallocator, arraydefnode.name)
+ for line in self.deallocator_lines(arraydefnode, '(*a)'):
+ yield '\t' + line
+ yield '\tOP_FREE(a);'
+ yield '}'
array_gcheader_initialitionexpr = common_gcheader_initializationexpr
Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py (original)
+++ pypy/dist/pypy/translator/c/node.py Tue Aug 23 18:33:15 2005
@@ -114,40 +114,16 @@
for line in gcpolicy.struct_after_definition(self):
yield line
- elif phase == 2: # xxx -> gc
- if self.gcinfo:
- gcinfo = self.gcinfo
- if gcinfo.static_deallocator:
- yield 'void %s(struct %s *p) {' % (gcinfo.static_deallocator,
- self.name)
- for line in self.visitor_lines('(*p)', generic_dealloc):
- yield '\t' + line
- yield '\tOP_FREE(p);'
- yield '}'
- if gcinfo.deallocator and gcinfo.deallocator != gcinfo.static_deallocator:
- yield 'void %s(struct %s *p) {' % (gcinfo.deallocator, self.name)
- yield '\tvoid (*staticdealloc) (void *);'
- # the refcount should be 0; temporarily bump it to 1
- yield '\tp->%s = 1;' % (self.gcheader,)
- # cast 'p' to the type expected by the rtti_query function
- yield '\tstaticdealloc = %s((%s) p);' % (
- gcinfo.rtti_query_funcptr,
- cdecl(gcinfo.rtti_query_funcptr_argtype, ''))
- yield '\tif (!--p->%s)' % (self.gcheader,)
- yield '\t\tstaticdealloc(p);'
- yield '}'
-
- def deallocator_lines(self, prefix):
- for line in self.visitor_lines(prefix, generic_dealloc):
- yield line
+ elif phase == 2:
+ for line in gcpolicy.struct_implementationcode(self):
+ yield line
def visitor_lines(self, prefix, on_field):
STRUCT = self.STRUCT
for name in STRUCT._names:
FIELD_T = self.c_struct_field_type(name)
cname = self.c_struct_field_name(name)
- for line in on_field(self.db,
- '%s.%s' % (prefix, cname),
+ for line in on_field('%s.%s' % (prefix, cname),
FIELD_T):
yield line
@@ -223,18 +199,8 @@
yield line
elif phase == 2:
- if self.gcinfo: # xxx -> gc
- gcinfo = self.gcinfo
- if gcinfo.deallocator:
- yield 'void %s(struct %s *a) {' % (gcinfo.deallocator, self.name)
- for line in self.visitor_lines('(*a)', generic_dealloc):
- yield '\t' + line
- yield '\tOP_FREE(a);'
- yield '}'
-
- def deallocator_lines(self, prefix):
- for line in self.visitor_lines(prefix, generic_dealloc):
- yield line
+ for line in gcpolicy.array_implementationcode(self):
+ yield line
def visitor_lines(self, prefix, on_item):
ARRAY = self.ARRAY
@@ -245,7 +211,7 @@
while prefix.find(varname) >= 0:
i += 1
varname = 'p%d' % i
- body = list(on_item(self.db, '(*%s)' % varname, ARRAY.OF))
+ body = list(on_item('(*%s)' % varname, ARRAY.OF))
if body:
yield '{'
yield '\t%s = %s.items;' % (cdecl(self.itemtypename, '*' + varname),
@@ -287,20 +253,6 @@
def definition(self, phase):
return []
-
-def generic_dealloc(db, expr, T): # xxx -> gc, refactor PyObjPtr case
- if isinstance(T, Ptr) and T._needsgc():
- line = db.cdecrefstmt(expr, T)
- if line:
- yield line
- elif isinstance(T, ContainerType):
- defnode = db.gettypedefnode(T)
- if isinstance(defnode, ExtTypeOpaqueDefNode):
- yield 'RPyOpaqueDealloc_%s(&(%s));' % (defnode.T.tag, expr)
- else:
- for line in defnode.visitor_lines(expr, generic_dealloc):
- yield line
-
# ____________________________________________________________
@@ -555,7 +507,7 @@
else:
raise ValueError, "don't know how to generate code for %r" % (fnobj,)
-
+# xxx move it completly to the gcpolicy
class RuntimeTypeInfo_OpaqueNode(ContainerNode):
globalcontainer = True
includes = ()
More information about the Pypy-commit
mailing list