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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
22dda2e4
Commit
22dda2e4
authored
Dec 09, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
call Py_TYPE(x) instead of type(x)
parent
bd1964ac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
27 deletions
+56
-27
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+1
-1
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+14
-25
tests/run/builtin_type.pyx
tests/run/builtin_type.pyx
+40
-0
No files found.
Cython/Compiler/Builtin.py
View file @
22dda2e4
...
...
@@ -50,7 +50,7 @@ builtin_function_table = [
#('round', "", "", ""),
(
'setattr'
,
"OOO"
,
"r"
,
"PyObject_SetAttr"
),
#('sum', "", "", ""),
(
'type'
,
"O"
,
"O"
,
"PyObject_Type"
),
#
('type', "O", "O", "PyObject_Type"),
#('unichr', "", "", ""),
#('unicode', "", "", ""),
#('vars', "", "", ""),
...
...
Cython/Compiler/ExprNodes.py
View file @
22dda2e4
...
...
@@ -2615,7 +2615,7 @@ class SimpleCallNode(CallNode):
func_type
.
opt_arg_cname
(
formal_arg
.
name
),
actual_arg
.
result_as
(
formal_arg
.
type
)))
exc_checks
=
[]
if
self
.
type
.
is_pyobject
:
if
self
.
type
.
is_pyobject
and
self
.
is_temp
:
exc_checks
.
append
(
"!%s"
%
self
.
result
())
else
:
exc_val
=
func_type
.
exception_value
...
...
Cython/Compiler/Optimize.py
View file @
22dda2e4
...
...
@@ -843,20 +843,6 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform):
return
replace_in
(
arg
)
return
node
Pyx_Type_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
type_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"object"
,
PyrexTypes
.
py_object_type
,
None
)
])
def
_handle_simple_function_type
(
self
,
node
,
pos_args
):
if
len
(
pos_args
)
!=
1
:
return
node
self
.
_inject_capi_function
(
node
,
"__Pyx_Type"
,
self
.
Pyx_Type_func_type
,
pytype_utility_code
)
return
node
def
_handle_simple_function_float
(
self
,
node
,
pos_args
):
if
len
(
pos_args
)
==
0
:
return
ExprNodes
.
FloatNode
(
node
.
pos
,
value
=
'0.0'
)
...
...
@@ -1188,6 +1174,20 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
)
return
node
Pyx_Type_func_type
=
PyrexTypes
.
CFuncType
(
Builtin
.
type_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"object"
,
PyrexTypes
.
py_object_type
,
None
)
])
def
_handle_simple_function_type
(
self
,
node
,
pos_args
):
if
len
(
pos_args
)
!=
1
:
return
node
node
=
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"Py_TYPE"
,
self
.
Pyx_Type_func_type
,
args
=
pos_args
,
is_temp
=
False
)
return
ExprNodes
.
CastNode
(
node
,
PyrexTypes
.
py_object_type
)
### special methods
Pyx_tp_new_func_type
=
PyrexTypes
.
CFuncType
(
...
...
@@ -1702,17 +1702,6 @@ bad:
)
pytype_utility_code
=
UtilityCode
(
proto
=
"""
static INLINE PyObject* __Pyx_Type(PyObject* o) {
PyObject* type = (PyObject*) Py_TYPE(o);
Py_INCREF(type);
return type;
}
"""
)
include_string_h_utility_code
=
UtilityCode
(
proto
=
"""
#include <string.h>
...
...
tests/run/builtin_type.pyx
0 → 100644
View file @
22dda2e4
cimport
cython
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode/PythonCapiFunctionNode[@cname="Py_TYPE"]'
)
def
get_type_of
(
a
):
"""
>>> get_type_of(object()) is object
True
"""
return
type
(
a
)
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode/PythonCapiFunctionNode[@cname="Py_TYPE"]'
)
def
get_type_through_local
(
a
):
"""
>>> get_type_of(object()) is object
True
"""
t
=
type
(
a
)
return
t
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode/PythonCapiFunctionNode[@cname="Py_TYPE"]'
)
@
cython
.
test_fail_if_path_exists
(
'//PythonCapiCallNode/PythonCapiFunctionNode[@cname="__Pyx_Type"]'
,
'//NameNode[@name="type"]'
)
def
test_type
(
a
,
t
):
"""
>>> test_type(object(), object)
True
"""
return
type
(
a
)
and
type
(
a
)
is
t
and
type
(
a
)
==
t
@
cython
.
test_assert_path_exists
(
'//NameNode[@name="type"]'
)
def
type_type
():
"""
>>> type_type()(object()) is object
True
"""
return
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