Fix typo: signed 64bit accessor is sb-sys:signed-sap-ref-64
[cffi.git] / libffi / built-in-types.lisp
blobfeeaec6f0f9462945c3045fed24f9010504c6430
1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; built-in-types.lisp -- Define libffi-type-pointers for built-in types and typedefs
4 ;;;
5 ;;; Copyright (C) 2011 Liam M. Healy <lhealy@common-lisp.net>
6 ;;;
7 ;;; Permission is hereby granted, free of charge, to any person
8 ;;; obtaining a copy of this software and associated documentation
9 ;;; files (the "Software"), to deal in the Software without
10 ;;; restriction, including without limitation the rights to use, copy,
11 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
12 ;;; of the Software, and to permit persons to whom the Software is
13 ;;; furnished to do so, subject to the following conditions:
14 ;;;
15 ;;; The above copyright notice and this permission notice shall be
16 ;;; included in all copies or substantial portions of the Software.
17 ;;;
18 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 ;;; DEALINGS IN THE SOFTWARE.
26 ;;;
28 (in-package #:cffi)
30 (defun set-libffi-type-pointer-for-built-in (type &optional (libffi-name type))
31 (set-libffi-type-pointer
32 type
33 (cffi:foreign-symbol-pointer (format nil "ffi_type_~(~a~)" libffi-name))))
35 ;;; Set the type pointers for non-integer built-in types
36 (dolist (type (append cffi:*built-in-float-types* cffi:*other-builtin-types*))
37 (set-libffi-type-pointer-for-built-in type))
39 ;;; Set the type pointers for integer built-in types
40 (dolist (type cffi:*built-in-integer-types*)
41 (set-libffi-type-pointer-for-built-in
42 type
43 (format
44 nil
45 "~aint~d"
46 (if (string-equal type "unsigned" :end1 (min 8 (length (string type))))
47 "u" "s")
48 (* 8 (cffi:foreign-type-size type)))))
50 ;;; Set the type pointer on demand for alias (e.g. typedef) types
51 (defmethod libffi-type-pointer ((type cffi::foreign-type-alias))
52 (libffi-type-pointer (cffi::follow-typedefs type)))
54 ;;; Luis thinks this is unnecessary; FOREIGN-ENUM inherits from FOREIGN-TYPE-ALIAS.
55 #+(or)
56 (defmethod libffi-type-pointer ((type cffi::foreign-enum))
57 (libffi-type-pointer (cffi::actual-type type)))