Subject: [clisp-list] FFI with complex numbers?

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Tue May 11 05:34:11 2004

Goffioul Michael 
>Would you then be able to make an external C functions acces the
>internal data of a LISP vector directly in "double*"-like way

No. You can write an "internal" C function which, with special care, can stuff the results of a foreign function call into a Lisp object.
CLISP specialized arrays exist for unsigned-byte 8/16/32.

The pseudo code would be as follows (sorry, no more time - actually, it's probably too sketchy to be usable)
LISPFUNN(myfoo...)
{
   # two arguments: int and Lisp array
   var param1 = popSTACK();
   # leave array on stack
   # array checking code not shown
   check_uint32(param1);
   unsigned long x = I_to_UL(param1);
   begin_call();
   var double ll = myfun(); # invoke foreign function
   end_call();
   # convert ll to some CLISP format, see dfloat.d and the like
   # array groking code, pull array from stack (not shown)
   var a = STACK_0; # move-safe code down here
   # put double in array, code not shown, see misc. examples in source tree
   return_values();
}

The key point #1 is that the Lisp array remained on the stack, so even if the foreign function were to invoke a callback, GC would find it.

Key point #2 is to fill the array in the safe, known place, i.e. not amid foreign call land, but rather after the foreign call (after end_call), back in Lisp C mode.

You see that this approach requires quite some familiarity with a small part of CLISP internals.

>Could you point me to some documentation about modules? I read the
>CLISP implementation doc, but didn't find it very explicit regarding
>modules.
Look at hand-written or hand-originated modules like
 o affi.d (probably only in attic of current CVS)
   an idea might be to investigate its MEM-READ/WRITE function
 o gdi.d
 o ...
also look at the output of the modprep program. It shows how functions which pull Lisp arguments from the Lisp stack are to be built.

Regards,
	Jörg Höhle.

---

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Fri May 14 02:19:00 2004

Sam wrote:
>it _DOES_ overwrite the results!!!
>please look at the code again!
Oops, my fault. It was so short, yet I didn't see these two lines :-)