Re: type checks (was: CLISP typed foreign references)

Kevin Rosenberg <kevin-HJRc7zDS/[email protected]> Wed, 3 Apr 2002 04:26:04 -0700 (MST)
Newsgroups gmane.lisp.uffi.general
Message-ID <[email protected]>
> Don't do malloc+free, I'll do. I'm already thinking about
> WITH-ALIEN/STACK-ALLOCATION for CLISP. I already have a MALLOC hack (but
> no free yet).

Great.

> The problem to me, however, is not malloc+free. It's matching C type
> information between foreign objects and function signatures. So far, I
> don't seem forward to implementing C subtype style testing in Lisp.

I agree, the alloc and free is the simple part.

> OTOH, if I declare (function GETENV (* char)) and pass a typeless
> foreign pointer (or worse, an integer like in ACL), I'm even less safe
> than working in plain ANSI-C. I don't like that.

Well, thinking worse-is-better, I might suggest that you start with a
typeless integer or do like CMUCL and wrap the address in a SAP object as
an (unsigned-byte 32).  You need to then provide a function that takes the
address and the type (passed to CLISP by the deref functions of UFFI), and
returns the object.

Later, you can add a layer that stores the type and the address so your
pointers will be "type-safe". BTW, ACL does both integer addresses and
well as typed pointers. You choose which type of pointer you want with the
allocation function. For UFFI, I choose to use integer pointers for
efficiency sake.


> BTW, thanks for putting my draft of an article on FFI design on the server.

A pleasure, it's a good document.

Kevin