summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--gobject/gobjectmodule.c75
-rw-r--r--gobject/pygobject.h3
3 files changed, 80 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index a69b0fd..906a112 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2007-04-14 Gustavo J. A. M. Carneiro <gjc@gnome.org>
+ * gobject/gobjectmodule.c, gobject/pygobject.h: Add a new
+ pyg_gerror_exception_check API. Fixes #425242.
+
* gobject/gobjectmodule.c (pyg_set_application_name)
(pyg_set_prgname): Add wrappers for g_set_application_name and
g_set_prgname. Patch by Havoc Pennington. Fixes #415853.
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index f2da743..32256a6 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -3010,6 +3010,78 @@ pyg_error_check(GError **error)
return FALSE;
}
+/**
+ * pyg_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.
+ */
+static gboolean
+pyg_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 *) &gerror_exc)) {
+ 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;
+}
+
static PyObject *
_pyg_strv_from_gvalue(const GValue *value)
@@ -3359,7 +3431,8 @@ struct _PyGObject_Functions pygobject_api_functions = {
add_warning_redirection,
disable_warning_redirections,
- pyg_type_register_custom_callback
+ pyg_type_register_custom_callback,
+ pyg_gerror_exception_check
};
#define REGISTER_TYPE(d, type, name) \
diff --git a/gobject/pygobject.h b/gobject/pygobject.h
index 045f53a..43e7906 100644
--- a/gobject/pygobject.h
+++ b/gobject/pygobject.h
@@ -185,6 +185,7 @@ struct _PyGObject_Functions {
void (*type_register_custom)(const gchar *type_name,
PyGTypeRegistrationFunction callback,
gpointer data);
+ gboolean (*gerror_exception_check) (GError **error);
};
@@ -248,6 +249,8 @@ struct _PyGObject_Functions *_PyGObject_API;
#define pyg_add_warning_redirection (_PyGObject_API->add_warning_redirection)
#define pyg_disable_warning_redirections (_PyGObject_API->disable_warning_redirections)
#define pyg_type_register_custom_callback (_PyGObject_API->type_register_custom)
+#define pyg_gerror_exception_check (_PyGObject_API->gerror_exception_check)
+
#define pyg_block_threads() G_STMT_START { \
if (_PyGObject_API->block_threads != NULL) \