コード例 #1
0
ファイル: channelobject.c プロジェクト: d11/rts
static PyObject *
_channel_send_sequence(PyChannelObject *self, PyObject *v)
{
	PyChannel_HeapType *t = (PyChannel_HeapType *) Py_TYPE(self);
	PyObject *it;
	int i;
	PyObject *ret;

	it = PyObject_GetIter(v);
	if (it == NULL)
		return NULL;

	/* Run iterator to exhaustion. */
	for (i = 0; ; i++) {
		PyObject *item = PyIter_Next(it);
		if (item == NULL) {
			if (PyErr_Occurred())
				goto error;
			break;
		}
		ret = t->send(self, item);
		Py_DECREF(item);
		if (ret == NULL)
			goto error;
		Py_DECREF(ret);
	}

	Py_DECREF(it);
	return PyLong_FromLong(i);

  error:
	Py_DECREF(it);
	return NULL;

}
コード例 #2
0
ファイル: channelobject.c プロジェクト: d11/rts
int
PyChannel_Send(PyChannelObject *self, PyObject *arg)
{
	PyChannel_HeapType *t = (PyChannel_HeapType *) Py_TYPE(self);

	return slp_return_wrapper(t->send(self, arg));
}
コード例 #3
0
int
PyChannel_Send(PyChannelObject *self, PyObject *arg)
{
	PyChannel_HeapType *t = (PyChannel_HeapType *) self->ob_type;

	return slp_return_wrapper(t->send(self, arg));
}
コード例 #4
0
ファイル: channelobject.c プロジェクト: d11/rts
int
PyChannel_Send_nr(PyChannelObject *self, PyObject *arg)
{
	PyChannel_HeapType *t = (PyChannel_HeapType *) Py_TYPE(self);

	slp_try_stackless = slp_enable_softswitch;
	return slp_return_wrapper(t->send(self, arg));
}
コード例 #5
0
ファイル: channelobject.c プロジェクト: d11/rts
PyObject *
channel_seq_callback(PyFrameObject *_f, int exc, PyObject *retval)
{
	PyThreadState *ts;
	PyCFrameObject *f = (PyCFrameObject *) _f;
	PyChannelObject *ch;
	PyChannel_HeapType *t;
	PyObject *item;
	int stage = f->n;

	/* prolog to re-enter the loop */
	if (stage == 1) {
		item = retval;
		goto back_with_data;
	}
	if (retval == NULL)
		goto exit_frame;

	Py_DECREF(retval);
	retval = NULL;

	if (stage == 2) {
		goto back_from_send;
	}

	/* Run iterator to exhaustion. */
	for (; ; f->i++) {
		/* get the data */
		STACKLESS_PROPOSE_ALL();
		item = PyIter_Next(f->ob1);

		if (STACKLESS_UNWINDING(item)) {
			stage = f->n = 1;
			return item;
		}

back_with_data:
		if (item == NULL) {
			if (PyErr_Occurred()) {
				if (PyErr_ExceptionMatches(
					PyExc_StopIteration))
					PyErr_Clear();
				else
					goto exit_frame;
			}
			break;
		}

		/* send the data */
		ch = (PyChannelObject *) f->ob2;
		t = (PyChannel_HeapType *) Py_TYPE(ch);
		STACKLESS_PROPOSE_ALL();
		retval = t->send(ch, item);
		Py_DECREF(item);
		if (retval == NULL)
			goto exit_frame;
		if (STACKLESS_UNWINDING(retval)) {
			stage = f->n = 2;
			return retval;
		}
		Py_DECREF(retval);
back_from_send:
		;
	}

	retval = PyLong_FromLong(f->i);
exit_frame:

	/* epilog to return from the frame */
	ts = PyThreadState_GET();
	ts->frame = f->f_back;
	Py_DECREF(f);
	return retval;
}