From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Kjetil S. Matheussen" Newsgroups: gmane.lisp.guile.user Subject: Re: Passing C pointers through guile Date: Sun, 06 Jul 2008 18:13:03 +0200 (CEST) Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7BIT X-Trace: ger.gmane.org 1215360920 5547 80.91.229.12 (6 Jul 2008 16:15:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 6 Jul 2008 16:15:20 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jul 06 18:16:07 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 1KFWuC-0000nb-5q for guile-user@m.gmane.org; Sun, 06 Jul 2008 18:16:04 +0200 Original-Received: from localhost ([127.0.0.1]:47831 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KFWtL-0005ju-4h for guile-user@m.gmane.org; Sun, 06 Jul 2008 12:15:11 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KFWtF-0005iN-Eu for guile-user@gnu.org; Sun, 06 Jul 2008 12:15:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KFWtD-0005gC-Ix for guile-user@gnu.org; Sun, 06 Jul 2008 12:15:05 -0400 Original-Received: from [199.232.76.173] (port=36321 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KFWtD-0005g7-Da for guile-user@gnu.org; Sun, 06 Jul 2008 12:15:03 -0400 Original-Received: from smtp.getmail.no ([84.208.20.33]:50445) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KFWt9-00089i-Qp for guile-user@gnu.org; Sun, 06 Jul 2008 12:15:00 -0400 Original-Received: from pmxchannel-daemon.no-osl-m323-srv-004-z2.isp.get.no by no-osl-m323-srv-004-z2.isp.get.no (Sun Java System Messaging Server 6.2-7.05 (built Sep 5 2006)) id <0K3L00K0JEGNS700@no-osl-m323-srv-004-z2.isp.get.no> for guile-user@gnu.org; Sun, 06 Jul 2008 18:14:47 +0200 (CEST) Original-Received: from smtp.getmail.no ([10.5.16.1]) by no-osl-m323-srv-004-z2.isp.get.no (Sun Java System Messaging Server 6.2-7.05 (built Sep 5 2006)) with ESMTP id <0K3L00EG8EDV5070@no-osl-m323-srv-004-z2.isp.get.no> for guile-user@gnu.org; Sun, 06 Jul 2008 18:13:07 +0200 (CEST) Original-Received: from cm-84.215.136.96.getinternet.no ([84.215.136.96]) by no-osl-m323-srv-004-z1.isp.get.no (Sun Java System Messaging Server 6.2-7.05 (built Sep 5 2006)) with ESMTP id <0K3L00EHGEDVUJJ0@no-osl-m323-srv-004-z1.isp.get.no> for guile-user@gnu.org; Sun, 06 Jul 2008 18:13:07 +0200 (CEST) In-reply-to: X-X-Sender: kjetil@ttleush X-detected-kernel: by monty-python.gnu.org: Solaris 10 (beta) 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:6630 Archived-At: Ludovic Court?s: > Hi, > > "Maciek Godek" writes: > >> is there any portable and recommended way for passing C pointers around >> in guile environment? >> I think of something like scm_to_ptr (analogous to scm_to_int etc.). >> Certainly such a value would be completely useless for the interpreter. >> One can achieve simillar functionality using the aforementioned >> scm_to_int (keeping track on the word length of the build target), >> but it seems rather unnatural. > > If the goal is to make a C object pointed to by some pointer available > to Scheme functions, the recommended (and simplest) way is to use a > "SMOB" (see the manual for details). In practice, SMOBs incur some > storage overhead because they hold 4 machines words, while you may only > need one. > > Another possibility is to use a "uo" field in a struct: it allows you to > have a struct field holding a machine word inaccessible to Scheme > functions (see the "Vtables" node of the manual). > I haven't heard of the "uo" field before, but at least using a SMOB is really inconvenient, and using an unsigned long for storing pointers is really convenient. (BTW. How does swig and gwrap handle pointers?) I agree with Maciek that it would at least be mind-comforting to have functions like scm_to_ptr/etc, although not strictly necessary, since using integers works just fine.