From 940d2711bd183a57340367f7767094f8f9354b82 Mon Sep 17 00:00:00 2001 From: Vitja Makarov Date: Fri, 10 Dec 2010 21:50:59 +0300 Subject: [PATCH] Change generator body signature to PyObject* (*body)(PyObject *, Pyobject *) --- Cython/Compiler/ExprNodes.py | 17 +++++++++-------- Cython/Compiler/Naming.py | 1 + Cython/Compiler/Nodes.py | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index fd1e66a5..c7e0adf8 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -5019,8 +5019,9 @@ class YieldExprNode(ExprNode): code.putln('%s = %s->%s;' % (cname, Naming.cur_scope_cname, save_cname)) if type.is_pyobject: code.putln('%s->%s = 0;' % (Naming.cur_scope_cname, save_cname)) - code.putln('%s = __pyx_send_value; %s' % - (self.result(), code.error_goto_if_null(self.result(), self.pos))) + code.putln('%s = %s; %s' % + (self.result(), Naming.sent_value_cname, + code.error_goto_if_null(self.result(), self.pos))) code.put_incref(self.result(), py_object_type) class StopIterationNode(Node): @@ -8308,10 +8309,10 @@ proto=""" static PyObject *__CyGenerator_Next(PyObject *self); static PyObject *__CyGenerator_Send(PyObject *self, PyObject *value); static PyObject *__CyGenerator_Close(PyObject *self); -typedef PyObject *(*__cygenerator_body_t)(PyObject *, PyObject *, int); +typedef PyObject *(*__cygenerator_body_t)(PyObject *, PyObject *); """, impl=""" -static CYTHON_INLINE PyObject *__CyGenerator_SendEx(struct __CyGenerator *self, PyObject *value, int is_exc) +static CYTHON_INLINE PyObject *__CyGenerator_SendEx(struct __CyGenerator *self, PyObject *value) { PyObject *retval; @@ -8336,7 +8337,7 @@ static CYTHON_INLINE PyObject *__CyGenerator_SendEx(struct __CyGenerator *self, } self->is_running = 1; - retval = self->body((PyObject *) self, value, is_exc); + retval = self->body((PyObject *) self, value); self->is_running = 0; return retval; @@ -8348,14 +8349,14 @@ static PyObject *__CyGenerator_Next(PyObject *self) PyObject *retval; Py_INCREF(Py_None); - retval = __CyGenerator_SendEx(generator, Py_None, 0); + retval = __CyGenerator_SendEx(generator, Py_None); Py_DECREF(Py_None); return retval; } static PyObject *__CyGenerator_Send(PyObject *self, PyObject *value) { - return __CyGenerator_SendEx((struct __CyGenerator *) self, value, 0); + return __CyGenerator_SendEx((struct __CyGenerator *) self, value); } static PyObject *__CyGenerator_Close(PyObject *self) @@ -8363,7 +8364,7 @@ static PyObject *__CyGenerator_Close(PyObject *self) struct __CyGenerator *generator = (struct __CyGenerator *) self; PyObject *retval; PyErr_SetNone(PyExc_GeneratorExit); - retval = __CyGenerator_SendEx(generator, NULL, 0); + retval = __CyGenerator_SendEx(generator, NULL); if (retval) { Py_DECREF(retval); PyErr_SetString(PyExc_RuntimeError, diff --git a/Cython/Compiler/Naming.py b/Cython/Compiler/Naming.py index 0dd4af8e..052c1e34 100644 --- a/Cython/Compiler/Naming.py +++ b/Cython/Compiler/Naming.py @@ -52,6 +52,7 @@ lambda_func_prefix = pyrex_prefix + "lambda_" module_is_main = pyrex_prefix + "module_is_main_" args_cname = pyrex_prefix + "args" +sent_value_cname = pyrex_prefix + "sent_value" pykwdlist_cname = pyrex_prefix + "pyargnames" obj_base_cname = pyrex_prefix + "base" builtins_cname = pyrex_prefix + "b" diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 48eb131b..364083f9 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1363,7 +1363,7 @@ class FuncDefNode(StatNode, BlockNode): code.use_label(first_run_label) code.put_label(first_run_label) code.putln('%s' % - (code.error_goto_if_null('__pyx_send_value', self.pos))) + (code.error_goto_if_null(Naming.sent_value_cname, self.pos))) if not self.is_generator: self.generate_argument_parsing_code(env, code) # If an argument is assigned to in the body, we must @@ -2395,8 +2395,8 @@ class DefNode(FuncDefNode): self.entry.pymethdef_cname) code.put_pymethoddef(self.entry, ";", allow_skip=False) if self.is_generator: - code.putln("static PyObject *%s(PyObject *%s, PyObject *__pyx_send_value, int __pyx_is_exc) /* generator body */\n{" % - (self.generator_body_cname, Naming.self_cname)) + code.putln("static PyObject *%s(PyObject *%s, PyObject *%s) /* generator body */\n{" % + (self.generator_body_cname, Naming.self_cname, Naming.sent_value_cname)) self.generator = GeneratorWrapperNode(self, func_cname=self.entry.func_cname, body_cname=self.generator_body_cname, -- 2.26.2