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: dynamic foreign function interface Date: Tue, 26 Jan 2010 23:06:07 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1264544095 29895 80.91.229.12 (26 Jan 2010 22:14:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Jan 2010 22:14:55 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Jan 26 23:14:47 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 1NZtgN-0007PI-EQ for guile-devel@m.gmane.org; Tue, 26 Jan 2010 23:14:47 +0100 Original-Received: from localhost ([127.0.0.1]:41944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZtgO-0007Bs-AD for guile-devel@m.gmane.org; Tue, 26 Jan 2010 17:14:48 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZtWp-0000Fq-R5 for guile-devel@gnu.org; Tue, 26 Jan 2010 17:04:55 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZtWl-0000BL-2j for guile-devel@gnu.org; Tue, 26 Jan 2010 17:04:55 -0500 Original-Received: from [199.232.76.173] (port=42286 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZtWk-0000BD-QT for guile-devel@gnu.org; Tue, 26 Jan 2010 17:04:50 -0500 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:65197 helo=sasl.smtp.pobox.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NZtWk-0000jn-EU for guile-devel@gnu.org; Tue, 26 Jan 2010 17:04:50 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id E62C294F89 for ; Tue, 26 Jan 2010 17:04:47 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:mime-version:content-type; s=sasl; bh=Y fWZprLtWvUAaxv6qaZ9YnkjocU=; b=QoQcjvexeb4WhxZFiM5X0iqeYPjpg9WcV BQGGzGHIDAGHLaYdeqLHOXBz/vo4dUaPhn78AUQcbssfTLqATGd5N/fRgCGBsC3n N3E0fp0z/arpiWB2Ri1es0UPeX7Gd//r23+hBEIVtuYoxGtIvPaxw5H5ru4I1BtK COsYPTN+48= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:mime-version:content-type; q=dns; s=sasl; b=BmY yuMTk2ybr58ICc9EYrRN7yMwsFGgvxsbQKwsNMnsa749OwIWAzXoXJsQB6DEDNKT Oh0/YV/Sb7Y6VUv6hqwxTM5zULJS6E82zlZi4D4Dl0SLYRRkVfH6r/sKR2ZHv+n7 MEYx+ohIkVXEMBNpTh59kAyf1p2D03eLwL7P3hjw= Original-Received: from a-pb-sasl-quonix. (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id E3B6094F88 for ; Tue, 26 Jan 2010 17:04:47 -0500 (EST) Original-Received: from unquote (unknown [81.38.187.11]) (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 41D0394F85 for ; Tue, 26 Jan 2010 17:04:46 -0500 (EST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) X-Pobox-Relay-ID: D1802450-0AC6-11DF-8847-6AF7ED7EF46B-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:9930 Archived-At: Hey all, I just finished up some work to make a dynamic foreign function interface. This is on the wip-ffi branch. By "dynamic", I mean that you don't have to write C and compile it; you can do everything at runtime from Scheme. You use dynamic-func and dynamic-link to get the raw function pointer, and make-foreign-function to turn that function pointer into a Scheme procedure. The interface is very low-level. Obviously declaring that an arbitrary symbol resolved via `dlsym' is of a certain function type is an unsafe operation that can lead to crashes. Apart from that typing problem, you have pointer and struct types. If you say that the function takes an int8, Guile will ensure that it can make an int8; but if you say that the function takes a pointer or a by-value struct, Guile will only ensure that the arg is a "foreign" (from foreign.[ch]) pointer, only checking lengths in the case that it's a struct of known length. The intention is to provide an expressive Scheme layer, on top of which any safety constructs can be built as needed. I would merge it now, except for the fact that it depends on libffi. Libffi is very portable, and probably exists for all of Guile's architectures, but it is an extra dependency. Should we require libffi in Guile 1.9.8? Or should we build the necessary pieces conditionally? Let me know, Andy -- http://wingolog.org/