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
d73ff291
Commit
d73ff291
authored
Aug 08, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extend no_gc_clear test to check closures for their automatic tp_clear() behaviour
parent
b274ea0b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
2 deletions
+46
-2
tests/run/no_gc_clear.pyx
tests/run/no_gc_clear.pyx
+46
-2
No files found.
tests/run/no_gc_clear.pyx
View file @
d73ff291
...
...
@@ -12,10 +12,22 @@ from cpython.ref cimport PyObject, Py_TYPE
# Pull tp_clear for PyTypeObject as I did not find another way to access it
# from Cython code.
cdef
extern
from
"Python.h"
:
cdef
extern
from
*
:
ctypedef
struct
PyTypeObject
:
void
(
*
tp_clear
)(
object
)
ctypedef
struct
__pyx_CyFunctionObject
:
PyObject
*
func_closure
def
is_tp_clear_null
(
obj
):
return
(
<
PyTypeObject
*>
Py_TYPE
(
obj
)).
tp_clear
is
NULL
def
is_closure_tp_clear_null
(
func
):
return
is_tp_clear_null
(
<
object
>
(
<
__pyx_CyFunctionObject
*>
func
).
func_closure
)
@
cython
.
no_gc_clear
cdef
class
DisableTpClear
:
...
...
@@ -24,6 +36,8 @@ cdef class DisableTpClear:
actually clears the references to NULL.
>>> uut = DisableTpClear()
>>> is_tp_clear_null(uut)
True
>>> uut.call_tp_clear()
>>> type(uut.requires_cleanup) == list
True
...
...
@@ -36,7 +50,37 @@ cdef class DisableTpClear:
self
.
requires_cleanup
=
[
"Some object that needs cleaning in __dealloc__"
]
cpdef
public
call_tp_clear
(
self
):
def
call_tp_clear
(
self
):
cdef
PyTypeObject
*
pto
=
Py_TYPE
(
self
)
if
pto
.
tp_clear
!=
NULL
:
pto
.
tp_clear
(
self
)
def
test_closure_without_clear
(
str
x
):
"""
>>> c = test_closure_without_clear('abc')
>>> is_tp_clear_null(c)
False
>>> is_closure_tp_clear_null(c)
True
>>> c('cba')
'abcxyzcba'
"""
def
c
(
str
s
):
return
x
+
'xyz'
+
s
return
c
def
test_closure_with_clear
(
list
x
):
"""
>>> c = test_closure_with_clear(list('abc'))
>>> is_tp_clear_null(c)
False
>>> is_closure_tp_clear_null(c)
False
>>> c('cba')
'abcxyzcba'
"""
def
c
(
str
s
):
return
''
.
join
(
x
)
+
'xyz'
+
s
return
c
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