From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mike Gran Newsgroups: gmane.lisp.guile.user Subject: Re: atexit in modules Date: Sat, 15 Nov 2008 19:26:14 -0800 (PST) Message-ID: <848430.74300.qm@web37904.mail.mud.yahoo.com> References: <677173.17745.qm@web37908.mail.mud.yahoo.com> <87wsf7whp5.fsf@gnu.org> <112113.55870.qm@web37908.mail.mud.yahoo.com> <119596.13840.qm@web37907.mail.mud.yahoo.com> <49dd78620811151627v3b34306if0c8e39022e83ad5@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1226805993 10775 80.91.229.12 (16 Nov 2008 03:26:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 16 Nov 2008 03:26:33 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Nov 16 04:27:35 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L1YIP-0002QE-46 for guile-user@m.gmane.org; Sun, 16 Nov 2008 04:27:33 +0100 Original-Received: from localhost ([127.0.0.1]:32904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L1YHG-0006N1-PV for guile-user@m.gmane.org; Sat, 15 Nov 2008 22:26:22 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L1YHC-0006Mw-CA for guile-user@gnu.org; Sat, 15 Nov 2008 22:26:18 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L1YHA-0006Mk-1A for guile-user@gnu.org; Sat, 15 Nov 2008 22:26:17 -0500 Original-Received: from [199.232.76.173] (port=47931 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L1YH9-0006Mh-Q2 for guile-user@gnu.org; Sat, 15 Nov 2008 22:26:15 -0500 Original-Received: from web37904.mail.mud.yahoo.com ([209.191.91.166]:26730) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1L1YH9-0002nI-La for guile-user@gnu.org; Sat, 15 Nov 2008 22:26:15 -0500 Original-Received: (qmail 74913 invoked by uid 60001); 16 Nov 2008 03:26:14 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:References:Date:From:Subject:To:MIME-Version:Content-Type:Message-ID; b=6LTvM4wTi3sIe9IcVXaG7urYHnQRcO2y3hbSXhAtZd6dXylIKBbsB3ceRtWY9Uk7rwsuLYBk2J814cTb6ix190qEUQRyse7+zyWt0mObLle12uC55N/sC5PZlmhHE2R29+wQn71RIjiqLAGt6R0qQAzlauC8vPAjchh5pMg9c88=; X-YMail-OSG: BhI8V5QVM1kDh1pFWpxI6VmC.Uq.ZpvtZ.e1mAdrOR6q.fWydxu2qtZAWl71ZEDVvpO4l8AEKiq4_7GZGwPl5ahsfUaF8IFBxeea1lhS6ralGA2JKcSINHCm_yQfbJ_sbgp3nJwj7CRpW29GpkNZFwN2thQjhgiAEDxJnIo3z_Smv8TQl9wk2NHX3g-- Original-Received: from [69.227.178.150] by web37904.mail.mud.yahoo.com via HTTP; Sat, 15 Nov 2008 19:26:14 PST X-Mailer: YahooMailRC/1155.29 YahooMailWebService/0.7.260.1 X-detected-operating-system: by monty-python.gnu.org: FreeBSD 6.x (1) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6923 Archived-At: > 2008/11/14 Mike Gran : > > > > So I'm back to the idea of creating a module-level variable that exists while > > the module is in memory, and then calling library_end() when that variable is > > GC'd. But I can make it more schemey by using guardians and after-gc-hook as > >you suggested. > > But are modules ever unloaded? I thought not. Everything I said above is nonsense. I tried four things, and the last one works fine. Here's a review. I had a scheme module that wrapped a C library that required calls to a library_init() and library_end() function pair that allocated and freed global data. Idea 1 was to wrap as library_init() as a scheme function that gets called when the scheme module is loaded, and then wrap library_end() as a scheme function that gets called when the module is unloaded. But, modules are never unloaded. Idea 2 was to wrap library_init() as above, and then wrap library_end() as a scheme function that gets called when Guile exits. But, there is no such hook as far as I know for non-REPL Guile scripts. Idea 3 was some nonsense idea that I could catch a module variable as it was being garbage collected and use this as the trigger to call library_end(). Ignore everything I said about that. Idea 4: So ultimately I went with this. The C function library_init() gets called in init_foo() in the call to (load-extension "libfoo.so" "init_foo"). The C function library_end() gets registered using the libc atexit() during the same call to init_foo(). That works fine. -Mike Gran