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