diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2019-03-03 22:04:39 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2019-03-03 22:04:39 +0100 |
commit | 61505ce492a8060f3458954320a5533d22a87c03 (patch) | |
tree | b4e42922aedae77ee44415881264857acc30e3e2 /Cython/Compiler/ExprNodes.py | |
parent | e8a9ab94f2334eb57550d0f29a337d230ae1ba88 (diff) | |
download | cython-61505ce492a8060f3458954320a5533d22a87c03.tar.gz |
Issue a warning when casting a GIL-requiring function into a nogil function (which breaks GIL validation).
Closes GH-2879.
Diffstat (limited to 'Cython/Compiler/ExprNodes.py')
-rw-r--r-- | Cython/Compiler/ExprNodes.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index ed08eeb8a..fa8575a98 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -10426,7 +10426,8 @@ class TypecastNode(ExprNode): error(self.pos, "Python objects cannot be cast from pointers of primitive types") else: # Should this be an error? - warning(self.pos, "No conversion from %s to %s, python object pointer used." % (self.operand.type, self.type)) + warning(self.pos, "No conversion from %s to %s, python object pointer used." % ( + self.operand.type, self.type)) self.operand = self.operand.coerce_to_simple(env) elif from_py and not to_py: if self.type.create_from_py_utility_code(env): @@ -10435,7 +10436,8 @@ class TypecastNode(ExprNode): if not (self.type.base_type.is_void or self.type.base_type.is_struct): error(self.pos, "Python objects cannot be cast to pointers of primitive types") else: - warning(self.pos, "No conversion from %s to %s, python object pointer used." % (self.type, self.operand.type)) + warning(self.pos, "No conversion from %s to %s, python object pointer used." % ( + self.type, self.operand.type)) elif from_py and to_py: if self.typecheck: self.operand = PyTypeTestNode(self.operand, self.type, env, notnone=True) @@ -10447,6 +10449,13 @@ class TypecastNode(ExprNode): elif self.operand.type.is_fused: self.operand = self.operand.coerce_to(self.type, env) #self.type = self.operand.type + if self.type.is_ptr and self.type.base_type.is_cfunction and self.type.base_type.nogil: + op_type = self.operand.type + if op_type.is_ptr: + op_type = op_type.base_type + if op_type.is_cfunction and not op_type.nogil: + warning(self.pos, + "Casting a GIL-requiring function into a nogil function circumvents GIL validation", 1) return self def is_simple(self): |