Re: SEGV when dlopen()ing Gnome code
- From: Samuel Hocevar <sam zoy org>
- To: gnome-devel-list gnome org
- Subject: Re: SEGV when dlopen()ing Gnome code
- Date: Sat, 10 Feb 2001 08:12:54 +0100
On Sat, Feb 10, 2001, Havoc Pennington wrote:
> Yes, you can't expect dlopen()'ing an arbitrary library or application
> to work. ;-)
Well, I just figured that :-)
> There can be all sorts of stuff that gets set up that
> depends on the lib/app code remaining loaded into the process.
>
> I would imagine there are literally several thousand aspects of
> glib/gtk/gnome-libs that break if you unload the library. They just
> aren't designed for it.
I do not really agree -- exiting from an application shouldn't be
very different from unloading a shared object. The only difference here
is the atexit() callbacks. Actually, both gtk and gdk call g_atexit() to
register stuff that is to be called on application exit.
This may be a practical way to do things, because one doesn't have to
bother where data is unallocated, but it looks awful to me. I'd rather
have these callbacks called at the end of gtk_main() or gnome_main().
For those interested, I found a workaround. It's absolutely ugly,
and I don't recommend reading the next few sentences to people with
epilepsy or heart problems. I export a function called g_atexit in my
code, which stores the gtk and gdk callbacks in a private structure
instead of calling atexit(). When dlopen()ing the shared object, my
g_atexit symbol is resolved before Glib's one, which means that when
calling gnome_init(), my private g_atexit is called. Then I call these
stored callbacks just after gtk_main() has finished. The library can
eventually be safely dlclosed().
Well, at least my application doesn't segfault on exit anymore and
now loads and unloads its Gnome interface on request. But I agree this
is rather kludgey.
Regards,
Sam.
--
Samuel Hocevar <sam zoy org> <http://sam.zoy.org/>
for DVDs in Linux screw the MPAA and ; do dig $DVDs.z.zoy.org ; done | \
perl -ne 's/\.//g; print pack("H224",$1) if(/^x([^z]*)/)' | gunzip
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]