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: atexit in modules Date: Wed, 12 Nov 2008 21:59:56 -0800 (PST) Message-ID: <677173.17745.qm@web37908.mail.mud.yahoo.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1226556023 6909 80.91.229.12 (13 Nov 2008 06:00:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Nov 2008 06:00:23 +0000 (UTC) To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Nov 13 07:01:16 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 1L0VGV-0008W7-Bl for guile-user@m.gmane.org; Thu, 13 Nov 2008 07:01:16 +0100 Original-Received: from localhost ([127.0.0.1]:56530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L0VFN-0007Qt-AI for guile-user@m.gmane.org; Thu, 13 Nov 2008 01:00:05 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L0VFI-0007QT-Eb for guile-user@gnu.org; Thu, 13 Nov 2008 01:00:00 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L0VFG-0007Pn-99 for guile-user@gnu.org; Thu, 13 Nov 2008 00:59:59 -0500 Original-Received: from [199.232.76.173] (port=35055 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L0VFG-0007Pk-2m for guile-user@gnu.org; Thu, 13 Nov 2008 00:59:58 -0500 Original-Received: from web37908.mail.mud.yahoo.com ([209.191.91.170]:33120) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1L0VFG-00013K-2H for guile-user@gnu.org; Thu, 13 Nov 2008 00:59:58 -0500 Original-Received: (qmail 17859 invoked by uid 60001); 13 Nov 2008 05:59:56 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Message-ID; b=4I9OVgtcUTtz1piJ3OB+JoeXqhtk4t8Io+jrTb1M1/oFtafVZQEKb7zV1F4s5SUFhgKA2vNFU7gbWFZ6aj/Ss5ZARBoZP+n3PZAfCdaudJ7mCVFhyi3QkqJMUkztmORkZsDMPJwAzQo7F/UbYs+uPVkijZjo3SWcOzFtDBVP51w=; X-YMail-OSG: EfsyFD0VM1nEUf6cXB71ZGw8BKUJLHkcniUAxtgHxUEHeZUS7X5n2aXdfYF9ngPyjZ.mDSPBVLCc4jErHTaeFGBBC..Uv3V80FSI0dm5xNX9xuL0qAL1HcJq61cgxDPu7eUbY.XXnr24XY86FwsAhePpRxg4H7cdHXrSoUzrzwuaJKfgikNCCZUnmQ-- Original-Received: from [69.227.189.37] by web37908.mail.mud.yahoo.com via HTTP; Wed, 12 Nov 2008 21:59:56 PST X-Mailer: YahooMailRC/1155.20 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:6896 Archived-At: 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