libffi: clean up the ABI enum
[cffi.git] / src / package.lisp
blob922e92be14a88e5e2ee0cddf188c0a5a06dd76a7
1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; package.lisp --- Package definition for CFFI.
4 ;;;
5 ;;; Copyright (C) 2005-2006, James Bielman <jamesjb@jamesjb.com>
6 ;;; Copyright (C) 2009, Luis Oliveira <loliveira@common-lisp.net>
7 ;;; Copyright (C) 2012, Mark Evenson <evenson.not.org@gmail.com>
8 ;;;
9 ;;; Permission is hereby granted, free of charge, to any person
10 ;;; obtaining a copy of this software and associated documentation
11 ;;; files (the "Software"), to deal in the Software without
12 ;;; restriction, including without limitation the rights to use, copy,
13 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
14 ;;; of the Software, and to permit persons to whom the Software is
15 ;;; furnished to do so, subject to the following conditions:
16 ;;;
17 ;;; The above copyright notice and this permission notice shall be
18 ;;; included in all copies or substantial portions of the Software.
19 ;;;
20 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 ;;; DEALINGS IN THE SOFTWARE.
28 ;;;
30 #+abcl
31 (eval-when (:compile-toplevel :load-toplevel :execute)
32 (require :abcl-contrib)
33 (require :jna)
34 (require :jss))
36 ;;;# Administrivia
38 (defpackage #:cffi-sys
39 (:use #:common-lisp #:alexandria
40 #+abcl #:java
41 #+(or ccl mcl) #:ccl
42 #+cmu #:alien #+cmu #:c-call
43 #+corman #:c-types
44 #+sbcl #:sb-alien)
45 #+ecl
46 (:import-from #:si #:null-pointer-p)
47 (:shadow #:copy-file ; Conflicts with ccl:copy-file
49 (:export
50 ;; Platform-specific functionality
51 #+ecl #:*cffi-ecl-method*
53 ;; C ABI utils
54 #:canonicalize-symbol-name-case
55 #:defcfun-helper-forms
57 ;; Pointers
58 #:foreign-pointer
59 #:pointerp
60 #:pointer-eq
61 #:null-pointer
62 #:null-pointer-p
63 #:inc-pointer
64 #:make-pointer
65 #:pointer-address
67 ;; Memory operators
68 #:%mem-ref
69 #:%mem-set
71 ;; Foreign symbols
72 #:%foreign-symbol-pointer
74 ;; Memory management
75 #:%foreign-alloc
76 #:foreign-free
77 #:with-foreign-pointer
79 ;; Foreign functions
80 #:%foreign-funcall
81 #:%foreign-funcall-pointer
82 #:%foreign-funcall-varargs
83 #:%foreign-funcall-pointer-varargs
84 #:%foreign-type-alignment
86 ;; Foreign types
87 #:%foreign-type-size
89 ;; Foreign libraries
90 #:%load-foreign-library
91 #:%close-foreign-library
92 #:native-namestring
94 ;; Callbacks
95 #:%defcallback
96 #:%callback
98 ;; Shareable vectors
99 #:make-shareable-byte-vector
100 #:with-pointer-to-vector-data
102 ;; Compiler macro utils
103 #:constant-form-p
104 #:constant-form-value))
106 ;;; Create a package to contain the symbols for callback functions.
107 ;;; We want to redefine callbacks with the same symbol so the internal
108 ;;; data structures are reused.
109 #+(or allegro ccl cmu ecl lispworks mkcl)
110 (defpackage #:cffi-callbacks
111 (:use))
113 (defpackage #:cffi-features
114 (:use #:cl)
115 (:export
116 #:cffi-feature-p
118 ;; Features related to the CFFI-SYS backend. Why no-*? This
119 ;; reflects the hope that these symbols will go away completely
120 ;; meaning that at some point all lisps will support long-longs,
121 ;; the foreign-funcall primitive, etc...
122 #:no-long-long
123 #:no-foreign-funcall
124 #:no-stdcall
125 #:flat-namespace
127 ;; Only ECL and SCL support long-double...
128 ;;#:no-long-double
130 ;; Features related to the operating system.
131 ;; More should be added.
132 #:darwin
133 #:unix
134 #:windows
136 ;; Features related to the processor.
137 ;; More should be added.
138 #:ppc32
139 #:x86
140 #:x86-64
141 #:sparc
142 #:sparc64
143 #:hppa
144 #:hppa64))
146 (defpackage #:cffi
147 (:use #:common-lisp #:cffi-sys #:babel-encodings)
148 (:import-from #:alexandria
149 #:compose
150 #:ensure-list
151 #:featurep
152 #:format-symbol
153 #:hash-table-values
154 #:if-let
155 #:ignore-some-conditions
156 #:lastcar
157 #:make-gensym-list
158 #:make-keyword
159 #:mappend
160 #:once-only
161 #:parse-body
162 #:simple-style-warning
163 #:symbolicate
164 #:unwind-protect-case
165 #:when-let
166 #:with-unique-names)
167 (:export
168 ;; Types.
169 #:foreign-pointer
171 ;; FIXME: the following types are undocumented. They should
172 ;; probably be replaced with a proper type introspection API
173 ;; though.
174 #:*built-in-foreign-types*
175 #:*other-builtin-types*
176 #:*built-in-integer-types*
177 #:*built-in-float-types*
179 ;; Primitive pointer operations.
180 #:foreign-free
181 #:foreign-alloc
182 #:mem-aptr
183 #:mem-aref
184 #:mem-ref
185 #:pointerp
186 #:pointer-eq
187 #:null-pointer
188 #:null-pointer-p
189 #:inc-pointer
190 #:incf-pointer
191 #:with-foreign-pointer
192 #:make-pointer
193 #:pointer-address
195 ;; Shareable vectors.
196 #:make-shareable-byte-vector
197 #:with-pointer-to-vector-data
199 ;; Foreign string operations.
200 #:*default-foreign-encoding*
201 #:foreign-string-alloc
202 #:foreign-string-free
203 #:foreign-string-to-lisp
204 #:lisp-string-to-foreign
205 #:with-foreign-string
206 #:with-foreign-strings
207 #:with-foreign-pointer-as-string
209 ;; Foreign array operations.
210 ;; TODO: document these
211 #:foreign-array-alloc
212 #:foreign-array-free
213 #:foreign-array-to-lisp
214 #:lisp-array-to-foreign
215 #:with-foreign-array
216 #:foreign-aref
218 ;; Foreign function operations.
219 #:defcfun
220 #:foreign-funcall
221 #:foreign-funcall-pointer
222 #:foreign-funcall-varargs
223 #:foreign-funcall-pointer-varargs
224 #:translate-camelcase-name
225 #:translate-name-from-foreign
226 #:translate-name-to-foreign
227 #:translate-underscore-separated-name
229 ;; Foreign library operations.
230 #:*foreign-library-directories*
231 #:*darwin-framework-directories*
232 #:foreign-library
233 #:foreign-library-load-state
234 #:foreign-library-name
235 #:foreign-library-pathname
236 #:foreign-library-type
237 #:foreign-library-loaded-p
238 #:list-foreign-libraries
239 #:define-foreign-library
240 #:load-foreign-library
241 #:load-foreign-library-error
242 #:use-foreign-library
243 #:close-foreign-library
244 #:reload-foreign-libraries
246 ;; Callbacks.
247 #:callback
248 #:get-callback
249 #:defcallback
251 ;; Foreign type operations.
252 #:defcstruct
253 #:defcunion
254 #:defctype
255 #:defcenum
256 #:defbitfield
257 #:define-foreign-type
258 #:define-parse-method
259 #:define-c-struct-wrapper
260 #:foreign-enum-keyword
261 #:foreign-enum-keyword-list
262 #:foreign-enum-value
263 #:foreign-bitfield-symbol-list
264 #:foreign-bitfield-symbols
265 #:foreign-bitfield-value
266 #:foreign-slot-pointer
267 #:foreign-slot-value
268 #:foreign-slot-type
269 #:foreign-slot-offset
270 #:foreign-slot-count
271 #:foreign-slot-names
272 #:foreign-type-alignment
273 #:foreign-type-size
274 #:with-foreign-object
275 #:with-foreign-objects
276 #:with-foreign-slots
277 #:convert-to-foreign
278 #:convert-from-foreign
279 #:convert-into-foreign-memory
280 #:free-converted-object
281 #:translation-forms-for-class
283 ;; Extensible foreign type operations.
284 #:define-translation-method ; FIXME: undocumented
285 #:translate-to-foreign
286 #:translate-from-foreign
287 #:translate-into-foreign-memory
288 #:free-translated-object
289 #:expand-to-foreign-dyn
290 #:expand-to-foreign
291 #:expand-from-foreign
292 #:expand-into-foreign-memory
294 ;; Foreign globals.
295 #:defcvar
296 #:get-var-pointer
297 #:foreign-symbol-pointer