Optimize MAKE-ARRAY on unknown element-type.
[sbcl.git] / src / code / common-os.lisp
1 ;;;; OS interface functions for SBCL common to all target OSes
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!SYS")
13
14 (defvar *software-version* nil)
15
16 (sb!alien:define-alien-variable ("posix_argv" *native-posix-argv*) (* (* char)))
17 (sb!alien:define-alien-variable ("core_string" *native-core-string*) (* char))
18 (sb!alien:define-alien-routine
19  os-get-runtime-executable-path sb!alien:c-string (external-path boolean))
20 (sb!alien:define-alien-variable
21  ("saved_runtime_path" *native-saved-runtime-path*) (* char))
22
23 (defmacro init-var-ignoring-errors (variable
24                                     form
25                                     &key default
26                                          explanation
27                                          (condition 'error))
28   `(setf ,variable
29          (handler-case ,form
30            (,condition (c)
31              (let ((default ,default))
32                (warn "Error initializing ~a~@[ ~a~]:~@
33              ~a
34              ~% Using ~s instead."
35                      ',variable
36                      ,explanation
37                      c
38                      default)
39                default)))))
40
41 ;;; If something ever needs to be done differently for one OS, then
42 ;;; split out the different part into per-os functions.
43 (defun os-cold-init-or-reinit ()
44   (/show0 "setting *CORE-STRING*")
45   (init-var-ignoring-errors
46    *core-string*
47    (sb!alien:cast *native-core-string* sb!alien:c-string)
48    :default "")
49   (/show0 "setting *POSIX-ARGV*")
50   (init-var-ignoring-errors
51    sb!ext:*posix-argv*
52    (loop for i from 0
53          for arg = (sb!alien:deref *native-posix-argv* i)
54          until (sb!alien:null-alien arg)
55          collect (sb!alien:cast arg sb!alien:c-string)))
56   (/show0 "entering OS-COLD-INIT-OR-REINIT")
57   (setf *software-version* nil)
58   (/show0 "setting *DEFAULT-PATHNAME-DEFAULTS*")
59   ;; Temporary value, so that #'NATIVE-PATHNAME won't blow up when
60   ;; we call it below
61   (setf *default-pathname-defaults* (make-trivial-default-pathname))
62   (init-var-ignoring-errors
63    *default-pathname-defaults* (native-pathname (sb!unix:posix-getcwd/))
64    :default (make-trivial-default-pathname)
65    :explanation "with the current directory")
66   (/show0 "setting *CORE-PATHNAME*")
67   (setf *core-pathname* (merge-pathnames (native-pathname *core-string*)))
68   (/show0 "setting *RUNTIME-PATHNAME*")
69   (init-var-ignoring-errors
70    *runtime-pathname*
71    (let ((exe (os-get-runtime-executable-path t))
72          (saved (sb!alien:cast *native-saved-runtime-path* sb!alien:c-string)))
73      (when (or exe saved) (native-pathname (or exe saved)))))
74   (/show0 "leaving OS-COLD-INIT-OR-REINIT"))