Commit | Line | Data |
---|---|---|
3d8d56df | 1 | /* Copyright (C) 1995,1996,1997 Free Software Foundation, Inc. |
0f2d19dd JB |
2 | * |
3 | * This program is free software; you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License as published by | |
5 | * the Free Software Foundation; either version 2, or (at your option) | |
6 | * any later version. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this software; see the file COPYING. If not, write to | |
82892bed JB |
15 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
16 | * Boston, MA 02111-1307 USA | |
0f2d19dd JB |
17 | * |
18 | * As a special exception, the Free Software Foundation gives permission | |
19 | * for additional uses of the text contained in its release of GUILE. | |
20 | * | |
21 | * The exception is that, if you link the GUILE library with other files | |
22 | * to produce an executable, this does not by itself cause the | |
23 | * resulting executable to be covered by the GNU General Public License. | |
24 | * Your use of that executable is in no way restricted on account of | |
25 | * linking the GUILE library code into it. | |
26 | * | |
27 | * This exception does not however invalidate any other reasons why | |
28 | * the executable file might be covered by the GNU General Public License. | |
29 | * | |
30 | * This exception applies only to the code released by the | |
31 | * Free Software Foundation under the name GUILE. If you copy | |
32 | * code from other Free Software Foundation releases into a copy of | |
33 | * GUILE, as the General Public License permits, the exception does | |
34 | * not apply to the code that you add in this way. To avoid misleading | |
35 | * anyone as to the status of such modified files, you must delete | |
36 | * this exception notice from them. | |
37 | * | |
38 | * If you write modifications of your own for GUILE, it is your choice | |
39 | * whether to permit this exception to apply to your modifications. | |
82892bed | 40 | * If you do not wish that, delete this exception notice. */ |
0f2d19dd JB |
41 | \f |
42 | ||
43 | #include <stdio.h> | |
44 | #include "_scm.h" | |
20e6290e JB |
45 | #include "pairs.h" |
46 | #include "genio.h" | |
47 | #include "throw.h" | |
48 | ||
49 | #include "error.h" | |
0f2d19dd | 50 | |
95b88819 GH |
51 | #ifdef HAVE_UNISTD_H |
52 | #include <unistd.h> | |
53 | #endif | |
0f2d19dd JB |
54 | \f |
55 | ||
56 | \f | |
57 | /* {Errors and Exceptional Conditions} | |
58 | */ | |
59 | ||
0f2d19dd | 60 | |
0f2d19dd | 61 | extern int errno; |
f5bf2977 | 62 | |
7cb1d4d3 | 63 | void (*scm_error_callback) () = 0; |
0f2d19dd | 64 | |
c37e0e55 | 65 | /* All errors should pass through here. */ |
7cb1d4d3 GH |
66 | void |
67 | scm_error (key, subr, message, args, rest) | |
68 | SCM key; | |
69 | char *subr; | |
70 | char *message; | |
71 | SCM args; | |
72 | SCM rest; | |
73 | { | |
74 | SCM arg_list; | |
75 | if (scm_error_callback) | |
76 | (*scm_error_callback) (key, subr, message, args, rest); | |
77 | ||
f5bf2977 | 78 | arg_list = scm_listify (subr ? scm_makfrom0str (subr) : SCM_BOOL_F, |
b59b97ba | 79 | message ? scm_makfrom0str (message) : SCM_BOOL_F, |
7cb1d4d3 GH |
80 | args, |
81 | rest, | |
82 | SCM_UNDEFINED); | |
83 | scm_ithrow (key, arg_list, 1); | |
84 | ||
85 | /* No return, but just in case: */ | |
86 | ||
89958ad0 JB |
87 | write (2, "unhandled system error\n", |
88 | sizeof ("unhandled system error\n") - 1); | |
7cb1d4d3 GH |
89 | exit (1); |
90 | } | |
0f2d19dd | 91 | |
c37e0e55 GH |
92 | /* Scheme interface to scm_error. */ |
93 | SCM_PROC(s_error_scm, "scm-error", 5, 0, 0, scm_error_scm); | |
94 | SCM | |
95 | scm_error_scm (key, subr, message, args, rest) | |
96 | SCM key; | |
97 | SCM subr; | |
98 | SCM message; | |
99 | SCM args; | |
100 | SCM rest; | |
101 | { | |
102 | SCM_ASSERT (SCM_NIMP (key) && SCM_SYMBOLP (key), key, SCM_ARG1, s_error_scm); | |
103 | SCM_ASSERT (SCM_FALSEP (subr) || (SCM_NIMP (subr) && SCM_ROSTRINGP (subr)), | |
104 | subr, SCM_ARG2, s_error_scm); | |
105 | SCM_ASSERT (SCM_FALSEP (message) | |
106 | || (SCM_NIMP (message) && SCM_ROSTRINGP (message)), | |
107 | message, SCM_ARG3, s_error_scm); | |
108 | ||
89958ad0 JB |
109 | SCM_COERCE_SUBSTR (message); |
110 | ||
c37e0e55 GH |
111 | scm_error (key, |
112 | (SCM_FALSEP (subr)) ? NULL : SCM_ROCHARS (subr), | |
113 | (SCM_FALSEP (message)) ? NULL : SCM_ROCHARS (message), | |
114 | args, | |
115 | rest); | |
116 | /* not reached. */ | |
117 | } | |
118 | ||
523f5266 | 119 | SCM_SYMBOL (scm_system_error_key, "system-error"); |
52859adf GH |
120 | void |
121 | scm_syserror (subr) | |
122 | char *subr; | |
123 | { | |
01f61221 | 124 | scm_error (scm_system_error_key, |
52859adf | 125 | subr, |
f5bf2977 | 126 | "%s", |
52859adf GH |
127 | scm_listify (scm_makfrom0str (strerror (errno)), |
128 | SCM_UNDEFINED), | |
129 | scm_listify (SCM_MAKINUM (errno), SCM_UNDEFINED)); | |
130 | } | |
131 | ||
132 | void | |
3d8d56df | 133 | scm_syserror_msg (subr, message, args, eno) |
52859adf GH |
134 | char *subr; |
135 | char *message; | |
136 | SCM args; | |
3d8d56df | 137 | int eno; |
52859adf | 138 | { |
01f61221 | 139 | scm_error (scm_system_error_key, |
52859adf GH |
140 | subr, |
141 | message, | |
142 | args, | |
3d8d56df | 143 | scm_listify (SCM_MAKINUM (eno), SCM_UNDEFINED)); |
52859adf GH |
144 | } |
145 | ||
146 | void | |
147 | scm_sysmissing (subr) | |
148 | char *subr; | |
149 | { | |
150 | #ifdef ENOSYS | |
01f61221 | 151 | scm_error (scm_system_error_key, |
52859adf | 152 | subr, |
f5bf2977 | 153 | "%s", |
52859adf GH |
154 | scm_listify (scm_makfrom0str (strerror (ENOSYS)), SCM_UNDEFINED), |
155 | scm_listify (SCM_MAKINUM (ENOSYS), SCM_UNDEFINED)); | |
156 | #else | |
01f61221 | 157 | scm_error (scm_system_error_key, |
52859adf GH |
158 | subr, |
159 | "Missing function", | |
160 | SCM_BOOL_F, | |
161 | scm_listify (SCM_MAKINUM (0), SCM_UNDEFINED)); | |
162 | #endif | |
163 | } | |
164 | ||
523f5266 | 165 | SCM_SYMBOL (scm_num_overflow_key, "numerical-overflow"); |
52859adf GH |
166 | void |
167 | scm_num_overflow (subr) | |
168 | char *subr; | |
169 | { | |
01f61221 | 170 | scm_error (scm_num_overflow_key, |
52859adf GH |
171 | subr, |
172 | "Numerical overflow", | |
173 | SCM_BOOL_F, | |
174 | SCM_BOOL_F); | |
175 | } | |
176 | ||
523f5266 | 177 | SCM_SYMBOL (scm_out_of_range_key, "out-of-range"); |
52859adf GH |
178 | void |
179 | scm_out_of_range (subr, bad_value) | |
180 | char *subr; | |
181 | SCM bad_value; | |
182 | { | |
01f61221 | 183 | scm_error (scm_out_of_range_key, |
52859adf GH |
184 | subr, |
185 | "Argument out of range: %S", | |
186 | scm_listify (bad_value, SCM_UNDEFINED), | |
187 | SCM_BOOL_F); | |
188 | } | |
f5bf2977 | 189 | |
523f5266 | 190 | SCM_SYMBOL (scm_args_number_key, "wrong-number-of-args"); |
0f2d19dd | 191 | void |
f5bf2977 GH |
192 | scm_wrong_num_args (proc) |
193 | SCM proc; | |
194 | { | |
01f61221 | 195 | scm_error (scm_args_number_key, |
f5bf2977 GH |
196 | NULL, |
197 | "Wrong number of arguments to %s", | |
198 | scm_listify (proc, SCM_UNDEFINED), | |
199 | SCM_BOOL_F); | |
200 | } | |
201 | ||
523f5266 | 202 | SCM_SYMBOL (scm_arg_type_key, "wrong-type-arg"); |
f5bf2977 GH |
203 | void |
204 | scm_wrong_type_arg (subr, pos, bad_value) | |
205 | char *subr; | |
206 | int pos; | |
207 | SCM bad_value; | |
208 | { | |
01f61221 | 209 | scm_error (scm_arg_type_key, |
f5bf2977 GH |
210 | subr, |
211 | (pos == 0) ? "Wrong type argument: %S" | |
212 | : "Wrong type argument in position %s: %S", | |
213 | (pos == 0) ? scm_listify (bad_value, SCM_UNDEFINED) | |
214 | : scm_listify (SCM_MAKINUM (pos), bad_value, SCM_UNDEFINED), | |
215 | SCM_BOOL_F); | |
216 | } | |
217 | ||
523f5266 | 218 | SCM_SYMBOL (scm_memory_alloc_key, "memory-allocation-error"); |
f5bf2977 GH |
219 | void |
220 | scm_memory_error (subr) | |
221 | char *subr; | |
222 | { | |
01f61221 | 223 | scm_error (scm_memory_alloc_key, |
f5bf2977 GH |
224 | subr, |
225 | "Memory allocation error", | |
226 | SCM_BOOL_F, | |
227 | SCM_BOOL_F); | |
228 | } | |
229 | ||
523f5266 GH |
230 | SCM_SYMBOL (scm_misc_error_key, "misc-error"); |
231 | void | |
232 | scm_misc_error (subr, message, args) | |
233 | char *subr; | |
234 | char *message; | |
235 | SCM args; | |
236 | { | |
237 | scm_error (scm_misc_error_key, subr, message, args, SCM_BOOL_F); | |
238 | } | |
239 | ||
f5bf2977 GH |
240 | /* implements the SCM_ASSERT interface. */ |
241 | SCM | |
242 | scm_wta (arg, pos, s_subr) | |
243 | SCM arg; | |
244 | char *pos; | |
245 | char *s_subr; | |
246 | { | |
247 | if (!s_subr || !*s_subr) | |
248 | s_subr = NULL; | |
249 | if ((~0x1fL) & (long) pos) | |
250 | { | |
251 | /* error string supplied. */ | |
b1edcd36 | 252 | scm_misc_error (s_subr, pos, SCM_EOL); |
f5bf2977 GH |
253 | } |
254 | else | |
255 | { | |
256 | /* numerical error code. */ | |
257 | int error = (long) pos; | |
258 | ||
259 | switch (error) | |
260 | { | |
261 | case SCM_ARGn: | |
262 | scm_wrong_type_arg (s_subr, 0, arg); | |
263 | case SCM_ARG1: | |
264 | scm_wrong_type_arg (s_subr, 1, arg); | |
265 | case SCM_ARG2: | |
266 | scm_wrong_type_arg (s_subr, 2, arg); | |
267 | case SCM_ARG3: | |
268 | scm_wrong_type_arg (s_subr, 3, arg); | |
269 | case SCM_ARG4: | |
270 | scm_wrong_type_arg (s_subr, 4, arg); | |
271 | case SCM_ARG5: | |
272 | scm_wrong_type_arg (s_subr, 5, arg); | |
273 | case SCM_WNA: | |
274 | scm_wrong_num_args (arg); | |
275 | case SCM_OUTOFRANGE: | |
276 | scm_out_of_range (s_subr, arg); | |
277 | case SCM_NALLOC: | |
278 | scm_memory_error (s_subr); | |
279 | default: | |
280 | /* this shouldn't happen. */ | |
b1edcd36 | 281 | scm_misc_error (s_subr, "Unknown error", SCM_EOL); |
f5bf2977 GH |
282 | } |
283 | } | |
284 | return SCM_UNSPECIFIED; | |
285 | } | |
286 | ||
287 | /* obsolete interface: scm_everr (exp, env, arg, pos, s_subr) | |
288 | was equivalent to scm_wta (arg, pos, s_subr) */ | |
289 | ||
0f2d19dd JB |
290 | void |
291 | scm_init_error () | |
0f2d19dd | 292 | { |
67ec3667 | 293 | #include "cpp_err_symbols.c" |
0f2d19dd JB |
294 | #include "error.x" |
295 | } | |
296 |