S_regcppush(pTHX_ I32 parenfloor)
{
int retval = PL_savestack_ix;
- int i = (PL_regsize - parenfloor) * 4;
+#define REGCP_PAREN_ELEMS 4
+ int paren_elems_to_push = (PL_regsize - parenfloor) * REGCP_PAREN_ELEMS;
int p;
- SSCHECK(i + 5);
+#define REGCP_OTHER_ELEMS 5
+ SSCHECK(paren_elems_to_push + REGCP_OTHER_ELEMS);
for (p = PL_regsize; p > parenfloor; p--) {
+/* REGCP_PARENS_ELEMS are pushed per pairs of parentheses. */
SSPUSHINT(PL_regendp[p]);
SSPUSHINT(PL_regstartp[p]);
SSPUSHPTR(PL_reg_start_tmp[p]);
SSPUSHINT(p);
}
+/* REGCP_OTHER_ELEMS are pushed in any case, parentheses or no. */
SSPUSHINT(PL_regsize);
SSPUSHINT(*PL_reglastparen);
SSPUSHPTR(PL_reginput);
- SSPUSHINT(i + 3);
- SSPUSHINT(SAVEt_REGCONTEXT);
+ SSPUSHINT(paren_elems_to_push + (REGCP_PAREN_ELEMS - 1));
+ SSPUSHINT(SAVEt_REGCONTEXT); /* Magic cookie. */
return retval;
}
STATIC char *
S_regcppop(pTHX)
{
- I32 i = SSPOPINT;
+ I32 i;
U32 paren = 0;
char *input;
I32 tmps;
- assert(i == SAVEt_REGCONTEXT);
+
+ /* Pop REGCP_OTHER_ELEMS before the parentheses loop starts. */
i = SSPOPINT;
+ assert(i == SAVEt_REGCONTEXT); /* Check that the magic cookie is there. */
+ i = SSPOPINT; /* Parentheses elements to pop. */
input = (char *) SSPOPPTR;
*PL_reglastparen = SSPOPINT;
PL_regsize = SSPOPINT;
- for (i -= 3; i > 0; i -= 4) {
+
+ /* Now restore the parentheses context. */
+ for (i -= (REGCP_PAREN_ELEMS - 1); i > 0; i -= REGCP_PAREN_ELEMS) {
paren = (U32)SSPOPINT;
PL_reg_start_tmp[paren] = (char *) SSPOPPTR;
PL_regstartp[paren] = SSPOPINT;