Commit cd2b0621 authored by Geoff Simmons's avatar Geoff Simmons

The match() and sub() functions re-use code to get call-scoped match contexts.

parent 9c1a7cdb
Pipeline #258 skipped
...@@ -940,32 +940,18 @@ vmod_match(VRT_CTX, struct vmod_priv *call, struct vmod_priv *task, ...@@ -940,32 +940,18 @@ vmod_match(VRT_CTX, struct vmod_priv *call, struct vmod_priv *task,
/* Compile and match options saved in PRIV_CALL scope */ /* Compile and match options saved in PRIV_CALL scope */
/* XXX need a lock */ /* XXX need a lock */
if (call->priv == NULL) { match_call = get_match_opts(ctx, call, MATCH_CTX_PARAMS,
pcre2_compile_context *cctx; MATCH_FLAGS_PARAMS, "pcre2", ".match()");
pcre2_match_context *mctx; if (match_call == NULL)
if ((cctx = get_compile_context(ctx, COMPILE_CTX_PARAMS,
"pcre2", ".match()")) == NULL)
return 0;
if ((mctx = get_match_context(ctx, MATCH_CTX_PARAMS,
"pcre2", ".match()")) == NULL)
return 0; return 0;
ALLOC_OBJ(match_call, VMOD_PCRE2_MATCH_CALL_MAGIC); if (match_call->cctx == NULL) {
if (match_call == NULL) { match_call->cctx = get_compile_context(ctx, COMPILE_CTX_PARAMS,
ERRNOMEM(ctx, "allocating call-scoped options in " "pcre2", ".match()");
"regex.match()"); if (match_call->cctx == NULL)
return 0; return 0;
}
call->priv = match_call;
call->free = match_call_free;
match_call->cctx = cctx;
match_call->mctx = mctx;
set_compile_flags(&match_call->compile_options, set_compile_flags(&match_call->compile_options,
COMPILE_FLAGS_PARAMS); COMPILE_FLAGS_PARAMS);
set_match_flags(&match_call->match_options, MATCH_FLAGS_PARAMS);
} }
else
CAST_OBJ(match_call, call->priv, VMOD_PCRE2_MATCH_CALL_MAGIC);
if ((code = compile(ctx, match_call->cctx, pattern, if ((code = compile(ctx, match_call->cctx, pattern,
match_call->compile_options, have_jit && !no_jit, match_call->compile_options, have_jit && !no_jit,
...@@ -1064,39 +1050,18 @@ vmod_sub(VRT_CTX, struct vmod_priv *priv_call, struct vmod_priv *priv_task, ...@@ -1064,39 +1050,18 @@ vmod_sub(VRT_CTX, struct vmod_priv *priv_call, struct vmod_priv *priv_task,
return NULL; return NULL;
} }
if (priv_call->priv == NULL) { match_opts = get_match_opts(ctx, priv_call, MATCH_CTX_PARAMS,
pcre2_compile_context *cctx; MATCH_SUB_FLAGS_PARAMS, "pcre2", ".sub()");
pcre2_match_context *mctx; if (match_opts == NULL)
return 0;
if ((cctx = get_compile_context(ctx, COMPILE_CTX_PARAMS, if (match_opts->cctx == NULL) {
"pcre2", ".match()")) == NULL) match_opts->cctx = get_compile_context(ctx, COMPILE_CTX_PARAMS,
return NULL; "pcre2", ".sub()");
if ((mctx = get_match_context(ctx, MATCH_CTX_PARAMS, "pcre2", if (match_opts->cctx == NULL)
".sub()")) == NULL) return 0;
return NULL;
ALLOC_OBJ(match_opts, VMOD_PCRE2_MATCH_CALL_MAGIC);
AN(match_opts);
match_opts->cctx = cctx;
match_opts->mctx = mctx;
priv_call->priv = match_opts;
priv_call->free = match_call_free;
set_compile_flags(&match_opts->compile_options, set_compile_flags(&match_opts->compile_options,
COMPILE_FLAGS_PARAMS); COMPILE_FLAGS_PARAMS);
set_match_flags(&match_opts->match_options, MATCH_FLAGS_PARAMS);
set_opt(&match_opts->match_options, suball,
PCRE2_SUBSTITUTE_GLOBAL);
set_opt(&match_opts->match_options, sub_extended,
PCRE2_SUBSTITUTE_EXTENDED);
set_opt(&match_opts->match_options, unknown_unset,
PCRE2_SUBSTITUTE_UNKNOWN_UNSET);
set_opt(&match_opts->match_options, unset_empty,
PCRE2_SUBSTITUTE_UNSET_EMPTY);
} }
else
CAST_OBJ(match_opts, priv_call->priv,
VMOD_PCRE2_MATCH_CALL_MAGIC);
if ((code = compile(ctx, match_opts->cctx, pattern, if ((code = compile(ctx, match_opts->cctx, pattern,
match_opts->compile_options, have_jit && !no_jit, match_opts->compile_options, have_jit && !no_jit,
......
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