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
03ea3932
Commit
03ea3932
authored
Oct 17, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix type inference for names of builtin functions
parent
6cf6fc66
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
2 deletions
+33
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-2
tests/run/builtin_abs.pyx
tests/run/builtin_abs.pyx
+9
-0
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+18
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
03ea3932
...
@@ -1349,8 +1349,12 @@ class NameNode(AtomicExprNode):
...
@@ -1349,8 +1349,12 @@ class NameNode(AtomicExprNode):
# is used for the pointer to the type they represent.
# is used for the pointer to the type they represent.
return
type_type
return
type_type
elif
self
.
entry
.
type
.
is_cfunction
:
elif
self
.
entry
.
type
.
is_cfunction
:
# special case: referring to a C function must return its pointer
if
self
.
entry
.
scope
.
is_builtin_scope
:
return
PyrexTypes
.
CPtrType
(
self
.
entry
.
type
)
# special case: optimised builtin functions must be treated as Python objects
return
py_object_type
else
:
# special case: referring to a C function must return its pointer
return
PyrexTypes
.
CPtrType
(
self
.
entry
.
type
)
else
:
else
:
return
self
.
entry
.
type
return
self
.
entry
.
type
...
...
tests/run/builtin_abs.pyx
View file @
03ea3932
...
@@ -12,6 +12,15 @@ max_long_long = 2 ** (sizeof(long long) * 8 - 1) - 1
...
@@ -12,6 +12,15 @@ max_long_long = 2 ** (sizeof(long long) * 8 - 1) - 1
cimport
cython
cimport
cython
def
abs_as_name
():
"""
>>> _abs = abs_as_name()
>>> _abs(-5)
5
"""
x
=
abs
return
x
def
py_abs
(
a
):
def
py_abs
(
a
):
"""
"""
>>> py_abs(-5)
>>> py_abs(-5)
...
...
tests/run/type_inference.pyx
View file @
03ea3932
...
@@ -221,6 +221,24 @@ def c_functions():
...
@@ -221,6 +221,24 @@ def c_functions():
assert
typeof
(
f
)
==
'int (*)(int)'
,
typeof
(
f
)
assert
typeof
(
f
)
==
'int (*)(int)'
,
typeof
(
f
)
assert
2
==
f
(
1
)
assert
2
==
f
(
1
)
def
builtin_functions
():
"""
>>> _abs, _getattr = builtin_functions()
Python object
Python object
>>> _abs(-1)
1
>>> class o(object): pass
>>> o.x = 1
>>> _getattr(o, 'x')
1
"""
_abs
=
abs
print
(
typeof
(
_abs
))
_getattr
=
getattr
print
(
typeof
(
_getattr
))
return
_abs
,
_getattr
def
cascade
():
def
cascade
():
"""
"""
>>> cascade()
>>> cascade()
...
...
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