Re: g_intern_static_string() and modules



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Federico Mena Quintero wrote:
> Hi,
> 
> 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()[1] 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.  (?)

	-brian

[1]http://developer.gnome.org/doc/API/2.0/glib/glib-Dynamic-Loading-of-Modules.html#GModuleCheckInit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD/9E06XyW6VEeAnsRAluzAKDiKu0hWtPMsG18IPxkoi1OFLbRGACgqMcs
K2pOaRp/FpE/UpDjPrvNaXY=
=ZrM3
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]