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
ee759881
Commit
ee759881
authored
Dec 14, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
do not generate vtable for subtypes of builtin types that do not define methods themselves
parent
ea858a2e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+13
-0
tests/run/builtin_type_inheritance_T608.pyx
tests/run/builtin_type_inheritance_T608.pyx
+68
-0
No files found.
Cython/Compiler/Symtab.py
View file @
ee759881
...
...
@@ -1121,6 +1121,19 @@ class ModuleScope(Scope):
type.vtabslot_cname = "%s.%s" % (
Naming.obj_base_cname, type.base_type.vtabslot_cname)
elif type.scope and type.scope.cfunc_entries:
# one special case here: when inheriting from builtin
# types, the methods may also be built-in, in which
# case they won'
t
need
a
vtable
entry_count
=
len
(
type
.
scope
.
cfunc_entries
)
base_type
=
type
.
base_type
while
base_type
:
# FIXME: this will break if we ever get non-inherited C methods
if
not
base_type
.
scope
or
entry_count
>
len
(
base_type
.
scope
.
cfunc_entries
):
break
if
base_type
.
is_builtin_type
:
# builtin base type defines all methods => no vtable needed
return
base_type
=
base_type
.
base_type
#print "...allocating vtabslot_cname because there are C methods" ###
type
.
vtabslot_cname
=
Naming
.
vtabslot_cname
if
type
.
vtabslot_cname
:
...
...
tests/run/builtin_type_inheritance_T608.pyx
View file @
ee759881
...
...
@@ -8,6 +8,35 @@ cdef class MyInt(int):
"""
cdef
readonly
object
attr
cdef
class
MyInt2
(
int
):
"""
>>> MyInt2(2) == 2
True
>>> MyInt2(2).attr is None
True
>>> MyInt2(2).test(3)
5
"""
cdef
readonly
object
attr
def
test
(
self
,
arg
):
return
self
.
_test
(
arg
)
cdef
_test
(
self
,
arg
):
return
self
+
arg
cdef
class
MyInt3
(
MyInt2
):
"""
>>> MyInt3(2) == 2
True
>>> MyInt3(2).attr is None
True
>>> MyInt3(2).test(3)
6
"""
cdef
_test
(
self
,
arg
):
return
self
+
arg
+
1
cdef
class
MyFloat
(
float
):
"""
>>> MyFloat(1.0)== 1.0
...
...
@@ -23,6 +52,8 @@ cdef class MyUnicode(unicode):
"""
>>> MyUnicode(ustring) == ustring
True
>>> MyUnicode(ustring + ustring) == ustring
False
>>> MyUnicode(ustring).attr is None
True
"""
...
...
@@ -37,6 +68,43 @@ cdef class MyList(list):
"""
cdef
readonly
object
attr
cdef
class
MyListOverride
(
list
):
"""
>>> MyListOverride([1,2,3]) == [1,2,3]
True
>>> l = MyListOverride([1,2,3])
>>> l.reverse()
>>> l
[1, 2, 3, 5]
>>> l._reverse()
>>> l
[1, 2, 3, 5, 5]
"""
# not doctested:
"""
>>> l = MyListOverride([1,2,3])
>>> l.append(8)
>>> l
[1, 2, 3, 0, 8]
>>> l._append(9)
>>> l
[1, 2, 3, 0, 8, 0, 9]
"""
def
reverse
(
self
):
self
[:]
=
self
+
[
5
]
def
_reverse
(
self
):
self
.
reverse
()
## FIXME: this doesn't currently work:
## cdef int append(self, value) except -1:
## self[:] = self + [0] + [value]
## return 0
## def _append(self, value):
## self.append(value)
cdef
class
MyDict
(
dict
):
"""
>>> MyDict({1:2, 3:4}) == {1:2, 3:4}
...
...
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