Subject: [clisp-list] AW: FFI crash: what am I missing?!

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Mon Aug 4 09:12:02 2003

Hi,

>what is the correct idiom for the C "unknown type array"?
>E.g., suppose
>        int* foo();
>will return the array of integers of size N, where N is the return
>value of another function
>        int foo_size();
>how do I express foo() and foo_size() in CLISP FFI?

>Suppose
>        int foo (int *size, int**arr);
>returns status and puts the length of the array into `size' and the
>pointer of the array into `arr'.
>what is the correct CLISP FFI idiom?

The latter case would have been covered by my (yet to be written) DEF-VARIABLE-CALL-OUT macro, which encapsulates this common scenario. I never found he time to implement that except for some notes one night I couldn't sleep.
Basically it's like in Haskell'FFI a size indication that's conveyed from one argument to another or to the return value.

Explicit management using WITH-FOREIGN-OBJECT and friends is involved. Maybe lookup all articles of mine on variable length arrays in clisp-list.

A longer answer may follow tomorrow, I need to go home now.

Regards,
	Jorg.

---

From: Sam Steingold <[email-masked]>
Date: Mon Aug 4 10:03:07 2003

> * In message <[email-masked]>
> * On the subject of "AW: FFI crash: what am I missing?!"
> * Sent on Mon, 4 Aug 2003 18:11:20 +0200
> * Honorable "Hoehle, Joerg-Cyril" <[email-masked]> writes:
>
> The latter case would have been covered by my (yet to be written)
> DEF-VARIABLE-CALL-OUT macro, which encapsulates this common
> scenario. I never found he time to implement that except for some
> notes one night I couldn't sleep.
> Basically it's like in Haskell'FFI a size indication that's conveyed
> from one argument to another or to the return value.

what if, as in the first example, the size is returned by a _different_
function?!

> Explicit management using WITH-FOREIGN-OBJECT and friends is
> involved.

any cast requires equal memory size.

        (with-foreign-object
             (ret `(c-array int ,(foo_size node))
                  (foo node))
           (print ret))

does not work.

c-array-max doesn't work because it expects to find a zero termination
and finds garbage instead.
is a C wrapper the only solution?

> A longer answer may follow tomorrow, I need to go home now.
biting my nails off :-)

--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Let us remember that ours is a nation of lawyers and order.