unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* atexit in modules
@ 2008-11-13  5:59 Mike Gran
  2008-11-13 19:26 ` Ludovic Courtès
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Gran @ 2008-11-13  5:59 UTC (permalink / raw)
  To: Guile User

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").

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

I read this thread
http://thread.gmane.org/gmane.lisp.guile.user/6430/focus=6443

This suggests dynamic-wind is the way to go, but, I don't think it would work in my case because I want to keep this in a Guile wrapper module that gets loaded with use-module.

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.

But then I started think about what happens if the module is used in multiple threads, and it made my head hurt.

Any better ideas?

-Mike Gran





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-11-17  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-13  5:59 atexit in modules Mike Gran
2008-11-13 19:26 ` Ludovic Courtès
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

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).