Re: g_intern_static_string() and modules
- From: "Brian J. Tarricone" <bjt23 cornell edu>
- To: gtk-devel-list gnome org
- Subject: Re: g_intern_static_string() and modules
- Date: Fri, 24 Feb 2006 19:38:29 -0800
-----BEGIN PGP SIGNED MESSAGE-----
Federico Mena Quintero wrote:
> Currently, we explicitly disallow the gtkfilesystemgnomevfs module from
> being unloaded because some dumb part of libgnomeui assumes that it is
> always in memory. I don't remember the exact problem right now, but
> finding it in the ChangeLog is left as an exercise for the reader.
> My question in particular is about g_intern_static_string(). If I'm
> a .so that is sometimes linked in, and sometimes dlopen()ed, how can I
> know whether I should use g_intern_static_string() or g_intern_string()?
> If I'm dlopen()ed, I can't intern a static string because it will cause
> trouble when I'm dlclose()d.
> The more general question, of course, is how to know when a library was
> loaded at runtime so that this problem can be avoided.
This may not be exactly what you're going for, and is not the most
elegant of solutions, but... If you can safely assume that everyone is
going to use the g_module_*() set of functions to load the module, you
could set a global flag in your g_module_check_init() function, which
will get called after the library is successfully g_module_open()ed.
Then check the value of this flag when deciding whether to use
g_intern_string() or g_intern_static_string().
I'm not sure if there's a similar bit of functionality with straight
dlopen(). The manpage doesn't seem to indicate anything aside from
_init() (which is listed as obsolete and not recommended), but I thought
that was called for a normal dynamic link/load as well. (?)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
-----END PGP SIGNATURE-----
] [Thread Prev