Skip to content

Commit

Permalink
merge 3.4-slp (Stackless python#117, code cleanup)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anselm Kruis committed Mar 17, 2017
2 parents f82f0d3 + efbee92 commit 32d50a2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 45 deletions.
8 changes: 1 addition & 7 deletions Stackless/core/stackless_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ PyObject * slp_frame_dispatch(PyFrameObject *f,
PyFrameObject *stopframe, int exc,
PyObject *retval);

/* the frame dispatcher for toplevel tasklets */
PyObject * slp_frame_dispatch_top(PyObject *retval);

/* the now exported eval_frame */
PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx_slp(struct _frame *, int, PyObject *);

Expand Down Expand Up @@ -377,6 +374,7 @@ int slp_ensure_linkage(PyTaskletObject *task);

/* tasklet/scheduling operations */
PyObject * slp_tasklet_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
PyObject * slp_tasklet_end(PyObject *retval);

int slp_schedule_task(PyObject **result,
PyTaskletObject *prev,
Expand Down Expand Up @@ -438,10 +436,6 @@ PyObject * slp_nomemory_bomb(void);
PyObject * slp_bomb_explode(PyObject *bomb);
int slp_init_bombtype(void);

/* tasklet startup */

PyObject * slp_run_tasklet(PyFrameObject *f);

/* handy abbrevations */

PyObject * slp_type_error(const char *msg);
Expand Down
33 changes: 31 additions & 2 deletions Stackless/core/stacklesseval.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,42 @@ climb_stack_and_eval_frame(PyFrameObject *f)
/* in rare cases, the need might have vanished due to the recursion */
intptr_t *goobledigoobs;
if (needed > 0) {
goobledigoobs = alloca(needed * sizeof(intptr_t));
goobledigoobs = alloca(needed * sizeof(intptr_t));
if (goobledigoobs == NULL)
return NULL;
}
return slp_eval_frame(f);
}

static PyObject * slp_frame_dispatch_top(PyObject *retval);

static PyObject *
slp_run_tasklet(PyFrameObject *f)
{
PyThreadState *ts = PyThreadState_GET();
PyObject *retval;

if ( (ts->st.main == NULL) && slp_initialize_main_and_current()) {
ts->frame = NULL;
return NULL;
}
ts->frame = f;

TASKLET_CLAIMVAL(ts->st.current, &retval);

if (PyBomb_Check(retval))
retval = slp_bomb_explode(retval);
while (ts->st.main != NULL) {
/* XXX correct condition? or current? */
retval = slp_frame_dispatch_top(retval);
retval = slp_tasklet_end(retval);
if (STACKLESS_UNWINDING(retval))
STACKLESS_UNPACK(ts, retval);
/* if we softswitched out from the tasklet end */
Py_CLEAR(ts->st.del_post_switch);
}
return retval;
}

PyObject *
slp_eval_frame(PyFrameObject *f)
Expand Down Expand Up @@ -1116,7 +1145,7 @@ slp_frame_dispatch(PyFrameObject *f, PyFrameObject *stopframe, int exc, PyObject
return retval;
}

PyObject *
static PyObject *
slp_frame_dispatch_top(PyObject *retval)
{
PyThreadState *ts = PyThreadState_GET();
Expand Down
38 changes: 2 additions & 36 deletions Stackless/module/scheduling.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,8 @@ extern int PyStackless_CallErrorHandler(void);
* the exception to be continued in the new
* context.
*/
static PyObject *
tasklet_end(PyObject *retval)
PyObject *
slp_tasklet_end(PyObject *retval)
{
PyThreadState *ts = PyThreadState_GET();
PyTaskletObject *task = ts->st.current;
Expand Down Expand Up @@ -1506,40 +1506,6 @@ tasklet_end(PyObject *retval)
return retval;
}

/*
the following functions only have to handle "real"
tasklets, those which need to switch the C stack.
The "soft" tasklets are handled by frame pushing.
It is not so much simpler than I thought :-(
*/

PyObject *
slp_run_tasklet(PyFrameObject *f)
{
PyThreadState *ts = PyThreadState_GET();
PyObject *retval;

if ( (ts->st.main == NULL) && slp_initialize_main_and_current()) {
ts->frame = NULL;
return NULL;
}
ts->frame = f;

TASKLET_CLAIMVAL(ts->st.current, &retval);

if (PyBomb_Check(retval))
retval = slp_bomb_explode(retval);
while (ts->st.main != NULL) {
/* XXX correct condition? or current? */
retval = slp_frame_dispatch_top(retval);
retval = tasklet_end(retval);
if (STACKLESS_UNWINDING(retval))
STACKLESS_UNPACK(ts, retval);
/* if we softswitched out from the tasklet end */
Py_CLEAR(ts->st.del_post_switch);
}
return retval;
}

/* Clear out the free list */

Expand Down

0 comments on commit 32d50a2

Please sign in to comment.