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 {
struct vmod_priv *task;
const struct vre_limits *vre_limits;
char *b, *e;
char *buf;
size_t len;
};
static int v_matchproto_(objiterate_f)
......@@ -485,25 +486,23 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len)
if (reip->s == PCRE2_ERROR_NOMATCH) {
AZ(reip->startoffset);
AZ(reip->b);
AZ(reip->e);
AZ(reip->buf);
AZ(reip->len);
subject = ptr;
}
else if (reip->s == PCRE2_ERROR_PARTIAL) {
AN(reip->e);
assert(reip->e >= reip->b);
if ((reip->e - reip->b) + len >
WS_ReservationSize(reip->ctx->ws)) {
AN(reip->buf);
if (reip->len + len > WS_ReservationSize(reip->ctx->ws)) {
errmsg(reip->ctx, "vmod re: insufficient workspace "
"while iterating (append)");
return (-1);
}
memcpy(reip->e, ptr, len);
reip->e += len;
memcpy(reip->buf + reip->len, ptr, len);
reip->len += len;
len = (reip->e - reip->b);
subject = reip->b;
len = reip->len;
subject = reip->buf;
}
else {
WRONG("match error should have been latched "
......@@ -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);
if (reip->s == PCRE2_ERROR_PARTIAL && reip->b != NULL)
if (reip->s == PCRE2_ERROR_PARTIAL && reip->buf != NULL)
return (0);
if (reip->s == PCRE2_ERROR_PARTIAL) {
......@@ -533,9 +532,9 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len)
"for partial copy");
return (-1);
}
reip->b = WS_Reservation(reip->ctx->ws);
memcpy(reip->b, ptr, len);
reip->e = reip->b + len;
reip->buf = WS_Reservation(reip->ctx->ws);
memcpy(reip->buf, ptr, len);
reip->len = len;
reip->startoffset = ov->ovector[0];
......@@ -549,15 +548,15 @@ match_iter_f(void *priv, unsigned flush, const void *ptr, ssize_t len)
if (reip->s == PCRE2_ERROR_NOMATCH) {
reip->startoffset = 0;
reip->b = 0;
reip->e = 0;
reip->buf = NULL;
reip->len = 0;
return (0);
}
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 */
WS_Release(reip->ctx->ws, 0);
return (0);
......@@ -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];
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 "
"for match copy");
WS_Release(reip->ctx->ws, 0);
......@@ -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);
if (reip->b == NULL)
if (reip->buf == NULL)
memcpy(p, subject + ov->ovector[0], len);
else
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