Skip to content

Commit e55d58b

Browse files
committed
Merge branch 'cb/pcre1-cleanup' into pu
* cb/pcre1-cleanup: grep: refactor and simplify PCRE1 support grep: make sure NO_LIBPCRE1_JIT disable JIT in PCRE1
2 parents a01aec2 + ff61681 commit e55d58b

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
@@ -413,6 +413,7 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
413413
const char *error;
414414
int erroffset;
415415
int options = PCRE_MULTILINE;
416+
int study_options = 0;
416417

417418
if (opt->ignore_case) {
418419
if (!opt->ignore_locale && has_non_ascii(p->pattern))
@@ -427,15 +428,18 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
427428
if (!p->pcre1_regexp)
428429
compile_regexp_failed(p, error);
429430

430-
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, GIT_PCRE_STUDY_JIT_COMPILE, &error);
431-
if (!p->pcre1_extra_info && error)
432-
die("%s", error);
433-
434-
#ifdef GIT_PCRE1_USE_JIT
431+
#if defined(PCRE_CONFIG_JIT) && !defined(NO_LIBPCRE1_JIT)
435432
pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
436433
if (opt->debug)
437434
fprintf(stderr, "pcre1_jit_on=%d\n", p->pcre1_jit_on);
435+
436+
if (p->pcre1_jit_on)
437+
study_options = PCRE_STUDY_JIT_COMPILE;
438438
#endif
439+
440+
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, study_options, &error);
441+
if (!p->pcre1_extra_info && error)
442+
die("%s", error);
439443
}
440444

441445
static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
@@ -464,7 +468,7 @@ static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
464468
static void free_pcre1_regexp(struct grep_pat *p)
465469
{
466470
pcre_free(p->pcre1_regexp);
467-
#ifdef GIT_PCRE1_USE_JIT
471+
#ifdef PCRE_CONFIG_JIT
468472
if (p->pcre1_jit_on)
469473
pcre_free_study(p->pcre1_extra_info);
470474
else

grep.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@
33
#include "color.h"
44
#ifdef USE_LIBPCRE1
55
#include <pcre.h>
6-
#ifdef PCRE_CONFIG_JIT
7-
#if PCRE_MAJOR >= 8 && PCRE_MINOR >= 32
8-
#ifndef NO_LIBPCRE1_JIT
9-
#define GIT_PCRE1_USE_JIT
10-
#define GIT_PCRE_STUDY_JIT_COMPILE PCRE_STUDY_JIT_COMPILE
11-
#endif
12-
#endif
13-
#endif
14-
#ifndef GIT_PCRE_STUDY_JIT_COMPILE
15-
#define GIT_PCRE_STUDY_JIT_COMPILE 0
16-
#endif
176
#else
187
typedef int pcre;
198
typedef int pcre_extra;

0 commit comments

Comments
 (0)