ALLOCATE-ENV: the number of elements is HASH-TABLE-COUNT not HASH-TABLE-SIZE
[iolib.git] / src / syscalls / designators.lisp
blob997c775039f2af9e2e3da1cec68233ebd376e4c5
1 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; --- CFFI type designators.
4 ;;;
6 (in-package :iolib.syscalls)
8 ;;;-------------------------------------------------------------------------
9 ;;; CFFI Type Designators
10 ;;;-------------------------------------------------------------------------
12 (defmacro define-designator (name cffi-type &body type-clauses)
13 (let ((type `(quote (or ,@(mapcar #'car type-clauses))))
14 (ctype (format-symbol t "~A-~A" (string name) (string '#:designator))))
15 `(progn
16 (deftype ,name () ,type)
17 (defun ,name (,name)
18 (etypecase ,name
19 ,@type-clauses))
20 (define-foreign-type ,ctype ()
22 (:simple-parser ,ctype)
23 (:actual-type ,cffi-type))
24 (defmethod expand-to-foreign (value (type ,ctype))
25 `(convert-to-foreign
26 (let ((,',name ,value))
27 (etypecase ,',name ,@',type-clauses))
28 ,',cffi-type)))))
30 (define-designator pointer-or-nil :pointer
31 (null (null-pointer))
32 (foreign-pointer pointer-or-nil))
34 (define-designator bool :int
35 (null 0)
36 (t 1))
39 ;;;-------------------------------------------------------------------------
40 ;;; Other Types
41 ;;;-------------------------------------------------------------------------
43 ;;; FIXME: with fd namespaces on Linux, someday this might be no
44 ;;; longer correct
45 (deftype fd () '(integer 0 65535))