[plt-scheme] ffi help

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Aug 23 18:07:32 EDT 2005

On Jul 26, Mike Miller wrote:
> I have a safe cvector of double values (or equivalently, an srfi-4  
> f64vector).  I'd like to pass it into the external C function:
> 
>     void cfunc (int alen, double *a);
> 
> and be able to modify values of a inside the C routine, and have the
> changes appear back on the Scheme side after returning from the
> function.

The cvector type, or the srfi-4 vectors should work fine for this.


> I tried to do the following, to no avail:
> 
>    (define cfunc (get-ffi-obj "cfunc" "myclib"
>                               (_fun _int _cvector -> _void)))

In this case it would be better to use the advanced features of
`_fun', and say that the first argument is always the cvector-length
of the second one.


> I also tried _f64vector instead of _cvector.  The error message I
> get is:
> 
>    procedure application: expected procedure, given: #f; arguments  
> were: #<struct:fun-syntax> #<syntax:54:36>
> 
> Earlier posters verified a bug exists with the foreign module.
> 
> However, can anyone suggest a workaround?

Yes, there is a yet-uncaught bug there.  You can put this code into
its own module, and require that from the rest of the program that
uses the foreign interface.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!



Posted on the users mailing list.