[gambit-list] FFI and scheme-object

Diogo F. S. Ramos diogofsr at gmail.com
Tue Apr 5 01:23:20 EDT 2011


Hello all,

I'm trying to get my way around the FFI interface but I am a little
lost.

I'm creating a list with scheme and I want to retrieve a piece of it
from C, but I'm receiving a segfault.

I was looking around the examples from the distribution and I found
(##still-copy), which made my code work, but I don't know why, and I
couldn't find any mention of it inside the manual.

Here is my scheme code (foo.scm):
;;;
(c-define (make-book title author) (char-string char-string) scheme-object "make_book" ""
          (list title author))

(c-define (get-title book) (scheme-object) char-string "get_title" ""
          (car book))
(c-define (get-author book) (scheme-object) char-string "get_author" ""
          (cadr book))

((c-lambda () void "f"))
;;;

And here is my C code (bar.c):
/**/
#define ___VERSION 406001

#include <gambit.h>

void f()
{
    ___SCMOBJ newbook = make_book("foo", "bar");

    get_title(newbook);
}
/**/

I'm compiling with:

gsc -o baz -exe bar.c foo.scm

-- 
Diogo F. S. Ramos



More information about the Gambit-list mailing list