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