1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 ;;; --- FFI designators.
6 (in-package :iolib.syscalls
)
10 (defmacro define-designator
(name cffi-type
&body type-clauses
)
11 (let ((type `(quote (or ,@(mapcar #'car type-clauses
))))
12 (ctype (format-symbol t
"~A-DESIGNATOR" name
)))
14 (deftype ,name
() ,type
)
18 (define-foreign-type ,ctype
()
20 (:simple-parser
,ctype
)
21 (:actual-type
,cffi-type
))
22 (defmethod expand-to-foreign (value (type ,ctype
))
24 (let ((,',name
,value
))
25 (etypecase ,',name
,@',type-clauses
))
28 (declaim (inline native-namestring
))
29 (defun native-namestring (pathname)
30 (cffi-sys:native-namestring pathname
))
32 ;;; NATIVE-NAMESTRING should take care of complaining when FILENAME
33 ;;; is wild but I don't think it does on all Lisps, so let's check it
35 (define-designator filename
:string
36 (pathname (when (wild-pathname-p filename
)
37 (system-error "Pathname is wild: ~S." filename
))
38 (native-namestring (translate-logical-pathname filename
)))
41 (define-designator pointer-or-nil
:pointer
43 (foreign-pointer pointer-or-nil
))
45 (define-designator bool
:int