Subject: [clisp-list] Re: array of strings?

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Thu Feb 26 06:36:03 2004

Hi,

Sam had another question about interfacing to C code.
><http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/engoutputbuffer.shtml>?
>   I will need to allocate and deallocate the buffer, right?
You'll need to keep your buffer constantly available to the C world, therefore you indeed need a constant address buffer. C Stack allocation using with-foreign is still possible, but don't forget unwind-protect to disable buffering upon exit of the scope!

>(setq z (allocate-shallow '(c-array char 1000)))
ok
>(engOutputBuffer ep (c-var-address z) 1000)
c-var-address is wrong, it's for places.
Just say z, and the FFI will extract the address inside the FOREIGN-VARIABLE object z.
Or use foreign-variable-address (IIRC).

>(engOutputBuffer ep NIL 0)
I cannot remember whether NIL argument is accepted with the c-pointer type. I believe it's not.
If not, you'll need two function declarations, or e.g. (unsigned-foreign-address 0) (iirk).

>(foreign-free z)
ok.

Regards,
	Jorg Hohle.

---

From: Sam Steingold <[email-masked]>
Date: Thu Feb 26 08:21:21 2004

> * Hoehle, Joerg-Cyril <[email-masked]> [2004-02-26 15:25:22 +0100]:
>

this is printed as #<FOREIGN-VARIABLE FOREIGN-ALLOCATE #x1012CEE8>
how do I extract the string?

> type. I believe it's not.

2003-08-05  Sam Steingold  <[email-masked]>

	* foreign.d (convert_from_foreign): treat NULL as NIL
	(convert_to_foreign): treat NIL as NULL

nevertheless, (engOutputBuffer ep NIL 0) returns 1 (error code!)

> If not, you'll need two function declarations, or
> e.g. (unsigned-foreign-address 0) (iirk).

(engOutputBuffer ep (unsigned-foreign-address 0) 0)
also returns 1, so, I guess, that's OK.

-- 
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>
If you're constantly being mistreated, you're cooperating with the treatment.