guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile dynamic FFI, C function expecting pointer


From: Matt Wette
Subject: Re: Guile dynamic FFI, C function expecting pointer
Date: Sun, 22 Nov 2020 16:16:47 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0



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 via email to

[Prev in Thread] Current Thread [Next in Thread]