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