Commit dd57b2de authored by Stefan Behnel's avatar Stefan Behnel

handle some more cases where the error status is known to be used and clean up...

handle some more cases where the error status is known to be used and clean up 'unraisable exception' code
parent 072f3834
......@@ -1919,8 +1919,10 @@ class CCodeWriter(object):
entry.name,
self.error_goto(pos)))
def set_error_info(self, pos):
def set_error_info(self, pos, used=False):
self.funcstate.should_declare_error_indicator = True
if used:
self.funcstate.uses_error_indicator = True
if self.c_line_in_traceback:
cinfo = " %s = %s;" % (Naming.clineno_cname, Naming.line_c_macro)
else:
......@@ -1972,7 +1974,7 @@ class CCodeWriter(object):
"""
Build a Python traceback for propagating exceptions.
qualified_name should be the qualified name of the function
qualified_name should be the qualified name of the function.
"""
format_tuple = (
qualified_name,
......@@ -1983,6 +1985,23 @@ class CCodeWriter(object):
self.funcstate.uses_error_indicator = True
self.putln('__Pyx_AddTraceback("%s", %s, %s, %s);' % format_tuple)
def put_unraisable(self, qualified_name):
"""
Generate code to print a Python warning for an unraisable exception.
qualified_name should be the qualified name of the function.
"""
format_tuple = (
qualified_name,
Naming.clineno_cname,
Naming.lineno_cname,
Naming.filename_cname,
)
self.funcstate.uses_error_indicator = True
self.putln('__Pyx_WriteUnraisable("%s", %s, %s, %s);' % format_tuple)
self.globalstate.use_utility_code(
UtilityCode.load_cached("WriteUnraisableException", "Exceptions.c"))
def put_trace_declarations(self):
self.putln('__Pyx_TraceDeclarations')
......
......@@ -9008,7 +9008,7 @@ class DivNode(NumBinopNode):
self.operand1.result(),
self.operand2.result()))
code.put_ensure_gil()
code.putln(code.set_error_info(self.pos))
code.putln(code.set_error_info(self.pos, used=True))
code.putln("if (__Pyx_cdivision_warning(%(FILENAME)s, "
"%(LINENO)s)) {" % {
'FILENAME': Naming.filename_cname,
......
......@@ -1798,18 +1798,10 @@ class FuncDefNode(StatNode, BlockNode):
code.put_release_ensured_gil()
code.putln("}")
else:
warning(self.entry.pos, "Unraisable exception in function '%s'." \
% self.entry.qualified_name, 0)
format_tuple = (
self.entry.qualified_name,
Naming.clineno_cname,
Naming.lineno_cname,
Naming.filename_cname,
)
code.putln(
'__Pyx_WriteUnraisable("%s", %s, %s, %s);' % format_tuple)
env.use_utility_code(unraisable_exception_utility_code)
env.use_utility_code(restore_exception_utility_code)
warning(self.entry.pos,
"Unraisable exception in function '%s'." %
self.entry.qualified_name, 0)
code.put_unraisable(self.entry.qualified_name)
default_retval = self.return_type.default_value
if err_val is None and default_retval:
err_val = default_retval
......@@ -7402,6 +7394,7 @@ class ParallelStatNode(StatNode, ParallelNode):
code.putln("__Pyx_ErrFetch(&%s, &%s, &%s);" % self.parallel_exc)
pos_info = chain(*zip(self.parallel_pos_info, self.pos_info))
code.funcstate.uses_error_indicator = True
code.putln("%s = %s; %s = %s; %s = %s;" % tuple(pos_info))
code.putln('__Pyx_GOTREF(%s);' % Naming.parallel_exc_type)
......@@ -8076,7 +8069,6 @@ restore_exception_utility_code = UtilityCode.load_cached("PyErrFetchRestore", "E
raise_utility_code = UtilityCode.load_cached("RaiseException", "Exceptions.c")
get_exception_utility_code = UtilityCode.load_cached("GetException", "Exceptions.c")
swap_exception_utility_code = UtilityCode.load_cached("SwapException", "Exceptions.c")
unraisable_exception_utility_code = UtilityCode.load_cached("WriteUnraisableException", "Exceptions.c")
reset_exception_utility_code = UtilityCode.load_cached("SaveResetException", "Exceptions.c")
traceback_utility_code = UtilityCode.load_cached("AddTraceback", "Exceptions.c")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment