mirror of
https://github.com/python/cpython.git
synced 2025-07-31 23:23:11 +00:00
frame_clear(): Explain why it's important to make the frame
look dead right at the start. Use Py_CLEAR for four more frame members.
This commit is contained in:
parent
de2acf6512
commit
adcd25e7fa
1 changed files with 11 additions and 18 deletions
|
@ -454,36 +454,29 @@ frame_clear(PyFrameObject *f)
|
||||||
PyObject **fastlocals, **p, **oldtop;
|
PyObject **fastlocals, **p, **oldtop;
|
||||||
int i, slots;
|
int i, slots;
|
||||||
|
|
||||||
oldtop = f->f_stacktop;
|
|
||||||
|
|
||||||
/* Before anything else, make sure that this frame is clearly marked
|
/* Before anything else, make sure that this frame is clearly marked
|
||||||
as being defunct! */
|
* as being defunct! Else, e.g., a generator reachable from this
|
||||||
|
* frame may also point to this frame, believe itself to still be
|
||||||
|
* active, and try cleaning up this frame again.
|
||||||
|
*/
|
||||||
|
oldtop = f->f_stacktop;
|
||||||
f->f_stacktop = NULL;
|
f->f_stacktop = NULL;
|
||||||
|
|
||||||
Py_XDECREF(f->f_exc_type);
|
Py_CLEAR(f->f_exc_type);
|
||||||
f->f_exc_type = NULL;
|
Py_CLEAR(f->f_exc_value);
|
||||||
|
Py_CLEAR(f->f_exc_traceback);
|
||||||
Py_XDECREF(f->f_exc_value);
|
Py_CLEAR(f->f_trace);
|
||||||
f->f_exc_value = NULL;
|
|
||||||
|
|
||||||
Py_XDECREF(f->f_exc_traceback);
|
|
||||||
f->f_exc_traceback = NULL;
|
|
||||||
|
|
||||||
Py_XDECREF(f->f_trace);
|
|
||||||
f->f_trace = NULL;
|
|
||||||
|
|
||||||
/* locals */
|
/* locals */
|
||||||
slots = f->f_nlocals + f->f_ncells + f->f_nfreevars;
|
slots = f->f_nlocals + f->f_ncells + f->f_nfreevars;
|
||||||
fastlocals = f->f_localsplus;
|
fastlocals = f->f_localsplus;
|
||||||
for (i = slots; --i >= 0; ++fastlocals) {
|
for (i = slots; --i >= 0; ++fastlocals)
|
||||||
Py_CLEAR(*fastlocals);
|
Py_CLEAR(*fastlocals);
|
||||||
}
|
|
||||||
|
|
||||||
/* stack */
|
/* stack */
|
||||||
if (oldtop != NULL) {
|
if (oldtop != NULL) {
|
||||||
for (p = f->f_valuestack; p < oldtop; p++) {
|
for (p = f->f_valuestack; p < oldtop; p++)
|
||||||
Py_CLEAR(*p);
|
Py_CLEAR(*p);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue