Hello,
when the environment variable PYGTK_FATAL_EXCEPTIONS is set and an
exception occurs in a signal handler, the current mainloop is
terminated so that the exception can be handled at the outer level
(instead of just printing an error message to sys.stderr).
In the current implementation, when another signal handler is executed
before the call of gtk_main() (in gtkmodule.c) returns, the exception
info is zapped. This happens when an exception occurs in the "close"
signal handler of GnomeDialog, when the "destroy" signal handler is
automatically invoked before gtk_main() returns.
The appended patch saves the exception info on return of the signal
handler and restores it on exit of gtk_main() (only the first
exception is saved, subsequent exceptions before ruturning from
gtk_main are printed to sys.stderr).
ciao
Andreas
PS: some parts of the diff have been deleted (other pending (?)
patches), so the line numbers aren't correct. sorry.
Index: gtkmodule.c
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/gtkmodule.c,v
retrieving revision 1.34
diff -u -r1.34 gtkmodule.c
--- gtkmodule.c 1999/09/28 16:10:59 1.34
+++ gtkmodule.c 1999/11/17 14:37:51
@@ -2350,6 +2355,33 @@
PyGTK_UNBLOCK_THREADS
}
+static PyObject *saved_exc_type = NULL;
+static PyObject *saved_exc_value = NULL;
+static PyObject *saved_exc_traceback = NULL;
+
+static void PyGtk_SuspendException(void)
+{
+ if (PyGtk_FatalExceptions && !saved_exc_type) {
+ PyErr_Fetch(&saved_exc_type, &saved_exc_value,
+ &saved_exc_traceback);
+ gtk_main_quit();
+ }
+ else {
+ PyErr_Print();
+ PyErr_Clear();
+ }
+}
+
+static int PyGtk_ResumeException(void)
+{
+ if (!saved_exc_type)
+ return 0;
+ PyErr_Restore(saved_exc_type,saved_exc_value,saved_exc_traceback);
+ saved_exc_type = saved_exc_value = saved_exc_traceback = NULL;
+ return 1;
+}
+
/* this hash table is used to let these functions know about new boxed
* types (eg. maybe some from GNOME). The functions return TRUE on error */
typedef PyObject *(*fromargfunc)(gpointer boxed);
@@ -3013,12 +3045,7 @@
ret = PyObject_CallObject(func, params);
Py_DECREF(params);
if (ret == NULL) {
- if (PyGtk_FatalExceptions)
- gtk_main_quit();
- else {
- PyErr_Print();
- PyErr_Clear();
- }
+ PyGtk_SuspendException();
PyGTK_UNBLOCK_THREADS
return;
}
@@ -3055,12 +3082,7 @@
Py_DECREF(params);
if (ret == NULL) {
- if (PyGtk_FatalExceptions)
- gtk_main_quit();
- else {
- PyErr_Print();
- PyErr_Clear();
- }
+ PyGtk_SuspendException();
PyGTK_UNBLOCK_THREADS
return;
}
@@ -3090,12 +3112,7 @@
else
ret = PyObject_CallObject(func, NULL);
if (ret == NULL) {
- if (PyGtk_FatalExceptions)
- gtk_main_quit();
- else {
- PyErr_Print();
- PyErr_Clear();
- }
+ PyGtk_SuspendException();
*GTK_RETLOC_BOOL(args[0]) = FALSE;
PyGTK_UNBLOCK_THREADS
return;
@@ -3119,12 +3136,7 @@
ret = PyObject_CallObject(func, tuple);
Py_DECREF(tuple);
if (ret == NULL) {
- if (PyGtk_FatalExceptions)
- gtk_main_quit();
- else {
- PyErr_Print();
- PyErr_Clear();
- }
+ PyGtk_SuspendException();
} else
Py_DECREF(ret);
PyGTK_UNBLOCK_THREADS
@@ -3479,7 +3477,7 @@
gtk_main();
PyGTK_BLOCK_THREADS
- if (PyErr_Occurred())
+ if (PyGtk_ResumeException())
return NULL;
Py_INCREF(Py_None);
return Py_None;
@@ -3493,6 +3491,8 @@
PyGTK_UNBLOCK_THREADS
ret = gtk_main_iteration_do(block);
PyGTK_BLOCK_THREADS
+ if (PyGtk_ResumeException())
+ return NULL;
return PyInt_FromLong(ret);
}
@@ -4457,12 +4448,7 @@
ret = PyObject_CallFunction(callback, "iO", action,
PyGtk_New((GtkObject *)widget));
if (ret == NULL) {
- if (PyGtk_FatalExceptions)
- gtk_main_quit();
- else {
- PyErr_Print();
- PyErr_Clear();
- }
+ PyGtk_SuspendException();
} else
Py_DECREF(ret);
PyGTK_UNBLOCK_THREADS
@@ -4534,12 +4520,7 @@
ret = PyObject_CallFunction(func, "Oii", PyGtk_New(GTK_OBJECT(menu)),
*x, *y);
if (ret == NULL || !PyArg_ParseTuple(ret, "ii", x, y)) {
- if (PyGtk_FatalExceptions)
- gtk_main_quit();
- else {
- PyErr_Print();
- PyErr_Clear();
- }
+ PyGtk_SuspendException();
if (ret) Py_DECREF(ret);
} else
Py_DECREF(ret);
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]