Skip to content

Commit b6ab2f7

Browse files
committed
Make sure we convert borrowed refs to func/code when copying generator frame
1 parent 85f9a64 commit b6ab2f7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Include/internal/pycore_frame.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ static inline void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *
156156
for (int i = 0; i < stacktop; i++) {
157157
dest->localsplus[i] = _PyStackRef_StealIfUnborrowed(src->localsplus[i]);
158158
}
159+
// XXX - More efficient version of this?
160+
if (_PyStackRef_IsBorrowed(dest->f_executable)) {
161+
Py_INCREF(PyStackRef_AsPyObjectBorrow(dest->f_executable));
162+
}
163+
if (_PyStackRef_IsBorrowed(dest->f_funcobj)) {
164+
Py_INCREF(PyStackRef_AsPyObjectBorrow(dest->f_funcobj));
165+
}
159166
// Don't leave a dangling pointer to the old frame when creating generators
160167
// and coroutines:
161168
dest->previous = NULL;

0 commit comments

Comments
 (0)