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.

1
  • 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
    Commented Mar 13, 2023 at 13:36

1 Answer 1

1

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

4
  • 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, setqing max-lisp-eval-depth to a proper value will make Emacs signal an error before the C stack is overflowed, instead crash immediately.
    – shynur
    Commented Mar 13, 2023 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
    Commented Mar 13, 2023 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
    Commented Mar 13, 2023 at 12:56
  • 2
    specpdl is a pointer into an array which is realloced, so it (the array) is in the (C program's) heap. See the function grow_specpdl() in src/eval.c and the functions in src/alloc.c.
    – NickD
    Commented Mar 13, 2023 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.