From: Thomas Weigert

Subject: def-c-type

Date: 1997-6-29 18:26


Folks,

I am trying to use the foreign function interface. Consider the following
simple c program:

struct e_logical
  {
    unsigned short function;
    unsigned short instance_hi;
    unsigned short instance_lo;
  };

void doit (struct e_logical *t4) {
  t4->function = 1;
  t4->instance_hi = 2;
  t4->instance_lo = 3;
  return;
}

Load this into lisp. Now let's define the lisp side:

(ff:def-c-type e_logical :struct
 (function :unsigned-short)
 (instance_hi :unsigned-short)
 (instance_lo :unsigned-short)
)

(ff:defforeign 'doit :return-type :void :arguments '(:lisp))

Now following the lisp manual:

(setf x (make-e_logical))
(setf (e_logical-function x) 10)
(doit x)

You would expect that now (e_logical-function x) is 1, but:

USER(23): (e_logical-function x)
10

What happened? Note that if we define the struct to reside
:in-foreign-space this works! (Of course, the argument then is integer.)

Any hints are appreciated.

Thanks, Thomas Weigert.