Skip to content

Commit 93424f1

Browse files
committed
Merge branch 'cb/pcre1-cleanup'
PCRE fixes. * cb/pcre1-cleanup: grep: refactor and simplify PCRE1 support grep: make sure NO_LIBPCRE1_JIT disable JIT in PCRE1
2 parents a73f917 + ff61681 commit 93424f1

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

Makefile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ all::
3434
# library. Support for version 1 will likely be removed in some future
3535
# release of Git, as upstream has all but abandoned it.
3636
#
37-
# When using USE_LIBPCRE1, define NO_LIBPCRE1_JIT if the PCRE v1
38-
# library is compiled without --enable-jit. We will auto-detect
39-
# whether the version of the PCRE v1 library in use has JIT support at
40-
# all, but we unfortunately can't auto-detect whether JIT support
41-
# hasn't been compiled in in an otherwise JIT-supporting version. If
42-
# you have link-time errors about a missing `pcre_jit_exec` define
43-
# this, or recompile PCRE v1 with --enable-jit.
37+
# When using USE_LIBPCRE1, define NO_LIBPCRE1_JIT if you want to
38+
# disable JIT even if supported by your library.
4439
#
4540
# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are
4641
# in /foo/bar/include and /foo/bar/lib directories. Which version of

grep.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
374374
const char *error;
375375
int erroffset;
376376
int options = PCRE_MULTILINE;
377+
int study_options = 0;
377378

378379
if (opt->ignore_case) {
379380
if (!opt->ignore_locale && has_non_ascii(p->pattern))
@@ -388,15 +389,18 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
388389
if (!p->pcre1_regexp)
389390
compile_regexp_failed(p, error);
390391

391-
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, GIT_PCRE_STUDY_JIT_COMPILE, &error);
392-
if (!p->pcre1_extra_info && error)
393-
die("%s", error);
394-
395-
#ifdef GIT_PCRE1_USE_JIT
392+
#if defined(PCRE_CONFIG_JIT) && !defined(NO_LIBPCRE1_JIT)
396393
pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
397394
if (opt->debug)
398395
fprintf(stderr, "pcre1_jit_on=%d\n", p->pcre1_jit_on);
396+
397+
if (p->pcre1_jit_on)
398+
study_options = PCRE_STUDY_JIT_COMPILE;
399399
#endif
400+
401+
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, study_options, &error);
402+
if (!p->pcre1_extra_info && error)
403+
die("%s", error);
400404
}
401405

402406
static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
@@ -425,7 +429,7 @@ static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
425429
static void free_pcre1_regexp(struct grep_pat *p)
426430
{
427431
pcre_free(p->pcre1_regexp);
428-
#ifdef GIT_PCRE1_USE_JIT
432+
#ifdef PCRE_CONFIG_JIT
429433
if (p->pcre1_jit_on)
430434
pcre_free_study(p->pcre1_extra_info);
431435
else

grep.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
#ifndef PCRE_NO_UTF8_CHECK
77
#define PCRE_NO_UTF8_CHECK 0
88
#endif
9-
#ifdef PCRE_CONFIG_JIT
10-
#if PCRE_MAJOR >= 8 && PCRE_MINOR >= 32
11-
#ifndef NO_LIBPCRE1_JIT
12-
#define GIT_PCRE1_USE_JIT
13-
#define GIT_PCRE_STUDY_JIT_COMPILE PCRE_STUDY_JIT_COMPILE
14-
#endif
15-
#endif
16-
#endif
17-
#ifndef GIT_PCRE_STUDY_JIT_COMPILE
18-
#define GIT_PCRE_STUDY_JIT_COMPILE 0
19-
#endif
209
#else
2110
typedef int pcre;
2211
typedef int pcre_extra;

0 commit comments

Comments
 (0)