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