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 (define-alien-type char (integer 8))
18 (define-alien-type short (integer 16))
19 (define-alien-type int (integer 32))
20 (define-alien-type long (integer #!-alpha 32 #!+alpha 64))
22 (define-alien-type unsigned-char (unsigned 8))
23 (define-alien-type unsigned-short (unsigned 16))
24 (define-alien-type unsigned-int (unsigned 32))
25 (define-alien-type unsigned-long (unsigned #!-alpha 32 #!+alpha 64))
27 (define-alien-type float single-float)
28 (define-alien-type double double-float)
30 (define-alien-type-translator void ()
31 (parse-alien-type '(values) (sb!kernel:make-null-lexenv)))
34 (define-alien-routine strlen integer
37 (defun %naturalize-c-string (sap)
38 (declare (type system-area-pointer sap))
39 (with-alien ((ptr (* char) sap))
40 (let* ((length (alien-funcall (extern-alien "strlen"
41 (function integer (* char)))
43 (result (make-string length)))
44 (declare (optimize (speed 3) (safety 0)))
45 (sb!kernel:%byte-blt sap 0 result 0 length)