Subject: [clisp-list] FFI questions about "C" unions

From: "John K. Hinsdale" <[email-masked]>
Date: Sun Dec 14 05:11:00 2003

I'm interfacing w/ a library (the Java "C" interface actually) that
uses a C "union" type.  E.g. to paraphrase its header file:

/* Simplified example from <jni.h> */
typedef union jvalue {
  x int;
  f float;
  d double;
} jvalue;

Now, I would like to pass these (and arrays of them) to and from my
Lisp and "C" code.  I know how to do this with structs: use say

   DEF-C-STRUCT foo (member1 <type) ...

and then you get Lisp accessors FOO-MEMBER1 defined.

There doesn't seem to be a DEF-C-UNION that accepts a "C" declaration
tag like a structure.  In "C" unions are just like structs except for
the storage overlap and that only one member can be used.  Is there
some reason I cannot do this in CLISP?

My workaround is that I can define a CLISP c-struct and pass that to
and from "C" but I will be wasting a bit of space doing so, esp.  if
my arrays are large.  But I don't mind doing that.

Any hints appreciated.  Are there any examples of CLISP interfacing to
"C" code that uses unions?

---
John Hinsdale, Alma Mater Software, Inc., Tarrytown, NY 10591-3710 USA
[email-masked] | http://www.alma.com/staff/hin | +1 914 631 4690

---

From: Sam Steingold <[email-masked]>
Date: Sun Dec 14 08:38:01 2003

> * John K. Hinsdale <[email-masked]> [2003-12-14 08:10:03 -0500]:
>

(c-union (d double-float) (f single-float) (x int))

note that the first slot should be the largest.

> tag like a structure.

<http://clisp.cons.org/impnotes/dffi.html#c-union>
<http://clisp.cons.org/impnotes/dffi.html#ffi-struct-arg>
<http://article.gmane.org/gmane.lisp.clisp.devel/10089>

disclaimer: the only purpose of this message is to bring the question
            to the attention of the experts (Bruno & Joerg).
All information herein should be assumed false unless proved otherwise.
Any resemblance to reality you observe is purely accidental.

-- 
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.honestreporting.com>
We're too busy mopping the floor to turn off the faucet.