unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <matt.wette@gmail.com>
To: guile-user@gnu.org
Subject: Re: Guile dynamic FFI, C function expecting pointer
Date: Sun, 22 Nov 2020 16:16:47 -0800	[thread overview]
Message-ID: <da5a069d-d156-6f69-386e-50b9364c7a65@gmail.com> (raw)
In-Reply-To: <CACgrOxJKMmxKJVxbLj+ohdmp-jPq+g_u_N_R1K7yRtnE=YsN=Q@mail.gmail.com>



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 <obj>) 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.






      reply	other threads:[~2020-11-23  0:16 UTC|newest]

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

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=da5a069d-d156-6f69-386e-50b9364c7a65@gmail.com \
    --to=matt.wette@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).