Hello,

Mike Gran <[EMAIL PROTECTED]> writes:

> I have a C library that I wrapped as gsubrs that get put into a Guile
> module.  The C library wants a library_init() function called when it
> is initialized and a library_end() function called when it taken down.
>
> (for the curious, it is specifically mysql_library_init() and
> mysql_library_end().)
>
> The library_init() call is easy because it can be called automatically
> in the initialization function called by (load-extension "libfoo.so"
> "foo_init").

In theory, the Right Way(tm) would be to register a finalizer for the
module that does `load-extension'.  That can be done using a guardian,
but the guardian the needs to be called once in a while, e.g., in
`after-gc-hook' and `exit-hook'.

> Since libraries are never unloaded, I guess I can wait until the
> program exit to call library_end().

Well, yes.  :-)

Then `exit-hook' should do the job, no?

> I've got one crazy idea.  I could create a new special SMOB type which
> calls library_end() as part of the SMOB's free function.  When the
> Guile library is loaded, it will define a single variable of that type
> in the module's environment.

The guardian suggestion above achieves that, but slightly more
elegantly.  :-)

Thanks,
Ludo'.



Reply via email to