--- GClosure.xs.~1.9.~ 2003-08-19 21:04:28.000000000 +0200 +++ GClosure.xs 2003-08-20 20:47:45.000000000 +0200 @@ -65,6 +65,8 @@ gpointer marshal_data) { guint i; + const int gtk2_perl_trap_exceptions_in_callbacks = 0; + const SV* gtk2_perl_trap_exceptions_save_errsv = NULL; GPerlClosure *pc = (GPerlClosure *)closure; SV * data; #ifndef PERL_IMPLICIT_CONTEXT @@ -137,7 +139,7 @@ PUTBACK; if (return_value && G_VALUE_TYPE (return_value)) { - i = call_sv (pc->callback, G_SCALAR); + i = call_sv (pc->callback, G_SCALAR|G_EVAL); SPAGAIN; if (i != 1) @@ -146,11 +148,30 @@ gperl_value_from_sv (return_value, POPs); } else - call_sv (pc->callback, G_DISCARD); + call_sv (pc->callback, G_DISCARD|G_EVAL); /* * clean up */ + if (SvTRUE(ERRSV)) { + if (!gtk2_perl_trap_exceptions_in_callbacks) + fprintf(stderr, "\tGtk2-Perl: callback threw a perl exception (a die) but I can't recover\n" + "\tcorrectly from it, sorry (only handled when callbacks are called from within\n" + "\ta gtk_main), continuing normal execution; try to not use exceptions in\n" + "\tthis callback. Exception:\n%s\n", SvPV_nolen(ERRSV)); + else { + if (!gtk2_perl_trap_exceptions_save_errsv) { + gtk2_perl_trap_exceptions_save_errsv = newSVsv(ERRSV); + gtk_main_quit(); + } else { + fprintf(stderr, "\tGtk2-Perl: callback threw a perl exception (a die) but there is\n" + "\talready a pending exception originating from another callback that\n" + "\tneeds to be re-launched; this one will then be ignored; FYI, the\n" + "\texception thrown by this callback was:\n%s\n", SvPV_nolen(ERRSV)); + } + } + } + FREETMPS; LEAVE;