unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Tim Meehan <btmeehan@gmail.com>
To: guile-user@gnu.org
Subject: Guile dynamic FFI, C function expecting pointer
Date: Sun, 22 Nov 2020 16:50:44 -0600	[thread overview]
Message-ID: <CACgrOxJKMmxKJVxbLj+ohdmp-jPq+g_u_N_R1K7yRtnE=YsN=Q@mail.gmail.com> (raw)

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 :(


             reply	other threads:[~2020-11-22 22:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-22 22:50 Tim Meehan [this message]
2020-11-23  0:16 ` Guile dynamic FFI, C function expecting pointer Matt Wette

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACgrOxJKMmxKJVxbLj+ohdmp-jPq+g_u_N_R1K7yRtnE=YsN=Q@mail.gmail.com' \
    --to=btmeehan@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).