summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Wilson <msw@redhat.com>2001-11-15 07:33:20 +0000
committerMatt Wilson <msw@src.gnome.org>2001-11-15 07:33:20 +0000
commitc9deb4cac0b6be500d0843df3b716f049458c661 (patch)
tree07f21aea82d76c32dcfa5cbea0ea69521a72b386
parent44bbf9615c68f2f482125becf46809d0b516d9c5 (diff)
downloadpygobject-c9deb4cac0b6be500d0843df3b716f049458c661.tar.gz
pygobject-c9deb4cac0b6be500d0843df3b716f049458c661.tar.xz
pygobject-c9deb4cac0b6be500d0843df3b716f049458c661.zip
added PyGFatalExceptionFunc typedef, API wrapper for
2001-11-15 Matt Wilson <msw@redhat.com> * pygobject.h: added PyGFatalExceptionFunc typedef, API wrapper for pyg_fatal_exceptions_{add,remove}. * gobjectmodule.c (pyg_boxed_new): return NULL on assertion failures, #62814 (pyg_closure_new): actually assign swap_data to the closure. (pyg_fatal_exceptions_notify, pyg_fatal_exceptions_notify_add, pyg_fatal_exceptions_remove): added mechanism for gobjectmodule using modules to get a function called when a fatal exception happens in closures, etc. (pyg_closure_marshal, pyg_signal_class_closure_marshal): return NULL if a gobjectmodule using module registered a fatal exception function. * gtk/pygtk-private.h: added declarations for pygtk_custom_destroy_notify, pygtk_tree_selection_marshal, pygtk_tree_foreach_marshal. Added typedef for PyGtkCustomNotify. #62814 * gtk/gtkmodule.c (init_gtk): register stock items, #62814. Set up fatal exception stuff if PYGTK_FATAL_EXCEPTIONS is set. This isn't 100% done yet, gtk mainloop specific functions still need work. * gtk/gtkobject-support.c (pygtk_tree_selection_marshal): added, #62814 (pygtk_tree_foreach_marshal): added, #62814 (pygtk_custom_destroy_notify): added, #62814 * gtk/gtk.override (_wrap_gtk_tree_selection_set_select_function): added, #62814 (_wrap_gtk_tree_selection_selected_foreach): added, #62814
-rw-r--r--gobject/gobjectmodule.c54
-rw-r--r--gobject/pygobject.h7
2 files changed, 50 insertions, 11 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 654b5d1..3f800f0 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -7,11 +7,13 @@ static GHashTable *class_hash;
static GQuark pygobject_wrapper_key = 0;
static GQuark pygobject_ownedref_key = 0;
+static GList *pygobject_exception_notifiers = NULL;
+
staticforward PyTypeObject PyGObject_Type;
static void pygobject_dealloc(PyGObject *self);
static int pygobject_traverse(PyGObject *self, visitproc visit, void *arg);
-
+static int pyg_fatal_exceptions_notify(void);
static void
object_free(PyObject *op)
@@ -492,8 +494,8 @@ pyg_boxed_new(GType boxed_type, gpointer boxed, gboolean copy_boxed,
PyGBoxed *self;
PyTypeObject *tp;
- g_return_if_fail(boxed_type != 0);
- g_return_if_fail(!copy_boxed || (copy_boxed && own_ref));
+ g_return_val_if_fail(boxed_type != 0, NULL);
+ g_return_val_if_fail(!copy_boxed || (copy_boxed && own_ref), NULL);
if (!boxed) {
Py_INCREF(Py_None);
@@ -948,10 +950,10 @@ pyg_closure_marshal(GClosure *closure,
}
ret = PyObject_CallObject(pc->callback, params);
if (ret == NULL) {
- /* XXXX - do fatal exceptions thing here */
- PyErr_Print();
- PyErr_Clear();
- /* XXXX - clean up if threading was used */
+ if (!pyg_fatal_exceptions_notify()) {
+ PyErr_Print();
+ PyErr_Clear();
+ }
return;
}
if (return_value)
@@ -983,7 +985,7 @@ pyg_closure_new(PyObject *callback, PyObject *extra_args, PyObject *swap_data)
}
if (swap_data) {
Py_INCREF(swap_data);
- ((PyGClosure *)closure)->swap_data;
+ ((PyGClosure *)closure)->swap_data = swap_data;
closure->derivative_flag = TRUE;
}
return closure;
@@ -1061,9 +1063,10 @@ pyg_signal_class_closure_marshal(GClosure *closure,
ret = PyObject_CallObject(method, params);
if (ret == NULL) {
- /* XXXX - do fatal exceptions thing here */
- PyErr_Print();
- PyErr_Clear();
+ if (!pyg_fatal_exceptions_notify()) {
+ PyErr_Print();
+ PyErr_Clear();
+ }
/* XXXX - clean up if threading was used */
Py_DECREF(method);
return;
@@ -2280,6 +2283,32 @@ pyg_flags_add_constants(PyObject *module, GType flags_type,
g_type_class_unref(fclass);
}
+static int
+pyg_fatal_exceptions_notify(void)
+{
+ GList *tmp_list = pygobject_exception_notifiers;
+ if (!tmp_list)
+ return 0;
+ while (tmp_list != NULL) {
+ PyGFatalExceptionFunc notifier = tmp_list->data;
+ (*notifier)();
+ tmp_list = g_list_next (tmp_list);
+ }
+ return 1;
+}
+static void
+pyg_fatal_exceptions_notify_add(PyGFatalExceptionFunc func)
+{
+ pygobject_exception_notifiers =
+ g_list_append(pygobject_exception_notifiers, &func);
+}
+
+static int
+pyg_fatal_exceptions_notify_remove(PyGFatalExceptionFunc func)
+{
+ pygobject_exception_notifiers =
+ g_list_remove(pygobject_exception_notifiers, &func);
+}
/* ----------------- gobject module initialisation -------------- */
@@ -2305,6 +2334,9 @@ static struct _PyGObject_Functions functions = {
pyg_enum_add_constants,
pyg_flags_add_constants,
+
+ pyg_fatal_exceptions_notify_add,
+ pyg_fatal_exceptions_notify_remove,
};
DL_EXPORT(void)
diff --git a/gobject/pygobject.h b/gobject/pygobject.h
index 4be17b9..95fd84e 100644
--- a/gobject/pygobject.h
+++ b/gobject/pygobject.h
@@ -28,6 +28,8 @@ typedef struct {
#define pyg_boxed_get(v,t) ((t *)((PyGBoxed *)(v))->boxed)
#define pyg_boxed_check(v,typecode) (PyObject_TypeCheck(v, &PyGBoxed_Type) && ((PyGBoxed *)(v))->gtype == typecode)
+typedef void (*PyGFatalExceptionFunc) (void);
+
struct _PyGObject_Functions {
void (* register_class)(PyObject *dict, const gchar *class_name,
GType gtype, PyTypeObject *type, PyObject *bases);
@@ -61,6 +63,9 @@ struct _PyGObject_Functions {
const gchar *strip_prefix);
void (* flags_add_constants)(PyObject *module, GType flags_type,
const gchar *strip_prefix);
+
+ void (* fatal_exceptions_notify_add)(PyGFatalExceptionFunc func);
+ void (* fatal_exceptions_notify_remove)(PyGFatalExceptionFunc func);
};
#ifndef _INSIDE_PYGOBJECT_
@@ -89,6 +94,8 @@ struct _PyGObject_Functions *_PyGObject_API;
#define pyg_boxed_new (_PyGObject_API->boxed_new)
#define pyg_enum_add_constants (_PyGObject_API->enum_add_constants)
#define pyg_flags_add_constants (_PyGObject_API->flags_add_constants)
+#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 init_pygobject() { \
PyObject *gobject = PyImport_ImportModule("gobject"); \