diff options
author | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2005-07-10 22:50:46 +0000 |
---|---|---|
committer | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2005-07-10 22:50:46 +0000 |
commit | c6b4cfa0ccbdf75f4e16db6516763b23b171f1f2 (patch) | |
tree | e9851aea2d9cc6573b0c53b3d244c7ae778ff1ad | |
parent | 34acc9bceabad67d7751d312bfc848504c40a34e (diff) | |
download | pygobject-c6b4cfa0ccbdf75f4e16db6516763b23b171f1f2.tar.gz pygobject-c6b4cfa0ccbdf75f4e16db6516763b23b171f1f2.tar.xz pygobject-c6b4cfa0ccbdf75f4e16db6516763b23b171f1f2.zip |
make iochannel api use new PyGPollFD type instead of tuples
-rw-r--r-- | gobject/pygiochannel.c | 20 | ||||
-rw-r--r-- | gobject/pygobject-private.h | 7 | ||||
-rw-r--r-- | gobject/pygsource.c | 10 |
3 files changed, 20 insertions, 17 deletions
diff --git a/gobject/pygiochannel.c b/gobject/pygiochannel.c index ba3cfa1..ad56a6f 100644 --- a/gobject/pygiochannel.c +++ b/gobject/pygiochannel.c @@ -518,17 +518,18 @@ py_io_channel_win32_poll(PyObject *self, PyObject *args, PyObject *kwargs) pollfd = g_newa(GPollFD, len); for (i = 0; i < len; ++i) { pyfd = PyList_GET_ITEM(pyfds, i); - if (!PyArg_ParseTuple(pyfd, "iii", &pollfd[i].fd, &pollfd[i].events, - &pollfd[i].revents)) + if (!PyObject_TypeCheck(pyfd, &PyGPollFD_Type)) { + PyErr_SetString(PyExc_TypeError, "'fds' must be a list of gobject.PollFD objects"); return NULL; + } + pollfd[i] = ((PyGPollFD *) pyfd)->pollfd; } result = g_io_channel_win32_poll(pollfd, len, timeout); - pyfds = PyList_New(len); - for (i = 0; i < len; ++i) - PyList_SET_ITEM(pyfds, i, Py_BuildValue("(iii)", pollfd[i].fd, - pollfd[i].events, - pollfd[i].revents)); + for (i = 0; i < len; ++i) { + pyfd = PyList_GET_ITEM(pyfds, i); + ((PyGPollFD *) pyfd)->pollfd = pollfd[i]; + } return PyInt_FromLong(result); } @@ -538,6 +539,7 @@ py_io_channel_win32_make_pollfd(PyObject *self, PyObject *args, PyObject *kwargs static char *kwlist[] = { "condition", NULL }; int condition; GPollFD pollfd; + PyGPollFD *pypollfd; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:gobject.IOChannel.win32_make_pollfd", @@ -546,7 +548,9 @@ py_io_channel_win32_make_pollfd(PyObject *self, PyObject *args, PyObject *kwargs g_io_channel_win32_make_pollfd(((PyGIOChannel *) self)->channel, condition, &pollfd); - return Py_BuildValue("[iii]", pollfd.fd, pollfd.events, pollfd.revents); + pypollfd = PyObject_NEW(PyGPollFD, &PyGPollFD_Type); + pypollfd->pollfd = pollfd; + return (PyObject *) pypollfd; } #endif /* def G_OS_WIN32 */ diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h index 192fde9..cb7e892 100644 --- a/gobject/pygobject-private.h +++ b/gobject/pygobject-private.h @@ -203,5 +203,12 @@ extern PyTypeObject PyGIdle_Type; extern PyTypeObject PyGTimeout_Type; extern PyTypeObject PyGPollFD_Type; +typedef struct +{ + PyObject_HEAD + GPollFD pollfd; + PyObject *fd_obj; +} PyGPollFD; + #endif diff --git a/gobject/pygsource.c b/gobject/pygsource.c index 2e49596..08ca458 100644 --- a/gobject/pygsource.c +++ b/gobject/pygsource.c @@ -54,14 +54,6 @@ typedef struct PyObject *obj; } PyGRealSource; -typedef struct -{ - PyObject_HEAD - GPollFD pollfd; - PyObject *fd_obj; -} PyGPollFD; - - static PyObject * source_repr(PyGSource *self, const char *type) { @@ -780,7 +772,7 @@ static PyMemberDef pyg_poll_fd_members[] = { static void pyg_poll_fd_dealloc(PyGPollFD *self) { - Py_DECREF(self->fd_obj); + Py_XDECREF(self->fd_obj); PyObject_DEL(self); } |