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