aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c195
1 files changed, 97 insertions, 98 deletions
diff --git a/src/eval.c b/src/eval.c
index 90d0df61858..4a3f5083b3b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1,5 +1,5 @@
1/* Evaluator for GNU Emacs Lisp interpreter. 1/* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985-1987, 1993-1995, 1999-2011 Free Software Foundation, Inc. 2 Copyright (C) 1985-1987, 1993-1995, 1999-2012 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -124,6 +124,12 @@ Lisp_Object Vsignaling_function;
124 124
125int handling_signal; 125int handling_signal;
126 126
127/* If non-nil, Lisp code must not be run since some part of Emacs is
128 in an inconsistent state. Currently, x-create-frame uses this to
129 avoid triggering window-configuration-change-hook while the new
130 frame is half-initialized. */
131Lisp_Object inhibit_lisp_code;
132
127static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *); 133static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
128static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN; 134static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN;
129static int interactive_p (int); 135static int interactive_p (int);
@@ -133,8 +139,9 @@ static Lisp_Object Ffetch_bytecode (Lisp_Object);
133void 139void
134init_eval_once (void) 140init_eval_once (void)
135{ 141{
136 specpdl_size = 50; 142 enum { size = 50 };
137 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding)); 143 specpdl = (struct specbinding *) xmalloc (size * sizeof (struct specbinding));
144 specpdl_size = size;
138 specpdl_ptr = specpdl; 145 specpdl_ptr = specpdl;
139 /* Don't forget to update docs (lispref node "Local Variables"). */ 146 /* Don't forget to update docs (lispref node "Local Variables"). */
140 max_specpdl_size = 1300; /* 1000 is not enough for CEDET's c-by.el. */ 147 max_specpdl_size = 1300; /* 1000 is not enough for CEDET's c-by.el. */
@@ -192,7 +199,7 @@ call_debugger (Lisp_Object arg)
192 if (lisp_eval_depth + 40 > max_lisp_eval_depth) 199 if (lisp_eval_depth + 40 > max_lisp_eval_depth)
193 max_lisp_eval_depth = lisp_eval_depth + 40; 200 max_lisp_eval_depth = lisp_eval_depth + 40;
194 201
195 if (SPECPDL_INDEX () + 100 > max_specpdl_size) 202 if (max_specpdl_size - 100 < SPECPDL_INDEX ())
196 max_specpdl_size = SPECPDL_INDEX () + 100; 203 max_specpdl_size = SPECPDL_INDEX () + 100;
197 204
198#ifdef HAVE_WINDOW_SYSTEM 205#ifdef HAVE_WINDOW_SYSTEM
@@ -466,7 +473,7 @@ usage: (setq [SYM VAL]...) */)
466 473
467 args_left = Fcdr (Fcdr (args_left)); 474 args_left = Fcdr (Fcdr (args_left));
468 } 475 }
469 while (!NILP(args_left)); 476 while (!NILP (args_left));
470 477
471 UNGCPRO; 478 UNGCPRO;
472 return val; 479 return val;
@@ -474,6 +481,14 @@ usage: (setq [SYM VAL]...) */)
474 481
475DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0, 482DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
476 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'. 483 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
484Warning: `quote' does not construct its return value, but just returns
485the value that was pre-constructed by the Lisp reader (see info node
486`(elisp)Printed Representation').
487This means that '(a . b) is not identical to (cons 'a 'b): the former
488does not cons. Quoting should be reserved for constants that will
489never be modified by side-effects, unless you like self-modifying code.
490See the common pitfall in info node `(elisp)Rearrangement' for an example
491of unexpected results when a quoted object is modified.
477usage: (quote ARG) */) 492usage: (quote ARG) */)
478 (Lisp_Object args) 493 (Lisp_Object args)
479{ 494{
@@ -771,17 +786,15 @@ The return value is BASE-VARIABLE. */)
771 786
772DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, 787DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
773 doc: /* Define SYMBOL as a variable, and return SYMBOL. 788 doc: /* Define SYMBOL as a variable, and return SYMBOL.
774You are not required to define a variable in order to use it, 789You are not required to define a variable in order to use it, but
775but the definition can supply documentation and an initial value 790defining it lets you supply an initial value and documentation, which
776in a way that tags can recognize. 791can be referred to by the Emacs help facilities and other programming
777 792tools. The `defvar' form also declares the variable as \"special\",
778INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void. 793so that it is always dynamically bound even if `lexical-binding' is t.
779If SYMBOL is buffer-local, its default value is what is set; 794
780 buffer-local values are not affected. 795The optional argument INITVALUE is evaluated, and used to set SYMBOL,
781INITVALUE and DOCSTRING are optional. 796only if SYMBOL's value is void. If SYMBOL is buffer-local, its
782If DOCSTRING starts with *, this variable is identified as a user option. 797default value is what is set; buffer-local values are not affected.
783 This means that M-x set-variable recognizes it.
784 See also `user-variable-p'.
785If INITVALUE is missing, SYMBOL's value is not set. 798If INITVALUE is missing, SYMBOL's value is not set.
786 799
787If SYMBOL has a local binding, then this form affects the local 800If SYMBOL has a local binding, then this form affects the local
@@ -790,6 +803,13 @@ load a file defining variables, with this form or with `defconst' or
790`defcustom', you should always load that file _outside_ any bindings 803`defcustom', you should always load that file _outside_ any bindings
791for these variables. \(`defconst' and `defcustom' behave similarly in 804for these variables. \(`defconst' and `defcustom' behave similarly in
792this respect.) 805this respect.)
806
807The optional argument DOCSTRING is a documentation string for the
808variable.
809
810To define a user option, use `defcustom' instead of `defvar'.
811The function `user-variable-p' also identifies a variable as a user
812option if its DOCSTRING starts with *, but this behavior is obsolete.
793usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) 813usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
794 (Lisp_Object args) 814 (Lisp_Object args)
795{ 815{
@@ -864,15 +884,19 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
864 884
865DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0, 885DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
866 doc: /* Define SYMBOL as a constant variable. 886 doc: /* Define SYMBOL as a constant variable.
867The intent is that neither programs nor users should ever change this value. 887This declares that neither programs nor users should ever change the
868Always sets the value of SYMBOL to the result of evalling INITVALUE. 888value. This constancy is not actually enforced by Emacs Lisp, but
869If SYMBOL is buffer-local, its default value is what is set; 889SYMBOL is marked as a special variable so that it is never lexically
870 buffer-local values are not affected. 890bound.
871DOCSTRING is optional. 891
872 892The `defconst' form always sets the value of SYMBOL to the result of
873If SYMBOL has a local binding, then this form sets the local binding's 893evalling INITVALUE. If SYMBOL is buffer-local, its default value is
874value. However, you should normally not make local bindings for 894what is set; buffer-local values are not affected. If SYMBOL has a
875variables defined with this form. 895local binding, then this form sets the local binding's value.
896However, you should normally not make local bindings for variables
897defined with this form.
898
899The optional DOCSTRING specifies the variable's documentation string.
876usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */) 900usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
877 (Lisp_Object args) 901 (Lisp_Object args)
878{ 902{
@@ -917,13 +941,14 @@ lisp_indirect_variable (Lisp_Object sym)
917DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0, 941DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
918 doc: /* Return t if VARIABLE is intended to be set and modified by users. 942 doc: /* Return t if VARIABLE is intended to be set and modified by users.
919\(The alternative is a variable used internally in a Lisp program.) 943\(The alternative is a variable used internally in a Lisp program.)
920A variable is a user variable if 944
921\(1) the first character of its documentation is `*', or 945This function returns t if (i) the first character of its
922\(2) it is customizable (its property list contains a non-nil value 946documentation is `*', or (ii) it is customizable (its property list
923 of `standard-value' or `custom-autoload'), or 947contains a non-nil value of `standard-value' or `custom-autoload'), or
924\(3) it is an alias for another user variable. 948\(iii) it is an alias for a user variable.
925Return nil if VARIABLE is an alias and there is a loop in the 949
926chain of symbols. */) 950But condition (i) is considered obsolete, so for most purposes this is
951equivalent to `custom-variable-p'. */)
927 (Lisp_Object variable) 952 (Lisp_Object variable)
928{ 953{
929 Lisp_Object documentation; 954 Lisp_Object documentation;
@@ -1357,8 +1382,12 @@ A handler is applicable to an error
1357if CONDITION-NAME is one of the error's condition names. 1382if CONDITION-NAME is one of the error's condition names.
1358If an error happens, the first applicable handler is run. 1383If an error happens, the first applicable handler is run.
1359 1384
1360The car of a handler may be a list of condition names 1385The car of a handler may be a list of condition names instead of a
1361instead of a single condition name. Then it handles all of them. 1386single condition name; then it handles all of them. If the special
1387condition name `debug' is present in this list, it allows another
1388condition in the list to run the debugger if `debug-on-error' and the
1389other usual mechanisms says it should (otherwise, `condition-case'
1390suppresses the debugger).
1362 1391
1363When a handler handles an error, control returns to the `condition-case' 1392When a handler handles an error, control returns to the `condition-case'
1364and it executes the handler's BODY... 1393and it executes the handler's BODY...
@@ -1461,13 +1490,6 @@ internal_condition_case (Lisp_Object (*bfun) (void), Lisp_Object handlers,
1461 struct catchtag c; 1490 struct catchtag c;
1462 struct handler h; 1491 struct handler h;
1463 1492
1464 /* Since Fsignal will close off all calls to x_catch_errors,
1465 we will get the wrong results if some are not closed now. */
1466#if HAVE_X_WINDOWS
1467 if (x_catching_errors ())
1468 abort ();
1469#endif
1470
1471 c.tag = Qnil; 1493 c.tag = Qnil;
1472 c.val = Qnil; 1494 c.val = Qnil;
1473 c.backlist = backtrace_list; 1495 c.backlist = backtrace_list;
@@ -1506,13 +1528,6 @@ internal_condition_case_1 (Lisp_Object (*bfun) (Lisp_Object), Lisp_Object arg,
1506 struct catchtag c; 1528 struct catchtag c;
1507 struct handler h; 1529 struct handler h;
1508 1530
1509 /* Since Fsignal will close off all calls to x_catch_errors,
1510 we will get the wrong results if some are not closed now. */
1511#if HAVE_X_WINDOWS
1512 if (x_catching_errors ())
1513 abort ();
1514#endif
1515
1516 c.tag = Qnil; 1531 c.tag = Qnil;
1517 c.val = Qnil; 1532 c.val = Qnil;
1518 c.backlist = backtrace_list; 1533 c.backlist = backtrace_list;
@@ -1555,13 +1570,6 @@ internal_condition_case_2 (Lisp_Object (*bfun) (Lisp_Object, Lisp_Object),
1555 struct catchtag c; 1570 struct catchtag c;
1556 struct handler h; 1571 struct handler h;
1557 1572
1558 /* Since Fsignal will close off all calls to x_catch_errors,
1559 we will get the wrong results if some are not closed now. */
1560#if HAVE_X_WINDOWS
1561 if (x_catching_errors ())
1562 abort ();
1563#endif
1564
1565 c.tag = Qnil; 1573 c.tag = Qnil;
1566 c.val = Qnil; 1574 c.val = Qnil;
1567 c.backlist = backtrace_list; 1575 c.backlist = backtrace_list;
@@ -1604,13 +1612,6 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1604 struct catchtag c; 1612 struct catchtag c;
1605 struct handler h; 1613 struct handler h;
1606 1614
1607 /* Since Fsignal will close off all calls to x_catch_errors,
1608 we will get the wrong results if some are not closed now. */
1609#if HAVE_X_WINDOWS
1610 if (x_catching_errors ())
1611 abort ();
1612#endif
1613
1614 c.tag = Qnil; 1615 c.tag = Qnil;
1615 c.val = Qnil; 1616 c.val = Qnil;
1616 c.backlist = backtrace_list; 1617 c.backlist = backtrace_list;
@@ -1644,6 +1645,18 @@ static Lisp_Object find_handler_clause (Lisp_Object, Lisp_Object);
1644static int maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, 1645static int maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig,
1645 Lisp_Object data); 1646 Lisp_Object data);
1646 1647
1648void
1649process_quit_flag (void)
1650{
1651 Lisp_Object flag = Vquit_flag;
1652 Vquit_flag = Qnil;
1653 if (EQ (flag, Qkill_emacs))
1654 Fkill_emacs (Qnil);
1655 if (EQ (Vthrow_on_input, flag))
1656 Fthrow (Vthrow_on_input, Qt);
1657 Fsignal (Qquit, Qnil);
1658}
1659
1647DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0, 1660DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
1648 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA. 1661 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1649This function does not return. 1662This function does not return.
@@ -1727,6 +1740,10 @@ See also the function `condition-case'. */)
1727 && (!NILP (Vdebug_on_signal) 1740 && (!NILP (Vdebug_on_signal)
1728 /* If no handler is present now, try to run the debugger. */ 1741 /* If no handler is present now, try to run the debugger. */
1729 || NILP (clause) 1742 || NILP (clause)
1743 /* A `debug' symbol in the handler list disables the normal
1744 suppression of the debugger. */
1745 || (CONSP (clause) && CONSP (XCAR (clause))
1746 && !NILP (Fmemq (Qdebug, XCAR (clause))))
1730 /* Special handler that means "print a message and run debugger 1747 /* Special handler that means "print a message and run debugger
1731 if requested". */ 1748 if requested". */
1732 || EQ (h->handler, Qerror))) 1749 || EQ (h->handler, Qerror)))
@@ -1968,37 +1985,13 @@ void
1968verror (const char *m, va_list ap) 1985verror (const char *m, va_list ap)
1969{ 1986{
1970 char buf[4000]; 1987 char buf[4000];
1971 size_t size = sizeof buf; 1988 ptrdiff_t size = sizeof buf;
1972 size_t size_max = STRING_BYTES_BOUND + 1; 1989 ptrdiff_t size_max = STRING_BYTES_BOUND + 1;
1973 size_t mlen = strlen (m);
1974 char *buffer = buf; 1990 char *buffer = buf;
1975 size_t used; 1991 ptrdiff_t used;
1976 Lisp_Object string; 1992 Lisp_Object string;
1977 1993
1978 while (1) 1994 used = evxprintf (&buffer, &size, buf, size_max, m, ap);
1979 {
1980 va_list ap_copy;
1981 va_copy (ap_copy, ap);
1982 used = doprnt (buffer, size, m, m + mlen, ap_copy);
1983 va_end (ap_copy);
1984
1985 /* Note: the -1 below is because `doprnt' returns the number of bytes
1986 excluding the terminating null byte, and it always terminates with a
1987 null byte, even when producing a truncated message. */
1988 if (used < size - 1)
1989 break;
1990 if (size <= size_max / 2)
1991 size *= 2;
1992 else if (size < size_max)
1993 size = size_max;
1994 else
1995 break; /* and leave the message truncated */
1996
1997 if (buffer != buf)
1998 xfree (buffer);
1999 buffer = (char *) xmalloc (size);
2000 }
2001
2002 string = make_string (buffer, used); 1995 string = make_string (buffer, used);
2003 if (buffer != buf) 1996 if (buffer != buf)
2004 xfree (buffer); 1997 xfree (buffer);
@@ -3274,17 +3267,21 @@ static void
3274grow_specpdl (void) 3267grow_specpdl (void)
3275{ 3268{
3276 register int count = SPECPDL_INDEX (); 3269 register int count = SPECPDL_INDEX ();
3277 if (specpdl_size >= max_specpdl_size) 3270 int max_size =
3271 min (max_specpdl_size,
3272 min (max (PTRDIFF_MAX, SIZE_MAX) / sizeof (struct specbinding),
3273 INT_MAX));
3274 int size;
3275 if (max_size <= specpdl_size)
3278 { 3276 {
3279 if (max_specpdl_size < 400) 3277 if (max_specpdl_size < 400)
3280 max_specpdl_size = 400; 3278 max_size = max_specpdl_size = 400;
3281 if (specpdl_size >= max_specpdl_size) 3279 if (max_size <= specpdl_size)
3282 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil); 3280 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil);
3283 } 3281 }
3284 specpdl_size *= 2; 3282 size = specpdl_size < max_size / 2 ? 2 * specpdl_size : max_size;
3285 if (specpdl_size > max_specpdl_size) 3283 specpdl = xnrealloc (specpdl, size, sizeof *specpdl);
3286 specpdl_size = max_specpdl_size; 3284 specpdl_size = size;
3287 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
3288 specpdl_ptr = specpdl + count; 3285 specpdl_ptr = specpdl + count;
3289} 3286}
3290 3287
@@ -3764,7 +3761,7 @@ When lexical binding is not being used, this variable is nil.
3764A value of `(t)' indicates an empty environment, otherwise it is an 3761A value of `(t)' indicates an empty environment, otherwise it is an
3765alist of active lexical bindings. */); 3762alist of active lexical bindings. */);
3766 Vinternal_interpreter_environment = Qnil; 3763 Vinternal_interpreter_environment = Qnil;
3767 /* Don't export this variable to Elisp, so noone can mess with it 3764 /* Don't export this variable to Elisp, so no one can mess with it
3768 (Just imagine if someone makes it buffer-local). */ 3765 (Just imagine if someone makes it buffer-local). */
3769 Funintern (Qinternal_interpreter_environment, Qnil); 3766 Funintern (Qinternal_interpreter_environment, Qnil);
3770 3767
@@ -3775,6 +3772,8 @@ alist of active lexical bindings. */);
3775 staticpro (&Vsignaling_function); 3772 staticpro (&Vsignaling_function);
3776 Vsignaling_function = Qnil; 3773 Vsignaling_function = Qnil;
3777 3774
3775 inhibit_lisp_code = Qnil;
3776
3778 defsubr (&Sor); 3777 defsubr (&Sor);
3779 defsubr (&Sand); 3778 defsubr (&Sand);
3780 defsubr (&Sif); 3779 defsubr (&Sif);