Example #1
0
static PyObject *
channel_send_exception(PyObject *myself, PyObject *args)
{
	STACKLESS_GETARG();
	PyObject *retval = NULL;
	PyObject *klass = PySequence_GetItem(args, 0);

	if (klass == NULL)
		VALUE_ERROR("channel.send_exception(e, v...)", NULL);
	args = PySequence_GetSlice(args, 1, PySequence_Size(args));
	if (!args) {
		goto err_exit;
	}
	STACKLESS_PROMOTE_ALL();
	retval = impl_channel_send_exception((PyChannelObject*)myself,
						klass, args);
	STACKLESS_ASSERT();
	if (retval == NULL || STACKLESS_UNWINDING(retval)) {
		goto err_exit;
	}
	Py_INCREF(Py_None);
	retval = Py_None;
err_exit:
	Py_DECREF(klass);
	Py_XDECREF(args);
	return retval;
}
Example #2
0
static TASKLET_KILL_HEAD(impl_tasklet_kill)
{
    STACKLESS_GETARG();
    PyObject *noargs;
    PyObject *ret;

    /*
     * silently do nothing if the tasklet is dead.
     * simple raising would kill ourself in this case.
     */
    if (slp_get_frame(task) == NULL)
        Py_RETURN_NONE;

    /* we might be called after exceptions are gone */
    if (PyExc_TaskletExit == NULL) {
        PyExc_TaskletExit = PyString_FromString("zombie");
        if (PyExc_TaskletExit == NULL)
            return NULL; /* give up */
    }
    noargs = PyTuple_New(0);
    STACKLESS_PROMOTE_ALL();
    ret = impl_tasklet_raise_exception(task, PyExc_TaskletExit,
                                       noargs);
    STACKLESS_ASSERT();
    Py_DECREF(noargs);
    return ret;
}
Example #3
0
static PyObject *
channel_iternext(PyChannelObject *self)
{
	STACKLESS_GETARG();

	if (self->flags.closing && self->balance == 0) {
		/* signal the end of the iteration */
		return NULL;
	}
	STACKLESS_PROMOTE_ALL();
	return impl_channel_receive(self);
}
Example #4
0
static PyObject *
schedule_generic(PyObject *self, PyObject *args, PyObject *kwds, int remove)
{
	STACKLESS_GETARG();
	PyObject *retval = (PyObject *) PyThreadState_GET()->st.current;
	static char *argnames[] = {"retval", NULL};

	if (PyTuple_GET_SIZE(args) > 0) {
		if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:schedule",
						 argnames, &retval))
			return NULL;
	}
	STACKLESS_PROMOTE_ALL();
	return PyStackless_Schedule(retval, remove);
}
Example #5
0
static PyObject *
run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals,
	 PyCompilerFlags *flags, PyArena *arena)
{
	STACKLESS_GETARG();
	PyCodeObject *co;
	PyObject *v;
	co = PyAST_Compile(mod, filename, flags, arena);
	if (co == NULL)
		return NULL;
	STACKLESS_PROMOTE_ALL();
	v = PyEval_EvalCode(co, globals, locals);
	STACKLESS_ASSERT();
	Py_DECREF(co);
	return v;
}
Example #6
0
static PyObject *
classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
		      PyObject *kwds)
{
	STACKLESS_GETARG();
	PyObject *func, *result;

	func = PyCFunction_New(descr->d_method, (PyObject *)descr->d_type);
	if (func == NULL)
		return NULL;

	STACKLESS_PROMOTE_ALL();
	result = PyEval_CallObjectWithKeywords(func, args, kwds);
	STACKLESS_ASSERT();
	Py_DECREF(func);
	return result;
}
Example #7
0
static PyObject *
wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
{
	STACKLESS_GETARG();
	Py_ssize_t argc;
	PyObject *self, *func, *result;

	/* Make sure that the first argument is acceptable as 'self' */
	assert(PyTuple_Check(args));
	argc = PyTuple_GET_SIZE(args);
	if (argc < 1) {
		PyErr_Format(PyExc_TypeError,
			     "descriptor '%.300s' of '%.100s' "
			     "object needs an argument",
			     descr_name((PyDescrObject *)descr),
			     descr->d_type->tp_name);
		return NULL;
	}
	self = PyTuple_GET_ITEM(args, 0);
	if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) {
		PyErr_Format(PyExc_TypeError,
			     "descriptor '%.200s' "
			     "requires a '%.100s' object "
			     "but received a '%.100s'",
			     descr_name((PyDescrObject *)descr),
			     descr->d_type->tp_name,
			     self->ob_type->tp_name);
		return NULL;
	}

	func = PyWrapper_New((PyObject *)descr, self);
	if (func == NULL)
		return NULL;
	args = PyTuple_GetSlice(args, 1, argc);
	if (args == NULL) {
		Py_DECREF(func);
		return NULL;
	}
	STACKLESS_PROMOTE_ALL();
	result = PyEval_CallObjectWithKeywords(func, args, kwds);
	STACKLESS_ASSERT();
	Py_DECREF(args);
	Py_DECREF(func);
	return result;
}
Example #8
0
PyObject *
PyRun_StringFlags(const char *str, int start, PyObject *globals,
		  PyObject *locals, PyCompilerFlags *flags)
{
	STACKLESS_GETARG();
	PyObject *ret = NULL;
	mod_ty mod;
	PyArena *arena = PyArena_New();
	if (arena == NULL)
		return NULL;
	
	mod = PyParser_ASTFromString(str, "<string>", start, flags, arena);
	if (mod != NULL) {
		STACKLESS_PROMOTE_ALL();
		ret = run_mod(mod, "<string>", globals, locals, flags, arena);
	}
	PyArena_Free(arena);
	return ret;
}
Example #9
0
static PyObject *
tasklet_raise_exception(PyObject *myself, PyObject *args)
{
    STACKLESS_GETARG();
    PyObject *result = NULL;
    PyObject *klass = PySequence_GetItem(args, 0);

    if (klass == NULL)
        VALUE_ERROR("tasklet.raise_exception(e, v...)", NULL);
    args = PySequence_GetSlice(args, 1, PySequence_Size(args));
    if (!args) goto err_exit;
    STACKLESS_PROMOTE_ALL();
    result = impl_tasklet_raise_exception(
        (PyTaskletObject*)myself, klass, args);
    STACKLESS_ASSERT();
err_exit:
    Py_DECREF(klass);
    Py_XDECREF(args);
    return result;
}
static PyObject *
channel_send_throw(PyObject *myself, PyObject *args)
{
    STACKLESS_GETARG();

    PyObject *typ;
    PyObject *tb = Py_None;
    PyObject *val = Py_None;
    PyObject *retval;
    if (!PyArg_UnpackTuple(args, "send_throw", 1, 3, &typ, &val, &tb))
        return NULL;

    STACKLESS_PROMOTE_ALL();
    retval = impl_channel_send_throw((PyChannelObject*)myself,
        typ, val, tb);
    STACKLESS_ASSERT();
    if (retval == NULL || STACKLESS_UNWINDING(retval)) {
        goto err_exit;
    }
    Py_INCREF(Py_None);
    retval = Py_None;
err_exit:
    return retval;
}
Example #11
0
PyObject *
PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
		  PyObject *locals, int closeit, PyCompilerFlags *flags)
{
	STACKLESS_GETARG();
	PyObject *ret;
	mod_ty mod;
	PyArena *arena = PyArena_New();
	if (arena == NULL)
		return NULL;
	
	mod = PyParser_ASTFromFile(fp, filename, start, 0, 0,
				   flags, NULL, arena);
	if (closeit)
		fclose(fp);
	if (mod == NULL) {
		PyArena_Free(arena);
		return NULL;
	}
	STACKLESS_PROMOTE_ALL();
	ret = run_mod(mod, filename, globals, locals, flags, arena);
	PyArena_Free(arena);
	return ret;
}