summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-07-21 17:27:22 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-07-21 17:27:22 +0000
commitbf49647a03923975eb24ce634dae8254553db8de (patch)
treefac72b5b605789d7fa566332bd6a986b148a1ca5
parent39cf2d9ca4fc9b50984ec172282d33b1843fceee (diff)
downloadpygobject-bf49647a03923975eb24ce634dae8254553db8de.tar.gz
pygobject-bf49647a03923975eb24ce634dae8254553db8de.tar.xz
pygobject-bf49647a03923975eb24ce634dae8254553db8de.zip
Move over Source, IOChannel, Idle, Timeout and PollFD to glib from
2008-07-21 Johan Dahlin <johan@gnome.org> * glib/Makefile.am: * glib/glibmodule.c (pyg_idle_add), (pyg_timeout_add), (pyg_timeout_add_seconds), (pyg_io_add_watch), (pyglib_register_api), (pyglib_register_error), (pyglib_register_version_tuples), (init_glib): * glib/pygiochannel.c (py_io_channel_next), (py_io_channel_shutdown), (py_io_channel_set_encoding), (py_io_channel_read_chars), (py_io_channel_write_chars), (py_io_channel_write_lines), (py_io_channel_flush), (py_io_channel_set_flags), (py_io_channel_read_line), (py_io_channel_read_lines), (py_io_channel_seek), (py_io_channel_init), (pyglib_iochannel_register_types): * glib/pygiochannel.h: * glib/pyglib-private.h: * glib/pyglib.c (pyglib_threads_enabled), (pyglib_gil_state_ensure), (pyglib_gil_state_release), (pyglib_enable_threads), (pyglib_block_threads), (pyglib_unblock_threads), (pyglib_set_thread_block_funcs), (pyglib_handler_marshal), (pyglib_destroy_notify): * glib/pyglib.h: * glib/pygsource.c (pyg_source_set_callback), (pyglib_source_register_types): * glib/pygsource.h: * glib/pygspawn.c (pyglib_spawn_register_types): * glib/pygspawn.h: * gobject/Makefile.am: * gobject/__init__.py: * gobject/gobjectmodule.c (pyg_set_thread_block_funcs), (init_gobject): * gobject/pygiochannel.c: * gobject/pygobject-private.h: * gobject/pygsource.c: Move over Source, IOChannel, Idle, Timeout and PollFD to glib from gobject. Clean up and add a bit of new api for glib. svn path=/trunk/; revision=846
-rw-r--r--ChangeLog38
-rw-r--r--glib/Makefile.am12
-rw-r--r--glib/glibmodule.c79
-rw-r--r--glib/pygiochannel.c (renamed from gobject/pygiochannel.c)52
-rw-r--r--glib/pygiochannel.h29
-rw-r--r--glib/pyglib-private.h6
-rw-r--r--glib/pyglib.c96
-rw-r--r--glib/pyglib.h6
-rw-r--r--glib/pygsource.c (renamed from gobject/pygsource.c)25
-rw-r--r--glib/pygsource.h39
-rw-r--r--glib/pygspawn.c2
-rw-r--r--glib/pygspawn.h2
-rw-r--r--gobject/Makefile.am2
-rw-r--r--gobject/__init__.py4
-rw-r--r--gobject/gobjectmodule.c10
-rw-r--r--gobject/pygobject-private.h29
16 files changed, 301 insertions, 130 deletions
diff --git a/ChangeLog b/ChangeLog
index e39bc5f..0df0122 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,43 @@
2008-07-21 Johan Dahlin <johan@gnome.org>
+ * glib/Makefile.am:
+ * glib/glibmodule.c (pyg_idle_add), (pyg_timeout_add),
+ (pyg_timeout_add_seconds), (pyg_io_add_watch),
+ (pyglib_register_api), (pyglib_register_error),
+ (pyglib_register_version_tuples), (init_glib):
+ * glib/pygiochannel.c (py_io_channel_next),
+ (py_io_channel_shutdown), (py_io_channel_set_encoding),
+ (py_io_channel_read_chars), (py_io_channel_write_chars),
+ (py_io_channel_write_lines), (py_io_channel_flush),
+ (py_io_channel_set_flags), (py_io_channel_read_line),
+ (py_io_channel_read_lines), (py_io_channel_seek),
+ (py_io_channel_init), (pyglib_iochannel_register_types):
+ * glib/pygiochannel.h:
+ * glib/pyglib-private.h:
+ * glib/pyglib.c (pyglib_threads_enabled),
+ (pyglib_gil_state_ensure), (pyglib_gil_state_release),
+ (pyglib_enable_threads), (pyglib_block_threads),
+ (pyglib_unblock_threads), (pyglib_set_thread_block_funcs),
+ (pyglib_handler_marshal), (pyglib_destroy_notify):
+ * glib/pyglib.h:
+ * glib/pygsource.c (pyg_source_set_callback),
+ (pyglib_source_register_types):
+ * glib/pygsource.h:
+ * glib/pygspawn.c (pyglib_spawn_register_types):
+ * glib/pygspawn.h:
+ * gobject/Makefile.am:
+ * gobject/__init__.py:
+ * gobject/gobjectmodule.c (pyg_set_thread_block_funcs),
+ (init_gobject):
+ * gobject/pygiochannel.c:
+ * gobject/pygobject-private.h:
+ * gobject/pygsource.c:
+ Move over Source, IOChannel, Idle, Timeout and PollFD to glib from
+ gobject.
+ Clean up and add a bit of new api for glib.
+
+2008-07-21 Johan Dahlin <johan@gnome.org>
+
* configure.ac:
Use yes/no instead of true/false. Avoid bashism.
Fix another logic bug, and let's hope I didn't break anything
diff --git a/glib/Makefile.am b/glib/Makefile.am
index e32d24d..c2cbf47 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -30,10 +30,16 @@ _glib_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_glib
_glib_la_LIBADD = $(GLIB_LIBS) libpyglib-2.0.la
_glib_la_SOURCES = \
glibmodule.c \
- pygspawn.c \
- pygspawn.h \
+ pygiochannel.c \
+ pygiochannel.h \
pygmaincontext.c \
- pygmainloop.c
+ pygmaincontext.h \
+ pygmainloop.c \
+ pygmainloop.h \
+ pygsource.c \
+ pygsource.h \
+ pygspawn.c \
+ pygspawn.h
if PLATFORM_WIN32
_glib_la_CFLAGS += -DPLATFORM_WIN32
diff --git a/glib/glibmodule.c b/glib/glibmodule.c
index 6892d1a..0281524 100644
--- a/glib/glibmodule.c
+++ b/glib/glibmodule.c
@@ -30,33 +30,16 @@
#include "pyglib.h"
#include "pyglib-private.h"
+#include "pygiochannel.h"
#include "pygmaincontext.h"
#include "pygmainloop.h"
+#include "pygsource.h"
#include "pygspawn.h"
#define PYGLIB_MAJOR_VERSION PYGOBJECT_MAJOR_VERSION
#define PYGLIB_MINOR_VERSION PYGOBJECT_MINOR_VERSION
#define PYGLIB_MICRO_VERSION PYGOBJECT_MICRO_VERSION
-/**
- * pyg_destroy_notify:
- * @user_data: a PyObject pointer.
- *
- * A function that can be used as a GDestroyNotify callback that will
- * call Py_DECREF on the data.
- */
-void
-pyg_destroy_notify(gpointer user_data)
-{
- PyObject *obj = (PyObject *)user_data;
- PyGILState_STATE state;
-
- state = pyglib_gil_state_ensure();
- Py_DECREF(obj);
- pyglib_gil_state_release(state);
-}
-
-
/* ---------------- glib module functions -------------------- */
@@ -100,33 +83,6 @@ get_handler_priority(gint *priority, PyObject *kwargs)
return 0;
}
-gboolean
-pyg_handler_marshal(gpointer user_data)
-{
- PyObject *tuple, *ret;
- gboolean res;
- PyGILState_STATE state;
-
- g_return_val_if_fail(user_data != NULL, FALSE);
-
- state = pyglib_gil_state_ensure();
-
- tuple = (PyObject *)user_data;
- ret = PyObject_CallObject(PyTuple_GetItem(tuple, 0),
- PyTuple_GetItem(tuple, 1));
- if (!ret) {
- PyErr_Print();
- res = FALSE;
- } else {
- res = PyObject_IsTrue(ret);
- Py_DECREF(ret);
- }
-
- pyglib_gil_state_release(state);
-
- return res;
-}
-
static PyObject *
pyg_idle_add(PyObject *self, PyObject *args, PyObject *kwargs)
{
@@ -160,8 +116,8 @@ pyg_idle_add(PyObject *self, PyObject *args, PyObject *kwargs)
data = Py_BuildValue("(ON)", callback, cbargs);
if (data == NULL)
return NULL;
- handler_id = g_idle_add_full(priority, pyg_handler_marshal, data,
- pyg_destroy_notify);
+ handler_id = g_idle_add_full(priority, pyglib_handler_marshal, data,
+ pyglib_destroy_notify);
return PyInt_FromLong(handler_id);
}
@@ -200,8 +156,8 @@ pyg_timeout_add(PyObject *self, PyObject *args, PyObject *kwargs)
if (data == NULL)
return NULL;
handler_id = g_timeout_add_full(priority, interval,
- pyg_handler_marshal, data,
- pyg_destroy_notify);
+ pyglib_handler_marshal, data,
+ pyglib_destroy_notify);
return PyInt_FromLong(handler_id);
}
@@ -239,8 +195,8 @@ pyg_timeout_add_seconds(PyObject *self, PyObject *args, PyObject *kwargs)
if (data == NULL)
return NULL;
handler_id = g_timeout_add_seconds_full(priority, interval,
- pyg_handler_marshal, data,
- pyg_destroy_notify);
+ pyglib_handler_marshal, data,
+ pyglib_destroy_notify);
return PyInt_FromLong(handler_id);
}
@@ -328,7 +284,7 @@ pyg_io_add_watch(PyObject *self, PyObject *args, PyObject *kwargs)
iochannel = g_io_channel_unix_new(fd);
handler_id = g_io_add_watch_full(iochannel, priority, condition,
iowatch_marshal, data,
- (GDestroyNotify)pyg_destroy_notify);
+ (GDestroyNotify)pyglib_destroy_notify);
g_io_channel_unref(iochannel);
return PyInt_FromLong(handler_id);
@@ -613,7 +569,7 @@ struct _PyGLib_Functions pyglib_api_functions = {
};
static void
-pyg_register_api(PyObject *d)
+pyglib_register_api(PyObject *d)
{
PyObject *o;
@@ -626,7 +582,7 @@ pyg_register_api(PyObject *d)
}
static void
-pyg_register_error(PyObject *d)
+pyglib_register_error(PyObject *d)
{
PyObject *dict;
PyObject *gerror_class;
@@ -644,7 +600,7 @@ pyg_register_error(PyObject *d)
}
static void
-pyg_register_version_tuples(PyObject *d)
+pyglib_register_version_tuples(PyObject *d)
{
PyObject *o;
@@ -671,11 +627,12 @@ init_glib(void)
m = Py_InitModule("glib._glib", pyglib_functions);
d = PyModule_GetDict(m);
- pyg_register_api(d);
- pyg_register_error(d);
- pyg_register_version_tuples(d);
- pyg_spawn_register_types(d);
-
+ pyglib_register_api(d);
+ pyglib_register_error(d);
+ pyglib_register_version_tuples(d);
+ pyglib_iochannel_register_types(d);
pyglib_mainloop_register_types(d);
pyglib_maincontext_register_types(d);
+ pyglib_source_register_types(d);
+ pyglib_spawn_register_types(d);
}
diff --git a/gobject/pygiochannel.c b/glib/pygiochannel.c
index 34ef837..609cdab 100644
--- a/gobject/pygiochannel.c
+++ b/glib/pygiochannel.c
@@ -4,11 +4,12 @@
# include <config.h>
#endif
-#include <pyglib.h>
-#include "pygobject-private.h"
-#include "pythread.h"
+#include <Python.h>
+#include <pythread.h>
#include <structmember.h> /* for PyMemberDef */
+#include "pyglib.h"
+#include "pyglib-private.h"
typedef struct {
PyObject_HEAD
@@ -27,7 +28,7 @@ py_io_channel_next(PyGIOChannel *self)
status = g_io_channel_read_line(self->channel, &str_return, &length,
&terminator_pos, &error);
- if (pyg_error_check(&error))
+ if (pyglib_error_check(&error))
return NULL;
if (status == G_IO_STATUS_EOF) {
@@ -82,7 +83,7 @@ py_io_channel_shutdown(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
return NULL;
ret = g_io_channel_shutdown(self->channel, PyObject_IsTrue(flush), &error);
- if (pyg_error_check(&error))
+ if (pyglib_error_check(&error))
return NULL;
return PyInt_FromLong(ret);
@@ -160,7 +161,7 @@ py_io_channel_set_encoding(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
return NULL;
g_io_channel_set_encoding(self->channel, encoding, &error);
- if (pyg_error_check(&error))
+ if (pyglib_error_check(&error))
return NULL;
Py_INCREF(Py_None);
@@ -230,11 +231,11 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
buf = PyString_AS_STRING(ret_obj) + total_read;
- pyg_unblock_threads();
+ pyglib_unblock_threads();
status = g_io_channel_read_chars(self->channel, buf, buf_size,
&single_read, &error);
- pyg_block_threads();
- if (pyg_error_check(&error))
+ pyglib_block_threads();
+ if (pyglib_error_check(&error))
goto failure;
total_read += single_read;
@@ -265,10 +266,10 @@ py_io_channel_write_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
kwlist, &buf, &buf_len))
return NULL;
- pyg_unblock_threads();
+ pyglib_unblock_threads();
status = g_io_channel_write_chars(self->channel, buf, buf_len, &count, &error);
- pyg_block_threads();
- if (pyg_error_check(&error))
+ pyglib_block_threads();
+ if (pyglib_error_check(&error))
return NULL;
return PyInt_FromLong(count);
@@ -304,11 +305,11 @@ py_io_channel_write_lines(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
return NULL;
}
PyString_AsStringAndSize(value, &buf, &buf_len);
- pyg_unblock_threads();
+ pyglib_unblock_threads();
status = g_io_channel_write_chars(self->channel, buf, buf_len, &count, &error);
- pyg_unblock_threads();
+ pyglib_unblock_threads();
Py_DECREF(value);
- if (pyg_error_check(&error)) {
+ if (pyglib_error_check(&error)) {
Py_DECREF(iter);
return NULL;
}
@@ -330,10 +331,10 @@ py_io_channel_flush(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
kwlist))
return NULL;
- pyg_unblock_threads();
+ pyglib_unblock_threads();
status = g_io_channel_flush(self->channel, &error);
- pyg_block_threads();
- if (pyg_error_check(&error))
+ pyglib_block_threads();
+ if (pyglib_error_check(&error))
return NULL;
return PyInt_FromLong(status);
@@ -352,7 +353,7 @@ py_io_channel_set_flags(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
return NULL;
status = g_io_channel_set_flags(self->channel, flags, &error);
- if (pyg_error_check(&error))
+ if (pyglib_error_check(&error))
return NULL;
return PyInt_FromLong(status);
@@ -576,7 +577,7 @@ py_io_channel_read_line(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
status = g_io_channel_read_line(self->channel, &str_return, &length,
&terminator_pos, &error);
- if (pyg_error_check(&error))
+ if (pyglib_error_check(&error))
return NULL;
ret_obj = PyString_FromStringAndSize(str_return, length);
g_free(str_return);
@@ -603,7 +604,7 @@ py_io_channel_read_lines(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
while (status == G_IO_STATUS_NORMAL) {
status = g_io_channel_read_line(self->channel, &str_return, &length,
&terminator_pos, &error);
- if (pyg_error_check(&error)) {
+ if (pyglib_error_check(&error)) {
Py_DECREF(line);
return NULL;
}
@@ -645,7 +646,7 @@ py_io_channel_seek(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
status = g_io_channel_seek_position(self->channel, offset,
seek_type, &error);
- if (pyg_error_check(&error))
+ if (pyglib_error_check(&error))
return NULL;
return PyInt_FromLong(status);
@@ -742,7 +743,7 @@ py_io_channel_init(PyGIOChannel *self, PyObject *args, PyObject *kwargs)
self->channel = g_io_channel_unix_new(fd);
else if (filename != NULL) {
self->channel = g_io_channel_new_file(filename, mode, &error);
- if (pyg_error_check(&error))
+ if (pyglib_error_check(&error))
return -1;
}
#ifdef G_OS_WIN32
@@ -810,3 +811,8 @@ PyTypeObject PyGIOChannel_Type = {
(PyObject *)0, /* tp_bases */
};
+void
+pyglib_iochannel_register_types(PyObject *d)
+{
+ PYGLIB_REGISTER_TYPE(d, PyGIOChannel_Type, "IOChannel");
+}
diff --git a/glib/pygiochannel.h b/glib/pygiochannel.h
new file mode 100644
index 0000000..35584b4
--- /dev/null
+++ b/glib/pygiochannel.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pyglib - Python bindings for GLib toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ * 2004-2008 Johan Dahlin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef __PYG_IOCHANNEL_H__
+#define __PYG_IOCHANNEL_H__
+
+extern PyTypeObject PyGIOChannel_Type;
+
+void pyglib_iochannel_register_types(PyObject *d);
+
+#endif /* __PYG_IOCHANNEL_H__ */
diff --git a/glib/pyglib-private.h b/glib/pyglib-private.h
index fa8c6dd..4609e90 100644
--- a/glib/pyglib-private.h
+++ b/glib/pyglib-private.h
@@ -28,8 +28,10 @@
G_BEGIN_DECLS
struct _PyGLib_Functions {
- gboolean threads_enabled;
- PyObject *gerror_exception;
+ gboolean threads_enabled;
+ PyObject *gerror_exception;
+ PyGLibThreadBlockFunc block_threads;
+ PyGLibThreadBlockFunc unblock_threads;
};
#define PYGLIB_REGISTER_TYPE(d, type, name) \
diff --git a/glib/pyglib.c b/glib/pyglib.c
index 3f7ebbd..a6d3c26 100644
--- a/glib/pyglib.c
+++ b/glib/pyglib.c
@@ -80,12 +80,16 @@ pyglib_init_internal(PyObject *api)
gboolean
pyglib_threads_enabled(void)
{
+ g_return_val_if_fail (_PyGLib_API != NULL, FALSE);
+
return _PyGLib_API->threads_enabled;
}
PyGILState_STATE
pyglib_gil_state_ensure(void)
{
+ g_return_val_if_fail (_PyGLib_API != NULL, PyGILState_LOCKED);
+
if (!_PyGLib_API->threads_enabled)
return PyGILState_LOCKED;
@@ -95,6 +99,8 @@ pyglib_gil_state_ensure(void)
void
pyglib_gil_state_release(PyGILState_STATE state)
{
+ g_return_if_fail (_PyGLib_API != NULL);
+
if (!_PyGLib_API->threads_enabled)
return;
@@ -116,6 +122,8 @@ pyglib_enable_threads(void)
gboolean
pyglib_enable_threads(void)
{
+ g_return_val_if_fail (_PyGLib_API != NULL, FALSE);
+
if (_PyGLib_API->threads_enabled)
return TRUE;
@@ -142,6 +150,47 @@ pyglib_gil_state_release_py23 (int flag)
PyGILState_Release(flag);
}
+/**
+ * pyglib_block_threads:
+ *
+ */
+void
+pyglib_block_threads(void)
+{
+ g_return_if_fail (_PyGLib_API != NULL);
+
+ if (_PyGLib_API->block_threads != NULL)
+ (* _PyGLib_API->block_threads)();
+}
+
+/**
+ * pyglib_unblock_threads:
+ *
+ */
+void
+pyglib_unblock_threads(void)
+{
+ g_return_if_fail (_PyGLib_API != NULL);
+ if (_PyGLib_API->unblock_threads != NULL)
+ (* _PyGLib_API->unblock_threads)();
+}
+
+/**
+ * pyglib_set_thread_block_funcs:
+ *
+ * hooks to register handlers for getting GDK threads to cooperate
+ * with python threading
+ */
+void
+pyglib_set_thread_block_funcs (PyGLibThreadBlockFunc block_threads_func,
+ PyGLibThreadBlockFunc unblock_threads_func)
+{
+ g_return_if_fail (_PyGLib_API != NULL);
+
+ _PyGLib_API->block_threads = block_threads_func;
+ _PyGLib_API->unblock_threads = unblock_threads_func;
+}
+
/**
* pyglib_error_check:
@@ -289,3 +338,50 @@ pyglib_main_context_new(GMainContext *context)
self->context = g_main_context_ref(context);
return (PyObject *)self;
}
+
+gboolean
+pyglib_handler_marshal(gpointer user_data)
+{
+ PyObject *tuple, *ret;
+ gboolean res;
+ PyGILState_STATE state;
+
+ g_return_val_if_fail(user_data != NULL, FALSE);
+
+ state = pyglib_gil_state_ensure();
+
+ tuple = (PyObject *)user_data;
+ ret = PyObject_CallObject(PyTuple_GetItem(tuple, 0),
+ PyTuple_GetItem(tuple, 1));
+ if (!ret) {
+ PyErr_Print();
+ res = FALSE;
+ } else {
+ res = PyObject_IsTrue(ret);
+ Py_DECREF(ret);
+ }
+
+ pyglib_gil_state_release(state);
+
+ return res;
+}
+
+/**
+ * pyglib_destroy_notify:
+ * @user_data: a PyObject pointer.
+ *
+ * A function that can be used as a GDestroyNotify callback that will
+ * call Py_DECREF on the data.
+ */
+void
+pyglib_destroy_notify(gpointer user_data)
+{
+ PyObject *obj = (PyObject *)user_data;
+ PyGILState_STATE state;
+
+ g_return_if_fail (_PyGLib_API != NULL);
+
+ state = pyglib_gil_state_ensure();
+ Py_DECREF(obj);
+ pyglib_gil_state_release(state);
+}
diff --git a/glib/pyglib.h b/glib/pyglib.h
index b2235d3..21da4d8 100644
--- a/glib/pyglib.h
+++ b/glib/pyglib.h
@@ -28,6 +28,8 @@
G_BEGIN_DECLS
+typedef void (*PyGLibThreadBlockFunc) (void);
+
void pyglib_init(void);
void pyglib_init_internal(PyObject *api);
PyGILState_STATE pyglib_gil_state_ensure(void);
@@ -37,6 +39,10 @@ gboolean pyglib_error_check(GError **error);
gboolean pyglib_gerror_exception_check(GError **error);
gboolean pyglib_threads_enabled(void);
PyObject *pyglib_main_context_new(GMainContext *context);
+gboolean pyglib_handler_marshal(gpointer user_data);
+void pyglib_destroy_notify(gpointer user_data);
+void pyglib_set_thread_block_funcs(PyGLibThreadBlockFunc block_threads_func,
+ PyGLibThreadBlockFunc unblock_threads_func);
#define pyglib_begin_allow_threads \
G_STMT_START { \
diff --git a/gobject/pygsource.c b/glib/pygsource.c
index ae667dc..1374c5d 100644
--- a/gobject/pygsource.c
+++ b/glib/pygsource.c
@@ -27,11 +27,14 @@
# include <config.h>
#endif
-#include "pygobject-private.h"
-#include "pythread.h"
-#include <structmember.h>
-#include <pyglib.h>
+#include <Python.h>
+#include <pythread.h>
+#include <structmember.h> /* for PyMemberDef */
+#include "pyglib.h"
+#include "pyglib-private.h"
+#include "pygmaincontext.h"
+#include "pygsource.h"
#define CHECK_DESTROYED(self, ret) G_STMT_START { \
if ((self)->source == NULL) { \
@@ -158,8 +161,9 @@ pyg_source_set_callback(PyGSource *self, PyObject *args)
if (data == NULL)
return NULL;
- g_source_set_callback(self->source, pyg_handler_marshal, data,
- pyg_destroy_notify);
+ g_source_set_callback(self->source,
+ pyglib_handler_marshal, data,
+ pyglib_destroy_notify);
Py_INCREF(Py_None);
return Py_None;
@@ -845,3 +849,12 @@ PyTypeObject PyGPollFD_Type = {
(inquiry)0, /* tp_is_gc */
(PyObject *)0, /* tp_bases */
};
+
+void
+pyglib_source_register_types(PyObject *d)
+{
+ PYGLIB_REGISTER_TYPE(d, PyGSource_Type, "Source");
+ PYGLIB_REGISTER_TYPE(d, PyGIdle_Type, "Idle");
+ PYGLIB_REGISTER_TYPE(d, PyGTimeout_Type, "Timeout");
+ PYGLIB_REGISTER_TYPE(d, PyGPollFD_Type, "PollFD");
+}
diff --git a/glib/pygsource.h b/glib/pygsource.h
new file mode 100644
index 0000000..bbfeee5
--- /dev/null
+++ b/glib/pygsource.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pyglib - Python bindings for GLib toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ * 2004-2008 Johan Dahlin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef __PYG_SOURCE_H__
+#define __PYG_SOURCE_H__
+
+extern PyTypeObject PyGSource_Type;
+extern PyTypeObject PyGIdle_Type;
+extern PyTypeObject PyGTimeout_Type;
+extern PyTypeObject PyGPollFD_Type;
+
+typedef struct
+{
+ PyObject_HEAD
+ GPollFD pollfd;
+ PyObject *fd_obj;
+} PyGPollFD;
+
+void pyglib_source_register_types(PyObject *d);
+
+#endif /* __PYG_SOURCE_H__ */
diff --git a/glib/pygspawn.c b/glib/pygspawn.c
index 08c40aa..7f35f58 100644
--- a/glib/pygspawn.c
+++ b/glib/pygspawn.c
@@ -290,7 +290,7 @@ pyglib_spawn_async(PyObject *object, PyObject *args, PyObject *kwargs)
}
void
-pyg_spawn_register_types(PyObject *d)
+pyglib_spawn_register_types(PyObject *d)
{
PyGPid_Type.tp_base = &PyInt_Type;
PYGLIB_REGISTER_TYPE(d, PyGPid_Type, "Pid");
diff --git a/glib/pygspawn.h b/glib/pygspawn.h
index e283b85..05dca15 100644
--- a/glib/pygspawn.h
+++ b/glib/pygspawn.h
@@ -23,7 +23,7 @@
#define __PYG_PID_H__
PyObject * pyg_pid_new(GPid pid);
-void pyg_spawn_register_types(PyObject *d);
+void pyglib_spawn_register_types(PyObject *d);
PyObject * pyglib_spawn_async(PyObject *self, PyObject *args, PyObject *kwargs);
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index dfd0f50..74c2e4c 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -53,8 +53,6 @@ _gobject_la_SOURCES = \
pygobject-private.h \
pygparamspec.c \
pygpointer.c \
- pygiochannel.c \
- pygsource.c \
pygtype.c \
pygoptioncontext.c \
pygoptiongroup.c
diff --git a/gobject/__init__.py b/gobject/__init__.py
index 19bdd0c..eba3eaf 100644
--- a/gobject/__init__.py
+++ b/gobject/__init__.py
@@ -32,7 +32,9 @@ from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \
get_current_time, filename_display_name, filename_display_basename, \
filename_from_utf8, get_application_name, set_application_name, \
get_prgname, set_prgname, main_depth, Pid, GError, glib_version, \
- MainLoop, MainContext, main_context_default
+ MainLoop, MainContext, main_context_default, IOChannel, Source, Idle, \
+ Timeout, PollFD
+
from gobject.constants import *
from _gobject import *
_PyGObject_API = _gobject._PyGObject_API
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 5af2c38..a5bf3aa 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -79,6 +79,8 @@ pyg_set_thread_block_funcs (PyGThreadBlockFunc block_threads_func,
pygobject_api_functions.block_threads = block_threads_func;
pygobject_api_functions.unblock_threads = unblock_threads_func;
+ pyglib_set_thread_block_funcs(block_threads_func,
+ unblock_threads_func);
}
static void
@@ -2753,13 +2755,6 @@ init_gobject(void)
PyGFlags_Type.tp_base = &PyInt_Type;
REGISTER_GTYPE(d, PyGFlags_Type, "GFlags", G_TYPE_FLAGS);
- REGISTER_TYPE(d, PyGIOChannel_Type, "IOChannel");
-
- REGISTER_TYPE(d, PyGSource_Type, "Source");
- REGISTER_TYPE(d, PyGIdle_Type, "Idle");
- REGISTER_TYPE(d, PyGTimeout_Type, "Timeout");
- REGISTER_TYPE(d, PyGPollFD_Type, "PollFD");
-
PyType_Ready(&PyGObjectWeakRef_Type);
PyDict_SetItemString(d, "GObjectWeakRef", (PyObject *) &PyGObjectWeakRef_Type);
@@ -2781,7 +2776,6 @@ init_gobject(void)
o=PyCObject_FromVoidPtr(&pygobject_api_functions,NULL));
Py_DECREF(o);
-
/* features */
features = PyDict_New();
#ifdef HAVE_FFI_H
diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h
index 5b71ed5..1b2255b 100644
--- a/gobject/pygobject-private.h
+++ b/gobject/pygobject-private.h
@@ -145,6 +145,13 @@ extern PyTypeObject PyGInterface_Type;
extern PyTypeObject PyGProps_Type;
extern PyTypeObject PyGPropsDescr_Type;
extern PyTypeObject PyGPropsIter_Type;
+
+ /* Data that belongs to the GObject instance, not the Python wrapper */
+struct _PyGObjectData {
+ PyTypeObject *type; /* wrapper type for this instance */
+ GSList *closures;
+};
+
void pygobject_register_class (PyObject *dict,
const gchar *type_name,
GType gtype, PyTypeObject *type,
@@ -236,28 +243,6 @@ PyTypeObject *_PyGMainContext_Type;
extern PyTypeObject PyGParamSpec_Type;
PyObject * pyg_param_spec_new (GParamSpec *pspec);
-/* pygiochannel.c */
-extern PyTypeObject PyGIOChannel_Type;
-
-/* pygsource.c */
-extern PyTypeObject PyGSource_Type;
-extern PyTypeObject PyGIdle_Type;
-extern PyTypeObject PyGTimeout_Type;
-extern PyTypeObject PyGPollFD_Type;
-
-typedef struct
-{
- PyObject_HEAD
- GPollFD pollfd;
- PyObject *fd_obj;
-} PyGPollFD;
-
- /* Data that belongs to the GObject instance, not the Python wrapper */
-struct _PyGObjectData {
- PyTypeObject *type; /* wrapper type for this instance */
- GSList *closures;
-};
-
/* pygoption.c */
extern PyTypeObject PyGOptionContext_Type;
extern PyTypeObject PyGOptionGroup_Type;