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
Gwenaël Samain
cython
Commits
33707f2e
Commit
33707f2e
authored
Mar 22, 2019
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid generating a tp_new() function for extension types that do not need their own one.
See #1555.
parent
85d2424f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
10 deletions
+65
-10
CHANGES.rst
CHANGES.rst
+5
-0
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+5
-2
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+5
-7
tests/run/exttype.pyx
tests/run/exttype.pyx
+48
-1
tests/run/tp_new.pyx
tests/run/tp_new.pyx
+2
-0
No files found.
CHANGES.rst
View file @
33707f2e
...
...
@@ -60,6 +60,11 @@ Bugs fixed
semantics
.
It
now
passes
through
the
Mapping
protocol
first
when
supported
.
(
Github
issue
#
1807
)
*
Extension
types
that
do
not
need
their
own
``
tp_new
``
implementation
(
because
they
have
no
object
attributes
etc
.)
directly
inherit
the
implementation
of
their
parent
type
if
that
is
available
in
the
same
module
.
(
Github
issue
#
1555
)
*
The
``
Py_hash_t
``
type
failed
to
accept
arbitrary
"index"
values
.
(
Github
issue
#
2752
)
...
...
Cython/Compiler/ModuleNode.py
View file @
33707f2e
...
...
@@ -1270,8 +1270,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type
.
empty_declaration_code
()))
def
generate_new_function
(
self
,
scope
,
code
,
cclass_entry
):
tp_slot
=
TypeSlots
.
ConstructorSlot
(
"tp_new"
,
'__new__'
)
tp_slot
=
TypeSlots
.
ConstructorSlot
(
"tp_new"
,
"__cinit__"
)
slot_func
=
scope
.
mangle_internal
(
"tp_new"
)
if
tp_slot
.
slot_code
(
scope
)
!=
slot_func
:
return
# never used
type
=
scope
.
parent_type
base_type
=
type
.
base_type
...
...
@@ -1554,7 +1557,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def
generate_usr_dealloc_call
(
self
,
scope
,
code
):
entry
=
scope
.
lookup_here
(
"__dealloc__"
)
if
not
entry
:
if
not
entry
or
not
entry
.
is_special
:
return
code
.
putln
(
"{"
)
...
...
Cython/Compiler/TypeSlots.py
View file @
33707f2e
...
...
@@ -362,17 +362,17 @@ class GCClearReferencesSlot(GCDependentSlot):
class
ConstructorSlot
(
InternalMethodSlot
):
# Descriptor for tp_new and tp_dealloc.
def
__init__
(
self
,
slot_name
,
method
,
**
kargs
):
def
__init__
(
self
,
slot_name
,
method
=
None
,
**
kargs
):
InternalMethodSlot
.
__init__
(
self
,
slot_name
,
**
kargs
)
self
.
method
=
method
def
slot_code
(
self
,
scope
):
entry
=
scope
.
lookup_here
(
self
.
method
)
if
(
self
.
slot_name
!=
'tp_new'
and
scope
.
parent_type
.
base_type
entry
=
scope
.
lookup_here
(
self
.
method
)
if
self
.
method
else
None
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
...
...
@@ -382,8 +382,6 @@ class ConstructorSlot(InternalMethodSlot):
entry
=
scope
.
parent_scope
.
lookup_here
(
scope
.
parent_type
.
base_type
.
name
)
if
entry
.
visibility
!=
'extern'
:
return
self
.
slot_code
(
parent_type_scope
)
if
entry
and
not
entry
.
is_special
:
return
"0"
return
InternalMethodSlot
.
slot_code
(
self
,
scope
)
...
...
@@ -877,7 +875,7 @@ slot_table = (
MethodSlot
(
initproc
,
"tp_init"
,
"__init__"
),
EmptySlot
(
"tp_alloc"
),
#FixedSlot("tp_alloc", "PyType_GenericAlloc"),
InternalMethodSlot
(
"tp_new
"
),
ConstructorSlot
(
"tp_new"
,
"__cinit__
"
),
EmptySlot
(
"tp_free"
),
EmptySlot
(
"tp_is_gc"
),
...
...
tests/run/exttype.pyx
View file @
33707f2e
# mode: run
# tag: exttype, tpnew
from
__future__
import
print_function
from
cpython.object
cimport
PyTypeObject
cdef
gobble
(
a
,
b
):
print
a
,
b
print
(
a
,
b
)
def
tp_new_ptr
(
exttype
):
assert
isinstance
(
exttype
,
type
)
tp
=
<
PyTypeObject
*>
exttype
return
<
unsigned
long
long
><
void
*>
tp
.
tp_new
cdef
class
Empty
:
"""
>>> n = Empty()
>>> isinstance(n, Empty)
True
>>> tp_new_ptr(Empty) != 0
True
"""
cdef
class
EmptySubclass
(
Empty
):
"""
>>> n = EmptySubclass()
>>> isinstance(n, EmptySubclass)
True
>>> tp_new_ptr(EmptySubclass) != 0
True
>>> tp_new_ptr(EmptySubclass) == tp_new_ptr(Empty)
True
"""
cdef
class
CInit
:
"""
>>> c = CInit()
>>> isinstance(c, CInit)
True
"""
def
__cinit__
(
self
):
assert
self
is
not
None
cdef
class
Spam
:
"""
...
...
@@ -21,6 +67,7 @@ cdef class Spam:
def
eat
(
self
):
gobble
(
self
.
eggs
,
self
.
ham
)
def
f
(
Spam
spam
):
"""
>>> s = Spam(12)
...
...
tests/run/tp_new.pyx
View file @
33707f2e
# mode: run
# tag: exttype, tpnew
# ticket: 808
cimport
cython
...
...
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