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;
|
4162
|
3103 PROFILE_DECLARE();
|
428
|
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;
|
4162
|
3536 PROFILE_DECLARE();
|
428
|
3537
|
1318
|
3538 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS
|
|
3539 check_proper_critical_section_lisp_protection ();
|
|
3540 #endif
|
|
3541
|
3989
|
3542 if (!CONSP (form))
|
|
3543 {
|
|
3544 if (SYMBOLP (form))
|
|
3545 {
|
|
3546 return Fsymbol_value (form);
|
|
3547 }
|
|
3548
|
|
3549 return form;
|
|
3550 }
|
|
3551
|
428
|
3552 /* I think this is a pretty safe place to call Lisp code, don't you? */
|
853
|
3553 while (!in_warnings && !NILP (Vpending_warnings)
|
|
3554 /* well, perhaps not so safe after all! */
|
|
3555 && !(inhibit_flags & INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY))
|
428
|
3556 {
|
|
3557 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
1204
|
3558 Lisp_Object this_warning_cons, this_warning, class_, level, messij;
|
853
|
3559 int speccount = internal_bind_int (&in_warnings, 1);
|
|
3560
|
428
|
3561 this_warning_cons = Vpending_warnings;
|
|
3562 this_warning = XCAR (this_warning_cons);
|
|
3563 /* in case an error occurs in the warn function, at least
|
|
3564 it won't happen infinitely */
|
|
3565 Vpending_warnings = XCDR (Vpending_warnings);
|
853
|
3566 free_cons (this_warning_cons);
|
1204
|
3567 class_ = XCAR (this_warning);
|
428
|
3568 level = XCAR (XCDR (this_warning));
|
|
3569 messij = XCAR (XCDR (XCDR (this_warning)));
|
|
3570 free_list (this_warning);
|
|
3571
|
|
3572 if (NILP (Vpending_warnings))
|
|
3573 Vpending_warnings_tail = Qnil; /* perhaps not strictly necessary,
|
|
3574 but safer */
|
|
3575
|
1204
|
3576 GCPRO4 (form, class_, level, messij);
|
428
|
3577 if (!STRINGP (messij))
|
|
3578 messij = Fprin1_to_string (messij, Qnil);
|
1204
|
3579 call3 (Qdisplay_warning, class_, messij, level);
|
428
|
3580 UNGCPRO;
|
771
|
3581 unbind_to (speccount);
|
428
|
3582 }
|
|
3583
|
|
3584 QUIT;
|
814
|
3585 if (need_to_garbage_collect)
|
428
|
3586 {
|
|
3587 struct gcpro gcpro1;
|
|
3588 GCPRO1 (form);
|
3092
|
3589 #ifdef NEW_GC
|
|
3590 gc_incremental ();
|
|
3591 #else /* not NEW_GC */
|
428
|
3592 garbage_collect_1 ();
|
3092
|
3593 #endif /* not NEW_GC */
|
428
|
3594 UNGCPRO;
|
|
3595 }
|
|
3596
|
|
3597 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
3598 {
|
|
3599 if (max_lisp_eval_depth < 100)
|
|
3600 max_lisp_eval_depth = 100;
|
|
3601 if (lisp_eval_depth > max_lisp_eval_depth)
|
563
|
3602 stack_overflow ("Lisp nesting exceeds `max-lisp-eval-depth'",
|
|
3603 Qunbound);
|
428
|
3604 }
|
|
3605
|
|
3606 /* We guaranteed CONSP (form) above */
|
|
3607 original_fun = XCAR (form);
|
|
3608 original_args = XCDR (form);
|
|
3609
|
|
3610 GET_EXTERNAL_LIST_LENGTH (original_args, nargs);
|
|
3611
|
|
3612 backtrace.pdlcount = specpdl_depth();
|
|
3613 backtrace.function = &original_fun; /* This also protects them from gc */
|
|
3614 backtrace.args = &original_args;
|
|
3615 backtrace.nargs = UNEVALLED;
|
|
3616 backtrace.evalargs = 1;
|
|
3617 backtrace.debug_on_exit = 0;
|
1292
|
3618 backtrace.function_being_called = 0;
|
428
|
3619 PUSH_BACKTRACE (backtrace);
|
|
3620
|
|
3621 if (debug_on_next_call)
|
|
3622 do_debug_on_call (Qt);
|
|
3623
|
|
3624 /* At this point, only original_fun and original_args
|
|
3625 have values that will be used below. */
|
|
3626 retry:
|
3989
|
3627 /* Optimise for no indirection. */
|
|
3628 fun = original_fun;
|
|
3629 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
|
|
3630 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
|
|
3631 {
|
|
3632 fun = indirect_function(original_fun, 1);
|
|
3633 }
|
428
|
3634
|
|
3635 if (SUBRP (fun))
|
|
3636 {
|
|
3637 Lisp_Subr *subr = XSUBR (fun);
|
|
3638 int max_args = subr->max_args;
|
|
3639
|
|
3640 if (nargs < subr->min_args)
|
|
3641 goto wrong_number_of_arguments;
|
|
3642
|
|
3643 if (max_args == UNEVALLED) /* Optimize for the common case */
|
|
3644 {
|
|
3645 backtrace.evalargs = 0;
|
1292
|
3646 PROFILE_ENTER_FUNCTION ();
|
428
|
3647 val = (((Lisp_Object (*) (Lisp_Object)) subr_function (subr))
|
|
3648 (original_args));
|
1292
|
3649 PROFILE_EXIT_FUNCTION ();
|
428
|
3650 }
|
|
3651 else if (nargs <= max_args)
|
|
3652 {
|
|
3653 struct gcpro gcpro1;
|
|
3654 Lisp_Object args[SUBR_MAX_ARGS];
|
|
3655 REGISTER Lisp_Object *p = args;
|
|
3656
|
|
3657 GCPRO1 (args[0]);
|
|
3658 gcpro1.nvars = 0;
|
|
3659
|
|
3660 {
|
|
3661 LIST_LOOP_2 (arg, original_args)
|
|
3662 {
|
|
3663 *p++ = Feval (arg);
|
|
3664 gcpro1.nvars++;
|
|
3665 }
|
|
3666 }
|
|
3667
|
|
3668 /* &optional args default to nil. */
|
|
3669 while (p - args < max_args)
|
|
3670 *p++ = Qnil;
|
|
3671
|
|
3672 backtrace.args = args;
|
|
3673 backtrace.nargs = nargs;
|
|
3674
|
1292
|
3675 PROFILE_ENTER_FUNCTION ();
|
428
|
3676 FUNCALL_SUBR (val, subr, args, max_args);
|
1292
|
3677 PROFILE_EXIT_FUNCTION ();
|
428
|
3678
|
|
3679 UNGCPRO;
|
|
3680 }
|
|
3681 else if (max_args == MANY)
|
|
3682 {
|
|
3683 /* Pass a vector of evaluated arguments */
|
|
3684 struct gcpro gcpro1;
|
|
3685 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
|
|
3686 REGISTER Lisp_Object *p = args;
|
|
3687
|
|
3688 GCPRO1 (args[0]);
|
|
3689 gcpro1.nvars = 0;
|
|
3690
|
|
3691 {
|
|
3692 LIST_LOOP_2 (arg, original_args)
|
|
3693 {
|
|
3694 *p++ = Feval (arg);
|
|
3695 gcpro1.nvars++;
|
|
3696 }
|
|
3697 }
|
|
3698
|
|
3699 backtrace.args = args;
|
|
3700 backtrace.nargs = nargs;
|
|
3701
|
1292
|
3702 PROFILE_ENTER_FUNCTION ();
|
428
|
3703 val = (((Lisp_Object (*) (int, Lisp_Object *)) subr_function (subr))
|
|
3704 (nargs, args));
|
1292
|
3705 PROFILE_EXIT_FUNCTION ();
|
428
|
3706
|
|
3707 UNGCPRO;
|
|
3708 }
|
|
3709 else
|
|
3710 {
|
|
3711 wrong_number_of_arguments:
|
440
|
3712 val = signal_wrong_number_of_arguments_error (original_fun, nargs);
|
428
|
3713 }
|
|
3714 }
|
|
3715 else if (COMPILED_FUNCTIONP (fun))
|
|
3716 {
|
|
3717 struct gcpro gcpro1;
|
|
3718 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
|
|
3719 REGISTER Lisp_Object *p = args;
|
|
3720
|
|
3721 GCPRO1 (args[0]);
|
|
3722 gcpro1.nvars = 0;
|
|
3723
|
|
3724 {
|
|
3725 LIST_LOOP_2 (arg, original_args)
|
|
3726 {
|
|
3727 *p++ = Feval (arg);
|
|
3728 gcpro1.nvars++;
|
|
3729 }
|
|
3730 }
|
|
3731
|
|
3732 backtrace.args = args;
|
|
3733 backtrace.nargs = nargs;
|
|
3734 backtrace.evalargs = 0;
|
|
3735
|
1292
|
3736 PROFILE_ENTER_FUNCTION ();
|
428
|
3737 val = funcall_compiled_function (fun, nargs, args);
|
1292
|
3738 PROFILE_EXIT_FUNCTION ();
|
428
|
3739
|
|
3740 /* Do the debug-on-exit now, while args is still GCPROed. */
|
|
3741 if (backtrace.debug_on_exit)
|
|
3742 val = do_debug_on_exit (val);
|
|
3743 /* Don't do it again when we return to eval. */
|
|
3744 backtrace.debug_on_exit = 0;
|
|
3745
|
|
3746 UNGCPRO;
|
|
3747 }
|
|
3748 else if (CONSP (fun))
|
|
3749 {
|
|
3750 Lisp_Object funcar = XCAR (fun);
|
|
3751
|
|
3752 if (EQ (funcar, Qautoload))
|
|
3753 {
|
970
|
3754 /* do_autoload GCPROs both arguments */
|
428
|
3755 do_autoload (fun, original_fun);
|
|
3756 goto retry;
|
|
3757 }
|
|
3758 else if (EQ (funcar, Qmacro))
|
|
3759 {
|
1292
|
3760 PROFILE_ENTER_FUNCTION ();
|
428
|
3761 val = Feval (apply1 (XCDR (fun), original_args));
|
1292
|
3762 PROFILE_EXIT_FUNCTION ();
|
428
|
3763 }
|
|
3764 else if (EQ (funcar, Qlambda))
|
|
3765 {
|
|
3766 struct gcpro gcpro1;
|
|
3767 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
|
|
3768 REGISTER Lisp_Object *p = args;
|
|
3769
|
|
3770 GCPRO1 (args[0]);
|
|
3771 gcpro1.nvars = 0;
|
|
3772
|
|
3773 {
|
|
3774 LIST_LOOP_2 (arg, original_args)
|
|
3775 {
|
|
3776 *p++ = Feval (arg);
|
|
3777 gcpro1.nvars++;
|
|
3778 }
|
|
3779 }
|
|
3780
|
|
3781 UNGCPRO;
|
|
3782
|
|
3783 backtrace.args = args; /* this also GCPROs `args' */
|
|
3784 backtrace.nargs = nargs;
|
|
3785 backtrace.evalargs = 0;
|
|
3786
|
1292
|
3787 PROFILE_ENTER_FUNCTION ();
|
428
|
3788 val = funcall_lambda (fun, nargs, args);
|
1292
|
3789 PROFILE_EXIT_FUNCTION ();
|
428
|
3790
|
|
3791 /* Do the debug-on-exit now, while args is still GCPROed. */
|
|
3792 if (backtrace.debug_on_exit)
|
|
3793 val = do_debug_on_exit (val);
|
|
3794 /* Don't do it again when we return to eval. */
|
|
3795 backtrace.debug_on_exit = 0;
|
|
3796 }
|
|
3797 else
|
|
3798 {
|
|
3799 goto invalid_function;
|
|
3800 }
|
|
3801 }
|
4104
|
3802 else if (UNBOUNDP (fun))
|
|
3803 {
|
|
3804 val = signal_void_function_error (original_fun);
|
|
3805 }
|
|
3806 else /* ! (SUBRP (fun) || COMPILED_FUNCTIONP (fun) || CONSP (fun)
|
|
3807 UNBOUNDP (fun)) */
|
428
|
3808 {
|
|
3809 invalid_function:
|
436
|
3810 val = signal_invalid_function_error (fun);
|
428
|
3811 }
|
|
3812
|
|
3813 lisp_eval_depth--;
|
|
3814 if (backtrace.debug_on_exit)
|
|
3815 val = do_debug_on_exit (val);
|
|
3816 POP_BACKTRACE (backtrace);
|
|
3817 return val;
|
|
3818 }
|
|
3819
|
|
3820
|
1111
|
3821
|
|
3822 static void
|
|
3823 run_post_gc_hook (void)
|
|
3824 {
|
|
3825 Lisp_Object args[2];
|
|
3826
|
|
3827 args[0] = Qpost_gc_hook;
|
|
3828 args[1] = Fcons (Fcons (Qfinalize_list, zap_finalize_list ()), Qnil);
|
|
3829
|
|
3830 run_hook_with_args_trapping_problems
|
1333
|
3831 (Qgarbage_collecting, 2, args, RUN_HOOKS_TO_COMPLETION,
|
1111
|
3832 INHIBIT_QUIT | NO_INHIBIT_ERRORS);
|
|
3833 }
|
|
3834
|
428
|
3835 DEFUN ("funcall", Ffuncall, 1, MANY, 0, /*
|
|
3836 Call first argument as a function, passing the remaining arguments to it.
|
|
3837 Thus, (funcall 'cons 'x 'y) returns (x . y).
|
|
3838 */
|
|
3839 (int nargs, Lisp_Object *args))
|
|
3840 {
|
|
3841 /* This function can GC */
|
|
3842 Lisp_Object fun;
|
|
3843 Lisp_Object val;
|
4162
|
3844 PROFILE_DECLARE();
|
428
|
3845 int fun_nargs = nargs - 1;
|
|
3846 Lisp_Object *fun_args = args + 1;
|
|
3847
|
1318
|
3848 /* QUIT will check for proper redisplay wrapping */
|
|
3849
|
428
|
3850 QUIT;
|
851
|
3851
|
|
3852 if (funcall_allocation_flag)
|
|
3853 {
|
|
3854 if (need_to_garbage_collect)
|
|
3855 /* Callers should gcpro lexpr args */
|
3092
|
3856 #ifdef NEW_GC
|
|
3857 gc_incremental ();
|
|
3858 #else /* not NEW_GC */
|
851
|
3859 garbage_collect_1 ();
|
3092
|
3860 #endif /* not NEW_GC */
|
851
|
3861 if (need_to_check_c_alloca)
|
|
3862 {
|
|
3863 if (++funcall_alloca_count >= MAX_FUNCALLS_BETWEEN_ALLOCA_CLEANUP)
|
|
3864 {
|
|
3865 xemacs_c_alloca (0);
|
|
3866 funcall_alloca_count = 0;
|
|
3867 }
|
|
3868 }
|
887
|
3869 if (need_to_signal_post_gc)
|
|
3870 {
|
|
3871 need_to_signal_post_gc = 0;
|
1111
|
3872 recompute_funcall_allocation_flag ();
|
3263
|
3873 #ifdef NEW_GC
|
|
3874 run_finalizers ();
|
|
3875 #endif /* NEW_GC */
|
1111
|
3876 run_post_gc_hook ();
|
887
|
3877 }
|
851
|
3878 }
|
428
|
3879
|
|
3880 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
3881 {
|
|
3882 if (max_lisp_eval_depth < 100)
|
|
3883 max_lisp_eval_depth = 100;
|
|
3884 if (lisp_eval_depth > max_lisp_eval_depth)
|
563
|
3885 stack_overflow ("Lisp nesting exceeds `max-lisp-eval-depth'",
|
|
3886 Qunbound);
|
428
|
3887 }
|
|
3888
|
1292
|
3889 backtrace.pdlcount = specpdl_depth ();
|
428
|
3890 backtrace.function = &args[0];
|
|
3891 backtrace.args = fun_args;
|
|
3892 backtrace.nargs = fun_nargs;
|
|
3893 backtrace.evalargs = 0;
|
|
3894 backtrace.debug_on_exit = 0;
|
1292
|
3895 backtrace.function_being_called = 0;
|
428
|
3896 PUSH_BACKTRACE (backtrace);
|
|
3897
|
|
3898 if (debug_on_next_call)
|
|
3899 do_debug_on_call (Qlambda);
|
|
3900
|
|
3901 retry:
|
|
3902
|
|
3903 fun = args[0];
|
|
3904
|
|
3905 /* We could call indirect_function directly, but profiling shows
|
|
3906 this is worth optimizing by partially unrolling the loop. */
|
|
3907 if (SYMBOLP (fun))
|
|
3908 {
|
|
3909 fun = XSYMBOL (fun)->function;
|
|
3910 if (SYMBOLP (fun))
|
|
3911 {
|
|
3912 fun = XSYMBOL (fun)->function;
|
|
3913 if (SYMBOLP (fun))
|
|
3914 fun = indirect_function (fun, 1);
|
|
3915 }
|
|
3916 }
|
|
3917
|
|
3918 if (SUBRP (fun))
|
|
3919 {
|
|
3920 Lisp_Subr *subr = XSUBR (fun);
|
|
3921 int max_args = subr->max_args;
|
|
3922 Lisp_Object spacious_args[SUBR_MAX_ARGS];
|
|
3923
|
|
3924 if (fun_nargs == max_args) /* Optimize for the common case */
|
|
3925 {
|
|
3926 funcall_subr:
|
1292
|
3927 PROFILE_ENTER_FUNCTION ();
|
428
|
3928 FUNCALL_SUBR (val, subr, fun_args, max_args);
|
1292
|
3929 PROFILE_EXIT_FUNCTION ();
|
428
|
3930 }
|
436
|
3931 else if (fun_nargs < subr->min_args)
|
|
3932 {
|
|
3933 goto wrong_number_of_arguments;
|
|
3934 }
|
428
|
3935 else if (fun_nargs < max_args)
|
|
3936 {
|
|
3937 Lisp_Object *p = spacious_args;
|
|
3938
|
|
3939 /* Default optionals to nil */
|
|
3940 while (fun_nargs--)
|
|
3941 *p++ = *fun_args++;
|
|
3942 while (p - spacious_args < max_args)
|
|
3943 *p++ = Qnil;
|
|
3944
|
|
3945 fun_args = spacious_args;
|
|
3946 goto funcall_subr;
|
|
3947 }
|
|
3948 else if (max_args == MANY)
|
|
3949 {
|
1292
|
3950 PROFILE_ENTER_FUNCTION ();
|
436
|
3951 val = SUBR_FUNCTION (subr, MANY) (fun_nargs, fun_args);
|
1292
|
3952 PROFILE_EXIT_FUNCTION ();
|
428
|
3953 }
|
|
3954 else if (max_args == UNEVALLED) /* Can't funcall a special form */
|
|
3955 {
|
|
3956 goto invalid_function;
|
|
3957 }
|
|
3958 else
|
|
3959 {
|
|
3960 wrong_number_of_arguments:
|
436
|
3961 val = signal_wrong_number_of_arguments_error (fun, fun_nargs);
|
428
|
3962 }
|
|
3963 }
|
|
3964 else if (COMPILED_FUNCTIONP (fun))
|
|
3965 {
|
1292
|
3966 PROFILE_ENTER_FUNCTION ();
|
428
|
3967 val = funcall_compiled_function (fun, fun_nargs, fun_args);
|
1292
|
3968 PROFILE_EXIT_FUNCTION ();
|
428
|
3969 }
|
|
3970 else if (CONSP (fun))
|
|
3971 {
|
|
3972 Lisp_Object funcar = XCAR (fun);
|
|
3973
|
|
3974 if (EQ (funcar, Qlambda))
|
|
3975 {
|
1292
|
3976 PROFILE_ENTER_FUNCTION ();
|
428
|
3977 val = funcall_lambda (fun, fun_nargs, fun_args);
|
1292
|
3978 PROFILE_EXIT_FUNCTION ();
|
428
|
3979 }
|
|
3980 else if (EQ (funcar, Qautoload))
|
|
3981 {
|
970
|
3982 /* do_autoload GCPROs both arguments */
|
428
|
3983 do_autoload (fun, args[0]);
|
|
3984 goto retry;
|
|
3985 }
|
|
3986 else /* Can't funcall a macro */
|
|
3987 {
|
|
3988 goto invalid_function;
|
|
3989 }
|
|
3990 }
|
|
3991 else if (UNBOUNDP (fun))
|
|
3992 {
|
436
|
3993 val = signal_void_function_error (args[0]);
|
428
|
3994 }
|
|
3995 else
|
|
3996 {
|
|
3997 invalid_function:
|
436
|
3998 val = signal_invalid_function_error (fun);
|
428
|
3999 }
|
|
4000
|
|
4001 lisp_eval_depth--;
|
|
4002 if (backtrace.debug_on_exit)
|
|
4003 val = do_debug_on_exit (val);
|
|
4004 POP_BACKTRACE (backtrace);
|
|
4005 return val;
|
|
4006 }
|
|
4007
|
|
4008 DEFUN ("functionp", Ffunctionp, 1, 1, 0, /*
|
|
4009 Return t if OBJECT can be called as a function, else nil.
|
|
4010 A function is an object that can be applied to arguments,
|
|
4011 using for example `funcall' or `apply'.
|
|
4012 */
|
|
4013 (object))
|
|
4014 {
|
|
4015 if (SYMBOLP (object))
|
|
4016 object = indirect_function (object, 0);
|
|
4017
|
919
|
4018 if (COMPILED_FUNCTIONP (object) || SUBRP (object))
|
|
4019 return Qt;
|
|
4020 if (CONSP (object))
|
|
4021 {
|
|
4022 Lisp_Object car = XCAR (object);
|
|
4023 if (EQ (car, Qlambda))
|
|
4024 return Qt;
|
|
4025 if (EQ (car, Qautoload)
|
|
4026 && NILP (Fcar_safe (Fcdr_safe (Fcdr_safe (Fcdr_safe (XCDR (object)))))))
|
|
4027 return Qt;
|
|
4028 }
|
|
4029 return Qnil;
|
428
|
4030 }
|
|
4031
|
|
4032 static Lisp_Object
|
|
4033 function_argcount (Lisp_Object function, int function_min_args_p)
|
|
4034 {
|
|
4035 Lisp_Object orig_function = function;
|
|
4036 Lisp_Object arglist;
|
|
4037
|
|
4038 retry:
|
|
4039
|
|
4040 if (SYMBOLP (function))
|
|
4041 function = indirect_function (function, 1);
|
|
4042
|
|
4043 if (SUBRP (function))
|
|
4044 {
|
442
|
4045 /* Using return with the ?: operator tickles a DEC CC compiler bug. */
|
|
4046 if (function_min_args_p)
|
|
4047 return Fsubr_min_args (function);
|
|
4048 else
|
|
4049 return Fsubr_max_args (function);
|
428
|
4050 }
|
|
4051 else if (COMPILED_FUNCTIONP (function))
|
|
4052 {
|
814
|
4053 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (function);
|
|
4054
|
1737
|
4055 if (!OPAQUEP (f->instructions))
|
|
4056 /* Lazily munge the instructions into a more efficient form */
|
|
4057 /* Needed to set max_args */
|
|
4058 optimize_compiled_function (function);
|
|
4059
|
814
|
4060 if (function_min_args_p)
|
|
4061 return make_int (f->min_args);
|
|
4062 else if (f->max_args == MANY)
|
|
4063 return Qnil;
|
|
4064 else
|
|
4065 return make_int (f->max_args);
|
428
|
4066 }
|
|
4067 else if (CONSP (function))
|
|
4068 {
|
|
4069 Lisp_Object funcar = XCAR (function);
|
|
4070
|
|
4071 if (EQ (funcar, Qmacro))
|
|
4072 {
|
|
4073 function = XCDR (function);
|
|
4074 goto retry;
|
|
4075 }
|
|
4076 else if (EQ (funcar, Qautoload))
|
|
4077 {
|
970
|
4078 /* do_autoload GCPROs both arguments */
|
428
|
4079 do_autoload (function, orig_function);
|
442
|
4080 function = orig_function;
|
428
|
4081 goto retry;
|
|
4082 }
|
|
4083 else if (EQ (funcar, Qlambda))
|
|
4084 {
|
|
4085 arglist = Fcar (XCDR (function));
|
|
4086 }
|
|
4087 else
|
|
4088 {
|
|
4089 goto invalid_function;
|
|
4090 }
|
|
4091 }
|
|
4092 else
|
|
4093 {
|
|
4094 invalid_function:
|
442
|
4095 return signal_invalid_function_error (orig_function);
|
428
|
4096 }
|
|
4097
|
|
4098 {
|
|
4099 int argcount = 0;
|
|
4100
|
|
4101 EXTERNAL_LIST_LOOP_2 (arg, arglist)
|
|
4102 {
|
|
4103 if (EQ (arg, Qand_optional))
|
|
4104 {
|
|
4105 if (function_min_args_p)
|
|
4106 break;
|
|
4107 }
|
|
4108 else if (EQ (arg, Qand_rest))
|
|
4109 {
|
|
4110 if (function_min_args_p)
|
|
4111 break;
|
|
4112 else
|
|
4113 return Qnil;
|
|
4114 }
|
|
4115 else
|
|
4116 {
|
|
4117 argcount++;
|
|
4118 }
|
|
4119 }
|
|
4120
|
|
4121 return make_int (argcount);
|
|
4122 }
|
|
4123 }
|
|
4124
|
|
4125 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /*
|
617
|
4126 Return the minimum 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.
|
853
|
4129
|
|
4130 To check if a function can be called with a specified number of
|
|
4131 arguments, use `function-allows-args'.
|
428
|
4132 */
|
|
4133 (function))
|
|
4134 {
|
|
4135 return function_argcount (function, 1);
|
|
4136 }
|
|
4137
|
|
4138 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /*
|
617
|
4139 Return the maximum number of arguments a function may be called with.
|
428
|
4140 The function may be any form that can be passed to `funcall',
|
|
4141 any special form, or any macro.
|
|
4142 If the function takes an arbitrary number of arguments or is
|
|
4143 a built-in special form, nil is returned.
|
853
|
4144
|
|
4145 To check if a function can be called with a specified number of
|
|
4146 arguments, use `function-allows-args'.
|
428
|
4147 */
|
|
4148 (function))
|
|
4149 {
|
|
4150 return function_argcount (function, 0);
|
|
4151 }
|
|
4152
|
|
4153
|
|
4154 DEFUN ("apply", Fapply, 2, MANY, 0, /*
|
|
4155 Call FUNCTION with the remaining args, using the last arg as a list of args.
|
|
4156 Thus, (apply '+ 1 2 '(3 4)) returns 10.
|
|
4157 */
|
|
4158 (int nargs, Lisp_Object *args))
|
|
4159 {
|
|
4160 /* This function can GC */
|
|
4161 Lisp_Object fun = args[0];
|
|
4162 Lisp_Object spread_arg = args [nargs - 1];
|
|
4163 int numargs;
|
|
4164 int funcall_nargs;
|
|
4165
|
|
4166 GET_EXTERNAL_LIST_LENGTH (spread_arg, numargs);
|
|
4167
|
|
4168 if (numargs == 0)
|
|
4169 /* (apply foo 0 1 '()) */
|
|
4170 return Ffuncall (nargs - 1, args);
|
|
4171 else if (numargs == 1)
|
|
4172 {
|
|
4173 /* (apply foo 0 1 '(2)) */
|
|
4174 args [nargs - 1] = XCAR (spread_arg);
|
|
4175 return Ffuncall (nargs, args);
|
|
4176 }
|
|
4177
|
|
4178 /* -1 for function, -1 for spread arg */
|
|
4179 numargs = nargs - 2 + numargs;
|
|
4180 /* +1 for function */
|
|
4181 funcall_nargs = 1 + numargs;
|
|
4182
|
|
4183 if (SYMBOLP (fun))
|
|
4184 fun = indirect_function (fun, 0);
|
|
4185
|
|
4186 if (SUBRP (fun))
|
|
4187 {
|
|
4188 Lisp_Subr *subr = XSUBR (fun);
|
|
4189 int max_args = subr->max_args;
|
|
4190
|
|
4191 if (numargs < subr->min_args
|
|
4192 || (max_args >= 0 && max_args < numargs))
|
|
4193 {
|
|
4194 /* Let funcall get the error */
|
|
4195 }
|
|
4196 else if (max_args > numargs)
|
|
4197 {
|
|
4198 /* Avoid having funcall cons up yet another new vector of arguments
|
|
4199 by explicitly supplying nil's for optional values */
|
|
4200 funcall_nargs += (max_args - numargs);
|
|
4201 }
|
|
4202 }
|
|
4203 else if (UNBOUNDP (fun))
|
|
4204 {
|
|
4205 /* Let funcall get the error */
|
|
4206 fun = args[0];
|
|
4207 }
|
|
4208
|
|
4209 {
|
|
4210 REGISTER int i;
|
|
4211 Lisp_Object *funcall_args = alloca_array (Lisp_Object, funcall_nargs);
|
|
4212 struct gcpro gcpro1;
|
|
4213
|
|
4214 GCPRO1 (*funcall_args);
|
|
4215 gcpro1.nvars = funcall_nargs;
|
|
4216
|
|
4217 /* Copy in the unspread args */
|
|
4218 memcpy (funcall_args, args, (nargs - 1) * sizeof (Lisp_Object));
|
|
4219 /* Spread the last arg we got. Its first element goes in
|
|
4220 the slot that it used to occupy, hence this value of I. */
|
|
4221 for (i = nargs - 1;
|
|
4222 !NILP (spread_arg); /* i < 1 + numargs */
|
|
4223 i++, spread_arg = XCDR (spread_arg))
|
|
4224 {
|
|
4225 funcall_args [i] = XCAR (spread_arg);
|
|
4226 }
|
|
4227 /* Supply nil for optional args (to subrs) */
|
|
4228 for (; i < funcall_nargs; i++)
|
|
4229 funcall_args[i] = Qnil;
|
|
4230
|
|
4231
|
|
4232 RETURN_UNGCPRO (Ffuncall (funcall_nargs, funcall_args));
|
|
4233 }
|
|
4234 }
|
|
4235
|
|
4236
|
|
4237 /* Apply lambda list FUN to the NARGS evaluated arguments in ARGS and
|
|
4238 return the result of evaluation. */
|
|
4239
|
|
4240 static Lisp_Object
|
|
4241 funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object args[])
|
|
4242 {
|
|
4243 /* This function can GC */
|
442
|
4244 Lisp_Object arglist, body, tail;
|
428
|
4245 int speccount = specpdl_depth();
|
|
4246 REGISTER int i = 0;
|
|
4247
|
|
4248 tail = XCDR (fun);
|
|
4249
|
|
4250 if (!CONSP (tail))
|
|
4251 goto invalid_function;
|
|
4252
|
|
4253 arglist = XCAR (tail);
|
|
4254 body = XCDR (tail);
|
|
4255
|
|
4256 {
|
|
4257 int optional = 0, rest = 0;
|
|
4258
|
442
|
4259 EXTERNAL_LIST_LOOP_2 (symbol, arglist)
|
428
|
4260 {
|
|
4261 if (!SYMBOLP (symbol))
|
|
4262 goto invalid_function;
|
|
4263 if (EQ (symbol, Qand_rest))
|
|
4264 rest = 1;
|
|
4265 else if (EQ (symbol, Qand_optional))
|
|
4266 optional = 1;
|
|
4267 else if (rest)
|
|
4268 {
|
|
4269 specbind (symbol, Flist (nargs - i, &args[i]));
|
|
4270 i = nargs;
|
|
4271 }
|
|
4272 else if (i < nargs)
|
|
4273 specbind (symbol, args[i++]);
|
|
4274 else if (!optional)
|
|
4275 goto wrong_number_of_arguments;
|
|
4276 else
|
|
4277 specbind (symbol, Qnil);
|
|
4278 }
|
|
4279 }
|
|
4280
|
|
4281 if (i < nargs)
|
|
4282 goto wrong_number_of_arguments;
|
|
4283
|
771
|
4284 return unbind_to_1 (speccount, Fprogn (body));
|
428
|
4285
|
|
4286 wrong_number_of_arguments:
|
436
|
4287 return signal_wrong_number_of_arguments_error (fun, nargs);
|
428
|
4288
|
|
4289 invalid_function:
|
436
|
4290 return signal_invalid_function_error (fun);
|
428
|
4291 }
|
|
4292
|
|
4293
|
|
4294 /************************************************************************/
|
|
4295 /* Run hook variables in various ways. */
|
|
4296 /************************************************************************/
|
|
4297
|
|
4298 DEFUN ("run-hooks", Frun_hooks, 1, MANY, 0, /*
|
|
4299 Run each hook in HOOKS. Major mode functions use this.
|
|
4300 Each argument should be a symbol, a hook variable.
|
|
4301 These symbols are processed in the order specified.
|
|
4302 If a hook symbol has a non-nil value, that value may be a function
|
|
4303 or a list of functions to be called to run the hook.
|
|
4304 If the value is a function, it is called with no arguments.
|
|
4305 If it is a list, the elements are called, in order, with no arguments.
|
|
4306
|
|
4307 To make a hook variable buffer-local, use `make-local-hook',
|
|
4308 not `make-local-variable'.
|
|
4309 */
|
|
4310 (int nargs, Lisp_Object *args))
|
|
4311 {
|
|
4312 REGISTER int i;
|
|
4313
|
|
4314 for (i = 0; i < nargs; i++)
|
|
4315 run_hook_with_args (1, args + i, RUN_HOOKS_TO_COMPLETION);
|
|
4316
|
|
4317 return Qnil;
|
|
4318 }
|
|
4319
|
|
4320 DEFUN ("run-hook-with-args", Frun_hook_with_args, 1, MANY, 0, /*
|
|
4321 Run HOOK with the specified arguments ARGS.
|
|
4322 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
|
|
4323 value, that value may be a function or a list of functions to be
|
|
4324 called to run the hook. If the value is a function, it is called with
|
|
4325 the given arguments and its return value is returned. If it is a list
|
|
4326 of functions, those functions are called, in order,
|
|
4327 with the given arguments ARGS.
|
444
|
4328 It is best not to depend on the value returned by `run-hook-with-args',
|
428
|
4329 as that may change.
|
|
4330
|
|
4331 To make a hook variable buffer-local, use `make-local-hook',
|
|
4332 not `make-local-variable'.
|
|
4333 */
|
|
4334 (int nargs, Lisp_Object *args))
|
|
4335 {
|
|
4336 return run_hook_with_args (nargs, args, RUN_HOOKS_TO_COMPLETION);
|
|
4337 }
|
|
4338
|
|
4339 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, 1, MANY, 0, /*
|
|
4340 Run HOOK with the specified arguments ARGS.
|
|
4341 HOOK should be a symbol, a hook variable. Its value should
|
|
4342 be a list of functions. We call those functions, one by one,
|
|
4343 passing arguments ARGS to each of them, until one of them
|
|
4344 returns a non-nil value. Then we return that value.
|
|
4345 If all the functions return nil, we return nil.
|
|
4346
|
|
4347 To make a hook variable buffer-local, use `make-local-hook',
|
|
4348 not `make-local-variable'.
|
|
4349 */
|
|
4350 (int nargs, Lisp_Object *args))
|
|
4351 {
|
|
4352 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_SUCCESS);
|
|
4353 }
|
|
4354
|
|
4355 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, 1, MANY, 0, /*
|
|
4356 Run HOOK with the specified arguments ARGS.
|
|
4357 HOOK should be a symbol, a hook variable. Its value should
|
|
4358 be a list of functions. We call those functions, one by one,
|
|
4359 passing arguments ARGS to each of them, until one of them
|
|
4360 returns nil. Then we return nil.
|
|
4361 If all the functions return non-nil, we return non-nil.
|
|
4362
|
|
4363 To make a hook variable buffer-local, use `make-local-hook',
|
|
4364 not `make-local-variable'.
|
|
4365 */
|
|
4366 (int nargs, Lisp_Object *args))
|
|
4367 {
|
|
4368 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_FAILURE);
|
|
4369 }
|
|
4370
|
|
4371 /* ARGS[0] should be a hook symbol.
|
|
4372 Call each of the functions in the hook value, passing each of them
|
|
4373 as arguments all the rest of ARGS (all NARGS - 1 elements).
|
|
4374 COND specifies a condition to test after each call
|
|
4375 to decide whether to stop.
|
|
4376 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
4377 except that it isn't necessary to gcpro ARGS[0]. */
|
|
4378
|
|
4379 Lisp_Object
|
|
4380 run_hook_with_args_in_buffer (struct buffer *buf, int nargs, Lisp_Object *args,
|
|
4381 enum run_hooks_condition cond)
|
|
4382 {
|
|
4383 Lisp_Object sym, val, ret;
|
|
4384
|
|
4385 if (!initialized || preparing_for_armageddon)
|
|
4386 /* We need to bail out of here pronto. */
|
|
4387 return Qnil;
|
|
4388
|
3092
|
4389 #ifndef NEW_GC
|
428
|
4390 /* Whenever gc_in_progress is true, preparing_for_armageddon
|
|
4391 will also be true unless something is really hosed. */
|
|
4392 assert (!gc_in_progress);
|
3092
|
4393 #endif /* not NEW_GC */
|
428
|
4394
|
|
4395 sym = args[0];
|
771
|
4396 val = symbol_value_in_buffer (sym, wrap_buffer (buf));
|
428
|
4397 ret = (cond == RUN_HOOKS_UNTIL_FAILURE ? Qt : Qnil);
|
|
4398
|
|
4399 if (UNBOUNDP (val) || NILP (val))
|
|
4400 return ret;
|
|
4401 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
|
|
4402 {
|
|
4403 args[0] = val;
|
|
4404 return Ffuncall (nargs, args);
|
|
4405 }
|
|
4406 else
|
|
4407 {
|
|
4408 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
4409 Lisp_Object globals = Qnil;
|
|
4410 GCPRO3 (sym, val, globals);
|
|
4411
|
|
4412 for (;
|
|
4413 CONSP (val) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
4414 || (cond == RUN_HOOKS_UNTIL_SUCCESS ? NILP (ret)
|
|
4415 : !NILP (ret)));
|
|
4416 val = XCDR (val))
|
|
4417 {
|
|
4418 if (EQ (XCAR (val), Qt))
|
|
4419 {
|
|
4420 /* t indicates this hook has a local binding;
|
|
4421 it means to run the global binding too. */
|
|
4422 globals = Fdefault_value (sym);
|
|
4423
|
|
4424 if ((! CONSP (globals) || EQ (XCAR (globals), Qlambda)) &&
|
|
4425 ! NILP (globals))
|
|
4426 {
|
|
4427 args[0] = globals;
|
|
4428 ret = Ffuncall (nargs, args);
|
|
4429 }
|
|
4430 else
|
|
4431 {
|
|
4432 for (;
|
|
4433 CONSP (globals) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
4434 || (cond == RUN_HOOKS_UNTIL_SUCCESS
|
|
4435 ? NILP (ret)
|
|
4436 : !NILP (ret)));
|
|
4437 globals = XCDR (globals))
|
|
4438 {
|
|
4439 args[0] = XCAR (globals);
|
|
4440 /* In a global value, t should not occur. If it does, we
|
|
4441 must ignore it to avoid an endless loop. */
|
|
4442 if (!EQ (args[0], Qt))
|
|
4443 ret = Ffuncall (nargs, args);
|
|
4444 }
|
|
4445 }
|
|
4446 }
|
|
4447 else
|
|
4448 {
|
|
4449 args[0] = XCAR (val);
|
|
4450 ret = Ffuncall (nargs, args);
|
|
4451 }
|
|
4452 }
|
|
4453
|
|
4454 UNGCPRO;
|
|
4455 return ret;
|
|
4456 }
|
|
4457 }
|
|
4458
|
|
4459 Lisp_Object
|
|
4460 run_hook_with_args (int nargs, Lisp_Object *args,
|
|
4461 enum run_hooks_condition cond)
|
|
4462 {
|
|
4463 return run_hook_with_args_in_buffer (current_buffer, nargs, args, cond);
|
|
4464 }
|
|
4465
|
|
4466 #if 0
|
|
4467
|
853
|
4468 /* From FSF 19.30, not currently used; seems like a big kludge. */
|
428
|
4469
|
|
4470 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
|
|
4471 present value of that symbol.
|
|
4472 Call each element of FUNLIST,
|
|
4473 passing each of them the rest of ARGS.
|
|
4474 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
4475 except that it isn't necessary to gcpro ARGS[0]. */
|
|
4476
|
|
4477 Lisp_Object
|
|
4478 run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args)
|
|
4479 {
|
853
|
4480 omitted;
|
428
|
4481 }
|
|
4482
|
|
4483 #endif /* 0 */
|
|
4484
|
|
4485 void
|
|
4486 va_run_hook_with_args (Lisp_Object hook_var, int nargs, ...)
|
|
4487 {
|
|
4488 /* This function can GC */
|
|
4489 struct gcpro gcpro1;
|
|
4490 int i;
|
|
4491 va_list vargs;
|
|
4492 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
|
4493
|
|
4494 va_start (vargs, nargs);
|
|
4495 funcall_args[0] = hook_var;
|
|
4496 for (i = 0; i < nargs; i++)
|
|
4497 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
4498 va_end (vargs);
|
|
4499
|
|
4500 GCPRO1 (*funcall_args);
|
|
4501 gcpro1.nvars = nargs + 1;
|
|
4502 run_hook_with_args (nargs + 1, funcall_args, RUN_HOOKS_TO_COMPLETION);
|
|
4503 UNGCPRO;
|
|
4504 }
|
|
4505
|
|
4506 void
|
|
4507 va_run_hook_with_args_in_buffer (struct buffer *buf, Lisp_Object hook_var,
|
|
4508 int nargs, ...)
|
|
4509 {
|
|
4510 /* This function can GC */
|
|
4511 struct gcpro gcpro1;
|
|
4512 int i;
|
|
4513 va_list vargs;
|
|
4514 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
|
4515
|
|
4516 va_start (vargs, nargs);
|
|
4517 funcall_args[0] = hook_var;
|
|
4518 for (i = 0; i < nargs; i++)
|
|
4519 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
4520 va_end (vargs);
|
|
4521
|
|
4522 GCPRO1 (*funcall_args);
|
|
4523 gcpro1.nvars = nargs + 1;
|
|
4524 run_hook_with_args_in_buffer (buf, nargs + 1, funcall_args,
|
|
4525 RUN_HOOKS_TO_COMPLETION);
|
|
4526 UNGCPRO;
|
|
4527 }
|
|
4528
|
|
4529 Lisp_Object
|
|
4530 run_hook (Lisp_Object hook)
|
|
4531 {
|
853
|
4532 return run_hook_with_args (1, &hook, RUN_HOOKS_TO_COMPLETION);
|
428
|
4533 }
|
|
4534
|
|
4535
|
|
4536 /************************************************************************/
|
|
4537 /* Front-ends to eval, funcall, apply */
|
|
4538 /************************************************************************/
|
|
4539
|
|
4540 /* Apply fn to arg */
|
|
4541 Lisp_Object
|
|
4542 apply1 (Lisp_Object fn, Lisp_Object arg)
|
|
4543 {
|
|
4544 /* This function can GC */
|
|
4545 struct gcpro gcpro1;
|
|
4546 Lisp_Object args[2];
|
|
4547
|
|
4548 if (NILP (arg))
|
|
4549 return Ffuncall (1, &fn);
|
|
4550 GCPRO1 (args[0]);
|
|
4551 gcpro1.nvars = 2;
|
|
4552 args[0] = fn;
|
|
4553 args[1] = arg;
|
|
4554 RETURN_UNGCPRO (Fapply (2, args));
|
|
4555 }
|
|
4556
|
|
4557 /* Call function fn on no arguments */
|
|
4558 Lisp_Object
|
|
4559 call0 (Lisp_Object fn)
|
|
4560 {
|
|
4561 /* This function can GC */
|
|
4562 struct gcpro gcpro1;
|
|
4563
|
|
4564 GCPRO1 (fn);
|
|
4565 RETURN_UNGCPRO (Ffuncall (1, &fn));
|
|
4566 }
|
|
4567
|
|
4568 /* Call function fn with argument arg0 */
|
|
4569 Lisp_Object
|
|
4570 call1 (Lisp_Object fn,
|
|
4571 Lisp_Object arg0)
|
|
4572 {
|
|
4573 /* This function can GC */
|
|
4574 struct gcpro gcpro1;
|
|
4575 Lisp_Object args[2];
|
|
4576 args[0] = fn;
|
|
4577 args[1] = arg0;
|
|
4578 GCPRO1 (args[0]);
|
|
4579 gcpro1.nvars = 2;
|
|
4580 RETURN_UNGCPRO (Ffuncall (2, args));
|
|
4581 }
|
|
4582
|
|
4583 /* Call function fn with arguments arg0, arg1 */
|
|
4584 Lisp_Object
|
|
4585 call2 (Lisp_Object fn,
|
|
4586 Lisp_Object arg0, Lisp_Object arg1)
|
|
4587 {
|
|
4588 /* This function can GC */
|
|
4589 struct gcpro gcpro1;
|
|
4590 Lisp_Object args[3];
|
|
4591 args[0] = fn;
|
|
4592 args[1] = arg0;
|
|
4593 args[2] = arg1;
|
|
4594 GCPRO1 (args[0]);
|
|
4595 gcpro1.nvars = 3;
|
|
4596 RETURN_UNGCPRO (Ffuncall (3, args));
|
|
4597 }
|
|
4598
|
|
4599 /* Call function fn with arguments arg0, arg1, arg2 */
|
|
4600 Lisp_Object
|
|
4601 call3 (Lisp_Object fn,
|
|
4602 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4603 {
|
|
4604 /* This function can GC */
|
|
4605 struct gcpro gcpro1;
|
|
4606 Lisp_Object args[4];
|
|
4607 args[0] = fn;
|
|
4608 args[1] = arg0;
|
|
4609 args[2] = arg1;
|
|
4610 args[3] = arg2;
|
|
4611 GCPRO1 (args[0]);
|
|
4612 gcpro1.nvars = 4;
|
|
4613 RETURN_UNGCPRO (Ffuncall (4, args));
|
|
4614 }
|
|
4615
|
|
4616 /* Call function fn with arguments arg0, arg1, arg2, arg3 */
|
|
4617 Lisp_Object
|
|
4618 call4 (Lisp_Object fn,
|
|
4619 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4620 Lisp_Object arg3)
|
|
4621 {
|
|
4622 /* This function can GC */
|
|
4623 struct gcpro gcpro1;
|
|
4624 Lisp_Object args[5];
|
|
4625 args[0] = fn;
|
|
4626 args[1] = arg0;
|
|
4627 args[2] = arg1;
|
|
4628 args[3] = arg2;
|
|
4629 args[4] = arg3;
|
|
4630 GCPRO1 (args[0]);
|
|
4631 gcpro1.nvars = 5;
|
|
4632 RETURN_UNGCPRO (Ffuncall (5, args));
|
|
4633 }
|
|
4634
|
|
4635 /* Call function fn with arguments arg0, arg1, arg2, arg3, arg4 */
|
|
4636 Lisp_Object
|
|
4637 call5 (Lisp_Object fn,
|
|
4638 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4639 Lisp_Object arg3, Lisp_Object arg4)
|
|
4640 {
|
|
4641 /* This function can GC */
|
|
4642 struct gcpro gcpro1;
|
|
4643 Lisp_Object args[6];
|
|
4644 args[0] = fn;
|
|
4645 args[1] = arg0;
|
|
4646 args[2] = arg1;
|
|
4647 args[3] = arg2;
|
|
4648 args[4] = arg3;
|
|
4649 args[5] = arg4;
|
|
4650 GCPRO1 (args[0]);
|
|
4651 gcpro1.nvars = 6;
|
|
4652 RETURN_UNGCPRO (Ffuncall (6, args));
|
|
4653 }
|
|
4654
|
|
4655 Lisp_Object
|
|
4656 call6 (Lisp_Object fn,
|
|
4657 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4658 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
4659 {
|
|
4660 /* This function can GC */
|
|
4661 struct gcpro gcpro1;
|
|
4662 Lisp_Object args[7];
|
|
4663 args[0] = fn;
|
|
4664 args[1] = arg0;
|
|
4665 args[2] = arg1;
|
|
4666 args[3] = arg2;
|
|
4667 args[4] = arg3;
|
|
4668 args[5] = arg4;
|
|
4669 args[6] = arg5;
|
|
4670 GCPRO1 (args[0]);
|
|
4671 gcpro1.nvars = 7;
|
|
4672 RETURN_UNGCPRO (Ffuncall (7, args));
|
|
4673 }
|
|
4674
|
|
4675 Lisp_Object
|
|
4676 call7 (Lisp_Object fn,
|
|
4677 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4678 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4679 Lisp_Object arg6)
|
|
4680 {
|
|
4681 /* This function can GC */
|
|
4682 struct gcpro gcpro1;
|
|
4683 Lisp_Object args[8];
|
|
4684 args[0] = fn;
|
|
4685 args[1] = arg0;
|
|
4686 args[2] = arg1;
|
|
4687 args[3] = arg2;
|
|
4688 args[4] = arg3;
|
|
4689 args[5] = arg4;
|
|
4690 args[6] = arg5;
|
|
4691 args[7] = arg6;
|
|
4692 GCPRO1 (args[0]);
|
|
4693 gcpro1.nvars = 8;
|
|
4694 RETURN_UNGCPRO (Ffuncall (8, args));
|
|
4695 }
|
|
4696
|
|
4697 Lisp_Object
|
|
4698 call8 (Lisp_Object fn,
|
|
4699 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4700 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4701 Lisp_Object arg6, Lisp_Object arg7)
|
|
4702 {
|
|
4703 /* This function can GC */
|
|
4704 struct gcpro gcpro1;
|
|
4705 Lisp_Object args[9];
|
|
4706 args[0] = fn;
|
|
4707 args[1] = arg0;
|
|
4708 args[2] = arg1;
|
|
4709 args[3] = arg2;
|
|
4710 args[4] = arg3;
|
|
4711 args[5] = arg4;
|
|
4712 args[6] = arg5;
|
|
4713 args[7] = arg6;
|
|
4714 args[8] = arg7;
|
|
4715 GCPRO1 (args[0]);
|
|
4716 gcpro1.nvars = 9;
|
|
4717 RETURN_UNGCPRO (Ffuncall (9, args));
|
|
4718 }
|
|
4719
|
|
4720 Lisp_Object
|
|
4721 call0_in_buffer (struct buffer *buf, Lisp_Object fn)
|
|
4722 {
|
|
4723 if (current_buffer == buf)
|
|
4724 return call0 (fn);
|
|
4725 else
|
|
4726 {
|
|
4727 Lisp_Object val;
|
|
4728 int speccount = specpdl_depth();
|
|
4729 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4730 set_buffer_internal (buf);
|
|
4731 val = call0 (fn);
|
771
|
4732 unbind_to (speccount);
|
428
|
4733 return val;
|
|
4734 }
|
|
4735 }
|
|
4736
|
|
4737 Lisp_Object
|
|
4738 call1_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4739 Lisp_Object arg0)
|
|
4740 {
|
|
4741 if (current_buffer == buf)
|
|
4742 return call1 (fn, arg0);
|
|
4743 else
|
|
4744 {
|
|
4745 Lisp_Object val;
|
|
4746 int speccount = specpdl_depth();
|
|
4747 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4748 set_buffer_internal (buf);
|
|
4749 val = call1 (fn, arg0);
|
771
|
4750 unbind_to (speccount);
|
428
|
4751 return val;
|
|
4752 }
|
|
4753 }
|
|
4754
|
|
4755 Lisp_Object
|
|
4756 call2_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4757 Lisp_Object arg0, Lisp_Object arg1)
|
|
4758 {
|
|
4759 if (current_buffer == buf)
|
|
4760 return call2 (fn, arg0, arg1);
|
|
4761 else
|
|
4762 {
|
|
4763 Lisp_Object val;
|
|
4764 int speccount = specpdl_depth();
|
|
4765 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4766 set_buffer_internal (buf);
|
|
4767 val = call2 (fn, arg0, arg1);
|
771
|
4768 unbind_to (speccount);
|
428
|
4769 return val;
|
|
4770 }
|
|
4771 }
|
|
4772
|
|
4773 Lisp_Object
|
|
4774 call3_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4775 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4776 {
|
|
4777 if (current_buffer == buf)
|
|
4778 return call3 (fn, arg0, arg1, arg2);
|
|
4779 else
|
|
4780 {
|
|
4781 Lisp_Object val;
|
|
4782 int speccount = specpdl_depth();
|
|
4783 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4784 set_buffer_internal (buf);
|
|
4785 val = call3 (fn, arg0, arg1, arg2);
|
771
|
4786 unbind_to (speccount);
|
428
|
4787 return val;
|
|
4788 }
|
|
4789 }
|
|
4790
|
|
4791 Lisp_Object
|
|
4792 call4_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4793 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4794 Lisp_Object arg3)
|
|
4795 {
|
|
4796 if (current_buffer == buf)
|
|
4797 return call4 (fn, arg0, arg1, arg2, arg3);
|
|
4798 else
|
|
4799 {
|
|
4800 Lisp_Object val;
|
|
4801 int speccount = specpdl_depth();
|
|
4802 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4803 set_buffer_internal (buf);
|
|
4804 val = call4 (fn, arg0, arg1, arg2, arg3);
|
771
|
4805 unbind_to (speccount);
|
428
|
4806 return val;
|
|
4807 }
|
|
4808 }
|
|
4809
|
|
4810 Lisp_Object
|
|
4811 eval_in_buffer (struct buffer *buf, Lisp_Object form)
|
|
4812 {
|
|
4813 if (current_buffer == buf)
|
|
4814 return Feval (form);
|
|
4815 else
|
|
4816 {
|
|
4817 Lisp_Object val;
|
|
4818 int speccount = specpdl_depth();
|
|
4819 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4820 set_buffer_internal (buf);
|
|
4821 val = Feval (form);
|
771
|
4822 unbind_to (speccount);
|
428
|
4823 return val;
|
|
4824 }
|
|
4825 }
|
|
4826
|
|
4827
|
|
4828 /************************************************************************/
|
|
4829 /* Error-catching front-ends to eval, funcall, apply */
|
|
4830 /************************************************************************/
|
|
4831
|
853
|
4832 int
|
|
4833 get_inhibit_flags (void)
|
|
4834 {
|
|
4835 return inhibit_flags;
|
|
4836 }
|
|
4837
|
|
4838 void
|
2286
|
4839 check_allowed_operation (int what, Lisp_Object obj, Lisp_Object UNUSED (prop))
|
853
|
4840 {
|
|
4841 if (inhibit_flags & INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION)
|
|
4842 {
|
|
4843 if (what == OPERATION_MODIFY_BUFFER_TEXT && BUFFERP (obj)
|
|
4844 && NILP (memq_no_quit (obj, Vmodifiable_buffers)))
|
|
4845 invalid_change
|
|
4846 ("Modification of this buffer not currently permitted", obj);
|
|
4847 }
|
|
4848 if (inhibit_flags & INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION)
|
|
4849 {
|
|
4850 if (what == OPERATION_DELETE_OBJECT
|
|
4851 && (BUFFERP (obj) || WINDOWP (obj) || FRAMEP (obj) || DEVICEP (obj)
|
|
4852 || CONSOLEP (obj))
|
|
4853 && NILP (memq_no_quit (obj, Vdeletable_permanent_display_objects)))
|
|
4854 invalid_change
|
|
4855 ("Deletion of this object not currently permitted", obj);
|
|
4856 }
|
|
4857 }
|
|
4858
|
|
4859 void
|
|
4860 note_object_created (Lisp_Object obj)
|
|
4861 {
|
|
4862 if (inhibit_flags & INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION)
|
|
4863 {
|
|
4864 if (BUFFERP (obj))
|
|
4865 Vmodifiable_buffers = Fcons (obj, Vmodifiable_buffers);
|
|
4866 }
|
|
4867 if (inhibit_flags & INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION)
|
|
4868 {
|
|
4869 if (BUFFERP (obj) || WINDOWP (obj) || FRAMEP (obj) || DEVICEP (obj)
|
|
4870 || CONSOLEP (obj))
|
|
4871 Vdeletable_permanent_display_objects =
|
|
4872 Fcons (obj, Vdeletable_permanent_display_objects);
|
|
4873 }
|
|
4874 }
|
|
4875
|
|
4876 void
|
|
4877 note_object_deleted (Lisp_Object obj)
|
|
4878 {
|
|
4879 if (inhibit_flags & INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION)
|
|
4880 {
|
|
4881 if (BUFFERP (obj))
|
|
4882 Vmodifiable_buffers = delq_no_quit (obj, Vmodifiable_buffers);
|
|
4883 }
|
|
4884 if (inhibit_flags & INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION)
|
|
4885 {
|
|
4886 if (BUFFERP (obj) || WINDOWP (obj) || FRAMEP (obj) || DEVICEP (obj)
|
|
4887 || CONSOLEP (obj))
|
|
4888 Vdeletable_permanent_display_objects =
|
|
4889 delq_no_quit (obj, Vdeletable_permanent_display_objects);
|
|
4890 }
|
|
4891 }
|
|
4892
|
|
4893 struct call_trapping_problems
|
|
4894 {
|
|
4895 Lisp_Object catchtag;
|
|
4896 Lisp_Object error_conditions;
|
|
4897 Lisp_Object data;
|
|
4898 Lisp_Object backtrace;
|
|
4899 Lisp_Object warning_class;
|
|
4900
|
867
|
4901 const CIbyte *warning_string;
|
853
|
4902 Lisp_Object (*fun) (void *);
|
|
4903 void *arg;
|
|
4904 };
|
428
|
4905
|
2532
|
4906 static Lisp_Object
|
|
4907 maybe_get_trapping_problems_backtrace (void)
|
|
4908 {
|
|
4909 Lisp_Object backtrace;
|
853
|
4910
|
1123
|
4911 if (!(inhibit_flags & INHIBIT_WARNING_ISSUE)
|
2532
|
4912 && !warning_will_be_discarded (current_warning_level ()))
|
428
|
4913 {
|
1333
|
4914 struct gcpro gcpro1;
|
|
4915 Lisp_Object lstream = Qnil;
|
|
4916 int speccount = specpdl_depth ();
|
|
4917
|
853
|
4918 /* We're no longer protected against errors or quit here, so at
|
|
4919 least let's temporarily inhibit quit. We definitely do not
|
|
4920 want to inhibit quit during the calling of the function
|
|
4921 itself!!!!!!!!!!! */
|
|
4922
|
|
4923 specbind (Qinhibit_quit, Qt);
|
|
4924
|
|
4925 GCPRO1 (lstream);
|
|
4926 lstream = make_resizing_buffer_output_stream ();
|
|
4927 Fbacktrace (lstream, Qt);
|
|
4928 Lstream_flush (XLSTREAM (lstream));
|
2532
|
4929 backtrace = resizing_buffer_to_lisp_string (XLSTREAM (lstream));
|
853
|
4930 Lstream_delete (XLSTREAM (lstream));
|
|
4931 UNGCPRO;
|
|
4932
|
|
4933 unbind_to (speccount);
|
428
|
4934 }
|
853
|
4935 else
|
2532
|
4936 backtrace = Qnil;
|
|
4937
|
|
4938 return backtrace;
|
|
4939 }
|
|
4940
|
|
4941 static DECLARE_DOESNT_RETURN_TYPE
|
|
4942 (Lisp_Object, flagged_a_squirmer (Lisp_Object, Lisp_Object, Lisp_Object));
|
|
4943
|
|
4944 static DOESNT_RETURN_TYPE (Lisp_Object)
|
|
4945 flagged_a_squirmer (Lisp_Object error_conditions, Lisp_Object data,
|
|
4946 Lisp_Object opaque)
|
|
4947 {
|
|
4948 struct call_trapping_problems *p =
|
|
4949 (struct call_trapping_problems *) get_opaque_ptr (opaque);
|
|
4950
|
|
4951 if (!EQ (error_conditions, Qquit))
|
|
4952 p->backtrace = maybe_get_trapping_problems_backtrace ();
|
|
4953 else
|
853
|
4954 p->backtrace = Qnil;
|
|
4955 p->error_conditions = error_conditions;
|
|
4956 p->data = data;
|
|
4957
|
|
4958 Fthrow (p->catchtag, Qnil);
|
2268
|
4959 RETURN_NOT_REACHED (Qnil);
|
853
|
4960 }
|
|
4961
|
|
4962 static Lisp_Object
|
|
4963 call_trapping_problems_2 (Lisp_Object opaque)
|
|
4964 {
|
|
4965 struct call_trapping_problems *p =
|
|
4966 (struct call_trapping_problems *) get_opaque_ptr (opaque);
|
|
4967
|
|
4968 return (p->fun) (p->arg);
|
428
|
4969 }
|
|
4970
|
|
4971 static Lisp_Object
|
853
|
4972 call_trapping_problems_1 (Lisp_Object opaque)
|
|
4973 {
|
|
4974 return call_with_condition_handler (flagged_a_squirmer, opaque,
|
|
4975 call_trapping_problems_2, opaque);
|
|
4976 }
|
|
4977
|
1333
|
4978 static void
|
|
4979 issue_call_trapping_problems_warning (Lisp_Object warning_class,
|
|
4980 const CIbyte *warning_string,
|
|
4981 struct call_trapping_problems_result *p)
|
|
4982 {
|
|
4983 if (!warning_will_be_discarded (current_warning_level ()))
|
|
4984 {
|
|
4985 int depth = specpdl_depth ();
|
|
4986
|
|
4987 /* We're no longer protected against errors or quit here, so at
|
|
4988 least let's temporarily inhibit quit. */
|
|
4989 specbind (Qinhibit_quit, Qt);
|
|
4990
|
|
4991 if (p->caught_throw)
|
|
4992 {
|
|
4993 Lisp_Object errstr =
|
|
4994 emacs_sprintf_string_lisp
|
2532
|
4995 ("%s: Attempt to throw outside of function:"
|
|
4996 "To catch `%s' with value `%s'\n\nBacktrace follows:\n\n%s",
|
2725
|
4997 Qnil, 4,
|
1333
|
4998 build_msg_string (warning_string ? warning_string : "error"),
|
2532
|
4999 p->thrown_tag, p->thrown_value, p->backtrace);
|
1333
|
5000 warn_when_safe_lispobj (Qerror, current_warning_level (), errstr);
|
|
5001 }
|
2421
|
5002 else if (p->caught_error && !EQ (p->error_conditions, Qquit))
|
1333
|
5003 {
|
|
5004 Lisp_Object errstr;
|
|
5005 /* #### This should call
|
|
5006 (with-output-to-string (display-error (cons error_conditions
|
|
5007 data))
|
|
5008 but that stuff is all in Lisp currently. */
|
|
5009 errstr =
|
|
5010 emacs_sprintf_string_lisp
|
|
5011 ("%s: (%s %s)\n\nBacktrace follows:\n\n%s",
|
|
5012 Qnil, 4,
|
|
5013 build_msg_string (warning_string ? warning_string : "error"),
|
|
5014 p->error_conditions, p->data, p->backtrace);
|
|
5015
|
|
5016 warn_when_safe_lispobj (warning_class, current_warning_level (),
|
|
5017 errstr);
|
|
5018 }
|
|
5019
|
|
5020 unbind_to (depth);
|
|
5021 }
|
|
5022 }
|
|
5023
|
1318
|
5024 /* Turn on the trapping flags in FLAGS -- see call_trapping_problems().
|
|
5025 This cannot handle INTERNAL_INHIBIT_THROWS() or INTERNAL_INHIBIT_ERRORS
|
|
5026 (because they ultimately boil down to a setjmp()!) -- you must directly
|
|
5027 use call_trapping_problems() for that. Turn the flags off with
|
|
5028 unbind_to(). Returns the "canonicalized" flags (particularly in the
|
|
5029 case of INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY, which is shorthand for
|
|
5030 various other flags). */
|
|
5031
|
|
5032 int
|
|
5033 set_trapping_problems_flags (int flags)
|
|
5034 {
|
|
5035 int new_inhibit_flags;
|
|
5036
|
|
5037 if (flags & INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY)
|
|
5038 flags |= INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION
|
|
5039 | INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION
|
|
5040 | INHIBIT_ENTERING_DEBUGGER
|
|
5041 | INHIBIT_WARNING_ISSUE
|
|
5042 | INHIBIT_GC;
|
|
5043
|
|
5044 new_inhibit_flags = inhibit_flags | flags;
|
|
5045 if (new_inhibit_flags != inhibit_flags)
|
|
5046 internal_bind_int (&inhibit_flags, new_inhibit_flags);
|
|
5047
|
|
5048 if (flags & INHIBIT_QUIT)
|
|
5049 specbind (Qinhibit_quit, Qt);
|
|
5050
|
|
5051 if (flags & UNINHIBIT_QUIT)
|
|
5052 begin_do_check_for_quit ();
|
|
5053
|
|
5054 if (flags & INHIBIT_GC)
|
|
5055 begin_gc_forbidden ();
|
|
5056
|
|
5057 /* #### If we have nested calls to call_trapping_problems(), and the
|
|
5058 inner one creates some buffers/etc., should the outer one be able
|
|
5059 to delete them? I think so, but it means we need to combine rather
|
|
5060 than just reset the value. */
|
|
5061 if (flags & INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION)
|
|
5062 internal_bind_lisp_object (&Vdeletable_permanent_display_objects, Qnil);
|
|
5063
|
|
5064 if (flags & INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION)
|
|
5065 internal_bind_lisp_object (&Vmodifiable_buffers, Qnil);
|
|
5066
|
|
5067 return flags;
|
|
5068 }
|
|
5069
|
853
|
5070 /* This is equivalent to (*fun) (arg), except that various conditions
|
|
5071 can be trapped or inhibited, according to FLAGS.
|
|
5072
|
|
5073 If FLAGS does not contain NO_INHIBIT_ERRORS, when an error occurs,
|
|
5074 the error is caught and a warning is issued, specifying the
|
|
5075 specific error that occurred and a backtrace. In that case,
|
|
5076 WARNING_STRING should be given, and will be printed at the
|
|
5077 beginning of the error to indicate where the error occurred.
|
|
5078
|
|
5079 If FLAGS does not contain NO_INHIBIT_THROWS, all attempts to
|
|
5080 `throw' out of the function being called are trapped, and a warning
|
|
5081 issued. (Again, WARNING_STRING should be given.)
|
|
5082
|
2367
|
5083 If FLAGS contains INHIBIT_WARNING_ISSUE, no warnings are issued;
|
853
|
5084 this applies to recursive invocations of call_trapping_problems, too.
|
|
5085
|
1333
|
5086 If FLAGS contains POSTPONE_WARNING_ISSUE, no warnings are issued;
|
|
5087 but values useful for generating a warning are still computed (in
|
|
5088 particular, the backtrace), so that the calling function can issue
|
|
5089 a warning.
|
|
5090
|
853
|
5091 If FLAGS contains ISSUE_WARNINGS_AT_DEBUG_LEVEL, warnings will be
|
|
5092 issued, but at level `debug', which normally is below the minimum
|
|
5093 specified by `log-warning-minimum-level', meaning such warnings will
|
|
5094 be ignored entirely. The user can change this variable, however,
|
|
5095 to see the warnings.)
|
|
5096
|
|
5097 Note: If neither of NO_INHIBIT_THROWS or NO_INHIBIT_ERRORS is
|
|
5098 given, you are *guaranteed* that there will be no non-local exits
|
|
5099 out of this function.
|
|
5100
|
|
5101 If FLAGS contains INHIBIT_QUIT, QUIT using C-g is inhibited. (This
|
|
5102 is *rarely* a good idea. Unless you use NO_INHIBIT_ERRORS, QUIT is
|
|
5103 automatically caught as well, and treated as an error; you can
|
|
5104 check for this using EQ (problems->error_conditions, Qquit).
|
|
5105
|
|
5106 If FLAGS contains UNINHIBIT_QUIT, QUIT checking will be explicitly
|
|
5107 turned on. (It will abort the code being called, but will still be
|
|
5108 trapped and reported as an error, unless NO_INHIBIT_ERRORS is
|
|
5109 given.) This is useful when QUIT checking has been turned off by a
|
|
5110 higher-level caller.
|
|
5111
|
|
5112 If FLAGS contains INHIBIT_GC, garbage collection is inhibited.
|
1123
|
5113 This is useful for Lisp called within redisplay, for example.
|
853
|
5114
|
|
5115 If FLAGS contains INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION,
|
|
5116 Lisp code is not allowed to delete any window, buffers, frames, devices,
|
|
5117 or consoles that were already in existence at the time this function
|
|
5118 was called. (However, it's perfectly legal for code to create a new
|
|
5119 buffer and then delete it.)
|
|
5120
|
|
5121 #### It might be useful to have a flag that inhibits deletion of a
|
|
5122 specific permanent display object and everything it's attached to
|
|
5123 (e.g. a window, and the buffer, frame, device, and console it's
|
|
5124 attached to.
|
|
5125
|
|
5126 If FLAGS contains INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION, Lisp
|
|
5127 code is not allowed to modify the text of any buffers that were
|
|
5128 already in existence at the time this function was called.
|
|
5129 (However, it's perfectly legal for code to create a new buffer and
|
|
5130 then modify its text.)
|
|
5131
|
|
5132 [These last two flags are implemented using global variables
|
|
5133 Vdeletable_permanent_display_objects and Vmodifiable_buffers,
|
|
5134 which keep track of a list of all buffers or permanent display
|
|
5135 objects created since the last time one of these flags was set.
|
|
5136 The code that deletes buffers, etc. and modifies buffers checks
|
|
5137
|
|
5138 (1) if the corresponding flag is set (through the global variable
|
|
5139 inhibit_flags or its accessor function get_inhibit_flags()), and
|
|
5140
|
|
5141 (2) if the object to be modified or deleted is not in the
|
|
5142 appropriate list.
|
|
5143
|
|
5144 If so, it signals an error.
|
|
5145
|
|
5146 Recursive calls to call_trapping_problems() are allowed. In
|
|
5147 the case of the two flags mentioned above, the current values
|
|
5148 of the global variables are stored in an unwind-protect, and
|
|
5149 they're reset to nil.]
|
|
5150
|
|
5151 If FLAGS contains INHIBIT_ENTERING_DEBUGGER, the debugger will not
|
|
5152 be entered if an error occurs inside the Lisp code being called,
|
|
5153 even when the user has requested an error. In such case, a warning
|
|
5154 is issued stating that access to the debugger is denied, unless
|
|
5155 INHIBIT_WARNING_ISSUE has also been supplied. This is useful when
|
|
5156 calling Lisp code inside redisplay, in menu callbacks, etc. because
|
|
5157 in such cases either the display is in an inconsistent state or
|
|
5158 doing window operations is explicitly forbidden by the OS, and the
|
|
5159 debugger would causes visual changes on the screen and might create
|
|
5160 another frame.
|
|
5161
|
|
5162 If FLAGS contains INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY, no
|
|
5163 changes of any sort to extents, faces, glyphs, buffer text,
|
|
5164 specifiers relating to display, other variables relating to
|
|
5165 display, splitting, deleting, or resizing windows or frames,
|
|
5166 deleting buffers, windows, frames, devices, or consoles, etc. is
|
|
5167 allowed. This is for things called absolutely in the middle of
|
|
5168 redisplay, which expects things to be *exactly* the same after the
|
|
5169 call as before. This isn't completely implemented and needs to be
|
|
5170 thought out some more to determine exactly what its semantics are.
|
|
5171 For the moment, turning on this flag also turns on
|
|
5172
|
|
5173 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION
|
|
5174 INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION
|
|
5175 INHIBIT_ENTERING_DEBUGGER
|
|
5176 INHIBIT_WARNING_ISSUE
|
|
5177 INHIBIT_GC
|
|
5178
|
|
5179 #### The following five flags are defined, but unimplemented:
|
|
5180
|
|
5181 #define INHIBIT_EXISTING_CODING_SYSTEM_DELETION (1<<6)
|
|
5182 #define INHIBIT_EXISTING_CHARSET_DELETION (1<<7)
|
|
5183 #define INHIBIT_PERMANENT_DISPLAY_OBJECT_CREATION (1<<8)
|
|
5184 #define INHIBIT_CODING_SYSTEM_CREATION (1<<9)
|
|
5185 #define INHIBIT_CHARSET_CREATION (1<<10)
|
|
5186
|
|
5187 FLAGS containing CALL_WITH_SUSPENDED_ERRORS is a sign that
|
|
5188 call_with_suspended_errors() was invoked. This exists only for
|
|
5189 debugging purposes -- often we want to break when a signal happens,
|
|
5190 but ignore signals from call_with_suspended_errors(), because they
|
|
5191 occur often and for legitimate reasons.
|
|
5192
|
|
5193 If PROBLEM is non-zero, it should be a pointer to a structure into
|
|
5194 which exact information about any occurring problems (either an
|
|
5195 error or an attempted throw past this boundary).
|
|
5196
|
|
5197 If a problem occurred and aborted operation (error, quit, or
|
|
5198 invalid throw), Qunbound is returned. Otherwise the return value
|
|
5199 from the call to (*fun) (arg) is returned. */
|
|
5200
|
|
5201 Lisp_Object
|
|
5202 call_trapping_problems (Lisp_Object warning_class,
|
867
|
5203 const CIbyte *warning_string,
|
853
|
5204 int flags,
|
|
5205 struct call_trapping_problems_result *problem,
|
|
5206 Lisp_Object (*fun) (void *),
|
|
5207 void *arg)
|
|
5208 {
|
1318
|
5209 int speccount = specpdl_depth ();
|
853
|
5210 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
|
5211 struct call_trapping_problems package;
|
1333
|
5212 struct call_trapping_problems_result real_problem;
|
2532
|
5213 Lisp_Object opaque, thrown_tag, tem, thrown_backtrace;
|
853
|
5214 int thrown = 0;
|
|
5215
|
|
5216 assert (SYMBOLP (warning_class)); /* sanity-check */
|
|
5217 assert (!NILP (warning_class));
|
|
5218
|
|
5219 flags ^= INTERNAL_INHIBIT_ERRORS | INTERNAL_INHIBIT_THROWS;
|
|
5220
|
|
5221 package.warning_class = warning_class;
|
|
5222 package.warning_string = warning_string;
|
|
5223 package.fun = fun;
|
|
5224 package.arg = arg;
|
|
5225 package.catchtag =
|
|
5226 flags & INTERNAL_INHIBIT_THROWS ? Vcatch_everything_tag :
|
|
5227 flags & INTERNAL_INHIBIT_ERRORS ? make_opaque_ptr (0) :
|
|
5228 Qnil;
|
|
5229 package.error_conditions = Qnil;
|
|
5230 package.data = Qnil;
|
|
5231 package.backtrace = Qnil;
|
|
5232
|
1318
|
5233 flags = set_trapping_problems_flags (flags);
|
853
|
5234
|
|
5235 if (flags & (INTERNAL_INHIBIT_THROWS | INTERNAL_INHIBIT_ERRORS))
|
|
5236 opaque = make_opaque_ptr (&package);
|
|
5237 else
|
|
5238 opaque = Qnil;
|
|
5239
|
|
5240 GCPRO5 (package.catchtag, package.error_conditions, package.data,
|
|
5241 package.backtrace, opaque);
|
|
5242
|
|
5243 if (flags & INTERNAL_INHIBIT_ERRORS)
|
|
5244 /* We need a catch so that our condition-handler can throw back here
|
|
5245 after printing the warning. (We print the warning in the stack
|
|
5246 context of the error, so we can get a backtrace.) */
|
|
5247 tem = internal_catch (package.catchtag, call_trapping_problems_1, opaque,
|
2532
|
5248 &thrown, &thrown_tag, &thrown_backtrace);
|
853
|
5249 else if (flags & INTERNAL_INHIBIT_THROWS)
|
|
5250 /* We skip over the first wrapper, which traps errors. */
|
|
5251 tem = internal_catch (package.catchtag, call_trapping_problems_2, opaque,
|
2532
|
5252 &thrown, &thrown_tag, &thrown_backtrace);
|
853
|
5253 else
|
|
5254 /* Nothing special. */
|
|
5255 tem = (fun) (arg);
|
|
5256
|
1333
|
5257 if (!problem)
|
|
5258 problem = &real_problem;
|
|
5259
|
|
5260 if (!thrown)
|
853
|
5261 {
|
1333
|
5262 problem->caught_error = 0;
|
|
5263 problem->caught_throw = 0;
|
|
5264 problem->error_conditions = Qnil;
|
|
5265 problem->data = Qnil;
|
|
5266 problem->backtrace = Qnil;
|
|
5267 problem->thrown_tag = Qnil;
|
|
5268 problem->thrown_value = Qnil;
|
853
|
5269 }
|
1333
|
5270 else if (EQ (thrown_tag, package.catchtag))
|
853
|
5271 {
|
1333
|
5272 problem->caught_error = 1;
|
|
5273 problem->caught_throw = 0;
|
|
5274 problem->error_conditions = package.error_conditions;
|
|
5275 problem->data = package.data;
|
|
5276 problem->backtrace = package.backtrace;
|
|
5277 problem->thrown_tag = Qnil;
|
|
5278 problem->thrown_value = Qnil;
|
853
|
5279 }
|
1333
|
5280 else
|
|
5281 {
|
|
5282 problem->caught_error = 0;
|
|
5283 problem->caught_throw = 1;
|
|
5284 problem->error_conditions = Qnil;
|
|
5285 problem->data = Qnil;
|
2532
|
5286 problem->backtrace = thrown_backtrace;
|
1333
|
5287 problem->thrown_tag = thrown_tag;
|
|
5288 problem->thrown_value = tem;
|
|
5289 }
|
|
5290
|
|
5291 if (!(flags & INHIBIT_WARNING_ISSUE) && !(flags & POSTPONE_WARNING_ISSUE))
|
|
5292 issue_call_trapping_problems_warning (warning_class, warning_string,
|
|
5293 problem);
|
853
|
5294
|
|
5295 if (!NILP (package.catchtag) &&
|
|
5296 !EQ (package.catchtag, Vcatch_everything_tag))
|
|
5297 free_opaque_ptr (package.catchtag);
|
|
5298
|
|
5299 if (!NILP (opaque))
|
|
5300 free_opaque_ptr (opaque);
|
|
5301
|
|
5302 unbind_to (speccount);
|
|
5303 RETURN_UNGCPRO (thrown ? Qunbound : tem);
|
|
5304 }
|
|
5305
|
|
5306 struct va_call_trapping_problems
|
|
5307 {
|
|
5308 lisp_fn_t fun;
|
|
5309 int nargs;
|
|
5310 Lisp_Object *args;
|
|
5311 };
|
|
5312
|
|
5313 static Lisp_Object
|
|
5314 va_call_trapping_problems_1 (void *ai_mi_madre)
|
|
5315 {
|
|
5316 struct va_call_trapping_problems *ai_no_corrida =
|
|
5317 (struct va_call_trapping_problems *) ai_mi_madre;
|
|
5318 Lisp_Object pegar_no_bumbum;
|
|
5319
|
|
5320 PRIMITIVE_FUNCALL (pegar_no_bumbum, ai_no_corrida->fun,
|
|
5321 ai_no_corrida->args, ai_no_corrida->nargs);
|
|
5322 return pegar_no_bumbum;
|
|
5323 }
|
|
5324
|
|
5325 /* #### document me. */
|
|
5326
|
|
5327 Lisp_Object
|
|
5328 va_call_trapping_problems (Lisp_Object warning_class,
|
867
|
5329 const CIbyte *warning_string,
|
853
|
5330 int flags,
|
|
5331 struct call_trapping_problems_result *problem,
|
|
5332 lisp_fn_t fun, int nargs, ...)
|
|
5333 {
|
|
5334 va_list vargs;
|
|
5335 Lisp_Object args[20];
|
|
5336 int i;
|
|
5337 struct va_call_trapping_problems fazer_invocacao_atrapalhando_problemas;
|
|
5338 struct gcpro gcpro1;
|
|
5339
|
|
5340 assert (nargs >= 0 && nargs < 20);
|
|
5341
|
|
5342 va_start (vargs, nargs);
|
|
5343 for (i = 0; i < nargs; i++)
|
|
5344 args[i] = va_arg (vargs, Lisp_Object);
|
|
5345 va_end (vargs);
|
|
5346
|
|
5347 fazer_invocacao_atrapalhando_problemas.fun = fun;
|
|
5348 fazer_invocacao_atrapalhando_problemas.nargs = nargs;
|
|
5349 fazer_invocacao_atrapalhando_problemas.args = args;
|
|
5350
|
|
5351 GCPRO1_ARRAY (args, nargs);
|
|
5352 RETURN_UNGCPRO
|
|
5353 (call_trapping_problems
|
|
5354 (warning_class, warning_string, flags, problem,
|
|
5355 va_call_trapping_problems_1, &fazer_invocacao_atrapalhando_problemas));
|
|
5356 }
|
|
5357
|
|
5358 /* this is an older interface, barely different from
|
|
5359 va_call_trapping_problems.
|
|
5360
|
|
5361 #### eliminate this or at least merge the ERROR_BEHAVIOR stuff into
|
|
5362 va_call_trapping_problems(). */
|
|
5363
|
|
5364 Lisp_Object
|
|
5365 call_with_suspended_errors (lisp_fn_t fun, Lisp_Object retval,
|
1204
|
5366 Lisp_Object class_, Error_Behavior errb,
|
853
|
5367 int nargs, ...)
|
|
5368 {
|
|
5369 va_list vargs;
|
|
5370 Lisp_Object args[20];
|
|
5371 int i;
|
|
5372 struct va_call_trapping_problems fazer_invocacao_atrapalhando_problemas;
|
|
5373 int flags;
|
|
5374 struct gcpro gcpro1;
|
|
5375
|
1204
|
5376 assert (SYMBOLP (class_)); /* sanity-check */
|
|
5377 assert (!NILP (class_));
|
853
|
5378 assert (nargs >= 0 && nargs < 20);
|
|
5379
|
|
5380 va_start (vargs, nargs);
|
|
5381 for (i = 0; i < nargs; i++)
|
|
5382 args[i] = va_arg (vargs, Lisp_Object);
|
|
5383 va_end (vargs);
|
|
5384
|
|
5385 /* If error-checking is not disabled, just call the function. */
|
|
5386
|
|
5387 if (ERRB_EQ (errb, ERROR_ME))
|
|
5388 {
|
|
5389 Lisp_Object val;
|
|
5390 PRIMITIVE_FUNCALL (val, fun, args, nargs);
|
|
5391 return val;
|
|
5392 }
|
|
5393
|
|
5394 if (ERRB_EQ (errb, ERROR_ME_NOT)) /* person wants no warnings */
|
|
5395 flags = INHIBIT_WARNING_ISSUE | INHIBIT_ENTERING_DEBUGGER;
|
|
5396 else if (ERRB_EQ (errb, ERROR_ME_DEBUG_WARN))
|
|
5397 flags = ISSUE_WARNINGS_AT_DEBUG_LEVEL | INHIBIT_ENTERING_DEBUGGER;
|
|
5398 else
|
|
5399 {
|
|
5400 assert (ERRB_EQ (errb, ERROR_ME_WARN));
|
|
5401 flags = INHIBIT_ENTERING_DEBUGGER;
|
|
5402 }
|
|
5403
|
|
5404 flags |= CALL_WITH_SUSPENDED_ERRORS;
|
|
5405
|
|
5406 fazer_invocacao_atrapalhando_problemas.fun = fun;
|
|
5407 fazer_invocacao_atrapalhando_problemas.nargs = nargs;
|
|
5408 fazer_invocacao_atrapalhando_problemas.args = args;
|
|
5409
|
|
5410 GCPRO1_ARRAY (args, nargs);
|
|
5411 {
|
|
5412 Lisp_Object its_way_too_goddamn_late =
|
|
5413 call_trapping_problems
|
1204
|
5414 (class_, 0, flags, 0, va_call_trapping_problems_1,
|
853
|
5415 &fazer_invocacao_atrapalhando_problemas);
|
|
5416 UNGCPRO;
|
|
5417 if (UNBOUNDP (its_way_too_goddamn_late))
|
|
5418 return retval;
|
|
5419 else
|
|
5420 return its_way_too_goddamn_late;
|
|
5421 }
|
|
5422 }
|
|
5423
|
|
5424 struct calln_trapping_problems
|
|
5425 {
|
|
5426 int nargs;
|
|
5427 Lisp_Object *args;
|
|
5428 };
|
|
5429
|
|
5430 static Lisp_Object
|
|
5431 calln_trapping_problems_1 (void *puta)
|
|
5432 {
|
|
5433 struct calln_trapping_problems *p = (struct calln_trapping_problems *) puta;
|
|
5434
|
|
5435 return Ffuncall (p->nargs, p->args);
|
428
|
5436 }
|
|
5437
|
|
5438 static Lisp_Object
|
853
|
5439 calln_trapping_problems (Lisp_Object warning_class,
|
867
|
5440 const CIbyte *warning_string, int flags,
|
853
|
5441 struct call_trapping_problems_result *problem,
|
|
5442 int nargs, Lisp_Object *args)
|
|
5443 {
|
|
5444 struct calln_trapping_problems foo;
|
|
5445 struct gcpro gcpro1;
|
|
5446
|
|
5447 if (SYMBOLP (args[0]))
|
|
5448 {
|
|
5449 Lisp_Object tem = XSYMBOL (args[0])->function;
|
|
5450 if (NILP (tem) || UNBOUNDP (tem))
|
|
5451 {
|
|
5452 if (problem)
|
|
5453 {
|
|
5454 problem->caught_error = 0;
|
|
5455 problem->caught_throw = 0;
|
|
5456 problem->error_conditions = Qnil;
|
|
5457 problem->data = Qnil;
|
|
5458 problem->backtrace = Qnil;
|
|
5459 problem->thrown_tag = Qnil;
|
|
5460 problem->thrown_value = Qnil;
|
|
5461 }
|
|
5462 return Qnil;
|
|
5463 }
|
|
5464 }
|
|
5465
|
|
5466 foo.nargs = nargs;
|
|
5467 foo.args = args;
|
|
5468
|
|
5469 GCPRO1_ARRAY (args, nargs);
|
|
5470 RETURN_UNGCPRO (call_trapping_problems (warning_class, warning_string,
|
|
5471 flags, problem,
|
|
5472 calln_trapping_problems_1,
|
|
5473 &foo));
|
|
5474 }
|
|
5475
|
|
5476 /* #### fix these functions to follow the calling convention of
|
|
5477 call_trapping_problems! */
|
|
5478
|
|
5479 Lisp_Object
|
867
|
5480 call0_trapping_problems (const CIbyte *warning_string, Lisp_Object function,
|
853
|
5481 int flags)
|
|
5482 {
|
|
5483 return calln_trapping_problems (Qerror, warning_string, flags, 0, 1,
|
|
5484 &function);
|
428
|
5485 }
|
|
5486
|
|
5487 Lisp_Object
|
867
|
5488 call1_trapping_problems (const CIbyte *warning_string, Lisp_Object function,
|
853
|
5489 Lisp_Object object, int flags)
|
|
5490 {
|
|
5491 Lisp_Object args[2];
|
|
5492
|
|
5493 args[0] = function;
|
|
5494 args[1] = object;
|
|
5495
|
|
5496 return calln_trapping_problems (Qerror, warning_string, flags, 0, 2,
|
|
5497 args);
|
|
5498 }
|
|
5499
|
|
5500 Lisp_Object
|
867
|
5501 call2_trapping_problems (const CIbyte *warning_string, Lisp_Object function,
|
853
|
5502 Lisp_Object object1, Lisp_Object object2,
|
|
5503 int flags)
|
|
5504 {
|
|
5505 Lisp_Object args[3];
|
|
5506
|
|
5507 args[0] = function;
|
|
5508 args[1] = object1;
|
|
5509 args[2] = object2;
|
|
5510
|
|
5511 return calln_trapping_problems (Qerror, warning_string, flags, 0, 3,
|
|
5512 args);
|
|
5513 }
|
|
5514
|
|
5515 Lisp_Object
|
867
|
5516 call3_trapping_problems (const CIbyte *warning_string, Lisp_Object function,
|
853
|
5517 Lisp_Object object1, Lisp_Object object2,
|
|
5518 Lisp_Object object3, int flags)
|
|
5519 {
|
|
5520 Lisp_Object args[4];
|
|
5521
|
|
5522 args[0] = function;
|
|
5523 args[1] = object1;
|
|
5524 args[2] = object2;
|
|
5525 args[3] = object3;
|
|
5526
|
|
5527 return calln_trapping_problems (Qerror, warning_string, flags, 0, 4,
|
|
5528 args);
|
|
5529 }
|
|
5530
|
|
5531 Lisp_Object
|
867
|
5532 call4_trapping_problems (const CIbyte *warning_string, Lisp_Object function,
|
853
|
5533 Lisp_Object object1, Lisp_Object object2,
|
|
5534 Lisp_Object object3, Lisp_Object object4,
|
|
5535 int flags)
|
|
5536 {
|
|
5537 Lisp_Object args[5];
|
|
5538
|
|
5539 args[0] = function;
|
|
5540 args[1] = object1;
|
|
5541 args[2] = object2;
|
|
5542 args[3] = object3;
|
|
5543 args[4] = object4;
|
|
5544
|
|
5545 return calln_trapping_problems (Qerror, warning_string, flags, 0, 5,
|
|
5546 args);
|
|
5547 }
|
|
5548
|
|
5549 Lisp_Object
|
867
|
5550 call5_trapping_problems (const CIbyte *warning_string, Lisp_Object function,
|
853
|
5551 Lisp_Object object1, Lisp_Object object2,
|
|
5552 Lisp_Object object3, Lisp_Object object4,
|
|
5553 Lisp_Object object5, int flags)
|
|
5554 {
|
|
5555 Lisp_Object args[6];
|
|
5556
|
|
5557 args[0] = function;
|
|
5558 args[1] = object1;
|
|
5559 args[2] = object2;
|
|
5560 args[3] = object3;
|
|
5561 args[4] = object4;
|
|
5562 args[5] = object5;
|
|
5563
|
|
5564 return calln_trapping_problems (Qerror, warning_string, flags, 0, 6,
|
|
5565 args);
|
|
5566 }
|
|
5567
|
|
5568 struct eval_in_buffer_trapping_problems
|
|
5569 {
|
|
5570 struct buffer *buf;
|
|
5571 Lisp_Object form;
|
|
5572 };
|
|
5573
|
|
5574 static Lisp_Object
|
|
5575 eval_in_buffer_trapping_problems_1 (void *arg)
|
|
5576 {
|
|
5577 struct eval_in_buffer_trapping_problems *p =
|
|
5578 (struct eval_in_buffer_trapping_problems *) arg;
|
|
5579
|
|
5580 return eval_in_buffer (p->buf, p->form);
|
|
5581 }
|
|
5582
|
|
5583 /* #### fix these functions to follow the calling convention of
|
|
5584 call_trapping_problems! */
|
|
5585
|
|
5586 Lisp_Object
|
867
|
5587 eval_in_buffer_trapping_problems (const CIbyte *warning_string,
|
853
|
5588 struct buffer *buf, Lisp_Object form,
|
|
5589 int flags)
|
|
5590 {
|
|
5591 struct eval_in_buffer_trapping_problems p;
|
|
5592 Lisp_Object buffer = wrap_buffer (buf);
|
428
|
5593 struct gcpro gcpro1, gcpro2;
|
|
5594
|
853
|
5595 GCPRO2 (buffer, form);
|
|
5596 p.buf = buf;
|
|
5597 p.form = form;
|
|
5598 RETURN_UNGCPRO (call_trapping_problems (Qerror, warning_string, flags, 0,
|
|
5599 eval_in_buffer_trapping_problems_1,
|
|
5600 &p));
|
|
5601 }
|
|
5602
|
|
5603 Lisp_Object
|
1333
|
5604 run_hook_trapping_problems (Lisp_Object warning_class,
|
853
|
5605 Lisp_Object hook_symbol,
|
|
5606 int flags)
|
|
5607 {
|
1333
|
5608 return run_hook_with_args_trapping_problems (warning_class, 1, &hook_symbol,
|
853
|
5609 RUN_HOOKS_TO_COMPLETION,
|
|
5610 flags);
|
428
|
5611 }
|
|
5612
|
|
5613 static Lisp_Object
|
853
|
5614 safe_run_hook_trapping_problems_1 (void *puta)
|
|
5615 {
|
|
5616 Lisp_Object hook = VOID_TO_LISP (puta);
|
|
5617
|
|
5618 run_hook (hook);
|
428
|
5619 return Qnil;
|
|
5620 }
|
|
5621
|
853
|
5622 /* Same as run_hook_trapping_problems() but also set the hook to nil
|
|
5623 if an error occurs (but not a quit). */
|
|
5624
|
428
|
5625 Lisp_Object
|
1333
|
5626 safe_run_hook_trapping_problems (Lisp_Object warning_class,
|
|
5627 Lisp_Object hook_symbol, int flags)
|
853
|
5628 {
|
428
|
5629 Lisp_Object tem;
|
853
|
5630 struct gcpro gcpro1, gcpro2;
|
|
5631 struct call_trapping_problems_result prob;
|
428
|
5632
|
|
5633 if (!initialized || preparing_for_armageddon)
|
|
5634 return Qnil;
|
|
5635 tem = find_symbol_value (hook_symbol);
|
|
5636 if (NILP (tem) || UNBOUNDP (tem))
|
|
5637 return Qnil;
|
|
5638
|
853
|
5639 GCPRO2 (hook_symbol, tem);
|
1333
|
5640 tem = call_trapping_problems (Qerror, NULL,
|
|
5641 flags | POSTPONE_WARNING_ISSUE,
|
853
|
5642 &prob,
|
|
5643 safe_run_hook_trapping_problems_1,
|
|
5644 LISP_TO_VOID (hook_symbol));
|
1333
|
5645 {
|
|
5646 Lisp_Object hook_name = XSYMBOL_NAME (hook_symbol);
|
|
5647 Ibyte *hook_str = XSTRING_DATA (hook_name);
|
|
5648 Ibyte *err = alloca_ibytes (XSTRING_LENGTH (hook_name) + 100);
|
|
5649
|
|
5650 if (prob.caught_throw || (prob.caught_error && !EQ (prob.error_conditions,
|
|
5651 Qquit)))
|
|
5652 {
|
|
5653 Fset (hook_symbol, Qnil);
|
|
5654 qxesprintf (err, "Error in `%s' (resetting to nil)", hook_str);
|
|
5655 }
|
|
5656 else
|
|
5657 qxesprintf (err, "Quit in `%s'", hook_str);
|
|
5658
|
|
5659
|
|
5660 issue_call_trapping_problems_warning (warning_class, (CIbyte *) err,
|
|
5661 &prob);
|
|
5662 }
|
|
5663
|
|
5664 UNGCPRO;
|
|
5665 return tem;
|
853
|
5666 }
|
|
5667
|
|
5668 struct run_hook_with_args_in_buffer_trapping_problems
|
|
5669 {
|
|
5670 struct buffer *buf;
|
|
5671 int nargs;
|
|
5672 Lisp_Object *args;
|
|
5673 enum run_hooks_condition cond;
|
|
5674 };
|
|
5675
|
|
5676 static Lisp_Object
|
|
5677 run_hook_with_args_in_buffer_trapping_problems_1 (void *puta)
|
|
5678 {
|
|
5679 struct run_hook_with_args_in_buffer_trapping_problems *porra =
|
|
5680 (struct run_hook_with_args_in_buffer_trapping_problems *) puta;
|
|
5681
|
|
5682 return run_hook_with_args_in_buffer (porra->buf, porra->nargs, porra->args,
|
|
5683 porra->cond);
|
|
5684 }
|
|
5685
|
|
5686 /* #### fix these functions to follow the calling convention of
|
|
5687 call_trapping_problems! */
|
428
|
5688
|
|
5689 Lisp_Object
|
1333
|
5690 run_hook_with_args_in_buffer_trapping_problems (Lisp_Object warning_class,
|
853
|
5691 struct buffer *buf, int nargs,
|
|
5692 Lisp_Object *args,
|
|
5693 enum run_hooks_condition cond,
|
|
5694 int flags)
|
|
5695 {
|
|
5696 Lisp_Object sym, val, ret;
|
|
5697 struct run_hook_with_args_in_buffer_trapping_problems diversity_and_distrust;
|
428
|
5698 struct gcpro gcpro1;
|
1333
|
5699 Lisp_Object hook_name;
|
|
5700 Ibyte *hook_str;
|
|
5701 Ibyte *err;
|
428
|
5702
|
|
5703 if (!initialized || preparing_for_armageddon)
|
853
|
5704 /* We need to bail out of here pronto. */
|
428
|
5705 return Qnil;
|
|
5706
|
853
|
5707 GCPRO1_ARRAY (args, nargs);
|
|
5708
|
|
5709 sym = args[0];
|
|
5710 val = symbol_value_in_buffer (sym, wrap_buffer (buf));
|
|
5711 ret = (cond == RUN_HOOKS_UNTIL_FAILURE ? Qt : Qnil);
|
|
5712
|
|
5713 if (UNBOUNDP (val) || NILP (val))
|
|
5714 RETURN_UNGCPRO (ret);
|
|
5715
|
|
5716 diversity_and_distrust.buf = buf;
|
|
5717 diversity_and_distrust.nargs = nargs;
|
|
5718 diversity_and_distrust.args = args;
|
|
5719 diversity_and_distrust.cond = cond;
|
|
5720
|
1333
|
5721 hook_name = XSYMBOL_NAME (args[0]);
|
|
5722 hook_str = XSTRING_DATA (hook_name);
|
|
5723 err = alloca_ibytes (XSTRING_LENGTH (hook_name) + 100);
|
|
5724 qxesprintf (err, "Error in `%s'", hook_str);
|
853
|
5725 RETURN_UNGCPRO
|
|
5726 (call_trapping_problems
|
1333
|
5727 (warning_class, (CIbyte *) err, flags, 0,
|
853
|
5728 run_hook_with_args_in_buffer_trapping_problems_1,
|
|
5729 &diversity_and_distrust));
|
428
|
5730 }
|
|
5731
|
|
5732 Lisp_Object
|
1333
|
5733 run_hook_with_args_trapping_problems (Lisp_Object warning_class,
|
853
|
5734 int nargs,
|
|
5735 Lisp_Object *args,
|
|
5736 enum run_hooks_condition cond,
|
|
5737 int flags)
|
|
5738 {
|
|
5739 return run_hook_with_args_in_buffer_trapping_problems
|
1333
|
5740 (warning_class, current_buffer, nargs, args, cond, flags);
|
428
|
5741 }
|
|
5742
|
|
5743 Lisp_Object
|
1333
|
5744 va_run_hook_with_args_trapping_problems (Lisp_Object warning_class,
|
853
|
5745 Lisp_Object hook_var,
|
|
5746 int nargs, ...)
|
|
5747 {
|
|
5748 /* This function can GC */
|
|
5749 struct gcpro gcpro1;
|
|
5750 int i;
|
|
5751 va_list vargs;
|
|
5752 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
|
5753 int flags;
|
|
5754
|
|
5755 va_start (vargs, nargs);
|
|
5756 funcall_args[0] = hook_var;
|
|
5757 for (i = 0; i < nargs; i++)
|
|
5758 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
5759 flags = va_arg (vargs, int);
|
|
5760 va_end (vargs);
|
|
5761
|
|
5762 GCPRO1_ARRAY (funcall_args, nargs + 1);
|
|
5763 RETURN_UNGCPRO (run_hook_with_args_in_buffer_trapping_problems
|
1333
|
5764 (warning_class, current_buffer, nargs + 1, funcall_args,
|
853
|
5765 RUN_HOOKS_TO_COMPLETION, flags));
|
428
|
5766 }
|
|
5767
|
|
5768 Lisp_Object
|
1333
|
5769 va_run_hook_with_args_in_buffer_trapping_problems (Lisp_Object warning_class,
|
853
|
5770 struct buffer *buf,
|
|
5771 Lisp_Object hook_var,
|
|
5772 int nargs, ...)
|
|
5773 {
|
|
5774 /* This function can GC */
|
|
5775 struct gcpro gcpro1;
|
|
5776 int i;
|
|
5777 va_list vargs;
|
|
5778 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
|
5779 int flags;
|
|
5780
|
|
5781 va_start (vargs, nargs);
|
|
5782 funcall_args[0] = hook_var;
|
|
5783 for (i = 0; i < nargs; i++)
|
|
5784 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
5785 flags = va_arg (vargs, int);
|
|
5786 va_end (vargs);
|
|
5787
|
|
5788 GCPRO1_ARRAY (funcall_args, nargs + 1);
|
|
5789 RETURN_UNGCPRO (run_hook_with_args_in_buffer_trapping_problems
|
1333
|
5790 (warning_class, buf, nargs + 1, funcall_args,
|
853
|
5791 RUN_HOOKS_TO_COMPLETION, flags));
|
428
|
5792 }
|
|
5793
|
|
5794
|
|
5795 /************************************************************************/
|
|
5796 /* The special binding stack */
|
771
|
5797 /* Most C code should simply use specbind() and unbind_to_1(). */
|
428
|
5798 /* When performance is critical, use the macros in backtrace.h. */
|
|
5799 /************************************************************************/
|
|
5800
|
|
5801 #define min_max_specpdl_size 400
|
|
5802
|
|
5803 void
|
647
|
5804 grow_specpdl (EMACS_INT reserved)
|
|
5805 {
|
|
5806 EMACS_INT size_needed = specpdl_depth() + reserved;
|
428
|
5807 if (size_needed >= max_specpdl_size)
|
|
5808 {
|
|
5809 if (max_specpdl_size < min_max_specpdl_size)
|
|
5810 max_specpdl_size = min_max_specpdl_size;
|
|
5811 if (size_needed >= max_specpdl_size)
|
|
5812 {
|
1951
|
5813 /* Leave room for some specpdl in the debugger. */
|
|
5814 max_specpdl_size = size_needed + 100;
|
|
5815 if (max_specpdl_size > specpdl_size)
|
|
5816 {
|
|
5817 specpdl_size = max_specpdl_size;
|
|
5818 XREALLOC_ARRAY (specpdl, struct specbinding, specpdl_size);
|
|
5819 specpdl_ptr = specpdl + specpdl_depth();
|
|
5820 }
|
563
|
5821 signal_continuable_error
|
|
5822 (Qstack_overflow,
|
|
5823 "Variable binding depth exceeds max-specpdl-size", Qunbound);
|
428
|
5824 }
|
|
5825 }
|
|
5826 while (specpdl_size < size_needed)
|
|
5827 {
|
|
5828 specpdl_size *= 2;
|
|
5829 if (specpdl_size > max_specpdl_size)
|
|
5830 specpdl_size = max_specpdl_size;
|
|
5831 }
|
|
5832 XREALLOC_ARRAY (specpdl, struct specbinding, specpdl_size);
|
|
5833 specpdl_ptr = specpdl + specpdl_depth();
|
853
|
5834 check_specbind_stack_sanity ();
|
428
|
5835 }
|
|
5836
|
|
5837
|
|
5838 /* Handle unbinding buffer-local variables */
|
|
5839 static Lisp_Object
|
|
5840 specbind_unwind_local (Lisp_Object ovalue)
|
|
5841 {
|
|
5842 Lisp_Object current = Fcurrent_buffer ();
|
|
5843 Lisp_Object symbol = specpdl_ptr->symbol;
|
853
|
5844 Lisp_Object victim = ovalue;
|
|
5845 Lisp_Object buf = get_buffer (XCAR (victim), 0);
|
|
5846 ovalue = XCDR (victim);
|
428
|
5847
|
|
5848 free_cons (victim);
|
|
5849
|
|
5850 if (NILP (buf))
|
|
5851 {
|
|
5852 /* Deleted buffer -- do nothing */
|
|
5853 }
|
|
5854 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buf)) == 0)
|
|
5855 {
|
|
5856 /* Was buffer-local when binding was made, now no longer is.
|
|
5857 * (kill-local-variable can do this.)
|
|
5858 * Do nothing in this case.
|
|
5859 */
|
|
5860 }
|
|
5861 else if (EQ (buf, current))
|
|
5862 Fset (symbol, ovalue);
|
|
5863 else
|
|
5864 {
|
|
5865 /* Urk! Somebody switched buffers */
|
|
5866 struct gcpro gcpro1;
|
|
5867 GCPRO1 (current);
|
|
5868 Fset_buffer (buf);
|
|
5869 Fset (symbol, ovalue);
|
|
5870 Fset_buffer (current);
|
|
5871 UNGCPRO;
|
|
5872 }
|
|
5873 return symbol;
|
|
5874 }
|
|
5875
|
|
5876 static Lisp_Object
|
|
5877 specbind_unwind_wasnt_local (Lisp_Object buffer)
|
|
5878 {
|
|
5879 Lisp_Object current = Fcurrent_buffer ();
|
|
5880 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
5881
|
|
5882 buffer = get_buffer (buffer, 0);
|
|
5883 if (NILP (buffer))
|
|
5884 {
|
|
5885 /* Deleted buffer -- do nothing */
|
|
5886 }
|
|
5887 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buffer)) == 0)
|
|
5888 {
|
|
5889 /* Was buffer-local when binding was made, now no longer is.
|
|
5890 * (kill-local-variable can do this.)
|
|
5891 * Do nothing in this case.
|
|
5892 */
|
|
5893 }
|
|
5894 else if (EQ (buffer, current))
|
|
5895 Fkill_local_variable (symbol);
|
|
5896 else
|
|
5897 {
|
|
5898 /* Urk! Somebody switched buffers */
|
|
5899 struct gcpro gcpro1;
|
|
5900 GCPRO1 (current);
|
|
5901 Fset_buffer (buffer);
|
|
5902 Fkill_local_variable (symbol);
|
|
5903 Fset_buffer (current);
|
|
5904 UNGCPRO;
|
|
5905 }
|
|
5906 return symbol;
|
|
5907 }
|
|
5908
|
|
5909
|
|
5910 void
|
|
5911 specbind (Lisp_Object symbol, Lisp_Object value)
|
|
5912 {
|
|
5913 SPECBIND (symbol, value);
|
853
|
5914
|
|
5915 check_specbind_stack_sanity ();
|
428
|
5916 }
|
|
5917
|
|
5918 void
|
|
5919 specbind_magic (Lisp_Object symbol, Lisp_Object value)
|
|
5920 {
|
|
5921 int buffer_local =
|
|
5922 symbol_value_buffer_local_info (symbol, current_buffer);
|
|
5923
|
|
5924 if (buffer_local == 0)
|
|
5925 {
|
|
5926 specpdl_ptr->old_value = find_symbol_value (symbol);
|
771
|
5927 specpdl_ptr->func = 0; /* Handled specially by unbind_to_1 */
|
428
|
5928 }
|
|
5929 else if (buffer_local > 0)
|
|
5930 {
|
|
5931 /* Already buffer-local */
|
|
5932 specpdl_ptr->old_value = noseeum_cons (Fcurrent_buffer (),
|
|
5933 find_symbol_value (symbol));
|
|
5934 specpdl_ptr->func = specbind_unwind_local;
|
|
5935 }
|
|
5936 else
|
|
5937 {
|
|
5938 /* About to become buffer-local */
|
|
5939 specpdl_ptr->old_value = Fcurrent_buffer ();
|
|
5940 specpdl_ptr->func = specbind_unwind_wasnt_local;
|
|
5941 }
|
|
5942
|
|
5943 specpdl_ptr->symbol = symbol;
|
|
5944 specpdl_ptr++;
|
|
5945 specpdl_depth_counter++;
|
|
5946
|
|
5947 Fset (symbol, value);
|
853
|
5948
|
|
5949 check_specbind_stack_sanity ();
|
428
|
5950 }
|
|
5951
|
771
|
5952 /* Record an unwind-protect -- FUNCTION will be called with ARG no matter
|
|
5953 whether a normal or non-local exit occurs. (You need to call unbind_to_1()
|
|
5954 before your function returns normally, passing in the integer returned
|
|
5955 by this function.) Note: As long as the unwind-protect exists, ARG is
|
|
5956 automatically GCPRO'd. The return value from FUNCTION is completely
|
|
5957 ignored. #### We should eliminate it entirely. */
|
|
5958
|
|
5959 int
|
428
|
5960 record_unwind_protect (Lisp_Object (*function) (Lisp_Object arg),
|
|
5961 Lisp_Object arg)
|
|
5962 {
|
|
5963 SPECPDL_RESERVE (1);
|
|
5964 specpdl_ptr->func = function;
|
|
5965 specpdl_ptr->symbol = Qnil;
|
|
5966 specpdl_ptr->old_value = arg;
|
|
5967 specpdl_ptr++;
|
|
5968 specpdl_depth_counter++;
|
853
|
5969 check_specbind_stack_sanity ();
|
771
|
5970 return specpdl_depth_counter - 1;
|
|
5971 }
|
|
5972
|
|
5973 static Lisp_Object
|
802
|
5974 restore_lisp_object (Lisp_Object cons)
|
|
5975 {
|
|
5976 Lisp_Object opaque = XCAR (cons);
|
|
5977 Lisp_Object *addr = (Lisp_Object *) get_opaque_ptr (opaque);
|
|
5978 *addr = XCDR (cons);
|
|
5979 free_opaque_ptr (opaque);
|
853
|
5980 free_cons (cons);
|
802
|
5981 return Qnil;
|
|
5982 }
|
|
5983
|
|
5984 /* Establish an unwind-protect which will restore the Lisp_Object pointed to
|
|
5985 by ADDR with the value VAL. */
|
814
|
5986 static int
|
802
|
5987 record_unwind_protect_restoring_lisp_object (Lisp_Object *addr,
|
|
5988 Lisp_Object val)
|
|
5989 {
|
|
5990 Lisp_Object opaque = make_opaque_ptr (addr);
|
|
5991 return record_unwind_protect (restore_lisp_object,
|
|
5992 noseeum_cons (opaque, val));
|
|
5993 }
|
|
5994
|
|
5995 /* Similar to specbind() but for any C variable whose value is a
|
|
5996 Lisp_Object. Sets up an unwind-protect to restore the variable
|
|
5997 pointed to by ADDR to its existing value, and then changes its
|
|
5998 value to NEWVAL. Returns the previous value of specpdl_depth();
|
|
5999 pass this to unbind_to() after you are done. */
|
|
6000 int
|
|
6001 internal_bind_lisp_object (Lisp_Object *addr, Lisp_Object newval)
|
|
6002 {
|
|
6003 int count = specpdl_depth ();
|
|
6004 record_unwind_protect_restoring_lisp_object (addr, *addr);
|
|
6005 *addr = newval;
|
|
6006 return count;
|
|
6007 }
|
|
6008
|
|
6009 static Lisp_Object
|
|
6010 restore_int (Lisp_Object cons)
|
|
6011 {
|
|
6012 Lisp_Object opaque = XCAR (cons);
|
|
6013 Lisp_Object lval = XCDR (cons);
|
|
6014 int *addr = (int *) get_opaque_ptr (opaque);
|
|
6015 int val;
|
|
6016
|
4025
|
6017 /* In the event that a C integer will always fit in an Emacs int, we
|
|
6018 haven't ever stored a C integer as an opaque pointer. This #ifdef
|
|
6019 eliminates a warning on AMD 64, where EMACS_INT has 63 value bits and C
|
|
6020 integers have 32 value bits. */
|
|
6021 #if INT_VALBITS < INTBITS
|
802
|
6022 if (INTP (lval))
|
4025
|
6023 {
|
|
6024 val = XINT (lval);
|
|
6025 }
|
802
|
6026 else
|
|
6027 {
|
|
6028 val = (int) get_opaque_ptr (lval);
|
|
6029 free_opaque_ptr (lval);
|
|
6030 }
|
4025
|
6031 #else /* !(INT_VALBITS < INTBITS) */
|
|
6032 val = XINT(lval);
|
|
6033 #endif /* INT_VALBITS < INTBITS */
|
802
|
6034
|
|
6035 *addr = val;
|
|
6036 free_opaque_ptr (opaque);
|
853
|
6037 free_cons (cons);
|
802
|
6038 return Qnil;
|
|
6039 }
|
|
6040
|
|
6041 /* Establish an unwind-protect which will restore the int pointed to
|
|
6042 by ADDR with the value VAL. This function works correctly with
|
|
6043 all ints, even those that don't fit into a Lisp integer. */
|
1333
|
6044 int
|
802
|
6045 record_unwind_protect_restoring_int (int *addr, int val)
|
|
6046 {
|
|
6047 Lisp_Object opaque = make_opaque_ptr (addr);
|
|
6048 Lisp_Object lval;
|
|
6049
|
4025
|
6050 /* In the event that a C integer will always fit in an Emacs int, we don't
|
|
6051 ever want to store a C integer as an opaque pointer. This #ifdef
|
|
6052 eliminates a warning on AMD 64, where EMACS_INT has 63 value bits and C
|
|
6053 integers have 32 value bits. */
|
|
6054 #if INT_VALBITS <= INTBITS
|
802
|
6055 if (NUMBER_FITS_IN_AN_EMACS_INT (val))
|
|
6056 lval = make_int (val);
|
|
6057 else
|
|
6058 lval = make_opaque_ptr ((void *) val);
|
4025
|
6059 #else /* !(INT_VALBITS < INTBITS) */
|
|
6060 lval = make_int (val);
|
|
6061 #endif /* INT_VALBITS <= INTBITS */
|
|
6062
|
802
|
6063 return record_unwind_protect (restore_int, noseeum_cons (opaque, lval));
|
|
6064 }
|
|
6065
|
|
6066 /* Similar to specbind() but for any C variable whose value is an int.
|
|
6067 Sets up an unwind-protect to restore the variable pointed to by
|
|
6068 ADDR to its existing value, and then changes its value to NEWVAL.
|
|
6069 Returns the previous value of specpdl_depth(); pass this to
|
|
6070 unbind_to() after you are done. This function works correctly with
|
|
6071 all ints, even those that don't fit into a Lisp integer. */
|
|
6072 int
|
|
6073 internal_bind_int (int *addr, int newval)
|
|
6074 {
|
|
6075 int count = specpdl_depth ();
|
|
6076 record_unwind_protect_restoring_int (addr, *addr);
|
|
6077 *addr = newval;
|
|
6078 return count;
|
|
6079 }
|
|
6080
|
|
6081 static Lisp_Object
|
771
|
6082 free_pointer (Lisp_Object opaque)
|
|
6083 {
|
1726
|
6084 xfree (get_opaque_ptr (opaque), void *);
|
771
|
6085 free_opaque_ptr (opaque);
|
|
6086 return Qnil;
|
|
6087 }
|
|
6088
|
|
6089 /* Establish an unwind-protect which will free the specified block.
|
|
6090 */
|
|
6091 int
|
|
6092 record_unwind_protect_freeing (void *ptr)
|
|
6093 {
|
|
6094 Lisp_Object opaque = make_opaque_ptr (ptr);
|
|
6095 return record_unwind_protect (free_pointer, opaque);
|
|
6096 }
|
|
6097
|
|
6098 static Lisp_Object
|
|
6099 free_dynarr (Lisp_Object opaque)
|
|
6100 {
|
|
6101 Dynarr_free (get_opaque_ptr (opaque));
|
|
6102 free_opaque_ptr (opaque);
|
|
6103 return Qnil;
|
|
6104 }
|
|
6105
|
|
6106 int
|
|
6107 record_unwind_protect_freeing_dynarr (void *ptr)
|
|
6108 {
|
|
6109 Lisp_Object opaque = make_opaque_ptr (ptr);
|
|
6110 return record_unwind_protect (free_dynarr, opaque);
|
|
6111 }
|
428
|
6112
|
|
6113 /* Unwind the stack till specpdl_depth() == COUNT.
|
|
6114 VALUE is not used, except that, purely as a convenience to the
|
771
|
6115 caller, it is protected from garbage-protection and returned. */
|
428
|
6116 Lisp_Object
|
771
|
6117 unbind_to_1 (int count, Lisp_Object value)
|
428
|
6118 {
|
|
6119 UNBIND_TO_GCPRO (count, value);
|
853
|
6120 check_specbind_stack_sanity ();
|
428
|
6121 return value;
|
|
6122 }
|
|
6123
|
|
6124 /* Don't call this directly.
|
|
6125 Only for use by UNBIND_TO* macros in backtrace.h */
|
|
6126 void
|
|
6127 unbind_to_hairy (int count)
|
|
6128 {
|
442
|
6129 ++specpdl_ptr;
|
|
6130 ++specpdl_depth_counter;
|
|
6131
|
428
|
6132 while (specpdl_depth_counter != count)
|
|
6133 {
|
1313
|
6134 Lisp_Object oquit = Qunbound;
|
|
6135
|
|
6136 /* Do this check BEFORE decrementing the values below, because once
|
|
6137 they're decremented, GC protection is lost on
|
|
6138 specpdl_ptr->old_value. */
|
1322
|
6139 if (specpdl_ptr[-1].func == Fprogn)
|
1313
|
6140 {
|
|
6141 /* Allow QUIT within unwind-protect routines, but defer any
|
|
6142 existing QUIT until afterwards. Only do this, however, for
|
|
6143 unwind-protects established by Lisp code, not by C code
|
|
6144 (e.g. free_opaque_ptr() or something), because the act of
|
|
6145 checking for QUIT can cause all sorts of weird things to
|
|
6146 happen, since it churns the event loop -- redisplay, running
|
|
6147 Lisp, etc. Code should not have to worry about this just
|
|
6148 because of establishing an unwind-protect. */
|
|
6149 check_quit (); /* make Vquit_flag accurate */
|
|
6150 oquit = Vquit_flag;
|
|
6151 Vquit_flag = Qnil;
|
|
6152 }
|
|
6153
|
428
|
6154 --specpdl_ptr;
|
|
6155 --specpdl_depth_counter;
|
|
6156
|
1313
|
6157 /* #### At this point, there is no GC protection on old_value. This
|
|
6158 could be a real problem, depending on what unwind-protect function
|
|
6159 is called. It looks like it just so happens that the ones
|
|
6160 actually called don't have a problem with this, e.g. Fprogn. But
|
|
6161 we should look into fixing this. (Many unwind-protect functions
|
|
6162 free values. Is it a problem if freed values are
|
|
6163 GC-protected?) */
|
428
|
6164 if (specpdl_ptr->func != 0)
|
1313
|
6165 {
|
|
6166 /* An unwind-protect */
|
|
6167 (*specpdl_ptr->func) (specpdl_ptr->old_value);
|
|
6168 }
|
|
6169
|
428
|
6170 else
|
|
6171 {
|
|
6172 /* We checked symbol for validity when we specbound it,
|
|
6173 so only need to call Fset if symbol has magic value. */
|
440
|
6174 Lisp_Symbol *sym = XSYMBOL (specpdl_ptr->symbol);
|
428
|
6175 if (!SYMBOL_VALUE_MAGIC_P (sym->value))
|
|
6176 sym->value = specpdl_ptr->old_value;
|
|
6177 else
|
|
6178 Fset (specpdl_ptr->symbol, specpdl_ptr->old_value);
|
|
6179 }
|
|
6180
|
|
6181 #if 0 /* martin */
|
|
6182 #ifndef EXCEEDINGLY_QUESTIONABLE_CODE
|
|
6183 /* There should never be anything here for us to remove.
|
|
6184 If so, it indicates a logic error in Emacs. Catches
|
|
6185 should get removed when a throw or signal occurs, or
|
|
6186 when a catch or condition-case exits normally. But
|
|
6187 it's too dangerous to just remove this code. --ben */
|
|
6188
|
|
6189 /* Furthermore, this code is not in FSFmacs!!!
|
|
6190 Braino on mly's part? */
|
|
6191 /* If we're unwound past the pdlcount of a catch frame,
|
|
6192 that catch can't possibly still be valid. */
|
|
6193 while (catchlist && catchlist->pdlcount > specpdl_depth_counter)
|
|
6194 {
|
|
6195 catchlist = catchlist->next;
|
|
6196 /* Don't mess with gcprolist, backtrace_list here */
|
|
6197 }
|
|
6198 #endif
|
|
6199 #endif
|
1313
|
6200
|
|
6201 if (!UNBOUNDP (oquit))
|
|
6202 Vquit_flag = oquit;
|
428
|
6203 }
|
853
|
6204 check_specbind_stack_sanity ();
|
428
|
6205 }
|
|
6206
|
|
6207
|
|
6208
|
|
6209 /* Get the value of symbol's global binding, even if that binding is
|
|
6210 not now dynamically visible. May return Qunbound or magic values. */
|
|
6211
|
|
6212 Lisp_Object
|
|
6213 top_level_value (Lisp_Object symbol)
|
|
6214 {
|
|
6215 REGISTER struct specbinding *ptr = specpdl;
|
|
6216
|
|
6217 CHECK_SYMBOL (symbol);
|
|
6218 for (; ptr != specpdl_ptr; ptr++)
|
|
6219 {
|
|
6220 if (EQ (ptr->symbol, symbol))
|
|
6221 return ptr->old_value;
|
|
6222 }
|
|
6223 return XSYMBOL (symbol)->value;
|
|
6224 }
|
|
6225
|
|
6226 #if 0
|
|
6227
|
|
6228 Lisp_Object
|
|
6229 top_level_set (Lisp_Object symbol, Lisp_Object newval)
|
|
6230 {
|
|
6231 REGISTER struct specbinding *ptr = specpdl;
|
|
6232
|
|
6233 CHECK_SYMBOL (symbol);
|
|
6234 for (; ptr != specpdl_ptr; ptr++)
|
|
6235 {
|
|
6236 if (EQ (ptr->symbol, symbol))
|
|
6237 {
|
|
6238 ptr->old_value = newval;
|
|
6239 return newval;
|
|
6240 }
|
|
6241 }
|
|
6242 return Fset (symbol, newval);
|
|
6243 }
|
|
6244
|
|
6245 #endif /* 0 */
|
|
6246
|
|
6247
|
|
6248 /************************************************************************/
|
|
6249 /* Backtraces */
|
|
6250 /************************************************************************/
|
|
6251
|
|
6252 DEFUN ("backtrace-debug", Fbacktrace_debug, 2, 2, 0, /*
|
|
6253 Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
|
|
6254 The debugger is entered when that frame exits, if the flag is non-nil.
|
|
6255 */
|
|
6256 (level, flag))
|
|
6257 {
|
|
6258 REGISTER struct backtrace *backlist = backtrace_list;
|
|
6259 REGISTER int i;
|
|
6260
|
|
6261 CHECK_INT (level);
|
|
6262
|
|
6263 for (i = 0; backlist && i < XINT (level); i++)
|
|
6264 {
|
|
6265 backlist = backlist->next;
|
|
6266 }
|
|
6267
|
|
6268 if (backlist)
|
|
6269 backlist->debug_on_exit = !NILP (flag);
|
|
6270
|
|
6271 return flag;
|
|
6272 }
|
|
6273
|
|
6274 static void
|
|
6275 backtrace_specials (int speccount, int speclimit, Lisp_Object stream)
|
|
6276 {
|
|
6277 int printing_bindings = 0;
|
|
6278
|
|
6279 for (; speccount > speclimit; speccount--)
|
|
6280 {
|
|
6281 if (specpdl[speccount - 1].func == 0
|
|
6282 || specpdl[speccount - 1].func == specbind_unwind_local
|
|
6283 || specpdl[speccount - 1].func == specbind_unwind_wasnt_local)
|
|
6284 {
|
826
|
6285 write_c_string (stream, !printing_bindings ? " # bind (" : " ");
|
428
|
6286 Fprin1 (specpdl[speccount - 1].symbol, stream);
|
|
6287 printing_bindings = 1;
|
|
6288 }
|
|
6289 else
|
|
6290 {
|
826
|
6291 if (printing_bindings) write_c_string (stream, ")\n");
|
|
6292 write_c_string (stream, " # (unwind-protect ...)\n");
|
428
|
6293 printing_bindings = 0;
|
|
6294 }
|
|
6295 }
|
826
|
6296 if (printing_bindings) write_c_string (stream, ")\n");
|
428
|
6297 }
|
|
6298
|
1292
|
6299 static Lisp_Object
|
|
6300 backtrace_unevalled_args (Lisp_Object *args)
|
|
6301 {
|
|
6302 if (args)
|
|
6303 return *args;
|
|
6304 else
|
|
6305 return list1 (build_string ("[internal]"));
|
|
6306 }
|
|
6307
|
428
|
6308 DEFUN ("backtrace", Fbacktrace, 0, 2, "", /*
|
|
6309 Print a trace of Lisp function calls currently active.
|
438
|
6310 Optional arg STREAM specifies the output stream to send the backtrace to,
|
444
|
6311 and defaults to the value of `standard-output'.
|
|
6312 Optional second arg DETAILED non-nil means show places where currently
|
|
6313 active variable bindings, catches, condition-cases, and
|
|
6314 unwind-protects, as well as function calls, were made.
|
428
|
6315 */
|
|
6316 (stream, detailed))
|
|
6317 {
|
|
6318 /* This function can GC */
|
|
6319 struct backtrace *backlist = backtrace_list;
|
|
6320 struct catchtag *catches = catchlist;
|
|
6321 int speccount = specpdl_depth();
|
|
6322
|
|
6323 int old_nl = print_escape_newlines;
|
|
6324 int old_pr = print_readably;
|
|
6325 Lisp_Object old_level = Vprint_level;
|
|
6326 Lisp_Object oiq = Vinhibit_quit;
|
|
6327 struct gcpro gcpro1, gcpro2;
|
|
6328
|
|
6329 /* We can't allow quits in here because that could cause the values
|
|
6330 of print_readably and print_escape_newlines to get screwed up.
|
|
6331 Normally we would use a record_unwind_protect but that would
|
|
6332 screw up the functioning of this function. */
|
|
6333 Vinhibit_quit = Qt;
|
|
6334
|
|
6335 entering_debugger = 0;
|
|
6336
|
872
|
6337 if (!NILP (detailed))
|
|
6338 Vprint_level = make_int (50);
|
|
6339 else
|
|
6340 Vprint_level = make_int (3);
|
428
|
6341 print_readably = 0;
|
|
6342 print_escape_newlines = 1;
|
|
6343
|
|
6344 GCPRO2 (stream, old_level);
|
|
6345
|
1261
|
6346 stream = canonicalize_printcharfun (stream);
|
428
|
6347
|
|
6348 for (;;)
|
|
6349 {
|
|
6350 if (!NILP (detailed) && catches && catches->backlist == backlist)
|
|
6351 {
|
|
6352 int catchpdl = catches->pdlcount;
|
438
|
6353 if (speccount > catchpdl
|
|
6354 && specpdl[catchpdl].func == condition_case_unwind)
|
428
|
6355 /* This is a condition-case catchpoint */
|
|
6356 catchpdl = catchpdl + 1;
|
|
6357
|
|
6358 backtrace_specials (speccount, catchpdl, stream);
|
|
6359
|
|
6360 speccount = catches->pdlcount;
|
|
6361 if (catchpdl == speccount)
|
|
6362 {
|
826
|
6363 write_c_string (stream, " # (catch ");
|
428
|
6364 Fprin1 (catches->tag, stream);
|
826
|
6365 write_c_string (stream, " ...)\n");
|
428
|
6366 }
|
|
6367 else
|
|
6368 {
|
826
|
6369 write_c_string (stream, " # (condition-case ... . ");
|
428
|
6370 Fprin1 (Fcdr (Fcar (catches->tag)), stream);
|
826
|
6371 write_c_string (stream, ")\n");
|
428
|
6372 }
|
|
6373 catches = catches->next;
|
|
6374 }
|
|
6375 else if (!backlist)
|
|
6376 break;
|
|
6377 else
|
|
6378 {
|
|
6379 if (!NILP (detailed) && backlist->pdlcount < speccount)
|
|
6380 {
|
|
6381 backtrace_specials (speccount, backlist->pdlcount, stream);
|
|
6382 speccount = backlist->pdlcount;
|
|
6383 }
|
826
|
6384 write_c_string (stream, backlist->debug_on_exit ? "* " : " ");
|
428
|
6385 if (backlist->nargs == UNEVALLED)
|
|
6386 {
|
1292
|
6387 Fprin1 (Fcons (*backlist->function,
|
|
6388 backtrace_unevalled_args (backlist->args)),
|
|
6389 stream);
|
826
|
6390 write_c_string (stream, "\n"); /* from FSFmacs 19.30 */
|
428
|
6391 }
|
|
6392 else
|
|
6393 {
|
|
6394 Lisp_Object tem = *backlist->function;
|
|
6395 Fprin1 (tem, stream); /* This can QUIT */
|
826
|
6396 write_c_string (stream, "(");
|
428
|
6397 if (backlist->nargs == MANY)
|
|
6398 {
|
|
6399 int i;
|
|
6400 Lisp_Object tail = Qnil;
|
|
6401 struct gcpro ngcpro1;
|
|
6402
|
|
6403 NGCPRO1 (tail);
|
|
6404 for (tail = *backlist->args, i = 0;
|
|
6405 !NILP (tail);
|
|
6406 tail = Fcdr (tail), i++)
|
|
6407 {
|
826
|
6408 if (i != 0) write_c_string (stream, " ");
|
428
|
6409 Fprin1 (Fcar (tail), stream);
|
|
6410 }
|
|
6411 NUNGCPRO;
|
|
6412 }
|
|
6413 else
|
|
6414 {
|
|
6415 int i;
|
|
6416 for (i = 0; i < backlist->nargs; i++)
|
|
6417 {
|
826
|
6418 if (!i && EQ (tem, Qbyte_code))
|
|
6419 {
|
|
6420 write_c_string (stream, "\"...\"");
|
|
6421 continue;
|
|
6422 }
|
|
6423 if (i != 0) write_c_string (stream, " ");
|
428
|
6424 Fprin1 (backlist->args[i], stream);
|
|
6425 }
|
|
6426 }
|
826
|
6427 write_c_string (stream, ")\n");
|
428
|
6428 }
|
|
6429 backlist = backlist->next;
|
|
6430 }
|
|
6431 }
|
|
6432 Vprint_level = old_level;
|
|
6433 print_readably = old_pr;
|
|
6434 print_escape_newlines = old_nl;
|
|
6435 UNGCPRO;
|
|
6436 Vinhibit_quit = oiq;
|
|
6437 return Qnil;
|
|
6438 }
|
|
6439
|
|
6440
|
444
|
6441 DEFUN ("backtrace-frame", Fbacktrace_frame, 1, 1, 0, /*
|
|
6442 Return the function and arguments NFRAMES up from current execution point.
|
428
|
6443 If that frame has not evaluated the arguments yet (or is a special form),
|
|
6444 the value is (nil FUNCTION ARG-FORMS...).
|
|
6445 If that frame has evaluated its arguments and called its function already,
|
|
6446 the value is (t FUNCTION ARG-VALUES...).
|
|
6447 A &rest arg is represented as the tail of the list ARG-VALUES.
|
|
6448 FUNCTION is whatever was supplied as car of evaluated list,
|
|
6449 or a lambda expression for macro calls.
|
444
|
6450 If NFRAMES is more than the number of frames, the value is nil.
|
428
|
6451 */
|
|
6452 (nframes))
|
|
6453 {
|
|
6454 REGISTER struct backtrace *backlist = backtrace_list;
|
|
6455 REGISTER int i;
|
|
6456 Lisp_Object tem;
|
|
6457
|
|
6458 CHECK_NATNUM (nframes);
|
|
6459
|
|
6460 /* Find the frame requested. */
|
|
6461 for (i = XINT (nframes); backlist && (i-- > 0);)
|
|
6462 backlist = backlist->next;
|
|
6463
|
|
6464 if (!backlist)
|
|
6465 return Qnil;
|
|
6466 if (backlist->nargs == UNEVALLED)
|
1292
|
6467 return Fcons (Qnil, Fcons (*backlist->function,
|
|
6468 backtrace_unevalled_args (backlist->args)));
|
428
|
6469 else
|
|
6470 {
|
|
6471 if (backlist->nargs == MANY)
|
|
6472 tem = *backlist->args;
|
|
6473 else
|
|
6474 tem = Flist (backlist->nargs, backlist->args);
|
|
6475
|
|
6476 return Fcons (Qt, Fcons (*backlist->function, tem));
|
|
6477 }
|
|
6478 }
|
|
6479
|
|
6480
|
|
6481 /************************************************************************/
|
|
6482 /* Warnings */
|
|
6483 /************************************************************************/
|
|
6484
|
1123
|
6485 static int
|
|
6486 warning_will_be_discarded (Lisp_Object level)
|
|
6487 {
|
|
6488 /* Don't even generate debug warnings if they're going to be discarded,
|
|
6489 to avoid excessive consing. */
|
|
6490 return (EQ (level, Qdebug) && !NILP (Vlog_warning_minimum_level) &&
|
|
6491 !EQ (Vlog_warning_minimum_level, Qdebug));
|
|
6492 }
|
|
6493
|
428
|
6494 void
|
1204
|
6495 warn_when_safe_lispobj (Lisp_Object class_, Lisp_Object level,
|
428
|
6496 Lisp_Object obj)
|
|
6497 {
|
1123
|
6498 if (warning_will_be_discarded (level))
|
793
|
6499 return;
|
1123
|
6500
|
1204
|
6501 obj = list1 (list3 (class_, level, obj));
|
428
|
6502 if (NILP (Vpending_warnings))
|
|
6503 Vpending_warnings = Vpending_warnings_tail = obj;
|
|
6504 else
|
|
6505 {
|
|
6506 Fsetcdr (Vpending_warnings_tail, obj);
|
|
6507 Vpending_warnings_tail = obj;
|
|
6508 }
|
|
6509 }
|
|
6510
|
|
6511 /* #### This should probably accept Lisp objects; but then we have
|
|
6512 to make sure that Feval() isn't called, since it might not be safe.
|
|
6513
|
|
6514 An alternative approach is to just pass some non-string type of
|
|
6515 Lisp_Object to warn_when_safe_lispobj(); `prin1-to-string' will
|
|
6516 automatically be called when it is safe to do so. */
|
|
6517
|
|
6518 void
|
1204
|
6519 warn_when_safe (Lisp_Object class_, Lisp_Object level, const CIbyte *fmt, ...)
|
428
|
6520 {
|
|
6521 Lisp_Object obj;
|
|
6522 va_list args;
|
|
6523
|
1123
|
6524 if (warning_will_be_discarded (level))
|
793
|
6525 return;
|
1123
|
6526
|
428
|
6527 va_start (args, fmt);
|
771
|
6528 obj = emacs_vsprintf_string (CGETTEXT (fmt), args);
|
428
|
6529 va_end (args);
|
|
6530
|
1204
|
6531 warn_when_safe_lispobj (class_, level, obj);
|
428
|
6532 }
|
|
6533
|
|
6534
|
|
6535
|
|
6536
|
|
6537 /************************************************************************/
|
|
6538 /* Initialization */
|
|
6539 /************************************************************************/
|
|
6540
|
|
6541 void
|
|
6542 syms_of_eval (void)
|
|
6543 {
|
442
|
6544 INIT_LRECORD_IMPLEMENTATION (subr);
|
|
6545
|
563
|
6546 DEFSYMBOL (Qinhibit_quit);
|
|
6547 DEFSYMBOL (Qautoload);
|
|
6548 DEFSYMBOL (Qdebug_on_error);
|
|
6549 DEFSYMBOL (Qstack_trace_on_error);
|
|
6550 DEFSYMBOL (Qdebug_on_signal);
|
|
6551 DEFSYMBOL (Qstack_trace_on_signal);
|
|
6552 DEFSYMBOL (Qdebugger);
|
|
6553 DEFSYMBOL (Qmacro);
|
428
|
6554 defsymbol (&Qand_rest, "&rest");
|
|
6555 defsymbol (&Qand_optional, "&optional");
|
|
6556 /* Note that the process code also uses Qexit */
|
563
|
6557 DEFSYMBOL (Qexit);
|
|
6558 DEFSYMBOL (Qsetq);
|
|
6559 DEFSYMBOL (Qinteractive);
|
|
6560 DEFSYMBOL (Qcommandp);
|
|
6561 DEFSYMBOL (Qdefun);
|
|
6562 DEFSYMBOL (Qprogn);
|
|
6563 DEFSYMBOL (Qvalues);
|
|
6564 DEFSYMBOL (Qdisplay_warning);
|
|
6565 DEFSYMBOL (Qrun_hooks);
|
887
|
6566 DEFSYMBOL (Qfinalize_list);
|
563
|
6567 DEFSYMBOL (Qif);
|
428
|
6568
|
|
6569 DEFSUBR (For);
|
|
6570 DEFSUBR (Fand);
|
|
6571 DEFSUBR (Fif);
|
|
6572 DEFSUBR_MACRO (Fwhen);
|
|
6573 DEFSUBR_MACRO (Funless);
|
|
6574 DEFSUBR (Fcond);
|
|
6575 DEFSUBR (Fprogn);
|
|
6576 DEFSUBR (Fprog1);
|
|
6577 DEFSUBR (Fprog2);
|
|
6578 DEFSUBR (Fsetq);
|
|
6579 DEFSUBR (Fquote);
|
|
6580 DEFSUBR (Ffunction);
|
|
6581 DEFSUBR (Fdefun);
|
|
6582 DEFSUBR (Fdefmacro);
|
|
6583 DEFSUBR (Fdefvar);
|
|
6584 DEFSUBR (Fdefconst);
|
|
6585 DEFSUBR (Fuser_variable_p);
|
|
6586 DEFSUBR (Flet);
|
|
6587 DEFSUBR (FletX);
|
|
6588 DEFSUBR (Fwhile);
|
|
6589 DEFSUBR (Fmacroexpand_internal);
|
|
6590 DEFSUBR (Fcatch);
|
|
6591 DEFSUBR (Fthrow);
|
|
6592 DEFSUBR (Funwind_protect);
|
|
6593 DEFSUBR (Fcondition_case);
|
|
6594 DEFSUBR (Fcall_with_condition_handler);
|
|
6595 DEFSUBR (Fsignal);
|
|
6596 DEFSUBR (Finteractive_p);
|
|
6597 DEFSUBR (Fcommandp);
|
|
6598 DEFSUBR (Fcommand_execute);
|
|
6599 DEFSUBR (Fautoload);
|
|
6600 DEFSUBR (Feval);
|
|
6601 DEFSUBR (Fapply);
|
|
6602 DEFSUBR (Ffuncall);
|
|
6603 DEFSUBR (Ffunctionp);
|
|
6604 DEFSUBR (Ffunction_min_args);
|
|
6605 DEFSUBR (Ffunction_max_args);
|
|
6606 DEFSUBR (Frun_hooks);
|
|
6607 DEFSUBR (Frun_hook_with_args);
|
|
6608 DEFSUBR (Frun_hook_with_args_until_success);
|
|
6609 DEFSUBR (Frun_hook_with_args_until_failure);
|
|
6610 DEFSUBR (Fbacktrace_debug);
|
|
6611 DEFSUBR (Fbacktrace);
|
|
6612 DEFSUBR (Fbacktrace_frame);
|
|
6613 }
|
|
6614
|
|
6615 void
|
814
|
6616 init_eval_semi_early (void)
|
428
|
6617 {
|
|
6618 specpdl_ptr = specpdl;
|
|
6619 specpdl_depth_counter = 0;
|
|
6620 catchlist = 0;
|
|
6621 Vcondition_handlers = Qnil;
|
|
6622 backtrace_list = 0;
|
|
6623 Vquit_flag = Qnil;
|
|
6624 debug_on_next_call = 0;
|
|
6625 lisp_eval_depth = 0;
|
|
6626 entering_debugger = 0;
|
|
6627 }
|
|
6628
|
|
6629 void
|
|
6630 reinit_vars_of_eval (void)
|
|
6631 {
|
|
6632 preparing_for_armageddon = 0;
|
|
6633 in_warnings = 0;
|
|
6634 specpdl_size = 50;
|
|
6635 specpdl = xnew_array (struct specbinding, specpdl_size);
|
|
6636 /* XEmacs change: increase these values. */
|
|
6637 max_specpdl_size = 3000;
|
442
|
6638 max_lisp_eval_depth = 1000;
|
|
6639 #ifdef DEFEND_AGAINST_THROW_RECURSION
|
428
|
6640 throw_level = 0;
|
|
6641 #endif
|
2367
|
6642 init_eval_semi_early ();
|
428
|
6643 }
|
|
6644
|
|
6645 void
|
|
6646 vars_of_eval (void)
|
|
6647 {
|
|
6648 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size /*
|
|
6649 Limit on number of Lisp variable bindings & unwind-protects before error.
|
|
6650 */ );
|
|
6651
|
|
6652 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth /*
|
|
6653 Limit on depth in `eval', `apply' and `funcall' before error.
|
|
6654 This limit is to catch infinite recursions for you before they cause
|
|
6655 actual stack overflow in C, which would be fatal for Emacs.
|
|
6656 You can safely make it considerably larger than its default value,
|
|
6657 if that proves inconveniently small.
|
|
6658 */ );
|
|
6659
|
|
6660 DEFVAR_LISP ("quit-flag", &Vquit_flag /*
|
853
|
6661 t causes running Lisp code to abort, unless `inhibit-quit' is non-nil.
|
|
6662 `critical' causes running Lisp code to abort regardless of `inhibit-quit'.
|
|
6663 Normally, you do not need to set this value yourself. It is set to
|
|
6664 t each time a Control-G is detected, and to `critical' each time a
|
|
6665 Shift-Control-G is detected. The XEmacs core C code is littered with
|
|
6666 calls to the QUIT; macro, which check the values of `quit-flag' and
|
2500
|
6667 `inhibit-quit' and ABORT (or more accurately, call (signal 'quit)) if
|
853
|
6668 it's correct to do so.
|
428
|
6669 */ );
|
|
6670 Vquit_flag = Qnil;
|
|
6671
|
|
6672 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit /*
|
|
6673 Non-nil inhibits C-g quitting from happening immediately.
|
|
6674 Note that `quit-flag' will still be set by typing C-g,
|
|
6675 so a quit will be signalled as soon as `inhibit-quit' is nil.
|
|
6676 To prevent this happening, set `quit-flag' to nil
|
853
|
6677 before making `inhibit-quit' nil.
|
|
6678
|
|
6679 The value of `inhibit-quit' is ignored if a critical quit is
|
|
6680 requested by typing control-shift-G in a window-system frame;
|
|
6681 this is explained in more detail in `quit-flag'.
|
428
|
6682 */ );
|
|
6683 Vinhibit_quit = Qnil;
|
|
6684
|
|
6685 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error /*
|
|
6686 *Non-nil means automatically display a backtrace buffer
|
|
6687 after any error that is not handled by a `condition-case'.
|
|
6688 If the value is a list, an error only means to display a backtrace
|
|
6689 if one of its condition symbols appears in the list.
|
|
6690 See also variable `stack-trace-on-signal'.
|
|
6691 */ );
|
|
6692 Vstack_trace_on_error = Qnil;
|
|
6693
|
|
6694 DEFVAR_LISP ("stack-trace-on-signal", &Vstack_trace_on_signal /*
|
|
6695 *Non-nil means automatically display a backtrace buffer
|
|
6696 after any error that is signalled, whether or not it is handled by
|
|
6697 a `condition-case'.
|
|
6698 If the value is a list, an error only means to display a backtrace
|
|
6699 if one of its condition symbols appears in the list.
|
|
6700 See also variable `stack-trace-on-error'.
|
|
6701 */ );
|
|
6702 Vstack_trace_on_signal = Qnil;
|
|
6703
|
|
6704 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors /*
|
|
6705 *List of errors for which the debugger should not be called.
|
|
6706 Each element may be a condition-name or a regexp that matches error messages.
|
|
6707 If any element applies to a given error, that error skips the debugger
|
|
6708 and just returns to top level.
|
|
6709 This overrides the variable `debug-on-error'.
|
|
6710 It does not apply to errors handled by `condition-case'.
|
|
6711 */ );
|
|
6712 Vdebug_ignored_errors = Qnil;
|
|
6713
|
|
6714 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error /*
|
|
6715 *Non-nil means enter debugger if an unhandled error is signalled.
|
|
6716 The debugger will not be entered if the error is handled by
|
|
6717 a `condition-case'.
|
|
6718 If the value is a list, an error only means to enter the debugger
|
|
6719 if one of its condition symbols appears in the list.
|
|
6720 This variable is overridden by `debug-ignored-errors'.
|
|
6721 See also variables `debug-on-quit' and `debug-on-signal'.
|
1123
|
6722
|
|
6723 If this variable is set while XEmacs is running noninteractively (using
|
|
6724 `-batch'), and XEmacs was configured with `--debug' (#define XEMACS_DEBUG
|
|
6725 in the C code), instead of trying to invoke the Lisp debugger (which
|
|
6726 obviously won't work), XEmacs will break out to a C debugger using
|
|
6727 \(force-debugging-signal t). This is useful because debugging
|
|
6728 noninteractive runs of XEmacs is often very difficult, since they typically
|
|
6729 happen as part of sometimes large and complex make suites (e.g. rebuilding
|
2500
|
6730 the XEmacs packages). NOTE: This runs ABORT()!!! (As well as and after
|
1123
|
6731 executing INT 3 under MS Windows, which should invoke a debugger if it's
|
|
6732 active.) This is guaranteed to kill XEmacs! (But in this situation, XEmacs
|
|
6733 is about to die anyway, and if no debugger is present, this will usefully
|
|
6734 dump core.) The most useful way to set this flag when debugging
|
|
6735 noninteractive runs, especially in makefiles, is using the environment
|
|
6736 variable XEMACSDEBUG, like this:
|
771
|
6737
|
|
6738 \(using csh) setenv XEMACSDEBUG '(setq debug-on-error t)'
|
|
6739 \(using bash) export XEMACSDEBUG='(setq debug-on-error t)'
|
428
|
6740 */ );
|
|
6741 Vdebug_on_error = Qnil;
|
|
6742
|
|
6743 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal /*
|
|
6744 *Non-nil means enter debugger if an error is signalled.
|
|
6745 The debugger will be entered whether or not the error is handled by
|
|
6746 a `condition-case'.
|
|
6747 If the value is a list, an error only means to enter the debugger
|
|
6748 if one of its condition symbols appears in the list.
|
|
6749 See also variable `debug-on-quit'.
|
1123
|
6750
|
|
6751 This will attempt to enter a C debugger when XEmacs is run noninteractively
|
|
6752 and under the same conditions as described in `debug-on-error'.
|
428
|
6753 */ );
|
|
6754 Vdebug_on_signal = Qnil;
|
|
6755
|
|
6756 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit /*
|
|
6757 *Non-nil means enter debugger if quit is signalled (C-G, for example).
|
|
6758 Does not apply if quit is handled by a `condition-case'. Entering the
|
|
6759 debugger can also be achieved at any time (for X11 console) by typing
|
|
6760 control-shift-G to signal a critical quit.
|
|
6761 */ );
|
|
6762 debug_on_quit = 0;
|
|
6763
|
|
6764 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call /*
|
|
6765 Non-nil means enter debugger before next `eval', `apply' or `funcall'.
|
|
6766 */ );
|
|
6767
|
1292
|
6768 DEFVAR_BOOL ("backtrace-with-interal-sections",
|
|
6769 &backtrace_with_internal_sections /*
|
|
6770 Non-nil means backtraces will contain additional information indicating
|
|
6771 when particular sections of the C code have been entered, e.g. redisplay(),
|
|
6772 byte-char conversion, internal-external conversion, etc. This can be
|
|
6773 particularly useful when XEmacs crashes, in helping to pinpoint the problem.
|
|
6774 */ );
|
|
6775 #ifdef ERROR_CHECK_STRUCTURES
|
|
6776 backtrace_with_internal_sections = 1;
|
|
6777 #else
|
|
6778 backtrace_with_internal_sections = 0;
|
|
6779 #endif
|
|
6780
|
428
|
6781 DEFVAR_LISP ("debugger", &Vdebugger /*
|
|
6782 Function to call to invoke debugger.
|
|
6783 If due to frame exit, args are `exit' and the value being returned;
|
|
6784 this function's value will be returned instead of that.
|
|
6785 If due to error, args are `error' and a list of the args to `signal'.
|
|
6786 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
6787 If due to `eval' entry, one arg, t.
|
|
6788 */ );
|
|
6789 Vdebugger = Qnil;
|
|
6790
|
853
|
6791 staticpro (&Vcatch_everything_tag);
|
|
6792 Vcatch_everything_tag = make_opaque (OPAQUE_CLEAR, 0);
|
|
6793
|
428
|
6794 staticpro (&Vpending_warnings);
|
|
6795 Vpending_warnings = Qnil;
|
1204
|
6796 dump_add_root_lisp_object (&Vpending_warnings_tail);
|
428
|
6797 Vpending_warnings_tail = Qnil;
|
|
6798
|
793
|
6799 DEFVAR_LISP ("log-warning-minimum-level", &Vlog_warning_minimum_level);
|
|
6800 Vlog_warning_minimum_level = Qinfo;
|
|
6801
|
428
|
6802 staticpro (&Vautoload_queue);
|
|
6803 Vautoload_queue = Qnil;
|
|
6804
|
|
6805 staticpro (&Vcondition_handlers);
|
|
6806
|
853
|
6807 staticpro (&Vdeletable_permanent_display_objects);
|
|
6808 Vdeletable_permanent_display_objects = Qnil;
|
|
6809
|
|
6810 staticpro (&Vmodifiable_buffers);
|
|
6811 Vmodifiable_buffers = Qnil;
|
|
6812
|
|
6813 inhibit_flags = 0;
|
|
6814 }
|