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