PaddiM8 / kalker

Scientific calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
https://kalker.xyz
MIT License
1.59k stars 70 forks source link

How to prevent stack overflow on tokio thread #121

Closed kvnxiao closed 11 months ago

kvnxiao commented 11 months ago

I'm using kalk = "3.0.3" as a library in a Rust application which takes in interactive user input. How can I configure things on the Rust side to prevent a stack overflow due to a recursive function being declared? For example, trying to parse this will obviously cause a thread 'tokio-runtime-worker' has overflowed its stack error:

f(x) = f(x) + 1
f(1)
PaddiM8 commented 11 months ago

Right now there is no functionality for catching stack overflows. However, I guess it would be possible to implement some stack depth limit. Will probably look into this for the next release (unclear when that's going to be), but will also be accepting PRs of course!

kvnxiao commented 11 months ago

@PaddiM8 I took a small stab at this. Made a really small change which increments a depth counter and early-returns with a KalkError if we exceed an arbitrarily picked default depth value.

https://github.com/PaddiM8/kalker/pull/122