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
Kirill Smelkov
cython
Commits
4eef0edd
Commit
4eef0edd
authored
Mar 31, 2019
by
Stefan Behnel
Committed by
GitHub
Mar 31, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2909 from cython/less_tp_new
Avoid generating empty tp_new() functions
parents
d0833008
77098e74
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
9 deletions
+38
-9
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+38
-9
No files found.
Cython/Compiler/TypeSlots.py
View file @
4eef0edd
...
...
@@ -366,24 +366,53 @@ class ConstructorSlot(InternalMethodSlot):
InternalMethodSlot
.
__init__
(
self
,
slot_name
,
**
kargs
)
self
.
method
=
method
def
slot_code
(
self
,
scope
):
entry
=
scope
.
lookup_here
(
self
.
method
)
if
self
.
method
else
None
def
_needs_own
(
self
,
scope
):
if
(
scope
.
parent_type
.
base_type
and
not
scope
.
has_pyobject_attrs
and
not
scope
.
has_memoryview_attrs
and
not
scope
.
has_cpp_class_attrs
and
not
(
self
.
slot_name
==
'tp_new'
and
scope
.
parent_type
.
vtabslot_cname
)
and
not
(
entry
and
entry
.
is_special
)):
# if the type does not have object attributes, it can
# delegate GC methods to its parent - iff the parent
# functions are defined in the same module
and
not
(
self
.
slot_name
==
'tp_new'
and
scope
.
parent_type
.
vtabslot_cname
)):
entry
=
scope
.
lookup_here
(
self
.
method
)
if
self
.
method
else
None
if
not
(
entry
and
entry
.
is_special
):
return
False
# Unless we can safely delegate to the parent, all types need a tp_new().
return
True
def
_parent_slot_function
(
self
,
scope
):
parent_type_scope
=
scope
.
parent_type
.
base_type
.
scope
if
scope
.
parent_scope
is
parent_type_scope
.
parent_scope
:
entry
=
scope
.
parent_scope
.
lookup_here
(
scope
.
parent_type
.
base_type
.
name
)
if
entry
.
visibility
!=
'extern'
:
return
self
.
slot_code
(
parent_type_scope
)
return
None
def
slot_code
(
self
,
scope
):
if
not
self
.
_needs_own
(
scope
):
# if the type does not have object attributes, it can
# delegate GC methods to its parent - iff the parent
# functions are defined in the same module
slot_code
=
self
.
_parent_slot_function
(
scope
)
return
slot_code
or
'0'
return
InternalMethodSlot
.
slot_code
(
self
,
scope
)
def
generate_dynamic_init_code
(
self
,
scope
,
code
):
if
self
.
slot_code
(
scope
)
!=
'0'
:
return
# If we don't have our own slot function and don't know the
# parent function statically, copy it dynamically.
base_type
=
scope
.
parent_type
.
base_type
if
base_type
.
is_extension_type
and
base_type
.
typeobj_cname
:
src
=
'%s.%s'
%
(
base_type
.
typeobj_cname
,
self
.
slot_name
)
elif
base_type
.
typeptr_cname
:
src
=
'%s->%s'
%
(
base_type
.
typeptr_cname
,
self
.
slot_name
)
else
:
return
code
.
putln
(
"%s.%s = %s;"
%
(
scope
.
parent_type
.
typeobj_cname
,
self
.
slot_name
,
src
))
class
SyntheticSlot
(
InternalMethodSlot
):
# Type slot descriptor for a synthesized method which
...
...
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