posix: remove superseded POSIX regex wrappers The old POSIX regex wrappers have been superseded by our own regexp API that provides a higher-level abstraction. Remove the POSIX wrappers in favor of the new one.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
diff --git a/cmake/Modules/FindPCRE2.cmake b/cmake/Modules/FindPCRE2.cmake
index 122f0e9..f8c5639 100644
--- a/cmake/Modules/FindPCRE2.cmake
+++ b/cmake/Modules/FindPCRE2.cmake
@@ -20,15 +20,14 @@ FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2posix.h)
# Look for the library.
FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8)
-FIND_LIBRARY(PCRE2_POSIX_LIBRARY NAMES pcre2-posix)
# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_POSIX_LIBRARY PCRE2_INCLUDE_DIR)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR)
# Copy the results to the output variables.
IF(PCRE2_FOUND)
- SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY} ${PCRE2_POSIX_LIBRARY})
+ SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
ELSE(PCRE2_FOUND)
SET(PCRE2_LIBRARIES)
diff --git a/src/common.h b/src/common.h
index 8a5761a..a4152ca 100644
--- a/src/common.h
+++ b/src/common.h
@@ -88,7 +88,6 @@
#include "git2/deprecated.h"
#include "posix.h"
-#include "posix_regex.h"
#define DEFAULT_BUFSIZE 65536
#define FILEIO_BUFSIZE DEFAULT_BUFSIZE
diff --git a/src/errors.c b/src/errors.c
index 18d6c2d..c75f6b1 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -110,21 +110,6 @@ void git_error_set_str(int error_class, const char *string)
set_error_from_buffer(error_class);
}
-int git_error_set_regex(const p_regex_t *regex, int error_code)
-{
- char error_buf[1024];
-
- assert(error_code);
-
- p_regerror(error_code, regex, error_buf, sizeof(error_buf));
- git_error_set_str(GIT_ERROR_REGEX, error_buf);
-
- if (error_code == P_REG_NOMATCH)
- return GIT_ENOTFOUND;
-
- return GIT_EINVALIDSPEC;
-}
-
void git_error_clear(void)
{
if (GIT_GLOBAL->last_error != NULL) {
diff --git a/src/errors.h b/src/errors.h
index 86f06f9..a2f60f7 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -8,7 +8,6 @@
#ifndef INCLUDE_errors_h__
#define INCLUDE_errors_h__
-#include "posix_regex.h"
#include "common.h"
/*
@@ -18,12 +17,6 @@ void git_error_set(int error_class, const char *fmt, ...) GIT_FORMAT_PRINTF(2, 3
void git_error_vset(int error_class, const char *fmt, va_list ap);
/**
- * Set the error message for a regex failure, using the internal regex
- * error code lookup and return a libgit error code.
- */
-int git_error_set_regex(const p_regex_t *regex, int error_code);
-
-/**
* Set error message for user callback if needed.
*
* If the error code in non-zero and no error message is set, this
diff --git a/src/posix_regex.h b/src/posix_regex.h
deleted file mode 100644
index 421ffeb..0000000
--- a/src/posix_regex.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) the libgit2 contributors. All rights reserved.
- *
- * This file is part of libgit2, distributed under the GNU GPL v2 with
- * a Linking Exception. For full terms see the included COPYING file.
- */
-#ifndef INCLUDE_posix_regex_h__
-#define INCLUDE_posix_regex_h__
-
-#include "common.h"
-
-/*
- * Regular expressions: if we were asked to use PCRE (either our
- * bundled version or a system version) then use their regcomp
- * compatible implementation.
- */
-
-#ifdef GIT_REGEX_BUILTIN
-
-# 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
-
-/*
- * Use the system-provided `regex` routines, whether that's via the
- * PCRE emulation layer, or libc, preferring `regcomp_l` it's available.
- */
-
-#else
-
-# if defined(GIT_REGEX_PCRE2)
-# include <pcre2posix.h>
-# elif defined(GIT_REGEX_PCRE)
-# include <pcreposix.h>
-# else
-# include <regex.h>
-# endif
-
-# define P_REG_EXTENDED REG_EXTENDED
-# define P_REG_ICASE REG_ICASE
-# define P_REG_NOMATCH REG_NOMATCH
-
-# 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_REGEX_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);
-}
-
-# else
-# define p_regcomp regcomp
-# endif /* GIT_REGEX_REGCOMP_L */
-
-#endif
-
-#endif
diff --git a/tests/core/posix.c b/tests/core/posix.c
index dcc619f..77ac65a 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -9,23 +9,12 @@
# endif
#endif
-#include <locale.h>
-
#include "clar_libgit2.h"
#include "futils.h"
#include "posix.h"
-#include "userdiff.h"
-
-#if LC_ALL > 0
-static const char *old_locales[LC_ALL];
-#endif
void test_core_posix__initialize(void)
{
-#if LC_ALL > 0
- memset(&old_locales, 0, sizeof(old_locales));
-#endif
-
#ifdef GIT_WIN32
/* on win32, the WSA context needs to be initialized
* before any socket calls can be performed */
@@ -156,115 +145,6 @@ void test_core_posix__utimes(void)
cl_must_pass(p_unlink("foo"));
}
-static void try_set_locale(int category)
-{
-#if LC_ALL > 0
- old_locales[category] = setlocale(category, NULL);
-#endif
-
- if (!setlocale(category, "UTF-8") &&
- !setlocale(category, "c.utf8") &&
- !setlocale(category, "en_US.UTF-8"))
- cl_skip();
-
- if (MB_CUR_MAX == 1)
- cl_fail("Expected locale to be switched to multibyte");
-}
-
-void test_core_posix__p_regcomp_ignores_global_locale_ctype(void)
-{
- p_regex_t preg;
-
- try_set_locale(LC_CTYPE);
-
- cl_assert(!p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", P_REG_EXTENDED));
-
- p_regfree(&preg);
-}
-
-void test_core_posix__p_regcomp_ignores_global_locale_collate(void)
-{
- p_regex_t preg;
-
-#ifdef GIT_WIN32
- cl_skip();
-#endif
-
- try_set_locale(LC_COLLATE);
- cl_assert(!p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", P_REG_EXTENDED));
-
- p_regfree(&preg);
-}
-
-void test_core_posix__p_regcomp_matches_digits_with_locale(void)
-{
- p_regex_t preg;
- char c, str[2];
-
-#ifdef GIT_WIN32
- cl_skip();
-#endif
-
- try_set_locale(LC_COLLATE);
- try_set_locale(LC_CTYPE);
-
- cl_assert(!p_regcomp(&preg, "[[:digit:]]", P_REG_EXTENDED));
-
- str[1] = '\0';
- for (c = '0'; c <= '9'; c++) {
- str[0] = c;
- cl_assert(!p_regexec(&preg, str, 0, NULL, 0));
- }
-
- p_regfree(&preg);
-}
-
-void test_core_posix__p_regcomp_matches_alphabet_with_locale(void)
-{
- p_regex_t preg;
- char c, str[2];
-
-#ifdef GIT_WIN32
- cl_skip();
-#endif
-
- try_set_locale(LC_COLLATE);
- try_set_locale(LC_CTYPE);
-
- cl_assert(!p_regcomp(&preg, "[[:alpha:]]", P_REG_EXTENDED));
-
- str[1] = '\0';
- for (c = 'a'; c <= 'z'; c++) {
- str[0] = c;
- cl_assert(!p_regexec(&preg, str, 0, NULL, 0));
- }
- for (c = 'A'; c <= 'Z'; c++) {
- str[0] = c;
- cl_assert(!p_regexec(&preg, str, 0, NULL, 0));
- }
-
- p_regfree(&preg);
-}
-
-void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
-{
- size_t idx;
-
- for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) {
- git_diff_driver_definition ddef = builtin_defs[idx];
- int error = 0;
- p_regex_t preg;
-
- error = p_regcomp(&preg, ddef.fns, P_REG_EXTENDED | ddef.flags);
- p_regfree(&preg);
- cl_assert(!error);
-
- error = p_regcomp(&preg, ddef.words, P_REG_EXTENDED);
- p_regfree(&preg);
- cl_assert(!error);
- }
-}
-
void test_core_posix__unlink_removes_symlink(void)
{
if (!git_path_supports_symlinks(clar_sandbox_path()))