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

From: Sam Steingold <[email-masked]>
Date: Mon Aug 4 08:11:04 2003

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?

this:

(def-call-out foo (:arguments) (:return-type (c-ptr-null int)))
(def-call-out foo_size (:arguments) (:return-type int))
(defun get-foo ()
  (let ((size (foo_size))
        (ptr (foo)))
    (ffi:cast ptr (c-array int size))))

shouldn't probably work (ptr is not a place, right?)

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?

(def-call-out foo
  (:arguments (size int :out) (arr (c-array-ptr int) :out))
  (:return-type int))
(defun get-foo ()
  (multiple-value-bind (status size arr) (foo)
    (when (zerop status)
      (ffi:cast arr (c-array int size)))))

same problem...

thanks!

--
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>
Someone has changed your life.  Save? (y/n)