[pypy-svn] r34760 - in pypy/dist/pypy: rpython/lltypesystem translator/c translator/c/src
arigo at codespeak.net
arigo at codespeak.net
Sun Nov 19 17:37:05 CET 2006
Author: arigo
Date: Sun Nov 19 17:37:02 2006
New Revision: 34760
Modified:
pypy/dist/pypy/rpython/lltypesystem/lloperation.py
pypy/dist/pypy/translator/c/exceptiontransform.py
pypy/dist/pypy/translator/c/extfunc.py
pypy/dist/pypy/translator/c/funcgen.py
pypy/dist/pypy/translator/c/node.py
pypy/dist/pypy/translator/c/src/exception.h
Log:
(pedronis, arigo)
Replacing the 'debug_log_exc' operation with a somewhat improved version.
The C code and its indirections are still rather obscure, and it's not
the Ultimate Traceback Shower for RPython. Next time...
Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py Sun Nov 19 17:37:02 2006
@@ -399,7 +399,6 @@
'debug_view': LLOp(),
'debug_print': LLOp(),
'debug_pdb': LLOp(),
- 'debug_log_exc': LLOp(),
'debug_assert': LLOp(canfold=True),
'debug_fatalerror': LLOp(),
Modified: pypy/dist/pypy/translator/c/exceptiontransform.py
==============================================================================
--- pypy/dist/pypy/translator/c/exceptiontransform.py (original)
+++ pypy/dist/pypy/translator/c/exceptiontransform.py Sun Nov 19 17:37:02 2006
@@ -56,7 +56,6 @@
def rpyexc_occured():
exc_type = exc_data.exc_type
- lloperation.llop.debug_log_exc(lltype.Void, exc_type)
return exc_type is not null_type
# XXX tmp HACK for genllvm
@@ -64,7 +63,6 @@
# calling rpyexc_occured() from c code with lltype.Bool
def _rpyexc_occured():
exc_type = exc_data.exc_type
- lloperation.llop.debug_log_exc(lltype.Void, exc_type)
return exc_type is not null_type
def rpyexc_fetch_type():
@@ -87,7 +85,8 @@
rpyexc_occured, [], l2a(lltype.Bool))
self.rpyexc_occured_ptr = Constant(lltype.functionptr(
RPYEXC_OCCURED_TYPE, "RPyExceptionOccurred",
- graph=rpyexc_occured_graph),
+ graph=rpyexc_occured_graph,
+ exception_policy="exc_helper"),
lltype.Ptr(RPYEXC_OCCURED_TYPE))
# XXX tmp HACK for genllvm
@@ -96,7 +95,8 @@
_rpyexc_occured, [], l2a(lltype.Signed))
self._rpyexc_occured_ptr = Constant(lltype.functionptr(
_RPYEXC_OCCURED_TYPE, "_RPyExceptionOccurred",
- graph=_rpyexc_occured_graph),
+ graph=_rpyexc_occured_graph,
+ exception_policy="exc_helper"),
lltype.Ptr(_RPYEXC_OCCURED_TYPE))
RPYEXC_FETCH_TYPE_TYPE = lltype.FuncType([], self.lltype_of_exception_type)
@@ -105,7 +105,8 @@
l2a(self.lltype_of_exception_type))
self.rpyexc_fetch_type_ptr = Constant(lltype.functionptr(
RPYEXC_FETCH_TYPE_TYPE, "RPyFetchExceptionType",
- graph=rpyexc_fetch_type_graph),
+ graph=rpyexc_fetch_type_graph,
+ exception_policy="exc_helper"),
lltype.Ptr(RPYEXC_FETCH_TYPE_TYPE))
RPYEXC_FETCH_VALUE_TYPE = lltype.FuncType([], self.lltype_of_exception_value)
@@ -114,7 +115,8 @@
l2a(self.lltype_of_exception_value))
self.rpyexc_fetch_value_ptr = Constant(lltype.functionptr(
RPYEXC_FETCH_VALUE_TYPE, "RPyFetchExceptionValue",
- graph=rpyexc_fetch_value_graph),
+ graph=rpyexc_fetch_value_graph,
+ exception_policy="exc_helper"),
lltype.Ptr(RPYEXC_FETCH_VALUE_TYPE))
RPYEXC_CLEAR = lltype.FuncType([], lltype.Void)
@@ -122,7 +124,8 @@
rpyexc_clear, [], l2a(lltype.Void))
self.rpyexc_clear_ptr = Constant(lltype.functionptr(
RPYEXC_CLEAR, "RPyClearException",
- graph=rpyexc_clear_graph),
+ graph=rpyexc_clear_graph,
+ exception_policy="exc_helper"),
lltype.Ptr(RPYEXC_CLEAR))
RPYEXC_RAISE = lltype.FuncType([self.lltype_of_exception_type,
@@ -134,7 +137,8 @@
l2a(lltype.Void))
self.rpyexc_raise_ptr = Constant(lltype.functionptr(
RPYEXC_RAISE, "RPyRaiseException",
- graph=rpyexc_raise_graph),
+ graph=rpyexc_raise_graph,
+ exception_policy="exc_helper"),
lltype.Ptr(RPYEXC_RAISE))
mixlevelannotator.finish()
@@ -321,7 +325,6 @@
lltype.Bool)
else:
v_exc_type = self.ExcData_repr.getfield(self.cexcdata, 'exc_type', llops)
- llops.genop('debug_log_exc', [v_exc_type], lltype.Void)
var_exc_occured = llops.genop('ptr_nonzero', [v_exc_type],
lltype.Bool)
Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py (original)
+++ pypy/dist/pypy/translator/c/extfunc.py Sun Nov 19 17:37:02 2006
@@ -208,7 +208,7 @@
yield ('RPYTHON_PYEXCCLASS2EXC', exceptiondata.fn_pyexcclass2exc)
yield ('_RPyExceptionOccurred', exctransformer._rpyexc_occured_ptr.value)
- yield ('RPyExceptionOccurred', exctransformer.rpyexc_occured_ptr.value)
+ yield ('RPyExceptionOccurred1', exctransformer.rpyexc_occured_ptr.value)
yield ('RPyFetchExceptionType', exctransformer.rpyexc_fetch_type_ptr.value)
yield ('RPyFetchExceptionValue', exctransformer.rpyexc_fetch_value_ptr.value)
yield ('RPyClearException', exctransformer.rpyexc_clear_ptr.value)
Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py (original)
+++ pypy/dist/pypy/translator/c/funcgen.py Sun Nov 19 17:37:02 2006
@@ -27,7 +27,7 @@
if USESLOTS:
__slots__ = """graph db gcpolicy
- cpython_exc
+ exception_policy
more_ll_values
vars
lltypes
@@ -36,11 +36,11 @@
blocknum
oldgraph""".split()
- def __init__(self, graph, db, cpython_exc=False, functionname=None):
+ def __init__(self, graph, db, exception_policy=None, functionname=None):
self.graph = graph
self.db = db
self.gcpolicy = db.gcpolicy
- self.cpython_exc = cpython_exc
+ self.exception_policy = exception_policy
self.functionname = functionname
# apply the stackless transformation
if db.stacklesstransformer:
@@ -85,7 +85,7 @@
self.more_ll_values.append(link.llexitcase)
elif link.exitcase is not None:
mix.append(Constant(link.exitcase))
- if self.cpython_exc:
+ if self.exception_policy == "CPython":
v, exc_cleanup_ops = self.graph.exc_cleanup
mix.append(v)
for cleanupop in exc_cleanup_ops:
@@ -179,7 +179,7 @@
return self.db.get(ErrorValue(returnlltype))
def return_with_error(self):
- if self.cpython_exc:
+ if self.exception_policy == "CPython":
assert self.lltypemap(self.graph.getreturnvar()) == PyObjPtr
v, exc_cleanup_ops = self.graph.exc_cleanup
vanishing_exc_value = self.expr(v)
@@ -226,13 +226,15 @@
if len(block.exits) == 0:
assert len(block.inputargs) == 1
# regular return block
- if self.cpython_exc:
+ if self.exception_policy == "CPython":
assert self.lltypemap(self.graph.getreturnvar()) == PyObjPtr
yield 'if (RPyExceptionOccurred()) {'
yield '\tRPyConvertExceptionToCPython();'
yield '\treturn NULL;'
yield '}'
retval = self.expr(block.inputargs[0])
+ if self.exception_policy != "exc_helper":
+ yield 'RPY_DEBUG_RETURN();'
yield 'return %s;' % retval
continue
elif block.exitswitch is None:
@@ -717,10 +719,6 @@
c_string_constant(' '.join(format) + '\n\000'),
''.join([', ' + s for s in argv]))
- def OP_DEBUG_LOG_EXC(self, op):
- exc_type = self.expr(op.args[0])
- return 'RPY_LOG_EXC(%s);' % exc_type
-
def OP_DEBUG_ASSERT(self, op):
return '/* debug_assert removed */'
Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py (original)
+++ pypy/dist/pypy/translator/c/node.py Sun Nov 19 17:37:02 2006
@@ -698,8 +698,9 @@
raise ValueError, "trying to compile suggested primitive %r" % (
fnobj._callable,)
elif hasattr(fnobj, 'graph'):
- cpython_exc = getattr(fnobj, 'exception_policy', None) == "CPython"
- return [FunctionCodeGenerator(fnobj.graph, db, cpython_exc, functionname)]
+ exception_policy = getattr(fnobj, 'exception_policy', None)
+ return [FunctionCodeGenerator(fnobj.graph, db, exception_policy,
+ functionname)]
elif getattr(fnobj, 'external', None) == 'C':
# deprecated case
if hasattr(fnobj, 'includes'):
Modified: pypy/dist/pypy/translator/c/src/exception.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/exception.h (original)
+++ pypy/dist/pypy/translator/c/src/exception.h Sun Nov 19 17:37:02 2006
@@ -6,7 +6,9 @@
PyObject *RPythonError;
#endif
-#define RPY_LOG_EXC(exc_type)
+/* just a renaming, unless DO_LOG_EXC is set */
+#define RPyExceptionOccurred RPyExceptionOccurred1
+#define RPY_DEBUG_RETURN() /* nothing */
#ifndef PyExceptionClass_Check /* Python < 2.5 */
# define PyExceptionClass_Check(x) PyClass_Check(x)
@@ -21,13 +23,27 @@
/******************************************************************/
#ifdef DO_LOG_EXC
-#undef RPY_LOG_EXC
-#define RPY_LOG_EXC(exc_type) if(exc_type) { \
- fprintf(stderr, "propagating %s:%ld %s %s\n", \
- __FILE__, __LINE__, __FUNCTION__, \
- exc_type->ov_name->items); \
+#undef RPyExceptionOccurred
+#undef RPY_DEBUG_RETURN
+#define RPyExceptionOccurred() RPyDebugException(" noticing a")
+#define RPY_DEBUG_RETURN() RPyDebugException("leaving with")
+#define RPyDebugException(msg) ( \
+ RPyExceptionOccurred1() \
+ ? (RPyDebugReturnShowException(msg, __FILE__, __LINE__, __FUNCTION__), 1) \
+ : 0 \
+ )
+void RPyDebugReturnShowException(const char *msg, const char *filename,
+ long lineno, const char *functionname);
+#ifndef PYPY_NOT_MAIN_FILE
+void RPyDebugReturnShowException(const char *msg, const char *filename,
+ long lineno, const char *functionname)
+{
+ fprintf(stderr, "%s %s: %s:%ld %s\n", msg,
+ RPyFetchExceptionType()->ov_name->items,
+ filename, lineno, functionname);
}
#endif
+#endif /* DO_LOG_EXC */
/* Hint: functions and macros not defined here, like RPyRaiseException,
come from exctransformer via the table in extfunc.py. */
@@ -109,7 +125,7 @@
#else /* non-RPython version of exceptions, using CPython only */
/******************************************************************/
-#define RPyExceptionOccurred() PyErr_Occurred()
+#define RPyExceptionOccurred1() PyErr_Occurred()
#define RPyRaiseException(etype, evalue) PyErr_Restore(etype, evalue, NULL)
#define RPyFetchException(etypevar, evaluevar, ignored) do { \
PyObject *__tb; \
More information about the Pypy-commit
mailing list