diff options
author | James Henstridge <james@daa.com.au> | 2001-12-02 02:59:19 +0000 |
---|---|---|
committer | James Henstridge <jamesh@src.gnome.org> | 2001-12-02 02:59:19 +0000 |
commit | 3a232784da8744857bc365b8030e9def6e2fce3c (patch) | |
tree | 1792d9f41d2e75c8141801d30ca88f9aee235200 | |
parent | e12d01c3cf7a54bbcbda2723113acaf3655c28d2 (diff) | |
download | pygobject-3a232784da8744857bc365b8030e9def6e2fce3c.tar.gz pygobject-3a232784da8744857bc365b8030e9def6e2fce3c.tar.xz pygobject-3a232784da8744857bc365b8030e9def6e2fce3c.zip |
use pyg_error_check to raise the exception. Now the domain and code
2001-12-02 James Henstridge <james@daa.com.au>
* codegen/argtypes.py (GTypeArg.write_return): use pyg_error_check
to raise the exception. Now the domain and code elements of the
GError are available.
(GtkTreePathArg.write_param): add to codeafter in order to free
the tree path we created, fixing a leak.
* gobjectmodule.c (initgobject): create a gobject.GError
exception.
(pyg_error_check): function for converting a GError into a
gobject.GError python exception.
-rw-r--r-- | gobject/gobjectmodule.c | 39 | ||||
-rw-r--r-- | gobject/pygobject.h | 3 |
2 files changed, 42 insertions, 0 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index ebd5d25..7ae484c 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -2,6 +2,8 @@ #define _INSIDE_PYGOBJECT_ #include "pygobject.h" +static PyObject *gerror_exc = NULL; + static GQuark pygobject_class_key = 0; static GQuark pygobject_wrapper_key = 0; static GQuark pygobject_ownedref_key = 0; @@ -2349,6 +2351,38 @@ pyg_fatal_exceptions_notify_remove(PyGFatalExceptionFunc func) g_list_remove(pygobject_exception_notifiers, func); } +static gboolean +pyg_error_check(GError **error) +{ + g_return_val_if_fail(error != NULL, FALSE); + + if (*error != NULL) { + PyObject *exc_instance; + PyObject *d; + + exc_instance = PyObject_CallFunction(gerror_exc, "z", + (*error)->message); + PyObject_SetAttrString(exc_instance, "domain", + d=PyString_FromString(g_quark_to_string((*error)->domain))); + Py_DECREF(d); + PyObject_SetAttrString(exc_instance, "code", + d=PyInt_FromLong((*error)->code)); + Py_DECREF(d); + if ((*error)->message) { + PyObject_SetAttrString(exc_instance, "message", + d=PyString_FromString((*error)->message)); + Py_DECREF(d); + } else { + PyObject_SetAttrString(exc_instance, "message", Py_None); + } + + PyErr_SetObject(gerror_exc, exc_instance); + g_clear_error(error); + return TRUE; + } + return FALSE; +} + /* ----------------- gobject module initialisation -------------- */ static struct _PyGObject_Functions functions = { @@ -2378,6 +2412,8 @@ static struct _PyGObject_Functions functions = { pyg_fatal_exceptions_notify_remove, pyg_constant_strip_prefix, + + pyg_error_check, }; DL_EXPORT(void) @@ -2401,6 +2437,9 @@ initgobject(void) pyobject_copy, pyobject_free); + gerror_exc = PyErr_NewException("gobject.GError", PyExc_RuntimeError,NULL); + PyDict_SetItemString(d, "GError", gerror_exc); + pygobject_register_class(d, "GObject", G_TYPE_OBJECT, &PyGObject_Type, NULL); diff --git a/gobject/pygobject.h b/gobject/pygobject.h index f5d6d68..a2d400a 100644 --- a/gobject/pygobject.h +++ b/gobject/pygobject.h @@ -69,6 +69,8 @@ struct _PyGObject_Functions { gchar *(* constant_strip_prefix)(gchar *name, const gchar *strip_prefix); + + gboolean (* error_check)(GError **error); }; #ifndef _INSIDE_PYGOBJECT_ @@ -100,6 +102,7 @@ struct _PyGObject_Functions *_PyGObject_API; #define pyg_fatal_exceptions_notify_add (_PyGObject_API->fatal_exceptions_notify_add) #define pyg_fatal_exceptions_notify_remove (_PyGObject_API->fatal_exceptions_notify_remove) #define pyg_constant_strip_prefix (_PyGObject_API->constant_strip_prefix) +#define pyg_error_check (_PyGObject_API->error_check) #define init_pygobject() { \ PyObject *gobject = PyImport_ImportModule("gobject"); \ |