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