On Mon, Jun 15, 2015 at 08:15:59AM +0100, [email protected] wrote: > On Mon, 15 Jun 2015, [email protected] wrote: > > > Would it be possible to change the recursion limit from number of calls to > > amount of memory? This would eliminate the wild guess of how many memory a > > call > > needs. > > As far as I know, there is no standard (OS-independent) way of finding > out, from within a C program, anything about the amount of memory > available on either the stack or the heap. > My proposal was to to measure number of consumed stack. Instead of adding 1 to a counter on each call, one would compute difference of stack pointer at current call to the first call and compared this delta to the limit. You could do it even without in-line assembler simply by referencing an automatic-storage variable like a variable local to the current function. Of course there would be some off-by-one-call drift but that could be ignored or extrapolated based on current stack usage growth ratio.
Your remark gave me an idea that the size of the stack could be obtained by getrlimit() on the first call, so even the user would not need to specify the limit explicitly as the default would be that (minus stack consumed by a PCRE application on the first call). That would provide fully automatic heuristic preventing from unexpected sefgaults. -- Petr -- ## List details at https://lists.exim.org/mailman/listinfo/pcre-dev
