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)
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
match(VRT_CTX, const vre_t *vre, VCL_STRING subject,
PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options,
......@@ -173,21 +191,14 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject,
if (subject == NULL)
subject = "";
if (task->priv == NULL) {
if ((task->priv = WS_Alloc(ctx->ws, sizeof(*ov))) == NULL) {
VSLb(ctx->vsl, SLT_VCL_Error, "vmod re error: "
"insufficient workspace for backref data");
return (s);
}
task->len = -1;
AZ(task->methods);
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);
}
AN(task);
if (task->priv == NULL)
init_task(ctx, task);
if (task->priv == NULL)
return (s);
AN(WS_Allocated(ctx->ws, task->priv, sizeof(*ov)));
CAST_OBJ_NOTNULL(ov, task->priv, OV_MAGIC);
// BEGIN duplication with 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