From 22516cc1a425b8d124d94613b87a94d4da68a034 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 27 Dec 2010 10:38:00 +0100 Subject: [PATCH] re-allow Python values in ExprStatNode and NameNode in nogil sections if they do not need cleanup (e.g. cached builtin names or constants) --- Cython/Compiler/ExprNodes.py | 4 ++-- Cython/Compiler/Nodes.py | 2 +- tests/errors/nogil.pyx | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 38ab6813..6a42cfed 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1431,8 +1431,8 @@ class NameNode(AtomicExprNode): if self.is_used_as_rvalue: entry = self.entry if entry.is_builtin: - # if not Options.cache_builtins: # cached builtins are ok - self.gil_error() + if not Options.cache_builtins: # cached builtins are ok + self.gil_error() elif entry.is_pyglobal: self.gil_error() diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index e9d889e5..92c051ac 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3347,7 +3347,7 @@ class ExprStatNode(StatNode): self.expr.analyse_expressions(env) def nogil_check(self, env): - if self.expr.type.is_pyobject: + if self.expr.type.is_pyobject and self.expr.is_temp: self.gil_error() gil_message = "Discarding owned Python object" diff --git a/tests/errors/nogil.pyx b/tests/errors/nogil.pyx index 387818ca..623d1ff4 100644 --- a/tests/errors/nogil.pyx +++ b/tests/errors/nogil.pyx @@ -82,8 +82,12 @@ def ticket_338(): for obj from 0 <= obj < 4: pass +def bare_pyvar_name(object x): + with nogil: + x + # For m(), the important thing is that there are errors on all lines in the range 23-69 -# except these: 34, 44, 56, 58, 60, 62-64 +# except these: 29, 34, 44, 56, 58, 60, 62-64 _ERRORS = u""" 1:5: Function with Python return type cannot be declared nogil @@ -96,8 +100,6 @@ _ERRORS = u""" 26:12: Assignment of Python object not allowed without gil 28:8: Discarding owned Python object not allowed without gil 28:16: Constructing complex number not allowed without gil -29:12: Accessing Python global or builtin not allowed without gil -29:12: Discarding owned Python object not allowed without gil 30:8: Backquote expression not allowed without gil 30:8: Discarding owned Python object not allowed without gil 30:9: Operation not allowed without gil -- 2.26.2