Skip to content

Commit efbee92

Browse files
author
Anselm Kruis
committed
merge 3.3-slp (Stackless python#117, code cleanup)
2 parents 77f6fd3 + 0d3af5e commit efbee92

File tree

3 files changed

+34
-45
lines changed

3 files changed

+34
-45
lines changed

Stackless/core/stackless_impl.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ PyObject * slp_frame_dispatch(PyFrameObject *f,
9191
PyFrameObject *stopframe, int exc,
9292
PyObject *retval);
9393

94-
/* the frame dispatcher for toplevel tasklets */
95-
PyObject * slp_frame_dispatch_top(PyObject *retval);
96-
9794
/* the now exported eval_frame */
9895
PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx_slp(struct _frame *, int, PyObject *);
9996

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

378375
/* tasklet/scheduling operations */
379376
PyObject * slp_tasklet_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
377+
PyObject * slp_tasklet_end(PyObject *retval);
380378

381379
int slp_schedule_task(PyObject **result,
382380
PyTaskletObject *prev,
@@ -438,10 +436,6 @@ PyObject * slp_nomemory_bomb(void);
438436
PyObject * slp_bomb_explode(PyObject *bomb);
439437
int slp_init_bombtype(void);
440438

441-
/* tasklet startup */
442-
443-
PyObject * slp_run_tasklet(PyFrameObject *f);
444-
445439
/* handy abbrevations */
446440

447441
PyObject * slp_type_error(const char *msg);

Stackless/core/stacklesseval.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,42 @@ climb_stack_and_eval_frame(PyFrameObject *f)
279279
/* in rare cases, the need might have vanished due to the recursion */
280280
intptr_t *goobledigoobs;
281281
if (needed > 0) {
282-
goobledigoobs = alloca(needed * sizeof(intptr_t));
282+
goobledigoobs = alloca(needed * sizeof(intptr_t));
283283
if (goobledigoobs == NULL)
284284
return NULL;
285285
}
286286
return slp_eval_frame(f);
287287
}
288288

289+
static PyObject * slp_frame_dispatch_top(PyObject *retval);
290+
291+
static PyObject *
292+
slp_run_tasklet(PyFrameObject *f)
293+
{
294+
PyThreadState *ts = PyThreadState_GET();
295+
PyObject *retval;
296+
297+
if ( (ts->st.main == NULL) && slp_initialize_main_and_current()) {
298+
ts->frame = NULL;
299+
return NULL;
300+
}
301+
ts->frame = f;
302+
303+
TASKLET_CLAIMVAL(ts->st.current, &retval);
304+
305+
if (PyBomb_Check(retval))
306+
retval = slp_bomb_explode(retval);
307+
while (ts->st.main != NULL) {
308+
/* XXX correct condition? or current? */
309+
retval = slp_frame_dispatch_top(retval);
310+
retval = slp_tasklet_end(retval);
311+
if (STACKLESS_UNWINDING(retval))
312+
STACKLESS_UNPACK(ts, retval);
313+
/* if we softswitched out from the tasklet end */
314+
Py_CLEAR(ts->st.del_post_switch);
315+
}
316+
return retval;
317+
}
289318

290319
PyObject *
291320
slp_eval_frame(PyFrameObject *f)
@@ -1091,7 +1120,7 @@ slp_frame_dispatch(PyFrameObject *f, PyFrameObject *stopframe, int exc, PyObject
10911120
return retval;
10921121
}
10931122

1094-
PyObject *
1123+
static PyObject *
10951124
slp_frame_dispatch_top(PyObject *retval)
10961125
{
10971126
PyThreadState *ts = PyThreadState_GET();

Stackless/module/scheduling.c

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,8 +1351,8 @@ extern int PyStackless_CallErrorHandler(void);
13511351
* the exception to be continued in the new
13521352
* context.
13531353
*/
1354-
static PyObject *
1355-
tasklet_end(PyObject *retval)
1354+
PyObject *
1355+
slp_tasklet_end(PyObject *retval)
13561356
{
13571357
PyThreadState *ts = PyThreadState_GET();
13581358
PyTaskletObject *task = ts->st.current;
@@ -1506,40 +1506,6 @@ tasklet_end(PyObject *retval)
15061506
return retval;
15071507
}
15081508

1509-
/*
1510-
the following functions only have to handle "real"
1511-
tasklets, those which need to switch the C stack.
1512-
The "soft" tasklets are handled by frame pushing.
1513-
It is not so much simpler than I thought :-(
1514-
*/
1515-
1516-
PyObject *
1517-
slp_run_tasklet(PyFrameObject *f)
1518-
{
1519-
PyThreadState *ts = PyThreadState_GET();
1520-
PyObject *retval;
1521-
1522-
if ( (ts->st.main == NULL) && slp_initialize_main_and_current()) {
1523-
ts->frame = NULL;
1524-
return NULL;
1525-
}
1526-
ts->frame = f;
1527-
1528-
TASKLET_CLAIMVAL(ts->st.current, &retval);
1529-
1530-
if (PyBomb_Check(retval))
1531-
retval = slp_bomb_explode(retval);
1532-
while (ts->st.main != NULL) {
1533-
/* XXX correct condition? or current? */
1534-
retval = slp_frame_dispatch_top(retval);
1535-
retval = tasklet_end(retval);
1536-
if (STACKLESS_UNWINDING(retval))
1537-
STACKLESS_UNPACK(ts, retval);
1538-
/* if we softswitched out from the tasklet end */
1539-
Py_CLEAR(ts->st.del_post_switch);
1540-
}
1541-
return retval;
1542-
}
15431509

15441510
/* Clear out the free list */
15451511

0 commit comments

Comments
 (0)