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