#define CHR_SVLEN(sv) (UTF ? sv_len_utf8(sv) : SvCUR(sv))
#define CHR_DIST(a,b) (UTF ? utf8_distance(a,b) : a - b)
+/* Allow for side effects in s */
+#define REGC(c,s) STMT_START { if (!SIZE_ONLY) *(s) = (c); else (s);} STMT_END
+
static void clear_re(pTHXo_ void *r);
STATIC void
regnode *stop = scan;
#endif
- next = scan + (*OPERAND(scan) + 2 - 1)/sizeof(regnode) + 2;
+ next = scan + NODE_SZ_STR(scan);
/* Skip NOTHING, merge EXACT*. */
while (n &&
( PL_regkind[(U8)OP(n)] == NOTHING ||
n = regnext(n);
}
else {
- int oldl = *OPERAND(scan);
+ int oldl = STR_LEN(scan);
regnode *nnext = regnext(n);
- if (oldl + *OPERAND(n) > U8_MAX)
+ if (oldl + STR_LEN(n) > U8_MAX)
break;
NEXT_OFF(scan) += NEXT_OFF(n);
- *OPERAND(scan) += *OPERAND(n);
- next = n + (*OPERAND(n) + 2 - 1)/sizeof(regnode) + 2;
+ STR_LEN(scan) += STR_LEN(n);
+ next = n + NODE_SZ_STR(n);
/* Now we can overwrite *n : */
- Move(OPERAND(n) + 1, OPERAND(scan) + oldl + 1,
- *OPERAND(n) + 1, char);
+ Move(STRING(n), STRING(scan) + oldl,
+ STR_LEN(n), char);
#ifdef DEBUGGING
if (stringok)
stop = next - 1;
}
#ifdef DEBUGGING
/* Allow dumping */
- n = scan + (*OPERAND(scan) + 2 - 1)/sizeof(regnode) + 2;
+ n = scan + NODE_SZ_STR(scan);
while (n <= stop) {
/* Purify reports a benign UMR here sometimes, because we
* don't initialize the OP() slot of a node when that node
continue;
}
else if (OP(scan) == EXACT) {
- I32 l = *OPERAND(scan);
+ I32 l = STR_LEN(scan);
if (UTF) {
- unsigned char *s = (unsigned char *)(OPERAND(scan)+1);
+ unsigned char *s = (unsigned char *)STRING(scan);
unsigned char *e = s + l;
I32 newl = 0;
while (s < e) {
data->last_start_max = is_inf
? I32_MAX : data->pos_min + data->pos_delta;
}
- sv_catpvn(data->last_found, (char *)(OPERAND(scan)+1), *OPERAND(scan));
+ sv_catpvn(data->last_found, STRING(scan), STR_LEN(scan));
data->last_end = data->pos_min + l;
data->pos_min += l; /* As in the first entry. */
data->flags &= ~SF_BEFORE_EOL;
}
}
else if (PL_regkind[(U8)OP(scan)] == EXACT) {
- I32 l = *OPERAND(scan);
+ I32 l = STR_LEN(scan);
if (flags & SCF_DO_SUBSTR)
scan_commit(data);
if (UTF) {
- unsigned char *s = (unsigned char *)(OPERAND(scan)+1);
+ unsigned char *s = (unsigned char *)STRING(scan);
unsigned char *e = s + l;
I32 newl = 0;
while (s < e) {
nxt = regnext(nxt);
if (!strchr((char*)PL_simple,OP(nxt))
&& !(PL_regkind[(U8)OP(nxt)] == EXACT
- && *OPERAND(nxt) == 1))
+ && STR_LEN(nxt) == 1))
goto nogo;
nxt2 = nxt;
nxt = regnext(nxt);
PL_regsize = 0L;
PL_regcode = &PL_regdummy;
PL_reg_whilem_seen = 0;
- regc((U8)REG_MAGIC, (char*)PL_regcode);
+ REGC((U8)REG_MAGIC, (char*)PL_regcode);
if (reg(0, &flags) == NULL) {
Safefree(PL_regprecomp);
PL_regprecomp = Nullch;
PL_regcode = r->program;
/* Store the count of eval-groups for security checks: */
PL_regcode->next_off = ((PL_seen_evals > U16_MAX) ? U16_MAX : PL_seen_evals);
- regc((U8)REG_MAGIC, (char*) PL_regcode++);
+ REGC((U8)REG_MAGIC, (char*) PL_regcode++);
r->data = 0;
if (reg(0, &flags) == NULL)
return(NULL);
ret = reg_node(FOLD
? (LOC ? EXACTFL : EXACTF)
: EXACT);
- s = (char *) OPERAND(ret);
- regc(0, s++); /* save spot for len */
+ s = STRING(ret);
for (len = 0, p = PL_regcomp_parse - 1;
len < 127 && p < PL_regxend;
len++)
}
else {
len++;
- regc(ender, s++);
+ REGC(ender, s++);
}
break;
}
len += numlen - 1;
}
else
- regc(ender, s++);
+ REGC(ender, s++);
}
loopdone:
PL_regcomp_parse = p - 1;
if (len == 1)
*flagp |= SIMPLE;
if (!SIZE_ONLY)
- *OPERAND(ret) = len;
- regc('\0', s++);
- if (SIZE_ONLY) {
- PL_regsize += (len + 2 + sizeof(regnode) - 1) / sizeof(regnode);
- }
- else {
- PL_regcode += (len + 2 + sizeof(regnode) - 1) / sizeof(regnode);
- }
+ STR_LEN(ret) = len;
+ if (SIZE_ONLY)
+ PL_regsize += STR_SZ(len);
+ else
+ PL_regcode += STR_SZ(len);
}
break;
}
I32 numlen;
I32 namedclass;
- s = opnd = (char *) OPERAND(PL_regcode);
+ s = opnd = MASK(PL_regcode);
ret = reg_node(ANYOF);
for (value = 0; value < ANYOF_SIZE; value++)
- regc(0, s++);
+ REGC(0, s++);
if (*PL_regcomp_parse == '^') { /* Complement of range. */
PL_regnaughty++;
PL_regcomp_parse++;
}
/*
-- regc - emit (if appropriate) a Unicode character
+- reguni - emit (if appropriate) a Unicode character
*/
STATIC void
S_reguni(pTHX_ UV uv, char* s, I32* lenp)
}
/*
-- regc - emit (if appropriate) a byte of code
-*/
-STATIC void
-S_regc(pTHX_ U8 b, char* s)
-{
- dTHR;
- if (!SIZE_ONLY)
- *s = b;
-}
-
-/*
- reginsert - insert an operator in front of already-emitted operand
*
* Means relocating the operand.
}
else if (PL_regkind[(U8)op] == EXACT) {
/* Literal string, where present. */
- node += ((*OPERAND(node)) + 2 + sizeof(regnode) - 1) / sizeof(regnode);
+ node += NODE_SZ_STR(node) - 1;
node = NEXTOPER(node);
}
else {
k = PL_regkind[(U8)OP(o)];
if (k == EXACT)
- Perl_sv_catpvf(aTHX_ sv, " <%s%s%s>", PL_colors[0], OPERAND(o) + 1, PL_colors[1]);
+ Perl_sv_catpvf(aTHX_ sv, " <%s%*s%s>", PL_colors[0],
+ STR_LEN(o), STRING(o), PL_colors[1]);
else if (k == CURLY) {
if (OP(o) == CURLYM || OP(o) == CURLYN)
Perl_sv_catpvf(aTHX_ sv, "[%d]", o->flags); /* Parenth number */
/* We know what class it must start with. */
switch (OP(c)) {
case ANYOFUTF8:
- cc = (char *) OPERAND(c);
+ cc = MASK(c);
while (s < strend) {
if (REGINCLASSUTF8(c, (U8*)s)) {
if (tmp && regtry(prog, s))
}
break;
case ANYOF:
- cc = (char *) OPERAND(c);
+ cc = MASK(c);
while (s < strend) {
if (REGINCLASS(cc, *s)) {
if (tmp && regtry(prog, s))
nextchr = UCHARAT(++locinput);
break;
case EXACT:
- s = (char *) OPERAND(scan);
- ln = UCHARAT(s++);
+ s = STRING(scan);
+ ln = STR_LEN(scan);
/* Inline the first character, for speed. */
if (UCHARAT(s) != nextchr)
sayNO;
PL_reg_flags |= RF_tainted;
/* FALL THROUGH */
case EXACTF:
- s = (char *) OPERAND(scan);
- ln = UCHARAT(s++);
+ s = STRING(scan);
+ ln = STR_LEN(scan);
if (UTF) {
char *l = locinput;
nextchr = UCHARAT(locinput);
break;
case ANYOFUTF8:
- s = (char *) OPERAND(scan);
+ s = MASK(scan);
if (!REGINCLASSUTF8(scan, (U8*)locinput))
sayNO;
if (locinput >= PL_regeol)
nextchr = UCHARAT(locinput);
break;
case ANYOF:
- s = (char *) OPERAND(scan);
+ s = MASK(scan);
if (nextchr < 0)
nextchr = UCHARAT(locinput);
if (!REGINCLASS(s, nextchr))
ln = n;
locinput = PL_reginput;
if (PL_regkind[(U8)OP(next)] == EXACT) {
- c1 = UCHARAT(OPERAND(next) + 1);
+ c1 = (U8)*STRING(next);
if (OP(next) == EXACTF)
c2 = PL_fold[c1];
else if (OP(next) == EXACTFL)
);
if (n >= ln) {
if (PL_regkind[(U8)OP(next)] == EXACT) {
- c1 = UCHARAT(OPERAND(next) + 1);
+ c1 = (U8)*STRING(next);
if (OP(next) == EXACTF)
c2 = PL_fold[c1];
else if (OP(next) == EXACTFL)
* when we know what character comes next.
*/
if (PL_regkind[(U8)OP(next)] == EXACT) {
- c1 = UCHARAT(OPERAND(next) + 1);
+ c1 = (U8)*STRING(next);
if (OP(next) == EXACTF)
c2 = PL_fold[c1];
else if (OP(next) == EXACTFL)
scan = PL_reginput;
if (max != REG_INFTY && max < loceol - scan)
loceol = scan + max;
- opnd = (char *) OPERAND(p);
switch (OP(p)) {
case REG_ANY:
while (scan < loceol && *scan != '\n')
}
break;
case EXACT: /* length of string is 1 */
- c = UCHARAT(++opnd);
+ c = (U8)*STRING(p);
while (scan < loceol && UCHARAT(scan) == c)
scan++;
break;
case EXACTF: /* length of string is 1 */
- c = UCHARAT(++opnd);
+ c = (U8)*STRING(p);
while (scan < loceol &&
(UCHARAT(scan) == c || UCHARAT(scan) == PL_fold[c]))
scan++;
break;
case EXACTFL: /* length of string is 1 */
PL_reg_flags |= RF_tainted;
- c = UCHARAT(++opnd);
+ c = (U8)*STRING(p);
while (scan < loceol &&
(UCHARAT(scan) == c || UCHARAT(scan) == PL_fold_locale[c]))
scan++;
}
break;
case ANYOF:
+ opnd = MASK(p);
while (scan < loceol && REGINCLASS(opnd, *scan))
scan++;
break;