Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit93fcc1f

Browse files
authored
pythonGH-97752: Clear theprevious member of newly-created generator/coroutine frames (pythonGH-97795)
1 parentd053c47 commit93fcc1f

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

‎Lib/test/test_generators.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,25 @@ def __del__(self):
206206
finally:
207207
gc.set_threshold(*thresholds)
208208

209+
deftest_ag_frame_f_back(self):
210+
asyncdeff():
211+
yield
212+
ag=f()
213+
self.assertIsNone(ag.ag_frame.f_back)
214+
215+
deftest_cr_frame_f_back(self):
216+
asyncdeff():
217+
pass
218+
cr=f()
219+
self.assertIsNone(cr.cr_frame.f_back)
220+
cr.close()# Suppress RuntimeWarning.
221+
222+
deftest_gi_frame_f_back(self):
223+
deff():
224+
yield
225+
gi=f()
226+
self.assertIsNone(gi.gi_frame.f_back)
227+
209228

210229

211230
classExceptionTest(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix possible data corruption or crashes when accessing the ``f_back`` member
2+
of newly-created generator or coroutine frames.

‎Python/frame.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest)
5454
assert(src->stacktop >=src->f_code->co_nlocalsplus);
5555
Py_ssize_tsize= ((char*)&src->localsplus[src->stacktop])- (char*)src;
5656
memcpy(dest,src,size);
57+
// Don't leave a dangling pointer to the old frame when creating generators
58+
// and coroutines:
59+
dest->previous=NULL;
5760
}
5861

5962

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp