Commit 441bea80 authored by Xavier Thompson's avatar Xavier Thompson

Fix typedefs of types convertible to Python always infering to PyObject

parent f3b532d8
......@@ -547,33 +547,40 @@ def aggressive_spanning_type(types, might_overflow, pos, scope):
def safe_spanning_type(types, might_overflow, pos, scope):
result_type = simply_type(reduce(find_spanning_type, types), pos)
if result_type.is_pyobject:
# if the result type is a typedef, use the resolved type to make decisions
# but keep the unresolved type as the value to be returned
resolved_result_type = result_type
if result_type.is_typedef:
resolved_result_type = result_type.resolve()
if resolved_result_type.is_pyobject:
# In theory, any specific Python type is always safe to
# 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':
if resolved_result_type.name == 'str':
return py_object_type
else:
return result_type
elif result_type is PyrexTypes.c_double_type:
elif resolved_result_type is PyrexTypes.c_double_type:
# Python's float type is just a C double, so it's safe to use
# the C type instead
return result_type
elif result_type is PyrexTypes.c_bint_type:
elif resolved_result_type is PyrexTypes.c_bint_type:
# find_spanning_type() only returns 'bint' for clean boolean
# operations without other int types, so this is safe, too
return result_type
elif result_type.is_pythran_expr:
elif resolved_result_type.is_pythran_expr:
return result_type
elif result_type.is_ptr:
elif resolved_result_type.is_ptr:
# Any pointer except (signed|unsigned|) char* can't implicitly
# become a PyObject, and inferring char* is now accepted, too.
return result_type
elif result_type.is_cpp_class:
elif resolved_result_type.is_cpp_class:
# These can't implicitly become Python objects either.
return result_type
elif result_type.is_struct:
elif resolved_result_type.is_struct:
# Though we have struct -> object for some structs, this is uncommonly
# used, won't arise in pure Python, and there shouldn't be side
# effects, so I'm declaring this safe.
......@@ -582,10 +589,10 @@ def safe_spanning_type(types, might_overflow, pos, scope):
return result_type
# TODO: double complex should be OK as well, but we need
# to make sure everything is supported.
elif (result_type.is_int or result_type.is_enum) and not might_overflow:
elif (resolved_result_type.is_int or resolved_result_type.is_enum) and not might_overflow:
return result_type
elif (not result_type.can_coerce_to_pyobject(scope)
and not result_type.is_error):
elif (not resolved_result_type.can_coerce_to_pyobject(scope)
and not resolved_result_type.is_error):
return result_type
return py_object_type
......
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