Use expanded stack during regex matches
commit13c6f1d185d301aad2f6d756c148acb2edd0889f
authorNoam Postavsky <npostavs@gmail.com>
Sun, 1 Jan 2017 19:09:13 +0000 (1 14:09 -0500)
committerNoam Postavsky <npostavs@gmail.com>
Sun, 8 Jan 2017 23:45:52 +0000 (8 18:45 -0500)
treeac1df03118e312742b8a9fdf83698ad6b25eb869
parent9a19f26cd796c7321f659a8dbea5296b0eeea51d
Use expanded stack during regex matches

While the stack is increased in main(), to allow the regex stack
allocation to use alloca we also need to modify regex.c to actually take
advantage of the increased stack, and not limit stack allocations to
SAFE_ALLOCA bytes.

* src/regex.c (MATCH_MAY_ALLOCATE): Remove obsolete comment about
allocations in signal handlers which no longer happens and correct
description about when and why MATCH_MAY_ALLOCATE should be defined.
(emacs_re_safe_alloca): New variable.
(REGEX_USE_SAFE_ALLOCA): Use it as the limit of stack allocation instead
of MAX_ALLOCA.
(emacs_re_max_failures): Rename from `re_max_failures' to avoid
confusion with glibc's `re_max_failures'.
* src/emacs.c (main): Increase the amount of fixed 'extra' bytes we add
to the stack.  Instead of changing emacs_re_max_failures based on the
new stack size, just change emacs_re_safe_alloca; emacs_re_max_failures
remains constant regardless, since if we run out stack space SAFE_ALLOCA
will fall back to heap allocation.

Co-authored-by: Eli Zaretskii <eliz@gnu.org>
src/emacs.c
src/regex.c
src/regex.h