unify regmatch_info data
authorDavid Mitchell <davem@iabyn.com>
Thu, 30 May 2013 15:27:09 +0000 (16:27 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sun, 2 Jun 2013 21:28:53 +0000 (22:28 +0100)
commitbf2039a952dec80d770a6793104c0280373be103
tree2a961841181429dfa30fb865f82979ef29ff0213
parentd3aa529cd2d266e88a576f1de24da5ec842089e5
unify regmatch_info data

Previously the regmatch_info struct was allocated as a local var on the C
stack, while some extra state (only needed for regexes having (?{})) was
malloced (as a regmatch_eval_state struct) as needed - and a destructor set
up to clean it up afterwards. This being because the stuff being cleaned
up couldn't be allocated on the C stack as it needed to hang around after
a croak().

Reorganise this so that:

* regmatch_info is on the C stack as before.

* a new struct, regmatch_info_aux is allocated within the first slot of the
  regmatch_state stack, for fields which must always exist but which need
  cleanup afterwards. This is currently unused, but will be shortly.

* a new struct, regmatch_info_aux_eval (which is just a renamed
  regmatch_eval_state struct), is optionally allocated in the second
  slot of regmatch_state. This is logically part of regmatch_info_aux,
  except that splitting it in two stops it being too large to fit in a
  regmatch_state slot (we can fit it in two instead).

(The second and third structs aren't allocated when we're intuit()
rather than regexec()).

Doing it like this simplifies allocation and cleanup: there's no need for
a malloc(), and we are already going to allocate a slab's worth of
regmatch_state slots, so using an extra one of two of them is effectively
free; and the cleanup just requires calling a single overall destructor.

In the next few commits, more of the regexec() state setup and tear-down
will be integrated into this new regime. And in particular, the new
regmatch_info_aux struct will give us somewhere to hang things like
PL_reg_poscache once it stops being global (it being local state that
needs cleanup).
regexec.c
regexp.h