Commit 04c4aac2 authored by Robert Bradshaw's avatar Robert Bradshaw

Merge pull request #111 from scoder/_warn_charptr_from_pyglobal

warn when taking char* from a global Python variable
parents 5a8c28b3 dbefbb55
......@@ -9187,9 +9187,14 @@ class CoerceFromPyTypeNode(CoercionNode):
if not result_type.create_from_py_utility_code(env):
error(arg.pos,
"Cannot convert Python object to '%s'" % result_type)
if self.type.is_string and self.arg.is_ephemeral():
error(arg.pos,
"Obtaining char * from temporary Python value")
if self.type.is_string:
if self.arg.is_ephemeral():
error(arg.pos,
"Obtaining char* from temporary Python value")
elif self.arg.is_name and self.arg.entry and self.arg.entry.is_pyglobal:
warning(arg.pos,
"Obtaining char* from externally modifiable global Python value",
level=1)
def analyse_types(self, env):
# The arg is always already analysed
......
# mode: error
# tag: werror, charptr, conversion, temp
cdef bytes c_s = b"abc"
s = b"abc"
cdef char* cptr
# constant => ok
cptr = b"xyz"
# global cdef variable => ok
cptr = c_s
# pyglobal => warning
cptr = s
# temp => error
cptr = s + b"cba"
_ERRORS = """
16:8: Obtaining char* from externally modifiable global Python value
19:9: Obtaining char* from temporary Python value
"""
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