Commit 61505ce4 authored by Stefan Behnel's avatar Stefan Behnel

Issue a warning when casting a GIL-requiring function into a nogil function...

Issue a warning when casting a GIL-requiring function into a nogil function (which breaks GIL validation).
Closes GH-2879.
parent e8a9ab94
......@@ -11,6 +11,9 @@ Bugs fixed
* Coverage reporting did not include the signature line of ``cdef`` functions.
(Github issue #1461)
* Casting a GIL-requiring function into a nogil function now issues a warning.
(Github issue #2879)
0.29.6 (2019-02-27)
===================
......
......@@ -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):
......
# mode: error
# tag: warnings
cdef extern from *:
cdef void f()
cdef void (*fp)() nogil
ctypedef void (*fp_t)() nogil
fp = f
fp = <fp_t>f
_ERRORS = u"""
7:5: Cannot assign type 'void (void)' to 'void (*)(void) nogil'
9:5: Cannot assign type 'void (void)' to 'void (*)(void) nogil'
"""
_WARNINGS = """
10:5: Casting a GIL-requiring function into a nogil function circumvents GIL validation
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment