Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
5e724cf1
Commit
5e724cf1
authored
Feb 13, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a seqiter_cls gc handler, and a test for these
parent
bd0b336a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
src/runtime/iterobject.cpp
src/runtime/iterobject.cpp
+11
-1
test/tests/iter_gc.py
test/tests/iter_gc.py
+35
-0
No files found.
src/runtime/iterobject.cpp
View file @
5e724cf1
...
@@ -58,6 +58,16 @@ Box* seqiterNext(Box* s) {
...
@@ -58,6 +58,16 @@ Box* seqiterNext(Box* s) {
return
r
;
return
r
;
}
}
static
void
seqiterGCVisit
(
GCVisitor
*
v
,
Box
*
b
)
{
assert
(
b
->
cls
==
seqiter_cls
);
boxGCHandler
(
v
,
b
);
BoxedSeqIter
*
si
=
static_cast
<
BoxedSeqIter
*>
(
b
);
v
->
visit
(
si
->
b
);
if
(
si
->
next
)
v
->
visit
(
si
->
next
);
}
static
void
iterwrapperGCVisit
(
GCVisitor
*
v
,
Box
*
b
)
{
static
void
iterwrapperGCVisit
(
GCVisitor
*
v
,
Box
*
b
)
{
assert
(
b
->
cls
==
iterwrapper_cls
);
assert
(
b
->
cls
==
iterwrapper_cls
);
boxGCHandler
(
v
,
b
);
boxGCHandler
(
v
,
b
);
...
@@ -108,7 +118,7 @@ extern "C" PyObject* PySeqIter_New(PyObject* seq) noexcept {
...
@@ -108,7 +118,7 @@ extern "C" PyObject* PySeqIter_New(PyObject* seq) noexcept {
}
}
void
setupIter
()
{
void
setupIter
()
{
seqiter_cls
=
new
BoxedHeapClass
(
object_cls
,
NULL
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"iterator"
);
seqiter_cls
=
new
BoxedHeapClass
(
object_cls
,
seqiterGCVisit
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"iterator"
);
seqiter_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
seqiterNext
,
UNKNOWN
,
1
)));
seqiter_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
seqiterNext
,
UNKNOWN
,
1
)));
seqiter_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
seqiterHasnext
,
BOXED_BOOL
,
1
)));
seqiter_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
seqiterHasnext
,
BOXED_BOOL
,
1
)));
...
...
test/tests/iter_gc.py
0 → 100644
View file @
5e724cf1
# Regression test: make sure we GC special iterator objects correctly
import
gc
class
C
(
object
):
def
f
(
self
,
i
):
return
i
*
i
def
__getitem__
(
self
,
i
):
if
i
<
1000
:
return
self
.
f
(
i
)
raise
IndexError
(
i
)
for
i
in
C
():
gc
.
collect
()
print
i
class
C2
(
object
):
def
__init__
(
self
):
self
.
n
=
0
def
__iter__
(
self
):
return
self
def
f
(
self
):
self
.
n
+=
1
return
self
.
n
*
2
def
next
(
self
):
if
self
.
n
<
1000
:
return
self
.
f
()
raise
StopIteration
()
for
i
in
C2
():
gc
.
collect
()
print
i
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