Example #1
0
PyObject * 
PyStackless_Call_Main(PyObject *func, PyObject *args, PyObject *kwds)
{
	PyThreadState *ts = PyThreadState_GET();
	PyCFrameObject *c;
	PyObject *retval;

	if (ts->st.main != NULL)
		RUNTIME_ERROR(
		    "Call_Main cannot run within a main tasklet", NULL);
	c = slp_cframe_newfunc(func, args, kwds, 0);
	if (c == NULL)
		return NULL;
	/* frames eat their own reference when returning */
	Py_INCREF((PyObject *)c);
	retval = slp_eval_frame((PyFrameObject *) c);
	Py_DECREF((PyObject *)c);
	return retval;
}
Example #2
0
static PyObject *
climb_stack_and_eval_frame(PyFrameObject *f)
{
	/* 
	 * a similar case to climb_stack_and_transfer,
	 * but here we need to incorporate a gap in the
	 * stack into main and keep this gap on the stack.
	 * This way, initial_stub is always valid to be
	 * used to return to the main c stack.
	 */
	PyThreadState *ts = PyThreadState_GET();
    intptr_t probe;
    ptrdiff_t needed = &probe - ts->st.cstack_base;
	/* in rare cases, the need might have vanished due to the recursion */
    intptr_t *goobledigoobs;
	if (needed > 0) {
        goobledigoobs = alloca(needed * sizeof(intptr_t));
		if (goobledigoobs == NULL)
			return NULL;
	}
	return slp_eval_frame(f);
}