On Fri, Jul 26, 2002 at 04:10:20PM -0400, Brian Smith wrote:
> I'm looking into building a GLib as a plug-in component for an app of
> mine and, according to one page, functions called via function pointers
> use the globals of the caller. The following is what I'm thinking this
> means:
>
> 1. I pass a pointer to a callback function in the app to the GLib.
> 2. If I call a function in the GLib that calls that callback function
> via the pointer, the callback is called with the globals of the GLib.
A GLib always accesses its globals via %a4, while (in prc-tools 2.x) an
application (typically) accesses its globals via %a5. In particular,
all code in a GLib considers %a5 to be fixed and untouchable, because
to do otherwise is unnecessary and can disgruntle the operating system.
In this particular case, your callback function foo() within the app is
of course compiled to access its (the app's) globals via %a5. Going via
code within the GLib doesn't disturb %a5, so when execution gets back to
foo(), e.g. as a "callback" via the function pointer you supplied, its
(i.e. the app's) globals are of course accessible.
What web page are you referring to? It's either wrong or, apparently,
unclear.
Wouldn't you just know it: this is all documented. See in particular
the "Initialising A4" section of the prc-tools manual, e.g., online at
http://prc-tools.sourceforge.net/cgi-bin/info/Initialising+A4
You should probably take the EntryPoints.h stuff with a grain of salt,
because it's never been extensively exercised.
> That is, unless
> I can call functions in the app code directly from the GLib. Is this
> possible?
Directly? Of course not -- half the point of a shared library is that
you don't yet know what the app looks like at the time you build the
shared library. A direct call would require (in this limited DSO
implementation) linking the app into the library.
John
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/