Commit eb637f5e authored by Stefan Behnel's avatar Stefan Behnel

do not consider indexing unsafe - reference will live safely in a container in most cases

parent 37e4a206
......@@ -2806,7 +2806,8 @@ class IndexNode(ExprNode):
def is_ephemeral(self):
# in most cases, indexing will return a safe reference to an object in a container,
# so we consider the result safe if the base object is
return self.base.is_ephemeral()
return self.base.is_ephemeral() or self.base.type in (
basestring_type, str_type, bytes_type, unicode_type)
def is_simple(self):
if self.is_buffer_access or self.memslice_index:
......@@ -10891,7 +10892,7 @@ class CoerceFromPyTypeNode(CoercionNode):
return self
def is_ephemeral(self):
return self.type.is_ptr and self.arg.is_temp and not self.arg.is_name
return self.type.is_ptr and self.arg.is_ephemeral()
def generate_result_code(self, code):
function = self.type.from_py_function
......
......@@ -18,7 +18,7 @@ cptr = s
# temp => error
cptr = s + b"cba"
# indexing => error
# indexing => error (but not clear enough to make it a compiler error)
cptr = s[0]
cdef char* x = <char*>s[0]
......@@ -47,8 +47,9 @@ cuptr = u + u"cba"
_ERRORS = """
16:8: Obtaining 'char *' from externally modifiable global Python value
19:9: Storing unsafe C derivative of temporary Python reference
22:8: Storing unsafe C derivative of temporary Python reference
23:5: Storing unsafe C derivative of temporary Python reference
#22:8: Storing unsafe C derivative of temporary Python reference
#23:5: Storing unsafe C derivative of temporary Python reference
#23:15: Casting temporary Python object to non-numeric non-Python type
26:8: Storing unsafe C derivative of temporary Python reference
41:9: Obtaining 'Py_UNICODE *' from externally modifiable global Python value
44:10: Storing unsafe C derivative of temporary Python reference
......
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