[gambit-list] Gambit C Interface (FFI)

Guillaume Cartier gcartier at jazzscheme.org
Sun Sep 16 18:15:59 EDT 2007


Help needed!
 
I am trying to understand Gambit's C interface and I have this very 
simple code to allocate a C structure that crashes and have no clue why. 
Anyone has any idea? (Gambit 4.0.0) (PS: sorry for the double post I 
forgot you had to post on a registered email else you're awaiting 
moderator approval)

With this function defined in my gambcini :
 
(define (C . rest)
  (let loop ((n (if (null? rest) 1 (car rest))))
    (if (> n 0)
        (begin
          (write n) (newline)
          (compile-file "c")
          (load "c")
          (make-S2)
          (loop (- n 1))))))
 
I run (C 50) maybe a couple times and always end up getting a random 
crash often the first time
 
File c.scm :

(c-declare
  "struct S2_
   {
    int x;
    int y;
   };
   typedef struct S2_ S2;"
   )

(c-define-type S2 (type "S2"))

(define make-S2
  (c-lambda () S2
    "___result_voidstar = calloc(1, sizeof(S2));"))




More information about the Gambit-list mailing list