Fredrik Lundh wrote: > > mal wrote: > > See my comments in the patch manager... the patch looks fine > > except for two things: getrlimit() should be tested for > > usability in the configure script and the call frequency > > of PyOS_CheckStack() should be lowered to only use it for > > potentially recursive programs. > > the latter would break windows and mac versions of Python, > where Python can run on very small stacks (not to mention > embedded systems...) > > for those platforms, CheckStack is designed to work with an > 8k safety margin (PYOS_STACK_MARGIN) Ok, I don't mind calling it every ten levels deep, but I'd rather not have it start at level 0. The reason is that many programs probably don't make much use of recursion anyway and have a maximum call depth of around 10-50 levels (Python programs usually using shallow class hierarchies). These programs should not be bothered by calling PyOS_CheckStack() all the time. Recursive programs will easily reach the 100 mark -- those should call PyOS_CheckStack often enough to notice the stack problems. So the check would look something like this: if (tstate->recursion_depth >= 50 && tstate->recursion_depth%10 == 0 && PyOS_CheckStack()) { PyErr_SetString(PyExc_MemoryError, "Stack overflow"); return NULL; } > ::: > > one way to address this is to introduce a scale factor, so that > you can add checks based on the default 8k limit, but auto- > magically apply them less often platforms where the safety > margin is much larger... > > /* checkstack, but with a "scale" factor */ > #if windows or mac > /* default safety margin */ > #define PYOS_CHECKSTACK(v, n)\ > (((v) % (n) == 0) && PyOS_CheckStack()) > #elif linux > /* at least 10 times the default safety margin */ > #define PYOS_CHECKSTACK(v, n)\ > (((v) % ((n)*10) == 0) && PyOS_CheckStack()) > #endif > > if (PYOS_CHECKSTACK(tstate->recursion_depth, 10) > ... I'm not exactly sure how large the safety margin is with Martin's patch, but this seems a good idea. -- Marc-Andre Lemburg ______________________________________________________________________ Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4