summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--glib/Makefile.am11
-rw-r--r--glib/glibmodule.c8
-rw-r--r--glib/pyglib.c77
-rw-r--r--glib/pyglib.h2
5 files changed, 97 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 8248b16..d36b213 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2008-07-20 Johan Dahlin <johan@gnome.org>
+ * glib/Makefile.am:
+ * glib/glibmodule.c (pyg_main_context_default):
+ * glib/pyglib.c (pyglib_gerror_exception_check):
+ * glib/pyglib.h:
+ Rename helper library to libpyglib-2.0.
+ Move over pyg_gerror_exception_check as well.
+
+2008-07-20 Johan Dahlin <johan@gnome.org>
+
* Makefile.am:
* configure.ac:
* glib/Makefile.am:
diff --git a/glib/Makefile.am b/glib/Makefile.am
index 7e57580..fcb5e76 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -1,10 +1,9 @@
AUTOMAKE_OPTIONS = 1.7
-PLATFORM_VERSION = 2.0
INCLUDES = $(PYTHON_INCLUDES) $(GLIB_CFLAGS) -DPY_SSIZE_T_CLEAN
# Workaround for automake so we can build shared library which are not
# going to be installed
-noinstshared_LTLIBRARIES = libpyglib.la _glib.la
+noinstshared_LTLIBRARIES = libpyglib-2.0.la _glib.la
noinstshareddir = /tmp
install-noinstsharedLTLIBRARIES: # prevent it from being installed
@@ -13,16 +12,16 @@ if PLATFORM_WIN32
common_ldflags += -no-undefined
endif
-libpyglib_la_CFLAGS = $(GLIB_CFLAGS)
-libpyglib_la_LIBADD = $(GLIB_LIBS) $(FFI_LIBS)
-libpyglib_la_SOURCES = \
+libpyglib_2_0_la_CFLAGS = $(GLIB_CFLAGS)
+libpyglib_2_0_la_LIBADD = $(GLIB_LIBS) $(FFI_LIBS)
+libpyglib_2_0_la_SOURCES = \
pyglib.c \
pyglib.h \
pyglib-private.h
_glib_la_CFLAGS = $(GLIB_CFLAGS)
_glib_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_glib
-_glib_la_LIBADD = $(GLIB_LIBS) libpyglib.la
+_glib_la_LIBADD = $(GLIB_LIBS) libpyglib-2.0.la
_glib_la_SOURCES = \
glibmodule.c \
pygspawn.c \
diff --git a/glib/glibmodule.c b/glib/glibmodule.c
index 4e01f58..25ded22 100644
--- a/glib/glibmodule.c
+++ b/glib/glibmodule.c
@@ -343,14 +343,13 @@ pyg_source_remove(PyObject *self, PyObject *args)
return PyBool_FromLong(g_source_remove(tag));
}
+#ifdef FIXME
static PyObject *
pyg_main_context_default(PyObject *unused)
{
-#ifdef FIXME
return pyg_main_context_new(g_main_context_default());
-#endif
- return NULL;
}
+#endif
struct _PyGChildData {
PyObject *func;
@@ -599,9 +598,10 @@ static PyMethodDef pyglib_functions[] = {
(PyCFunction)pyg_set_prgname, METH_VARARGS },
{ "main_depth",
(PyCFunction)pyg_main_depth, METH_NOARGS },
+#if 0
{ "main_context_default",
(PyCFunction)pyg_main_context_default, METH_NOARGS },
-
+#endif
{ NULL, NULL, 0 }
};
diff --git a/glib/pyglib.c b/glib/pyglib.c
index bdc3d67..57bc095 100644
--- a/glib/pyglib.c
+++ b/glib/pyglib.c
@@ -98,6 +98,9 @@ pyglib_enable_threads(void)
return FALSE;
}
#else
+/* Enable threading; note that the GIL must be held by the current
+ * thread when this function is called
+ */
gboolean
pyglib_enable_threads(void)
{
@@ -178,3 +181,77 @@ pyglib_error_check(GError **error)
return TRUE;
}
+
+/**
+ * pyglib_gerror_exception_check:
+ * @error: a standard GLib GError ** output parameter
+ *
+ * Checks to see if a GError exception has been raised, and if so
+ * translates the python exception to a standard GLib GError. If the
+ * raised exception is not a GError then PyErr_Print() is called.
+ *
+ * Returns: 0 if no exception has been raised, -1 if it is a
+ * valid gobject.GError, -2 otherwise.
+ */
+gboolean
+pyglib_gerror_exception_check(GError **error)
+{
+ PyObject *type, *value, *traceback;
+ PyObject *py_message, *py_domain, *py_code;
+ const char *bad_gerror_message;
+
+ PyErr_Fetch(&type, &value, &traceback);
+ if (type == NULL)
+ return 0;
+ PyErr_NormalizeException(&type, &value, &traceback);
+ if (value == NULL) {
+ PyErr_Restore(type, value, traceback);
+ PyErr_Print();
+ return -2;
+ }
+ if (!value ||
+ !PyErr_GivenExceptionMatches(type,
+ (PyObject *) _PyGLib_API->gerror_exception)) {
+ PyErr_Restore(type, value, traceback);
+ PyErr_Print();
+ return -2;
+ }
+ Py_DECREF(type);
+ Py_XDECREF(traceback);
+
+ py_message = PyObject_GetAttrString(value, "message");
+ if (!py_message || !PyString_Check(py_message)) {
+ bad_gerror_message = "gobject.GError instances must have a 'message' string attribute";
+ goto bad_gerror;
+ }
+
+ py_domain = PyObject_GetAttrString(value, "domain");
+ if (!py_domain || !PyString_Check(py_domain)) {
+ bad_gerror_message = "gobject.GError instances must have a 'domain' string attribute";
+ Py_DECREF(py_message);
+ goto bad_gerror;
+ }
+
+ py_code = PyObject_GetAttrString(value, "code");
+ if (!py_code || !PyInt_Check(py_code)) {
+ bad_gerror_message = "gobject.GError instances must have a 'code' int attribute";
+ Py_DECREF(py_message);
+ Py_DECREF(py_domain);
+ goto bad_gerror;
+ }
+
+ g_set_error(error, g_quark_from_string(PyString_AsString(py_domain)),
+ PyInt_AsLong(py_code), PyString_AsString(py_message));
+
+ Py_DECREF(py_message);
+ Py_DECREF(py_code);
+ Py_DECREF(py_domain);
+ return -1;
+
+bad_gerror:
+ Py_DECREF(value);
+ g_set_error(error, g_quark_from_static_string("pygobject"), 0, bad_gerror_message);
+ PyErr_SetString(PyExc_ValueError, bad_gerror_message);
+ PyErr_Print();
+ return -2;
+}
diff --git a/glib/pyglib.h b/glib/pyglib.h
index 578aaa7..30b5f74 100644
--- a/glib/pyglib.h
+++ b/glib/pyglib.h
@@ -32,7 +32,9 @@ void pyglib_init(void);
void pyglib_init_internal(PyObject *api);
PyGILState_STATE pyglib_gil_state_ensure(void);
void pyglib_gil_state_release(PyGILState_STATE state);
+gboolean pyglib_enable_threads(void);
gboolean pyglib_error_check(GError **error);
+gboolean pyglib_gerror_exception_check(GError **error);
G_END_DECLS