[master] 8cdba637f vre: Add a jit argument to VRE_compile()
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Jul 5 15:49:05 UTC 2021
commit 8cdba637f83184e2bec32f1bdbf7af39ee1bb38e
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Fri Jun 18 14:06:41 2021 +0200
vre: Add a jit argument to VRE_compile()
We always use it internally except:
- where the pcre2_jit_compilation parameter applies
- when libvcc verifies that a regular expression compiles
For the latter, the verification would attempt a jit compilation as well
until now, but we no longer need to waste cycles on that.
diff --git a/bin/varnishd/cache/cache_vrt_re.c b/bin/varnishd/cache/cache_vrt_re.c
index bda5256f6..4cb5e7b17 100644
--- a/bin/varnishd/cache/cache_vrt_re.c
+++ b/bin/varnishd/cache/cache_vrt_re.c
@@ -45,7 +45,8 @@ VPI_re_init(vre_t **rep, const char *re)
int error, erroroffset;
/* This was already check-compiled by the VCL compiler */
- t = VRE_compile(re, 0, &error, &erroroffset);
+ t = VRE_compile(re, 0, &error, &erroroffset,
+ cache_param->pcre_jit_compilation);
AN(t);
*rep = t;
}
diff --git a/bin/varnishtest/vtc_haproxy.c b/bin/varnishtest/vtc_haproxy.c
index ec6ab1b40..7f0e11601 100644
--- a/bin/varnishtest/vtc_haproxy.c
+++ b/bin/varnishtest/vtc_haproxy.c
@@ -318,7 +318,7 @@ cmd_haproxy_cli_expect(CMD_ARGS)
haproxy_cli_recv(hc);
- vre = VRE_compile(spec, 0, &error, &erroroffset);
+ vre = VRE_compile(spec, 0, &error, &erroroffset, 1);
if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, error));
diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c
index a1d8a2c55..34c139db8 100644
--- a/bin/varnishtest/vtc_logexp.c
+++ b/bin/varnishtest/vtc_logexp.c
@@ -650,7 +650,7 @@ cmd_logexp_common(struct logexp *le, struct vtclog *vl,
}
vre = NULL;
if (av[4]) {
- vre = VRE_compile(av[4], 0, &err, &pos);
+ vre = VRE_compile(av[4], 0, &err, &pos, 1);
if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, err));
diff --git a/bin/varnishtest/vtc_misc.c b/bin/varnishtest/vtc_misc.c
index 4d267c46b..5133ece37 100644
--- a/bin/varnishtest/vtc_misc.c
+++ b/bin/varnishtest/vtc_misc.c
@@ -155,7 +155,7 @@ cmd_shell_engine(struct vtclog *vl, int ok, const char *cmd,
vsb = VSB_new_auto();
AN(vsb);
if (re != NULL) {
- vre = VRE_compile(re, 0, &err, &erroff);
+ vre = VRE_compile(re, 0, &err, &erroff, 1);
if (vre == NULL) {
AN(VSB_init(re_vsb, errbuf, sizeof errbuf));
AZ(VRE_error(re_vsb, err));
diff --git a/bin/varnishtest/vtc_subr.c b/bin/varnishtest/vtc_subr.c
index 3d78566e7..4a9c7ec0e 100644
--- a/bin/varnishtest/vtc_subr.c
+++ b/bin/varnishtest/vtc_subr.c
@@ -100,7 +100,7 @@ vtc_expect(struct vtclog *vl,
rhs = "<undef>";
if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
- vre = VRE_compile(rhs, 0, &error, &erroroffset);
+ vre = VRE_compile(rhs, 0, &error, &erroroffset, 1);
if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, error));
diff --git a/bin/varnishtest/vtc_syslog.c b/bin/varnishtest/vtc_syslog.c
index 78ccf77ee..ac988e9af 100644
--- a/bin/varnishtest/vtc_syslog.c
+++ b/bin/varnishtest/vtc_syslog.c
@@ -406,7 +406,7 @@ cmd_syslog_expect(CMD_ARGS)
assert(!strcmp(cmp, "~") || !strcmp(cmp, "!~"));
- vre = VRE_compile(spec, 0, &error, &erroroffset);
+ vre = VRE_compile(spec, 0, &error, &erroroffset, 1);
if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, error));
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index a463b5665..15ca52016 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -746,7 +746,7 @@ varnish_cli(struct varnish *v, const char *cli, unsigned exp, const char *re)
VARNISH_LAUNCH(v);
if (re != NULL) {
- vre = VRE_compile(re, 0, &err, &erroff);
+ vre = VRE_compile(re, 0, &err, &erroff, 1);
if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, err));
diff --git a/include/vre.h b/include/vre.h
index 0ecdfe806..08c768cd7 100644
--- a/include/vre.h
+++ b/include/vre.h
@@ -56,7 +56,7 @@ typedef struct vre vre_t;
extern const unsigned VRE_has_jit;
extern const unsigned VRE_CASELESS;
-vre_t *VRE_compile(const char *, unsigned, int *, int *);
+vre_t *VRE_compile(const char *, unsigned, int *, int *, unsigned);
int VRE_error(struct vsb *, int err);
int VRE_match(const vre_t *code, const char *subject, size_t length,
int options, const volatile struct vre_limits *lim);
diff --git a/lib/libvarnish/vre.c b/lib/libvarnish/vre.c
index 006b15afb..a4e3f4a72 100644
--- a/lib/libvarnish/vre.c
+++ b/lib/libvarnish/vre.c
@@ -81,7 +81,7 @@ const unsigned VRE_CASELESS = PCRE_CASELESS;
vre_t *
VRE_compile(const char *pattern, unsigned options,
- int *errptr, int *erroffset)
+ int *errptr, int *erroffset, unsigned jit)
{
const char *errstr = NULL;
vre_t *v;
@@ -106,7 +106,11 @@ VRE_compile(const char *pattern, unsigned options,
VRE_free(&v);
return (NULL);
}
- v->re_extra = pcre_study(v->re, VRE_STUDY_JIT_COMPILE, &errstr);
+
+ errstr = NULL;
+ if (jit)
+ v->re_extra = pcre_study(v->re, VRE_STUDY_JIT_COMPILE, &errstr);
+
if (errstr != NULL) {
*errptr = PCRE_ERROR_INTERNAL;
VRE_free(&v);
diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c
index d42d92b24..f7cbcc822 100644
--- a/lib/libvarnishapi/vsl_arg.c
+++ b/lib/libvarnishapi/vsl_arg.c
@@ -283,7 +283,7 @@ vsl_IX_arg(struct VSL_data *vsl, int opt, const char *arg)
b = e + 1;
}
- vre = VRE_compile(b, vsl->C_opt ? VRE_CASELESS : 0, &err, &off);
+ vre = VRE_compile(b, vsl->C_opt ? VRE_CASELESS : 0, &err, &off, 1);
if (vre == NULL) {
if (tags)
vbit_destroy(tags);
diff --git a/lib/libvarnishapi/vxp_parse.c b/lib/libvarnishapi/vxp_parse.c
index 65ebff9a8..6d346d55d 100644
--- a/lib/libvarnishapi/vxp_parse.c
+++ b/lib/libvarnishapi/vxp_parse.c
@@ -278,7 +278,7 @@ vxp_expr_regex(struct vxp *vxp, struct vex_rhs **prhs)
(*prhs)->type = VEX_REGEX;
(*prhs)->val_string = strdup(vxp->t->dec);
(*prhs)->val_regex = VRE_compile(vxp->t->dec, vxp->vre_options,
- &err, &erroff);
+ &err, &erroff, 1);
if ((*prhs)->val_regex == NULL) {
VSB_cat(vxp->sb, "Regular expression error: ");
AZ(VRE_error(vxp->sb, err));
diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c
index bc39936ff..04dca950d 100644
--- a/lib/libvcc/vcc_utils.c
+++ b/lib/libvcc/vcc_utils.c
@@ -58,7 +58,7 @@ vcc_regexp(struct vcc *tl, struct vsb *vgc_name)
assert(tl->t->tok == CSTR);
- t = VRE_compile(tl->t->dec, 0, &error, &erroroffset);
+ t = VRE_compile(tl->t->dec, 0, &error, &erroroffset, 0);
if (t == NULL) {
VSB_cat(tl->sb, "Regexp compilation error:\n\n");
AZ(VRE_error(tl->sb, error));
More information about the varnish-commit
mailing list