Commit 1bd74d59 authored by Stefan Behnel's avatar Stefan Behnel

warn when taking char* from a global Python variable (which is externally modifiable)

parent 6d4efb6e
...@@ -9187,9 +9187,14 @@ class CoerceFromPyTypeNode(CoercionNode): ...@@ -9187,9 +9187,14 @@ class CoerceFromPyTypeNode(CoercionNode):
if not result_type.create_from_py_utility_code(env): if not result_type.create_from_py_utility_code(env):
error(arg.pos, error(arg.pos,
"Cannot convert Python object to '%s'" % result_type) "Cannot convert Python object to '%s'" % result_type)
if self.type.is_string and self.arg.is_ephemeral(): if self.type.is_string:
error(arg.pos, if self.arg.is_ephemeral():
"Obtaining char * from temporary Python value") 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): def analyse_types(self, env):
# The arg is always already analysed # The arg is always already analysed
......
# mode: error
# tag: werror, charptr, conversion, temp
s = b"abc"
cdef char* cptr
cptr = s
cptr = s + b"cba"
_ERRORS = """
8:8: Obtaining char* from externally modifiable global Python value
10: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