X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=Cython%2FCompiler%2FExprNodes.py;h=496aa461f1823da1932dcf43c974d30463856f94;hb=d8d2e019ad66eff1b1343ee0d5c4ab10d2b255ce;hp=ba6a82761f2e33873a13602ebe43d6e3c0d0f5c8;hpb=756d0872263f142c273b92e1ce1ebb5ebb1f4d92;p=cython.git diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index ba6a8276..496aa461 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1910,6 +1910,40 @@ class NextNode(AtomicExprNode): code.putln("}") +class WithExitCallNode(ExprNode): + # The __exit__() call of a 'with' statement. Used in both the + # except and finally clauses. + + # with_stat WithStatNode the surrounding 'with' statement + # args TupleNode or ResultStatNode the exception info tuple + + subexprs = ['args'] + + def analyse_types(self, env): + self.args.analyse_types(env) + self.type = PyrexTypes.c_bint_type + self.is_temp = True + + def generate_result_code(self, code): + if isinstance(self.args, TupleNode): + # call only if it was not already called (and decref-cleared) + code.putln("if (%s) {" % self.with_stat.exit_var) + result_var = code.funcstate.allocate_temp(py_object_type, manage_ref=False) + code.putln("%s = PyObject_Call(%s, %s, NULL);" % ( + result_var, + self.with_stat.exit_var, + self.args.result())) + code.put_decref_clear(self.with_stat.exit_var, type=py_object_type) + code.putln(code.error_goto_if_null(result_var, self.pos)) + code.put_gotref(result_var) + code.putln("%s = __Pyx_PyObject_IsTrue(%s);" % (self.result(), result_var)) + code.put_decref_clear(result_var, type=py_object_type) + code.putln(code.error_goto_if_neg(self.result(), self.pos)) + code.funcstate.release_temp(result_var) + if isinstance(self.args, TupleNode): + code.putln("}") + + class ExcValueNode(AtomicExprNode): # Node created during analyse_types phase # of an ExceptClauseNode to fetch the current @@ -1944,7 +1978,7 @@ class TempNode(ExprNode): subexprs = [] - def __init__(self, pos, type, env): + def __init__(self, pos, type, env=None): ExprNode.__init__(self, pos) self.type = type if type.is_pyobject: @@ -1954,6 +1988,9 @@ class TempNode(ExprNode): def analyse_types(self, env): return self.type + def analyse_target_declaration(self, env): + pass + def generate_result_code(self, code): pass @@ -8604,7 +8641,7 @@ static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args, CYTHON_UN if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb)) return NULL; - __Pyx_Raise(typ, val, tb); + __Pyx_Raise(typ, val, tb, NULL); return __Pyx_Generator_SendEx(generator, NULL); } """,