pygobject r840 - in trunk: . glib



Author: johan
Date: Sun Jul 20 12:06:24 2008
New Revision: 840
URL: http://svn.gnome.org/viewvc/pygobject?rev=840&view=rev

Log:
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.



Modified:
   trunk/ChangeLog
   trunk/glib/Makefile.am
   trunk/glib/glibmodule.c
   trunk/glib/pyglib.c
   trunk/glib/pyglib.h

Modified: trunk/glib/Makefile.am
==============================================================================
--- trunk/glib/Makefile.am	(original)
+++ trunk/glib/Makefile.am	Sun Jul 20 12:06:24 2008
@@ -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 @@
 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	\

Modified: trunk/glib/glibmodule.c
==============================================================================
--- trunk/glib/glibmodule.c	(original)
+++ trunk/glib/glibmodule.c	Sun Jul 20 12:06:24 2008
@@ -343,14 +343,13 @@
     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 @@
       (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 }
 };
 

Modified: trunk/glib/pyglib.c
==============================================================================
--- trunk/glib/pyglib.c	(original)
+++ trunk/glib/pyglib.c	Sun Jul 20 12:06:24 2008
@@ -98,6 +98,9 @@
     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 @@
     
     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;
+}

Modified: trunk/glib/pyglib.h
==============================================================================
--- trunk/glib/pyglib.h	(original)
+++ trunk/glib/pyglib.h	Sun Jul 20 12:06:24 2008
@@ -32,7 +32,9 @@
 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
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]