Commit 681dcbf4 authored by Craig Citro's avatar Craig Citro

Make str unsafe for type inference. See trac #553.

parent b091fe65
...@@ -314,8 +314,14 @@ def safe_spanning_type(types, might_overflow): ...@@ -314,8 +314,14 @@ def safe_spanning_type(types, might_overflow):
if result_type.is_reference: if result_type.is_reference:
result_type = result_type.ref_base_type result_type = result_type.ref_base_type
if result_type.is_pyobject: if result_type.is_pyobject:
# any specific Python type is always safe to infer # In theory, any specific Python type is always safe to
return result_type # infer. However, inferring str can cause some existing code
# to break, since we are also now much more strict about
# coercion from str to char *. See trac #553.
if result_type.name == 'str':
return py_object_type
else:
return result_type
elif result_type is PyrexTypes.c_double_type: elif result_type is PyrexTypes.c_double_type:
# Python's float type is just a C double, so it's safe to use # Python's float type is just a C double, so it's safe to use
# the C type instead # the C type instead
......
...@@ -362,6 +362,11 @@ def safe_only(): ...@@ -362,6 +362,11 @@ def safe_only():
res = ~d res = ~d
assert typeof(d) == "long", typeof(d) assert typeof(d) == "long", typeof(d)
# we special-case inference to type str, see
# trac #
s = "abc"
assert typeof(s) == "Python object", typeof(s)
# potentially overflowing arithmetic # potentially overflowing arithmetic
e = 1 e = 1
e += 1 e += 1
......
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