[pypy-svn] r23129 - in pypy: branch/genc-gc-refactoring dist/pypy/rpython/memory
pedronis at codespeak.net
pedronis at codespeak.net
Wed Feb 8 00:29:39 CET 2006
Author: pedronis
Date: Wed Feb 8 00:29:37 2006
New Revision: 23129
Modified:
pypy/branch/genc-gc-refactoring/funcgen.py
pypy/dist/pypy/rpython/memory/gctransform.py
Log:
fixing some breakage.
now gctransform attach a pair (var, ops) exc_cleanup to graphs to use to gc pop an exception if necessary.
Modified: pypy/branch/genc-gc-refactoring/funcgen.py
==============================================================================
--- pypy/branch/genc-gc-refactoring/funcgen.py (original)
+++ pypy/branch/genc-gc-refactoring/funcgen.py Wed Feb 8 00:29:37 2006
@@ -65,7 +65,12 @@
self.more_ll_values.append(link.llexitcase)
elif link.exitcase is not None:
mix.append(Constant(link.exitcase))
-
+ if cpython_exc:
+ _, exc_cleanup_ops = graph.exc_cleanup
+ for cleanupop in exc_cleanup_ops:
+ mix.extend(cleanupop.args)
+ mix.append(cleanupop.result)
+
uniquemix = []
seen = {}
for v in mix:
@@ -134,19 +139,17 @@
def return_with_error(self):
if self.cpython_exc:
- # this should most likely be done on the graph level!
- lltype_of_exception_value = self.db.get_lltype_of_exception_value()
- exc_value_typename = self.db.gettype(lltype_of_exception_value)
assert self.lltypemap(self.graph.getreturnvar()) == PyObjPtr
- yield '{'
- yield '\t%s;' % cdecl(exc_value_typename, 'vanishing_exc_value')
- yield '\tRPyConvertExceptionToCPython(vanishing_exc_value);'
- if lltype_of_exception_value == PyObjPtr:
- yield '\tPy_XDECREF(vanishing_exc_value);'
- else:
- yield '\t%s' % self.gcpolicy.pop_alive_nopyobj(
- 'vanishing_exc_value', lltype_of_exception_value)
- yield '}'
+ v, exc_cleanup_ops = self.graph.exc_cleanup
+ vanishing_exc_value = self.expr(v)
+ yield 'RPyConvertExceptionToCPython(%s);' % vanishing_exc_value
+ for cleanupop in exc_cleanup_ops:
+ line = self.gen_op(cleanupop, 'should_never_be_jumped_to')
+ if '\n' in line:
+ for l in line.splitlines():
+ yield l
+ else:
+ yield line
yield 'return %s; ' % self.error_return_value()
# ____________________________________________________________
@@ -311,7 +314,7 @@
fallthrough = False # this label was already generated
for cleanupop in op.cleanup:
line = self.gen_op(cleanupop, 'should_never_be_jumped_to')
- if '\\n' in line:
+ if '\n' in line:
for l in line.splitlines():
yield l
else:
Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py (original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py Wed Feb 8 00:29:37 2006
@@ -52,6 +52,13 @@
self.translator = translator
self.seen_graphs = {}
+ def get_lltype_of_exception_value(self):
+ if self.translator is not None and self.translator.rtyper is not None:
+ exceptiondata = self.translator.rtyper.getexceptiondata()
+ return exceptiondata.lltype_of_exception_value
+ else:
+ return Ptr(PyObject)
+
def transform(self, graphs):
for graph in graphs:
self.transform_graph(graph)
@@ -82,6 +89,11 @@
link.prevblock.operations.extend(newops)
else:
insert_empty_block(None, link, newops)
+
+ v = Variable('vanishing_exc_value')
+ v.concretetype = self.get_lltype_of_exception_value()
+ graph.exc_cleanup = (v, self.pop_alive(v))
+
if self.translator.rtyper is not None:
self.translator.rtyper.specialize_more_blocks()
@@ -301,8 +313,10 @@
rtti = self.get_rtti(TYPE)
if rtti is not None and hasattr(rtti._obj, 'destructor_funcptr'):
destrptr = rtti._obj.destructor_funcptr
+ DESTR_ARG = lltype.typeOf(destrptr).TO.ARGS[0]
else:
destrptr = None
+ DESTR_ARG = None
if destrptr is not None:
body = '\n'.join(self._static_deallocator_body_for_type('v', TYPE, 2))
@@ -312,8 +326,9 @@
gcheader = addr - gc_header_offset
# refcount is at zero, temporarily bump it to 1:
gcheader.signed[0] = 1
+ destr_v = cast_pointer(DESTR_ARG, v)
try:
- destrptr(v)
+ destrptr(destr_v)
except Exception:
os.write(0, "a destructor raised an exception, ignoring it")
refcount = gcheader.signed[0] - 1
@@ -332,7 +347,9 @@
'destrptr': destrptr,
'gc_header_offset': RefcountingGCTransformer.gc_header_offset,
'cast_adr_to_ptr': objectmodel.cast_adr_to_ptr,
+ 'cast_pointer': lltype.cast_pointer,
'PTR_TYPE': lltype.Ptr(TYPE),
+ 'DESTR_ARG': DESTR_ARG,
'os': py.std.os}
print
print src
More information about the Pypy-commit
mailing list