Subject: [clisp-list] FFI: variable size values

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Tue Aug 5 00:28:06 2003

Sam,

Your attempt IMHO is a misleaded attempt at interfacing, so I'll not comment it further.

For a solution to your interfacing problem, see my todays article "Re: FFI crash: what am I missing?!"

>the return vector buf happens to be 0-filled.
>on converting the first return vector element to a single-float, I get
>*** - floating point underflow

Really? Here I obtain
[55]> (with-c-var (x 'uint32 0) (cast x 'ffi:single-float))
0.0
[58]> (with-c-var (x 'uint64 0) (cast x 'ffi:double-float))
0.0d0

But I don't know what the (IEEE) floating-point representation of 0.0 is (i.e. whether it's all zero-bits, or if the mantissa must be something like #b10000000.
That means I don't know whether the above cast can be expected to work -- at least on machines where
(= (bitsizeof 'single-float) (bitsizeof 'uint32))
which CLISP checks inside the FFI:CAST operator.
or whether it can produce a FP-underflow, depending on FP settings.

Regards,
	Jorg Hohle.

---

From: Sam Steingold <[email-masked]>
Date: Tue Aug 5 09:42:02 2003

> * In message <[email-masked]>
> * On the subject of "FFI: variable size values"
> * Sent on Tue, 5 Aug 2003 09:27:14 +0200
> * Honorable "Hoehle, Joerg-Cyril" <[email-masked]> writes:
>

Jorg, __PLEASE__ do explain to me why I have to use the "garbage"
variable!!!

void* null_terminate (void *garbage, void *data, int size, int num_el) {
  static char buf[BUFSIZ];
  if (size*num_el>BUFSIZ) abort();
  memset(buf,0,BUFSIZ*sizeof(char));
  memcpy(buf,data,size*num_el);
  return buf;
}

(def-call-out null_terminate_float
  (:arguments (prob-vec c-pointer) (size int) (num int))
  (:return-type (c-array-max float #.MAX_STATE))
  (:name "null_terminate"))

why do I see "prob-vec" in "data" not in "garbage"??!!

-- 
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>
There is Truth, and its value is T.  Or just non-NIL.  So 0 is True!