comparison src/eval.c @ 83644:0ece58f6e0aa

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 803-813) - Update from CVS - Merge from emacs--rel--22 * emacs--rel--22 (patch 51-58) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 233-236) - Merge from emacs--devo--0 - Update from CVS Revision: emacs@sv.gnu.org/emacs--multi-tty--0--patch-25
author Miles Bader <miles@gnu.org>
date Sun, 15 Jul 2007 02:05:20 +0000
parents b8d9a391daf3 f533b796856e
children fd5b4a865d1d
comparison
equal deleted inserted replaced
83643:70b38dec13a1 83644:0ece58f6e0aa
95 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun; 95 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
96 Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag; 96 Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag;
97 Lisp_Object Qand_rest, Qand_optional; 97 Lisp_Object Qand_rest, Qand_optional;
98 Lisp_Object Qdebug_on_error; 98 Lisp_Object Qdebug_on_error;
99 Lisp_Object Qdeclare; 99 Lisp_Object Qdeclare;
100 Lisp_Object Qdebug;
100 101
101 /* This holds either the symbol `run-hooks' or nil. 102 /* This holds either the symbol `run-hooks' or nil.
102 It is nil at an early stage of startup, and when Emacs 103 It is nil at an early stage of startup, and when Emacs
103 is shutting down. */ 104 is shutting down. */
104 105
218 specpdl_size = 50; 219 specpdl_size = 50;
219 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding)); 220 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
220 specpdl_ptr = specpdl; 221 specpdl_ptr = specpdl;
221 /* Don't forget to update docs (lispref node "Local Variables"). */ 222 /* Don't forget to update docs (lispref node "Local Variables"). */
222 max_specpdl_size = 1000; 223 max_specpdl_size = 1000;
223 max_lisp_eval_depth = 300; 224 max_lisp_eval_depth = 400;
224 225
225 Vrun_hooks = Qnil; 226 Vrun_hooks = Qnil;
226 } 227 }
227 228
228 void 229 void
431 return val; 432 return val;
432 } 433 }
433 434
434 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0, 435 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
435 doc: /* Eval BODY forms sequentially and return value of last one. 436 doc: /* Eval BODY forms sequentially and return value of last one.
436 usage: (progn BODY ...) */) 437 usage: (progn BODY...) */)
437 (args) 438 (args)
438 Lisp_Object args; 439 Lisp_Object args;
439 { 440 {
440 register Lisp_Object val = Qnil; 441 register Lisp_Object val = Qnil;
441 struct gcpro gcpro1; 442 struct gcpro gcpro1;
1593 return val; 1594 return val;
1594 } 1595 }
1595 1596
1596 1597
1597 static Lisp_Object find_handler_clause P_ ((Lisp_Object, Lisp_Object, 1598 static Lisp_Object find_handler_clause P_ ((Lisp_Object, Lisp_Object,
1598 Lisp_Object, Lisp_Object, 1599 Lisp_Object, Lisp_Object));
1599 Lisp_Object *));
1600 1600
1601 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0, 1601 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
1602 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA. 1602 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1603 This function does not return. 1603 This function does not return.
1604 1604
1620 That is a special case--don't do this in other situations. */ 1620 That is a special case--don't do this in other situations. */
1621 register struct handler *allhandlers = handlerlist; 1621 register struct handler *allhandlers = handlerlist;
1622 Lisp_Object conditions; 1622 Lisp_Object conditions;
1623 extern int gc_in_progress; 1623 extern int gc_in_progress;
1624 extern int waiting_for_input; 1624 extern int waiting_for_input;
1625 Lisp_Object debugger_value;
1626 Lisp_Object string; 1625 Lisp_Object string;
1627 Lisp_Object real_error_symbol; 1626 Lisp_Object real_error_symbol;
1628 struct backtrace *bp; 1627 struct backtrace *bp;
1629 1628
1630 immediate_quit = handling_signal = 0; 1629 immediate_quit = handling_signal = 0;
1678 for (; handlerlist; handlerlist = handlerlist->next) 1677 for (; handlerlist; handlerlist = handlerlist->next)
1679 { 1678 {
1680 register Lisp_Object clause; 1679 register Lisp_Object clause;
1681 1680
1682 clause = find_handler_clause (handlerlist->handler, conditions, 1681 clause = find_handler_clause (handlerlist->handler, conditions,
1683 error_symbol, data, &debugger_value); 1682 error_symbol, data);
1684 1683
1685 if (EQ (clause, Qlambda)) 1684 if (EQ (clause, Qlambda))
1686 { 1685 {
1687 /* We can't return values to code which signaled an error, but we 1686 /* We can't return values to code which signaled an error, but we
1688 can continue code which has signaled a quit. */ 1687 can continue code which has signaled a quit. */
1709 } 1708 }
1710 1709
1711 handlerlist = allhandlers; 1710 handlerlist = allhandlers;
1712 /* If no handler is present now, try to run the debugger, 1711 /* If no handler is present now, try to run the debugger,
1713 and if that fails, throw to top level. */ 1712 and if that fails, throw to top level. */
1714 find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value); 1713 find_handler_clause (Qerror, conditions, error_symbol, data);
1715 if (catchlist != 0) 1714 if (catchlist != 0)
1716 Fthrow (Qtop_level, Qt); 1715 Fthrow (Qtop_level, Qt);
1717 1716
1718 if (! NILP (error_symbol)) 1717 if (! NILP (error_symbol))
1719 data = Fcons (error_symbol, data); 1718 data = Fcons (error_symbol, data);
1861 There are two ways to pass SIG and DATA: 1860 There are two ways to pass SIG and DATA:
1862 = SIG is the error symbol, and DATA is the rest of the data. 1861 = SIG is the error symbol, and DATA is the rest of the data.
1863 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA). 1862 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1864 This is for memory-full errors only. 1863 This is for memory-full errors only.
1865 1864
1866 Store value returned from debugger into *DEBUGGER_VALUE_PTR.
1867
1868 We need to increase max_specpdl_size temporarily around 1865 We need to increase max_specpdl_size temporarily around
1869 anything we do that can push on the specpdl, so as not to get 1866 anything we do that can push on the specpdl, so as not to get
1870 a second error here in case we're handling specpdl overflow. */ 1867 a second error here in case we're handling specpdl overflow. */
1871 1868
1872 static Lisp_Object 1869 static Lisp_Object
1873 find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr) 1870 find_handler_clause (handlers, conditions, sig, data)
1874 Lisp_Object handlers, conditions, sig, data; 1871 Lisp_Object handlers, conditions, sig, data;
1875 Lisp_Object *debugger_value_ptr;
1876 { 1872 {
1877 register Lisp_Object h; 1873 register Lisp_Object h;
1878 register Lisp_Object tem; 1874 register Lisp_Object tem;
1879 1875 int debugger_called = 0;
1880 if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */ 1876 int debugger_considered = 0;
1877
1878 /* t is used by handlers for all conditions, set up by C code. */
1879 if (EQ (handlers, Qt))
1881 return Qt; 1880 return Qt;
1881
1882 /* Don't run the debugger for a memory-full error.
1883 (There is no room in memory to do that!) */
1884 if (NILP (sig))
1885 debugger_considered = 1;
1886
1882 /* error is used similarly, but means print an error message 1887 /* error is used similarly, but means print an error message
1883 and run the debugger if that is enabled. */ 1888 and run the debugger if that is enabled. */
1884 if (EQ (handlers, Qerror) 1889 if (EQ (handlers, Qerror)
1885 || !NILP (Vdebug_on_signal)) /* This says call debugger even if 1890 || !NILP (Vdebug_on_signal)) /* This says call debugger even if
1886 there is a handler. */ 1891 there is a handler. */
1887 { 1892 {
1888 int debugger_called = 0; 1893 if (!NILP (sig) && wants_debugger (Vstack_trace_on_error, conditions))
1889 Lisp_Object sig_symbol, combined_data;
1890 /* This is set to 1 if we are handling a memory-full error,
1891 because these must not run the debugger.
1892 (There is no room in memory to do that!) */
1893 int no_debugger = 0;
1894
1895 if (NILP (sig))
1896 {
1897 combined_data = data;
1898 sig_symbol = Fcar (data);
1899 no_debugger = 1;
1900 }
1901 else
1902 {
1903 combined_data = Fcons (sig, data);
1904 sig_symbol = sig;
1905 }
1906
1907 if (wants_debugger (Vstack_trace_on_error, conditions))
1908 { 1894 {
1909 max_specpdl_size++; 1895 max_specpdl_size++;
1910 #ifdef PROTOTYPES 1896 #ifdef PROTOTYPES
1911 internal_with_output_to_temp_buffer ("*Backtrace*", 1897 internal_with_output_to_temp_buffer ("*Backtrace*",
1912 (Lisp_Object (*) (Lisp_Object)) Fbacktrace, 1898 (Lisp_Object (*) (Lisp_Object)) Fbacktrace,
1913 Qnil); 1899 Qnil);
1914 #else 1900 #else
1915 internal_with_output_to_temp_buffer ("*Backtrace*", 1901 internal_with_output_to_temp_buffer ("*Backtrace*",
1916 Fbacktrace, Qnil); 1902 Fbacktrace, Qnil);
1917 #endif 1903 #endif
1918 max_specpdl_size--; 1904 max_specpdl_size--;
1919 } 1905 }
1920 if (! no_debugger 1906
1921 /* Don't try to run the debugger with interrupts blocked. 1907 if (!debugger_considered)
1922 The editing loop would return anyway. */ 1908 {
1923 && ! INPUT_BLOCKED_P 1909 debugger_considered = 1;
1924 && (EQ (sig_symbol, Qquit) 1910 debugger_called = maybe_call_debugger (conditions, sig, data);
1925 ? debug_on_quit 1911 }
1926 : wants_debugger (Vdebug_on_error, conditions)) 1912
1927 && ! skip_debugger (conditions, combined_data)
1928 && when_entered_debugger < num_nonmacro_input_events)
1929 {
1930 *debugger_value_ptr
1931 = call_debugger (Fcons (Qerror,
1932 Fcons (combined_data, Qnil)));
1933 debugger_called = 1;
1934 }
1935 /* If there is no handler, return saying whether we ran the debugger. */ 1913 /* If there is no handler, return saying whether we ran the debugger. */
1936 if (EQ (handlers, Qerror)) 1914 if (EQ (handlers, Qerror))
1937 { 1915 {
1938 if (debugger_called) 1916 if (debugger_called)
1939 return Qlambda; 1917 return Qlambda;
1940 return Qt; 1918 return Qt;
1941 } 1919 }
1942 } 1920 }
1921
1943 for (h = handlers; CONSP (h); h = Fcdr (h)) 1922 for (h = handlers; CONSP (h); h = Fcdr (h))
1944 { 1923 {
1945 Lisp_Object handler, condit; 1924 Lisp_Object handler, condit;
1946 1925
1947 handler = Fcar (h); 1926 handler = Fcar (h);
1956 return handler; 1935 return handler;
1957 } 1936 }
1958 /* Handle a list of condition names in handler HANDLER. */ 1937 /* Handle a list of condition names in handler HANDLER. */
1959 else if (CONSP (condit)) 1938 else if (CONSP (condit))
1960 { 1939 {
1961 while (CONSP (condit)) 1940 Lisp_Object tail;
1941 for (tail = condit; CONSP (tail); tail = XCDR (tail))
1962 { 1942 {
1963 tem = Fmemq (Fcar (condit), conditions); 1943 tem = Fmemq (Fcar (tail), conditions);
1964 if (!NILP (tem)) 1944 if (!NILP (tem))
1965 return handler; 1945 {
1966 condit = XCDR (condit); 1946 /* This handler is going to apply.
1947 Does it allow the debugger to run first? */
1948 if (! debugger_considered && !NILP (Fmemq (Qdebug, condit)))
1949 maybe_call_debugger (conditions, sig, data);
1950 return handler;
1951 }
1967 } 1952 }
1968 } 1953 }
1969 } 1954 }
1955
1970 return Qnil; 1956 return Qnil;
1957 }
1958
1959 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1960 SIG and DATA describe the signal, as in find_handler_clause. */
1961
1962 int
1963 maybe_call_debugger (conditions, sig, data)
1964 Lisp_Object conditions, sig, data;
1965 {
1966 Lisp_Object combined_data;
1967
1968 combined_data = Fcons (sig, data);
1969
1970 if (
1971 /* Don't try to run the debugger with interrupts blocked.
1972 The editing loop would return anyway. */
1973 ! INPUT_BLOCKED_P
1974 /* Does user wants to enter debugger for this kind of error? */
1975 && (EQ (sig, Qquit)
1976 ? debug_on_quit
1977 : wants_debugger (Vdebug_on_error, conditions))
1978 && ! skip_debugger (conditions, combined_data)
1979 /* rms: what's this for? */
1980 && when_entered_debugger < num_nonmacro_input_events)
1981 {
1982 call_debugger (Fcons (Qerror, Fcons (combined_data, Qnil)));
1983 return 1;
1984 }
1985
1986 return 0;
1971 } 1987 }
1972 1988
1973 /* dump an error message; called like printf */ 1989 /* dump an error message; called like printf */
1974 1990
1975 /* VARARGS 1 */ 1991 /* VARARGS 1 */
3607 Qand_rest = intern ("&rest"); 3623 Qand_rest = intern ("&rest");
3608 staticpro (&Qand_rest); 3624 staticpro (&Qand_rest);
3609 3625
3610 Qand_optional = intern ("&optional"); 3626 Qand_optional = intern ("&optional");
3611 staticpro (&Qand_optional); 3627 staticpro (&Qand_optional);
3628
3629 Qdebug = intern ("debug");
3630 staticpro (&Qdebug);
3612 3631
3613 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error, 3632 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
3614 doc: /* *Non-nil means errors display a backtrace buffer. 3633 doc: /* *Non-nil means errors display a backtrace buffer.
3615 More precisely, this happens for any error that is handled 3634 More precisely, this happens for any error that is handled
3616 by the editor command loop. 3635 by the editor command loop.