Re: exception trap in key snooper callback
- From: muppet <scott asofyet org>
- To: "gtk-perl-list gnome org List" <gtk-perl-list gnome org>
- Subject: Re: exception trap in key snooper callback
- Date: Sun, 3 Aug 2008 17:37:00 -0400
On Aug 3, 2008, at 9:51 AM, Torsten Schoenfeld wrote:
Kevin Ryde wrote:
I had an error in some key snooper callback code and hoped it might
trap
to the installed "exception_handler" instead of aborting the program.
Is there a reason the "GPerlClosure" and "GPerlCallback" stuff
differ in
that trapping?
As far as I can tell, the only place where the exception handlers
are invoked
from is gperl_signal_class_closure_marshal. So it seems that they
are only
meant to handle exceptions occurring inside signal handlers.
That's correct. We didn't initially have any plans to do anything
special with exceptions in signal handlers, but we had to. Perl
exceptions do a longjmp(), which would jump right past the C stack
frames which held the signal invocation state in libgobject, causing a
SIGSEGV shortly thereafter. So, we put in the exception handler to
trap these exceptions and finish cleanly; if you don't want simply to
print the exception and go on, you install a handler and call exit()
or queue an idle or whatever.
The rationale is detailed here:
http://mail.gnome.org/archives/gtk-perl-list/2003-August/msg00398.html
GPerlCallback wraps up a plain old C function pointer, such as those
used by most of the "i need a callback" APIs throughout the rest of
the gnome stack. These things don't give you enough context to employ
a GClosure properly (e.g., they take only a funciton pointer, not a
GClosure object, and might not give you a destroy-notify callback that
could be used to unref the closure). Also, in most places where a
GPerlCallback is used, the same sort of stack cleanup that
necessitated the exception handlers for signals is not required ---
that is, you *can* cleanly longjmp() out of most callbacks (or at
least, we haven't seen crashes because of it). Technically, a
GPerlCallback object is not required for these -- you could just write
some bog-standard xs callback stuff -- but using it takes care of a
fair amount of tedious boilerplate.
--
If the monkey could type one keystroke every nanosecond, the expected
waiting time until the monkey types out Hamlet is so long that the
estimated age of the universe is insignificant by comparison ... this
is not a practical method for writing plays.
-- Gian-Carlo Rota
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]