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
5b19736e
Commit
5b19736e
authored
Feb 23, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify code for directly calling module internal tp_new() slot function
parent
9fd5c96d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
43 deletions
+18
-43
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+18
-37
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+0
-6
No files found.
Cython/Compiler/Optimize.py
View file @
5b19736e
...
@@ -2153,21 +2153,6 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
...
@@ -2153,21 +2153,6 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
PyrexTypes
.
CFuncTypeArg
(
"kwargs"
,
Builtin
.
dict_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"kwargs"
,
Builtin
.
dict_type
,
None
),
])
])
Pyx_call_tp_new_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
py_object_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"tpnew_func"
,
PyrexTypes
.
c_void_ptr_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"type"
,
PyrexTypes
.
py_object_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"args"
,
Builtin
.
tuple_type
,
None
),
])
Pyx_call_tp_new_kwargs_func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
py_object_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"tpnew_func"
,
PyrexTypes
.
c_void_ptr_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"type"
,
PyrexTypes
.
py_object_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"args"
,
Builtin
.
tuple_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"kwargs"
,
Builtin
.
dict_type
,
None
),
])
def
_handle_any_slot__new__
(
self
,
node
,
args
,
is_unbound_method
,
kwargs
=
None
):
def
_handle_any_slot__new__
(
self
,
node
,
args
,
is_unbound_method
,
kwargs
=
None
):
"""Replace 'exttype.__new__(exttype, ...)' by a call to exttype->tp_new()
"""Replace 'exttype.__new__(exttype, ...)' by a call to exttype->tp_new()
"""
"""
...
@@ -2197,29 +2182,25 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
...
@@ -2197,29 +2182,25 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
if
type_arg
.
type_entry
:
if
type_arg
.
type_entry
:
ext_type
=
type_arg
.
type_entry
.
type
ext_type
=
type_arg
.
type_entry
.
type
if
ext_type
.
is_extension_type
and
not
ext_type
.
is_external
:
if
ext_type
.
is_extension_type
and
not
ext_type
.
is_external
:
utility_code
=
UtilityCode
.
load_cached
(
cython_scope
=
self
.
context
.
cython_scope
'call_tp_new'
,
'ObjectHandling.c'
)
PyTypeObjectPtr
=
PyrexTypes
.
CPtrType
(
slot_func_cname
=
ext_type
.
scope
.
mangle_internal
(
"tp_new"
)
cython_scope
.
lookup
(
'PyTypeObject'
).
type
)
slot_func
=
ExprNodes
.
RawCNameExprNode
(
pyx_tp_new_kwargs_func_type
=
PyrexTypes
.
CFuncType
(
node
.
pos
,
cname
=
slot_func_cname
,
PyrexTypes
.
py_object_type
,
[
type
=
PyrexTypes
.
c_void_ptr_type
)
PyrexTypes
.
CFuncTypeArg
(
"type"
,
PyTypeObjectPtr
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"args"
,
PyrexTypes
.
py_object_type
,
None
),
PyrexTypes
.
CFuncTypeArg
(
"kwargs"
,
PyrexTypes
.
py_object_type
,
None
),
])
if
kwargs
:
type_arg
=
ExprNodes
.
CastNode
(
type_arg
,
PyTypeObjectPtr
)
return
ExprNodes
.
PythonCapiCallNode
(
slot_func_cname
=
ext_type
.
scope
.
mangle_internal
(
"tp_new"
)
node
.
pos
,
"__Pyx_call_tp_new_kwargs"
,
if
not
kwargs
:
self
.
Pyx_call_tp_new_kwargs_func_type
,
kwargs
=
ExprNodes
.
NullNode
(
node
.
pos
,
type
=
PyrexTypes
.
py_object_type
)
# hack?
args
=
[
slot_func
,
type_arg
,
args_tuple
,
kwargs
],
return
ExprNodes
.
PythonCapiCallNode
(
utility_code
=
utility_code
,
node
.
pos
,
slot_func_cname
,
is_temp
=
node
.
is_temp
pyx_tp_new_kwargs_func_type
,
)
args
=
[
type_arg
,
args_tuple
,
kwargs
],
else
:
is_temp
=
True
)
return
ExprNodes
.
PythonCapiCallNode
(
node
.
pos
,
"__Pyx_call_tp_new"
,
self
.
Pyx_call_tp_new_func_type
,
args
=
[
slot_func
,
type_arg
,
args_tuple
],
utility_code
=
utility_code
,
is_temp
=
node
.
is_temp
)
else
:
else
:
# arbitrary variable, needs a None check for safety
# arbitrary variable, needs a None check for safety
type_arg
=
type_arg
.
as_none_safe_node
(
type_arg
=
type_arg
.
as_none_safe_node
(
...
...
Cython/Utility/ObjectHandling.c
View file @
5b19736e
...
@@ -658,9 +658,3 @@ bad:
...
@@ -658,9 +658,3 @@ bad:
static
CYTHON_INLINE
PyObject
*
__Pyx_tp_new_kwargs
(
PyObject
*
type_obj
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
static
CYTHON_INLINE
PyObject
*
__Pyx_tp_new_kwargs
(
PyObject
*
type_obj
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
return
(
PyObject
*
)
(((
PyTypeObject
*
)
type_obj
)
->
tp_new
((
PyTypeObject
*
)
type_obj
,
args
,
kwargs
));
return
(
PyObject
*
)
(((
PyTypeObject
*
)
type_obj
)
->
tp_new
((
PyTypeObject
*
)
type_obj
,
args
,
kwargs
));
}
}
/////////////// call_tp_new.proto ///////////////
#define __Pyx_call_tp_new(tp_new_func, type_obj, args) __Pyx_call_tp_new_kwargs(tp_new_func, type_obj, args, NULL)
#define __Pyx_call_tp_new_kwargs(tp_new_func, type_obj, args, kwargs) tp_new_func((PyTypeObject*)type_obj, 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