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
Boxiang Sun
cython
Commits
026e3de9
Commit
026e3de9
authored
Feb 21, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reference type inference
parent
9444212e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+4
-0
tests/wrappers/cpp_references.pyx
tests/wrappers/cpp_references.pyx
+16
-0
No files found.
Cython/Compiler/TypeInference.py
View file @
026e3de9
...
...
@@ -276,10 +276,14 @@ def find_spanning_type(type1, type2):
def
aggressive_spanning_type
(
types
,
might_overflow
):
result_type
=
reduce
(
find_spanning_type
,
types
)
if
result_type
.
is_reference
:
result_type
=
result_type
.
ref_base_type
return
result_type
def
safe_spanning_type
(
types
,
might_overflow
):
result_type
=
reduce
(
find_spanning_type
,
types
)
if
result_type
.
is_reference
:
result_type
=
result_type
.
ref_base_type
if
result_type
.
is_pyobject
:
# any specific Python type is always safe to infer
return
result_type
...
...
tests/wrappers/cpp_references.pyx
View file @
026e3de9
cimport
cython
cdef
extern
from
"cpp_references_helper.h"
:
cdef
int
&
ref_func
(
int
&
)
cdef
int
ref_var_value
cdef
int
&
ref_var
def
test_ref_func
(
int
x
):
"""
>>> test_ref_func(2)
...
...
@@ -42,3 +46,15 @@ def test_ref_assign(int x):
"""
cdef
double
d
=
ref_func
(
x
)
return
d
@
cython
.
infer_types
(
True
)
def
test_ref_inference
(
int
x
):
"""
>>> test_ref_inference(23)
23
>>> test_ref_inference(29)
29
"""
z
=
ref_func
(
x
)
assert
cython
.
typeof
(
z
)
==
"int"
,
cython
.
typeof
(
z
)
return
z
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