2

C-h v max-lisp-eval-depth:

You can safely make it considerably larger than its default value, if that proves inconveniently small.

Yes, I want it to be as large as possible.

However, the docstring also says:

However, if you increase it too far, Emacs could overflow the real C stack, and crash.


I want to set it to a large enough but safe value.
How do I know this value?

If it needs to dive into C code, then simply recommend a estimated value that is absolutely safe and reasonably large.

shynur
  • 4,065
  • 1
  • 3
  • 23
  • 2
    In (currently unreleased) versions of Emacs >= 29.1, `max-specpdl-size` has been made obsolete. Its doc string says: `This variable is obsolete since 29.1. Former limit on specbindings, now without effect. This variable used to limit the size of the specpdl stack which, among other things, holds dynamic variable bindings and ‘unwind-protect’ activations. To prevent runaway recursion, use ‘max-lisp-eval-depth’ instead; it will indirectly limit the specpdl stack size as well. ` – NickD Mar 13 '23 at 13:36

1 Answers1

1

They’re both numbers. They have the same maximum value as any other number: 2305843009213693951. See also most-positive-fixnum.

db48x
  • 15,741
  • 1
  • 19
  • 23
  • It seems that my description of the question has misled you. I mean, what is the maximum value under the condition that Emacs is running properly? For example, `setq`ing `max-lisp-eval-depth` to a proper value will make Emacs signal an error before the C stack is overflowed, instead crash immediately. – shynur Mar 13 '23 at 11:07
  • 2
    Ok, you shouldn’t change your question after it is answered. As the documentation says, the safe values will all be smaller than the stack size divided by the size of a stack frame. The stack size varies based on OS and configuration, and isn’t even a fixed number because libc will grow it as needed, if it can. The stack frame size depends on other factors; you could look in the Emacs source code to find out. – db48x Mar 13 '23 at 11:46
  • Thanks for your explanation. I never knew that stack size can be increased dynamically. So, at the user level, there's no way to accurately know the maximum safe value of `max-lisp-eval-depth` / `max-specpdl-size`, right? Also, is the `specpdl` on the heap? – shynur Mar 13 '23 at 12:56
  • 2
    `specpdl` is a pointer into an array which is `realloc`ed, so it (the array) is in the (C program's) heap. See the function [`grow_specpdl()`](https://github.com/emacs-mirror/emacs/blob/emacs-28/src/eval.c#L2341) in `src/eval.c` and the functions in `src/alloc.c`. – NickD Mar 13 '23 at 20:40