From: ludo@gnu.org (Ludovic Courtès)
To: guile-user@gnu.org
Subject: Re: atexit in modules
Date: Thu, 13 Nov 2008 20:26:30 +0100 [thread overview]
Message-ID: <87wsf7whp5.fsf@gnu.org> (raw)
In-Reply-To: 677173.17745.qm@web37908.mail.mud.yahoo.com
Hello,
Mike Gran <spk121@yahoo.com> 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'.
next prev parent reply other threads:[~2008-11-13 19:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-13 5:59 atexit in modules Mike Gran
2008-11-13 19:26 ` Ludovic Courtès [this message]
2008-11-13 19:59 ` Mike Gran
2008-11-14 2:27 ` Mike Gran
2008-11-16 0:27 ` Neil Jerram
2008-11-16 3:26 ` Mike Gran
2008-11-17 0:00 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wsf7whp5.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).