diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2019-01-12 22:55:31 +0000 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2019-05-19 11:12:13 +0100 |
| commit | 9ceafb57b2c91732cf7fc0a2be02808f871d5a8b (patch) | |
| tree | 4a16e6f337b3cad2e882c04425907572628e8321 /src | |
| parent | d3a440ca19b060ed69fcb7bb08d2d0fad9a4559d (diff) | |
| download | libgit2-9ceafb57b2c91732cf7fc0a2be02808f871d5a8b.tar.gz | |
regexec: use pcre as our fallback/builtin regex
Use PCRE 8.42 as the builtin regex implementation, using its POSIX
compatibility layer. PCRE uses ASCII by default and the users locale
will not influence its behavior, so its `regcomp` implementation is
similar to `regcomp_l` with a C locale.
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | src/posix_regex.h | 34 | ||||
| -rw-r--r-- | src/win32/precompiled.h | 2 |
3 files changed, 33 insertions, 13 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7a1898fe7..4cdfe23dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -306,6 +306,16 @@ ELSE() MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend ${SHA1_BACKEND}") ENDIF() +# Include PCRE and its POSIX regex compatibility layer when it is required +IF (HAVE_REGCOMP_L) + ADD_FEATURE_INFO(regex ON "using system regcomp_l") +ELSE() + ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/pcre" "${libgit2_BINARY_DIR}/deps/pcre") + LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre") + LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:pcre>) + ADD_FEATURE_INFO(regex ON "using bundled PCRE") +ENDIF() + # Optional external dependency: http-parser FIND_PACKAGE(HTTP_Parser) IF (USE_EXT_HTTP_PARSER AND HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2) diff --git a/src/posix_regex.h b/src/posix_regex.h index fa9190695..c39631edc 100644 --- a/src/posix_regex.h +++ b/src/posix_regex.h @@ -8,14 +8,17 @@ #define INCLUDE_posix_regex_h__ #include "common.h" -#include <regex.h> /* * Regular expressions: if the operating system has p_regcomp_l, - * use that as our p_regcomp implementation, otherwise fall back - * to standard regcomp. + * use it so that we can override the locale environment variable. + * Otherwise, use our bundled PCRE implementation. */ +#ifdef GIT_USE_REGCOMP_L +# include <regex.h> +# include <xlocale.h> + #define P_REG_EXTENDED REG_EXTENDED #define P_REG_ICASE REG_ICASE #define P_REG_NOMATCH REG_NOMATCH @@ -23,19 +26,28 @@ #define p_regex_t regex_t #define p_regmatch_t regmatch_t -#define p_regerror regerror -#define p_regexec regexec -#define p_regfree regfree - -#ifdef GIT_USE_REGCOMP_L -#include <xlocale.h> - GIT_INLINE(int) p_regcomp(p_regex_t *preg, const char *pattern, int cflags) { return regcomp_l(preg, pattern, cflags, (locale_t) 0); } + +#define p_regerror regerror +#define p_regexec regexec +#define p_regfree regfree + #else -# define p_regcomp regcomp +# include "pcreposix.h" + +# define P_REG_EXTENDED PCRE_REG_EXTENDED +# define P_REG_ICASE PCRE_REG_ICASE +# define P_REG_NOMATCH PCRE_REG_NOMATCH + +# define p_regex_t pcre_regex_t +# define p_regmatch_t pcre_regmatch_t +# define p_regcomp pcre_regcomp +# define p_regerror pcre_regerror +# define p_regexec pcre_regexec +# define p_regfree pcre_regfree #endif #endif diff --git a/src/win32/precompiled.h b/src/win32/precompiled.h index 851a083d5..314383d31 100644 --- a/src/win32/precompiled.h +++ b/src/win32/precompiled.h @@ -13,8 +13,6 @@ #include <sys/types.h> #include <sys/stat.h> -#include <regex.h> - #include <io.h> #include <direct.h> #ifdef GIT_THREADS |
