From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: Compilation and load-extension Date: Sun, 03 Jan 2010 11:25:16 +0100 Message-ID: References: <2e6d10880912180044j6bccf95cjdad0dc6a931c9d5f@mail.gmail.com> <877hskk3kd.fsf@gnu.org> <2e6d10880912180223q7b640151j9427c0648144dbe7@mail.gmail.com> <87my1ginbx.fsf@gnu.org> <2e6d10880912180522w64df75e1i9c9c616fc220ed40@mail.gmail.com> <2e6d10880912300727u4f996a5ax9f26a123fb47c46f@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 1262514269 4151 80.91.229.12 (3 Jan 2010 10:24:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 3 Jan 2010 10:24:29 +0000 (UTC) Cc: guile-devel@gnu.org To: Tristan Colgate Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jan 03 11:24:22 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NRNdE-0006h5-TZ for guile-devel@m.gmane.org; Sun, 03 Jan 2010 11:24:21 +0100 Original-Received: from localhost ([127.0.0.1]:43883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NRNdF-00055x-4G for guile-devel@m.gmane.org; Sun, 03 Jan 2010 05:24:21 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NRNdB-00055g-88 for guile-devel@gnu.org; Sun, 03 Jan 2010 05:24:17 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NRNd5-00054x-Ec for guile-devel@gnu.org; Sun, 03 Jan 2010 05:24:15 -0500 Original-Received: from [199.232.76.173] (port=40198 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NRNd5-00054t-7M for guile-devel@gnu.org; Sun, 03 Jan 2010 05:24:11 -0500 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:57528 helo=sasl.smtp.pobox.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NRNd4-0003Pg-RA for guile-devel@gnu.org; Sun, 03 Jan 2010 05:24:10 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 2F8428D126; Sun, 3 Jan 2010 05:24:10 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=klGav00PcOPzAT/lPfBVeSKSc5k=; b=F2jAsW ELj0cJtX5WK5cGn/rwE5Y5iTpioD/C2f1rd1vu3vKFxk4qBl79IJATzUNUO/5Yl+ ULwSES0LbNMImhxZdLqV1N1XZcMiInV5EV/sMnOArNNPJNVwKoXWAiUhBTScSrxc V7Ed1aLT+qbSA+WAdZU9OekuBPEk60znb6Ogs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=xetPpjldN/spzvm6qnkK8+oX/Ki9Ghar uPNUuSm2X5kak9wXV8MjLuWr0/g8Ug0ueJ5wZ++WlOATjzHfdUAOLvRno+bdzRjR RZ3CkSxpSWp59iZG6OPlKrr3SctVLLs21hLkwnucOn4eSXC2CPyS2XzAe4WyqD5H Eaezv7AjNHU= Original-Received: from a-pb-sasl-quonix. (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 5D6018D124; Sun, 3 Jan 2010 05:24:06 -0500 (EST) Original-Received: from unquote (unknown [82.123.112.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id B498D8D123; Sun, 3 Jan 2010 05:24:04 -0500 (EST) In-Reply-To: <2e6d10880912300727u4f996a5ax9f26a123fb47c46f@mail.gmail.com> (Tristan Colgate's message of "Wed, 30 Dec 2009 15:27:14 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) X-Pobox-Relay-ID: 1F478F3E-F852-11DE-B5DF-9D59EE7EF46B-02397024!a-pb-sasl-quonix.pobox.com X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:9815 Archived-At: Hi Tristan, On Wed 30 Dec 2009 16:27, Tristan Colgate writes: > 2009/12/28 Andy Wingo : >> I can't see how this is happening, though I am sure it is indeed >> happening for you :) Can you put a tarball up somewhere so that we can >> have a look at it? > > I've created a stripped down module that uses that same style as the > swig ones and attached it to the following > bug report > > http://savannah.gnu.org/bugs/index.php?28442 Thanks for the test case. Here's dir/mymodule.scm: (define-module (dir mymodule)) (load-extension "test-module.so" "scm_init_my_module") (use-modules ((dir mymodule-prim) :renamer (symbol-prefix-proc 'primitive:))) What happens when Guile tries to compile this file is that the forms are expanded one by one, then compiled all together. Since expanders are written in Scheme they can do any computation -- and indeed we have `define-module' and `use-modules' hooked up to define and import modules at expansion-time as well as when you load the compiled file (load-time). But the problem is that the load-extension form is just a function call, not a macro, so it's not going to cause any code to run at expand-time. Specifically it will not cause the extension to be loaded at expand time, so later when you try to use (dir mymodule-prim) Guile rightly complains about there being no such module. Guile then switches to the interpreter, after compilation failed -- and since the interpreter evaluates each form after expanding it, indeed the extension does get loaded in time for the use-modules to see it. The solution is to enclose the (load-extension ...) in an eval-when: (eval-when (eval load compile) (load-extension "test-module.so" "scm_init_my_module")) This ensures that the primitives module gets defined at compile-time. See also the NEWS section entitled, "Functions needed by macros at expand-time need to be present at expand-time.". If this code is generated by SWIG, as you had mentioned before, please let the SWIG maintainers know about this issue, and point them to this message. Regards, Andy -- http://wingolog.org/