[racket] FFI crashing Racket

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Oct 12 09:03:20 EDT 2014

I wasn't able to provoke a crash with your example on my machine, but
try dropping `_void` from `(_cpointer _void)`.

A type passed to `_cpointer` isn't the type of data that the pointer
references. It's the representation of the pointer itself (so that you
can pick NULL and GC handling, for example). I think that `_cpointer`
should probably have raised on error for a non-pointer type like
`_void`.

At Fri, 10 Oct 2014 18:38:19 +0200, Adriaan Leijnse wrote:
> I'm trying to make use of Clang's C-API, but I might be missing
> something in getting it to work with the FFI. Here's a C-program which
> runs fine after compilation with "clang -o test test.c -lclang
> -L/usr/lib/llvm-3.4/lib":
> 
> 
> #include <stdio.h>
> 
> typedef void *CXIndex;
> extern CXIndex clang_createIndex(int, int);
> 
> int main() {
>   clang_createIndex(0, 0);
>   return 0;
> }
> 
> 
> However, running the following Racket program results in a crash
> (probably a segfault but Racket just prints "aborted").
> 
> 
> #lang racket
> 
> (require ffi/unsafe
>          ffi/unsafe/define)
> 
> (define libclang (ffi-lib "libclang"
>                           #:global? #t
>                           #:get-lib-dirs (λ _ '("/usr/lib/llvm-3.4/lib"))))
> 
> (define-ffi-definer defclang libclang)
> 
> (define _CXIndex (_cpointer _void))
> 
> (defclang clang_createIndex
>   (_fun _int _int -> _CXIndex))
> 
> (clang_createIndex 0 0)
> 
> 
> These programs look identical to me and I haven't had problems like
> this using the FFI before, so I'm at a loss here. Any pointers?
> 
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users


Posted on the users mailing list.