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,
/* Compile and match options saved in PRIV_CALL scope */
/* XXX need a lock */
if (call->priv == NULL) {
pcre2_compile_context *cctx;
pcre2_match_context *mctx;
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)
match_call = get_match_opts(ctx, call, MATCH_CTX_PARAMS,
MATCH_FLAGS_PARAMS, "pcre2", ".match()");
if (match_call == NULL)
return 0;
ALLOC_OBJ(match_call, VMOD_PCRE2_MATCH_CALL_MAGIC);
if (match_call == NULL) {
ERRNOMEM(ctx, "allocating call-scoped options in "
"regex.match()");
if (match_call->cctx == NULL) {
match_call->cctx = get_compile_context(ctx, COMPILE_CTX_PARAMS,
"pcre2", ".match()");
if (match_call->cctx == NULL)
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,
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,
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,
return NULL;
}
if (priv_call->priv == NULL) {
pcre2_compile_context *cctx;
pcre2_match_context *mctx;
if ((cctx = get_compile_context(ctx, COMPILE_CTX_PARAMS,
"pcre2", ".match()")) == NULL)
return NULL;
if ((mctx = get_match_context(ctx, MATCH_CTX_PARAMS, "pcre2",
".sub()")) == NULL)
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;
match_opts = get_match_opts(ctx, priv_call, MATCH_CTX_PARAMS,
MATCH_SUB_FLAGS_PARAMS, "pcre2", ".sub()");
if (match_opts == NULL)
return 0;
if (match_opts->cctx == NULL) {
match_opts->cctx = get_compile_context(ctx, COMPILE_CTX_PARAMS,
"pcre2", ".sub()");
if (match_opts->cctx == NULL)
return 0;
set_compile_flags(&match_opts->compile_options,
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,
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