8977f80015076bcf137201773393f919c7d3e1ab
[sbcl.git] / src / code / host-c-call.lisp
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
9
10 (in-package "SB!C-CALL")
11
12 (def-alien-type-class (c-string :include pointer :include-args (to)))
13
14 (def-alien-type-translator c-string ()
15   (make-alien-c-string-type :to
16                             (parse-alien-type 'char
17                                               (sb!kernel::make-null-lexenv))))
18
19 (def-alien-type-method (c-string :unparse) (type)
20   (declare (ignore type))
21   'c-string)
22
23 (def-alien-type-method (c-string :lisp-rep) (type)
24   (declare (ignore type))
25   '(or simple-base-string null (alien (* char))))
26
27 (def-alien-type-method (c-string :naturalize-gen) (type alien)
28   (declare (ignore type))
29   `(if (zerop (sap-int ,alien))
30        nil
31        (%naturalize-c-string ,alien)))
32
33 (def-alien-type-method (c-string :deport-gen) (type value)
34   (declare (ignore type))
35   `(etypecase ,value
36      (null (int-sap 0))
37      ((alien (* char)) (alien-sap ,value))
38      (simple-base-string (vector-sap ,value))))