summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grep.c18
-rw-r--r--grep.h3
2 files changed, 7 insertions, 14 deletions
diff --git a/grep.c b/grep.c
index 7d262a2..e580444 100644
--- a/grep.c
+++ b/grep.c
@@ -400,21 +400,11 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
!(!opt->ignore_case && (p->fixed || p->is_fixed)))
options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF);
+#ifdef GIT_PCRE2_VERSION_10_36_OR_HIGHER
/* Work around https://bugs.exim.org/show_bug.cgi?id=2642 fixed in 10.36 */
- if (PCRE2_MATCH_INVALID_UTF && options & (PCRE2_UTF | PCRE2_CASELESS)) {
- struct strbuf buf;
- int len;
- int err;
-
- if ((len = pcre2_config(PCRE2_CONFIG_VERSION, NULL)) < 0)
- BUG("pcre2_config(..., NULL) failed: %d", len);
- strbuf_init(&buf, len + 1);
- if ((err = pcre2_config(PCRE2_CONFIG_VERSION, buf.buf)) < 0)
- BUG("pcre2_config(..., buf.buf) failed: %d", err);
- if (versioncmp(buf.buf, "10.36") < 0)
- options |= PCRE2_NO_START_OPTIMIZE;
- strbuf_release(&buf);
- }
+ if (PCRE2_MATCH_INVALID_UTF && options & (PCRE2_UTF | PCRE2_CASELESS))
+ options |= PCRE2_NO_START_OPTIMIZE;
+#endif
p->pcre2_pattern = pcre2_compile((PCRE2_SPTR)p->pattern,
p->patternlen, options, &error, &erroffset,
diff --git a/grep.h b/grep.h
index ae89d62..54e5204 100644
--- a/grep.h
+++ b/grep.h
@@ -4,6 +4,9 @@
#ifdef USE_LIBPCRE2
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
+#if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 36) || PCRE2_MAJOR >= 11
+#define GIT_PCRE2_VERSION_10_36_OR_HIGHER
+#endif
#else
typedef int pcre2_code;
typedef int pcre2_match_data;