Refactor out init of the ovector in task->priv

... such that it can optionally be called before match()
parent 9b123dc5
...@@ -156,6 +156,24 @@ vmod_regex__fini(struct vmod_re_regex **rep) ...@@ -156,6 +156,24 @@ vmod_regex__fini(struct vmod_re_regex **rep)
FREE_OBJ(re); FREE_OBJ(re);
} }
static void
init_task(VRT_CTX, struct vmod_priv *task)
{
ov_t *ov;
AZ(task->priv);
task->priv = WS_Alloc(ctx->ws, sizeof(*ov));
if (task->priv == NULL) {
VSLb(ctx->vsl, SLT_VCL_Error, "vmod re error: "
"insufficient workspace for backref data");
return;
}
task->len = -1;
AZ(task->methods);
ov = (ov_t *) task->priv;
INIT_OBJ(ov, OV_MAGIC);
}
static int static int
match(VRT_CTX, const vre_t *vre, VCL_STRING subject, match(VRT_CTX, const vre_t *vre, VCL_STRING subject,
PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options,
...@@ -173,21 +191,14 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject, ...@@ -173,21 +191,14 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject,
if (subject == NULL) if (subject == NULL)
subject = ""; subject = "";
if (task->priv == NULL) { AN(task);
if ((task->priv = WS_Alloc(ctx->ws, sizeof(*ov))) == NULL) { if (task->priv == NULL)
VSLb(ctx->vsl, SLT_VCL_Error, "vmod re error: " init_task(ctx, task);
"insufficient workspace for backref data"); if (task->priv == NULL)
return (s); return (s);
}
task->len = -1; AN(WS_Allocated(ctx->ws, task->priv, sizeof(*ov)));
AZ(task->methods); CAST_OBJ_NOTNULL(ov, task->priv, OV_MAGIC);
ov = (ov_t *) task->priv;
ov->magic = OV_MAGIC;
}
else {
AN(WS_Allocated(ctx->ws, task->priv, sizeof(*ov)));
CAST_OBJ_NOTNULL(ov, task->priv, OV_MAGIC);
}
// BEGIN duplication with vre // BEGIN duplication with vre
re = VRE_unpack(vre); re = VRE_unpack(vre);
......
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