Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8fd544ff
Kaydet (Commit)
8fd544ff
authored
Agu 20, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #12791: Break reference cycles early when a generator exits with an exception.
üst
18bb3302
a370fcf3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
+76
-0
test_exceptions.py
Lib/test/test_exceptions.py
+62
-0
NEWS
Misc/NEWS
+3
-0
genobject.c
Objects/genobject.c
+11
-0
No files found.
Lib/test/test_exceptions.py
Dosyayı görüntüle @
8fd544ff
...
...
@@ -608,6 +608,68 @@ class ExceptionTests(unittest.TestCase):
gc_collect
()
self
.
assertEqual
(
sys
.
exc_info
(),
(
None
,
None
,
None
))
def
_check_generator_cleanup_exc_state
(
self
,
testfunc
):
# Issue #12791: exception state is cleaned up as soon as a generator
# is closed (reference cycles are broken).
class
MyException
(
Exception
):
def
__init__
(
self
,
obj
):
self
.
obj
=
obj
class
MyObj
:
pass
def
raising_gen
():
try
:
raise
MyException
(
obj
)
except
MyException
:
yield
obj
=
MyObj
()
wr
=
weakref
.
ref
(
obj
)
g
=
raising_gen
()
next
(
g
)
testfunc
(
g
)
g
=
obj
=
None
obj
=
wr
()
self
.
assertIs
(
obj
,
None
)
def
test_generator_throw_cleanup_exc_state
(
self
):
def
do_throw
(
g
):
try
:
g
.
throw
(
RuntimeError
())
except
RuntimeError
:
pass
self
.
_check_generator_cleanup_exc_state
(
do_throw
)
def
test_generator_close_cleanup_exc_state
(
self
):
def
do_close
(
g
):
g
.
close
()
self
.
_check_generator_cleanup_exc_state
(
do_close
)
def
test_generator_del_cleanup_exc_state
(
self
):
def
do_del
(
g
):
g
=
None
self
.
_check_generator_cleanup_exc_state
(
do_del
)
def
test_generator_next_cleanup_exc_state
(
self
):
def
do_next
(
g
):
try
:
next
(
g
)
except
StopIteration
:
pass
else
:
self
.
fail
(
"should have raised StopIteration"
)
self
.
_check_generator_cleanup_exc_state
(
do_next
)
def
test_generator_send_cleanup_exc_state
(
self
):
def
do_send
(
g
):
try
:
g
.
send
(
None
)
except
StopIteration
:
pass
else
:
self
.
fail
(
"should have raised StopIteration"
)
self
.
_check_generator_cleanup_exc_state
(
do_send
)
def
test_3114
(
self
):
# Bug #3114: in its destructor, MyObject retrieves a pointer to
# obsolete and/or deallocated objects.
...
...
Misc/NEWS
Dosyayı görüntüle @
8fd544ff
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
- Issue #12791: Break reference cycles early when a generator exits with
an exception.
- Issue #12773: Make __doc__ mutable on user-defined classes.
- Issue #12766: Raise an ValueError when creating a class with a class variable
...
...
Objects/genobject.c
Dosyayı görüntüle @
8fd544ff
...
...
@@ -100,6 +100,17 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc)
if
(
!
result
||
f
->
f_stacktop
==
NULL
)
{
/* generator can't be rerun, so release the frame */
/* first clean reference cycle through stored exception traceback */
PyObject
*
t
,
*
v
,
*
tb
;
t
=
f
->
f_exc_type
;
v
=
f
->
f_exc_value
;
tb
=
f
->
f_exc_traceback
;
f
->
f_exc_type
=
NULL
;
f
->
f_exc_value
=
NULL
;
f
->
f_exc_traceback
=
NULL
;
Py_XDECREF
(
t
);
Py_XDECREF
(
v
);
Py_XDECREF
(
tb
);
Py_DECREF
(
f
);
gen
->
gi_frame
=
NULL
;
}
...
...
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