Commit a403707a by Geoff Simmons

Set up compile contexts and options flags in a single function.

parent 7ea83d5c
Pipeline #260 skipped
......@@ -316,10 +316,48 @@ match_call_free(void *priv)
FREE_OBJ(match_call);
}
static inline void
set_opt(uint32_t *options, VCL_BOOL vmod_opt, uint32_t pcre2_opt)
{
if (vmod_opt)
*options |= pcre2_opt;
}
static inline void
set_compile_flags(uint32_t *options, COMPILE_FLAGS)
{
/* XXX check illegal combinations such as never_ucp && ucp ... ? */
set_opt(options, anchored, PCRE2_ANCHORED);
set_opt(options, allow_empty_class, PCRE2_ALLOW_EMPTY_CLASS);
set_opt(options, alt_bsux, PCRE2_ALT_BSUX);
set_opt(options, alt_circumflex, PCRE2_ALT_CIRCUMFLEX);
set_opt(options, alt_verbnames, PCRE2_ALT_VERBNAMES);
set_opt(options, caseless, PCRE2_CASELESS);
set_opt(options, dollar_endonly, PCRE2_DOLLAR_ENDONLY);
set_opt(options, dotall, PCRE2_DOTALL);
set_opt(options, dupnames, PCRE2_DUPNAMES);
set_opt(options, extended, PCRE2_EXTENDED);
set_opt(options, firstline, PCRE2_FIRSTLINE);
set_opt(options, match_unset_backref, PCRE2_MATCH_UNSET_BACKREF);
set_opt(options, multiline, PCRE2_MULTILINE);
set_opt(options, never_backslash_c, PCRE2_NEVER_BACKSLASH_C);
set_opt(options, never_ucp, PCRE2_NEVER_UCP);
set_opt(options, never_utf, PCRE2_NEVER_UTF);
set_opt(options, no_auto_capture, PCRE2_NO_AUTO_CAPTURE);
set_opt(options, no_auto_possess, PCRE2_NO_AUTO_POSSESS);
set_opt(options, no_dotstar_anchor, PCRE2_NO_DOTSTAR_ANCHOR);
set_opt(options, no_start_optimize, PCRE2_NO_START_OPTIMIZE);
set_opt(options, no_utf_check, PCRE2_NO_UTF_CHECK);
set_opt(options, ucp, PCRE2_UCP);
set_opt(options, ungreedy, PCRE2_UNGREEDY);
set_opt(options, use_offset_limit, PCRE2_USE_OFFSET_LIMIT);
set_opt(options, utf, PCRE2_UTF);
}
static pcre2_compile_context *
get_compile_context(VRT_CTX, COMPILE_CTX_OPTS,
const char * restrict const context,
const char * restrict const caller)
get_compile_opts(VRT_CTX, COMPILE_CTX_OPTS, COMPILE_FLAGS, uint32_t *options,
const char * restrict const context,
const char * restrict const caller)
{
pcre2_compile_context *ccontext;
uint32_t val;
......@@ -384,6 +422,7 @@ get_compile_context(VRT_CTX, COMPILE_CTX_OPTS,
WRONG("Illegal newline enum value");
AZ(pcre2_set_newline(ccontext, val));
}
set_compile_flags(options, COMPILE_FLAGS_PARAMS);
return ccontext;
}
......@@ -415,13 +454,6 @@ get_match_context(VRT_CTX, MATCH_CTX_OPTS, const char * restrict const context,
}
static inline void
set_opt(uint32_t *options, VCL_BOOL vmod_opt, uint32_t pcre2_opt)
{
if (vmod_opt)
*options |= pcre2_opt;
}
static inline void
set_match_flags(uint32_t *options, MATCH_FLAGS, SUB_OPTS)
{
set_opt(options, anchored, PCRE2_ANCHORED);
......@@ -514,37 +546,6 @@ get_task(VRT_CTX, struct vmod_priv *priv_task,
return match_task;
}
static inline void
set_compile_flags(uint32_t *options, COMPILE_FLAGS)
{
/* XXX check illegal combinations such as never_ucp && ucp ... ? */
set_opt(options, anchored, PCRE2_ANCHORED);
set_opt(options, allow_empty_class, PCRE2_ALLOW_EMPTY_CLASS);
set_opt(options, alt_bsux, PCRE2_ALT_BSUX);
set_opt(options, alt_circumflex, PCRE2_ALT_CIRCUMFLEX);
set_opt(options, alt_verbnames, PCRE2_ALT_VERBNAMES);
set_opt(options, caseless, PCRE2_CASELESS);
set_opt(options, dollar_endonly, PCRE2_DOLLAR_ENDONLY);
set_opt(options, dotall, PCRE2_DOTALL);
set_opt(options, dupnames, PCRE2_DUPNAMES);
set_opt(options, extended, PCRE2_EXTENDED);
set_opt(options, firstline, PCRE2_FIRSTLINE);
set_opt(options, match_unset_backref, PCRE2_MATCH_UNSET_BACKREF);
set_opt(options, multiline, PCRE2_MULTILINE);
set_opt(options, never_backslash_c, PCRE2_NEVER_BACKSLASH_C);
set_opt(options, never_ucp, PCRE2_NEVER_UCP);
set_opt(options, never_utf, PCRE2_NEVER_UTF);
set_opt(options, no_auto_capture, PCRE2_NO_AUTO_CAPTURE);
set_opt(options, no_auto_possess, PCRE2_NO_AUTO_POSSESS);
set_opt(options, no_dotstar_anchor, PCRE2_NO_DOTSTAR_ANCHOR);
set_opt(options, no_start_optimize, PCRE2_NO_START_OPTIMIZE);
set_opt(options, no_utf_check, PCRE2_NO_UTF_CHECK);
set_opt(options, ucp, PCRE2_UCP);
set_opt(options, ungreedy, PCRE2_UNGREEDY);
set_opt(options, use_offset_limit, PCRE2_USE_OFFSET_LIMIT);
set_opt(options, utf, PCRE2_UTF);
}
static pcre2_code *
compile(VRT_CTX, pcre2_compile_context * restrict const cctx,
VCL_STRING const restrict pattern, uint32_t options, int do_jit,
......@@ -782,10 +783,10 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
VERR(ctx, "pattern is NULL in %s constructor", vcl_name);
return;
}
if ((ccontext = get_compile_context(ctx, COMPILE_CTX_PARAMS, vcl_name,
" constructor")) == NULL)
if ((ccontext = get_compile_opts(ctx, COMPILE_CTX_PARAMS,
COMPILE_FLAGS_PARAMS, &options,
vcl_name, " constructor")) == NULL)
return;
set_compile_flags(&options, COMPILE_FLAGS_PARAMS);
if ((code = compile(ctx, ccontext, pattern, options, have_jit,
vcl_name, " constructor")) == NULL)
......@@ -954,12 +955,13 @@ vmod_match(VRT_CTX, struct vmod_priv *call, struct vmod_priv *task,
if (match_call == NULL)
return 0;
if (match_call->cctx == NULL) {
match_call->cctx = get_compile_context(ctx, COMPILE_CTX_PARAMS,
"pcre2", ".match()");
match_call->cctx
= get_compile_opts(ctx, COMPILE_CTX_PARAMS,
COMPILE_FLAGS_PARAMS,
&match_call->compile_options,
"pcre2", ".match()");
if (match_call->cctx == NULL)
return 0;
set_compile_flags(&match_call->compile_options,
COMPILE_FLAGS_PARAMS);
}
if ((code = compile(ctx, match_call->cctx, pattern,
......@@ -1058,12 +1060,13 @@ vmod_sub(VRT_CTX, struct vmod_priv *priv_call, struct vmod_priv *priv_task,
if (match_opts == NULL)
return 0;
if (match_opts->cctx == NULL) {
match_opts->cctx = get_compile_context(ctx, COMPILE_CTX_PARAMS,
"pcre2", ".sub()");
match_opts->cctx
= get_compile_opts(ctx, COMPILE_CTX_PARAMS,
COMPILE_FLAGS_PARAMS,
&match_opts->compile_options,
"pcre2", ".sub()");
if (match_opts->cctx == NULL)
return 0;
set_compile_flags(&match_opts->compile_options,
COMPILE_FLAGS_PARAMS);
}
if ((code = compile(ctx, match_opts->cctx, pattern,
......
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