428
|
1 /* Evaluator for XEmacs Lisp interpreter.
|
|
2 Copyright (C) 1985-1987, 1992-1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
793
|
4 Copyright (C) 2000, 2001, 2002 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: FSF 19.30 (except for Fsignal), Mule 2.0. */
|
|
24
|
|
25 #include <config.h>
|
|
26 #include "lisp.h"
|
|
27
|
|
28 #include "commands.h"
|
|
29 #include "backtrace.h"
|
|
30 #include "bytecode.h"
|
|
31 #include "buffer.h"
|
|
32 #include "console.h"
|
|
33 #include "opaque.h"
|
|
34
|
|
35 #ifdef ERROR_CHECK_GC
|
|
36 int always_gc; /* Debugging hack */
|
|
37 #else
|
|
38 #define always_gc 0
|
|
39 #endif
|
|
40
|
|
41 struct backtrace *backtrace_list;
|
|
42
|
|
43 /* Note: you must always fill in all of the fields in a backtrace structure
|
|
44 before pushing them on the backtrace_list. The profiling code depends
|
|
45 on this. */
|
|
46
|
|
47 #define PUSH_BACKTRACE(bt) do { \
|
|
48 (bt).next = backtrace_list; \
|
|
49 backtrace_list = &(bt); \
|
|
50 } while (0)
|
|
51
|
|
52 #define POP_BACKTRACE(bt) do { \
|
|
53 backtrace_list = (bt).next; \
|
|
54 } while (0)
|
|
55
|
|
56 /* Macros for calling subrs with an argument list whose length is only
|
|
57 known at runtime. See EXFUN and DEFUN for similar hackery. */
|
|
58
|
|
59 #define AV_0(av)
|
|
60 #define AV_1(av) av[0]
|
|
61 #define AV_2(av) AV_1(av), av[1]
|
|
62 #define AV_3(av) AV_2(av), av[2]
|
|
63 #define AV_4(av) AV_3(av), av[3]
|
|
64 #define AV_5(av) AV_4(av), av[4]
|
|
65 #define AV_6(av) AV_5(av), av[5]
|
|
66 #define AV_7(av) AV_6(av), av[6]
|
|
67 #define AV_8(av) AV_7(av), av[7]
|
|
68
|
|
69 #define PRIMITIVE_FUNCALL_1(fn, av, ac) \
|
444
|
70 (((Lisp_Object (*)(EXFUN_##ac)) (fn)) (AV_##ac (av)))
|
428
|
71
|
|
72 /* If subrs take more than 8 arguments, more cases need to be added
|
|
73 to this switch. (But wait - don't do it - if you really need
|
|
74 a SUBR with more than 8 arguments, use max_args == MANY.
|
|
75 See the DEFUN macro in lisp.h) */
|
|
76 #define PRIMITIVE_FUNCALL(rv, fn, av, ac) do { \
|
|
77 void (*PF_fn)(void) = (void (*)(void)) fn; \
|
|
78 Lisp_Object *PF_av = (av); \
|
|
79 switch (ac) \
|
|
80 { \
|
436
|
81 default:rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 0); break; \
|
428
|
82 case 1: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 1); break; \
|
|
83 case 2: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 2); break; \
|
|
84 case 3: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 3); break; \
|
|
85 case 4: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 4); break; \
|
|
86 case 5: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 5); break; \
|
|
87 case 6: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 6); break; \
|
|
88 case 7: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 7); break; \
|
|
89 case 8: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 8); break; \
|
|
90 } \
|
|
91 } while (0)
|
|
92
|
|
93 #define FUNCALL_SUBR(rv, subr, av, ac) \
|
|
94 PRIMITIVE_FUNCALL (rv, subr_function (subr), av, ac);
|
|
95
|
|
96
|
|
97 /* This is the list of current catches (and also condition-cases).
|
|
98 This is a stack: the most recent catch is at the head of the
|
|
99 list. Catches are created by declaring a 'struct catchtag'
|
|
100 locally, filling the .TAG field in with the tag, and doing
|
|
101 a setjmp() on .JMP. Fthrow() will store the value passed
|
|
102 to it in .VAL and longjmp() back to .JMP, back to the function
|
|
103 that established the catch. This will always be either
|
|
104 internal_catch() (catches established internally or through
|
|
105 `catch') or condition_case_1 (condition-cases established
|
|
106 internally or through `condition-case').
|
|
107
|
|
108 The catchtag also records the current position in the
|
|
109 call stack (stored in BACKTRACE_LIST), the current position
|
|
110 in the specpdl stack (used for variable bindings and
|
|
111 unwind-protects), the value of LISP_EVAL_DEPTH, and the
|
|
112 current position in the GCPRO stack. All of these are
|
|
113 restored by Fthrow().
|
|
114 */
|
|
115
|
|
116 struct catchtag *catchlist;
|
|
117
|
|
118 Lisp_Object Qautoload, Qmacro, Qexit;
|
|
119 Lisp_Object Qinteractive, Qcommandp, Qdefun, Qprogn, Qvalues;
|
|
120 Lisp_Object Vquit_flag, Vinhibit_quit;
|
|
121 Lisp_Object Qand_rest, Qand_optional;
|
|
122 Lisp_Object Qdebug_on_error, Qstack_trace_on_error;
|
|
123 Lisp_Object Qdebug_on_signal, Qstack_trace_on_signal;
|
|
124 Lisp_Object Qdebugger;
|
|
125 Lisp_Object Qinhibit_quit;
|
|
126 Lisp_Object Qrun_hooks;
|
|
127 Lisp_Object Qsetq;
|
|
128 Lisp_Object Qdisplay_warning;
|
|
129 Lisp_Object Vpending_warnings, Vpending_warnings_tail;
|
|
130 Lisp_Object Qif;
|
|
131
|
|
132 /* Records whether we want errors to occur. This will be a boolean,
|
|
133 nil (errors OK) or t (no errors). If t, an error will cause a
|
|
134 throw to Qunbound_suspended_errors_tag.
|
|
135
|
|
136 See call_with_suspended_errors(). */
|
|
137 Lisp_Object Vcurrent_error_state;
|
|
138
|
|
139 /* Current warning class when warnings occur, or nil for no warnings.
|
|
140 Only meaningful when Vcurrent_error_state is non-nil.
|
|
141 See call_with_suspended_errors(). */
|
|
142 Lisp_Object Vcurrent_warning_class;
|
|
143
|
793
|
144 /* Current warning level when warnings occur, or nil for no warnings.
|
|
145 Only meaningful when Vcurrent_error_state is non-nil.
|
|
146 See call_with_suspended_errors(). */
|
|
147 Lisp_Object Vcurrent_warning_level;
|
|
148
|
|
149 /* Minimum level at which warnings are logged. Below this, they're ignored
|
|
150 entirely -- not even generated. */
|
|
151 Lisp_Object Vlog_warning_minimum_level;
|
|
152
|
428
|
153 /* Special catch tag used in call_with_suspended_errors(). */
|
|
154 Lisp_Object Qunbound_suspended_errors_tag;
|
|
155
|
|
156 /* Non-nil means record all fset's and provide's, to be undone
|
|
157 if the file being autoloaded is not fully loaded.
|
|
158 They are recorded by being consed onto the front of Vautoload_queue:
|
|
159 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
|
|
160 Lisp_Object Vautoload_queue;
|
|
161
|
|
162 /* Current number of specbindings allocated in specpdl. */
|
|
163 int specpdl_size;
|
|
164
|
|
165 /* Pointer to beginning of specpdl. */
|
|
166 struct specbinding *specpdl;
|
|
167
|
|
168 /* Pointer to first unused element in specpdl. */
|
|
169 struct specbinding *specpdl_ptr;
|
|
170
|
|
171 /* specpdl_ptr - specpdl */
|
|
172 int specpdl_depth_counter;
|
|
173
|
|
174 /* Maximum size allowed for specpdl allocation */
|
458
|
175 Fixnum max_specpdl_size;
|
428
|
176
|
|
177 /* Depth in Lisp evaluations and function calls. */
|
|
178 static int lisp_eval_depth;
|
|
179
|
|
180 /* Maximum allowed depth in Lisp evaluations and function calls. */
|
458
|
181 Fixnum max_lisp_eval_depth;
|
428
|
182
|
|
183 /* Nonzero means enter debugger before next function call */
|
|
184 static int debug_on_next_call;
|
|
185
|
|
186 /* List of conditions (non-nil atom means all) which cause a backtrace
|
|
187 if an error is handled by the command loop's error handler. */
|
|
188 Lisp_Object Vstack_trace_on_error;
|
|
189
|
|
190 /* List of conditions (non-nil atom means all) which enter the debugger
|
|
191 if an error is handled by the command loop's error handler. */
|
|
192 Lisp_Object Vdebug_on_error;
|
|
193
|
|
194 /* List of conditions and regexps specifying error messages which
|
|
195 do not enter the debugger even if Vdebug_on_error says they should. */
|
|
196 Lisp_Object Vdebug_ignored_errors;
|
|
197
|
|
198 /* List of conditions (non-nil atom means all) which cause a backtrace
|
|
199 if any error is signalled. */
|
|
200 Lisp_Object Vstack_trace_on_signal;
|
|
201
|
|
202 /* List of conditions (non-nil atom means all) which enter the debugger
|
|
203 if any error is signalled. */
|
|
204 Lisp_Object Vdebug_on_signal;
|
|
205
|
|
206 /* Nonzero means enter debugger if a quit signal
|
|
207 is handled by the command loop's error handler.
|
|
208
|
|
209 From lisp, this is a boolean variable and may have the values 0 and 1.
|
|
210 But, eval.c temporarily uses the second bit of this variable to indicate
|
|
211 that a critical_quit is in progress. The second bit is reset immediately
|
|
212 after it is processed in signal_call_debugger(). */
|
|
213 int debug_on_quit;
|
|
214
|
|
215 #if 0 /* FSFmacs */
|
|
216 /* entering_debugger is basically equivalent */
|
|
217 /* The value of num_nonmacro_input_chars as of the last time we
|
|
218 started to enter the debugger. If we decide to enter the debugger
|
|
219 again when this is still equal to num_nonmacro_input_chars, then we
|
|
220 know that the debugger itself has an error, and we should just
|
|
221 signal the error instead of entering an infinite loop of debugger
|
|
222 invocations. */
|
|
223 int when_entered_debugger;
|
|
224 #endif
|
|
225
|
|
226 /* Nonzero means we are trying to enter the debugger.
|
|
227 This is to prevent recursive attempts.
|
|
228 Cleared by the debugger calling Fbacktrace */
|
|
229 static int entering_debugger;
|
|
230
|
|
231 /* Function to call to invoke the debugger */
|
|
232 Lisp_Object Vdebugger;
|
|
233
|
|
234 /* Chain of condition handlers currently in effect.
|
|
235 The elements of this chain are contained in the stack frames
|
|
236 of Fcondition_case and internal_condition_case.
|
|
237 When an error is signaled (by calling Fsignal, below),
|
|
238 this chain is searched for an element that applies.
|
|
239
|
|
240 Each element of this list is one of the following:
|
|
241
|
|
242 A list of a handler function and possibly args to pass to
|
|
243 the function. This is a handler established with
|
|
244 `call-with-condition-handler' (q.v.).
|
|
245
|
|
246 A list whose car is Qunbound and whose cdr is Qt.
|
|
247 This is a special condition-case handler established
|
|
248 by C code with condition_case_1(). All errors are
|
|
249 trapped; the debugger is not invoked even if
|
|
250 `debug-on-error' was set.
|
|
251
|
|
252 A list whose car is Qunbound and whose cdr is Qerror.
|
|
253 This is a special condition-case handler established
|
|
254 by C code with condition_case_1(). It is like Qt
|
|
255 except that the debugger is invoked normally if it is
|
|
256 called for.
|
|
257
|
|
258 A list whose car is Qunbound and whose cdr is a list
|
|
259 of lists (CONDITION-NAME BODY ...) exactly as in
|
|
260 `condition-case'. This is a normal `condition-case'
|
|
261 handler.
|
|
262
|
|
263 Note that in all cases *except* the first, there is a
|
|
264 corresponding catch, whose TAG is the value of
|
|
265 Vcondition_handlers just after the handler data just
|
|
266 described is pushed onto it. The reason is that
|
|
267 `condition-case' handlers need to throw back to the
|
|
268 place where the handler was installed before invoking
|
|
269 it, while `call-with-condition-handler' handlers are
|
|
270 invoked in the environment that `signal' was invoked
|
|
271 in.
|
|
272 */
|
|
273 static Lisp_Object Vcondition_handlers;
|
|
274
|
|
275
|
442
|
276 #define DEFEND_AGAINST_THROW_RECURSION
|
|
277
|
|
278 #ifdef DEFEND_AGAINST_THROW_RECURSION
|
428
|
279 /* Used for error catching purposes by throw_or_bomb_out */
|
|
280 static int throw_level;
|
442
|
281 #endif
|
|
282
|
800
|
283 #ifdef ERROR_CHECK_STRUCTURES
|
|
284 static void check_error_state_sanity (void);
|
|
285 #define CHECK_ERROR_STATE_SANITY() check_error_state_sanity ()
|
|
286 #else
|
|
287 #define CHECK_ERROR_STATE_SANITY()
|
442
|
288 #endif
|
428
|
289
|
|
290
|
|
291 /************************************************************************/
|
|
292 /* The subr object type */
|
|
293 /************************************************************************/
|
|
294
|
|
295 static void
|
|
296 print_subr (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
297 {
|
|
298 Lisp_Subr *subr = XSUBR (obj);
|
665
|
299 const CIntbyte *header =
|
428
|
300 (subr->max_args == UNEVALLED) ? "#<special-form " : "#<subr ";
|
665
|
301 const CIntbyte *name = subr_name (subr);
|
|
302 const CIntbyte *trailer = subr->prompt ? " (interactive)>" : ">";
|
428
|
303
|
|
304 if (print_readably)
|
563
|
305 printing_unreadable_object ("%s%s%s", header, name, trailer);
|
428
|
306
|
|
307 write_c_string (header, printcharfun);
|
|
308 write_c_string (name, printcharfun);
|
|
309 write_c_string (trailer, printcharfun);
|
|
310 }
|
|
311
|
|
312 static const struct lrecord_description subr_description[] = {
|
440
|
313 { XD_DOC_STRING, offsetof (Lisp_Subr, doc) },
|
428
|
314 { XD_END }
|
|
315 };
|
|
316
|
|
317 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("subr", subr,
|
442
|
318 0, print_subr, 0, 0, 0,
|
428
|
319 subr_description,
|
|
320 Lisp_Subr);
|
|
321
|
|
322 /************************************************************************/
|
|
323 /* Entering the debugger */
|
|
324 /************************************************************************/
|
|
325
|
|
326 /* unwind-protect used by call_debugger() to restore the value of
|
|
327 entering_debugger. (We cannot use specbind() because the
|
|
328 variable is not Lisp-accessible.) */
|
|
329
|
|
330 static Lisp_Object
|
|
331 restore_entering_debugger (Lisp_Object arg)
|
|
332 {
|
|
333 entering_debugger = ! NILP (arg);
|
|
334 return arg;
|
|
335 }
|
|
336
|
|
337 /* Actually call the debugger. ARG is a list of args that will be
|
|
338 passed to the debugger function, as follows;
|
|
339
|
|
340 If due to frame exit, args are `exit' and the value being returned;
|
|
341 this function's value will be returned instead of that.
|
|
342 If due to error, args are `error' and a list of the args to `signal'.
|
|
343 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
344 If due to `eval' entry, one arg, t.
|
|
345
|
|
346 */
|
|
347
|
|
348 static Lisp_Object
|
|
349 call_debugger_259 (Lisp_Object arg)
|
|
350 {
|
|
351 return apply1 (Vdebugger, arg);
|
|
352 }
|
|
353
|
|
354 /* Call the debugger, doing some encapsulation. We make sure we have
|
|
355 some room on the eval and specpdl stacks, and bind entering_debugger
|
|
356 to 1 during this call. This is used to trap errors that may occur
|
|
357 when entering the debugger (e.g. the value of `debugger' is invalid),
|
|
358 so that the debugger will not be recursively entered if debug-on-error
|
|
359 is set. (Otherwise, XEmacs would infinitely recurse, attempting to
|
|
360 enter the debugger.) entering_debugger gets reset to 0 as soon
|
|
361 as a backtrace is displayed, so that further errors can indeed be
|
|
362 handled normally.
|
|
363
|
|
364 We also establish a catch for 'debugger. If the debugger function
|
|
365 throws to this instead of returning a value, it means that the user
|
|
366 pressed 'c' (pretend like the debugger was never entered). The
|
|
367 function then returns Qunbound. (If the user pressed 'r', for
|
|
368 return a value, then the debugger function returns normally with
|
|
369 this value.)
|
|
370
|
|
371 The difference between 'c' and 'r' is as follows:
|
|
372
|
|
373 debug-on-call:
|
|
374 No difference. The call proceeds as normal.
|
|
375 debug-on-exit:
|
|
376 With 'r', the specified value is returned as the function's
|
|
377 return value. With 'c', the value that would normally be
|
|
378 returned is returned.
|
|
379 signal:
|
|
380 With 'r', the specified value is returned as the return
|
|
381 value of `signal'. (This is the only time that `signal'
|
|
382 can return, instead of making a non-local exit.) With `c',
|
|
383 `signal' will continue looking for handlers as if the
|
|
384 debugger was never entered, and will probably end up
|
|
385 throwing to a handler or to top-level.
|
|
386 */
|
|
387
|
|
388 static Lisp_Object
|
|
389 call_debugger (Lisp_Object arg)
|
|
390 {
|
|
391 int threw;
|
|
392 Lisp_Object val;
|
|
393 int speccount;
|
|
394
|
|
395 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
|
|
396 max_lisp_eval_depth = lisp_eval_depth + 20;
|
|
397 if (specpdl_size + 40 > max_specpdl_size)
|
|
398 max_specpdl_size = specpdl_size + 40;
|
|
399 debug_on_next_call = 0;
|
|
400
|
|
401 speccount = specpdl_depth();
|
|
402 record_unwind_protect (restore_entering_debugger,
|
|
403 (entering_debugger ? Qt : Qnil));
|
|
404 entering_debugger = 1;
|
|
405 val = internal_catch (Qdebugger, call_debugger_259, arg, &threw);
|
|
406
|
771
|
407 return unbind_to_1 (speccount, ((threw)
|
428
|
408 ? Qunbound /* Not returning a value */
|
|
409 : val));
|
|
410 }
|
|
411
|
|
412 /* Called when debug-on-exit behavior is called for. Enter the debugger
|
|
413 with the appropriate args for this. VAL is the exit value that is
|
|
414 about to be returned. */
|
|
415
|
|
416 static Lisp_Object
|
|
417 do_debug_on_exit (Lisp_Object val)
|
|
418 {
|
|
419 /* This is falsified by call_debugger */
|
|
420 Lisp_Object v = call_debugger (list2 (Qexit, val));
|
|
421
|
|
422 return !UNBOUNDP (v) ? v : val;
|
|
423 }
|
|
424
|
|
425 /* Called when debug-on-call behavior is called for. Enter the debugger
|
|
426 with the appropriate args for this. VAL is either t for a call
|
|
427 through `eval' or 'lambda for a call through `funcall'.
|
|
428
|
|
429 #### The differentiation here between EVAL and FUNCALL is bogus.
|
|
430 FUNCALL can be defined as
|
|
431
|
|
432 (defmacro func (fun &rest args)
|
|
433 (cons (eval fun) args))
|
|
434
|
|
435 and should be treated as such.
|
|
436 */
|
|
437
|
|
438 static void
|
|
439 do_debug_on_call (Lisp_Object code)
|
|
440 {
|
|
441 debug_on_next_call = 0;
|
|
442 backtrace_list->debug_on_exit = 1;
|
|
443 call_debugger (list1 (code));
|
|
444 }
|
|
445
|
|
446 /* LIST is the value of one of the variables `debug-on-error',
|
|
447 `debug-on-signal', `stack-trace-on-error', or `stack-trace-on-signal',
|
|
448 and CONDITIONS is the list of error conditions associated with
|
|
449 the error being signalled. This returns non-nil if LIST
|
|
450 matches CONDITIONS. (A nil value for LIST does not match
|
|
451 CONDITIONS. A non-list value for LIST does match CONDITIONS.
|
|
452 A list matches CONDITIONS when one of the symbols in LIST is the
|
|
453 same as one of the symbols in CONDITIONS.) */
|
|
454
|
|
455 static int
|
|
456 wants_debugger (Lisp_Object list, Lisp_Object conditions)
|
|
457 {
|
|
458 if (NILP (list))
|
|
459 return 0;
|
|
460 if (! CONSP (list))
|
|
461 return 1;
|
|
462
|
|
463 while (CONSP (conditions))
|
|
464 {
|
|
465 Lisp_Object this, tail;
|
|
466 this = XCAR (conditions);
|
|
467 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
468 if (EQ (XCAR (tail), this))
|
|
469 return 1;
|
|
470 conditions = XCDR (conditions);
|
|
471 }
|
|
472 return 0;
|
|
473 }
|
|
474
|
|
475
|
|
476 /* Return 1 if an error with condition-symbols CONDITIONS,
|
|
477 and described by SIGNAL-DATA, should skip the debugger
|
|
478 according to debugger-ignore-errors. */
|
|
479
|
|
480 static int
|
|
481 skip_debugger (Lisp_Object conditions, Lisp_Object data)
|
|
482 {
|
|
483 /* This function can GC */
|
|
484 Lisp_Object tail;
|
|
485 int first_string = 1;
|
|
486 Lisp_Object error_message = Qnil;
|
|
487
|
|
488 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
|
|
489 {
|
|
490 if (STRINGP (XCAR (tail)))
|
|
491 {
|
|
492 if (first_string)
|
|
493 {
|
|
494 error_message = Ferror_message_string (data);
|
|
495 first_string = 0;
|
|
496 }
|
|
497 if (fast_lisp_string_match (XCAR (tail), error_message) >= 0)
|
|
498 return 1;
|
|
499 }
|
|
500 else
|
|
501 {
|
|
502 Lisp_Object contail;
|
|
503
|
|
504 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
|
|
505 if (EQ (XCAR (tail), XCAR (contail)))
|
|
506 return 1;
|
|
507 }
|
|
508 }
|
|
509
|
|
510 return 0;
|
|
511 }
|
|
512
|
|
513 /* Actually generate a backtrace on STREAM. */
|
|
514
|
|
515 static Lisp_Object
|
|
516 backtrace_259 (Lisp_Object stream)
|
|
517 {
|
|
518 return Fbacktrace (stream, Qt);
|
|
519 }
|
|
520
|
|
521 /* An error was signaled. Maybe call the debugger, if the `debug-on-error'
|
|
522 etc. variables call for this. CONDITIONS is the list of conditions
|
|
523 associated with the error being signalled. SIG is the actual error
|
|
524 being signalled, and DATA is the associated data (these are exactly
|
|
525 the same as the arguments to `signal'). ACTIVE_HANDLERS is the
|
|
526 list of error handlers that are to be put in place while the debugger
|
|
527 is called. This is generally the remaining handlers that are
|
|
528 outside of the innermost handler trapping this error. This way,
|
|
529 if the same error occurs inside of the debugger, you usually don't get
|
|
530 the debugger entered recursively.
|
|
531
|
|
532 This function returns Qunbound if it didn't call the debugger or if
|
|
533 the user asked (through 'c') that XEmacs should pretend like the
|
|
534 debugger was never entered. Otherwise, it returns the value
|
|
535 that the user specified with `r'. (Note that much of the time,
|
|
536 the user will abort with C-], and we will never have a chance to
|
|
537 return anything at all.)
|
|
538
|
|
539 SIGNAL_VARS_ONLY means we should only look at debug-on-signal
|
|
540 and stack-trace-on-signal to control whether we do anything.
|
|
541 This is so that debug-on-error doesn't make handled errors
|
|
542 cause the debugger to get invoked.
|
|
543
|
|
544 STACK_TRACE_DISPLAYED and DEBUGGER_ENTERED are used so that
|
|
545 those functions aren't done more than once in a single `signal'
|
|
546 session. */
|
|
547
|
|
548 static Lisp_Object
|
|
549 signal_call_debugger (Lisp_Object conditions,
|
|
550 Lisp_Object sig, Lisp_Object data,
|
|
551 Lisp_Object active_handlers,
|
|
552 int signal_vars_only,
|
|
553 int *stack_trace_displayed,
|
|
554 int *debugger_entered)
|
|
555 {
|
|
556 /* This function can GC */
|
|
557 Lisp_Object val = Qunbound;
|
|
558 Lisp_Object all_handlers = Vcondition_handlers;
|
|
559 Lisp_Object temp_data = Qnil;
|
|
560 int speccount = specpdl_depth();
|
|
561 struct gcpro gcpro1, gcpro2;
|
|
562 GCPRO2 (all_handlers, temp_data);
|
|
563
|
|
564 Vcondition_handlers = active_handlers;
|
|
565
|
|
566 temp_data = Fcons (sig, data); /* needed for skip_debugger */
|
|
567
|
|
568 if (!entering_debugger && !*stack_trace_displayed && !signal_vars_only
|
|
569 && wants_debugger (Vstack_trace_on_error, conditions)
|
|
570 && !skip_debugger (conditions, temp_data))
|
|
571 {
|
|
572 specbind (Qdebug_on_error, Qnil);
|
|
573 specbind (Qstack_trace_on_error, Qnil);
|
|
574 specbind (Qdebug_on_signal, Qnil);
|
|
575 specbind (Qstack_trace_on_signal, Qnil);
|
|
576
|
442
|
577 if (!noninteractive)
|
|
578 internal_with_output_to_temp_buffer (build_string ("*Backtrace*"),
|
|
579 backtrace_259,
|
|
580 Qnil,
|
|
581 Qnil);
|
|
582 else /* in batch mode, we want this going to stderr. */
|
|
583 backtrace_259 (Qnil);
|
771
|
584 unbind_to (speccount);
|
428
|
585 *stack_trace_displayed = 1;
|
|
586 }
|
|
587
|
|
588 if (!entering_debugger && !*debugger_entered && !signal_vars_only
|
|
589 && (EQ (sig, Qquit)
|
|
590 ? debug_on_quit
|
|
591 : wants_debugger (Vdebug_on_error, conditions))
|
|
592 && !skip_debugger (conditions, temp_data))
|
|
593 {
|
|
594 debug_on_quit &= ~2; /* reset critical bit */
|
|
595 specbind (Qdebug_on_error, Qnil);
|
|
596 specbind (Qstack_trace_on_error, Qnil);
|
|
597 specbind (Qdebug_on_signal, Qnil);
|
|
598 specbind (Qstack_trace_on_signal, Qnil);
|
|
599
|
|
600 val = call_debugger (list2 (Qerror, (Fcons (sig, data))));
|
|
601 *debugger_entered = 1;
|
|
602 }
|
|
603
|
|
604 if (!entering_debugger && !*stack_trace_displayed
|
|
605 && wants_debugger (Vstack_trace_on_signal, conditions))
|
|
606 {
|
|
607 specbind (Qdebug_on_error, Qnil);
|
|
608 specbind (Qstack_trace_on_error, Qnil);
|
|
609 specbind (Qdebug_on_signal, Qnil);
|
|
610 specbind (Qstack_trace_on_signal, Qnil);
|
|
611
|
442
|
612 if (!noninteractive)
|
|
613 internal_with_output_to_temp_buffer (build_string ("*Backtrace*"),
|
|
614 backtrace_259,
|
|
615 Qnil,
|
|
616 Qnil);
|
|
617 else /* in batch mode, we want this going to stderr. */
|
|
618 backtrace_259 (Qnil);
|
771
|
619 unbind_to (speccount);
|
428
|
620 *stack_trace_displayed = 1;
|
|
621 }
|
|
622
|
|
623 if (!entering_debugger && !*debugger_entered
|
|
624 && (EQ (sig, Qquit)
|
|
625 ? debug_on_quit
|
|
626 : wants_debugger (Vdebug_on_signal, conditions)))
|
|
627 {
|
|
628 debug_on_quit &= ~2; /* reset critical bit */
|
|
629 specbind (Qdebug_on_error, Qnil);
|
|
630 specbind (Qstack_trace_on_error, Qnil);
|
|
631 specbind (Qdebug_on_signal, Qnil);
|
|
632 specbind (Qstack_trace_on_signal, Qnil);
|
|
633
|
|
634 val = call_debugger (list2 (Qerror, (Fcons (sig, data))));
|
|
635 *debugger_entered = 1;
|
|
636 }
|
|
637
|
|
638 UNGCPRO;
|
|
639 Vcondition_handlers = all_handlers;
|
771
|
640 return unbind_to_1 (speccount, val);
|
428
|
641 }
|
|
642
|
|
643
|
|
644 /************************************************************************/
|
|
645 /* The basic special forms */
|
|
646 /************************************************************************/
|
|
647
|
|
648 /* Except for Fprogn(), the basic special forms below are only called
|
|
649 from interpreted code. The byte compiler turns them into bytecodes. */
|
|
650
|
|
651 DEFUN ("or", For, 0, UNEVALLED, 0, /*
|
|
652 Eval args until one of them yields non-nil, then return that value.
|
|
653 The remaining args are not evalled at all.
|
|
654 If all args return nil, return nil.
|
|
655 */
|
|
656 (args))
|
|
657 {
|
|
658 /* This function can GC */
|
442
|
659 REGISTER Lisp_Object val;
|
428
|
660
|
|
661 LIST_LOOP_2 (arg, args)
|
|
662 {
|
|
663 if (!NILP (val = Feval (arg)))
|
|
664 return val;
|
|
665 }
|
|
666
|
|
667 return Qnil;
|
|
668 }
|
|
669
|
|
670 DEFUN ("and", Fand, 0, UNEVALLED, 0, /*
|
|
671 Eval args until one of them yields nil, then return nil.
|
|
672 The remaining args are not evalled at all.
|
|
673 If no arg yields nil, return the last arg's value.
|
|
674 */
|
|
675 (args))
|
|
676 {
|
|
677 /* This function can GC */
|
442
|
678 REGISTER Lisp_Object val = Qt;
|
428
|
679
|
|
680 LIST_LOOP_2 (arg, args)
|
|
681 {
|
|
682 if (NILP (val = Feval (arg)))
|
|
683 return val;
|
|
684 }
|
|
685
|
|
686 return val;
|
|
687 }
|
|
688
|
|
689 DEFUN ("if", Fif, 2, UNEVALLED, 0, /*
|
|
690 \(if COND THEN ELSE...): if COND yields non-nil, do THEN, else do ELSE...
|
|
691 Returns the value of THEN or the value of the last of the ELSE's.
|
|
692 THEN must be one expression, but ELSE... can be zero or more expressions.
|
|
693 If COND yields nil, and there are no ELSE's, the value is nil.
|
|
694 */
|
|
695 (args))
|
|
696 {
|
|
697 /* This function can GC */
|
|
698 Lisp_Object condition = XCAR (args);
|
|
699 Lisp_Object then_form = XCAR (XCDR (args));
|
|
700 Lisp_Object else_forms = XCDR (XCDR (args));
|
|
701
|
|
702 if (!NILP (Feval (condition)))
|
|
703 return Feval (then_form);
|
|
704 else
|
|
705 return Fprogn (else_forms);
|
|
706 }
|
|
707
|
|
708 /* Macros `when' and `unless' are trivially defined in Lisp,
|
|
709 but it helps for bootstrapping to have them ALWAYS defined. */
|
|
710
|
|
711 DEFUN ("when", Fwhen, 1, MANY, 0, /*
|
|
712 \(when COND BODY...): if COND yields non-nil, do BODY, else return nil.
|
|
713 BODY can be zero or more expressions. If BODY is nil, return nil.
|
|
714 */
|
|
715 (int nargs, Lisp_Object *args))
|
|
716 {
|
|
717 Lisp_Object cond = args[0];
|
|
718 Lisp_Object body;
|
|
719
|
|
720 switch (nargs)
|
|
721 {
|
|
722 case 1: body = Qnil; break;
|
|
723 case 2: body = args[1]; break;
|
|
724 default: body = Fcons (Qprogn, Flist (nargs-1, args+1)); break;
|
|
725 }
|
|
726
|
|
727 return list3 (Qif, cond, body);
|
|
728 }
|
|
729
|
|
730 DEFUN ("unless", Funless, 1, MANY, 0, /*
|
|
731 \(unless COND BODY...): if COND yields nil, do BODY, else return nil.
|
|
732 BODY can be zero or more expressions. If BODY is nil, return nil.
|
|
733 */
|
|
734 (int nargs, Lisp_Object *args))
|
|
735 {
|
|
736 Lisp_Object cond = args[0];
|
|
737 Lisp_Object body = Flist (nargs-1, args+1);
|
|
738 return Fcons (Qif, Fcons (cond, Fcons (Qnil, body)));
|
|
739 }
|
|
740
|
|
741 DEFUN ("cond", Fcond, 0, UNEVALLED, 0, /*
|
444
|
742 \(cond CLAUSES...): try each clause until one succeeds.
|
428
|
743 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
|
|
744 and, if the value is non-nil, this clause succeeds:
|
|
745 then the expressions in BODY are evaluated and the last one's
|
|
746 value is the value of the cond-form.
|
|
747 If no clause succeeds, cond returns nil.
|
|
748 If a clause has one element, as in (CONDITION),
|
|
749 CONDITION's value if non-nil is returned from the cond-form.
|
|
750 */
|
|
751 (args))
|
|
752 {
|
|
753 /* This function can GC */
|
442
|
754 REGISTER Lisp_Object val;
|
428
|
755
|
|
756 LIST_LOOP_2 (clause, args)
|
|
757 {
|
|
758 CHECK_CONS (clause);
|
|
759 if (!NILP (val = Feval (XCAR (clause))))
|
|
760 {
|
|
761 if (!NILP (clause = XCDR (clause)))
|
|
762 {
|
|
763 CHECK_TRUE_LIST (clause);
|
|
764 val = Fprogn (clause);
|
|
765 }
|
|
766 return val;
|
|
767 }
|
|
768 }
|
|
769
|
|
770 return Qnil;
|
|
771 }
|
|
772
|
|
773 DEFUN ("progn", Fprogn, 0, UNEVALLED, 0, /*
|
|
774 \(progn BODY...): eval BODY forms sequentially and return value of last one.
|
|
775 */
|
|
776 (args))
|
|
777 {
|
|
778 /* This function can GC */
|
|
779 /* Caller must provide a true list in ARGS */
|
442
|
780 REGISTER Lisp_Object val = Qnil;
|
428
|
781 struct gcpro gcpro1;
|
|
782
|
|
783 GCPRO1 (args);
|
|
784
|
|
785 {
|
|
786 LIST_LOOP_2 (form, args)
|
|
787 val = Feval (form);
|
|
788 }
|
|
789
|
|
790 UNGCPRO;
|
|
791 return val;
|
|
792 }
|
|
793
|
|
794 /* Fprog1() is the canonical example of a function that must GCPRO a
|
|
795 Lisp_Object across calls to Feval(). */
|
|
796
|
|
797 DEFUN ("prog1", Fprog1, 1, UNEVALLED, 0, /*
|
|
798 Similar to `progn', but the value of the first form is returned.
|
|
799 \(prog1 FIRST BODY...): All the arguments are evaluated sequentially.
|
|
800 The value of FIRST is saved during evaluation of the remaining args,
|
|
801 whose values are discarded.
|
|
802 */
|
|
803 (args))
|
|
804 {
|
|
805 /* This function can GC */
|
442
|
806 REGISTER Lisp_Object val;
|
428
|
807 struct gcpro gcpro1;
|
|
808
|
|
809 val = Feval (XCAR (args));
|
|
810
|
|
811 GCPRO1 (val);
|
|
812
|
|
813 {
|
|
814 LIST_LOOP_2 (form, XCDR (args))
|
|
815 Feval (form);
|
|
816 }
|
|
817
|
|
818 UNGCPRO;
|
|
819 return val;
|
|
820 }
|
|
821
|
|
822 DEFUN ("prog2", Fprog2, 2, UNEVALLED, 0, /*
|
|
823 Similar to `progn', but the value of the second form is returned.
|
|
824 \(prog2 FIRST SECOND BODY...): All the arguments are evaluated sequentially.
|
|
825 The value of SECOND is saved during evaluation of the remaining args,
|
|
826 whose values are discarded.
|
|
827 */
|
|
828 (args))
|
|
829 {
|
|
830 /* This function can GC */
|
442
|
831 REGISTER Lisp_Object val;
|
428
|
832 struct gcpro gcpro1;
|
|
833
|
|
834 Feval (XCAR (args));
|
|
835 args = XCDR (args);
|
|
836 val = Feval (XCAR (args));
|
|
837 args = XCDR (args);
|
|
838
|
|
839 GCPRO1 (val);
|
|
840
|
442
|
841 {
|
|
842 LIST_LOOP_2 (form, args)
|
|
843 Feval (form);
|
|
844 }
|
428
|
845
|
|
846 UNGCPRO;
|
|
847 return val;
|
|
848 }
|
|
849
|
|
850 DEFUN ("let*", FletX, 1, UNEVALLED, 0, /*
|
|
851 \(let* VARLIST BODY...): bind variables according to VARLIST then eval BODY.
|
|
852 The value of the last form in BODY is returned.
|
|
853 Each element of VARLIST is a symbol (which is bound to nil)
|
|
854 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
|
|
855 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
|
|
856 */
|
|
857 (args))
|
|
858 {
|
|
859 /* This function can GC */
|
|
860 Lisp_Object varlist = XCAR (args);
|
|
861 Lisp_Object body = XCDR (args);
|
|
862 int speccount = specpdl_depth();
|
|
863
|
|
864 EXTERNAL_LIST_LOOP_3 (var, varlist, tail)
|
|
865 {
|
|
866 Lisp_Object symbol, value, tem;
|
|
867 if (SYMBOLP (var))
|
|
868 symbol = var, value = Qnil;
|
|
869 else
|
|
870 {
|
|
871 CHECK_CONS (var);
|
|
872 symbol = XCAR (var);
|
|
873 tem = XCDR (var);
|
|
874 if (NILP (tem))
|
|
875 value = Qnil;
|
|
876 else
|
|
877 {
|
|
878 CHECK_CONS (tem);
|
|
879 value = Feval (XCAR (tem));
|
|
880 if (!NILP (XCDR (tem)))
|
563
|
881 sferror
|
428
|
882 ("`let' bindings can have only one value-form", var);
|
|
883 }
|
|
884 }
|
|
885 specbind (symbol, value);
|
|
886 }
|
771
|
887 return unbind_to_1 (speccount, Fprogn (body));
|
428
|
888 }
|
|
889
|
|
890 DEFUN ("let", Flet, 1, UNEVALLED, 0, /*
|
|
891 \(let VARLIST BODY...): bind variables according to VARLIST then eval BODY.
|
|
892 The value of the last form in BODY is returned.
|
|
893 Each element of VARLIST is a symbol (which is bound to nil)
|
|
894 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
|
|
895 All the VALUEFORMs are evalled before any symbols are bound.
|
|
896 */
|
|
897 (args))
|
|
898 {
|
|
899 /* This function can GC */
|
|
900 Lisp_Object varlist = XCAR (args);
|
|
901 Lisp_Object body = XCDR (args);
|
|
902 int speccount = specpdl_depth();
|
|
903 Lisp_Object *temps;
|
|
904 int idx;
|
|
905 struct gcpro gcpro1;
|
|
906
|
|
907 /* Make space to hold the values to give the bound variables. */
|
|
908 {
|
|
909 int varcount;
|
|
910 GET_EXTERNAL_LIST_LENGTH (varlist, varcount);
|
|
911 temps = alloca_array (Lisp_Object, varcount);
|
|
912 }
|
|
913
|
|
914 /* Compute the values and store them in `temps' */
|
|
915 GCPRO1 (*temps);
|
|
916 gcpro1.nvars = 0;
|
|
917
|
|
918 idx = 0;
|
442
|
919 {
|
|
920 LIST_LOOP_2 (var, varlist)
|
|
921 {
|
|
922 Lisp_Object *value = &temps[idx++];
|
|
923 if (SYMBOLP (var))
|
|
924 *value = Qnil;
|
|
925 else
|
|
926 {
|
|
927 Lisp_Object tem;
|
|
928 CHECK_CONS (var);
|
|
929 tem = XCDR (var);
|
|
930 if (NILP (tem))
|
|
931 *value = Qnil;
|
|
932 else
|
|
933 {
|
|
934 CHECK_CONS (tem);
|
|
935 *value = Feval (XCAR (tem));
|
|
936 gcpro1.nvars = idx;
|
|
937
|
|
938 if (!NILP (XCDR (tem)))
|
563
|
939 sferror
|
442
|
940 ("`let' bindings can have only one value-form", var);
|
|
941 }
|
|
942 }
|
|
943 }
|
|
944 }
|
428
|
945
|
|
946 idx = 0;
|
442
|
947 {
|
|
948 LIST_LOOP_2 (var, varlist)
|
|
949 {
|
|
950 specbind (SYMBOLP (var) ? var : XCAR (var), temps[idx++]);
|
|
951 }
|
|
952 }
|
428
|
953
|
|
954 UNGCPRO;
|
|
955
|
771
|
956 return unbind_to_1 (speccount, Fprogn (body));
|
428
|
957 }
|
|
958
|
|
959 DEFUN ("while", Fwhile, 1, UNEVALLED, 0, /*
|
|
960 \(while TEST BODY...): if TEST yields non-nil, eval BODY... and repeat.
|
|
961 The order of execution is thus TEST, BODY, TEST, BODY and so on
|
|
962 until TEST returns nil.
|
|
963 */
|
|
964 (args))
|
|
965 {
|
|
966 /* This function can GC */
|
|
967 Lisp_Object test = XCAR (args);
|
|
968 Lisp_Object body = XCDR (args);
|
|
969
|
|
970 while (!NILP (Feval (test)))
|
|
971 {
|
|
972 QUIT;
|
|
973 Fprogn (body);
|
|
974 }
|
|
975
|
|
976 return Qnil;
|
|
977 }
|
|
978
|
|
979 DEFUN ("setq", Fsetq, 0, UNEVALLED, 0, /*
|
|
980 \(setq SYM VAL SYM VAL ...): set each SYM to the value of its VAL.
|
|
981 The symbols SYM are variables; they are literal (not evaluated).
|
|
982 The values VAL are expressions; they are evaluated.
|
|
983 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
|
|
984 The second VAL is not computed until after the first SYM is set, and so on;
|
|
985 each VAL can use the new value of variables set earlier in the `setq'.
|
|
986 The return value of the `setq' form is the value of the last VAL.
|
|
987 */
|
|
988 (args))
|
|
989 {
|
|
990 /* This function can GC */
|
|
991 Lisp_Object symbol, tail, val = Qnil;
|
|
992 int nargs;
|
|
993 struct gcpro gcpro1;
|
|
994
|
|
995 GET_LIST_LENGTH (args, nargs);
|
|
996
|
|
997 if (nargs & 1) /* Odd number of arguments? */
|
|
998 Fsignal (Qwrong_number_of_arguments, list2 (Qsetq, make_int (nargs)));
|
|
999
|
|
1000 GCPRO1 (val);
|
|
1001
|
|
1002 PROPERTY_LIST_LOOP (tail, symbol, val, args)
|
|
1003 {
|
|
1004 val = Feval (val);
|
|
1005 Fset (symbol, val);
|
|
1006 }
|
|
1007
|
|
1008 UNGCPRO;
|
|
1009 return val;
|
|
1010 }
|
|
1011
|
|
1012 DEFUN ("quote", Fquote, 1, UNEVALLED, 0, /*
|
|
1013 Return the argument, without evaluating it. `(quote x)' yields `x'.
|
|
1014 */
|
|
1015 (args))
|
|
1016 {
|
|
1017 return XCAR (args);
|
|
1018 }
|
|
1019
|
|
1020 DEFUN ("function", Ffunction, 1, UNEVALLED, 0, /*
|
|
1021 Like `quote', but preferred for objects which are functions.
|
|
1022 In byte compilation, `function' causes its argument to be compiled.
|
|
1023 `quote' cannot do that.
|
|
1024 */
|
|
1025 (args))
|
|
1026 {
|
|
1027 return XCAR (args);
|
|
1028 }
|
|
1029
|
|
1030
|
|
1031 /************************************************************************/
|
|
1032 /* Defining functions/variables */
|
|
1033 /************************************************************************/
|
|
1034 static Lisp_Object
|
|
1035 define_function (Lisp_Object name, Lisp_Object defn)
|
|
1036 {
|
|
1037 Ffset (name, defn);
|
|
1038 LOADHIST_ATTACH (name);
|
|
1039 return name;
|
|
1040 }
|
|
1041
|
|
1042 DEFUN ("defun", Fdefun, 2, UNEVALLED, 0, /*
|
|
1043 \(defun NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
|
|
1044 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
|
|
1045 See also the function `interactive'.
|
|
1046 */
|
|
1047 (args))
|
|
1048 {
|
|
1049 /* This function can GC */
|
|
1050 return define_function (XCAR (args),
|
|
1051 Fcons (Qlambda, XCDR (args)));
|
|
1052 }
|
|
1053
|
|
1054 DEFUN ("defmacro", Fdefmacro, 2, UNEVALLED, 0, /*
|
|
1055 \(defmacro NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro.
|
|
1056 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).
|
|
1057 When the macro is called, as in (NAME ARGS...),
|
|
1058 the function (lambda ARGLIST BODY...) is applied to
|
|
1059 the list ARGS... as it appears in the expression,
|
|
1060 and the result should be a form to be evaluated instead of the original.
|
|
1061 */
|
|
1062 (args))
|
|
1063 {
|
|
1064 /* This function can GC */
|
|
1065 return define_function (XCAR (args),
|
|
1066 Fcons (Qmacro, Fcons (Qlambda, XCDR (args))));
|
|
1067 }
|
|
1068
|
|
1069 DEFUN ("defvar", Fdefvar, 1, UNEVALLED, 0, /*
|
|
1070 \(defvar SYMBOL INITVALUE DOCSTRING): define SYMBOL as a variable.
|
|
1071 You are not required to define a variable in order to use it,
|
|
1072 but the definition can supply documentation and an initial value
|
|
1073 in a way that tags can recognize.
|
|
1074
|
|
1075 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is
|
|
1076 void. (However, when you evaluate a defvar interactively, it acts like a
|
|
1077 defconst: SYMBOL's value is always set regardless of whether it's currently
|
|
1078 void.)
|
|
1079 If SYMBOL is buffer-local, its default value is what is set;
|
|
1080 buffer-local values are not affected.
|
|
1081 INITVALUE and DOCSTRING are optional.
|
|
1082 If DOCSTRING starts with *, this variable is identified as a user option.
|
442
|
1083 This means that M-x set-variable recognizes it.
|
428
|
1084 If INITVALUE is missing, SYMBOL's value is not set.
|
|
1085
|
|
1086 In lisp-interaction-mode defvar is treated as defconst.
|
|
1087 */
|
|
1088 (args))
|
|
1089 {
|
|
1090 /* This function can GC */
|
|
1091 Lisp_Object sym = XCAR (args);
|
|
1092
|
|
1093 if (!NILP (args = XCDR (args)))
|
|
1094 {
|
|
1095 Lisp_Object val = XCAR (args);
|
|
1096
|
|
1097 if (NILP (Fdefault_boundp (sym)))
|
|
1098 {
|
|
1099 struct gcpro gcpro1;
|
|
1100 GCPRO1 (val);
|
|
1101 val = Feval (val);
|
|
1102 Fset_default (sym, val);
|
|
1103 UNGCPRO;
|
|
1104 }
|
|
1105
|
|
1106 if (!NILP (args = XCDR (args)))
|
|
1107 {
|
|
1108 Lisp_Object doc = XCAR (args);
|
|
1109 Fput (sym, Qvariable_documentation, doc);
|
|
1110 if (!NILP (args = XCDR (args)))
|
563
|
1111 signal_error (Qwrong_number_of_arguments, "too many arguments", Qunbound);
|
428
|
1112 }
|
|
1113 }
|
|
1114
|
|
1115 #ifdef I18N3
|
|
1116 if (!NILP (Vfile_domain))
|
|
1117 Fput (sym, Qvariable_domain, Vfile_domain);
|
|
1118 #endif
|
|
1119
|
|
1120 LOADHIST_ATTACH (sym);
|
|
1121 return sym;
|
|
1122 }
|
|
1123
|
|
1124 DEFUN ("defconst", Fdefconst, 2, UNEVALLED, 0, /*
|
|
1125 \(defconst SYMBOL INITVALUE DOCSTRING): define SYMBOL as a constant
|
|
1126 variable.
|
|
1127 The intent is that programs do not change this value, but users may.
|
|
1128 Always sets the value of SYMBOL to the result of evalling INITVALUE.
|
|
1129 If SYMBOL is buffer-local, its default value is what is set;
|
|
1130 buffer-local values are not affected.
|
|
1131 DOCSTRING is optional.
|
|
1132 If DOCSTRING starts with *, this variable is identified as a user option.
|
442
|
1133 This means that M-x set-variable recognizes it.
|
428
|
1134
|
|
1135 Note: do not use `defconst' for user options in libraries that are not
|
|
1136 normally loaded, since it is useful for users to be able to specify
|
|
1137 their own values for such variables before loading the library.
|
|
1138 Since `defconst' unconditionally assigns the variable,
|
|
1139 it would override the user's choice.
|
|
1140 */
|
|
1141 (args))
|
|
1142 {
|
|
1143 /* This function can GC */
|
|
1144 Lisp_Object sym = XCAR (args);
|
|
1145 Lisp_Object val = Feval (XCAR (args = XCDR (args)));
|
|
1146 struct gcpro gcpro1;
|
|
1147
|
|
1148 GCPRO1 (val);
|
|
1149
|
|
1150 Fset_default (sym, val);
|
|
1151
|
|
1152 UNGCPRO;
|
|
1153
|
|
1154 if (!NILP (args = XCDR (args)))
|
|
1155 {
|
|
1156 Lisp_Object doc = XCAR (args);
|
|
1157 Fput (sym, Qvariable_documentation, doc);
|
|
1158 if (!NILP (args = XCDR (args)))
|
563
|
1159 signal_error (Qwrong_number_of_arguments, "too many arguments", Qunbound);
|
428
|
1160 }
|
|
1161
|
|
1162 #ifdef I18N3
|
|
1163 if (!NILP (Vfile_domain))
|
|
1164 Fput (sym, Qvariable_domain, Vfile_domain);
|
|
1165 #endif
|
|
1166
|
|
1167 LOADHIST_ATTACH (sym);
|
|
1168 return sym;
|
|
1169 }
|
|
1170
|
|
1171 DEFUN ("user-variable-p", Fuser_variable_p, 1, 1, 0, /*
|
|
1172 Return t if VARIABLE is intended to be set and modified by users.
|
|
1173 \(The alternative is a variable used internally in a Lisp program.)
|
|
1174 Determined by whether the first character of the documentation
|
|
1175 for the variable is `*'.
|
|
1176 */
|
|
1177 (variable))
|
|
1178 {
|
|
1179 Lisp_Object documentation = Fget (variable, Qvariable_documentation, Qnil);
|
|
1180
|
|
1181 return
|
|
1182 ((INTP (documentation) && XINT (documentation) < 0) ||
|
|
1183
|
|
1184 (STRINGP (documentation) &&
|
793
|
1185 (XSTRING_BYTE (documentation, 0) == '*')) ||
|
428
|
1186
|
|
1187 /* If (STRING . INTEGER), a negative integer means a user variable. */
|
|
1188 (CONSP (documentation)
|
|
1189 && STRINGP (XCAR (documentation))
|
|
1190 && INTP (XCDR (documentation))
|
|
1191 && XINT (XCDR (documentation)) < 0)) ?
|
|
1192 Qt : Qnil;
|
|
1193 }
|
|
1194
|
|
1195 DEFUN ("macroexpand-internal", Fmacroexpand_internal, 1, 2, 0, /*
|
|
1196 Return result of expanding macros at top level of FORM.
|
|
1197 If FORM is not a macro call, it is returned unchanged.
|
|
1198 Otherwise, the macro is expanded and the expansion is considered
|
|
1199 in place of FORM. When a non-macro-call results, it is returned.
|
|
1200
|
442
|
1201 The second optional arg ENVIRONMENT specifies an environment of macro
|
428
|
1202 definitions to shadow the loaded ones for use in file byte-compilation.
|
|
1203 */
|
442
|
1204 (form, environment))
|
428
|
1205 {
|
|
1206 /* This function can GC */
|
|
1207 /* With cleanups from Hallvard Furuseth. */
|
|
1208 REGISTER Lisp_Object expander, sym, def, tem;
|
|
1209
|
|
1210 while (1)
|
|
1211 {
|
|
1212 /* Come back here each time we expand a macro call,
|
|
1213 in case it expands into another macro call. */
|
|
1214 if (!CONSP (form))
|
|
1215 break;
|
|
1216 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
|
|
1217 def = sym = XCAR (form);
|
|
1218 tem = Qnil;
|
|
1219 /* Trace symbols aliases to other symbols
|
|
1220 until we get a symbol that is not an alias. */
|
|
1221 while (SYMBOLP (def))
|
|
1222 {
|
|
1223 QUIT;
|
|
1224 sym = def;
|
442
|
1225 tem = Fassq (sym, environment);
|
428
|
1226 if (NILP (tem))
|
|
1227 {
|
|
1228 def = XSYMBOL (sym)->function;
|
|
1229 if (!UNBOUNDP (def))
|
|
1230 continue;
|
|
1231 }
|
|
1232 break;
|
|
1233 }
|
442
|
1234 /* Right now TEM is the result from SYM in ENVIRONMENT,
|
428
|
1235 and if TEM is nil then DEF is SYM's function definition. */
|
|
1236 if (NILP (tem))
|
|
1237 {
|
442
|
1238 /* SYM is not mentioned in ENVIRONMENT.
|
428
|
1239 Look at its function definition. */
|
|
1240 if (UNBOUNDP (def)
|
|
1241 || !CONSP (def))
|
|
1242 /* Not defined or definition not suitable */
|
|
1243 break;
|
|
1244 if (EQ (XCAR (def), Qautoload))
|
|
1245 {
|
|
1246 /* Autoloading function: will it be a macro when loaded? */
|
|
1247 tem = Felt (def, make_int (4));
|
|
1248 if (EQ (tem, Qt) || EQ (tem, Qmacro))
|
|
1249 {
|
|
1250 /* Yes, load it and try again. */
|
|
1251 do_autoload (def, sym);
|
|
1252 continue;
|
|
1253 }
|
|
1254 else
|
|
1255 break;
|
|
1256 }
|
|
1257 else if (!EQ (XCAR (def), Qmacro))
|
|
1258 break;
|
|
1259 else expander = XCDR (def);
|
|
1260 }
|
|
1261 else
|
|
1262 {
|
|
1263 expander = XCDR (tem);
|
|
1264 if (NILP (expander))
|
|
1265 break;
|
|
1266 }
|
|
1267 form = apply1 (expander, XCDR (form));
|
|
1268 }
|
|
1269 return form;
|
|
1270 }
|
|
1271
|
|
1272
|
|
1273 /************************************************************************/
|
|
1274 /* Non-local exits */
|
|
1275 /************************************************************************/
|
|
1276
|
|
1277 DEFUN ("catch", Fcatch, 1, UNEVALLED, 0, /*
|
|
1278 \(catch TAG BODY...): eval BODY allowing nonlocal exits using `throw'.
|
|
1279 TAG is evalled to get the tag to use. Then the BODY is executed.
|
|
1280 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
|
|
1281 If no throw happens, `catch' returns the value of the last BODY form.
|
|
1282 If a throw happens, it specifies the value to return from `catch'.
|
|
1283 */
|
|
1284 (args))
|
|
1285 {
|
|
1286 /* This function can GC */
|
|
1287 Lisp_Object tag = Feval (XCAR (args));
|
|
1288 Lisp_Object body = XCDR (args);
|
|
1289 return internal_catch (tag, Fprogn, body, 0);
|
|
1290 }
|
|
1291
|
|
1292 /* Set up a catch, then call C function FUNC on argument ARG.
|
|
1293 FUNC should return a Lisp_Object.
|
|
1294 This is how catches are done from within C code. */
|
|
1295
|
|
1296 Lisp_Object
|
|
1297 internal_catch (Lisp_Object tag,
|
|
1298 Lisp_Object (*func) (Lisp_Object arg),
|
|
1299 Lisp_Object arg,
|
|
1300 int * volatile threw)
|
|
1301 {
|
|
1302 /* This structure is made part of the chain `catchlist'. */
|
|
1303 struct catchtag c;
|
|
1304
|
|
1305 /* Fill in the components of c, and put it on the list. */
|
|
1306 c.next = catchlist;
|
|
1307 c.tag = tag;
|
|
1308 c.val = Qnil;
|
|
1309 c.backlist = backtrace_list;
|
|
1310 #if 0 /* FSFmacs */
|
|
1311 /* #### */
|
|
1312 c.handlerlist = handlerlist;
|
|
1313 #endif
|
|
1314 c.lisp_eval_depth = lisp_eval_depth;
|
|
1315 c.pdlcount = specpdl_depth();
|
|
1316 #if 0 /* FSFmacs */
|
|
1317 c.poll_suppress_count = async_timer_suppress_count;
|
|
1318 #endif
|
|
1319 c.gcpro = gcprolist;
|
|
1320 catchlist = &c;
|
|
1321
|
|
1322 /* Call FUNC. */
|
|
1323 if (SETJMP (c.jmp))
|
|
1324 {
|
|
1325 /* Throw works by a longjmp that comes right here. */
|
|
1326 if (threw) *threw = 1;
|
|
1327 return c.val;
|
|
1328 }
|
|
1329 c.val = (*func) (arg);
|
|
1330 if (threw) *threw = 0;
|
|
1331 catchlist = c.next;
|
800
|
1332 CHECK_ERROR_STATE_SANITY ();
|
428
|
1333 return c.val;
|
|
1334 }
|
|
1335
|
|
1336
|
|
1337 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
|
|
1338 jump to that CATCH, returning VALUE as the value of that catch.
|
|
1339
|
|
1340 This is the guts Fthrow and Fsignal; they differ only in the way
|
|
1341 they choose the catch tag to throw to. A catch tag for a
|
|
1342 condition-case form has a TAG of Qnil.
|
|
1343
|
|
1344 Before each catch is discarded, unbind all special bindings and
|
|
1345 execute all unwind-protect clauses made above that catch. Unwind
|
|
1346 the handler stack as we go, so that the proper handlers are in
|
|
1347 effect for each unwind-protect clause we run. At the end, restore
|
|
1348 some static info saved in CATCH, and longjmp to the location
|
|
1349 specified in the
|
|
1350
|
|
1351 This is used for correct unwinding in Fthrow and Fsignal. */
|
|
1352
|
|
1353 static void
|
|
1354 unwind_to_catch (struct catchtag *c, Lisp_Object val)
|
|
1355 {
|
|
1356 REGISTER int last_time;
|
|
1357
|
|
1358 /* Unwind the specbind, catch, and handler stacks back to CATCH
|
|
1359 Before each catch is discarded, unbind all special bindings
|
|
1360 and execute all unwind-protect clauses made above that catch.
|
|
1361 At the end, restore some static info saved in CATCH,
|
|
1362 and longjmp to the location specified.
|
|
1363 */
|
|
1364
|
|
1365 /* Save the value somewhere it will be GC'ed.
|
|
1366 (Can't overwrite tag slot because an unwind-protect may
|
|
1367 want to throw to this same tag, which isn't yet invalid.) */
|
|
1368 c->val = val;
|
|
1369
|
|
1370 #if 0 /* FSFmacs */
|
|
1371 /* Restore the polling-suppression count. */
|
|
1372 set_poll_suppress_count (catch->poll_suppress_count);
|
|
1373 #endif
|
|
1374
|
617
|
1375 #if 1
|
428
|
1376 do
|
|
1377 {
|
|
1378 last_time = catchlist == c;
|
|
1379
|
|
1380 /* Unwind the specpdl stack, and then restore the proper set of
|
|
1381 handlers. */
|
771
|
1382 unbind_to (catchlist->pdlcount);
|
428
|
1383 catchlist = catchlist->next;
|
800
|
1384 CHECK_ERROR_STATE_SANITY ();
|
428
|
1385 }
|
|
1386 while (! last_time);
|
617
|
1387 #else
|
|
1388 /* Former XEmacs code. This is definitely not as correct because
|
|
1389 there may be a number of catches we're unwinding, and a number
|
|
1390 of unwind-protects in the process. By not undoing the catches till
|
|
1391 the end, there may be invalid catches still current. (This would
|
|
1392 be a particular problem with code like this:
|
|
1393
|
|
1394 (catch 'foo
|
|
1395 (call-some-code-which-does...
|
|
1396 (catch 'bar
|
|
1397 (unwind-protect
|
|
1398 (call-some-code-which-does...
|
|
1399 (catch 'bar
|
|
1400 (call-some-code-which-does...
|
|
1401 (throw 'foo nil))))
|
|
1402 (throw 'bar nil)))))
|
|
1403
|
|
1404 This would try to throw to the inner (catch 'bar)!
|
|
1405
|
|
1406 --ben
|
|
1407 */
|
428
|
1408 /* Unwind the specpdl stack */
|
771
|
1409 unbind_to (c->pdlcount);
|
428
|
1410 catchlist = c->next;
|
800
|
1411 CHECK_ERROR_STATE_SANITY ();
|
617
|
1412 #endif /* Former code */
|
428
|
1413
|
|
1414 gcprolist = c->gcpro;
|
|
1415 backtrace_list = c->backlist;
|
|
1416 lisp_eval_depth = c->lisp_eval_depth;
|
|
1417
|
442
|
1418 #ifdef DEFEND_AGAINST_THROW_RECURSION
|
428
|
1419 throw_level = 0;
|
|
1420 #endif
|
|
1421 LONGJMP (c->jmp, 1);
|
|
1422 }
|
|
1423
|
|
1424 static DOESNT_RETURN
|
|
1425 throw_or_bomb_out (Lisp_Object tag, Lisp_Object val, int bomb_out_p,
|
|
1426 Lisp_Object sig, Lisp_Object data)
|
|
1427 {
|
442
|
1428 #ifdef DEFEND_AGAINST_THROW_RECURSION
|
428
|
1429 /* die if we recurse more than is reasonable */
|
|
1430 if (++throw_level > 20)
|
793
|
1431 abort ();
|
428
|
1432 #endif
|
|
1433
|
|
1434 /* If bomb_out_p is t, this is being called from Fsignal as a
|
|
1435 "last resort" when there is no handler for this error and
|
|
1436 the debugger couldn't be invoked, so we are throwing to
|
|
1437 'top-level. If this tag doesn't exist (happens during the
|
|
1438 initialization stages) we would get in an infinite recursive
|
|
1439 Fsignal/Fthrow loop, so instead we bomb out to the
|
|
1440 really-early-error-handler.
|
|
1441
|
|
1442 Note that in fact the only time that the "last resort"
|
|
1443 occurs is when there's no catch for 'top-level -- the
|
|
1444 'top-level catch and the catch-all error handler are
|
|
1445 established at the same time, in initial_command_loop/
|
|
1446 top_level_1.
|
|
1447
|
|
1448 #### Fix this horrifitude!
|
|
1449 */
|
|
1450
|
|
1451 while (1)
|
|
1452 {
|
|
1453 REGISTER struct catchtag *c;
|
|
1454
|
|
1455 #if 0 /* FSFmacs */
|
|
1456 if (!NILP (tag)) /* #### */
|
|
1457 #endif
|
|
1458 for (c = catchlist; c; c = c->next)
|
|
1459 {
|
|
1460 if (EQ (c->tag, tag))
|
|
1461 unwind_to_catch (c, val);
|
|
1462 }
|
|
1463 if (!bomb_out_p)
|
|
1464 tag = Fsignal (Qno_catch, list2 (tag, val));
|
|
1465 else
|
|
1466 call1 (Qreally_early_error_handler, Fcons (sig, data));
|
|
1467 }
|
|
1468
|
|
1469 /* can't happen. who cares? - (Sun's compiler does) */
|
|
1470 /* throw_level--; */
|
|
1471 /* getting tired of compilation warnings */
|
|
1472 /* return Qnil; */
|
|
1473 }
|
|
1474
|
|
1475 /* See above, where CATCHLIST is defined, for a description of how
|
|
1476 Fthrow() works.
|
|
1477
|
|
1478 Fthrow() is also called by Fsignal(), to do a non-local jump
|
|
1479 back to the appropriate condition-case handler after (maybe)
|
|
1480 the debugger is entered. In that case, TAG is the value
|
|
1481 of Vcondition_handlers that was in place just after the
|
|
1482 condition-case handler was set up. The car of this will be
|
|
1483 some data referring to the handler: Its car will be Qunbound
|
|
1484 (thus, this tag can never be generated by Lisp code), and
|
|
1485 its CDR will be the HANDLERS argument to condition_case_1()
|
|
1486 (either Qerror, Qt, or a list of handlers as in `condition-case').
|
|
1487 This works fine because Fthrow() does not care what TAG was
|
|
1488 passed to it: it just looks up the catch list for something
|
|
1489 that is EQ() to TAG. When it finds it, it will longjmp()
|
|
1490 back to the place that established the catch (in this case,
|
|
1491 condition_case_1). See below for more info.
|
|
1492 */
|
|
1493
|
|
1494 DEFUN ("throw", Fthrow, 2, 2, 0, /*
|
444
|
1495 Throw to the catch for TAG and return VALUE from it.
|
428
|
1496 Both TAG and VALUE are evalled.
|
|
1497 */
|
444
|
1498 (tag, value))
|
|
1499 {
|
|
1500 throw_or_bomb_out (tag, value, 0, Qnil, Qnil); /* Doesn't return */
|
428
|
1501 return Qnil;
|
|
1502 }
|
|
1503
|
|
1504 DEFUN ("unwind-protect", Funwind_protect, 1, UNEVALLED, 0, /*
|
|
1505 Do BODYFORM, protecting with UNWINDFORMS.
|
|
1506 Usage looks like (unwind-protect BODYFORM UNWINDFORMS...).
|
|
1507 If BODYFORM completes normally, its value is returned
|
|
1508 after executing the UNWINDFORMS.
|
|
1509 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
|
|
1510 */
|
|
1511 (args))
|
|
1512 {
|
|
1513 /* This function can GC */
|
|
1514 int speccount = specpdl_depth();
|
|
1515
|
|
1516 record_unwind_protect (Fprogn, XCDR (args));
|
771
|
1517 return unbind_to_1 (speccount, Feval (XCAR (args)));
|
428
|
1518 }
|
|
1519
|
|
1520
|
|
1521 /************************************************************************/
|
|
1522 /* Signalling and trapping errors */
|
|
1523 /************************************************************************/
|
|
1524
|
|
1525 static Lisp_Object
|
|
1526 condition_bind_unwind (Lisp_Object loser)
|
|
1527 {
|
617
|
1528 /* There is no problem freeing stuff here like there is in
|
|
1529 condition_case_unwind(), because there are no outside pointers
|
|
1530 (like the tag below in the catchlist) pointing to the objects. */
|
440
|
1531 Lisp_Cons *victim;
|
428
|
1532 /* ((handler-fun . handler-args) ... other handlers) */
|
|
1533 Lisp_Object tem = XCAR (loser);
|
|
1534
|
|
1535 while (CONSP (tem))
|
|
1536 {
|
|
1537 victim = XCONS (tem);
|
|
1538 tem = victim->cdr;
|
|
1539 free_cons (victim);
|
|
1540 }
|
|
1541 victim = XCONS (loser);
|
|
1542
|
|
1543 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */
|
|
1544 Vcondition_handlers = victim->cdr;
|
|
1545
|
|
1546 free_cons (victim);
|
|
1547 return Qnil;
|
|
1548 }
|
|
1549
|
|
1550 static Lisp_Object
|
|
1551 condition_case_unwind (Lisp_Object loser)
|
|
1552 {
|
|
1553 /* ((<unbound> . clauses) ... other handlers */
|
617
|
1554 /* NO! Doing this now leaves the tag deleted in a still-active
|
|
1555 catch. With the recent changes to unwind_to_catch(), the
|
|
1556 evil situation might not happen any more; it certainly could
|
|
1557 happen before because it did. But it's very precarious to rely
|
|
1558 on something like this. #### Instead we should rewrite, adopting
|
|
1559 the FSF's mechanism with a struct handler instead of
|
|
1560 Vcondition_handlers; then we have NO Lisp-object structures used
|
|
1561 to hold all of the values, and there's no possibility either of
|
|
1562 crashes from freeing objects too quickly, or objects not getting
|
|
1563 freed and hanging around till the next GC.
|
|
1564
|
|
1565 In practice, the extra consing here should not matter because
|
|
1566 it only happens when we throw past the condition-case, which almost
|
|
1567 always is the result of an error. Most of the time, there will be
|
|
1568 no error, and we will free the objects below in the main function.
|
|
1569
|
|
1570 --ben
|
|
1571
|
|
1572 DO NOT DO: free_cons (XCAR (loser));
|
|
1573 */
|
|
1574
|
428
|
1575 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */
|
617
|
1576 Vcondition_handlers = XCDR (loser);
|
|
1577
|
|
1578 /* DO NOT DO: free_cons (loser); */
|
428
|
1579 return Qnil;
|
|
1580 }
|
|
1581
|
|
1582 /* Split out from condition_case_3 so that primitive C callers
|
|
1583 don't have to cons up a lisp handler form to be evaluated. */
|
|
1584
|
|
1585 /* Call a function BFUN of one argument BARG, trapping errors as
|
|
1586 specified by HANDLERS. If no error occurs that is indicated by
|
|
1587 HANDLERS as something to be caught, the return value of this
|
|
1588 function is the return value from BFUN. If such an error does
|
|
1589 occur, HFUN is called, and its return value becomes the
|
|
1590 return value of condition_case_1(). The second argument passed
|
|
1591 to HFUN will always be HARG. The first argument depends on
|
|
1592 HANDLERS:
|
|
1593
|
|
1594 If HANDLERS is Qt, all errors (this includes QUIT, but not
|
|
1595 non-local exits with `throw') cause HFUN to be invoked, and VAL
|
|
1596 (the first argument to HFUN) is a cons (SIG . DATA) of the
|
|
1597 arguments passed to `signal'. The debugger is not invoked even if
|
|
1598 `debug-on-error' was set.
|
|
1599
|
|
1600 A HANDLERS value of Qerror is the same as Qt except that the
|
|
1601 debugger is invoked if `debug-on-error' was set.
|
|
1602
|
|
1603 Otherwise, HANDLERS should be a list of lists (CONDITION-NAME BODY ...)
|
|
1604 exactly as in `condition-case', and errors will be trapped
|
|
1605 as indicated in HANDLERS. VAL (the first argument to HFUN) will
|
|
1606 be a cons whose car is the cons (SIG . DATA) and whose CDR is the
|
|
1607 list (BODY ...) from the appropriate slot in HANDLERS.
|
|
1608
|
|
1609 This function pushes HANDLERS onto the front of Vcondition_handlers
|
|
1610 (actually with a Qunbound marker as well -- see Fthrow() above
|
|
1611 for why), establishes a catch whose tag is this new value of
|
|
1612 Vcondition_handlers, and calls BFUN. When Fsignal() is called,
|
|
1613 it calls Fthrow(), setting TAG to this same new value of
|
|
1614 Vcondition_handlers and setting VAL to the same thing that will
|
|
1615 be passed to HFUN, as above. Fthrow() longjmp()s back to the
|
|
1616 jump point we just established, and we in turn just call the
|
|
1617 HFUN and return its value.
|
|
1618
|
|
1619 For a real condition-case, HFUN will always be
|
|
1620 run_condition_case_handlers() and HARG is the argument VAR
|
|
1621 to condition-case. That function just binds VAR to the cons
|
|
1622 (SIG . DATA) that is the CAR of VAL, and calls the handler
|
|
1623 (BODY ...) that is the CDR of VAL. Note that before calling
|
|
1624 Fthrow(), Fsignal() restored Vcondition_handlers to the value
|
|
1625 it had *before* condition_case_1() was called. This maintains
|
|
1626 consistency (so that the state of things at exit of
|
|
1627 condition_case_1() is the same as at entry), and implies
|
|
1628 that the handler can signal the same error again (possibly
|
|
1629 after processing of its own), without getting in an infinite
|
|
1630 loop. */
|
|
1631
|
|
1632 Lisp_Object
|
|
1633 condition_case_1 (Lisp_Object handlers,
|
|
1634 Lisp_Object (*bfun) (Lisp_Object barg),
|
|
1635 Lisp_Object barg,
|
|
1636 Lisp_Object (*hfun) (Lisp_Object val, Lisp_Object harg),
|
|
1637 Lisp_Object harg)
|
|
1638 {
|
|
1639 int speccount = specpdl_depth();
|
|
1640 struct catchtag c;
|
617
|
1641 struct gcpro gcpro1, gcpro2, gcpro3;
|
428
|
1642
|
|
1643 #if 0 /* FSFmacs */
|
|
1644 c.tag = Qnil;
|
|
1645 #else
|
|
1646 /* Do consing now so out-of-memory error happens up front */
|
|
1647 /* (unbound . stuff) is a special condition-case kludge marker
|
|
1648 which is known specially by Fsignal.
|
617
|
1649 [[ This is an abomination, but to fix it would require either
|
428
|
1650 making condition_case cons (a union of the conditions of the clauses)
|
617
|
1651 or changing the byte-compiler output (no thanks).]]
|
|
1652
|
|
1653 The above comment is clearly wrong. FSF does not do it this way
|
|
1654 and did not change the byte-compiler output. Instead they use a
|
|
1655 `struct handler' to hold the various values (in place of our
|
|
1656 Vcondition_handlers) and chain them together, with pointers from
|
|
1657 the `struct catchtag' to the `struct handler'. We should perhaps
|
|
1658 consider moving to something similar, but not before I merge my
|
|
1659 stderr-proc workspace, which contains changes to these
|
|
1660 functions. --ben */
|
428
|
1661 c.tag = noseeum_cons (noseeum_cons (Qunbound, handlers),
|
|
1662 Vcondition_handlers);
|
|
1663 #endif
|
|
1664 c.val = Qnil;
|
|
1665 c.backlist = backtrace_list;
|
|
1666 #if 0 /* FSFmacs */
|
|
1667 /* #### */
|
|
1668 c.handlerlist = handlerlist;
|
|
1669 #endif
|
|
1670 c.lisp_eval_depth = lisp_eval_depth;
|
|
1671 c.pdlcount = specpdl_depth();
|
|
1672 #if 0 /* FSFmacs */
|
|
1673 c.poll_suppress_count = async_timer_suppress_count;
|
|
1674 #endif
|
|
1675 c.gcpro = gcprolist;
|
|
1676 /* #### FSFmacs does the following statement *after* the setjmp(). */
|
|
1677 c.next = catchlist;
|
|
1678
|
|
1679 if (SETJMP (c.jmp))
|
|
1680 {
|
|
1681 /* throw does ungcpro, etc */
|
|
1682 return (*hfun) (c.val, harg);
|
|
1683 }
|
|
1684
|
|
1685 record_unwind_protect (condition_case_unwind, c.tag);
|
|
1686
|
|
1687 catchlist = &c;
|
|
1688 #if 0 /* FSFmacs */
|
|
1689 h.handler = handlers;
|
|
1690 h.var = Qnil;
|
|
1691 h.next = handlerlist;
|
|
1692 h.tag = &c;
|
|
1693 handlerlist = &h;
|
|
1694 #else
|
|
1695 Vcondition_handlers = c.tag;
|
|
1696 #endif
|
|
1697 GCPRO1 (harg); /* Somebody has to gc-protect */
|
|
1698 c.val = ((*bfun) (barg));
|
|
1699 UNGCPRO;
|
617
|
1700
|
|
1701 /* Once we change `catchlist' below, the stuff in c will not be GCPRO'd. */
|
|
1702 GCPRO3 (harg, c.val, c.tag);
|
|
1703
|
428
|
1704 catchlist = c.next;
|
800
|
1705 CHECK_ERROR_STATE_SANITY ();
|
617
|
1706 /* Note: The unbind also resets Vcondition_handlers. Maybe we should
|
|
1707 delete this here. */
|
428
|
1708 Vcondition_handlers = XCDR (c.tag);
|
771
|
1709 unbind_to (speccount);
|
617
|
1710
|
|
1711 UNGCPRO;
|
|
1712 /* free the conses *after* the unbind, because the unbind will run
|
|
1713 condition_case_unwind above. */
|
|
1714 free_cons (XCONS (XCAR (c.tag)));
|
|
1715 free_cons (XCONS (c.tag));
|
|
1716 return c.val;
|
428
|
1717 }
|
|
1718
|
|
1719 static Lisp_Object
|
|
1720 run_condition_case_handlers (Lisp_Object val, Lisp_Object var)
|
|
1721 {
|
|
1722 /* This function can GC */
|
|
1723 #if 0 /* FSFmacs */
|
|
1724 if (!NILP (h.var))
|
|
1725 specbind (h.var, c.val);
|
|
1726 val = Fprogn (Fcdr (h.chosen_clause));
|
|
1727
|
|
1728 /* Note that this just undoes the binding of h.var; whoever
|
|
1729 longjmp()ed to us unwound the stack to c.pdlcount before
|
|
1730 throwing. */
|
771
|
1731 unbind_to (c.pdlcount);
|
428
|
1732 return val;
|
|
1733 #else
|
|
1734 int speccount;
|
|
1735
|
|
1736 CHECK_TRUE_LIST (val);
|
|
1737 if (NILP (var))
|
|
1738 return Fprogn (Fcdr (val)); /* tail call */
|
|
1739
|
|
1740 speccount = specpdl_depth();
|
|
1741 specbind (var, Fcar (val));
|
|
1742 val = Fprogn (Fcdr (val));
|
771
|
1743 return unbind_to_1 (speccount, val);
|
428
|
1744 #endif
|
|
1745 }
|
|
1746
|
|
1747 /* Here for bytecode to call non-consfully. This is exactly like
|
|
1748 condition-case except that it takes three arguments rather
|
|
1749 than a single list of arguments. */
|
|
1750 Lisp_Object
|
|
1751 condition_case_3 (Lisp_Object bodyform, Lisp_Object var, Lisp_Object handlers)
|
|
1752 {
|
|
1753 /* This function can GC */
|
|
1754 EXTERNAL_LIST_LOOP_2 (handler, handlers)
|
|
1755 {
|
|
1756 if (NILP (handler))
|
|
1757 ;
|
|
1758 else if (CONSP (handler))
|
|
1759 {
|
|
1760 Lisp_Object conditions = XCAR (handler);
|
|
1761 /* CONDITIONS must a condition name or a list of condition names */
|
|
1762 if (SYMBOLP (conditions))
|
|
1763 ;
|
|
1764 else
|
|
1765 {
|
|
1766 EXTERNAL_LIST_LOOP_2 (condition, conditions)
|
|
1767 if (!SYMBOLP (condition))
|
|
1768 goto invalid_condition_handler;
|
|
1769 }
|
|
1770 }
|
|
1771 else
|
|
1772 {
|
|
1773 invalid_condition_handler:
|
563
|
1774 sferror ("Invalid condition handler", handler);
|
428
|
1775 }
|
|
1776 }
|
|
1777
|
|
1778 CHECK_SYMBOL (var);
|
|
1779
|
|
1780 return condition_case_1 (handlers,
|
|
1781 Feval, bodyform,
|
|
1782 run_condition_case_handlers,
|
|
1783 var);
|
|
1784 }
|
|
1785
|
|
1786 DEFUN ("condition-case", Fcondition_case, 2, UNEVALLED, 0, /*
|
|
1787 Regain control when an error is signalled.
|
|
1788 Usage looks like (condition-case VAR BODYFORM HANDLERS...).
|
|
1789 Executes BODYFORM and returns its value if no error happens.
|
|
1790 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
|
|
1791 where the BODY is made of Lisp expressions.
|
|
1792
|
771
|
1793 A typical usage of `condition-case' looks like this:
|
|
1794
|
|
1795 (condition-case nil
|
|
1796 ;; you need a progn here if you want more than one statement ...
|
|
1797 (progn
|
|
1798 (do-something)
|
|
1799 (do-something-else))
|
|
1800 (error
|
|
1801 (issue-warning-or)
|
|
1802 ;; but strangely, you don't need one here.
|
|
1803 (return-a-value-etc)
|
|
1804 ))
|
|
1805
|
428
|
1806 A handler is applicable to an error if CONDITION-NAME is one of the
|
|
1807 error's condition names. If an error happens, the first applicable
|
|
1808 handler is run. As a special case, a CONDITION-NAME of t matches
|
|
1809 all errors, even those without the `error' condition name on them
|
|
1810 \(e.g. `quit').
|
|
1811
|
|
1812 The car of a handler may be a list of condition names
|
|
1813 instead of a single condition name.
|
|
1814
|
|
1815 When a handler handles an error,
|
|
1816 control returns to the condition-case and the handler BODY... is executed
|
|
1817 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
|
|
1818 VAR may be nil; then you do not get access to the signal information.
|
|
1819
|
|
1820 The value of the last BODY form is returned from the condition-case.
|
|
1821 See also the function `signal' for more info.
|
|
1822
|
|
1823 Note that at the time the condition handler is invoked, the Lisp stack
|
|
1824 and the current catches, condition-cases, and bindings have all been
|
|
1825 popped back to the state they were in just before the call to
|
|
1826 `condition-case'. This means that resignalling the error from
|
|
1827 within the handler will not result in an infinite loop.
|
|
1828
|
|
1829 If you want to establish an error handler that is called with the
|
|
1830 Lisp stack, bindings, etc. as they were when `signal' was called,
|
|
1831 rather than when the handler was set, use `call-with-condition-handler'.
|
|
1832 */
|
|
1833 (args))
|
|
1834 {
|
|
1835 /* This function can GC */
|
|
1836 Lisp_Object var = XCAR (args);
|
|
1837 Lisp_Object bodyform = XCAR (XCDR (args));
|
|
1838 Lisp_Object handlers = XCDR (XCDR (args));
|
|
1839 return condition_case_3 (bodyform, var, handlers);
|
|
1840 }
|
|
1841
|
|
1842 DEFUN ("call-with-condition-handler", Fcall_with_condition_handler, 2, MANY, 0, /*
|
|
1843 Regain control when an error is signalled, without popping the stack.
|
|
1844 Usage looks like (call-with-condition-handler HANDLER FUNCTION &rest ARGS).
|
|
1845 This function is similar to `condition-case', but the handler is invoked
|
|
1846 with the same environment (Lisp stack, bindings, catches, condition-cases)
|
|
1847 that was current when `signal' was called, rather than when the handler
|
|
1848 was established.
|
|
1849
|
|
1850 HANDLER should be a function of one argument, which is a cons of the args
|
|
1851 \(SIG . DATA) that were passed to `signal'. It is invoked whenever
|
|
1852 `signal' is called (this differs from `condition-case', which allows
|
|
1853 you to specify which errors are trapped). If the handler function
|
|
1854 returns, `signal' continues as if the handler were never invoked.
|
|
1855 \(It continues to look for handlers established earlier than this one,
|
|
1856 and invokes the standard error-handler if none is found.)
|
|
1857 */
|
|
1858 (int nargs, Lisp_Object *args)) /* Note! Args side-effected! */
|
|
1859 {
|
|
1860 /* This function can GC */
|
|
1861 int speccount = specpdl_depth();
|
|
1862 Lisp_Object tem;
|
|
1863
|
|
1864 /* #### If there were a way to check that args[0] were a function
|
|
1865 which accepted one arg, that should be done here ... */
|
|
1866
|
|
1867 /* (handler-fun . handler-args) */
|
|
1868 tem = noseeum_cons (list1 (args[0]), Vcondition_handlers);
|
|
1869 record_unwind_protect (condition_bind_unwind, tem);
|
|
1870 Vcondition_handlers = tem;
|
|
1871
|
|
1872 /* Caller should have GC-protected args */
|
771
|
1873 return unbind_to_1 (speccount, Ffuncall (nargs - 1, args + 1));
|
428
|
1874 }
|
|
1875
|
|
1876 static int
|
|
1877 condition_type_p (Lisp_Object type, Lisp_Object conditions)
|
|
1878 {
|
|
1879 if (EQ (type, Qt))
|
|
1880 /* (condition-case c # (t c)) catches -all- signals
|
|
1881 * Use with caution! */
|
|
1882 return 1;
|
|
1883
|
|
1884 if (SYMBOLP (type))
|
|
1885 return !NILP (Fmemq (type, conditions));
|
|
1886
|
|
1887 for (; CONSP (type); type = XCDR (type))
|
|
1888 if (!NILP (Fmemq (XCAR (type), conditions)))
|
|
1889 return 1;
|
|
1890
|
|
1891 return 0;
|
|
1892 }
|
|
1893
|
|
1894 static Lisp_Object
|
|
1895 return_from_signal (Lisp_Object value)
|
|
1896 {
|
|
1897 #if 1
|
|
1898 /* Most callers are not prepared to handle gc if this
|
|
1899 returns. So, since this feature is not very useful,
|
|
1900 take it out. */
|
|
1901 /* Have called debugger; return value to signaller */
|
|
1902 return value;
|
|
1903 #else /* But the reality is that that stinks, because: */
|
|
1904 /* GACK!!! Really want some way for debug-on-quit errors
|
|
1905 to be continuable!! */
|
563
|
1906 signal_error (Qunimplemented,
|
|
1907 "Returning a value from an error is no longer supported",
|
|
1908 Qunbound);
|
428
|
1909 #endif
|
|
1910 }
|
|
1911
|
|
1912 extern int in_display;
|
|
1913
|
|
1914
|
|
1915 /************************************************************************/
|
|
1916 /* the workhorse error-signaling function */
|
|
1917 /************************************************************************/
|
|
1918
|
|
1919 /* #### This function has not been synched with FSF. It diverges
|
|
1920 significantly. */
|
|
1921
|
|
1922 static Lisp_Object
|
|
1923 signal_1 (Lisp_Object sig, Lisp_Object data)
|
|
1924 {
|
|
1925 /* This function can GC */
|
|
1926 struct gcpro gcpro1, gcpro2;
|
|
1927 Lisp_Object conditions;
|
|
1928 Lisp_Object handlers;
|
|
1929 /* signal_call_debugger() could get called more than once
|
|
1930 (once when a call-with-condition-handler is about to
|
|
1931 be dealt with, and another when a condition-case handler
|
|
1932 is about to be invoked). So make sure the debugger and/or
|
|
1933 stack trace aren't done more than once. */
|
|
1934 int stack_trace_displayed = 0;
|
|
1935 int debugger_entered = 0;
|
|
1936 GCPRO2 (conditions, handlers);
|
|
1937
|
|
1938 if (!initialized)
|
|
1939 {
|
|
1940 /* who knows how much has been initialized? Safest bet is
|
|
1941 just to bomb out immediately. */
|
771
|
1942 stderr_out ("Error before initialization is complete!\n");
|
428
|
1943 abort ();
|
|
1944 }
|
|
1945
|
|
1946 if (gc_in_progress || in_display)
|
|
1947 /* This is one of many reasons why you can't run lisp code from redisplay.
|
|
1948 There is no sensible way to handle errors there. */
|
|
1949 abort ();
|
|
1950
|
|
1951 conditions = Fget (sig, Qerror_conditions, Qnil);
|
|
1952
|
|
1953 for (handlers = Vcondition_handlers;
|
|
1954 CONSP (handlers);
|
|
1955 handlers = XCDR (handlers))
|
|
1956 {
|
|
1957 Lisp_Object handler_fun = XCAR (XCAR (handlers));
|
|
1958 Lisp_Object handler_data = XCDR (XCAR (handlers));
|
|
1959 Lisp_Object outer_handlers = XCDR (handlers);
|
|
1960
|
|
1961 if (!UNBOUNDP (handler_fun))
|
|
1962 {
|
|
1963 /* call-with-condition-handler */
|
|
1964 Lisp_Object tem;
|
|
1965 Lisp_Object all_handlers = Vcondition_handlers;
|
|
1966 struct gcpro ngcpro1;
|
|
1967 NGCPRO1 (all_handlers);
|
|
1968 Vcondition_handlers = outer_handlers;
|
|
1969
|
|
1970 tem = signal_call_debugger (conditions, sig, data,
|
|
1971 outer_handlers, 1,
|
|
1972 &stack_trace_displayed,
|
|
1973 &debugger_entered);
|
|
1974 if (!UNBOUNDP (tem))
|
|
1975 RETURN_NUNGCPRO (return_from_signal (tem));
|
|
1976
|
|
1977 tem = Fcons (sig, data);
|
|
1978 if (NILP (handler_data))
|
|
1979 tem = call1 (handler_fun, tem);
|
|
1980 else
|
|
1981 {
|
|
1982 /* (This code won't be used (for now?).) */
|
|
1983 struct gcpro nngcpro1;
|
|
1984 Lisp_Object args[3];
|
|
1985 NNGCPRO1 (args[0]);
|
|
1986 nngcpro1.nvars = 3;
|
|
1987 args[0] = handler_fun;
|
|
1988 args[1] = tem;
|
|
1989 args[2] = handler_data;
|
|
1990 nngcpro1.var = args;
|
|
1991 tem = Fapply (3, args);
|
|
1992 NNUNGCPRO;
|
|
1993 }
|
|
1994 NUNGCPRO;
|
|
1995 #if 0
|
|
1996 if (!EQ (tem, Qsignal))
|
|
1997 return return_from_signal (tem);
|
|
1998 #endif
|
|
1999 /* If handler didn't throw, try another handler */
|
|
2000 Vcondition_handlers = all_handlers;
|
|
2001 }
|
|
2002
|
|
2003 /* It's a condition-case handler */
|
|
2004
|
|
2005 /* t is used by handlers for all conditions, set up by C code.
|
|
2006 * debugger is not called even if debug_on_error */
|
|
2007 else if (EQ (handler_data, Qt))
|
|
2008 {
|
|
2009 UNGCPRO;
|
|
2010 return Fthrow (handlers, Fcons (sig, data));
|
|
2011 }
|
|
2012 /* `error' is used similarly to the way `t' is used, but in
|
|
2013 addition it invokes the debugger if debug_on_error.
|
|
2014 This is normally used for the outer command-loop error
|
|
2015 handler. */
|
|
2016 else if (EQ (handler_data, Qerror))
|
|
2017 {
|
|
2018 Lisp_Object tem = signal_call_debugger (conditions, sig, data,
|
|
2019 outer_handlers, 0,
|
|
2020 &stack_trace_displayed,
|
|
2021 &debugger_entered);
|
|
2022
|
|
2023 UNGCPRO;
|
|
2024 if (!UNBOUNDP (tem))
|
|
2025 return return_from_signal (tem);
|
|
2026
|
|
2027 tem = Fcons (sig, data);
|
|
2028 return Fthrow (handlers, tem);
|
|
2029 }
|
|
2030 else
|
|
2031 {
|
|
2032 /* handler established by real (Lisp) condition-case */
|
|
2033 Lisp_Object h;
|
|
2034
|
|
2035 for (h = handler_data; CONSP (h); h = Fcdr (h))
|
|
2036 {
|
|
2037 Lisp_Object clause = Fcar (h);
|
|
2038 Lisp_Object tem = Fcar (clause);
|
|
2039
|
|
2040 if (condition_type_p (tem, conditions))
|
|
2041 {
|
|
2042 tem = signal_call_debugger (conditions, sig, data,
|
|
2043 outer_handlers, 1,
|
|
2044 &stack_trace_displayed,
|
|
2045 &debugger_entered);
|
|
2046 UNGCPRO;
|
|
2047 if (!UNBOUNDP (tem))
|
|
2048 return return_from_signal (tem);
|
|
2049
|
|
2050 /* Doesn't return */
|
|
2051 tem = Fcons (Fcons (sig, data), Fcdr (clause));
|
|
2052 return Fthrow (handlers, tem);
|
|
2053 }
|
|
2054 }
|
|
2055 }
|
|
2056 }
|
|
2057
|
|
2058 /* If no handler is present now, try to run the debugger,
|
|
2059 and if that fails, throw to top level.
|
|
2060
|
|
2061 #### The only time that no handler is present is during
|
|
2062 temacs or perhaps very early in XEmacs. In both cases,
|
|
2063 there is no 'top-level catch. (That's why the
|
|
2064 "bomb-out" hack was added.)
|
|
2065
|
|
2066 #### Fix this horrifitude!
|
|
2067 */
|
|
2068 signal_call_debugger (conditions, sig, data, Qnil, 0,
|
|
2069 &stack_trace_displayed,
|
|
2070 &debugger_entered);
|
|
2071 UNGCPRO;
|
|
2072 throw_or_bomb_out (Qtop_level, Qt, 1, sig, data); /* Doesn't return */
|
|
2073 return Qnil;
|
|
2074 }
|
|
2075
|
|
2076
|
|
2077 /****************** Error functions class 1 ******************/
|
|
2078
|
|
2079 /* Class 1: General functions that signal an error.
|
|
2080 These functions take an error type and a list of associated error
|
|
2081 data. */
|
|
2082
|
|
2083 /* The simplest external error function: it would be called
|
563
|
2084 signal_continuable_error_1() in the terminology below, but it's
|
428
|
2085 Lisp-callable. */
|
|
2086
|
|
2087 DEFUN ("signal", Fsignal, 2, 2, 0, /*
|
|
2088 Signal a continuable error. Args are ERROR-SYMBOL, and associated DATA.
|
|
2089 An error symbol is a symbol defined using `define-error'.
|
|
2090 DATA should be a list. Its elements are printed as part of the error message.
|
|
2091 If the signal is handled, DATA is made available to the handler.
|
|
2092 See also the function `signal-error', and the functions to handle errors:
|
|
2093 `condition-case' and `call-with-condition-handler'.
|
|
2094
|
|
2095 Note that this function can return, if the debugger is invoked and the
|
|
2096 user invokes the "return from signal" option.
|
|
2097 */
|
|
2098 (error_symbol, data))
|
|
2099 {
|
|
2100 /* Fsignal() is one of these functions that's called all the time
|
|
2101 with newly-created Lisp objects. We allow this; but we must GC-
|
|
2102 protect the objects because all sorts of weird stuff could
|
|
2103 happen. */
|
|
2104
|
|
2105 struct gcpro gcpro1;
|
|
2106
|
|
2107 GCPRO1 (data);
|
|
2108 if (!NILP (Vcurrent_error_state))
|
|
2109 {
|
793
|
2110 if (!NILP (Vcurrent_warning_class) && !NILP (Vcurrent_warning_level))
|
|
2111 warn_when_safe_lispobj (Vcurrent_warning_class, Vcurrent_warning_level,
|
428
|
2112 Fcons (error_symbol, data));
|
|
2113 Fthrow (Qunbound_suspended_errors_tag, Qnil);
|
|
2114 abort (); /* Better not get here! */
|
|
2115 }
|
|
2116 RETURN_UNGCPRO (signal_1 (error_symbol, data));
|
|
2117 }
|
|
2118
|
|
2119 /* Signal a non-continuable error. */
|
|
2120
|
|
2121 DOESNT_RETURN
|
563
|
2122 signal_error_1 (Lisp_Object sig, Lisp_Object data)
|
428
|
2123 {
|
|
2124 for (;;)
|
|
2125 Fsignal (sig, data);
|
|
2126 }
|
800
|
2127 #ifdef ERROR_CHECK_STRUCTURES
|
|
2128 static void
|
442
|
2129 check_error_state_sanity (void)
|
|
2130 {
|
|
2131 struct catchtag *c;
|
|
2132 int found_error_tag = 0;
|
|
2133
|
|
2134 for (c = catchlist; c; c = c->next)
|
|
2135 {
|
|
2136 if (EQ (c->tag, Qunbound_suspended_errors_tag))
|
|
2137 {
|
|
2138 found_error_tag = 1;
|
|
2139 break;
|
|
2140 }
|
|
2141 }
|
|
2142
|
|
2143 assert (found_error_tag || NILP (Vcurrent_error_state));
|
|
2144 }
|
|
2145 #endif
|
428
|
2146
|
|
2147 static Lisp_Object
|
|
2148 restore_current_warning_class (Lisp_Object warning_class)
|
|
2149 {
|
|
2150 Vcurrent_warning_class = warning_class;
|
|
2151 return Qnil;
|
|
2152 }
|
|
2153
|
|
2154 static Lisp_Object
|
793
|
2155 restore_current_warning_level (Lisp_Object warning_level)
|
|
2156 {
|
|
2157 Vcurrent_warning_level = warning_level;
|
|
2158 return Qnil;
|
|
2159 }
|
|
2160
|
|
2161 static Lisp_Object
|
428
|
2162 restore_current_error_state (Lisp_Object error_state)
|
|
2163 {
|
|
2164 Vcurrent_error_state = error_state;
|
|
2165 return Qnil;
|
|
2166 }
|
|
2167
|
442
|
2168 static Lisp_Object
|
|
2169 call_with_suspended_errors_1 (Lisp_Object opaque_arg)
|
|
2170 {
|
|
2171 Lisp_Object val;
|
|
2172 Lisp_Object *kludgy_args = (Lisp_Object *) get_opaque_ptr (opaque_arg);
|
|
2173 int speccount = specpdl_depth ();
|
|
2174
|
793
|
2175 if (NILP (Vcurrent_error_state))
|
442
|
2176 {
|
|
2177 record_unwind_protect (restore_current_error_state,
|
|
2178 Vcurrent_error_state);
|
793
|
2179 Vcurrent_error_state = Qt;
|
442
|
2180 }
|
|
2181 PRIMITIVE_FUNCALL (val, get_opaque_ptr (kludgy_args[0]),
|
793
|
2182 kludgy_args + 2, XINT (kludgy_args[1]));
|
771
|
2183 return unbind_to_1 (speccount, val);
|
442
|
2184 }
|
|
2185
|
428
|
2186 /* Many functions would like to do one of three things if an error
|
|
2187 occurs:
|
|
2188
|
|
2189 (1) signal the error, as usual.
|
|
2190 (2) silently fail and return some error value.
|
|
2191 (3) do as (2) but issue a warning in the process.
|
|
2192
|
578
|
2193 Currently there's lots of stuff that passes an Error_Behavior
|
428
|
2194 value and calls maybe_signal_error() and other such functions.
|
|
2195 This approach is inherently error-prone and broken. A much
|
|
2196 more robust and easier approach is to use call_with_suspended_errors().
|
|
2197 Wrap this around any function in which you might want errors
|
|
2198 to not be errors.
|
|
2199 */
|
|
2200
|
|
2201 Lisp_Object
|
|
2202 call_with_suspended_errors (lisp_fn_t fun, volatile Lisp_Object retval,
|
578
|
2203 Lisp_Object class, Error_Behavior errb,
|
428
|
2204 int nargs, ...)
|
|
2205 {
|
|
2206 va_list vargs;
|
|
2207 int speccount;
|
793
|
2208 Lisp_Object kludgy_args[22];
|
|
2209 Lisp_Object *args = kludgy_args + 2;
|
428
|
2210 int i;
|
|
2211
|
|
2212 assert (SYMBOLP (class)); /* sanity-check */
|
|
2213 assert (!NILP (class));
|
|
2214 assert (nargs >= 0 && nargs < 20);
|
|
2215
|
|
2216 va_start (vargs, nargs);
|
|
2217 for (i = 0; i < nargs; i++)
|
|
2218 args[i] = va_arg (vargs, Lisp_Object);
|
|
2219 va_end (vargs);
|
|
2220
|
793
|
2221 /* ERROR_ME means don't trap errors. (However, if errors are
|
|
2222 already trapped, we leave them trapped.)
|
|
2223
|
|
2224 Otherwise, we trap errors, and display as warnings if ERROR_ME_WARN.
|
|
2225
|
|
2226 If ERROR_ME_NOT, we silently fail.
|
|
2227
|
|
2228 If ERROR_ME_DEBUG_WARN, we display a warning, but at warning level to
|
|
2229 `debug'. Normally these disappear, but can be seen if we changed
|
|
2230 log-warning-minimum-level.
|
|
2231 */
|
|
2232
|
428
|
2233 /* If error-checking is not disabled, just call the function.
|
|
2234 It's important not to override disabled error-checking with
|
|
2235 enabled error-checking. */
|
|
2236
|
|
2237 if (ERRB_EQ (errb, ERROR_ME))
|
|
2238 {
|
|
2239 Lisp_Object val;
|
|
2240 PRIMITIVE_FUNCALL (val, fun, args, nargs);
|
|
2241 return val;
|
|
2242 }
|
|
2243
|
442
|
2244 speccount = specpdl_depth ();
|
793
|
2245 if (NILP (Vcurrent_warning_class))
|
428
|
2246 {
|
793
|
2247 /* Don't change the existing class.
|
|
2248 #### Should we be consing the two together? */
|
428
|
2249 record_unwind_protect (restore_current_warning_class,
|
|
2250 Vcurrent_warning_class);
|
|
2251 Vcurrent_warning_class = class;
|
|
2252 }
|
|
2253
|
793
|
2254 record_unwind_protect (restore_current_warning_level,
|
|
2255 Vcurrent_warning_level);
|
|
2256 Vcurrent_warning_level =
|
|
2257 (ERRB_EQ (errb, ERROR_ME_NOT) ? Qnil :
|
|
2258 ERRB_EQ (errb, ERROR_ME_DEBUG_WARN) ? Qdebug :
|
|
2259 Qwarning);
|
|
2260
|
|
2261
|
428
|
2262 {
|
|
2263 int threw;
|
|
2264 Lisp_Object the_retval;
|
|
2265 Lisp_Object opaque1 = make_opaque_ptr (kludgy_args);
|
|
2266 Lisp_Object opaque2 = make_opaque_ptr ((void *) fun);
|
|
2267 struct gcpro gcpro1, gcpro2;
|
|
2268
|
|
2269 GCPRO2 (opaque1, opaque2);
|
|
2270 kludgy_args[0] = opaque2;
|
|
2271 kludgy_args[1] = make_int (nargs);
|
|
2272 the_retval = internal_catch (Qunbound_suspended_errors_tag,
|
|
2273 call_with_suspended_errors_1,
|
|
2274 opaque1, &threw);
|
|
2275 free_opaque_ptr (opaque1);
|
|
2276 free_opaque_ptr (opaque2);
|
|
2277 UNGCPRO;
|
|
2278 /* Use the returned value except in non-local exit, when
|
|
2279 RETVAL applies. */
|
|
2280 /* Some perverse compilers require the perverse cast below. */
|
771
|
2281 return unbind_to_1 (speccount,
|
428
|
2282 threw ? *((Lisp_Object*) &(retval)) : the_retval);
|
|
2283 }
|
|
2284 }
|
|
2285
|
|
2286 /* Signal a non-continuable error or display a warning or do nothing,
|
|
2287 according to ERRB. CLASS is the class of warning and should
|
|
2288 refer to what sort of operation is being done (e.g. Qtoolbar,
|
|
2289 Qresource, etc.). */
|
|
2290
|
|
2291 void
|
563
|
2292 maybe_signal_error_1 (Lisp_Object sig, Lisp_Object data, Lisp_Object class,
|
578
|
2293 Error_Behavior errb)
|
428
|
2294 {
|
|
2295 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2296 return;
|
793
|
2297 else if (ERRB_EQ (errb, ERROR_ME_DEBUG_WARN))
|
|
2298 warn_when_safe_lispobj (class, Qdebug, Fcons (sig, data));
|
428
|
2299 else if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2300 warn_when_safe_lispobj (class, Qwarning, Fcons (sig, data));
|
|
2301 else
|
|
2302 for (;;)
|
|
2303 Fsignal (sig, data);
|
|
2304 }
|
|
2305
|
|
2306 /* Signal a continuable error or display a warning or do nothing,
|
|
2307 according to ERRB. */
|
|
2308
|
|
2309 Lisp_Object
|
563
|
2310 maybe_signal_continuable_error_1 (Lisp_Object sig, Lisp_Object data,
|
578
|
2311 Lisp_Object class, Error_Behavior errb)
|
428
|
2312 {
|
|
2313 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2314 return Qnil;
|
793
|
2315 else if (ERRB_EQ (errb, ERROR_ME_DEBUG_WARN))
|
|
2316 {
|
|
2317 warn_when_safe_lispobj (class, Qdebug, Fcons (sig, data));
|
|
2318 return Qnil;
|
|
2319 }
|
428
|
2320 else if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2321 {
|
|
2322 warn_when_safe_lispobj (class, Qwarning, Fcons (sig, data));
|
|
2323 return Qnil;
|
|
2324 }
|
|
2325 else
|
|
2326 return Fsignal (sig, data);
|
|
2327 }
|
|
2328
|
|
2329
|
|
2330 /****************** Error functions class 2 ******************/
|
|
2331
|
563
|
2332 /* Class 2: Signal an error with a string and an associated object.
|
|
2333 Normally these functions are used to attach one associated object,
|
|
2334 but to attach no objects, specify Qunbound for FROB, and for more
|
|
2335 than one object, make a list of the objects with Qunbound as the
|
|
2336 first element. (If you have specifically two objects to attach,
|
|
2337 consider using the function in class 3 below.) These functions
|
|
2338 signal an error of a specified type, whose data is one or more
|
|
2339 objects (usually two), a string the related Lisp object(s)
|
|
2340 specified as FROB. */
|
|
2341
|
|
2342 /* Out of REASON and FROB, return a list of elements suitable for passing
|
|
2343 to signal_error_1(). */
|
|
2344
|
|
2345 Lisp_Object
|
665
|
2346 build_error_data (const CIntbyte *reason, Lisp_Object frob)
|
563
|
2347 {
|
|
2348 if (EQ (frob, Qunbound))
|
|
2349 frob = Qnil;
|
|
2350 else if (CONSP (frob) && EQ (XCAR (frob), Qunbound))
|
|
2351 frob = XCDR (frob);
|
|
2352 else
|
|
2353 frob = list1 (frob);
|
|
2354 if (!reason)
|
|
2355 return frob;
|
|
2356 else
|
771
|
2357 return Fcons (build_msg_string (reason), frob);
|
563
|
2358 }
|
|
2359
|
|
2360 DOESNT_RETURN
|
665
|
2361 signal_error (Lisp_Object type, const CIntbyte *reason, Lisp_Object frob)
|
563
|
2362 {
|
|
2363 signal_error_1 (type, build_error_data (reason, frob));
|
|
2364 }
|
|
2365
|
|
2366 void
|
665
|
2367 maybe_signal_error (Lisp_Object type, const CIntbyte *reason,
|
563
|
2368 Lisp_Object frob, Lisp_Object class,
|
578
|
2369 Error_Behavior errb)
|
563
|
2370 {
|
|
2371 /* Optimization: */
|
|
2372 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2373 return;
|
|
2374 maybe_signal_error_1 (type, build_error_data (reason, frob), class, errb);
|
|
2375 }
|
|
2376
|
|
2377 Lisp_Object
|
665
|
2378 signal_continuable_error (Lisp_Object type, const CIntbyte *reason,
|
563
|
2379 Lisp_Object frob)
|
|
2380 {
|
|
2381 return Fsignal (type, build_error_data (reason, frob));
|
|
2382 }
|
|
2383
|
|
2384 Lisp_Object
|
665
|
2385 maybe_signal_continuable_error (Lisp_Object type, const CIntbyte *reason,
|
563
|
2386 Lisp_Object frob, Lisp_Object class,
|
578
|
2387 Error_Behavior errb)
|
563
|
2388 {
|
|
2389 /* Optimization: */
|
|
2390 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2391 return Qnil;
|
|
2392 return maybe_signal_continuable_error_1 (type,
|
|
2393 build_error_data (reason, frob),
|
|
2394 class, errb);
|
|
2395 }
|
|
2396
|
|
2397
|
|
2398 /****************** Error functions class 3 ******************/
|
|
2399
|
|
2400 /* Class 3: Signal an error with a string and two associated objects.
|
|
2401 These functions signal an error of a specified type, whose data
|
|
2402 is three objects, a string and two related Lisp objects.
|
|
2403 (The equivalent could be accomplished using the class 2 functions,
|
|
2404 but these are more convenient in this particular case.) */
|
|
2405
|
|
2406 DOESNT_RETURN
|
665
|
2407 signal_error_2 (Lisp_Object type, const CIntbyte *reason,
|
563
|
2408 Lisp_Object frob0, Lisp_Object frob1)
|
|
2409 {
|
771
|
2410 signal_error_1 (type, list3 (build_msg_string (reason), frob0,
|
563
|
2411 frob1));
|
|
2412 }
|
|
2413
|
|
2414 void
|
665
|
2415 maybe_signal_error_2 (Lisp_Object type, const CIntbyte *reason,
|
563
|
2416 Lisp_Object frob0, Lisp_Object frob1,
|
578
|
2417 Lisp_Object class, Error_Behavior errb)
|
563
|
2418 {
|
|
2419 /* Optimization: */
|
|
2420 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2421 return;
|
771
|
2422 maybe_signal_error_1 (type, list3 (build_msg_string (reason), frob0,
|
563
|
2423 frob1), class, errb);
|
|
2424 }
|
|
2425
|
|
2426 Lisp_Object
|
665
|
2427 signal_continuable_error_2 (Lisp_Object type, const CIntbyte *reason,
|
563
|
2428 Lisp_Object frob0, Lisp_Object frob1)
|
|
2429 {
|
771
|
2430 return Fsignal (type, list3 (build_msg_string (reason), frob0,
|
563
|
2431 frob1));
|
|
2432 }
|
|
2433
|
|
2434 Lisp_Object
|
665
|
2435 maybe_signal_continuable_error_2 (Lisp_Object type, const CIntbyte *reason,
|
563
|
2436 Lisp_Object frob0, Lisp_Object frob1,
|
578
|
2437 Lisp_Object class, Error_Behavior errb)
|
563
|
2438 {
|
|
2439 /* Optimization: */
|
|
2440 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2441 return Qnil;
|
|
2442 return maybe_signal_continuable_error_1
|
771
|
2443 (type, list3 (build_msg_string (reason), frob0, frob1),
|
563
|
2444 class, errb);
|
|
2445 }
|
|
2446
|
|
2447
|
|
2448 /****************** Error functions class 4 ******************/
|
|
2449
|
|
2450 /* Class 4: Printf-like functions that signal an error.
|
442
|
2451 These functions signal an error of a specified type, whose data
|
428
|
2452 is a single string, created using the arguments. */
|
|
2453
|
|
2454 DOESNT_RETURN
|
665
|
2455 signal_ferror (Lisp_Object type, const CIntbyte *fmt, ...)
|
442
|
2456 {
|
|
2457 Lisp_Object obj;
|
|
2458 va_list args;
|
|
2459
|
|
2460 va_start (args, fmt);
|
771
|
2461 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
442
|
2462 va_end (args);
|
|
2463
|
|
2464 /* Fsignal GC-protects its args */
|
563
|
2465 signal_error (type, 0, obj);
|
442
|
2466 }
|
|
2467
|
|
2468 void
|
578
|
2469 maybe_signal_ferror (Lisp_Object type, Lisp_Object class, Error_Behavior errb,
|
665
|
2470 const CIntbyte *fmt, ...)
|
442
|
2471 {
|
|
2472 Lisp_Object obj;
|
|
2473 va_list args;
|
|
2474
|
|
2475 /* Optimization: */
|
|
2476 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2477 return;
|
|
2478
|
|
2479 va_start (args, fmt);
|
771
|
2480 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
442
|
2481 va_end (args);
|
|
2482
|
|
2483 /* Fsignal GC-protects its args */
|
563
|
2484 maybe_signal_error (type, 0, obj, class, errb);
|
442
|
2485 }
|
|
2486
|
|
2487 Lisp_Object
|
665
|
2488 signal_continuable_ferror (Lisp_Object type, const CIntbyte *fmt, ...)
|
428
|
2489 {
|
|
2490 Lisp_Object obj;
|
|
2491 va_list args;
|
|
2492
|
|
2493 va_start (args, fmt);
|
771
|
2494 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
442
|
2495 va_end (args);
|
|
2496
|
|
2497 /* Fsignal GC-protects its args */
|
|
2498 return Fsignal (type, list1 (obj));
|
|
2499 }
|
|
2500
|
|
2501 Lisp_Object
|
563
|
2502 maybe_signal_continuable_ferror (Lisp_Object type, Lisp_Object class,
|
665
|
2503 Error_Behavior errb, const CIntbyte *fmt, ...)
|
442
|
2504 {
|
|
2505 Lisp_Object obj;
|
|
2506 va_list args;
|
|
2507
|
|
2508 /* Optimization: */
|
|
2509 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2510 return Qnil;
|
|
2511
|
|
2512 va_start (args, fmt);
|
771
|
2513 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
442
|
2514 va_end (args);
|
|
2515
|
|
2516 /* Fsignal GC-protects its args */
|
563
|
2517 return maybe_signal_continuable_error (type, 0, obj, class, errb);
|
442
|
2518 }
|
|
2519
|
|
2520
|
|
2521 /****************** Error functions class 5 ******************/
|
|
2522
|
563
|
2523 /* Class 5: Printf-like functions that signal an error.
|
442
|
2524 These functions signal an error of a specified type, whose data
|
563
|
2525 is a one or more objects, a string (created using the arguments)
|
|
2526 and additional Lisp objects specified in FROB. (The syntax of FROB
|
|
2527 is the same as for class 2.)
|
|
2528
|
|
2529 There is no need for a class 6 because you can always attach 2
|
|
2530 objects using class 5 (for FROB, specify a list with three
|
|
2531 elements, the first of which is Qunbound), and these functions are
|
|
2532 not commonly used.
|
|
2533 */
|
442
|
2534
|
|
2535 DOESNT_RETURN
|
665
|
2536 signal_ferror_with_frob (Lisp_Object type, Lisp_Object frob, const CIntbyte *fmt,
|
563
|
2537 ...)
|
442
|
2538 {
|
|
2539 Lisp_Object obj;
|
|
2540 va_list args;
|
|
2541
|
|
2542 va_start (args, fmt);
|
771
|
2543 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
442
|
2544 va_end (args);
|
|
2545
|
|
2546 /* Fsignal GC-protects its args */
|
563
|
2547 signal_error_1 (type, Fcons (obj, build_error_data (0, frob)));
|
442
|
2548 }
|
|
2549
|
|
2550 void
|
563
|
2551 maybe_signal_ferror_with_frob (Lisp_Object type, Lisp_Object frob,
|
578
|
2552 Lisp_Object class, Error_Behavior errb,
|
665
|
2553 const CIntbyte *fmt, ...)
|
442
|
2554 {
|
|
2555 Lisp_Object obj;
|
|
2556 va_list args;
|
|
2557
|
|
2558 /* Optimization: */
|
|
2559 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2560 return;
|
|
2561
|
|
2562 va_start (args, fmt);
|
771
|
2563 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
428
|
2564 va_end (args);
|
|
2565
|
|
2566 /* Fsignal GC-protects its args */
|
563
|
2567 maybe_signal_error_1 (type, Fcons (obj, build_error_data (0, frob)), class,
|
|
2568 errb);
|
428
|
2569 }
|
|
2570
|
|
2571 Lisp_Object
|
563
|
2572 signal_continuable_ferror_with_frob (Lisp_Object type, Lisp_Object frob,
|
665
|
2573 const CIntbyte *fmt, ...)
|
428
|
2574 {
|
|
2575 Lisp_Object obj;
|
|
2576 va_list args;
|
|
2577
|
|
2578 va_start (args, fmt);
|
771
|
2579 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
428
|
2580 va_end (args);
|
|
2581
|
|
2582 /* Fsignal GC-protects its args */
|
563
|
2583 return Fsignal (type, Fcons (obj, build_error_data (0, frob)));
|
428
|
2584 }
|
|
2585
|
|
2586 Lisp_Object
|
563
|
2587 maybe_signal_continuable_ferror_with_frob (Lisp_Object type, Lisp_Object frob,
|
|
2588 Lisp_Object class,
|
578
|
2589 Error_Behavior errb,
|
665
|
2590 const CIntbyte *fmt, ...)
|
428
|
2591 {
|
|
2592 Lisp_Object obj;
|
|
2593 va_list args;
|
|
2594
|
|
2595 /* Optimization: */
|
|
2596 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2597 return Qnil;
|
|
2598
|
|
2599 va_start (args, fmt);
|
771
|
2600 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
428
|
2601 va_end (args);
|
|
2602
|
|
2603 /* Fsignal GC-protects its args */
|
563
|
2604 return maybe_signal_continuable_error_1 (type,
|
|
2605 Fcons (obj,
|
|
2606 build_error_data (0, frob)),
|
|
2607 class, errb);
|
428
|
2608 }
|
|
2609
|
|
2610
|
|
2611 /* This is what the QUIT macro calls to signal a quit */
|
|
2612 void
|
|
2613 signal_quit (void)
|
|
2614 {
|
|
2615 /* This function can GC */
|
|
2616 if (EQ (Vquit_flag, Qcritical))
|
|
2617 debug_on_quit |= 2; /* set critical bit. */
|
|
2618 Vquit_flag = Qnil;
|
|
2619 /* note that this is continuable. */
|
|
2620 Fsignal (Qquit, Qnil);
|
|
2621 }
|
|
2622
|
|
2623
|
563
|
2624 /************************ convenience error functions ***********************/
|
|
2625
|
436
|
2626 Lisp_Object
|
428
|
2627 signal_void_function_error (Lisp_Object function)
|
|
2628 {
|
436
|
2629 return Fsignal (Qvoid_function, list1 (function));
|
428
|
2630 }
|
|
2631
|
436
|
2632 Lisp_Object
|
428
|
2633 signal_invalid_function_error (Lisp_Object function)
|
|
2634 {
|
436
|
2635 return Fsignal (Qinvalid_function, list1 (function));
|
428
|
2636 }
|
|
2637
|
436
|
2638 Lisp_Object
|
428
|
2639 signal_wrong_number_of_arguments_error (Lisp_Object function, int nargs)
|
|
2640 {
|
436
|
2641 return Fsignal (Qwrong_number_of_arguments,
|
|
2642 list2 (function, make_int (nargs)));
|
428
|
2643 }
|
|
2644
|
|
2645 /* Used in list traversal macros for efficiency. */
|
436
|
2646 DOESNT_RETURN
|
428
|
2647 signal_malformed_list_error (Lisp_Object list)
|
|
2648 {
|
563
|
2649 signal_error (Qmalformed_list, 0, list);
|
428
|
2650 }
|
|
2651
|
436
|
2652 DOESNT_RETURN
|
428
|
2653 signal_malformed_property_list_error (Lisp_Object list)
|
|
2654 {
|
563
|
2655 signal_error (Qmalformed_property_list, 0, list);
|
428
|
2656 }
|
|
2657
|
436
|
2658 DOESNT_RETURN
|
428
|
2659 signal_circular_list_error (Lisp_Object list)
|
|
2660 {
|
563
|
2661 signal_error (Qcircular_list, 0, list);
|
428
|
2662 }
|
|
2663
|
436
|
2664 DOESNT_RETURN
|
428
|
2665 signal_circular_property_list_error (Lisp_Object list)
|
|
2666 {
|
563
|
2667 signal_error (Qcircular_property_list, 0, list);
|
428
|
2668 }
|
442
|
2669
|
|
2670 DOESNT_RETURN
|
665
|
2671 syntax_error (const CIntbyte *reason, Lisp_Object frob)
|
442
|
2672 {
|
563
|
2673 signal_error (Qsyntax_error, reason, frob);
|
442
|
2674 }
|
|
2675
|
|
2676 DOESNT_RETURN
|
665
|
2677 syntax_error_2 (const CIntbyte *reason, Lisp_Object frob1, Lisp_Object frob2)
|
442
|
2678 {
|
563
|
2679 signal_error_2 (Qsyntax_error, reason, frob1, frob2);
|
|
2680 }
|
|
2681
|
|
2682 void
|
665
|
2683 maybe_syntax_error (const CIntbyte *reason, Lisp_Object frob,
|
578
|
2684 Lisp_Object class, Error_Behavior errb)
|
563
|
2685 {
|
|
2686 maybe_signal_error (Qsyntax_error, reason, frob, class, errb);
|
|
2687 }
|
|
2688
|
|
2689 DOESNT_RETURN
|
665
|
2690 sferror (const CIntbyte *reason, Lisp_Object frob)
|
563
|
2691 {
|
|
2692 signal_error (Qstructure_formation_error, reason, frob);
|
|
2693 }
|
|
2694
|
|
2695 DOESNT_RETURN
|
665
|
2696 sferror_2 (const CIntbyte *reason, Lisp_Object frob1, Lisp_Object frob2)
|
563
|
2697 {
|
|
2698 signal_error_2 (Qstructure_formation_error, reason, frob1, frob2);
|
|
2699 }
|
|
2700
|
|
2701 void
|
665
|
2702 maybe_sferror (const CIntbyte *reason, Lisp_Object frob,
|
578
|
2703 Lisp_Object class, Error_Behavior errb)
|
563
|
2704 {
|
|
2705 maybe_signal_error (Qstructure_formation_error, reason, frob, class, errb);
|
442
|
2706 }
|
|
2707
|
|
2708 DOESNT_RETURN
|
665
|
2709 invalid_argument (const CIntbyte *reason, Lisp_Object frob)
|
442
|
2710 {
|
563
|
2711 signal_error (Qinvalid_argument, reason, frob);
|
442
|
2712 }
|
|
2713
|
|
2714 DOESNT_RETURN
|
665
|
2715 invalid_argument_2 (const CIntbyte *reason, Lisp_Object frob1,
|
609
|
2716 Lisp_Object frob2)
|
442
|
2717 {
|
563
|
2718 signal_error_2 (Qinvalid_argument, reason, frob1, frob2);
|
|
2719 }
|
|
2720
|
|
2721 void
|
665
|
2722 maybe_invalid_argument (const CIntbyte *reason, Lisp_Object frob,
|
578
|
2723 Lisp_Object class, Error_Behavior errb)
|
563
|
2724 {
|
|
2725 maybe_signal_error (Qinvalid_argument, reason, frob, class, errb);
|
|
2726 }
|
|
2727
|
|
2728 DOESNT_RETURN
|
665
|
2729 invalid_constant (const CIntbyte *reason, Lisp_Object frob)
|
563
|
2730 {
|
|
2731 signal_error (Qinvalid_constant, reason, frob);
|
|
2732 }
|
|
2733
|
|
2734 DOESNT_RETURN
|
665
|
2735 invalid_constant_2 (const CIntbyte *reason, Lisp_Object frob1,
|
609
|
2736 Lisp_Object frob2)
|
563
|
2737 {
|
|
2738 signal_error_2 (Qinvalid_constant, reason, frob1, frob2);
|
|
2739 }
|
|
2740
|
|
2741 void
|
665
|
2742 maybe_invalid_constant (const CIntbyte *reason, Lisp_Object frob,
|
578
|
2743 Lisp_Object class, Error_Behavior errb)
|
563
|
2744 {
|
|
2745 maybe_signal_error (Qinvalid_constant, reason, frob, class, errb);
|
442
|
2746 }
|
|
2747
|
|
2748 DOESNT_RETURN
|
665
|
2749 invalid_operation (const CIntbyte *reason, Lisp_Object frob)
|
442
|
2750 {
|
563
|
2751 signal_error (Qinvalid_operation, reason, frob);
|
442
|
2752 }
|
|
2753
|
|
2754 DOESNT_RETURN
|
665
|
2755 invalid_operation_2 (const CIntbyte *reason, Lisp_Object frob1,
|
609
|
2756 Lisp_Object frob2)
|
442
|
2757 {
|
563
|
2758 signal_error_2 (Qinvalid_operation, reason, frob1, frob2);
|
|
2759 }
|
|
2760
|
|
2761 void
|
665
|
2762 maybe_invalid_operation (const CIntbyte *reason, Lisp_Object frob,
|
578
|
2763 Lisp_Object class, Error_Behavior errb)
|
563
|
2764 {
|
|
2765 maybe_signal_error (Qinvalid_operation, reason, frob, class, errb);
|
442
|
2766 }
|
|
2767
|
|
2768 DOESNT_RETURN
|
665
|
2769 invalid_change (const CIntbyte *reason, Lisp_Object frob)
|
442
|
2770 {
|
563
|
2771 signal_error (Qinvalid_change, reason, frob);
|
442
|
2772 }
|
|
2773
|
|
2774 DOESNT_RETURN
|
665
|
2775 invalid_change_2 (const CIntbyte *reason, Lisp_Object frob1, Lisp_Object frob2)
|
442
|
2776 {
|
563
|
2777 signal_error_2 (Qinvalid_change, reason, frob1, frob2);
|
|
2778 }
|
|
2779
|
|
2780 void
|
665
|
2781 maybe_invalid_change (const CIntbyte *reason, Lisp_Object frob,
|
578
|
2782 Lisp_Object class, Error_Behavior errb)
|
563
|
2783 {
|
|
2784 maybe_signal_error (Qinvalid_change, reason, frob, class, errb);
|
|
2785 }
|
|
2786
|
|
2787 DOESNT_RETURN
|
665
|
2788 invalid_state (const CIntbyte *reason, Lisp_Object frob)
|
563
|
2789 {
|
|
2790 signal_error (Qinvalid_state, reason, frob);
|
|
2791 }
|
|
2792
|
|
2793 DOESNT_RETURN
|
665
|
2794 invalid_state_2 (const CIntbyte *reason, Lisp_Object frob1, Lisp_Object frob2)
|
563
|
2795 {
|
|
2796 signal_error_2 (Qinvalid_state, reason, frob1, frob2);
|
|
2797 }
|
|
2798
|
|
2799 void
|
665
|
2800 maybe_invalid_state (const CIntbyte *reason, Lisp_Object frob,
|
578
|
2801 Lisp_Object class, Error_Behavior errb)
|
563
|
2802 {
|
|
2803 maybe_signal_error (Qinvalid_state, reason, frob, class, errb);
|
|
2804 }
|
|
2805
|
|
2806 DOESNT_RETURN
|
665
|
2807 wtaerror (const CIntbyte *reason, Lisp_Object frob)
|
563
|
2808 {
|
|
2809 signal_error (Qwrong_type_argument, reason, frob);
|
|
2810 }
|
|
2811
|
|
2812 DOESNT_RETURN
|
665
|
2813 stack_overflow (const CIntbyte *reason, Lisp_Object frob)
|
563
|
2814 {
|
|
2815 signal_error (Qstack_overflow, reason, frob);
|
|
2816 }
|
|
2817
|
|
2818 DOESNT_RETURN
|
665
|
2819 out_of_memory (const CIntbyte *reason, Lisp_Object frob)
|
563
|
2820 {
|
|
2821 signal_error (Qout_of_memory, reason, frob);
|
|
2822 }
|
|
2823
|
|
2824 DOESNT_RETURN
|
665
|
2825 printing_unreadable_object (const CIntbyte *fmt, ...)
|
563
|
2826 {
|
|
2827 Lisp_Object obj;
|
|
2828 va_list args;
|
|
2829
|
|
2830 va_start (args, fmt);
|
771
|
2831 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
563
|
2832 va_end (args);
|
|
2833
|
|
2834 /* Fsignal GC-protects its args */
|
|
2835 signal_error (Qprinting_unreadable_object, 0, obj);
|
442
|
2836 }
|
|
2837
|
428
|
2838
|
|
2839 /************************************************************************/
|
|
2840 /* User commands */
|
|
2841 /************************************************************************/
|
|
2842
|
|
2843 DEFUN ("commandp", Fcommandp, 1, 1, 0, /*
|
|
2844 Return t if FUNCTION makes provisions for interactive calling.
|
|
2845 This means it contains a description for how to read arguments to give it.
|
|
2846 The value is nil for an invalid function or a symbol with no function
|
|
2847 definition.
|
|
2848
|
|
2849 Interactively callable functions include
|
|
2850
|
|
2851 -- strings and vectors (treated as keyboard macros)
|
|
2852 -- lambda-expressions that contain a top-level call to `interactive'
|
|
2853 -- autoload definitions made by `autoload' with non-nil fourth argument
|
|
2854 (i.e. the interactive flag)
|
|
2855 -- compiled-function objects with a non-nil `compiled-function-interactive'
|
|
2856 value
|
|
2857 -- subrs (built-in functions) that are interactively callable
|
|
2858
|
|
2859 Also, a symbol satisfies `commandp' if its function definition does so.
|
|
2860 */
|
|
2861 (function))
|
|
2862 {
|
|
2863 Lisp_Object fun = indirect_function (function, 0);
|
|
2864
|
|
2865 if (COMPILED_FUNCTIONP (fun))
|
|
2866 return XCOMPILED_FUNCTION (fun)->flags.interactivep ? Qt : Qnil;
|
|
2867
|
|
2868 /* Lists may represent commands. */
|
|
2869 if (CONSP (fun))
|
|
2870 {
|
|
2871 Lisp_Object funcar = XCAR (fun);
|
|
2872 if (EQ (funcar, Qlambda))
|
|
2873 return Fassq (Qinteractive, Fcdr (Fcdr (fun)));
|
|
2874 if (EQ (funcar, Qautoload))
|
|
2875 return Fcar (Fcdr (Fcdr (Fcdr (fun))));
|
|
2876 else
|
|
2877 return Qnil;
|
|
2878 }
|
|
2879
|
|
2880 /* Emacs primitives are interactive if their DEFUN specifies an
|
|
2881 interactive spec. */
|
|
2882 if (SUBRP (fun))
|
|
2883 return XSUBR (fun)->prompt ? Qt : Qnil;
|
|
2884
|
|
2885 /* Strings and vectors are keyboard macros. */
|
|
2886 if (VECTORP (fun) || STRINGP (fun))
|
|
2887 return Qt;
|
|
2888
|
|
2889 /* Everything else (including Qunbound) is not a command. */
|
|
2890 return Qnil;
|
|
2891 }
|
|
2892
|
|
2893 DEFUN ("command-execute", Fcommand_execute, 1, 3, 0, /*
|
|
2894 Execute CMD as an editor command.
|
|
2895 CMD must be an object that satisfies the `commandp' predicate.
|
|
2896 Optional second arg RECORD-FLAG is as in `call-interactively'.
|
|
2897 The argument KEYS specifies the value to use instead of (this-command-keys)
|
|
2898 when reading the arguments.
|
|
2899 */
|
444
|
2900 (cmd, record_flag, keys))
|
428
|
2901 {
|
|
2902 /* This function can GC */
|
|
2903 Lisp_Object prefixarg;
|
|
2904 Lisp_Object final = cmd;
|
|
2905 struct backtrace backtrace;
|
|
2906 struct console *con = XCONSOLE (Vselected_console);
|
|
2907
|
|
2908 prefixarg = con->prefix_arg;
|
|
2909 con->prefix_arg = Qnil;
|
|
2910 Vcurrent_prefix_arg = prefixarg;
|
|
2911 debug_on_next_call = 0; /* #### from FSFmacs; correct? */
|
|
2912
|
|
2913 if (SYMBOLP (cmd) && !NILP (Fget (cmd, Qdisabled, Qnil)))
|
733
|
2914 return run_hook (Qdisabled_command_hook);
|
428
|
2915
|
|
2916 for (;;)
|
|
2917 {
|
|
2918 final = indirect_function (cmd, 1);
|
|
2919 if (CONSP (final) && EQ (Fcar (final), Qautoload))
|
|
2920 do_autoload (final, cmd);
|
|
2921 else
|
|
2922 break;
|
|
2923 }
|
|
2924
|
|
2925 if (CONSP (final) || SUBRP (final) || COMPILED_FUNCTIONP (final))
|
|
2926 {
|
|
2927 backtrace.function = &Qcall_interactively;
|
|
2928 backtrace.args = &cmd;
|
|
2929 backtrace.nargs = 1;
|
|
2930 backtrace.evalargs = 0;
|
|
2931 backtrace.pdlcount = specpdl_depth();
|
|
2932 backtrace.debug_on_exit = 0;
|
|
2933 PUSH_BACKTRACE (backtrace);
|
|
2934
|
444
|
2935 final = Fcall_interactively (cmd, record_flag, keys);
|
428
|
2936
|
|
2937 POP_BACKTRACE (backtrace);
|
|
2938 return final;
|
|
2939 }
|
|
2940 else if (STRINGP (final) || VECTORP (final))
|
|
2941 {
|
|
2942 return Fexecute_kbd_macro (final, prefixarg);
|
|
2943 }
|
|
2944 else
|
|
2945 {
|
|
2946 Fsignal (Qwrong_type_argument,
|
|
2947 Fcons (Qcommandp,
|
|
2948 (EQ (cmd, final)
|
|
2949 ? list1 (cmd)
|
|
2950 : list2 (cmd, final))));
|
|
2951 return Qnil;
|
|
2952 }
|
|
2953 }
|
|
2954
|
|
2955 DEFUN ("interactive-p", Finteractive_p, 0, 0, 0, /*
|
|
2956 Return t if function in which this appears was called interactively.
|
|
2957 This means that the function was called with call-interactively (which
|
|
2958 includes being called as the binding of a key)
|
|
2959 and input is currently coming from the keyboard (not in keyboard macro).
|
|
2960 */
|
|
2961 ())
|
|
2962 {
|
|
2963 REGISTER struct backtrace *btp;
|
|
2964 REGISTER Lisp_Object fun;
|
|
2965
|
|
2966 if (!INTERACTIVE)
|
|
2967 return Qnil;
|
|
2968
|
|
2969 /* Unless the object was compiled, skip the frame of interactive-p itself
|
|
2970 (if interpreted) or the frame of byte-code (if called from a compiled
|
|
2971 function). Note that *btp->function may be a symbol pointing at a
|
|
2972 compiled function. */
|
|
2973 btp = backtrace_list;
|
|
2974
|
|
2975 #if 0 /* FSFmacs */
|
|
2976
|
|
2977 /* #### FSFmacs does the following instead. I can't figure
|
|
2978 out which one is more correct. */
|
|
2979 /* If this isn't a byte-compiled function, there may be a frame at
|
|
2980 the top for Finteractive_p itself. If so, skip it. */
|
|
2981 fun = Findirect_function (*btp->function);
|
|
2982 if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p)
|
|
2983 btp = btp->next;
|
|
2984
|
|
2985 /* If we're running an Emacs 18-style byte-compiled function, there
|
|
2986 may be a frame for Fbyte_code. Now, given the strictest
|
|
2987 definition, this function isn't really being called
|
|
2988 interactively, but because that's the way Emacs 18 always builds
|
|
2989 byte-compiled functions, we'll accept it for now. */
|
|
2990 if (EQ (*btp->function, Qbyte_code))
|
|
2991 btp = btp->next;
|
|
2992
|
|
2993 /* If this isn't a byte-compiled function, then we may now be
|
|
2994 looking at several frames for special forms. Skip past them. */
|
|
2995 while (btp &&
|
|
2996 btp->nargs == UNEVALLED)
|
|
2997 btp = btp->next;
|
|
2998
|
|
2999 #else
|
|
3000
|
|
3001 if (! (COMPILED_FUNCTIONP (Findirect_function (*btp->function))))
|
|
3002 btp = btp->next;
|
|
3003 for (;
|
|
3004 btp && (btp->nargs == UNEVALLED
|
|
3005 || EQ (*btp->function, Qbyte_code));
|
|
3006 btp = btp->next)
|
|
3007 {}
|
|
3008 /* btp now points at the frame of the innermost function
|
|
3009 that DOES eval its args.
|
|
3010 If it is a built-in function (such as load or eval-region)
|
|
3011 return nil. */
|
|
3012 /* Beats me why this is necessary, but it is */
|
|
3013 if (btp && EQ (*btp->function, Qcall_interactively))
|
|
3014 return Qt;
|
|
3015
|
|
3016 #endif
|
|
3017
|
|
3018 fun = Findirect_function (*btp->function);
|
|
3019 if (SUBRP (fun))
|
|
3020 return Qnil;
|
|
3021 /* btp points to the frame of a Lisp function that called interactive-p.
|
|
3022 Return t if that function was called interactively. */
|
|
3023 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
|
|
3024 return Qt;
|
|
3025 return Qnil;
|
|
3026 }
|
|
3027
|
|
3028
|
|
3029 /************************************************************************/
|
|
3030 /* Autoloading */
|
|
3031 /************************************************************************/
|
|
3032
|
|
3033 DEFUN ("autoload", Fautoload, 2, 5, 0, /*
|
444
|
3034 Define FUNCTION to autoload from FILENAME.
|
|
3035 FUNCTION is a symbol; FILENAME is a file name string to pass to `load'.
|
|
3036 The remaining optional arguments provide additional info about the
|
|
3037 real definition.
|
|
3038 DOCSTRING is documentation for FUNCTION.
|
|
3039 INTERACTIVE, if non-nil, says FUNCTION can be called interactively.
|
|
3040 TYPE indicates the type of the object:
|
428
|
3041 nil or omitted says FUNCTION is a function,
|
|
3042 `keymap' says FUNCTION is really a keymap, and
|
|
3043 `macro' or t says FUNCTION is really a macro.
|
444
|
3044 If FUNCTION already has a non-void function definition that is not an
|
|
3045 autoload object, this function does nothing and returns nil.
|
428
|
3046 */
|
444
|
3047 (function, filename, docstring, interactive, type))
|
428
|
3048 {
|
|
3049 /* This function can GC */
|
|
3050 CHECK_SYMBOL (function);
|
444
|
3051 CHECK_STRING (filename);
|
428
|
3052
|
|
3053 /* If function is defined and not as an autoload, don't override */
|
|
3054 {
|
|
3055 Lisp_Object f = XSYMBOL (function)->function;
|
|
3056 if (!UNBOUNDP (f) && !(CONSP (f) && EQ (XCAR (f), Qautoload)))
|
|
3057 return Qnil;
|
|
3058 }
|
|
3059
|
|
3060 if (purify_flag)
|
|
3061 {
|
|
3062 /* Attempt to avoid consing identical (string=) pure strings. */
|
444
|
3063 filename = Fsymbol_name (Fintern (filename, Qnil));
|
428
|
3064 }
|
440
|
3065
|
444
|
3066 return Ffset (function, Fcons (Qautoload, list4 (filename,
|
428
|
3067 docstring,
|
|
3068 interactive,
|
|
3069 type)));
|
|
3070 }
|
|
3071
|
|
3072 Lisp_Object
|
|
3073 un_autoload (Lisp_Object oldqueue)
|
|
3074 {
|
|
3075 /* This function can GC */
|
|
3076 REGISTER Lisp_Object queue, first, second;
|
|
3077
|
|
3078 /* Queue to unwind is current value of Vautoload_queue.
|
|
3079 oldqueue is the shadowed value to leave in Vautoload_queue. */
|
|
3080 queue = Vautoload_queue;
|
|
3081 Vautoload_queue = oldqueue;
|
|
3082 while (CONSP (queue))
|
|
3083 {
|
|
3084 first = XCAR (queue);
|
|
3085 second = Fcdr (first);
|
|
3086 first = Fcar (first);
|
|
3087 if (NILP (second))
|
|
3088 Vfeatures = first;
|
|
3089 else
|
|
3090 Ffset (first, second);
|
|
3091 queue = Fcdr (queue);
|
|
3092 }
|
|
3093 return Qnil;
|
|
3094 }
|
|
3095
|
|
3096 void
|
|
3097 do_autoload (Lisp_Object fundef,
|
|
3098 Lisp_Object funname)
|
|
3099 {
|
|
3100 /* This function can GC */
|
|
3101 int speccount = specpdl_depth();
|
|
3102 Lisp_Object fun = funname;
|
|
3103 struct gcpro gcpro1, gcpro2;
|
|
3104
|
|
3105 CHECK_SYMBOL (funname);
|
|
3106 GCPRO2 (fun, funname);
|
|
3107
|
|
3108 /* Value saved here is to be restored into Vautoload_queue */
|
|
3109 record_unwind_protect (un_autoload, Vautoload_queue);
|
|
3110 Vautoload_queue = Qt;
|
|
3111 call4 (Qload, Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil);
|
|
3112
|
|
3113 {
|
|
3114 Lisp_Object queue;
|
|
3115
|
|
3116 /* Save the old autoloads, in case we ever do an unload. */
|
|
3117 for (queue = Vautoload_queue; CONSP (queue); queue = XCDR (queue))
|
|
3118 {
|
|
3119 Lisp_Object first = XCAR (queue);
|
|
3120 Lisp_Object second = Fcdr (first);
|
|
3121
|
|
3122 first = Fcar (first);
|
|
3123
|
|
3124 /* Note: This test is subtle. The cdr of an autoload-queue entry
|
|
3125 may be an atom if the autoload entry was generated by a defalias
|
|
3126 or fset. */
|
|
3127 if (CONSP (second))
|
|
3128 Fput (first, Qautoload, (XCDR (second)));
|
|
3129 }
|
|
3130 }
|
|
3131
|
|
3132 /* Once loading finishes, don't undo it. */
|
|
3133 Vautoload_queue = Qt;
|
771
|
3134 unbind_to (speccount);
|
428
|
3135
|
|
3136 fun = indirect_function (fun, 0);
|
|
3137
|
|
3138 #if 0 /* FSFmacs */
|
|
3139 if (!NILP (Fequal (fun, fundef)))
|
|
3140 #else
|
|
3141 if (UNBOUNDP (fun)
|
|
3142 || (CONSP (fun)
|
|
3143 && EQ (XCAR (fun), Qautoload)))
|
|
3144 #endif
|
563
|
3145 invalid_state ("Autoloading failed to define function", funname);
|
428
|
3146 UNGCPRO;
|
|
3147 }
|
|
3148
|
|
3149
|
|
3150 /************************************************************************/
|
|
3151 /* eval, funcall, apply */
|
|
3152 /************************************************************************/
|
|
3153
|
|
3154 static Lisp_Object funcall_lambda (Lisp_Object fun,
|
442
|
3155 int nargs, Lisp_Object args[]);
|
428
|
3156 static int in_warnings;
|
|
3157
|
|
3158 static Lisp_Object
|
|
3159 in_warnings_restore (Lisp_Object minimus)
|
|
3160 {
|
|
3161 in_warnings = 0;
|
|
3162 return Qnil;
|
|
3163 }
|
|
3164
|
|
3165 DEFUN ("eval", Feval, 1, 1, 0, /*
|
|
3166 Evaluate FORM and return its value.
|
|
3167 */
|
|
3168 (form))
|
|
3169 {
|
|
3170 /* This function can GC */
|
|
3171 Lisp_Object fun, val, original_fun, original_args;
|
|
3172 int nargs;
|
|
3173 struct backtrace backtrace;
|
|
3174
|
|
3175 /* I think this is a pretty safe place to call Lisp code, don't you? */
|
|
3176 while (!in_warnings && !NILP (Vpending_warnings))
|
|
3177 {
|
|
3178 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
3179 int speccount = specpdl_depth();
|
|
3180 Lisp_Object this_warning_cons, this_warning, class, level, messij;
|
|
3181
|
|
3182 record_unwind_protect (in_warnings_restore, Qnil);
|
|
3183 in_warnings = 1;
|
|
3184 this_warning_cons = Vpending_warnings;
|
|
3185 this_warning = XCAR (this_warning_cons);
|
|
3186 /* in case an error occurs in the warn function, at least
|
|
3187 it won't happen infinitely */
|
|
3188 Vpending_warnings = XCDR (Vpending_warnings);
|
|
3189 free_cons (XCONS (this_warning_cons));
|
|
3190 class = XCAR (this_warning);
|
|
3191 level = XCAR (XCDR (this_warning));
|
|
3192 messij = XCAR (XCDR (XCDR (this_warning)));
|
|
3193 free_list (this_warning);
|
|
3194
|
|
3195 if (NILP (Vpending_warnings))
|
|
3196 Vpending_warnings_tail = Qnil; /* perhaps not strictly necessary,
|
|
3197 but safer */
|
|
3198
|
|
3199 GCPRO4 (form, class, level, messij);
|
|
3200 if (!STRINGP (messij))
|
|
3201 messij = Fprin1_to_string (messij, Qnil);
|
|
3202 call3 (Qdisplay_warning, class, messij, level);
|
|
3203 UNGCPRO;
|
771
|
3204 unbind_to (speccount);
|
428
|
3205 }
|
|
3206
|
|
3207 if (!CONSP (form))
|
|
3208 {
|
|
3209 if (SYMBOLP (form))
|
|
3210 return Fsymbol_value (form);
|
|
3211 else
|
|
3212 return form;
|
|
3213 }
|
|
3214
|
|
3215 QUIT;
|
|
3216 if ((consing_since_gc > gc_cons_threshold) || always_gc)
|
|
3217 {
|
|
3218 struct gcpro gcpro1;
|
|
3219 GCPRO1 (form);
|
|
3220 garbage_collect_1 ();
|
|
3221 UNGCPRO;
|
|
3222 }
|
|
3223
|
|
3224 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
3225 {
|
|
3226 if (max_lisp_eval_depth < 100)
|
|
3227 max_lisp_eval_depth = 100;
|
|
3228 if (lisp_eval_depth > max_lisp_eval_depth)
|
563
|
3229 stack_overflow ("Lisp nesting exceeds `max-lisp-eval-depth'",
|
|
3230 Qunbound);
|
428
|
3231 }
|
|
3232
|
|
3233 /* We guaranteed CONSP (form) above */
|
|
3234 original_fun = XCAR (form);
|
|
3235 original_args = XCDR (form);
|
|
3236
|
|
3237 GET_EXTERNAL_LIST_LENGTH (original_args, nargs);
|
|
3238
|
|
3239 backtrace.pdlcount = specpdl_depth();
|
|
3240 backtrace.function = &original_fun; /* This also protects them from gc */
|
|
3241 backtrace.args = &original_args;
|
|
3242 backtrace.nargs = UNEVALLED;
|
|
3243 backtrace.evalargs = 1;
|
|
3244 backtrace.debug_on_exit = 0;
|
|
3245 PUSH_BACKTRACE (backtrace);
|
|
3246
|
|
3247 if (debug_on_next_call)
|
|
3248 do_debug_on_call (Qt);
|
|
3249
|
|
3250 if (profiling_active)
|
|
3251 profile_increase_call_count (original_fun);
|
|
3252
|
|
3253 /* At this point, only original_fun and original_args
|
|
3254 have values that will be used below. */
|
|
3255 retry:
|
|
3256 fun = indirect_function (original_fun, 1);
|
|
3257
|
|
3258 if (SUBRP (fun))
|
|
3259 {
|
|
3260 Lisp_Subr *subr = XSUBR (fun);
|
|
3261 int max_args = subr->max_args;
|
|
3262
|
|
3263 if (nargs < subr->min_args)
|
|
3264 goto wrong_number_of_arguments;
|
|
3265
|
|
3266 if (max_args == UNEVALLED) /* Optimize for the common case */
|
|
3267 {
|
|
3268 backtrace.evalargs = 0;
|
|
3269 val = (((Lisp_Object (*) (Lisp_Object)) subr_function (subr))
|
|
3270 (original_args));
|
|
3271 }
|
|
3272 else if (nargs <= max_args)
|
|
3273 {
|
|
3274 struct gcpro gcpro1;
|
|
3275 Lisp_Object args[SUBR_MAX_ARGS];
|
|
3276 REGISTER Lisp_Object *p = args;
|
|
3277
|
|
3278 GCPRO1 (args[0]);
|
|
3279 gcpro1.nvars = 0;
|
|
3280
|
|
3281 {
|
|
3282 LIST_LOOP_2 (arg, original_args)
|
|
3283 {
|
|
3284 *p++ = Feval (arg);
|
|
3285 gcpro1.nvars++;
|
|
3286 }
|
|
3287 }
|
|
3288
|
|
3289 /* &optional args default to nil. */
|
|
3290 while (p - args < max_args)
|
|
3291 *p++ = Qnil;
|
|
3292
|
|
3293 backtrace.args = args;
|
|
3294 backtrace.nargs = nargs;
|
|
3295
|
|
3296 FUNCALL_SUBR (val, subr, args, max_args);
|
|
3297
|
|
3298 UNGCPRO;
|
|
3299 }
|
|
3300 else if (max_args == MANY)
|
|
3301 {
|
|
3302 /* Pass a vector of evaluated arguments */
|
|
3303 struct gcpro gcpro1;
|
|
3304 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
|
|
3305 REGISTER Lisp_Object *p = args;
|
|
3306
|
|
3307 GCPRO1 (args[0]);
|
|
3308 gcpro1.nvars = 0;
|
|
3309
|
|
3310 {
|
|
3311 LIST_LOOP_2 (arg, original_args)
|
|
3312 {
|
|
3313 *p++ = Feval (arg);
|
|
3314 gcpro1.nvars++;
|
|
3315 }
|
|
3316 }
|
|
3317
|
|
3318 backtrace.args = args;
|
|
3319 backtrace.nargs = nargs;
|
|
3320
|
|
3321 val = (((Lisp_Object (*) (int, Lisp_Object *)) subr_function (subr))
|
|
3322 (nargs, args));
|
|
3323
|
|
3324 UNGCPRO;
|
|
3325 }
|
|
3326 else
|
|
3327 {
|
|
3328 wrong_number_of_arguments:
|
440
|
3329 val = signal_wrong_number_of_arguments_error (original_fun, nargs);
|
428
|
3330 }
|
|
3331 }
|
|
3332 else if (COMPILED_FUNCTIONP (fun))
|
|
3333 {
|
|
3334 struct gcpro gcpro1;
|
|
3335 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
|
|
3336 REGISTER Lisp_Object *p = args;
|
|
3337
|
|
3338 GCPRO1 (args[0]);
|
|
3339 gcpro1.nvars = 0;
|
|
3340
|
|
3341 {
|
|
3342 LIST_LOOP_2 (arg, original_args)
|
|
3343 {
|
|
3344 *p++ = Feval (arg);
|
|
3345 gcpro1.nvars++;
|
|
3346 }
|
|
3347 }
|
|
3348
|
|
3349 backtrace.args = args;
|
|
3350 backtrace.nargs = nargs;
|
|
3351 backtrace.evalargs = 0;
|
|
3352
|
|
3353 val = funcall_compiled_function (fun, nargs, args);
|
|
3354
|
|
3355 /* Do the debug-on-exit now, while args is still GCPROed. */
|
|
3356 if (backtrace.debug_on_exit)
|
|
3357 val = do_debug_on_exit (val);
|
|
3358 /* Don't do it again when we return to eval. */
|
|
3359 backtrace.debug_on_exit = 0;
|
|
3360
|
|
3361 UNGCPRO;
|
|
3362 }
|
|
3363 else if (CONSP (fun))
|
|
3364 {
|
|
3365 Lisp_Object funcar = XCAR (fun);
|
|
3366
|
|
3367 if (EQ (funcar, Qautoload))
|
|
3368 {
|
|
3369 do_autoload (fun, original_fun);
|
|
3370 goto retry;
|
|
3371 }
|
|
3372 else if (EQ (funcar, Qmacro))
|
|
3373 {
|
|
3374 val = Feval (apply1 (XCDR (fun), original_args));
|
|
3375 }
|
|
3376 else if (EQ (funcar, Qlambda))
|
|
3377 {
|
|
3378 struct gcpro gcpro1;
|
|
3379 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
|
|
3380 REGISTER Lisp_Object *p = args;
|
|
3381
|
|
3382 GCPRO1 (args[0]);
|
|
3383 gcpro1.nvars = 0;
|
|
3384
|
|
3385 {
|
|
3386 LIST_LOOP_2 (arg, original_args)
|
|
3387 {
|
|
3388 *p++ = Feval (arg);
|
|
3389 gcpro1.nvars++;
|
|
3390 }
|
|
3391 }
|
|
3392
|
|
3393 UNGCPRO;
|
|
3394
|
|
3395 backtrace.args = args; /* this also GCPROs `args' */
|
|
3396 backtrace.nargs = nargs;
|
|
3397 backtrace.evalargs = 0;
|
|
3398
|
|
3399 val = funcall_lambda (fun, nargs, args);
|
|
3400
|
|
3401 /* Do the debug-on-exit now, while args is still GCPROed. */
|
|
3402 if (backtrace.debug_on_exit)
|
|
3403 val = do_debug_on_exit (val);
|
|
3404 /* Don't do it again when we return to eval. */
|
|
3405 backtrace.debug_on_exit = 0;
|
|
3406 }
|
|
3407 else
|
|
3408 {
|
|
3409 goto invalid_function;
|
|
3410 }
|
|
3411 }
|
|
3412 else /* ! (SUBRP (fun) || COMPILED_FUNCTIONP (fun) || CONSP (fun)) */
|
|
3413 {
|
|
3414 invalid_function:
|
436
|
3415 val = signal_invalid_function_error (fun);
|
428
|
3416 }
|
|
3417
|
|
3418 lisp_eval_depth--;
|
|
3419 if (backtrace.debug_on_exit)
|
|
3420 val = do_debug_on_exit (val);
|
|
3421 POP_BACKTRACE (backtrace);
|
|
3422 return val;
|
|
3423 }
|
|
3424
|
|
3425
|
|
3426 DEFUN ("funcall", Ffuncall, 1, MANY, 0, /*
|
|
3427 Call first argument as a function, passing the remaining arguments to it.
|
|
3428 Thus, (funcall 'cons 'x 'y) returns (x . y).
|
|
3429 */
|
|
3430 (int nargs, Lisp_Object *args))
|
|
3431 {
|
|
3432 /* This function can GC */
|
|
3433 Lisp_Object fun;
|
|
3434 Lisp_Object val;
|
|
3435 struct backtrace backtrace;
|
|
3436 int fun_nargs = nargs - 1;
|
|
3437 Lisp_Object *fun_args = args + 1;
|
|
3438
|
|
3439 QUIT;
|
|
3440 if ((consing_since_gc > gc_cons_threshold) || always_gc)
|
|
3441 /* Callers should gcpro lexpr args */
|
|
3442 garbage_collect_1 ();
|
|
3443
|
|
3444 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
3445 {
|
|
3446 if (max_lisp_eval_depth < 100)
|
|
3447 max_lisp_eval_depth = 100;
|
|
3448 if (lisp_eval_depth > max_lisp_eval_depth)
|
563
|
3449 stack_overflow ("Lisp nesting exceeds `max-lisp-eval-depth'",
|
|
3450 Qunbound);
|
428
|
3451 }
|
|
3452
|
|
3453 backtrace.pdlcount = specpdl_depth();
|
|
3454 backtrace.function = &args[0];
|
|
3455 backtrace.args = fun_args;
|
|
3456 backtrace.nargs = fun_nargs;
|
|
3457 backtrace.evalargs = 0;
|
|
3458 backtrace.debug_on_exit = 0;
|
|
3459 PUSH_BACKTRACE (backtrace);
|
|
3460
|
|
3461 if (debug_on_next_call)
|
|
3462 do_debug_on_call (Qlambda);
|
|
3463
|
|
3464 retry:
|
|
3465
|
|
3466 fun = args[0];
|
|
3467
|
|
3468 /* It might be useful to place this *after* all the checks. */
|
|
3469 if (profiling_active)
|
|
3470 profile_increase_call_count (fun);
|
|
3471
|
|
3472 /* We could call indirect_function directly, but profiling shows
|
|
3473 this is worth optimizing by partially unrolling the loop. */
|
|
3474 if (SYMBOLP (fun))
|
|
3475 {
|
|
3476 fun = XSYMBOL (fun)->function;
|
|
3477 if (SYMBOLP (fun))
|
|
3478 {
|
|
3479 fun = XSYMBOL (fun)->function;
|
|
3480 if (SYMBOLP (fun))
|
|
3481 fun = indirect_function (fun, 1);
|
|
3482 }
|
|
3483 }
|
|
3484
|
|
3485 if (SUBRP (fun))
|
|
3486 {
|
|
3487 Lisp_Subr *subr = XSUBR (fun);
|
|
3488 int max_args = subr->max_args;
|
|
3489 Lisp_Object spacious_args[SUBR_MAX_ARGS];
|
|
3490
|
|
3491 if (fun_nargs == max_args) /* Optimize for the common case */
|
|
3492 {
|
|
3493 funcall_subr:
|
|
3494 FUNCALL_SUBR (val, subr, fun_args, max_args);
|
|
3495 }
|
436
|
3496 else if (fun_nargs < subr->min_args)
|
|
3497 {
|
|
3498 goto wrong_number_of_arguments;
|
|
3499 }
|
428
|
3500 else if (fun_nargs < max_args)
|
|
3501 {
|
|
3502 Lisp_Object *p = spacious_args;
|
|
3503
|
|
3504 /* Default optionals to nil */
|
|
3505 while (fun_nargs--)
|
|
3506 *p++ = *fun_args++;
|
|
3507 while (p - spacious_args < max_args)
|
|
3508 *p++ = Qnil;
|
|
3509
|
|
3510 fun_args = spacious_args;
|
|
3511 goto funcall_subr;
|
|
3512 }
|
|
3513 else if (max_args == MANY)
|
|
3514 {
|
436
|
3515 val = SUBR_FUNCTION (subr, MANY) (fun_nargs, fun_args);
|
428
|
3516 }
|
|
3517 else if (max_args == UNEVALLED) /* Can't funcall a special form */
|
|
3518 {
|
|
3519 goto invalid_function;
|
|
3520 }
|
|
3521 else
|
|
3522 {
|
|
3523 wrong_number_of_arguments:
|
436
|
3524 val = signal_wrong_number_of_arguments_error (fun, fun_nargs);
|
428
|
3525 }
|
|
3526 }
|
|
3527 else if (COMPILED_FUNCTIONP (fun))
|
|
3528 {
|
|
3529 val = funcall_compiled_function (fun, fun_nargs, fun_args);
|
|
3530 }
|
|
3531 else if (CONSP (fun))
|
|
3532 {
|
|
3533 Lisp_Object funcar = XCAR (fun);
|
|
3534
|
|
3535 if (EQ (funcar, Qlambda))
|
|
3536 {
|
|
3537 val = funcall_lambda (fun, fun_nargs, fun_args);
|
|
3538 }
|
|
3539 else if (EQ (funcar, Qautoload))
|
|
3540 {
|
|
3541 do_autoload (fun, args[0]);
|
|
3542 goto retry;
|
|
3543 }
|
|
3544 else /* Can't funcall a macro */
|
|
3545 {
|
|
3546 goto invalid_function;
|
|
3547 }
|
|
3548 }
|
|
3549 else if (UNBOUNDP (fun))
|
|
3550 {
|
436
|
3551 val = signal_void_function_error (args[0]);
|
428
|
3552 }
|
|
3553 else
|
|
3554 {
|
|
3555 invalid_function:
|
436
|
3556 val = signal_invalid_function_error (fun);
|
428
|
3557 }
|
|
3558
|
|
3559 lisp_eval_depth--;
|
|
3560 if (backtrace.debug_on_exit)
|
|
3561 val = do_debug_on_exit (val);
|
|
3562 POP_BACKTRACE (backtrace);
|
|
3563 return val;
|
|
3564 }
|
|
3565
|
|
3566 DEFUN ("functionp", Ffunctionp, 1, 1, 0, /*
|
|
3567 Return t if OBJECT can be called as a function, else nil.
|
|
3568 A function is an object that can be applied to arguments,
|
|
3569 using for example `funcall' or `apply'.
|
|
3570 */
|
|
3571 (object))
|
|
3572 {
|
|
3573 if (SYMBOLP (object))
|
|
3574 object = indirect_function (object, 0);
|
|
3575
|
|
3576 return
|
|
3577 (SUBRP (object) ||
|
|
3578 COMPILED_FUNCTIONP (object) ||
|
|
3579 (CONSP (object) &&
|
|
3580 (EQ (XCAR (object), Qlambda) ||
|
|
3581 EQ (XCAR (object), Qautoload))))
|
|
3582 ? Qt : Qnil;
|
|
3583 }
|
|
3584
|
|
3585 static Lisp_Object
|
|
3586 function_argcount (Lisp_Object function, int function_min_args_p)
|
|
3587 {
|
|
3588 Lisp_Object orig_function = function;
|
|
3589 Lisp_Object arglist;
|
|
3590
|
|
3591 retry:
|
|
3592
|
|
3593 if (SYMBOLP (function))
|
|
3594 function = indirect_function (function, 1);
|
|
3595
|
|
3596 if (SUBRP (function))
|
|
3597 {
|
442
|
3598 /* Using return with the ?: operator tickles a DEC CC compiler bug. */
|
|
3599 if (function_min_args_p)
|
|
3600 return Fsubr_min_args (function);
|
|
3601 else
|
|
3602 return Fsubr_max_args (function);
|
428
|
3603 }
|
|
3604 else if (COMPILED_FUNCTIONP (function))
|
|
3605 {
|
|
3606 arglist = compiled_function_arglist (XCOMPILED_FUNCTION (function));
|
|
3607 }
|
|
3608 else if (CONSP (function))
|
|
3609 {
|
|
3610 Lisp_Object funcar = XCAR (function);
|
|
3611
|
|
3612 if (EQ (funcar, Qmacro))
|
|
3613 {
|
|
3614 function = XCDR (function);
|
|
3615 goto retry;
|
|
3616 }
|
|
3617 else if (EQ (funcar, Qautoload))
|
|
3618 {
|
442
|
3619 struct gcpro gcpro1;
|
|
3620
|
|
3621 GCPRO1 (function);
|
428
|
3622 do_autoload (function, orig_function);
|
442
|
3623 UNGCPRO;
|
|
3624 function = orig_function;
|
428
|
3625 goto retry;
|
|
3626 }
|
|
3627 else if (EQ (funcar, Qlambda))
|
|
3628 {
|
|
3629 arglist = Fcar (XCDR (function));
|
|
3630 }
|
|
3631 else
|
|
3632 {
|
|
3633 goto invalid_function;
|
|
3634 }
|
|
3635 }
|
|
3636 else
|
|
3637 {
|
|
3638 invalid_function:
|
442
|
3639 return signal_invalid_function_error (orig_function);
|
428
|
3640 }
|
|
3641
|
|
3642 {
|
|
3643 int argcount = 0;
|
|
3644
|
|
3645 EXTERNAL_LIST_LOOP_2 (arg, arglist)
|
|
3646 {
|
|
3647 if (EQ (arg, Qand_optional))
|
|
3648 {
|
|
3649 if (function_min_args_p)
|
|
3650 break;
|
|
3651 }
|
|
3652 else if (EQ (arg, Qand_rest))
|
|
3653 {
|
|
3654 if (function_min_args_p)
|
|
3655 break;
|
|
3656 else
|
|
3657 return Qnil;
|
|
3658 }
|
|
3659 else
|
|
3660 {
|
|
3661 argcount++;
|
|
3662 }
|
|
3663 }
|
|
3664
|
|
3665 return make_int (argcount);
|
|
3666 }
|
|
3667 }
|
|
3668
|
|
3669 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /*
|
617
|
3670 Return the minimum number of arguments a function may be called with.
|
428
|
3671 The function may be any form that can be passed to `funcall',
|
|
3672 any special form, or any macro.
|
|
3673 */
|
|
3674 (function))
|
|
3675 {
|
|
3676 return function_argcount (function, 1);
|
|
3677 }
|
|
3678
|
|
3679 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /*
|
617
|
3680 Return the maximum number of arguments a function may be called with.
|
428
|
3681 The function may be any form that can be passed to `funcall',
|
|
3682 any special form, or any macro.
|
|
3683 If the function takes an arbitrary number of arguments or is
|
|
3684 a built-in special form, nil is returned.
|
|
3685 */
|
|
3686 (function))
|
|
3687 {
|
|
3688 return function_argcount (function, 0);
|
|
3689 }
|
|
3690
|
|
3691
|
|
3692 DEFUN ("apply", Fapply, 2, MANY, 0, /*
|
|
3693 Call FUNCTION with the remaining args, using the last arg as a list of args.
|
|
3694 Thus, (apply '+ 1 2 '(3 4)) returns 10.
|
|
3695 */
|
|
3696 (int nargs, Lisp_Object *args))
|
|
3697 {
|
|
3698 /* This function can GC */
|
|
3699 Lisp_Object fun = args[0];
|
|
3700 Lisp_Object spread_arg = args [nargs - 1];
|
|
3701 int numargs;
|
|
3702 int funcall_nargs;
|
|
3703
|
|
3704 GET_EXTERNAL_LIST_LENGTH (spread_arg, numargs);
|
|
3705
|
|
3706 if (numargs == 0)
|
|
3707 /* (apply foo 0 1 '()) */
|
|
3708 return Ffuncall (nargs - 1, args);
|
|
3709 else if (numargs == 1)
|
|
3710 {
|
|
3711 /* (apply foo 0 1 '(2)) */
|
|
3712 args [nargs - 1] = XCAR (spread_arg);
|
|
3713 return Ffuncall (nargs, args);
|
|
3714 }
|
|
3715
|
|
3716 /* -1 for function, -1 for spread arg */
|
|
3717 numargs = nargs - 2 + numargs;
|
|
3718 /* +1 for function */
|
|
3719 funcall_nargs = 1 + numargs;
|
|
3720
|
|
3721 if (SYMBOLP (fun))
|
|
3722 fun = indirect_function (fun, 0);
|
|
3723
|
|
3724 if (SUBRP (fun))
|
|
3725 {
|
|
3726 Lisp_Subr *subr = XSUBR (fun);
|
|
3727 int max_args = subr->max_args;
|
|
3728
|
|
3729 if (numargs < subr->min_args
|
|
3730 || (max_args >= 0 && max_args < numargs))
|
|
3731 {
|
|
3732 /* Let funcall get the error */
|
|
3733 }
|
|
3734 else if (max_args > numargs)
|
|
3735 {
|
|
3736 /* Avoid having funcall cons up yet another new vector of arguments
|
|
3737 by explicitly supplying nil's for optional values */
|
|
3738 funcall_nargs += (max_args - numargs);
|
|
3739 }
|
|
3740 }
|
|
3741 else if (UNBOUNDP (fun))
|
|
3742 {
|
|
3743 /* Let funcall get the error */
|
|
3744 fun = args[0];
|
|
3745 }
|
|
3746
|
|
3747 {
|
|
3748 REGISTER int i;
|
|
3749 Lisp_Object *funcall_args = alloca_array (Lisp_Object, funcall_nargs);
|
|
3750 struct gcpro gcpro1;
|
|
3751
|
|
3752 GCPRO1 (*funcall_args);
|
|
3753 gcpro1.nvars = funcall_nargs;
|
|
3754
|
|
3755 /* Copy in the unspread args */
|
|
3756 memcpy (funcall_args, args, (nargs - 1) * sizeof (Lisp_Object));
|
|
3757 /* Spread the last arg we got. Its first element goes in
|
|
3758 the slot that it used to occupy, hence this value of I. */
|
|
3759 for (i = nargs - 1;
|
|
3760 !NILP (spread_arg); /* i < 1 + numargs */
|
|
3761 i++, spread_arg = XCDR (spread_arg))
|
|
3762 {
|
|
3763 funcall_args [i] = XCAR (spread_arg);
|
|
3764 }
|
|
3765 /* Supply nil for optional args (to subrs) */
|
|
3766 for (; i < funcall_nargs; i++)
|
|
3767 funcall_args[i] = Qnil;
|
|
3768
|
|
3769
|
|
3770 RETURN_UNGCPRO (Ffuncall (funcall_nargs, funcall_args));
|
|
3771 }
|
|
3772 }
|
|
3773
|
|
3774
|
|
3775 /* Apply lambda list FUN to the NARGS evaluated arguments in ARGS and
|
|
3776 return the result of evaluation. */
|
|
3777
|
|
3778 static Lisp_Object
|
|
3779 funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object args[])
|
|
3780 {
|
|
3781 /* This function can GC */
|
442
|
3782 Lisp_Object arglist, body, tail;
|
428
|
3783 int speccount = specpdl_depth();
|
|
3784 REGISTER int i = 0;
|
|
3785
|
|
3786 tail = XCDR (fun);
|
|
3787
|
|
3788 if (!CONSP (tail))
|
|
3789 goto invalid_function;
|
|
3790
|
|
3791 arglist = XCAR (tail);
|
|
3792 body = XCDR (tail);
|
|
3793
|
|
3794 {
|
|
3795 int optional = 0, rest = 0;
|
|
3796
|
442
|
3797 EXTERNAL_LIST_LOOP_2 (symbol, arglist)
|
428
|
3798 {
|
|
3799 if (!SYMBOLP (symbol))
|
|
3800 goto invalid_function;
|
|
3801 if (EQ (symbol, Qand_rest))
|
|
3802 rest = 1;
|
|
3803 else if (EQ (symbol, Qand_optional))
|
|
3804 optional = 1;
|
|
3805 else if (rest)
|
|
3806 {
|
|
3807 specbind (symbol, Flist (nargs - i, &args[i]));
|
|
3808 i = nargs;
|
|
3809 }
|
|
3810 else if (i < nargs)
|
|
3811 specbind (symbol, args[i++]);
|
|
3812 else if (!optional)
|
|
3813 goto wrong_number_of_arguments;
|
|
3814 else
|
|
3815 specbind (symbol, Qnil);
|
|
3816 }
|
|
3817 }
|
|
3818
|
|
3819 if (i < nargs)
|
|
3820 goto wrong_number_of_arguments;
|
|
3821
|
771
|
3822 return unbind_to_1 (speccount, Fprogn (body));
|
428
|
3823
|
|
3824 wrong_number_of_arguments:
|
436
|
3825 return signal_wrong_number_of_arguments_error (fun, nargs);
|
428
|
3826
|
|
3827 invalid_function:
|
436
|
3828 return signal_invalid_function_error (fun);
|
428
|
3829 }
|
|
3830
|
|
3831
|
|
3832 /************************************************************************/
|
|
3833 /* Run hook variables in various ways. */
|
|
3834 /************************************************************************/
|
|
3835
|
|
3836 DEFUN ("run-hooks", Frun_hooks, 1, MANY, 0, /*
|
|
3837 Run each hook in HOOKS. Major mode functions use this.
|
|
3838 Each argument should be a symbol, a hook variable.
|
|
3839 These symbols are processed in the order specified.
|
|
3840 If a hook symbol has a non-nil value, that value may be a function
|
|
3841 or a list of functions to be called to run the hook.
|
|
3842 If the value is a function, it is called with no arguments.
|
|
3843 If it is a list, the elements are called, in order, with no arguments.
|
|
3844
|
|
3845 To make a hook variable buffer-local, use `make-local-hook',
|
|
3846 not `make-local-variable'.
|
|
3847 */
|
|
3848 (int nargs, Lisp_Object *args))
|
|
3849 {
|
|
3850 REGISTER int i;
|
|
3851
|
|
3852 for (i = 0; i < nargs; i++)
|
|
3853 run_hook_with_args (1, args + i, RUN_HOOKS_TO_COMPLETION);
|
|
3854
|
|
3855 return Qnil;
|
|
3856 }
|
|
3857
|
|
3858 DEFUN ("run-hook-with-args", Frun_hook_with_args, 1, MANY, 0, /*
|
|
3859 Run HOOK with the specified arguments ARGS.
|
|
3860 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
|
|
3861 value, that value may be a function or a list of functions to be
|
|
3862 called to run the hook. If the value is a function, it is called with
|
|
3863 the given arguments and its return value is returned. If it is a list
|
|
3864 of functions, those functions are called, in order,
|
|
3865 with the given arguments ARGS.
|
444
|
3866 It is best not to depend on the value returned by `run-hook-with-args',
|
428
|
3867 as that may change.
|
|
3868
|
|
3869 To make a hook variable buffer-local, use `make-local-hook',
|
|
3870 not `make-local-variable'.
|
|
3871 */
|
|
3872 (int nargs, Lisp_Object *args))
|
|
3873 {
|
|
3874 return run_hook_with_args (nargs, args, RUN_HOOKS_TO_COMPLETION);
|
|
3875 }
|
|
3876
|
|
3877 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, 1, MANY, 0, /*
|
|
3878 Run HOOK with the specified arguments ARGS.
|
|
3879 HOOK should be a symbol, a hook variable. Its value should
|
|
3880 be a list of functions. We call those functions, one by one,
|
|
3881 passing arguments ARGS to each of them, until one of them
|
|
3882 returns a non-nil value. Then we return that value.
|
|
3883 If all the functions return nil, we return nil.
|
|
3884
|
|
3885 To make a hook variable buffer-local, use `make-local-hook',
|
|
3886 not `make-local-variable'.
|
|
3887 */
|
|
3888 (int nargs, Lisp_Object *args))
|
|
3889 {
|
|
3890 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_SUCCESS);
|
|
3891 }
|
|
3892
|
|
3893 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, 1, MANY, 0, /*
|
|
3894 Run HOOK with the specified arguments ARGS.
|
|
3895 HOOK should be a symbol, a hook variable. Its value should
|
|
3896 be a list of functions. We call those functions, one by one,
|
|
3897 passing arguments ARGS to each of them, until one of them
|
|
3898 returns nil. Then we return nil.
|
|
3899 If all the functions return non-nil, we return non-nil.
|
|
3900
|
|
3901 To make a hook variable buffer-local, use `make-local-hook',
|
|
3902 not `make-local-variable'.
|
|
3903 */
|
|
3904 (int nargs, Lisp_Object *args))
|
|
3905 {
|
|
3906 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_FAILURE);
|
|
3907 }
|
|
3908
|
|
3909 /* ARGS[0] should be a hook symbol.
|
|
3910 Call each of the functions in the hook value, passing each of them
|
|
3911 as arguments all the rest of ARGS (all NARGS - 1 elements).
|
|
3912 COND specifies a condition to test after each call
|
|
3913 to decide whether to stop.
|
|
3914 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
3915 except that it isn't necessary to gcpro ARGS[0]. */
|
|
3916
|
|
3917 Lisp_Object
|
|
3918 run_hook_with_args_in_buffer (struct buffer *buf, int nargs, Lisp_Object *args,
|
|
3919 enum run_hooks_condition cond)
|
|
3920 {
|
|
3921 Lisp_Object sym, val, ret;
|
|
3922
|
|
3923 if (!initialized || preparing_for_armageddon)
|
|
3924 /* We need to bail out of here pronto. */
|
|
3925 return Qnil;
|
|
3926
|
|
3927 /* Whenever gc_in_progress is true, preparing_for_armageddon
|
|
3928 will also be true unless something is really hosed. */
|
|
3929 assert (!gc_in_progress);
|
|
3930
|
|
3931 sym = args[0];
|
771
|
3932 val = symbol_value_in_buffer (sym, wrap_buffer (buf));
|
428
|
3933 ret = (cond == RUN_HOOKS_UNTIL_FAILURE ? Qt : Qnil);
|
|
3934
|
|
3935 if (UNBOUNDP (val) || NILP (val))
|
|
3936 return ret;
|
|
3937 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
|
|
3938 {
|
|
3939 args[0] = val;
|
|
3940 return Ffuncall (nargs, args);
|
|
3941 }
|
|
3942 else
|
|
3943 {
|
|
3944 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3945 Lisp_Object globals = Qnil;
|
|
3946 GCPRO3 (sym, val, globals);
|
|
3947
|
|
3948 for (;
|
|
3949 CONSP (val) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3950 || (cond == RUN_HOOKS_UNTIL_SUCCESS ? NILP (ret)
|
|
3951 : !NILP (ret)));
|
|
3952 val = XCDR (val))
|
|
3953 {
|
|
3954 if (EQ (XCAR (val), Qt))
|
|
3955 {
|
|
3956 /* t indicates this hook has a local binding;
|
|
3957 it means to run the global binding too. */
|
|
3958 globals = Fdefault_value (sym);
|
|
3959
|
|
3960 if ((! CONSP (globals) || EQ (XCAR (globals), Qlambda)) &&
|
|
3961 ! NILP (globals))
|
|
3962 {
|
|
3963 args[0] = globals;
|
|
3964 ret = Ffuncall (nargs, args);
|
|
3965 }
|
|
3966 else
|
|
3967 {
|
|
3968 for (;
|
|
3969 CONSP (globals) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3970 || (cond == RUN_HOOKS_UNTIL_SUCCESS
|
|
3971 ? NILP (ret)
|
|
3972 : !NILP (ret)));
|
|
3973 globals = XCDR (globals))
|
|
3974 {
|
|
3975 args[0] = XCAR (globals);
|
|
3976 /* In a global value, t should not occur. If it does, we
|
|
3977 must ignore it to avoid an endless loop. */
|
|
3978 if (!EQ (args[0], Qt))
|
|
3979 ret = Ffuncall (nargs, args);
|
|
3980 }
|
|
3981 }
|
|
3982 }
|
|
3983 else
|
|
3984 {
|
|
3985 args[0] = XCAR (val);
|
|
3986 ret = Ffuncall (nargs, args);
|
|
3987 }
|
|
3988 }
|
|
3989
|
|
3990 UNGCPRO;
|
|
3991 return ret;
|
|
3992 }
|
|
3993 }
|
|
3994
|
|
3995 Lisp_Object
|
|
3996 run_hook_with_args (int nargs, Lisp_Object *args,
|
|
3997 enum run_hooks_condition cond)
|
|
3998 {
|
|
3999 return run_hook_with_args_in_buffer (current_buffer, nargs, args, cond);
|
|
4000 }
|
|
4001
|
|
4002 #if 0
|
|
4003
|
|
4004 /* From FSF 19.30, not currently used */
|
|
4005
|
|
4006 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
|
|
4007 present value of that symbol.
|
|
4008 Call each element of FUNLIST,
|
|
4009 passing each of them the rest of ARGS.
|
|
4010 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
4011 except that it isn't necessary to gcpro ARGS[0]. */
|
|
4012
|
|
4013 Lisp_Object
|
|
4014 run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args)
|
|
4015 {
|
|
4016 Lisp_Object sym = args[0];
|
|
4017 Lisp_Object val;
|
|
4018 struct gcpro gcpro1, gcpro2;
|
|
4019
|
|
4020 GCPRO2 (sym, val);
|
|
4021
|
|
4022 for (val = funlist; CONSP (val); val = XCDR (val))
|
|
4023 {
|
|
4024 if (EQ (XCAR (val), Qt))
|
|
4025 {
|
|
4026 /* t indicates this hook has a local binding;
|
|
4027 it means to run the global binding too. */
|
|
4028 Lisp_Object globals;
|
|
4029
|
|
4030 for (globals = Fdefault_value (sym);
|
|
4031 CONSP (globals);
|
|
4032 globals = XCDR (globals))
|
|
4033 {
|
|
4034 args[0] = XCAR (globals);
|
|
4035 /* In a global value, t should not occur. If it does, we
|
|
4036 must ignore it to avoid an endless loop. */
|
|
4037 if (!EQ (args[0], Qt))
|
|
4038 Ffuncall (nargs, args);
|
|
4039 }
|
|
4040 }
|
|
4041 else
|
|
4042 {
|
|
4043 args[0] = XCAR (val);
|
|
4044 Ffuncall (nargs, args);
|
|
4045 }
|
|
4046 }
|
|
4047 UNGCPRO;
|
|
4048 return Qnil;
|
|
4049 }
|
|
4050
|
|
4051 #endif /* 0 */
|
|
4052
|
|
4053 void
|
|
4054 va_run_hook_with_args (Lisp_Object hook_var, int nargs, ...)
|
|
4055 {
|
|
4056 /* This function can GC */
|
|
4057 struct gcpro gcpro1;
|
|
4058 int i;
|
|
4059 va_list vargs;
|
|
4060 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
|
4061
|
|
4062 va_start (vargs, nargs);
|
|
4063 funcall_args[0] = hook_var;
|
|
4064 for (i = 0; i < nargs; i++)
|
|
4065 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
4066 va_end (vargs);
|
|
4067
|
|
4068 GCPRO1 (*funcall_args);
|
|
4069 gcpro1.nvars = nargs + 1;
|
|
4070 run_hook_with_args (nargs + 1, funcall_args, RUN_HOOKS_TO_COMPLETION);
|
|
4071 UNGCPRO;
|
|
4072 }
|
|
4073
|
|
4074 void
|
|
4075 va_run_hook_with_args_in_buffer (struct buffer *buf, Lisp_Object hook_var,
|
|
4076 int nargs, ...)
|
|
4077 {
|
|
4078 /* This function can GC */
|
|
4079 struct gcpro gcpro1;
|
|
4080 int i;
|
|
4081 va_list vargs;
|
|
4082 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
|
4083
|
|
4084 va_start (vargs, nargs);
|
|
4085 funcall_args[0] = hook_var;
|
|
4086 for (i = 0; i < nargs; i++)
|
|
4087 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
4088 va_end (vargs);
|
|
4089
|
|
4090 GCPRO1 (*funcall_args);
|
|
4091 gcpro1.nvars = nargs + 1;
|
|
4092 run_hook_with_args_in_buffer (buf, nargs + 1, funcall_args,
|
|
4093 RUN_HOOKS_TO_COMPLETION);
|
|
4094 UNGCPRO;
|
|
4095 }
|
|
4096
|
|
4097 Lisp_Object
|
|
4098 run_hook (Lisp_Object hook)
|
|
4099 {
|
|
4100 Frun_hooks (1, &hook);
|
|
4101 return Qnil;
|
|
4102 }
|
|
4103
|
|
4104
|
|
4105 /************************************************************************/
|
|
4106 /* Front-ends to eval, funcall, apply */
|
|
4107 /************************************************************************/
|
|
4108
|
|
4109 /* Apply fn to arg */
|
|
4110 Lisp_Object
|
|
4111 apply1 (Lisp_Object fn, Lisp_Object arg)
|
|
4112 {
|
|
4113 /* This function can GC */
|
|
4114 struct gcpro gcpro1;
|
|
4115 Lisp_Object args[2];
|
|
4116
|
|
4117 if (NILP (arg))
|
|
4118 return Ffuncall (1, &fn);
|
|
4119 GCPRO1 (args[0]);
|
|
4120 gcpro1.nvars = 2;
|
|
4121 args[0] = fn;
|
|
4122 args[1] = arg;
|
|
4123 RETURN_UNGCPRO (Fapply (2, args));
|
|
4124 }
|
|
4125
|
|
4126 /* Call function fn on no arguments */
|
|
4127 Lisp_Object
|
|
4128 call0 (Lisp_Object fn)
|
|
4129 {
|
|
4130 /* This function can GC */
|
|
4131 struct gcpro gcpro1;
|
|
4132
|
|
4133 GCPRO1 (fn);
|
|
4134 RETURN_UNGCPRO (Ffuncall (1, &fn));
|
|
4135 }
|
|
4136
|
|
4137 /* Call function fn with argument arg0 */
|
|
4138 Lisp_Object
|
|
4139 call1 (Lisp_Object fn,
|
|
4140 Lisp_Object arg0)
|
|
4141 {
|
|
4142 /* This function can GC */
|
|
4143 struct gcpro gcpro1;
|
|
4144 Lisp_Object args[2];
|
|
4145 args[0] = fn;
|
|
4146 args[1] = arg0;
|
|
4147 GCPRO1 (args[0]);
|
|
4148 gcpro1.nvars = 2;
|
|
4149 RETURN_UNGCPRO (Ffuncall (2, args));
|
|
4150 }
|
|
4151
|
|
4152 /* Call function fn with arguments arg0, arg1 */
|
|
4153 Lisp_Object
|
|
4154 call2 (Lisp_Object fn,
|
|
4155 Lisp_Object arg0, Lisp_Object arg1)
|
|
4156 {
|
|
4157 /* This function can GC */
|
|
4158 struct gcpro gcpro1;
|
|
4159 Lisp_Object args[3];
|
|
4160 args[0] = fn;
|
|
4161 args[1] = arg0;
|
|
4162 args[2] = arg1;
|
|
4163 GCPRO1 (args[0]);
|
|
4164 gcpro1.nvars = 3;
|
|
4165 RETURN_UNGCPRO (Ffuncall (3, args));
|
|
4166 }
|
|
4167
|
|
4168 /* Call function fn with arguments arg0, arg1, arg2 */
|
|
4169 Lisp_Object
|
|
4170 call3 (Lisp_Object fn,
|
|
4171 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4172 {
|
|
4173 /* This function can GC */
|
|
4174 struct gcpro gcpro1;
|
|
4175 Lisp_Object args[4];
|
|
4176 args[0] = fn;
|
|
4177 args[1] = arg0;
|
|
4178 args[2] = arg1;
|
|
4179 args[3] = arg2;
|
|
4180 GCPRO1 (args[0]);
|
|
4181 gcpro1.nvars = 4;
|
|
4182 RETURN_UNGCPRO (Ffuncall (4, args));
|
|
4183 }
|
|
4184
|
|
4185 /* Call function fn with arguments arg0, arg1, arg2, arg3 */
|
|
4186 Lisp_Object
|
|
4187 call4 (Lisp_Object fn,
|
|
4188 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4189 Lisp_Object arg3)
|
|
4190 {
|
|
4191 /* This function can GC */
|
|
4192 struct gcpro gcpro1;
|
|
4193 Lisp_Object args[5];
|
|
4194 args[0] = fn;
|
|
4195 args[1] = arg0;
|
|
4196 args[2] = arg1;
|
|
4197 args[3] = arg2;
|
|
4198 args[4] = arg3;
|
|
4199 GCPRO1 (args[0]);
|
|
4200 gcpro1.nvars = 5;
|
|
4201 RETURN_UNGCPRO (Ffuncall (5, args));
|
|
4202 }
|
|
4203
|
|
4204 /* Call function fn with arguments arg0, arg1, arg2, arg3, arg4 */
|
|
4205 Lisp_Object
|
|
4206 call5 (Lisp_Object fn,
|
|
4207 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4208 Lisp_Object arg3, Lisp_Object arg4)
|
|
4209 {
|
|
4210 /* This function can GC */
|
|
4211 struct gcpro gcpro1;
|
|
4212 Lisp_Object args[6];
|
|
4213 args[0] = fn;
|
|
4214 args[1] = arg0;
|
|
4215 args[2] = arg1;
|
|
4216 args[3] = arg2;
|
|
4217 args[4] = arg3;
|
|
4218 args[5] = arg4;
|
|
4219 GCPRO1 (args[0]);
|
|
4220 gcpro1.nvars = 6;
|
|
4221 RETURN_UNGCPRO (Ffuncall (6, args));
|
|
4222 }
|
|
4223
|
|
4224 Lisp_Object
|
|
4225 call6 (Lisp_Object fn,
|
|
4226 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4227 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
4228 {
|
|
4229 /* This function can GC */
|
|
4230 struct gcpro gcpro1;
|
|
4231 Lisp_Object args[7];
|
|
4232 args[0] = fn;
|
|
4233 args[1] = arg0;
|
|
4234 args[2] = arg1;
|
|
4235 args[3] = arg2;
|
|
4236 args[4] = arg3;
|
|
4237 args[5] = arg4;
|
|
4238 args[6] = arg5;
|
|
4239 GCPRO1 (args[0]);
|
|
4240 gcpro1.nvars = 7;
|
|
4241 RETURN_UNGCPRO (Ffuncall (7, args));
|
|
4242 }
|
|
4243
|
|
4244 Lisp_Object
|
|
4245 call7 (Lisp_Object fn,
|
|
4246 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4247 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4248 Lisp_Object arg6)
|
|
4249 {
|
|
4250 /* This function can GC */
|
|
4251 struct gcpro gcpro1;
|
|
4252 Lisp_Object args[8];
|
|
4253 args[0] = fn;
|
|
4254 args[1] = arg0;
|
|
4255 args[2] = arg1;
|
|
4256 args[3] = arg2;
|
|
4257 args[4] = arg3;
|
|
4258 args[5] = arg4;
|
|
4259 args[6] = arg5;
|
|
4260 args[7] = arg6;
|
|
4261 GCPRO1 (args[0]);
|
|
4262 gcpro1.nvars = 8;
|
|
4263 RETURN_UNGCPRO (Ffuncall (8, args));
|
|
4264 }
|
|
4265
|
|
4266 Lisp_Object
|
|
4267 call8 (Lisp_Object fn,
|
|
4268 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4269 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4270 Lisp_Object arg6, Lisp_Object arg7)
|
|
4271 {
|
|
4272 /* This function can GC */
|
|
4273 struct gcpro gcpro1;
|
|
4274 Lisp_Object args[9];
|
|
4275 args[0] = fn;
|
|
4276 args[1] = arg0;
|
|
4277 args[2] = arg1;
|
|
4278 args[3] = arg2;
|
|
4279 args[4] = arg3;
|
|
4280 args[5] = arg4;
|
|
4281 args[6] = arg5;
|
|
4282 args[7] = arg6;
|
|
4283 args[8] = arg7;
|
|
4284 GCPRO1 (args[0]);
|
|
4285 gcpro1.nvars = 9;
|
|
4286 RETURN_UNGCPRO (Ffuncall (9, args));
|
|
4287 }
|
|
4288
|
|
4289 Lisp_Object
|
|
4290 call0_in_buffer (struct buffer *buf, Lisp_Object fn)
|
|
4291 {
|
|
4292 if (current_buffer == buf)
|
|
4293 return call0 (fn);
|
|
4294 else
|
|
4295 {
|
|
4296 Lisp_Object val;
|
|
4297 int speccount = specpdl_depth();
|
|
4298 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4299 set_buffer_internal (buf);
|
|
4300 val = call0 (fn);
|
771
|
4301 unbind_to (speccount);
|
428
|
4302 return val;
|
|
4303 }
|
|
4304 }
|
|
4305
|
|
4306 Lisp_Object
|
|
4307 call1_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4308 Lisp_Object arg0)
|
|
4309 {
|
|
4310 if (current_buffer == buf)
|
|
4311 return call1 (fn, arg0);
|
|
4312 else
|
|
4313 {
|
|
4314 Lisp_Object val;
|
|
4315 int speccount = specpdl_depth();
|
|
4316 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4317 set_buffer_internal (buf);
|
|
4318 val = call1 (fn, arg0);
|
771
|
4319 unbind_to (speccount);
|
428
|
4320 return val;
|
|
4321 }
|
|
4322 }
|
|
4323
|
|
4324 Lisp_Object
|
|
4325 call2_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4326 Lisp_Object arg0, Lisp_Object arg1)
|
|
4327 {
|
|
4328 if (current_buffer == buf)
|
|
4329 return call2 (fn, arg0, arg1);
|
|
4330 else
|
|
4331 {
|
|
4332 Lisp_Object val;
|
|
4333 int speccount = specpdl_depth();
|
|
4334 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4335 set_buffer_internal (buf);
|
|
4336 val = call2 (fn, arg0, arg1);
|
771
|
4337 unbind_to (speccount);
|
428
|
4338 return val;
|
|
4339 }
|
|
4340 }
|
|
4341
|
|
4342 Lisp_Object
|
|
4343 call3_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4344 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4345 {
|
|
4346 if (current_buffer == buf)
|
|
4347 return call3 (fn, arg0, arg1, arg2);
|
|
4348 else
|
|
4349 {
|
|
4350 Lisp_Object val;
|
|
4351 int speccount = specpdl_depth();
|
|
4352 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4353 set_buffer_internal (buf);
|
|
4354 val = call3 (fn, arg0, arg1, arg2);
|
771
|
4355 unbind_to (speccount);
|
428
|
4356 return val;
|
|
4357 }
|
|
4358 }
|
|
4359
|
|
4360 Lisp_Object
|
|
4361 call4_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4362 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4363 Lisp_Object arg3)
|
|
4364 {
|
|
4365 if (current_buffer == buf)
|
|
4366 return call4 (fn, arg0, arg1, arg2, arg3);
|
|
4367 else
|
|
4368 {
|
|
4369 Lisp_Object val;
|
|
4370 int speccount = specpdl_depth();
|
|
4371 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4372 set_buffer_internal (buf);
|
|
4373 val = call4 (fn, arg0, arg1, arg2, arg3);
|
771
|
4374 unbind_to (speccount);
|
428
|
4375 return val;
|
|
4376 }
|
|
4377 }
|
|
4378
|
|
4379 Lisp_Object
|
|
4380 eval_in_buffer (struct buffer *buf, Lisp_Object form)
|
|
4381 {
|
|
4382 if (current_buffer == buf)
|
|
4383 return Feval (form);
|
|
4384 else
|
|
4385 {
|
|
4386 Lisp_Object val;
|
|
4387 int speccount = specpdl_depth();
|
|
4388 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4389 set_buffer_internal (buf);
|
|
4390 val = Feval (form);
|
771
|
4391 unbind_to (speccount);
|
428
|
4392 return val;
|
|
4393 }
|
|
4394 }
|
|
4395
|
|
4396
|
|
4397 /************************************************************************/
|
|
4398 /* Error-catching front-ends to eval, funcall, apply */
|
|
4399 /************************************************************************/
|
|
4400
|
|
4401 /* Call function fn on no arguments, with condition handler */
|
|
4402 Lisp_Object
|
|
4403 call0_with_handler (Lisp_Object handler, Lisp_Object fn)
|
|
4404 {
|
|
4405 /* This function can GC */
|
|
4406 struct gcpro gcpro1;
|
|
4407 Lisp_Object args[2];
|
|
4408 args[0] = handler;
|
|
4409 args[1] = fn;
|
|
4410 GCPRO1 (args[0]);
|
|
4411 gcpro1.nvars = 2;
|
|
4412 RETURN_UNGCPRO (Fcall_with_condition_handler (2, args));
|
|
4413 }
|
|
4414
|
|
4415 /* Call function fn with argument arg0, with condition handler */
|
|
4416 Lisp_Object
|
|
4417 call1_with_handler (Lisp_Object handler, Lisp_Object fn,
|
|
4418 Lisp_Object arg0)
|
|
4419 {
|
|
4420 /* This function can GC */
|
|
4421 struct gcpro gcpro1;
|
|
4422 Lisp_Object args[3];
|
|
4423 args[0] = handler;
|
|
4424 args[1] = fn;
|
|
4425 args[2] = arg0;
|
|
4426 GCPRO1 (args[0]);
|
|
4427 gcpro1.nvars = 3;
|
|
4428 RETURN_UNGCPRO (Fcall_with_condition_handler (3, args));
|
|
4429 }
|
|
4430
|
|
4431
|
|
4432 /* The following functions provide you with error-trapping versions
|
|
4433 of the various front-ends above. They take an additional
|
|
4434 "warning_string" argument; if non-zero, a warning with this
|
|
4435 string and the actual error that occurred will be displayed
|
|
4436 in the *Warnings* buffer if an error occurs. In all cases,
|
|
4437 QUIT is inhibited while these functions are running, and if
|
|
4438 an error occurs, Qunbound is returned instead of the normal
|
|
4439 return value.
|
|
4440 */
|
|
4441
|
|
4442 /* #### This stuff needs to catch throws as well. We need to
|
|
4443 improve internal_catch() so it can take a "catch anything"
|
|
4444 argument similar to Qt or Qerror for condition_case_1(). */
|
|
4445
|
|
4446 static Lisp_Object
|
|
4447 caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4448 {
|
771
|
4449 /* #### should be rewritten to work with emacs_sprintf_string_lisp(); but this
|
|
4450 whole stuff is getting junked and replaced from my stderr-proc ws */
|
428
|
4451 if (!NILP (errordata))
|
|
4452 {
|
|
4453 Lisp_Object args[2];
|
|
4454
|
|
4455 if (!NILP (arg))
|
|
4456 {
|
771
|
4457 Intbyte *str = (Intbyte *) get_opaque_ptr (arg);
|
|
4458 args[0] = build_intstring (str);
|
428
|
4459 }
|
|
4460 else
|
771
|
4461 args[0] = build_msg_string ("error");
|
428
|
4462 /* #### This should call
|
|
4463 (with-output-to-string (display-error errordata))
|
|
4464 but that stuff is all in Lisp currently. */
|
|
4465 args[1] = errordata;
|
|
4466 warn_when_safe_lispobj
|
|
4467 (Qerror, Qwarning,
|
771
|
4468 emacs_vsprintf_string_lisp ("%s: %s", Qnil, 2, args));
|
428
|
4469 }
|
|
4470 return Qunbound;
|
|
4471 }
|
|
4472
|
|
4473 static Lisp_Object
|
|
4474 allow_quit_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4475 {
|
|
4476 if (CONSP (errordata) && EQ (XCAR (errordata), Qquit))
|
|
4477 return Fsignal (Qquit, XCDR (errordata));
|
|
4478 return caught_a_squirmer (errordata, arg);
|
|
4479 }
|
|
4480
|
|
4481 static Lisp_Object
|
|
4482 safe_run_hook_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4483 {
|
|
4484 Lisp_Object hook = Fcar (arg);
|
|
4485 arg = Fcdr (arg);
|
|
4486 /* Clear out the hook. */
|
|
4487 Fset (hook, Qnil);
|
|
4488 return caught_a_squirmer (errordata, arg);
|
|
4489 }
|
|
4490
|
|
4491 static Lisp_Object
|
|
4492 allow_quit_safe_run_hook_caught_a_squirmer (Lisp_Object errordata,
|
|
4493 Lisp_Object arg)
|
|
4494 {
|
|
4495 Lisp_Object hook = Fcar (arg);
|
|
4496 arg = Fcdr (arg);
|
|
4497 if (!CONSP (errordata) || !EQ (XCAR (errordata), Qquit))
|
|
4498 /* Clear out the hook. */
|
|
4499 Fset (hook, Qnil);
|
|
4500 return allow_quit_caught_a_squirmer (errordata, arg);
|
|
4501 }
|
|
4502
|
|
4503 static Lisp_Object
|
|
4504 catch_them_squirmers_eval_in_buffer (Lisp_Object cons)
|
|
4505 {
|
|
4506 return eval_in_buffer (XBUFFER (XCAR (cons)), XCDR (cons));
|
|
4507 }
|
|
4508
|
|
4509 Lisp_Object
|
665
|
4510 eval_in_buffer_trapping_errors (const CIntbyte *warning_string,
|
428
|
4511 struct buffer *buf, Lisp_Object form)
|
|
4512 {
|
|
4513 int speccount = specpdl_depth();
|
|
4514 Lisp_Object tem;
|
|
4515 Lisp_Object buffer;
|
|
4516 Lisp_Object cons;
|
|
4517 Lisp_Object opaque;
|
|
4518 struct gcpro gcpro1, gcpro2;
|
|
4519
|
793
|
4520 buffer = wrap_buffer (buf);
|
428
|
4521
|
|
4522 specbind (Qinhibit_quit, Qt);
|
771
|
4523 /* begin_gc_forbidden(); Currently no reason to do this; */
|
428
|
4524
|
|
4525 cons = noseeum_cons (buffer, form);
|
|
4526 opaque = (warning_string ? make_opaque_ptr ((void *)warning_string) : Qnil);
|
|
4527 GCPRO2 (cons, opaque);
|
|
4528 /* Qerror not Qt, so you can get a backtrace */
|
|
4529 tem = condition_case_1 (Qerror,
|
|
4530 catch_them_squirmers_eval_in_buffer, cons,
|
|
4531 caught_a_squirmer, opaque);
|
|
4532 free_cons (XCONS (cons));
|
|
4533 if (OPAQUE_PTRP (opaque))
|
|
4534 free_opaque_ptr (opaque);
|
|
4535 UNGCPRO;
|
|
4536
|
771
|
4537 return unbind_to_1 (speccount, tem);
|
428
|
4538 }
|
|
4539
|
|
4540 static Lisp_Object
|
|
4541 catch_them_squirmers_run_hook (Lisp_Object hook_symbol)
|
|
4542 {
|
|
4543 /* This function can GC */
|
|
4544 run_hook (hook_symbol);
|
|
4545 return Qnil;
|
|
4546 }
|
|
4547
|
|
4548 Lisp_Object
|
665
|
4549 run_hook_trapping_errors (const CIntbyte *warning_string,
|
609
|
4550 Lisp_Object hook_symbol)
|
428
|
4551 {
|
|
4552 int speccount;
|
|
4553 Lisp_Object tem;
|
|
4554 Lisp_Object opaque;
|
|
4555 struct gcpro gcpro1;
|
|
4556
|
|
4557 if (!initialized || preparing_for_armageddon)
|
|
4558 return Qnil;
|
|
4559 tem = find_symbol_value (hook_symbol);
|
|
4560 if (NILP (tem) || UNBOUNDP (tem))
|
|
4561 return Qnil;
|
|
4562
|
|
4563 speccount = specpdl_depth();
|
|
4564 specbind (Qinhibit_quit, Qt);
|
|
4565
|
|
4566 opaque = (warning_string ? make_opaque_ptr ((void *)warning_string) : Qnil);
|
|
4567 GCPRO1 (opaque);
|
|
4568 /* Qerror not Qt, so you can get a backtrace */
|
|
4569 tem = condition_case_1 (Qerror,
|
|
4570 catch_them_squirmers_run_hook, hook_symbol,
|
|
4571 caught_a_squirmer, opaque);
|
|
4572 if (OPAQUE_PTRP (opaque))
|
|
4573 free_opaque_ptr (opaque);
|
|
4574 UNGCPRO;
|
|
4575
|
771
|
4576 return unbind_to_1 (speccount, tem);
|
428
|
4577 }
|
|
4578
|
|
4579 /* Same as run_hook_trapping_errors() but also set the hook to nil
|
|
4580 if an error occurs. */
|
|
4581
|
|
4582 Lisp_Object
|
665
|
4583 safe_run_hook_trapping_errors (const CIntbyte *warning_string,
|
428
|
4584 Lisp_Object hook_symbol,
|
|
4585 int allow_quit)
|
|
4586 {
|
|
4587 int speccount = specpdl_depth();
|
|
4588 Lisp_Object tem;
|
|
4589 Lisp_Object cons = Qnil;
|
|
4590 struct gcpro gcpro1;
|
|
4591
|
|
4592 if (!initialized || preparing_for_armageddon)
|
|
4593 return Qnil;
|
|
4594 tem = find_symbol_value (hook_symbol);
|
|
4595 if (NILP (tem) || UNBOUNDP (tem))
|
|
4596 return Qnil;
|
|
4597
|
|
4598 if (!allow_quit)
|
|
4599 specbind (Qinhibit_quit, Qt);
|
|
4600
|
|
4601 cons = noseeum_cons (hook_symbol,
|
|
4602 warning_string ? make_opaque_ptr ((void *)warning_string)
|
|
4603 : Qnil);
|
|
4604 GCPRO1 (cons);
|
|
4605 /* Qerror not Qt, so you can get a backtrace */
|
|
4606 tem = condition_case_1 (Qerror,
|
|
4607 catch_them_squirmers_run_hook,
|
|
4608 hook_symbol,
|
|
4609 allow_quit ?
|
|
4610 allow_quit_safe_run_hook_caught_a_squirmer :
|
|
4611 safe_run_hook_caught_a_squirmer,
|
|
4612 cons);
|
|
4613 if (OPAQUE_PTRP (XCDR (cons)))
|
|
4614 free_opaque_ptr (XCDR (cons));
|
|
4615 free_cons (XCONS (cons));
|
|
4616 UNGCPRO;
|
|
4617
|
771
|
4618 return unbind_to_1 (speccount, tem);
|
428
|
4619 }
|
|
4620
|
|
4621 static Lisp_Object
|
|
4622 catch_them_squirmers_call0 (Lisp_Object function)
|
|
4623 {
|
|
4624 /* This function can GC */
|
|
4625 return call0 (function);
|
|
4626 }
|
|
4627
|
|
4628 Lisp_Object
|
665
|
4629 call0_trapping_errors (const CIntbyte *warning_string, Lisp_Object function)
|
428
|
4630 {
|
|
4631 int speccount;
|
|
4632 Lisp_Object tem;
|
|
4633 Lisp_Object opaque = Qnil;
|
|
4634 struct gcpro gcpro1, gcpro2;
|
|
4635
|
|
4636 if (SYMBOLP (function))
|
|
4637 {
|
|
4638 tem = XSYMBOL (function)->function;
|
|
4639 if (NILP (tem) || UNBOUNDP (tem))
|
|
4640 return Qnil;
|
|
4641 }
|
|
4642
|
|
4643 GCPRO2 (opaque, function);
|
|
4644 speccount = specpdl_depth();
|
|
4645 specbind (Qinhibit_quit, Qt);
|
771
|
4646 /* begin_gc_forbidden(); Currently no reason to do this; */
|
428
|
4647
|
|
4648 opaque = (warning_string ? make_opaque_ptr ((void *)warning_string) : Qnil);
|
|
4649 /* Qerror not Qt, so you can get a backtrace */
|
|
4650 tem = condition_case_1 (Qerror,
|
|
4651 catch_them_squirmers_call0, function,
|
|
4652 caught_a_squirmer, opaque);
|
|
4653 if (OPAQUE_PTRP (opaque))
|
|
4654 free_opaque_ptr (opaque);
|
|
4655 UNGCPRO;
|
|
4656
|
771
|
4657 return unbind_to_1 (speccount, tem);
|
428
|
4658 }
|
|
4659
|
|
4660 static Lisp_Object
|
|
4661 catch_them_squirmers_call1 (Lisp_Object cons)
|
|
4662 {
|
|
4663 /* This function can GC */
|
|
4664 return call1 (XCAR (cons), XCDR (cons));
|
|
4665 }
|
|
4666
|
|
4667 static Lisp_Object
|
|
4668 catch_them_squirmers_call2 (Lisp_Object cons)
|
|
4669 {
|
|
4670 /* This function can GC */
|
|
4671 return call2 (XCAR (cons), XCAR (XCDR (cons)), XCAR (XCDR (XCDR (cons))));
|
|
4672 }
|
|
4673
|
|
4674 Lisp_Object
|
665
|
4675 call1_trapping_errors (const CIntbyte *warning_string, Lisp_Object function,
|
428
|
4676 Lisp_Object object)
|
|
4677 {
|
|
4678 int speccount = specpdl_depth();
|
|
4679 Lisp_Object tem;
|
|
4680 Lisp_Object cons = Qnil;
|
|
4681 Lisp_Object opaque = Qnil;
|
|
4682 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
4683
|
|
4684 if (SYMBOLP (function))
|
|
4685 {
|
|
4686 tem = XSYMBOL (function)->function;
|
|
4687 if (NILP (tem) || UNBOUNDP (tem))
|
|
4688 return Qnil;
|
|
4689 }
|
|
4690
|
|
4691 GCPRO4 (cons, opaque, function, object);
|
|
4692
|
|
4693 specbind (Qinhibit_quit, Qt);
|
771
|
4694 /* begin_gc_forbidden(); Currently no reason to do this; */
|
428
|
4695
|
|
4696 cons = noseeum_cons (function, object);
|
|
4697 opaque = (warning_string ? make_opaque_ptr ((void *)warning_string) : Qnil);
|
|
4698 /* Qerror not Qt, so you can get a backtrace */
|
|
4699 tem = condition_case_1 (Qerror,
|
|
4700 catch_them_squirmers_call1, cons,
|
|
4701 caught_a_squirmer, opaque);
|
|
4702 if (OPAQUE_PTRP (opaque))
|
|
4703 free_opaque_ptr (opaque);
|
|
4704 free_cons (XCONS (cons));
|
|
4705 UNGCPRO;
|
|
4706
|
771
|
4707 return unbind_to_1 (speccount, tem);
|
428
|
4708 }
|
|
4709
|
|
4710 Lisp_Object
|
665
|
4711 call2_trapping_errors (const CIntbyte *warning_string, Lisp_Object function,
|
428
|
4712 Lisp_Object object1, Lisp_Object object2)
|
|
4713 {
|
|
4714 int speccount = specpdl_depth();
|
|
4715 Lisp_Object tem;
|
|
4716 Lisp_Object cons = Qnil;
|
|
4717 Lisp_Object opaque = Qnil;
|
|
4718 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
|
4719
|
|
4720 if (SYMBOLP (function))
|
|
4721 {
|
|
4722 tem = XSYMBOL (function)->function;
|
|
4723 if (NILP (tem) || UNBOUNDP (tem))
|
|
4724 return Qnil;
|
|
4725 }
|
|
4726
|
|
4727 GCPRO5 (cons, opaque, function, object1, object2);
|
|
4728 specbind (Qinhibit_quit, Qt);
|
771
|
4729 /* begin_gc_forbidden(); Currently no reason to do this; */
|
428
|
4730
|
|
4731 cons = list3 (function, object1, object2);
|
|
4732 opaque = (warning_string ? make_opaque_ptr ((void *)warning_string) : Qnil);
|
|
4733 /* Qerror not Qt, so you can get a backtrace */
|
|
4734 tem = condition_case_1 (Qerror,
|
|
4735 catch_them_squirmers_call2, cons,
|
|
4736 caught_a_squirmer, opaque);
|
|
4737 if (OPAQUE_PTRP (opaque))
|
|
4738 free_opaque_ptr (opaque);
|
|
4739 free_list (cons);
|
|
4740 UNGCPRO;
|
|
4741
|
771
|
4742 return unbind_to_1 (speccount, tem);
|
428
|
4743 }
|
|
4744
|
|
4745
|
|
4746 /************************************************************************/
|
|
4747 /* The special binding stack */
|
771
|
4748 /* Most C code should simply use specbind() and unbind_to_1(). */
|
428
|
4749 /* When performance is critical, use the macros in backtrace.h. */
|
|
4750 /************************************************************************/
|
|
4751
|
|
4752 #define min_max_specpdl_size 400
|
|
4753
|
|
4754 void
|
647
|
4755 grow_specpdl (EMACS_INT reserved)
|
|
4756 {
|
|
4757 EMACS_INT size_needed = specpdl_depth() + reserved;
|
428
|
4758 if (size_needed >= max_specpdl_size)
|
|
4759 {
|
|
4760 if (max_specpdl_size < min_max_specpdl_size)
|
|
4761 max_specpdl_size = min_max_specpdl_size;
|
|
4762 if (size_needed >= max_specpdl_size)
|
|
4763 {
|
|
4764 if (!NILP (Vdebug_on_error) ||
|
|
4765 !NILP (Vdebug_on_signal))
|
|
4766 /* Leave room for some specpdl in the debugger. */
|
|
4767 max_specpdl_size = size_needed + 100;
|
563
|
4768 signal_continuable_error
|
|
4769 (Qstack_overflow,
|
|
4770 "Variable binding depth exceeds max-specpdl-size", Qunbound);
|
428
|
4771 }
|
|
4772 }
|
|
4773 while (specpdl_size < size_needed)
|
|
4774 {
|
|
4775 specpdl_size *= 2;
|
|
4776 if (specpdl_size > max_specpdl_size)
|
|
4777 specpdl_size = max_specpdl_size;
|
|
4778 }
|
|
4779 XREALLOC_ARRAY (specpdl, struct specbinding, specpdl_size);
|
|
4780 specpdl_ptr = specpdl + specpdl_depth();
|
|
4781 }
|
|
4782
|
|
4783
|
|
4784 /* Handle unbinding buffer-local variables */
|
|
4785 static Lisp_Object
|
|
4786 specbind_unwind_local (Lisp_Object ovalue)
|
|
4787 {
|
|
4788 Lisp_Object current = Fcurrent_buffer ();
|
|
4789 Lisp_Object symbol = specpdl_ptr->symbol;
|
440
|
4790 Lisp_Cons *victim = XCONS (ovalue);
|
428
|
4791 Lisp_Object buf = get_buffer (victim->car, 0);
|
|
4792 ovalue = victim->cdr;
|
|
4793
|
|
4794 free_cons (victim);
|
|
4795
|
|
4796 if (NILP (buf))
|
|
4797 {
|
|
4798 /* Deleted buffer -- do nothing */
|
|
4799 }
|
|
4800 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buf)) == 0)
|
|
4801 {
|
|
4802 /* Was buffer-local when binding was made, now no longer is.
|
|
4803 * (kill-local-variable can do this.)
|
|
4804 * Do nothing in this case.
|
|
4805 */
|
|
4806 }
|
|
4807 else if (EQ (buf, current))
|
|
4808 Fset (symbol, ovalue);
|
|
4809 else
|
|
4810 {
|
|
4811 /* Urk! Somebody switched buffers */
|
|
4812 struct gcpro gcpro1;
|
|
4813 GCPRO1 (current);
|
|
4814 Fset_buffer (buf);
|
|
4815 Fset (symbol, ovalue);
|
|
4816 Fset_buffer (current);
|
|
4817 UNGCPRO;
|
|
4818 }
|
|
4819 return symbol;
|
|
4820 }
|
|
4821
|
|
4822 static Lisp_Object
|
|
4823 specbind_unwind_wasnt_local (Lisp_Object buffer)
|
|
4824 {
|
|
4825 Lisp_Object current = Fcurrent_buffer ();
|
|
4826 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
4827
|
|
4828 buffer = get_buffer (buffer, 0);
|
|
4829 if (NILP (buffer))
|
|
4830 {
|
|
4831 /* Deleted buffer -- do nothing */
|
|
4832 }
|
|
4833 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buffer)) == 0)
|
|
4834 {
|
|
4835 /* Was buffer-local when binding was made, now no longer is.
|
|
4836 * (kill-local-variable can do this.)
|
|
4837 * Do nothing in this case.
|
|
4838 */
|
|
4839 }
|
|
4840 else if (EQ (buffer, current))
|
|
4841 Fkill_local_variable (symbol);
|
|
4842 else
|
|
4843 {
|
|
4844 /* Urk! Somebody switched buffers */
|
|
4845 struct gcpro gcpro1;
|
|
4846 GCPRO1 (current);
|
|
4847 Fset_buffer (buffer);
|
|
4848 Fkill_local_variable (symbol);
|
|
4849 Fset_buffer (current);
|
|
4850 UNGCPRO;
|
|
4851 }
|
|
4852 return symbol;
|
|
4853 }
|
|
4854
|
|
4855
|
|
4856 void
|
|
4857 specbind (Lisp_Object symbol, Lisp_Object value)
|
|
4858 {
|
|
4859 SPECBIND (symbol, value);
|
|
4860 }
|
|
4861
|
|
4862 void
|
|
4863 specbind_magic (Lisp_Object symbol, Lisp_Object value)
|
|
4864 {
|
|
4865 int buffer_local =
|
|
4866 symbol_value_buffer_local_info (symbol, current_buffer);
|
|
4867
|
|
4868 if (buffer_local == 0)
|
|
4869 {
|
|
4870 specpdl_ptr->old_value = find_symbol_value (symbol);
|
771
|
4871 specpdl_ptr->func = 0; /* Handled specially by unbind_to_1 */
|
428
|
4872 }
|
|
4873 else if (buffer_local > 0)
|
|
4874 {
|
|
4875 /* Already buffer-local */
|
|
4876 specpdl_ptr->old_value = noseeum_cons (Fcurrent_buffer (),
|
|
4877 find_symbol_value (symbol));
|
|
4878 specpdl_ptr->func = specbind_unwind_local;
|
|
4879 }
|
|
4880 else
|
|
4881 {
|
|
4882 /* About to become buffer-local */
|
|
4883 specpdl_ptr->old_value = Fcurrent_buffer ();
|
|
4884 specpdl_ptr->func = specbind_unwind_wasnt_local;
|
|
4885 }
|
|
4886
|
|
4887 specpdl_ptr->symbol = symbol;
|
|
4888 specpdl_ptr++;
|
|
4889 specpdl_depth_counter++;
|
|
4890
|
|
4891 Fset (symbol, value);
|
|
4892 }
|
|
4893
|
771
|
4894 /* Record an unwind-protect -- FUNCTION will be called with ARG no matter
|
|
4895 whether a normal or non-local exit occurs. (You need to call unbind_to_1()
|
|
4896 before your function returns normally, passing in the integer returned
|
|
4897 by this function.) Note: As long as the unwind-protect exists, ARG is
|
|
4898 automatically GCPRO'd. The return value from FUNCTION is completely
|
|
4899 ignored. #### We should eliminate it entirely. */
|
|
4900
|
|
4901 int
|
428
|
4902 record_unwind_protect (Lisp_Object (*function) (Lisp_Object arg),
|
|
4903 Lisp_Object arg)
|
|
4904 {
|
|
4905 SPECPDL_RESERVE (1);
|
|
4906 specpdl_ptr->func = function;
|
|
4907 specpdl_ptr->symbol = Qnil;
|
|
4908 specpdl_ptr->old_value = arg;
|
|
4909 specpdl_ptr++;
|
|
4910 specpdl_depth_counter++;
|
771
|
4911 return specpdl_depth_counter - 1;
|
|
4912 }
|
|
4913
|
|
4914 static Lisp_Object
|
|
4915 free_pointer (Lisp_Object opaque)
|
|
4916 {
|
|
4917 xfree (get_opaque_ptr (opaque));
|
|
4918 free_opaque_ptr (opaque);
|
|
4919 return Qnil;
|
|
4920 }
|
|
4921
|
|
4922 /* Establish an unwind-protect which will free the specified block.
|
|
4923 */
|
|
4924 int
|
|
4925 record_unwind_protect_freeing (void *ptr)
|
|
4926 {
|
|
4927 Lisp_Object opaque = make_opaque_ptr (ptr);
|
|
4928 return record_unwind_protect (free_pointer, opaque);
|
|
4929 }
|
|
4930
|
|
4931 static Lisp_Object
|
|
4932 free_dynarr (Lisp_Object opaque)
|
|
4933 {
|
|
4934 Dynarr_free (get_opaque_ptr (opaque));
|
|
4935 free_opaque_ptr (opaque);
|
|
4936 return Qnil;
|
|
4937 }
|
|
4938
|
|
4939 int
|
|
4940 record_unwind_protect_freeing_dynarr (void *ptr)
|
|
4941 {
|
|
4942 Lisp_Object opaque = make_opaque_ptr (ptr);
|
|
4943 return record_unwind_protect (free_dynarr, opaque);
|
|
4944 }
|
428
|
4945
|
|
4946 /* Unwind the stack till specpdl_depth() == COUNT.
|
|
4947 VALUE is not used, except that, purely as a convenience to the
|
771
|
4948 caller, it is protected from garbage-protection and returned. */
|
428
|
4949 Lisp_Object
|
771
|
4950 unbind_to_1 (int count, Lisp_Object value)
|
428
|
4951 {
|
|
4952 UNBIND_TO_GCPRO (count, value);
|
|
4953 return value;
|
|
4954 }
|
|
4955
|
|
4956 /* Don't call this directly.
|
|
4957 Only for use by UNBIND_TO* macros in backtrace.h */
|
|
4958 void
|
|
4959 unbind_to_hairy (int count)
|
|
4960 {
|
771
|
4961 Lisp_Object oquit;
|
428
|
4962
|
442
|
4963 ++specpdl_ptr;
|
|
4964 ++specpdl_depth_counter;
|
|
4965
|
771
|
4966 /* Allow QUIT within unwind-protect routines, but defer any existing QUIT
|
|
4967 until afterwards. */
|
428
|
4968 check_quit (); /* make Vquit_flag accurate */
|
771
|
4969 oquit = Vquit_flag;
|
428
|
4970 Vquit_flag = Qnil;
|
|
4971
|
|
4972 while (specpdl_depth_counter != count)
|
|
4973 {
|
|
4974 --specpdl_ptr;
|
|
4975 --specpdl_depth_counter;
|
|
4976
|
|
4977 if (specpdl_ptr->func != 0)
|
|
4978 /* An unwind-protect */
|
|
4979 (*specpdl_ptr->func) (specpdl_ptr->old_value);
|
|
4980 else
|
|
4981 {
|
|
4982 /* We checked symbol for validity when we specbound it,
|
|
4983 so only need to call Fset if symbol has magic value. */
|
440
|
4984 Lisp_Symbol *sym = XSYMBOL (specpdl_ptr->symbol);
|
428
|
4985 if (!SYMBOL_VALUE_MAGIC_P (sym->value))
|
|
4986 sym->value = specpdl_ptr->old_value;
|
|
4987 else
|
|
4988 Fset (specpdl_ptr->symbol, specpdl_ptr->old_value);
|
|
4989 }
|
|
4990
|
|
4991 #if 0 /* martin */
|
|
4992 #ifndef EXCEEDINGLY_QUESTIONABLE_CODE
|
|
4993 /* There should never be anything here for us to remove.
|
|
4994 If so, it indicates a logic error in Emacs. Catches
|
|
4995 should get removed when a throw or signal occurs, or
|
|
4996 when a catch or condition-case exits normally. But
|
|
4997 it's too dangerous to just remove this code. --ben */
|
|
4998
|
|
4999 /* Furthermore, this code is not in FSFmacs!!!
|
|
5000 Braino on mly's part? */
|
|
5001 /* If we're unwound past the pdlcount of a catch frame,
|
|
5002 that catch can't possibly still be valid. */
|
|
5003 while (catchlist && catchlist->pdlcount > specpdl_depth_counter)
|
|
5004 {
|
|
5005 catchlist = catchlist->next;
|
|
5006 /* Don't mess with gcprolist, backtrace_list here */
|
|
5007 }
|
|
5008 #endif
|
|
5009 #endif
|
|
5010 }
|
771
|
5011 Vquit_flag = oquit;
|
428
|
5012 }
|
|
5013
|
|
5014
|
|
5015
|
|
5016 /* Get the value of symbol's global binding, even if that binding is
|
|
5017 not now dynamically visible. May return Qunbound or magic values. */
|
|
5018
|
|
5019 Lisp_Object
|
|
5020 top_level_value (Lisp_Object symbol)
|
|
5021 {
|
|
5022 REGISTER struct specbinding *ptr = specpdl;
|
|
5023
|
|
5024 CHECK_SYMBOL (symbol);
|
|
5025 for (; ptr != specpdl_ptr; ptr++)
|
|
5026 {
|
|
5027 if (EQ (ptr->symbol, symbol))
|
|
5028 return ptr->old_value;
|
|
5029 }
|
|
5030 return XSYMBOL (symbol)->value;
|
|
5031 }
|
|
5032
|
|
5033 #if 0
|
|
5034
|
|
5035 Lisp_Object
|
|
5036 top_level_set (Lisp_Object symbol, Lisp_Object newval)
|
|
5037 {
|
|
5038 REGISTER struct specbinding *ptr = specpdl;
|
|
5039
|
|
5040 CHECK_SYMBOL (symbol);
|
|
5041 for (; ptr != specpdl_ptr; ptr++)
|
|
5042 {
|
|
5043 if (EQ (ptr->symbol, symbol))
|
|
5044 {
|
|
5045 ptr->old_value = newval;
|
|
5046 return newval;
|
|
5047 }
|
|
5048 }
|
|
5049 return Fset (symbol, newval);
|
|
5050 }
|
|
5051
|
|
5052 #endif /* 0 */
|
|
5053
|
|
5054
|
|
5055 /************************************************************************/
|
|
5056 /* Backtraces */
|
|
5057 /************************************************************************/
|
|
5058
|
|
5059 DEFUN ("backtrace-debug", Fbacktrace_debug, 2, 2, 0, /*
|
|
5060 Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
|
|
5061 The debugger is entered when that frame exits, if the flag is non-nil.
|
|
5062 */
|
|
5063 (level, flag))
|
|
5064 {
|
|
5065 REGISTER struct backtrace *backlist = backtrace_list;
|
|
5066 REGISTER int i;
|
|
5067
|
|
5068 CHECK_INT (level);
|
|
5069
|
|
5070 for (i = 0; backlist && i < XINT (level); i++)
|
|
5071 {
|
|
5072 backlist = backlist->next;
|
|
5073 }
|
|
5074
|
|
5075 if (backlist)
|
|
5076 backlist->debug_on_exit = !NILP (flag);
|
|
5077
|
|
5078 return flag;
|
|
5079 }
|
|
5080
|
|
5081 static void
|
|
5082 backtrace_specials (int speccount, int speclimit, Lisp_Object stream)
|
|
5083 {
|
|
5084 int printing_bindings = 0;
|
|
5085
|
|
5086 for (; speccount > speclimit; speccount--)
|
|
5087 {
|
|
5088 if (specpdl[speccount - 1].func == 0
|
|
5089 || specpdl[speccount - 1].func == specbind_unwind_local
|
|
5090 || specpdl[speccount - 1].func == specbind_unwind_wasnt_local)
|
|
5091 {
|
|
5092 write_c_string (((!printing_bindings) ? " # bind (" : " "),
|
|
5093 stream);
|
|
5094 Fprin1 (specpdl[speccount - 1].symbol, stream);
|
|
5095 printing_bindings = 1;
|
|
5096 }
|
|
5097 else
|
|
5098 {
|
|
5099 if (printing_bindings) write_c_string (")\n", stream);
|
|
5100 write_c_string (" # (unwind-protect ...)\n", stream);
|
|
5101 printing_bindings = 0;
|
|
5102 }
|
|
5103 }
|
|
5104 if (printing_bindings) write_c_string (")\n", stream);
|
|
5105 }
|
|
5106
|
|
5107 DEFUN ("backtrace", Fbacktrace, 0, 2, "", /*
|
|
5108 Print a trace of Lisp function calls currently active.
|
438
|
5109 Optional arg STREAM specifies the output stream to send the backtrace to,
|
444
|
5110 and defaults to the value of `standard-output'.
|
|
5111 Optional second arg DETAILED non-nil means show places where currently
|
|
5112 active variable bindings, catches, condition-cases, and
|
|
5113 unwind-protects, as well as function calls, were made.
|
428
|
5114 */
|
|
5115 (stream, detailed))
|
|
5116 {
|
|
5117 /* This function can GC */
|
|
5118 struct backtrace *backlist = backtrace_list;
|
|
5119 struct catchtag *catches = catchlist;
|
|
5120 int speccount = specpdl_depth();
|
|
5121
|
|
5122 int old_nl = print_escape_newlines;
|
|
5123 int old_pr = print_readably;
|
|
5124 Lisp_Object old_level = Vprint_level;
|
|
5125 Lisp_Object oiq = Vinhibit_quit;
|
|
5126 struct gcpro gcpro1, gcpro2;
|
|
5127
|
|
5128 /* We can't allow quits in here because that could cause the values
|
|
5129 of print_readably and print_escape_newlines to get screwed up.
|
|
5130 Normally we would use a record_unwind_protect but that would
|
|
5131 screw up the functioning of this function. */
|
|
5132 Vinhibit_quit = Qt;
|
|
5133
|
|
5134 entering_debugger = 0;
|
|
5135
|
|
5136 Vprint_level = make_int (3);
|
|
5137 print_readably = 0;
|
|
5138 print_escape_newlines = 1;
|
|
5139
|
|
5140 GCPRO2 (stream, old_level);
|
|
5141
|
|
5142 if (NILP (stream))
|
|
5143 stream = Vstandard_output;
|
|
5144 if (!noninteractive && (NILP (stream) || EQ (stream, Qt)))
|
|
5145 stream = Fselected_frame (Qnil);
|
|
5146
|
|
5147 for (;;)
|
|
5148 {
|
|
5149 if (!NILP (detailed) && catches && catches->backlist == backlist)
|
|
5150 {
|
|
5151 int catchpdl = catches->pdlcount;
|
438
|
5152 if (speccount > catchpdl
|
|
5153 && specpdl[catchpdl].func == condition_case_unwind)
|
428
|
5154 /* This is a condition-case catchpoint */
|
|
5155 catchpdl = catchpdl + 1;
|
|
5156
|
|
5157 backtrace_specials (speccount, catchpdl, stream);
|
|
5158
|
|
5159 speccount = catches->pdlcount;
|
|
5160 if (catchpdl == speccount)
|
|
5161 {
|
|
5162 write_c_string (" # (catch ", stream);
|
|
5163 Fprin1 (catches->tag, stream);
|
|
5164 write_c_string (" ...)\n", stream);
|
|
5165 }
|
|
5166 else
|
|
5167 {
|
|
5168 write_c_string (" # (condition-case ... . ", stream);
|
|
5169 Fprin1 (Fcdr (Fcar (catches->tag)), stream);
|
|
5170 write_c_string (")\n", stream);
|
|
5171 }
|
|
5172 catches = catches->next;
|
|
5173 }
|
|
5174 else if (!backlist)
|
|
5175 break;
|
|
5176 else
|
|
5177 {
|
|
5178 if (!NILP (detailed) && backlist->pdlcount < speccount)
|
|
5179 {
|
|
5180 backtrace_specials (speccount, backlist->pdlcount, stream);
|
|
5181 speccount = backlist->pdlcount;
|
|
5182 }
|
|
5183 write_c_string (((backlist->debug_on_exit) ? "* " : " "),
|
|
5184 stream);
|
|
5185 if (backlist->nargs == UNEVALLED)
|
|
5186 {
|
|
5187 Fprin1 (Fcons (*backlist->function, *backlist->args), stream);
|
|
5188 write_c_string ("\n", stream); /* from FSFmacs 19.30 */
|
|
5189 }
|
|
5190 else
|
|
5191 {
|
|
5192 Lisp_Object tem = *backlist->function;
|
|
5193 Fprin1 (tem, stream); /* This can QUIT */
|
|
5194 write_c_string ("(", stream);
|
|
5195 if (backlist->nargs == MANY)
|
|
5196 {
|
|
5197 int i;
|
|
5198 Lisp_Object tail = Qnil;
|
|
5199 struct gcpro ngcpro1;
|
|
5200
|
|
5201 NGCPRO1 (tail);
|
|
5202 for (tail = *backlist->args, i = 0;
|
|
5203 !NILP (tail);
|
|
5204 tail = Fcdr (tail), i++)
|
|
5205 {
|
|
5206 if (i != 0) write_c_string (" ", stream);
|
|
5207 Fprin1 (Fcar (tail), stream);
|
|
5208 }
|
|
5209 NUNGCPRO;
|
|
5210 }
|
|
5211 else
|
|
5212 {
|
|
5213 int i;
|
|
5214 for (i = 0; i < backlist->nargs; i++)
|
|
5215 {
|
|
5216 if (!i && EQ(tem, Qbyte_code)) {
|
|
5217 write_c_string("\"...\"", stream);
|
|
5218 continue;
|
|
5219 }
|
|
5220 if (i != 0) write_c_string (" ", stream);
|
|
5221 Fprin1 (backlist->args[i], stream);
|
|
5222 }
|
|
5223 }
|
442
|
5224 write_c_string (")\n", stream);
|
428
|
5225 }
|
|
5226 backlist = backlist->next;
|
|
5227 }
|
|
5228 }
|
|
5229 Vprint_level = old_level;
|
|
5230 print_readably = old_pr;
|
|
5231 print_escape_newlines = old_nl;
|
|
5232 UNGCPRO;
|
|
5233 Vinhibit_quit = oiq;
|
|
5234 return Qnil;
|
|
5235 }
|
|
5236
|
|
5237
|
444
|
5238 DEFUN ("backtrace-frame", Fbacktrace_frame, 1, 1, 0, /*
|
|
5239 Return the function and arguments NFRAMES up from current execution point.
|
428
|
5240 If that frame has not evaluated the arguments yet (or is a special form),
|
|
5241 the value is (nil FUNCTION ARG-FORMS...).
|
|
5242 If that frame has evaluated its arguments and called its function already,
|
|
5243 the value is (t FUNCTION ARG-VALUES...).
|
|
5244 A &rest arg is represented as the tail of the list ARG-VALUES.
|
|
5245 FUNCTION is whatever was supplied as car of evaluated list,
|
|
5246 or a lambda expression for macro calls.
|
444
|
5247 If NFRAMES is more than the number of frames, the value is nil.
|
428
|
5248 */
|
|
5249 (nframes))
|
|
5250 {
|
|
5251 REGISTER struct backtrace *backlist = backtrace_list;
|
|
5252 REGISTER int i;
|
|
5253 Lisp_Object tem;
|
|
5254
|
|
5255 CHECK_NATNUM (nframes);
|
|
5256
|
|
5257 /* Find the frame requested. */
|
|
5258 for (i = XINT (nframes); backlist && (i-- > 0);)
|
|
5259 backlist = backlist->next;
|
|
5260
|
|
5261 if (!backlist)
|
|
5262 return Qnil;
|
|
5263 if (backlist->nargs == UNEVALLED)
|
|
5264 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
|
|
5265 else
|
|
5266 {
|
|
5267 if (backlist->nargs == MANY)
|
|
5268 tem = *backlist->args;
|
|
5269 else
|
|
5270 tem = Flist (backlist->nargs, backlist->args);
|
|
5271
|
|
5272 return Fcons (Qt, Fcons (*backlist->function, tem));
|
|
5273 }
|
|
5274 }
|
|
5275
|
|
5276
|
|
5277 /************************************************************************/
|
|
5278 /* Warnings */
|
|
5279 /************************************************************************/
|
|
5280
|
|
5281 void
|
|
5282 warn_when_safe_lispobj (Lisp_Object class, Lisp_Object level,
|
|
5283 Lisp_Object obj)
|
|
5284 {
|
793
|
5285 /* Don't even generate debug warnings if they're going to be discarded,
|
|
5286 to avoid excessive consing. */
|
|
5287 if (EQ (level, Qdebug) && !NILP (Vlog_warning_minimum_level) &&
|
|
5288 !EQ (Vlog_warning_minimum_level, Qdebug))
|
|
5289 return;
|
|
5290
|
428
|
5291 obj = list1 (list3 (class, level, obj));
|
|
5292 if (NILP (Vpending_warnings))
|
|
5293 Vpending_warnings = Vpending_warnings_tail = obj;
|
|
5294 else
|
|
5295 {
|
|
5296 Fsetcdr (Vpending_warnings_tail, obj);
|
|
5297 Vpending_warnings_tail = obj;
|
|
5298 }
|
|
5299 }
|
|
5300
|
|
5301 /* #### This should probably accept Lisp objects; but then we have
|
|
5302 to make sure that Feval() isn't called, since it might not be safe.
|
|
5303
|
|
5304 An alternative approach is to just pass some non-string type of
|
|
5305 Lisp_Object to warn_when_safe_lispobj(); `prin1-to-string' will
|
|
5306 automatically be called when it is safe to do so. */
|
|
5307
|
|
5308 void
|
665
|
5309 warn_when_safe (Lisp_Object class, Lisp_Object level, const CIntbyte *fmt, ...)
|
428
|
5310 {
|
|
5311 Lisp_Object obj;
|
|
5312 va_list args;
|
|
5313
|
793
|
5314 /* Don't even generate debug warnings if they're going to be discarded,
|
|
5315 to avoid excessive consing. */
|
|
5316 if (EQ (level, Qdebug) && !NILP (Vlog_warning_minimum_level) &&
|
|
5317 !EQ (Vlog_warning_minimum_level, Qdebug))
|
|
5318 return;
|
|
5319
|
428
|
5320 va_start (args, fmt);
|
771
|
5321 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
428
|
5322 va_end (args);
|
|
5323
|
|
5324 warn_when_safe_lispobj (class, level, obj);
|
|
5325 }
|
|
5326
|
|
5327
|
|
5328
|
|
5329
|
|
5330 /************************************************************************/
|
|
5331 /* Initialization */
|
|
5332 /************************************************************************/
|
|
5333
|
|
5334 void
|
|
5335 syms_of_eval (void)
|
|
5336 {
|
442
|
5337 INIT_LRECORD_IMPLEMENTATION (subr);
|
|
5338
|
563
|
5339 DEFSYMBOL (Qinhibit_quit);
|
|
5340 DEFSYMBOL (Qautoload);
|
|
5341 DEFSYMBOL (Qdebug_on_error);
|
|
5342 DEFSYMBOL (Qstack_trace_on_error);
|
|
5343 DEFSYMBOL (Qdebug_on_signal);
|
|
5344 DEFSYMBOL (Qstack_trace_on_signal);
|
|
5345 DEFSYMBOL (Qdebugger);
|
|
5346 DEFSYMBOL (Qmacro);
|
428
|
5347 defsymbol (&Qand_rest, "&rest");
|
|
5348 defsymbol (&Qand_optional, "&optional");
|
|
5349 /* Note that the process code also uses Qexit */
|
563
|
5350 DEFSYMBOL (Qexit);
|
|
5351 DEFSYMBOL (Qsetq);
|
|
5352 DEFSYMBOL (Qinteractive);
|
|
5353 DEFSYMBOL (Qcommandp);
|
|
5354 DEFSYMBOL (Qdefun);
|
|
5355 DEFSYMBOL (Qprogn);
|
|
5356 DEFSYMBOL (Qvalues);
|
|
5357 DEFSYMBOL (Qdisplay_warning);
|
|
5358 DEFSYMBOL (Qrun_hooks);
|
|
5359 DEFSYMBOL (Qif);
|
428
|
5360
|
|
5361 DEFSUBR (For);
|
|
5362 DEFSUBR (Fand);
|
|
5363 DEFSUBR (Fif);
|
|
5364 DEFSUBR_MACRO (Fwhen);
|
|
5365 DEFSUBR_MACRO (Funless);
|
|
5366 DEFSUBR (Fcond);
|
|
5367 DEFSUBR (Fprogn);
|
|
5368 DEFSUBR (Fprog1);
|
|
5369 DEFSUBR (Fprog2);
|
|
5370 DEFSUBR (Fsetq);
|
|
5371 DEFSUBR (Fquote);
|
|
5372 DEFSUBR (Ffunction);
|
|
5373 DEFSUBR (Fdefun);
|
|
5374 DEFSUBR (Fdefmacro);
|
|
5375 DEFSUBR (Fdefvar);
|
|
5376 DEFSUBR (Fdefconst);
|
|
5377 DEFSUBR (Fuser_variable_p);
|
|
5378 DEFSUBR (Flet);
|
|
5379 DEFSUBR (FletX);
|
|
5380 DEFSUBR (Fwhile);
|
|
5381 DEFSUBR (Fmacroexpand_internal);
|
|
5382 DEFSUBR (Fcatch);
|
|
5383 DEFSUBR (Fthrow);
|
|
5384 DEFSUBR (Funwind_protect);
|
|
5385 DEFSUBR (Fcondition_case);
|
|
5386 DEFSUBR (Fcall_with_condition_handler);
|
|
5387 DEFSUBR (Fsignal);
|
|
5388 DEFSUBR (Finteractive_p);
|
|
5389 DEFSUBR (Fcommandp);
|
|
5390 DEFSUBR (Fcommand_execute);
|
|
5391 DEFSUBR (Fautoload);
|
|
5392 DEFSUBR (Feval);
|
|
5393 DEFSUBR (Fapply);
|
|
5394 DEFSUBR (Ffuncall);
|
|
5395 DEFSUBR (Ffunctionp);
|
|
5396 DEFSUBR (Ffunction_min_args);
|
|
5397 DEFSUBR (Ffunction_max_args);
|
|
5398 DEFSUBR (Frun_hooks);
|
|
5399 DEFSUBR (Frun_hook_with_args);
|
|
5400 DEFSUBR (Frun_hook_with_args_until_success);
|
|
5401 DEFSUBR (Frun_hook_with_args_until_failure);
|
|
5402 DEFSUBR (Fbacktrace_debug);
|
|
5403 DEFSUBR (Fbacktrace);
|
|
5404 DEFSUBR (Fbacktrace_frame);
|
|
5405 }
|
|
5406
|
|
5407 void
|
771
|
5408 init_eval_early (void)
|
428
|
5409 {
|
|
5410 specpdl_ptr = specpdl;
|
|
5411 specpdl_depth_counter = 0;
|
|
5412 catchlist = 0;
|
|
5413 Vcondition_handlers = Qnil;
|
|
5414 backtrace_list = 0;
|
|
5415 Vquit_flag = Qnil;
|
|
5416 debug_on_next_call = 0;
|
|
5417 lisp_eval_depth = 0;
|
|
5418 entering_debugger = 0;
|
|
5419 }
|
|
5420
|
|
5421 void
|
|
5422 reinit_vars_of_eval (void)
|
|
5423 {
|
|
5424 preparing_for_armageddon = 0;
|
|
5425 in_warnings = 0;
|
|
5426 Qunbound_suspended_errors_tag = make_opaque_ptr (&Qunbound_suspended_errors_tag);
|
|
5427 staticpro_nodump (&Qunbound_suspended_errors_tag);
|
|
5428
|
|
5429 specpdl_size = 50;
|
|
5430 specpdl = xnew_array (struct specbinding, specpdl_size);
|
|
5431 /* XEmacs change: increase these values. */
|
|
5432 max_specpdl_size = 3000;
|
442
|
5433 max_lisp_eval_depth = 1000;
|
|
5434 #ifdef DEFEND_AGAINST_THROW_RECURSION
|
428
|
5435 throw_level = 0;
|
|
5436 #endif
|
|
5437 }
|
|
5438
|
|
5439 void
|
|
5440 vars_of_eval (void)
|
|
5441 {
|
|
5442 reinit_vars_of_eval ();
|
|
5443
|
|
5444 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size /*
|
|
5445 Limit on number of Lisp variable bindings & unwind-protects before error.
|
|
5446 */ );
|
|
5447
|
|
5448 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth /*
|
|
5449 Limit on depth in `eval', `apply' and `funcall' before error.
|
|
5450 This limit is to catch infinite recursions for you before they cause
|
|
5451 actual stack overflow in C, which would be fatal for Emacs.
|
|
5452 You can safely make it considerably larger than its default value,
|
|
5453 if that proves inconveniently small.
|
|
5454 */ );
|
|
5455
|
|
5456 DEFVAR_LISP ("quit-flag", &Vquit_flag /*
|
|
5457 Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
|
|
5458 Typing C-G sets `quit-flag' non-nil, regardless of `inhibit-quit'.
|
|
5459 */ );
|
|
5460 Vquit_flag = Qnil;
|
|
5461
|
|
5462 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit /*
|
|
5463 Non-nil inhibits C-g quitting from happening immediately.
|
|
5464 Note that `quit-flag' will still be set by typing C-g,
|
|
5465 so a quit will be signalled as soon as `inhibit-quit' is nil.
|
|
5466 To prevent this happening, set `quit-flag' to nil
|
|
5467 before making `inhibit-quit' nil. The value of `inhibit-quit' is
|
|
5468 ignored if a critical quit is requested by typing control-shift-G in
|
|
5469 an X frame.
|
|
5470 */ );
|
|
5471 Vinhibit_quit = Qnil;
|
|
5472
|
|
5473 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error /*
|
|
5474 *Non-nil means automatically display a backtrace buffer
|
|
5475 after any error that is not handled by a `condition-case'.
|
|
5476 If the value is a list, an error only means to display a backtrace
|
|
5477 if one of its condition symbols appears in the list.
|
|
5478 See also variable `stack-trace-on-signal'.
|
|
5479 */ );
|
|
5480 Vstack_trace_on_error = Qnil;
|
|
5481
|
|
5482 DEFVAR_LISP ("stack-trace-on-signal", &Vstack_trace_on_signal /*
|
|
5483 *Non-nil means automatically display a backtrace buffer
|
|
5484 after any error that is signalled, whether or not it is handled by
|
|
5485 a `condition-case'.
|
|
5486 If the value is a list, an error only means to display a backtrace
|
|
5487 if one of its condition symbols appears in the list.
|
|
5488 See also variable `stack-trace-on-error'.
|
|
5489 */ );
|
|
5490 Vstack_trace_on_signal = Qnil;
|
|
5491
|
|
5492 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors /*
|
|
5493 *List of errors for which the debugger should not be called.
|
|
5494 Each element may be a condition-name or a regexp that matches error messages.
|
|
5495 If any element applies to a given error, that error skips the debugger
|
|
5496 and just returns to top level.
|
|
5497 This overrides the variable `debug-on-error'.
|
|
5498 It does not apply to errors handled by `condition-case'.
|
|
5499 */ );
|
|
5500 Vdebug_ignored_errors = Qnil;
|
|
5501
|
|
5502 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error /*
|
|
5503 *Non-nil means enter debugger if an unhandled error is signalled.
|
|
5504 The debugger will not be entered if the error is handled by
|
|
5505 a `condition-case'.
|
|
5506 If the value is a list, an error only means to enter the debugger
|
|
5507 if one of its condition symbols appears in the list.
|
|
5508 This variable is overridden by `debug-ignored-errors'.
|
|
5509 See also variables `debug-on-quit' and `debug-on-signal'.
|
771
|
5510 If this variable is set while XEmacs is running noninteractively,
|
|
5511 an unhandled error will cause a backtrace to be output and the C
|
|
5512 debugger entered using `force-debugging-signal'. This can be very
|
|
5513 useful when debugging noninteractive errors in tricky situations,
|
|
5514 e.g. makefiles, since you can set this variable using an environment
|
|
5515 variable, like this:
|
|
5516
|
|
5517 \(using csh) setenv XEMACSDEBUG '(setq debug-on-error t)'
|
|
5518 \(using bash) export XEMACSDEBUG='(setq debug-on-error t)'
|
428
|
5519 */ );
|
|
5520 Vdebug_on_error = Qnil;
|
|
5521
|
|
5522 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal /*
|
|
5523 *Non-nil means enter debugger if an error is signalled.
|
|
5524 The debugger will be entered whether or not the error is handled by
|
|
5525 a `condition-case'.
|
|
5526 If the value is a list, an error only means to enter the debugger
|
|
5527 if one of its condition symbols appears in the list.
|
|
5528 See also variable `debug-on-quit'.
|
|
5529 */ );
|
|
5530 Vdebug_on_signal = Qnil;
|
|
5531
|
|
5532 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit /*
|
|
5533 *Non-nil means enter debugger if quit is signalled (C-G, for example).
|
|
5534 Does not apply if quit is handled by a `condition-case'. Entering the
|
|
5535 debugger can also be achieved at any time (for X11 console) by typing
|
|
5536 control-shift-G to signal a critical quit.
|
|
5537 */ );
|
|
5538 debug_on_quit = 0;
|
|
5539
|
|
5540 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call /*
|
|
5541 Non-nil means enter debugger before next `eval', `apply' or `funcall'.
|
|
5542 */ );
|
|
5543
|
|
5544 DEFVAR_LISP ("debugger", &Vdebugger /*
|
|
5545 Function to call to invoke debugger.
|
|
5546 If due to frame exit, args are `exit' and the value being returned;
|
|
5547 this function's value will be returned instead of that.
|
|
5548 If due to error, args are `error' and a list of the args to `signal'.
|
|
5549 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
5550 If due to `eval' entry, one arg, t.
|
|
5551 */ );
|
|
5552 Vdebugger = Qnil;
|
|
5553
|
|
5554 staticpro (&Vpending_warnings);
|
|
5555 Vpending_warnings = Qnil;
|
452
|
5556 dump_add_root_object (&Vpending_warnings_tail);
|
428
|
5557 Vpending_warnings_tail = Qnil;
|
|
5558
|
793
|
5559 DEFVAR_LISP ("log-warning-minimum-level", &Vlog_warning_minimum_level);
|
|
5560 Vlog_warning_minimum_level = Qinfo;
|
|
5561
|
428
|
5562 staticpro (&Vautoload_queue);
|
|
5563 Vautoload_queue = Qnil;
|
|
5564
|
|
5565 staticpro (&Vcondition_handlers);
|
|
5566
|
|
5567 staticpro (&Vcurrent_warning_class);
|
|
5568 Vcurrent_warning_class = Qnil;
|
|
5569
|
793
|
5570 staticpro (&Vcurrent_warning_level);
|
|
5571 Vcurrent_warning_level = Qnil;
|
|
5572
|
428
|
5573 staticpro (&Vcurrent_error_state);
|
|
5574 Vcurrent_error_state = Qnil; /* errors as normal */
|
771
|
5575 }
|