1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-28 04:36:10 +02:00

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
This commit is contained in:
Junio C Hamano 2019-10-11 14:24:47 +09:00
commit 93424f1f7d
3 changed files with 12 additions and 24 deletions

View File

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

16
grep.c
View File

@ -374,6 +374,7 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
const char *error; const char *error;
int erroffset; int erroffset;
int options = PCRE_MULTILINE; int options = PCRE_MULTILINE;
int study_options = 0;
if (opt->ignore_case) { if (opt->ignore_case) {
if (!opt->ignore_locale && has_non_ascii(p->pattern)) 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)
if (!p->pcre1_regexp) if (!p->pcre1_regexp)
compile_regexp_failed(p, error); compile_regexp_failed(p, error);
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, GIT_PCRE_STUDY_JIT_COMPILE, &error); #if defined(PCRE_CONFIG_JIT) && !defined(NO_LIBPCRE1_JIT)
if (!p->pcre1_extra_info && error)
die("%s", error);
#ifdef GIT_PCRE1_USE_JIT
pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on); pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
if (opt->debug) if (opt->debug)
fprintf(stderr, "pcre1_jit_on=%d\n", p->pcre1_jit_on); fprintf(stderr, "pcre1_jit_on=%d\n", p->pcre1_jit_on);
if (p->pcre1_jit_on)
study_options = PCRE_STUDY_JIT_COMPILE;
#endif #endif
p->pcre1_extra_info = pcre_study(p->pcre1_regexp, study_options, &error);
if (!p->pcre1_extra_info && error)
die("%s", error);
} }
static int pcre1match(struct grep_pat *p, const char *line, const char *eol, 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,
static void free_pcre1_regexp(struct grep_pat *p) static void free_pcre1_regexp(struct grep_pat *p)
{ {
pcre_free(p->pcre1_regexp); pcre_free(p->pcre1_regexp);
#ifdef GIT_PCRE1_USE_JIT #ifdef PCRE_CONFIG_JIT
if (p->pcre1_jit_on) if (p->pcre1_jit_on)
pcre_free_study(p->pcre1_extra_info); pcre_free_study(p->pcre1_extra_info);
else else

11
grep.h
View File

@ -6,17 +6,6 @@
#ifndef PCRE_NO_UTF8_CHECK #ifndef PCRE_NO_UTF8_CHECK
#define PCRE_NO_UTF8_CHECK 0 #define PCRE_NO_UTF8_CHECK 0
#endif #endif
#ifdef PCRE_CONFIG_JIT
#if PCRE_MAJOR >= 8 && PCRE_MINOR >= 32
#ifndef NO_LIBPCRE1_JIT
#define GIT_PCRE1_USE_JIT
#define GIT_PCRE_STUDY_JIT_COMPILE PCRE_STUDY_JIT_COMPILE
#endif
#endif
#endif
#ifndef GIT_PCRE_STUDY_JIT_COMPILE
#define GIT_PCRE_STUDY_JIT_COMPILE 0
#endif
#else #else
typedef int pcre; typedef int pcre;
typedef int pcre_extra; typedef int pcre_extra;