guile-user
[Top][All Lists]
Advanced

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

Guile dynamic FFI, C function expecting pointer


From: Tim Meehan
Subject: Guile dynamic FFI, C function expecting pointer
Date: Sun, 22 Nov 2020 16:50:44 -0600

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

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