提交 25297b8d authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Refactor after code review

上级 a1ec4942
......@@ -94,22 +94,36 @@ class CodeBlock:
"\ndouble __DUMMY_%(id)i;\n" % sub) # % sub
def failure_code(sub):
def failure_code(sub, use_goto=True):
"""
Code contained in sub['fail'], usually substituted for %(fail)s.
It sets information about current error, then goto the code
actually handling the failure, which is defined in struct_gen().
Parameters
----------
sub: dict
Contains other code snippets that can be substituted,
in particular 'failure_var' and 'id'.
use_goto: bool, True by default
Include a "goto" statement to the failure label.
Passing False is sometimes required, in which cases we have to
be careful to avoid executing incorrect code.
"""
if use_goto:
goto_statement = 'goto __label_%(id)i;' % sub
else:
goto_statement = ''
return '''{
%(failure_var)s = %(id)s;
%(failure_var)s = %(id)i;
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"Unexpected error in an Op's C code. "
"No Python exception was set.");
}
goto __label_%(id)i;}''' % sub
}
%(goto_statement)s}''' % dict(sub, goto_statement=goto_statement)
def failure_code_init(sub):
......
......@@ -1040,15 +1040,7 @@ second dimension
if self.openmp:
# If we are using openmp, we need to get rid of the "goto"
# statement in sub['fail']. For now we recreate it here.
fail = '''
{
%(failure_var)s = %(id)s;
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"Unexpected error in an Op's C code. "
"No Python exception was set.");
}
}''' % sub
fail = gof.cc.failure_code(sub, use_goto=False)
else:
fail = sub['fail']
task_code = self.scalar_op.c_code(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论