[cffi-devel] why avoid NIL as NULL pointer in CFFI?

Luís Oliveira luismbo at gmail.com
Fri Dec 9 18:54:08 UTC 2005


On 2005-dec-09, at 13:55, Hoehle, Joerg-Cyril wrote:
> I had a short glance at the CLISP implementation and it immediately  
> struck me that CFFI dislikes CLISP's consistent use of NIL for a  
> NULL FFI pointer. Why?

I'm not sure I dislike it. What I don't like is that CLISP doesn't  
offer a type that *doesn't* translate between NIL and a FFI pointer.

It's just that it's easy to come up with a type that does the NIL <->  
NULL translation out of a raw pointer type.

(defctype :ptr :pointer)

(define-type-translator :ptr :to-c (type value)
   `(or ,type (null-pointer))

(define-type-translator :ptr :from-c (type value)
   (with-unique-names (pointer)
     `(let ((,pointer ,value))
        (if (null-pointer-p ,pointer)
            nil
            ,pointer))))

IIRC, James deliberately doesn't want to translate between NIL and  
the NULL pointer because NIL shows up often in error situations. I  
suppose we could put this alternate type in CFFI for those who like  
it anyway?


-- 
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt




More information about the cffi-devel mailing list