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
Gwenaël Samain
cython
Commits
95228cfe
Commit
95228cfe
authored
Oct 07, 2014
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Infer pointer type for array assignment.
parent
e1d36b1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+4
-0
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+14
-0
No files found.
Cython/Compiler/TypeInference.py
View file @
95228cfe
...
...
@@ -502,6 +502,8 @@ def aggressive_spanning_type(types, might_overflow, pos):
result_type
=
result_type
.
const_base_type
if
result_type
.
is_cpp_class
:
result_type
.
check_nullary_constructor
(
pos
)
if
result_type
.
is_array
:
result_type
=
PyrexTypes
.
c_ptr_type
(
result_type
.
base_type
)
return
result_type
def
safe_spanning_type
(
types
,
might_overflow
,
pos
):
...
...
@@ -512,6 +514,8 @@ def safe_spanning_type(types, might_overflow, pos):
result_type
=
result_type
.
ref_base_type
if
result_type
.
is_cpp_class
:
result_type
.
check_nullary_constructor
(
pos
)
if
result_type
.
is_array
:
result_type
=
PyrexTypes
.
c_ptr_type
(
result_type
.
base_type
)
if
result_type
.
is_pyobject
:
# In theory, any specific Python type is always safe to
# infer. However, inferring str can cause some existing code
...
...
tests/run/type_inference.pyx
View file @
95228cfe
...
...
@@ -494,6 +494,20 @@ def safe_c_functions():
assert
typeof
(
f
)
==
'int (*)(int)'
,
typeof
(
f
)
assert
2
==
f
(
1
)
@
infer_types
(
None
)
def
ptr_types
():
"""
>>> ptr_types()
"""
cdef
int
a
a_ptr
=
&
a
assert
typeof
(
a_ptr
)
==
"int *"
,
typeof
(
a_ptr
)
a_ptr_ptr
=
&
a_ptr
assert
typeof
(
a_ptr_ptr
)
==
"int **"
,
typeof
(
a_ptr_ptr
)
cdef
int
[
1
]
b
b_ref
=
b
assert
typeof
(
b_ref
)
==
"int *"
,
typeof
(
b_ref
)
@
infer_types
(
None
)
def
args_tuple_keywords
(
*
args
,
**
kwargs
):
"""
...
...
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