Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
cython
Commits
5d496c99
Commit
5d496c99
authored
Jul 29, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix typedefs of types convertible to Python always infering to PyObject
parent
06ba4584
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+18
-11
No files found.
Cython/Compiler/TypeInference.py
View file @
5d496c99
...
@@ -547,33 +547,40 @@ def aggressive_spanning_type(types, might_overflow, pos, scope):
...
@@ -547,33 +547,40 @@ def aggressive_spanning_type(types, might_overflow, pos, scope):
def
safe_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
)
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
# In theory, any specific Python type is always safe to
# infer. However, inferring str can cause some existing code
# infer. However, inferring str can cause some existing code
# to break, since we are also now much more strict about
# to break, since we are also now much more strict about
# coercion from str to char *. See trac #553.
# coercion from str to char *. See trac #553.
if
result_type
.
name
==
'str'
:
if
res
olved_res
ult_type
.
name
==
'str'
:
return
py_object_type
return
py_object_type
else
:
else
:
return
result_type
return
result_type
elif
result_type
is
PyrexTypes
.
c_double_type
:
elif
res
olved_res
ult_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
return
result_type
return
result_type
elif
result_type
is
PyrexTypes
.
c_bint_type
:
elif
res
olved_res
ult_type
is
PyrexTypes
.
c_bint_type
:
# find_spanning_type() only returns 'bint' for clean boolean
# find_spanning_type() only returns 'bint' for clean boolean
# operations without other int types, so this is safe, too
# operations without other int types, so this is safe, too
return
result_type
return
result_type
elif
result_type
.
is_pythran_expr
:
elif
res
olved_res
ult_type
.
is_pythran_expr
:
return
result_type
return
result_type
elif
result_type
.
is_ptr
:
elif
res
olved_res
ult_type
.
is_ptr
:
# Any pointer except (signed|unsigned|) char* can't implicitly
# Any pointer except (signed|unsigned|) char* can't implicitly
# become a PyObject, and inferring char* is now accepted, too.
# become a PyObject, and inferring char* is now accepted, too.
return
result_type
return
result_type
elif
result_type
.
is_cpp_class
:
elif
res
olved_res
ult_type
.
is_cpp_class
:
# These can't implicitly become Python objects either.
# These can't implicitly become Python objects either.
return
result_type
return
result_type
elif
result_type
.
is_struct
:
elif
res
olved_res
ult_type
.
is_struct
:
# Though we have struct -> object for some structs, this is uncommonly
# Though we have struct -> object for some structs, this is uncommonly
# used, won't arise in pure Python, and there shouldn't be side
# used, won't arise in pure Python, and there shouldn't be side
# effects, so I'm declaring this safe.
# effects, so I'm declaring this safe.
...
@@ -582,10 +589,10 @@ def safe_spanning_type(types, might_overflow, pos, scope):
...
@@ -582,10 +589,10 @@ def safe_spanning_type(types, might_overflow, pos, scope):
return
result_type
return
result_type
# TODO: double complex should be OK as well, but we need
# TODO: double complex should be OK as well, but we need
# to make sure everything is supported.
# to make sure everything is supported.
elif
(
res
ult_type
.
is_int
or
result_type
.
is_enum
)
and
not
might_overflow
:
elif
(
res
olved_result_type
.
is_int
or
resolved_
result_type
.
is_enum
)
and
not
might_overflow
:
return
result_type
return
result_type
elif
(
not
result_type
.
can_coerce_to_pyobject
(
scope
)
elif
(
not
res
olved_res
ult_type
.
can_coerce_to_pyobject
(
scope
)
and
not
result_type
.
is_error
):
and
not
res
olved_res
ult_type
.
is_error
):
return
result_type
return
result_type
return
py_object_type
return
py_object_type
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment