Skip to content

Commit cfd51a5

Browse files
author
Anselm Kruis
committed
Stackless issue python#133: fix Python/ceval.c
Always track frames. Otherwise Stackless leaks frames.
1 parent da8a841 commit cfd51a5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Python/ceval.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4615,6 +4615,12 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
46154615
* when the generator is resumed. */
46164616
Py_CLEAR(f->f_back);
46174617

4618+
#ifdef STACKLESS
4619+
/* Stackless calls need GC. */
4620+
assert(!_PyObject_GC_IS_TRACKED(f));
4621+
_PyObject_GC_TRACK(f);
4622+
#endif
4623+
46184624
/* Create a new generator that owns the ready to run frame
46194625
* and return that as the value. */
46204626
if (is_coro) {
@@ -4642,6 +4648,8 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
46424648
if (stackless) {
46434649
Py_INCREF(Py_None);
46444650
retval = Py_None;
4651+
assert(!_PyObject_GC_IS_TRACKED(f));
4652+
_PyObject_GC_TRACK(f);
46454653
SLP_STORE_NEXT_FRAME(tstate, f);
46464654
Py_DECREF(f);
46474655
return STACKLESS_PACK(tstate, retval);
@@ -4659,8 +4667,6 @@ _PyEval_EvalCodeWithName(PyObject *_co, PyObject *globals, PyObject *locals,
46594667
else {
46604668
retval = slp_eval_frame(f);
46614669
}
4662-
Py_DECREF(f);
4663-
return retval;
46644670
}
46654671
#else
46664672
retval = PyEval_EvalFrameEx(f,0);
@@ -5455,6 +5461,8 @@ _PyFunction_FastCall(PyCodeObject *co, PyObject **args, Py_ssize_t nargs,
54555461
if (stackless) {
54565462
Py_INCREF(Py_None);
54575463
result = Py_None;
5464+
assert(!_PyObject_GC_IS_TRACKED(f));
5465+
_PyObject_GC_TRACK(f);
54585466
SLP_STORE_NEXT_FRAME(tstate, f);
54595467
Py_DECREF(f);
54605468
return STACKLESS_PACK(tstate, result);

0 commit comments

Comments
 (0)