From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: Re: Guile dynamic FFI, C function expecting pointer Date: Sun, 22 Nov 2020 16:16:47 -0800 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33438"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon Nov 23 01:17:12 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kgzXc-0008bi-27 for guile-user@m.gmane-mx.org; Mon, 23 Nov 2020 01:17:12 +0100 Original-Received: from localhost ([::1]:49148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgzXa-0006df-UB for guile-user@m.gmane-mx.org; Sun, 22 Nov 2020 19:17:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgzXJ-0006dU-Du for guile-user@gnu.org; Sun, 22 Nov 2020 19:16:53 -0500 Original-Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:36180) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kgzXG-00083T-Tv for guile-user@gnu.org; Sun, 22 Nov 2020 19:16:53 -0500 Original-Received: by mail-pg1-x52d.google.com with SMTP id t21so12632320pgl.3 for ; Sun, 22 Nov 2020 16:16:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=cGyjba/BJAmvuEMopb1rJ2foLNADIEutkaHkbO4/20s=; b=Jbk6enkAv+kRP2wDW2+ndeI1xjsmSCGDQhgabdfo58GdvWy6ZD9ayHJYyukZGuS9mT YwK2VTRFRh5r0hBmW1FqM+L8b9n1mjA/2iU4qZVV3NLKJtP1TSNbDSoWdYH2l3ispKJk BsHCGcr2+ZKhjQAa4vvR2qw5th2xuatQOg0vW9Gk39beKl4wTaQlBznG3YX1gSvxRbbu mY1brzkgkQhMXUurFPF4vVVpPP2jUL9czTXfRWPYKti/KVBkTT5v5x/uMil8PTLF6VTw L8dLZZE21AX6u7JbX6jUKTB0b4OJ78Dvm9HavepKbuamUc+QRWjitqYBK7eBJJ7xomMN VUpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=cGyjba/BJAmvuEMopb1rJ2foLNADIEutkaHkbO4/20s=; b=LkkFM8baDFqSPOe7BmXUQOjKstXEE/ezIRmSDh1m+MF3wKr9vdqC3zCaaY7sJpx+W8 4Ezl4RpunvxaYH7jTjJ8JJE3Z8kbKhxG6Z8G5+BOIqspAETmZJ6B4olmerSsfs5ruVz2 /gyQSTubuF7orlvtUTXOzA+jt8H6DheLuWNdI29W1PFa2wkwYlKwZbCETLz76H3uJiDo h+xQuEhpEM+KHJiBnRlZprFBtT6l/IEEOo/U/HvFtw1QWWWI51hjYI40ckiGb+z6rAhP Bv11a/9r5NJhzf8K5XvQsJhgsJrrbZ95H+2vnFzehEdywUXJ4+Y5UqwnIeoO32+VlDAB G3lA== X-Gm-Message-State: AOAM532jBgfg85L+i2LHAZuoPyF9es56jx9/EPfhh1Rq+9nS+n66fmT1 BCQb5o0h+0EAWX+8ViqYaOZh7bV45EA= X-Google-Smtp-Source: ABdhPJyHBTpClmuehnzfS9vpjLsr3kLOFEfgO92fZmFZcpFI9uxYSLz00bWmokDh00m5U4cx9meEHw== X-Received: by 2002:a05:6a00:78d:b029:18b:f46:5262 with SMTP id g13-20020a056a00078db029018b0f465262mr23702246pfu.74.1606090609103; Sun, 22 Nov 2020 16:16:49 -0800 (PST) Original-Received: from [192.168.2.183] (64-52-176-132.championbroadband.com. [64.52.176.132]) by smtp.gmail.com with ESMTPSA id r130sm2723813pfc.41.2020.11.22.16.16.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Nov 2020 16:16:48 -0800 (PST) In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=matt.wette@gmail.com; helo=mail-pg1-x52d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17044 Archived-At: On 11/22/20 2:50 PM, Tim Meehan wrote: > I tried to boil this question down to the most simple thing that > represented what I needed to understand. I have had luck getting C > functions that expect arguments "by value," but "by reference" has been > problematic. > > The failure mode is "Segmentation Fault," so I gather that I may not be > using the right Guile call at all. > > The Guile user manual is usually quite excellent, but I seem to be missing > something important. > > Thanks, > > ;;----------------------------------------------------------------------------;; > ;; C source for "libstuff.so": > ;; file stuff.c, compiled as: > ;; gcc stuff.c -o libstuff.so -fPIC -shared > #| > void int_ptr_example1(int *a) { > *a = 5; > } > |# You'll need to make-bytevector a bytevector that holds sizeof(int) bytes. Then pass (bytevector->pointer ) as the argument. (let ((obj (make-bytevector (sizeof int))))   (int-ptr-example (bytevector->pointer obj))) Now the 5 should be in the bytevector.  You will need to extract it.