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
68f92630
Commit
68f92630
authored
Apr 26, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix memory leak for memory views in extension subtypes
parent
58c7a899
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
1 deletion
+68
-1
CHANGES.rst
CHANGES.rst
+4
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+5
-1
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+1
-0
tests/memoryview/memoryview_in_subclasses.pyx
tests/memoryview/memoryview_in_subclasses.pyx
+58
-0
No files found.
CHANGES.rst
View file @
68f92630
...
@@ -15,6 +15,10 @@ Features added
...
@@ -15,6 +15,10 @@ Features added
Bugs fixed
Bugs fixed
----------
----------
* Memory leak when extension subtypes add a memory view as attribute
to those of the parent type without having Python object attributes
or a user provided dealloc method.
* Compiler crash on readonly properties in "binding" mode.
* Compiler crash on readonly properties in "binding" mode.
* Auto-encoding with ``c_string_encoding=ascii`` failed in Py3.3.
* Auto-encoding with ``c_string_encoding=ascii`` failed in Py3.3.
...
...
Cython/Compiler/Symtab.py
View file @
68f92630
...
@@ -1768,6 +1768,7 @@ class CClassScope(ClassScope):
...
@@ -1768,6 +1768,7 @@ class CClassScope(ClassScope):
# method_table_cname string
# method_table_cname string
# getset_table_cname string
# getset_table_cname string
# has_pyobject_attrs boolean Any PyObject attributes?
# has_pyobject_attrs boolean Any PyObject attributes?
# has_memoryview_attrs boolean Any memory view attributes?
# has_cyclic_pyobject_attrs boolean Any PyObject attributes that may need GC?
# has_cyclic_pyobject_attrs boolean Any PyObject attributes that may need GC?
# property_entries [Entry]
# property_entries [Entry]
# defined boolean Defined in .pxd file
# defined boolean Defined in .pxd file
...
@@ -1777,6 +1778,7 @@ class CClassScope(ClassScope):
...
@@ -1777,6 +1778,7 @@ class CClassScope(ClassScope):
is_c_class_scope
=
1
is_c_class_scope
=
1
has_pyobject_attrs
=
False
has_pyobject_attrs
=
False
has_memoryview_attrs
=
False
has_cyclic_pyobject_attrs
=
False
has_cyclic_pyobject_attrs
=
False
defined
=
False
defined
=
False
implemented
=
False
implemented
=
False
...
@@ -1850,7 +1852,9 @@ class CClassScope(ClassScope):
...
@@ -1850,7 +1852,9 @@ class CClassScope(ClassScope):
entry
=
self
.
declare
(
name
,
cname
,
type
,
pos
,
visibility
)
entry
=
self
.
declare
(
name
,
cname
,
type
,
pos
,
visibility
)
entry
.
is_variable
=
1
entry
.
is_variable
=
1
self
.
var_entries
.
append
(
entry
)
self
.
var_entries
.
append
(
entry
)
if
type
.
is_pyobject
and
name
!=
'__weakref__'
:
if
type
.
is_memoryviewslice
:
self
.
has_memoryview_attrs
=
True
elif
type
.
is_pyobject
and
name
!=
'__weakref__'
:
self
.
has_pyobject_attrs
=
True
self
.
has_pyobject_attrs
=
True
if
(
not
type
.
is_builtin_type
if
(
not
type
.
is_builtin_type
or
not
type
.
scope
or
type
.
scope
.
needs_gc
()):
or
not
type
.
scope
or
type
.
scope
.
needs_gc
()):
...
...
Cython/Compiler/TypeSlots.py
View file @
68f92630
...
@@ -353,6 +353,7 @@ class ConstructorSlot(InternalMethodSlot):
...
@@ -353,6 +353,7 @@ class ConstructorSlot(InternalMethodSlot):
if
(
self
.
slot_name
!=
'tp_new'
if
(
self
.
slot_name
!=
'tp_new'
and
scope
.
parent_type
.
base_type
and
scope
.
parent_type
.
base_type
and
not
scope
.
has_pyobject_attrs
and
not
scope
.
has_pyobject_attrs
and
not
scope
.
has_memoryview_attrs
and
not
scope
.
lookup_here
(
self
.
method
)):
and
not
scope
.
lookup_here
(
self
.
method
)):
# if the type does not have object attributes, it can
# if the type does not have object attributes, it can
# delegate GC methods to its parent - iff the parent
# delegate GC methods to its parent - iff the parent
...
...
tests/memoryview/memoryview_in_subclasses.pyx
0 → 100644
View file @
68f92630
"""
Test for memory leaks when adding more memory view attributes in subtypes.
"""
import
gc
from
cython.view
cimport
array
def
count_memoryviews
():
gc
.
collect
()
return
sum
([
1
if
'memoryview'
in
str
(
type
(
o
))
else
0
for
o
in
gc
.
get_objects
()])
def
run_test
(
cls
,
num_iters
):
orig_count
=
count_memoryviews
()
def
f
():
x
=
cls
(
1024
)
for
i
in
range
(
num_iters
):
f
()
return
count_memoryviews
()
-
orig_count
cdef
class
BaseType
:
"""
>>> run_test(BaseType, 10)
0
"""
cdef
double
[:]
buffer
def
__cinit__
(
self
,
n
):
self
.
buffer
=
array
((
n
,),
sizeof
(
double
),
'd'
)
cdef
class
Subtype
(
BaseType
):
"""
>>> run_test(Subtype, 10)
0
"""
cdef
double
[:]
buffer2
def
__cinit__
(
self
,
n
):
self
.
buffer2
=
array
((
n
,),
sizeof
(
double
),
'd'
)
cdef
class
SubtypeWithUserDealloc
(
BaseType
):
"""
>>> run_test(SubtypeWithUserDealloc, 10)
0
"""
cdef
double
[:]
buffer2
def
__cinit__
(
self
,
n
):
self
.
buffer2
=
array
((
n
,),
sizeof
(
double
),
'd'
)
def
__dealloc__
(
self
):
pass
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