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
f118d43a
Commit
f118d43a
authored
Sep 25, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch exceptions from weakref callbacks
parent
ee7c4f47
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
src/gc/collector.cpp
src/gc/collector.cpp
+6
-1
test/tests/finalizer_exception.py
test/tests/finalizer_exception.py
+25
-1
No files found.
src/gc/collector.cpp
View file @
f118d43a
...
@@ -660,7 +660,12 @@ static void graphTraversalMarking(Worklist& worklist, GCVisitor& visitor) {
...
@@ -660,7 +660,12 @@ static void graphTraversalMarking(Worklist& worklist, GCVisitor& visitor) {
static
void
callWeakrefCallback
(
PyWeakReference
*
head
)
{
static
void
callWeakrefCallback
(
PyWeakReference
*
head
)
{
if
(
head
->
wr_callback
)
{
if
(
head
->
wr_callback
)
{
runtimeCall
(
head
->
wr_callback
,
ArgPassSpec
(
1
),
reinterpret_cast
<
Box
*>
(
head
),
NULL
,
NULL
,
NULL
,
NULL
);
try
{
runtimeCall
(
head
->
wr_callback
,
ArgPassSpec
(
1
),
reinterpret_cast
<
Box
*>
(
head
),
NULL
,
NULL
,
NULL
,
NULL
);
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
PyErr_WriteUnraisable
(
head
->
wr_callback
);
}
head
->
wr_callback
=
NULL
;
head
->
wr_callback
=
NULL
;
}
}
}
}
...
...
test/tests/finalizer_exception.py
View file @
f118d43a
# Exceptions from finalizers should get caught:
import
sys
import
sys
from
testing_helpers
import
test_gc
from
testing_helpers
import
test_gc
...
@@ -24,4 +25,27 @@ test_gc(test, 10)
...
@@ -24,4 +25,27 @@ test_gc(test, 10)
print
sorted
(
strs
)
print
sorted
(
strs
)
print
"done"
# Similarly for exceptions from weakref callbacks:
import
weakref
called_callback
=
False
def
callback
(
ref
):
global
called_callback
if
not
called_callback
:
print
"callback"
called_callback
=
True
raise
ValueError
()
class
C
(
object
):
pass
import
gc
l
=
[]
# Make a bunch of them just to make sure at least one gets collected:
for
i
in
xrange
(
100
):
l
.
append
(
weakref
.
ref
(
C
(),
callback
))
gc
.
collect
()
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