1 ;;;; This file contains some extensions to the Alien facility to
2 ;;;; simplify importing C interfaces.
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
13 (in-package "SB!C-CALL")
17 (def-alien-type char (integer 8))
18 (def-alien-type short (integer 16))
19 (def-alien-type int (integer 32))
20 (def-alien-type long (integer #!-alpha 32 #!+alpha 64))
22 (def-alien-type unsigned-char (unsigned 8))
23 (def-alien-type unsigned-short (unsigned 16))
24 (def-alien-type unsigned-int (unsigned 32))
25 (def-alien-type unsigned-long (unsigned #!-alpha 32 #!+alpha 64))
27 (def-alien-type float single-float)
28 (def-alien-type double double-float)
30 (def-alien-type-translator void ()
31 (parse-alien-type '(values) (sb!kernel:make-null-lexenv)))
33 (defun %naturalize-c-string (sap)
34 (declare (type system-area-pointer sap))
35 (with-alien ((ptr (* char) sap))
37 (declare (optimize (speed 3) (safety 0)))
39 for offset of-type fixnum upfrom 0
40 until (zerop (deref ptr offset))
41 finally (return offset))))
42 (let ((result (make-string length)))
43 (sb!kernel:copy-from-system-area (alien-sap ptr) 0
44 result (* sb!vm:vector-data-offset
46 (* length sb!vm:byte-bits))