Commit e1bf48fc authored by Geoff Simmons's avatar Geoff Simmons

Move compile() back into the source, it might be inlined into the

match() and sub() functions (gcc does so at least).
parent c6901806
Pipeline #263 skipped
......@@ -279,52 +279,3 @@ get_match_opts(VRT_CTX, struct vmod_priv *priv, MATCH_CTX_OPTS, MATCH_FLAGS,
return match_opts;
}
pcre2_code *
compile(VRT_CTX, pcre2_compile_context * restrict const cctx,
VCL_STRING const restrict pattern, uint32_t options, int do_jit,
const char * const restrict context, const char * const restrict caller)
{
pcre2_code *code;
int err_code = 0;
PCRE2_SIZE err_offset;
/* XXX set the length via parameter */
code = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
options, &err_code, &err_offset, cctx);
if (code == NULL) {
char *msg, *offset_msg;
uintptr_t snap = WS_Snapshot(ctx->ws);
if ((msg = WS_Printf(ctx->ws, "Cannot compile '%s' in %s%s",
pattern, context, caller)) == NULL)
msg = "";
if ((offset_msg = WS_Printf(ctx->ws, " at offset %zu",
err_offset)) == NULL)
offset_msg = "";
report_pcre2_err(ctx, err_code, msg, offset_msg);
WS_Reset(ctx->ws, snap);
return NULL;
}
if (do_jit) {
int ret;
/* XXX check option compatibility; disable via param */
/* XXX set complete or soft/hard partial via param */
options |= PCRE2_JIT_COMPLETE;
ret = pcre2_jit_compile(code, options);
if (ret != 0) {
char *msg;
uintptr_t snap = WS_Snapshot(ctx->ws);
if ((msg = WS_Printf(ctx->ws, "Cannot jit-compile "
"'%s' in %s%s", pattern, context,
caller)) == NULL)
msg = "";
report_pcre2_err(ctx, ret, msg, "");
WS_Reset(ctx->ws, snap);
return NULL;
}
}
return code;
}
......@@ -144,6 +144,55 @@ get_task(VRT_CTX, struct vmod_priv *priv_task,
return match_task;
}
static inline pcre2_code *
compile(VRT_CTX, pcre2_compile_context * restrict const cctx,
VCL_STRING const restrict pattern, uint32_t options, int do_jit,
const char * const restrict context, const char * const restrict caller)
{
pcre2_code *code;
int err_code = 0;
PCRE2_SIZE err_offset;
/* XXX set the length via parameter */
code = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
options, &err_code, &err_offset, cctx);
if (code == NULL) {
char *msg, *offset_msg;
uintptr_t snap = WS_Snapshot(ctx->ws);
if ((msg = WS_Printf(ctx->ws, "Cannot compile '%s' in %s%s",
pattern, context, caller)) == NULL)
msg = "";
if ((offset_msg = WS_Printf(ctx->ws, " at offset %zu",
err_offset)) == NULL)
offset_msg = "";
report_pcre2_err(ctx, err_code, msg, offset_msg);
WS_Reset(ctx->ws, snap);
return NULL;
}
if (do_jit) {
int ret;
/* XXX check option compatibility; disable via param */
/* XXX set complete or soft/hard partial via param */
options |= PCRE2_JIT_COMPLETE;
ret = pcre2_jit_compile(code, options);
if (ret != 0) {
char *msg;
uintptr_t snap = WS_Snapshot(ctx->ws);
if ((msg = WS_Printf(ctx->ws, "Cannot jit-compile "
"'%s' in %s%s", pattern, context,
caller)) == NULL)
msg = "";
report_pcre2_err(ctx, ret, msg, "");
WS_Reset(ctx->ws, snap);
return NULL;
}
}
return code;
}
static inline VCL_BOOL
match(VRT_CTX, pcre2_code * restrict const code,
VCL_STRING restrict const subject, VCL_INT len, const uint32_t options,
......
......@@ -161,11 +161,6 @@ struct match_call *get_match_opts(VRT_CTX, struct vmod_priv *priv,
MATCH_CTX_OPTS, MATCH_FLAGS, SUB_OPTS,
const char *context, const char *caller);
pcre2_code *compile(VRT_CTX, pcre2_compile_context * restrict const cctx,
VCL_STRING const restrict pattern, uint32_t options,
int do_jit, const char * const restrict context,
const char * const restrict caller);
static inline int
check_uint32_range(VRT_CTX, long long limit, const char * const restrict name,
const char * const restrict context,
......
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