diff options
| author | Gregory Heytings | 2022-10-30 17:00:35 +0100 |
|---|---|---|
| committer | Gregory Heytings | 2022-10-30 17:00:35 +0100 |
| commit | aef803d6c3d61004f15d0bc82fa7bf9952302312 (patch) | |
| tree | 087c444f788cda27006ddc066ad430f62f5ac02a /src/eval.c | |
| parent | 3bf19c417fd39766ee9c7a793c9faadd3bd88478 (diff) | |
| parent | 3fa4cca3d244f51e471e7779c934278731fc21e9 (diff) | |
| download | emacs-aef803d6c3d61004f15d0bc82fa7bf9952302312.tar.gz emacs-aef803d6c3d61004f15d0bc82fa7bf9952302312.zip | |
Merge master into feature/improved-locked-narrowing.
Diffstat (limited to 'src/eval.c')
| -rw-r--r-- | src/eval.c | 107 |
1 files changed, 32 insertions, 75 deletions
diff --git a/src/eval.c b/src/eval.c index 56b42966623..ea238299488 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -211,15 +211,8 @@ backtrace_thread_next (struct thread_state *tstate, union specbinding *pdl) | |||
| 211 | void | 211 | void |
| 212 | init_eval_once (void) | 212 | init_eval_once (void) |
| 213 | { | 213 | { |
| 214 | /* Don't forget to update docs (lispref node "Local Variables"). */ | 214 | /* Don't forget to update docs (lispref node "Eval"). */ |
| 215 | #ifndef HAVE_NATIVE_COMP | ||
| 216 | max_specpdl_size = 1800; /* See bug#46818. */ | ||
| 217 | max_lisp_eval_depth = 800; | ||
| 218 | #else | ||
| 219 | /* Original values increased for comp.el. */ | ||
| 220 | max_specpdl_size = 2500; | ||
| 221 | max_lisp_eval_depth = 1600; | 215 | max_lisp_eval_depth = 1600; |
| 222 | #endif | ||
| 223 | Vrun_hooks = Qnil; | 216 | Vrun_hooks = Qnil; |
| 224 | pdumper_do_now_and_after_load (init_eval_once_for_pdumper); | 217 | pdumper_do_now_and_after_load (init_eval_once_for_pdumper); |
| 225 | } | 218 | } |
| @@ -270,8 +263,7 @@ max_ensure_room (intmax_t *m, intmax_t a, intmax_t b) | |||
| 270 | static void | 263 | static void |
| 271 | restore_stack_limits (Lisp_Object data) | 264 | restore_stack_limits (Lisp_Object data) |
| 272 | { | 265 | { |
| 273 | integer_to_intmax (XCAR (data), &max_specpdl_size); | 266 | integer_to_intmax (data, &max_lisp_eval_depth); |
| 274 | integer_to_intmax (XCDR (data), &max_lisp_eval_depth); | ||
| 275 | } | 267 | } |
| 276 | 268 | ||
| 277 | /* Call the Lisp debugger, giving it argument ARG. */ | 269 | /* Call the Lisp debugger, giving it argument ARG. */ |
| @@ -283,9 +275,6 @@ call_debugger (Lisp_Object arg) | |||
| 283 | specpdl_ref count = SPECPDL_INDEX (); | 275 | specpdl_ref count = SPECPDL_INDEX (); |
| 284 | Lisp_Object val; | 276 | Lisp_Object val; |
| 285 | intmax_t old_depth = max_lisp_eval_depth; | 277 | intmax_t old_depth = max_lisp_eval_depth; |
| 286 | /* Do not allow max_specpdl_size less than actual depth (Bug#16603). */ | ||
| 287 | ptrdiff_t counti = specpdl_ref_to_count (count); | ||
| 288 | intmax_t old_max = max (max_specpdl_size, counti); | ||
| 289 | 278 | ||
| 290 | /* The previous value of 40 is too small now that the debugger | 279 | /* The previous value of 40 is too small now that the debugger |
| 291 | prints using cl-prin1 instead of prin1. Printing lists nested 8 | 280 | prints using cl-prin1 instead of prin1. Printing lists nested 8 |
| @@ -293,20 +282,8 @@ call_debugger (Lisp_Object arg) | |||
| 293 | currently requires 77 additional frames. See bug#31919. */ | 282 | currently requires 77 additional frames. See bug#31919. */ |
| 294 | max_ensure_room (&max_lisp_eval_depth, lisp_eval_depth, 100); | 283 | max_ensure_room (&max_lisp_eval_depth, lisp_eval_depth, 100); |
| 295 | 284 | ||
| 296 | /* While debugging Bug#16603, previous value of 100 was found | ||
| 297 | too small to avoid specpdl overflow in the debugger itself. */ | ||
| 298 | max_ensure_room (&max_specpdl_size, counti, 200); | ||
| 299 | |||
| 300 | if (old_max == counti) | ||
| 301 | { | ||
| 302 | /* We can enter the debugger due to specpdl overflow (Bug#16603). */ | ||
| 303 | specpdl_ptr--; | ||
| 304 | grow_specpdl (); | ||
| 305 | } | ||
| 306 | |||
| 307 | /* Restore limits after leaving the debugger. */ | 285 | /* Restore limits after leaving the debugger. */ |
| 308 | record_unwind_protect (restore_stack_limits, | 286 | record_unwind_protect (restore_stack_limits, make_int (old_depth)); |
| 309 | Fcons (make_int (old_max), make_int (old_depth))); | ||
| 310 | 287 | ||
| 311 | #ifdef HAVE_WINDOW_SYSTEM | 288 | #ifdef HAVE_WINDOW_SYSTEM |
| 312 | if (display_hourglass_p) | 289 | if (display_hourglass_p) |
| @@ -507,8 +484,7 @@ usage: (setq [SYM VAL]...) */) | |||
| 507 | /* Like for eval_sub, we do not check declared_special here since | 484 | /* Like for eval_sub, we do not check declared_special here since |
| 508 | it's been done when let-binding. */ | 485 | it's been done when let-binding. */ |
| 509 | Lisp_Object lex_binding | 486 | Lisp_Object lex_binding |
| 510 | = ((!NILP (Vinternal_interpreter_environment) /* Mere optimization! */ | 487 | = (SYMBOLP (sym) |
| 511 | && SYMBOLP (sym)) | ||
| 512 | ? Fassq (sym, Vinternal_interpreter_environment) | 488 | ? Fassq (sym, Vinternal_interpreter_environment) |
| 513 | : Qnil); | 489 | : Qnil); |
| 514 | if (!NILP (lex_binding)) | 490 | if (!NILP (lex_binding)) |
| @@ -574,8 +550,12 @@ usage: (function ARG) */) | |||
| 574 | CHECK_STRING (docstring); | 550 | CHECK_STRING (docstring); |
| 575 | cdr = Fcons (XCAR (cdr), Fcons (docstring, XCDR (XCDR (cdr)))); | 551 | cdr = Fcons (XCAR (cdr), Fcons (docstring, XCDR (XCDR (cdr)))); |
| 576 | } | 552 | } |
| 577 | return Fcons (Qclosure, Fcons (Vinternal_interpreter_environment, | 553 | if (NILP (Vinternal_make_interpreted_closure_function)) |
| 578 | cdr)); | 554 | return Fcons (Qclosure, Fcons (Vinternal_interpreter_environment, cdr)); |
| 555 | else | ||
| 556 | return call2 (Vinternal_make_interpreted_closure_function, | ||
| 557 | Fcons (Qlambda, cdr), | ||
| 558 | Vinternal_interpreter_environment); | ||
| 579 | } | 559 | } |
| 580 | else | 560 | else |
| 581 | /* Simply quote the argument. */ | 561 | /* Simply quote the argument. */ |
| @@ -938,12 +918,9 @@ usage: (let* VARLIST BODY...) */) | |||
| 938 | lexenv = Vinternal_interpreter_environment; | 918 | lexenv = Vinternal_interpreter_environment; |
| 939 | 919 | ||
| 940 | Lisp_Object varlist = XCAR (args); | 920 | Lisp_Object varlist = XCAR (args); |
| 941 | while (CONSP (varlist)) | 921 | FOR_EACH_TAIL (varlist) |
| 942 | { | 922 | { |
| 943 | maybe_quit (); | ||
| 944 | |||
| 945 | elt = XCAR (varlist); | 923 | elt = XCAR (varlist); |
| 946 | varlist = XCDR (varlist); | ||
| 947 | if (SYMBOLP (elt)) | 924 | if (SYMBOLP (elt)) |
| 948 | { | 925 | { |
| 949 | var = elt; | 926 | var = elt; |
| @@ -1677,10 +1654,12 @@ process_quit_flag (void) | |||
| 1677 | void | 1654 | void |
| 1678 | probably_quit (void) | 1655 | probably_quit (void) |
| 1679 | { | 1656 | { |
| 1657 | specpdl_ref gc_count = inhibit_garbage_collection (); | ||
| 1680 | if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) | 1658 | if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) |
| 1681 | process_quit_flag (); | 1659 | process_quit_flag (); |
| 1682 | else if (pending_signals) | 1660 | else if (pending_signals) |
| 1683 | process_pending_signals (); | 1661 | process_pending_signals (); |
| 1662 | unbind_to (gc_count, Qnil); | ||
| 1684 | } | 1663 | } |
| 1685 | 1664 | ||
| 1686 | DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0, | 1665 | DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0, |
| @@ -1737,6 +1716,7 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool keyboard_quit) | |||
| 1737 | Lisp_Object clause = Qnil; | 1716 | Lisp_Object clause = Qnil; |
| 1738 | struct handler *h; | 1717 | struct handler *h; |
| 1739 | 1718 | ||
| 1719 | eassert (!itree_iterator_busy_p ()); | ||
| 1740 | if (gc_in_progress || waiting_for_input) | 1720 | if (gc_in_progress || waiting_for_input) |
| 1741 | emacs_abort (); | 1721 | emacs_abort (); |
| 1742 | 1722 | ||
| @@ -1757,8 +1737,6 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool keyboard_quit) | |||
| 1757 | { | 1737 | { |
| 1758 | /* Edebug takes care of restoring these variables when it exits. */ | 1738 | /* Edebug takes care of restoring these variables when it exits. */ |
| 1759 | max_ensure_room (&max_lisp_eval_depth, lisp_eval_depth, 20); | 1739 | max_ensure_room (&max_lisp_eval_depth, lisp_eval_depth, 20); |
| 1760 | ptrdiff_t counti = specpdl_ref_to_count (SPECPDL_INDEX ()); | ||
| 1761 | max_ensure_room (&max_specpdl_size, counti, 40); | ||
| 1762 | 1740 | ||
| 1763 | call2 (Vsignal_hook_function, error_symbol, data); | 1741 | call2 (Vsignal_hook_function, error_symbol, data); |
| 1764 | } | 1742 | } |
| @@ -1827,8 +1805,6 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool keyboard_quit) | |||
| 1827 | { | 1805 | { |
| 1828 | max_ensure_room (&max_lisp_eval_depth, lisp_eval_depth, 100); | 1806 | max_ensure_room (&max_lisp_eval_depth, lisp_eval_depth, 100); |
| 1829 | specpdl_ref count = SPECPDL_INDEX (); | 1807 | specpdl_ref count = SPECPDL_INDEX (); |
| 1830 | ptrdiff_t counti = specpdl_ref_to_count (count); | ||
| 1831 | max_ensure_room (&max_specpdl_size, counti, 200); | ||
| 1832 | specbind (Qdebugger, Qdebug_early); | 1808 | specbind (Qdebugger, Qdebug_early); |
| 1833 | call_debugger (list2 (Qerror, Fcons (error_symbol, data))); | 1809 | call_debugger (list2 (Qerror, Fcons (error_symbol, data))); |
| 1834 | unbind_to (count, Qnil); | 1810 | unbind_to (count, Qnil); |
| @@ -1844,12 +1820,10 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool keyboard_quit) | |||
| 1844 | { | 1820 | { |
| 1845 | max_ensure_room (&max_lisp_eval_depth, lisp_eval_depth, 100); | 1821 | max_ensure_room (&max_lisp_eval_depth, lisp_eval_depth, 100); |
| 1846 | specpdl_ref count = SPECPDL_INDEX (); | 1822 | specpdl_ref count = SPECPDL_INDEX (); |
| 1847 | ptrdiff_t counti = specpdl_ref_to_count (count); | ||
| 1848 | AUTO_STRING (redisplay_trace, "*Redisplay_trace*"); | 1823 | AUTO_STRING (redisplay_trace, "*Redisplay_trace*"); |
| 1849 | Lisp_Object redisplay_trace_buffer; | 1824 | Lisp_Object redisplay_trace_buffer; |
| 1850 | AUTO_STRING (gap, "\n\n\n\n"); /* Separates things in *Redisplay-trace* */ | 1825 | AUTO_STRING (gap, "\n\n\n\n"); /* Separates things in *Redisplay-trace* */ |
| 1851 | Lisp_Object delayed_warning; | 1826 | Lisp_Object delayed_warning; |
| 1852 | max_ensure_room (&max_specpdl_size, counti, 200); | ||
| 1853 | redisplay_trace_buffer = Fget_buffer_create (redisplay_trace, Qnil); | 1827 | redisplay_trace_buffer = Fget_buffer_create (redisplay_trace, Qnil); |
| 1854 | current_buffer = XBUFFER (redisplay_trace_buffer); | 1828 | current_buffer = XBUFFER (redisplay_trace_buffer); |
| 1855 | if (!backtrace_yet) /* Are we on the first backtrace of the command? */ | 1829 | if (!backtrace_yet) /* Are we on the first backtrace of the command? */ |
| @@ -2381,17 +2355,12 @@ grow_specpdl_allocation (void) | |||
| 2381 | eassert (specpdl_ptr == specpdl_end); | 2355 | eassert (specpdl_ptr == specpdl_end); |
| 2382 | 2356 | ||
| 2383 | specpdl_ref count = SPECPDL_INDEX (); | 2357 | specpdl_ref count = SPECPDL_INDEX (); |
| 2384 | ptrdiff_t max_size = min (max_specpdl_size, PTRDIFF_MAX - 1000); | 2358 | ptrdiff_t max_size = PTRDIFF_MAX - 1000; |
| 2385 | union specbinding *pdlvec = specpdl - 1; | 2359 | union specbinding *pdlvec = specpdl - 1; |
| 2386 | ptrdiff_t size = specpdl_end - specpdl; | 2360 | ptrdiff_t size = specpdl_end - specpdl; |
| 2387 | ptrdiff_t pdlvecsize = size + 1; | 2361 | ptrdiff_t pdlvecsize = size + 1; |
| 2388 | if (max_size <= size) | 2362 | if (max_size <= size) |
| 2389 | { | 2363 | xsignal0 (Qexcessive_variable_binding); /* Can't happen, essentially. */ |
| 2390 | if (max_specpdl_size < 400) | ||
| 2391 | max_size = max_specpdl_size = 400; | ||
| 2392 | if (max_size <= size) | ||
| 2393 | xsignal0 (Qexcessive_variable_binding); | ||
| 2394 | } | ||
| 2395 | pdlvec = xpalloc (pdlvec, &pdlvecsize, 1, max_size + 1, sizeof *specpdl); | 2364 | pdlvec = xpalloc (pdlvec, &pdlvecsize, 1, max_size + 1, sizeof *specpdl); |
| 2396 | specpdl = pdlvec + 1; | 2365 | specpdl = pdlvec + 1; |
| 2397 | specpdl_end = specpdl + pdlvecsize - 1; | 2366 | specpdl_end = specpdl + pdlvecsize - 1; |
| @@ -2409,9 +2378,7 @@ eval_sub (Lisp_Object form) | |||
| 2409 | We do not pay attention to the declared_special flag here, since we | 2378 | We do not pay attention to the declared_special flag here, since we |
| 2410 | already did that when let-binding the variable. */ | 2379 | already did that when let-binding the variable. */ |
| 2411 | Lisp_Object lex_binding | 2380 | Lisp_Object lex_binding |
| 2412 | = (!NILP (Vinternal_interpreter_environment) /* Mere optimization! */ | 2381 | = Fassq (form, Vinternal_interpreter_environment); |
| 2413 | ? Fassq (form, Vinternal_interpreter_environment) | ||
| 2414 | : Qnil); | ||
| 2415 | return !NILP (lex_binding) ? XCDR (lex_binding) : Fsymbol_value (form); | 2382 | return !NILP (lex_binding) ? XCDR (lex_binding) : Fsymbol_value (form); |
| 2416 | } | 2383 | } |
| 2417 | 2384 | ||
| @@ -2427,7 +2394,7 @@ eval_sub (Lisp_Object form) | |||
| 2427 | if (max_lisp_eval_depth < 100) | 2394 | if (max_lisp_eval_depth < 100) |
| 2428 | max_lisp_eval_depth = 100; | 2395 | max_lisp_eval_depth = 100; |
| 2429 | if (lisp_eval_depth > max_lisp_eval_depth) | 2396 | if (lisp_eval_depth > max_lisp_eval_depth) |
| 2430 | xsignal0 (Qexcessive_lisp_nesting); | 2397 | xsignal1 (Qexcessive_lisp_nesting, make_fixnum (lisp_eval_depth)); |
| 2431 | } | 2398 | } |
| 2432 | 2399 | ||
| 2433 | Lisp_Object original_fun = XCAR (form); | 2400 | Lisp_Object original_fun = XCAR (form); |
| @@ -2468,7 +2435,9 @@ eval_sub (Lisp_Object form) | |||
| 2468 | 2435 | ||
| 2469 | else if (XSUBR (fun)->max_args == UNEVALLED) | 2436 | else if (XSUBR (fun)->max_args == UNEVALLED) |
| 2470 | val = (XSUBR (fun)->function.aUNEVALLED) (args_left); | 2437 | val = (XSUBR (fun)->function.aUNEVALLED) (args_left); |
| 2471 | else if (XSUBR (fun)->max_args == MANY) | 2438 | else if (XSUBR (fun)->max_args == MANY |
| 2439 | || XSUBR (fun)->max_args > 8) | ||
| 2440 | |||
| 2472 | { | 2441 | { |
| 2473 | /* Pass a vector of evaluated arguments. */ | 2442 | /* Pass a vector of evaluated arguments. */ |
| 2474 | Lisp_Object *vals; | 2443 | Lisp_Object *vals; |
| @@ -3001,7 +2970,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */) | |||
| 3001 | if (max_lisp_eval_depth < 100) | 2970 | if (max_lisp_eval_depth < 100) |
| 3002 | max_lisp_eval_depth = 100; | 2971 | max_lisp_eval_depth = 100; |
| 3003 | if (lisp_eval_depth > max_lisp_eval_depth) | 2972 | if (lisp_eval_depth > max_lisp_eval_depth) |
| 3004 | xsignal0 (Qexcessive_lisp_nesting); | 2973 | xsignal1 (Qexcessive_lisp_nesting, make_fixnum (lisp_eval_depth)); |
| 3005 | } | 2974 | } |
| 3006 | 2975 | ||
| 3007 | count = record_in_backtrace (args[0], &args[1], nargs - 1); | 2976 | count = record_in_backtrace (args[0], &args[1], nargs - 1); |
| @@ -3031,7 +3000,8 @@ funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args) | |||
| 3031 | if (numargs >= subr->min_args) | 3000 | if (numargs >= subr->min_args) |
| 3032 | { | 3001 | { |
| 3033 | /* Conforming call to finite-arity subr. */ | 3002 | /* Conforming call to finite-arity subr. */ |
| 3034 | if (numargs <= subr->max_args) | 3003 | if (numargs <= subr->max_args |
| 3004 | && subr->max_args <= 8) | ||
| 3035 | { | 3005 | { |
| 3036 | Lisp_Object argbuf[8]; | 3006 | Lisp_Object argbuf[8]; |
| 3037 | Lisp_Object *a; | 3007 | Lisp_Object *a; |
| @@ -3067,15 +3037,13 @@ funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args) | |||
| 3067 | return subr->function.a8 (a[0], a[1], a[2], a[3], a[4], a[5], | 3037 | return subr->function.a8 (a[0], a[1], a[2], a[3], a[4], a[5], |
| 3068 | a[6], a[7]); | 3038 | a[6], a[7]); |
| 3069 | default: | 3039 | default: |
| 3070 | /* If a subr takes more than 8 arguments without using MANY | 3040 | emacs_abort (); /* Can't happen. */ |
| 3071 | or UNEVALLED, we need to extend this function to support it. | ||
| 3072 | Until this is done, there is no way to call the function. */ | ||
| 3073 | emacs_abort (); | ||
| 3074 | } | 3041 | } |
| 3075 | } | 3042 | } |
| 3076 | 3043 | ||
| 3077 | /* Call to n-adic subr. */ | 3044 | /* Call to n-adic subr. */ |
| 3078 | if (subr->max_args == MANY) | 3045 | if (subr->max_args == MANY |
| 3046 | || subr->max_args > 8) | ||
| 3079 | return subr->function.aMANY (numargs, args); | 3047 | return subr->function.aMANY (numargs, args); |
| 3080 | } | 3048 | } |
| 3081 | 3049 | ||
| @@ -4234,22 +4202,6 @@ Lisp_Object backtrace_top_function (void) | |||
| 4234 | void | 4202 | void |
| 4235 | syms_of_eval (void) | 4203 | syms_of_eval (void) |
| 4236 | { | 4204 | { |
| 4237 | DEFVAR_INT ("max-specpdl-size", max_specpdl_size, | ||
| 4238 | doc: /* Limit on number of Lisp variable bindings and `unwind-protect's. | ||
| 4239 | |||
| 4240 | If Lisp code tries to use more bindings than this amount, an error is | ||
| 4241 | signaled. | ||
| 4242 | |||
| 4243 | You can safely increase this variable substantially if the default | ||
| 4244 | value proves inconveniently small. However, if you increase it too | ||
| 4245 | much, Emacs could run out of memory trying to make the stack bigger. | ||
| 4246 | Note that this limit may be silently increased by the debugger if | ||
| 4247 | `debug-on-error' or `debug-on-quit' is set. | ||
| 4248 | |||
| 4249 | \"spec\" is short for \"special variables\", i.e., dynamically bound | ||
| 4250 | variables. \"PDL\" is short for \"push-down list\", which is an old | ||
| 4251 | term for \"stack\". */); | ||
| 4252 | |||
| 4253 | DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth, | 4205 | DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth, |
| 4254 | doc: /* Limit on depth in `eval', `apply' and `funcall' before error. | 4206 | doc: /* Limit on depth in `eval', `apply' and `funcall' before error. |
| 4255 | 4207 | ||
| @@ -4408,6 +4360,11 @@ alist of active lexical bindings. */); | |||
| 4408 | (Just imagine if someone makes it buffer-local). */ | 4360 | (Just imagine if someone makes it buffer-local). */ |
| 4409 | Funintern (Qinternal_interpreter_environment, Qnil); | 4361 | Funintern (Qinternal_interpreter_environment, Qnil); |
| 4410 | 4362 | ||
| 4363 | DEFVAR_LISP ("internal-make-interpreted-closure-function", | ||
| 4364 | Vinternal_make_interpreted_closure_function, | ||
| 4365 | doc: /* Function to filter the env when constructing a closure. */); | ||
| 4366 | Vinternal_make_interpreted_closure_function = Qnil; | ||
| 4367 | |||
| 4411 | Vrun_hooks = intern_c_string ("run-hooks"); | 4368 | Vrun_hooks = intern_c_string ("run-hooks"); |
| 4412 | staticpro (&Vrun_hooks); | 4369 | staticpro (&Vrun_hooks); |
| 4413 | 4370 | ||