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
fe4c5c0c
Commit
fe4c5c0c
authored
Feb 23, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
try a potentially safer way to find out if we know the tp_new slot function of a type
parent
84c076b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
19 deletions
+36
-19
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+22
-19
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+14
-0
No files found.
Cython/Compiler/Optimize.py
View file @
fe4c5c0c
from
Cython.Compiler
import
TypeSlots
from
Cython.Compiler.ExprNodes
import
not_a_constant
import
cython
cython
.
declare
(
UtilityCode
=
object
,
EncodedString
=
object
,
BytesLiteral
=
object
,
...
...
@@ -2182,25 +2183,27 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
if
type_arg
.
type_entry
:
ext_type
=
type_arg
.
type_entry
.
type
if
ext_type
.
is_extension_type
and
not
ext_type
.
is_external
:
cython_scope
=
self
.
context
.
cython_scope
PyTypeObjectPtr
=
PyrexTypes
.
CPtrType
(
cython_scope
.
lookup
(
'PyTypeObject'
).
type
)
pyx_tp_new_kwargs_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
py_object_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"type"
,
PyTypeObjectPtr
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"args"
,
PyrexTypes
.
py_object_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"kwargs"
,
PyrexTypes
.
py_object_type
,
None
),
])
type_arg
=
ExprNodes
.
CastNode
(
type_arg
,
PyTypeObjectPtr
)
slot_func_cname
=
ext_type
.
scope
.
mangle_internal
(
"tp_new"
)
if
not
kwargs
:
kwargs
=
ExprNodes
.
NullNode
(
node
.
pos
,
type
=
PyrexTypes
.
py_object_type
)
# hack?
return
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
slot_func_cname
,
pyx_tp_new_kwargs_func_type
,
args
=
[
type_arg
,
args_tuple
,
kwargs
],
is_temp
=
True
)
tp_slot
=
TypeSlots
.
ConstructorSlot
(
"tp_new"
,
'__new__'
)
slot_func_cname
=
TypeSlots
.
get_slot_function
(
ext_type
.
scope
,
tp_slot
)
if
slot_func_cname
:
cython_scope
=
self
.
context
.
cython_scope
PyTypeObjectPtr
=
PyrexTypes
.
CPtrType
(
cython_scope
.
lookup
(
'PyTypeObject'
).
type
)
pyx_tp_new_kwargs_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
py_object_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"type"
,
PyTypeObjectPtr
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"args"
,
PyrexTypes
.
py_object_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"kwargs"
,
PyrexTypes
.
py_object_type
,
None
),
])
type_arg
=
ExprNodes
.
CastNode
(
type_arg
,
PyTypeObjectPtr
)
if
not
kwargs
:
kwargs
=
ExprNodes
.
NullNode
(
node
.
pos
,
type
=
PyrexTypes
.
py_object_type
)
# hack?
return
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
slot_func_cname
,
pyx_tp_new_kwargs_func_type
,
args
=
[
type_arg
,
args_tuple
,
kwargs
],
is_temp
=
True
)
else
:
# arbitrary variable, needs a None check for safety
type_arg
=
type_arg
.
as_none_safe_node
(
...
...
Cython/Compiler/TypeSlots.py
View file @
fe4c5c0c
...
...
@@ -493,11 +493,13 @@ def get_special_method_signature(name):
else
:
return
None
def
get_property_accessor_signature
(
name
):
# Return signature of accessor for an extension type
# property, else None.
return
property_accessor_signatures
.
get
(
name
)
def
get_base_slot_function
(
scope
,
slot
):
# Returns the function implementing this slot in the baseclass.
# This is useful for enabling the compiler to optimize calls
...
...
@@ -511,6 +513,18 @@ def get_base_slot_function(scope, slot):
return
parent_slot
return
None
def
get_slot_function
(
scope
,
slot
):
# Returns the function implementing this slot in the baseclass.
# This is useful for enabling the compiler to optimize calls
# that recursively climb the class hierarchy.
slot_code
=
slot
.
slot_code
(
scope
)
if
slot_code
!=
'0'
:
entry
=
scope
.
parent_scope
.
lookup_here
(
scope
.
parent_type
.
name
)
if
entry
.
visibility
!=
'extern'
:
return
slot_code
return
None
#------------------------------------------------------------------------------------------
#
# Signatures for generic Python functions and methods.
...
...
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