Lisp HUG Maillist Archive

How to pass a C array to foreign callable?

Hi there,

I am trying to pass an array of long signed ints from a dll to Lisp in  
order to have that filled. The callable looks like this:

(fli:define-foreign-callable ("FillBufferLisp" :result-type :void)
     ((buflen :int)
      (arr (:c-array (:signed :long))))
   (populate-farray buflen arr))

where buflen is the length of the array, and populate-farray populates the  
foreign array with data. The code is called from C like this:

(*fbl)(buflen, arr);

where *fbl is the pointer to the foreign callable and it appears to call  
lisp code just fine. However what happens when the callable is called is  
this error:

Error: The subscript 0 exceeds the limit -1 for the first dimension of the  
foreign-array #<Foreign-Array (:SIGNED :LONG) (0): addr #x04CB0020>.

It seems to me that the function expects the length of the array to be  
specified in the call (or definition?), but I cannot figure out how to do  
that. Or maybe it is something else. Any suggestions will be quite welcome.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: How to pass a C array to foreign callable?

On Sat, 07 Sep 2013 14:07:39 +0100, Yuri Davidovsky  
<yury.davidouski2@mail.dcu.ie> wrote:

> It seems to me that the function expects the length of the array to be  
> specified in the call (or definition?),

Apparently the length of the array has to be specified during the compile  
time of the callable, otherwise it seems that it assumes that the length  
of the array passed is 0. It does not seem to be possible to pass arrays  
with unknown lengths at runtime.

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:35 UTC