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