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:
"""
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,
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')
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
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)
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")