Commit 8cdba637 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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.
parent 6715fb68
...@@ -45,7 +45,8 @@ VPI_re_init(vre_t **rep, const char *re) ...@@ -45,7 +45,8 @@ VPI_re_init(vre_t **rep, const char *re)
int error, erroroffset; int error, erroroffset;
/* This was already check-compiled by the VCL compiler */ /* 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); AN(t);
*rep = t; *rep = t;
} }
......
...@@ -318,7 +318,7 @@ cmd_haproxy_cli_expect(CMD_ARGS) ...@@ -318,7 +318,7 @@ cmd_haproxy_cli_expect(CMD_ARGS)
haproxy_cli_recv(hc); haproxy_cli_recv(hc);
vre = VRE_compile(spec, 0, &error, &erroroffset); vre = VRE_compile(spec, 0, &error, &erroroffset, 1);
if (vre == NULL) { if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf)); AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, error)); AZ(VRE_error(vsb, error));
......
...@@ -650,7 +650,7 @@ cmd_logexp_common(struct logexp *le, struct vtclog *vl, ...@@ -650,7 +650,7 @@ cmd_logexp_common(struct logexp *le, struct vtclog *vl,
} }
vre = NULL; vre = NULL;
if (av[4]) { if (av[4]) {
vre = VRE_compile(av[4], 0, &err, &pos); vre = VRE_compile(av[4], 0, &err, &pos, 1);
if (vre == NULL) { if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf)); AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, err)); AZ(VRE_error(vsb, err));
......
...@@ -155,7 +155,7 @@ cmd_shell_engine(struct vtclog *vl, int ok, const char *cmd, ...@@ -155,7 +155,7 @@ cmd_shell_engine(struct vtclog *vl, int ok, const char *cmd,
vsb = VSB_new_auto(); vsb = VSB_new_auto();
AN(vsb); AN(vsb);
if (re != NULL) { if (re != NULL) {
vre = VRE_compile(re, 0, &err, &erroff); vre = VRE_compile(re, 0, &err, &erroff, 1);
if (vre == NULL) { if (vre == NULL) {
AN(VSB_init(re_vsb, errbuf, sizeof errbuf)); AN(VSB_init(re_vsb, errbuf, sizeof errbuf));
AZ(VRE_error(re_vsb, err)); AZ(VRE_error(re_vsb, err));
......
...@@ -100,7 +100,7 @@ vtc_expect(struct vtclog *vl, ...@@ -100,7 +100,7 @@ vtc_expect(struct vtclog *vl,
rhs = "<undef>"; rhs = "<undef>";
if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) { if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
vre = VRE_compile(rhs, 0, &error, &erroroffset); vre = VRE_compile(rhs, 0, &error, &erroroffset, 1);
if (vre == NULL) { if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf)); AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, error)); AZ(VRE_error(vsb, error));
......
...@@ -406,7 +406,7 @@ cmd_syslog_expect(CMD_ARGS) ...@@ -406,7 +406,7 @@ cmd_syslog_expect(CMD_ARGS)
assert(!strcmp(cmp, "~") || !strcmp(cmp, "!~")); assert(!strcmp(cmp, "~") || !strcmp(cmp, "!~"));
vre = VRE_compile(spec, 0, &error, &erroroffset); vre = VRE_compile(spec, 0, &error, &erroroffset, 1);
if (vre == NULL) { if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf)); AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, error)); AZ(VRE_error(vsb, error));
......
...@@ -746,7 +746,7 @@ varnish_cli(struct varnish *v, const char *cli, unsigned exp, const char *re) ...@@ -746,7 +746,7 @@ varnish_cli(struct varnish *v, const char *cli, unsigned exp, const char *re)
VARNISH_LAUNCH(v); VARNISH_LAUNCH(v);
if (re != NULL) { if (re != NULL) {
vre = VRE_compile(re, 0, &err, &erroff); vre = VRE_compile(re, 0, &err, &erroff, 1);
if (vre == NULL) { if (vre == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf)); AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, err)); AZ(VRE_error(vsb, err));
......
...@@ -56,7 +56,7 @@ typedef struct vre vre_t; ...@@ -56,7 +56,7 @@ typedef struct vre vre_t;
extern const unsigned VRE_has_jit; extern const unsigned VRE_has_jit;
extern const unsigned VRE_CASELESS; 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_error(struct vsb *, int err);
int VRE_match(const vre_t *code, const char *subject, size_t length, int VRE_match(const vre_t *code, const char *subject, size_t length,
int options, const volatile struct vre_limits *lim); int options, const volatile struct vre_limits *lim);
......
...@@ -81,7 +81,7 @@ const unsigned VRE_CASELESS = PCRE_CASELESS; ...@@ -81,7 +81,7 @@ const unsigned VRE_CASELESS = PCRE_CASELESS;
vre_t * vre_t *
VRE_compile(const char *pattern, unsigned options, VRE_compile(const char *pattern, unsigned options,
int *errptr, int *erroffset) int *errptr, int *erroffset, unsigned jit)
{ {
const char *errstr = NULL; const char *errstr = NULL;
vre_t *v; vre_t *v;
...@@ -106,7 +106,11 @@ VRE_compile(const char *pattern, unsigned options, ...@@ -106,7 +106,11 @@ VRE_compile(const char *pattern, unsigned options,
VRE_free(&v); VRE_free(&v);
return (NULL); 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) { if (errstr != NULL) {
*errptr = PCRE_ERROR_INTERNAL; *errptr = PCRE_ERROR_INTERNAL;
VRE_free(&v); VRE_free(&v);
......
...@@ -283,7 +283,7 @@ vsl_IX_arg(struct VSL_data *vsl, int opt, const char *arg) ...@@ -283,7 +283,7 @@ vsl_IX_arg(struct VSL_data *vsl, int opt, const char *arg)
b = e + 1; 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 (vre == NULL) {
if (tags) if (tags)
vbit_destroy(tags); vbit_destroy(tags);
......
...@@ -278,7 +278,7 @@ vxp_expr_regex(struct vxp *vxp, struct vex_rhs **prhs) ...@@ -278,7 +278,7 @@ vxp_expr_regex(struct vxp *vxp, struct vex_rhs **prhs)
(*prhs)->type = VEX_REGEX; (*prhs)->type = VEX_REGEX;
(*prhs)->val_string = strdup(vxp->t->dec); (*prhs)->val_string = strdup(vxp->t->dec);
(*prhs)->val_regex = VRE_compile(vxp->t->dec, vxp->vre_options, (*prhs)->val_regex = VRE_compile(vxp->t->dec, vxp->vre_options,
&err, &erroff); &err, &erroff, 1);
if ((*prhs)->val_regex == NULL) { if ((*prhs)->val_regex == NULL) {
VSB_cat(vxp->sb, "Regular expression error: "); VSB_cat(vxp->sb, "Regular expression error: ");
AZ(VRE_error(vxp->sb, err)); AZ(VRE_error(vxp->sb, err));
......
...@@ -58,7 +58,7 @@ vcc_regexp(struct vcc *tl, struct vsb *vgc_name) ...@@ -58,7 +58,7 @@ vcc_regexp(struct vcc *tl, struct vsb *vgc_name)
assert(tl->t->tok == CSTR); 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) { if (t == NULL) {
VSB_cat(tl->sb, "Regexp compilation error:\n\n"); VSB_cat(tl->sb, "Regexp compilation error:\n\n");
AZ(VRE_error(tl->sb, error)); AZ(VRE_error(tl->sb, error));
......
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