chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Help with foreign-lambda


From: Hans Bulfone
Subject: Re: [Chicken-users] Help with foreign-lambda
Date: Tue, 16 May 2006 16:49:29 +0200
User-agent: Mutt/1.5.9i

hi,

On Mon, May 15, 2006 at 11:59:09PM -0400, Jim Miller wrote:
> I'm trying to least expensive way to wrap a C function into scheme.  The
> following is the C interface to the function I need:
> 
> typedef long int integer;
> typedef float real;
> 
> int gtd6_(integer *iyd, real *sec, real *alt, real *glat, real *glong, real
> *stl, real *f107a, real *f107, real *ap, integer *mass, real *d__, real *t);
> 
> (Its actually a fortran function so the pointers to the function are not my
> choice)
> 
> The first 10 arguments (iyd - mass) are actually pointers to single values.
> The final two must be pointers to arrays.  d must be capable of holding 8
> elements while t must be capable of 2.
> 
> [...]
> 
> when I run the program I get the error:
> Error: bad argument type - not a pointer: 138
> 
> So my questions are
> 
> a) If I have to pass a pointer to an allocated array of memory in the C
> function am I doing this correctly when I use the make-f32vector function?
> I'm not sure if this is where the error is occurring but it seems like its
> the only place that it could?

the error occurs because c-pointer objects are expected as
arguments to gtd6.  you can use let-location to make c-pointer
objects pointing to scheme data.  imho the following should work:

(define gtd6
  (foreign-lambda integer "gtd6_"
                  (nonnull-c-pointer integer)
                  (nonnull-c-pointer float)
                  (nonnull-c-pointer float)
                  (nonnull-c-pointer float)
                  (nonnull-c-pointer float)
                  (nonnull-c-pointer float)
                  (nonnull-c-pointer float)
                  (nonnull-c-pointer float)
                  (nonnull-c-pointer float)
                  (nonnull-c-pointer integer)
                  nonnull-f32vector
                  nonnull-f32vector))

(let-location
    ([iyd   integer 138]
     [sec   float   345.0]
     [lat   float   50.0]
     [alt   float   100.0]
     [lon   float   50.0]
     [stl   float   100.0]
     [f107a float   150.0]
     [f107  float   150.0]
     [ap    float   8.0]
     [mass  integer 48])
  (let ([d (make-f32vector 8)]
        [t (make-f32vector 2)])
    (gtd6 #$iyd #$sec #$alt #$lat #$lon #$stl #$f107a #$f107 #$ap #$mass d t)))


regards,
hans.




reply via email to

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