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