440b8facc76ed56236dcf94dd8648c902908412f
[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 (/show0 "host-c-call.lisp 12")
13
14 (def-alien-type-class (c-string :include pointer :include-args (to)))
15
16 (def-alien-type-translator c-string ()
17   (make-alien-c-string-type :to
18                             (parse-alien-type 'char
19                                               (sb!kernel::make-null-lexenv))))
20
21 (def-alien-type-method (c-string :unparse) (type)
22   (declare (ignore type))
23   'c-string)
24
25 (def-alien-type-method (c-string :lisp-rep) (type)
26   (declare (ignore type))
27   '(or simple-base-string null (alien (* char))))
28
29 (def-alien-type-method (c-string :naturalize-gen) (type alien)
30   (declare (ignore type))
31   `(if (zerop (sap-int ,alien))
32        nil
33        (%naturalize-c-string ,alien)))
34
35 (def-alien-type-method (c-string :deport-gen) (type value)
36   (declare (ignore type))
37   `(etypecase ,value
38      (null (int-sap 0))
39      ((alien (* char)) (alien-sap ,value))
40      (simple-base-string (vector-sap ,value))))
41
42 (/show0 "host-c-call.lisp end of file")