Subject: [clisp-list] ffi:c-array-ptr (was: c-string vs bounded buffers)

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Tue Mar 19 11:16:03 2002

Hi,

Sam Steingold wrote:
> What is c-array-ptr?

Thanks for bringing this to my attention, I didn't know about it - maybe it was not in the initial FFI developed years ago. I looked at the source since I couldn't understand it otherwise just from impnotes.

1. it's something needed, since it is e.g. appropriate for the typical char*argv[]: an array of unknown length, but which is NULL, 0 or \0 terminated (depending on its element type). In other words, it allows C string style conventions for other array types.

2. I don't know why there is this shortcut instead of (the hypothetical)
(c-ptr-null (c-array-ZERO-TERMINATED <elt-type>)) which would more fit the other FFI types. Note the c-ptr-NULL instead of just c-ptr behaviour (from peeking at the source).

2. However it's integration into CLISP seems incomplete to me. It always returns a VECTOR of element-type T, no specialized array type for characters or numbers, as the other arrays do. Therefore, C-STRING and (C-ARRAY-PTR CHARACTER) results differ. I consider this a bug, rather than a feature. There's no obvious reason (at least no documentation) for this deviation from the behaviour of the other C-ARRAY and C-ARRAY-MAX return types.

(:return-type (c-array-ptr character)) -> #(#\f #\o #\o)
(:return-type (c-ptr-null (c-array-max character 10))) -> "foo"
(:return-type c-string) -> "foo"

> why is only c-ptr acceptable as :out/:in-out?
Could you please elaborate? or provide an example.

> I would expect that c-ptr-null and c-array-ptr would be 
> acceptable too.
> 
> can you fix this?

I think I can fix the above IMHO misfeature (+/- Unicode translation) if you so wish. But you meant something else.

Regards,
	Jorg Hohle.

---

From: Sam Steingold <[email-masked]>
Date: Tue Mar 19 12:45:37 2002

> * In message <[email-masked]>
> * On the subject of "[clisp-list] ffi:c-array-ptr (was: c-string vs bounded buffers)"
> * Sent on Tue, 19 Mar 2002 16:57:22 +0100
> * Honorable "Hoehle, Joerg-Cyril" <[email-masked]> writes:
>

an :OUT arg must be a c-ptr:

(def-call-out foo
  (:arguments (bar (c-ptr-null int) :out)))

does not work.

> I think I can fix the above IMHO misfeature (+/- Unicode translation)
> if you so wish. But you meant something else.

what I meant, loosely, was making sure that the CLISP FFI is better
than the competition. :-)

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.2 GNU/Linux
Keep Jerusalem united! <http://www.onejerusalem.org/Petition.asp>
Read, think and remember! <http://www.iris.org.il> <http://www.memri.org/>
Don't ascribe to malice what can be adequately explained by stupidity.