Refactor body match iterator from double pointer to extent (ptr+len)

This is in preparation of an upcoming refactor to heap space.
parent 5e4bf311
...@@ -459,7 +459,8 @@ struct re_iter_priv { ...@@ -459,7 +459,8 @@ struct re_iter_priv {
struct vmod_priv *task; struct vmod_priv *task;
const struct vre_limits *vre_limits; const struct vre_limits *vre_limits;
char *b, *e; char *buf;
size_t len;
}; };
static int v_matchproto_(objiterate_f) static int v_matchproto_(objiterate_f)
...@@ -485,25 +486,23 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len) ...@@ -485,25 +486,23 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len)
if (reip->s == PCRE2_ERROR_NOMATCH) { if (reip->s == PCRE2_ERROR_NOMATCH) {
AZ(reip->startoffset); AZ(reip->startoffset);
AZ(reip->b); AZ(reip->buf);
AZ(reip->e); AZ(reip->len);
subject = ptr; subject = ptr;
} }
else if (reip->s == PCRE2_ERROR_PARTIAL) { else if (reip->s == PCRE2_ERROR_PARTIAL) {
AN(reip->e); AN(reip->buf);
assert(reip->e >= reip->b); if (reip->len + len > WS_ReservationSize(reip->ctx->ws)) {
if ((reip->e - reip->b) + len >
WS_ReservationSize(reip->ctx->ws)) {
errmsg(reip->ctx, "vmod re: insufficient workspace " errmsg(reip->ctx, "vmod re: insufficient workspace "
"while iterating (append)"); "while iterating (append)");
return (-1); return (-1);
} }
memcpy(reip->e, ptr, len); memcpy(reip->buf + reip->len, ptr, len);
reip->e += len; reip->len += len;
len = (reip->e - reip->b); len = reip->len;
subject = reip->b; subject = reip->buf;
} }
else { else {
WRONG("match error should have been latched " WRONG("match error should have been latched "
...@@ -524,7 +523,7 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len) ...@@ -524,7 +523,7 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len)
CAST_OBJ_NOTNULL(ov, reip->task->priv, OV_MAGIC); CAST_OBJ_NOTNULL(ov, reip->task->priv, OV_MAGIC);
if (reip->s == PCRE2_ERROR_PARTIAL && reip->b != NULL) if (reip->s == PCRE2_ERROR_PARTIAL && reip->buf != NULL)
return (0); return (0);
if (reip->s == PCRE2_ERROR_PARTIAL) { if (reip->s == PCRE2_ERROR_PARTIAL) {
...@@ -533,9 +532,9 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len) ...@@ -533,9 +532,9 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len)
"for partial copy"); "for partial copy");
return (-1); return (-1);
} }
reip->b = WS_Reservation(reip->ctx->ws); reip->buf = WS_Reservation(reip->ctx->ws);
memcpy(reip->b, ptr, len); memcpy(reip->buf, ptr, len);
reip->e = reip->b + len; reip->len = len;
reip->startoffset = ov->ovector[0]; reip->startoffset = ov->ovector[0];
...@@ -549,15 +548,15 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len) ...@@ -549,15 +548,15 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len)
if (reip->s == PCRE2_ERROR_NOMATCH) { if (reip->s == PCRE2_ERROR_NOMATCH) {
reip->startoffset = 0; reip->startoffset = 0;
reip->b = 0; reip->buf = NULL;
reip->e = 0; reip->len = 0;
return (0); return (0);
} }
assert(reip->s > PCRE2_ERROR_NOMATCH); assert(reip->s > PCRE2_ERROR_NOMATCH);
if (reip->b == NULL && (flush & OBJ_ITER_FLUSH) == 0) { if (reip->buf == NULL && (flush & OBJ_ITER_FLUSH) == 0) {
/* no need to copy */ /* no need to copy */
WS_Release(reip->ctx->ws, 0); WS_Release(reip->ctx->ws, 0);
return (0); return (0);
...@@ -566,7 +565,7 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len) ...@@ -566,7 +565,7 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len)
len = (ssize_t)ov->ovector[1] - (ssize_t)ov->ovector[0]; len = (ssize_t)ov->ovector[1] - (ssize_t)ov->ovector[0];
assert(len >= 0); assert(len >= 0);
if (reip->b == NULL && len > WS_ReservationSize(reip->ctx->ws)) { if (reip->buf == NULL && len > WS_ReservationSize(reip->ctx->ws)) {
errmsg(reip->ctx, "vmod re: insufficient workspace " errmsg(reip->ctx, "vmod re: insufficient workspace "
"for match copy"); "for match copy");
WS_Release(reip->ctx->ws, 0); WS_Release(reip->ctx->ws, 0);
...@@ -574,7 +573,7 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len) ...@@ -574,7 +573,7 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len)
} }
ov->subject = p = WS_Reservation(reip->ctx->ws); ov->subject = p = WS_Reservation(reip->ctx->ws);
if (reip->b == NULL) if (reip->buf == NULL)
memcpy(p, subject + ov->ovector[0], len); memcpy(p, subject + ov->ovector[0], len);
else else
memmove(p, subject + ov->ovector[0], len); memmove(p, subject + ov->ovector[0], len);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment