From 3f11a2855248134af98ca8d71cf71a3fe736dbae Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Mon, 9 Jan 2023 20:49:12 +0100 Subject: regexec engine - wrap and replace RX_OFFS() with better abstractions RX_OFFS() exposes a bit too much about how capture buffers are represented. This adds RX_OFFS_START() and RX_OFFS_END() and RX_OFFS_VALID() to replace most of the uses of the RX_OFFS() macro or direct access to the rx->off[] array. (We add RX_OFFSp() for those rare cases that should have direct access to the array.) This allows us to replace this logic with more complicated macros in the future. Pretty much anything using RX_OFFS() is going to be broken by future changes, so changing the define allows us to track it down easily. Not all use of the rx->offs[] array are converted; some uses are required for the regex engine internals, but anything outside of the regex engine should be using the replacement macros, and most things in the regex internals should use it also. --- pp_ctl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'pp_ctl.c') diff --git a/pp_ctl.c b/pp_ctl.c index e26ac219dc..4ffd59bbbe 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -320,14 +320,14 @@ PP(pp_substcont) s = orig + (m - s); cx->sb_strend = s + (cx->sb_strend - m); } - cx->sb_m = m = RX_OFFS(rx)[0].start + orig; + cx->sb_m = m = RX_OFFS_START(rx,0) + orig; if (m > s) { if (DO_UTF8(dstr) && !SvUTF8(cx->sb_targ)) sv_catpvn_nomg_utf8_upgrade(dstr, s, m - s, nsv); else sv_catpvn_nomg(dstr, s, m-s); } - cx->sb_s = RX_OFFS(rx)[0].end + orig; + cx->sb_s = RX_OFFS_END(rx,0) + orig; { /* Update the pos() information. */ SV * const sv = (pm->op_pmflags & PMf_NONDESTRUCT) ? cx->sb_dstr : cx->sb_targ; @@ -407,8 +407,8 @@ Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx) *p++ = (UV)RX_SUBOFFSET(rx); *p++ = (UV)RX_SUBCOFFSET(rx); for (i = 0; i <= RX_NPARENS(rx); ++i) { - *p++ = (UV)RX_OFFS(rx)[i].start; - *p++ = (UV)RX_OFFS(rx)[i].end; + *p++ = (UV)RX_OFFSp(rx)[i].start; + *p++ = (UV)RX_OFFSp(rx)[i].end; } } @@ -438,8 +438,8 @@ S_rxres_restore(pTHX_ void **rsp, REGEXP *rx) RX_SUBOFFSET(rx) = (I32)*p++; RX_SUBCOFFSET(rx) = (I32)*p++; for (i = 0; i <= RX_NPARENS(rx); ++i) { - RX_OFFS(rx)[i].start = (I32)(*p++); - RX_OFFS(rx)[i].end = (I32)(*p++); + RX_OFFSp(rx)[i].start = (I32)(*p++); + RX_OFFSp(rx)[i].end = (I32)(*p++); } } -- cgit v1.2.1