guile-user
[Top][All Lists]
Advanced

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

Re: atexit in modules


From: Ludovic Courtès
Subject: Re: atexit in modules
Date: Thu, 13 Nov 2008 20:26:30 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux)

Hello,

Mike Gran <address@hidden> 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

[Prev in Thread] Current Thread [Next in Thread]