From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tim Meehan Newsgroups: gmane.lisp.guile.user Subject: Guile dynamic FFI, C function expecting pointer Date: Sun, 22 Nov 2020 16:50:44 -0600 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="594"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Nov 22 23:51:29 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 1kgyCf-000AaE-Jp for guile-user@m.gmane-mx.org; Sun, 22 Nov 2020 23:51:29 +0100 Original-Received: from localhost ([::1]:53454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kgyCe-0008Vc-F0 for guile-user@m.gmane-mx.org; Sun, 22 Nov 2020 17:51:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kgyCA-0008Uh-E5 for guile-user@gnu.org; Sun, 22 Nov 2020 17:50:58 -0500 Original-Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:32987) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kgyC8-0005mN-Eb for guile-user@gnu.org; Sun, 22 Nov 2020 17:50:58 -0500 Original-Received: by mail-qk1-x72a.google.com with SMTP id l2so15097974qkf.0 for ; Sun, 22 Nov 2020 14:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=ZYy5YJVxJ8xXm2O3fyrFxiI82PWnsPohKIZ05c3aork=; b=C/CQuA6eN0zpXwUhOrwQG/FUPfLo35fWgUOLnkDsODHsCS5VW6Oilf0T1lg7qyRiPe 2Zbg3Jqoi2SX7N4tvFLMr80XMZMuxnO9bcgo85lkHGO6Hm+Q6R3f8rz2h31bqDoqzPcO GhV4LkA8mJpYcSDDEQ3LlQsIGD/d8DFL+l867k6xamqe9SmUPi+JOejwiC//AxiDdL/+ PswYqpHr+cz+RChb9K/5whAJB4VuMDm5T0j8+RVvWIdwAxHEEwNUN8G6NOUXFdDIKcg8 gAKt3yFuek0oM5SjB835vlUhCVM2/LXpzgJMOXjEnIAucV7wIH/WbEpi17poMn+bUH+U Ub8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ZYy5YJVxJ8xXm2O3fyrFxiI82PWnsPohKIZ05c3aork=; b=KMj0FW6JCKtuJeBnDWs9/kWS53WpMy1bbBFUXzepqiCRRCp5DniiITe/yw1vGGawov PhwrspTTPF1crow66v5WpTwg+MyFVNubXpMSLS59Hg8waePaejXfS2qnYxEdisS5JxPu uD0T+ZbITXWduKYA4bCkM0lRbKji5uf9mbVY8VX58oDTIGSgUmflTPv1aUirBXnPVGfI aPKjuS3POlYma7wPAGkzy6waF7QooKHsOopt0RQ1BLw3M51aUilsZ42YHs0Y3G30uRXh PXzHd953yqrvSoOxbDzNgC6dJ+bs4twPExnXk6FqtatcfXUIToZhpzGyocCu+mwembrG 8TxQ== X-Gm-Message-State: AOAM533wKNHcKEtpoiB7CZ01CJHDiFr5uCMYxQWWNanjqI4R8N/0SK0C s39Qim8l/1BQiB2sP4952tOQlJ6bHF1m1j3oJ5OmwDyV2L4= X-Google-Smtp-Source: ABdhPJzmrcAIVb/TEL7MKaIX7UK/F8Mrh3w1HYTKeDTvZV+b8cIsCHNcRa9xdRdI+6kW9LId4RSqvFmucePJKQmNipk= X-Received: by 2002:a37:634a:: with SMTP id x71mr27575417qkb.51.1606085455102; Sun, 22 Nov 2020 14:50:55 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=btmeehan@gmail.com; helo=mail-qk1-x72a.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, HTML_MESSAGE=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-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:17041 Archived-At: 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; } |# ;;----------------------------------------------------------------------------;; ;; Test loading and using the library. (use-modules (system foreign)) (define libstuff (dynamic-link "./libstuff.so")) (define int-ptr-example1 (pointer->procedure void (dynamic-func "int_ptr_example1" libstuff) (list '*))) ;; Following: ;; https://nalaginrut.com/archives/2015/03/27/do-some-quick-and-dirty-with-guile-ffi (let ([a %null-pointer]) (int-ptr-example1 a) (display a) (newline)) ;;----------------------------------------------------------------------------;; ;; Sadly, when it runs, I get a segmentation fault at the call to ;; int-ptr-example1 :(