Commit f585b129 by Patrick Steinhardt

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.
parent 7aacf027
...@@ -20,15 +20,14 @@ FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2posix.h) ...@@ -20,15 +20,14 @@ FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2posix.h)
# Look for the library. # Look for the library.
FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8) 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. # Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs) 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. # Copy the results to the output variables.
IF(PCRE2_FOUND) IF(PCRE2_FOUND)
SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY} ${PCRE2_POSIX_LIBRARY}) SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
ELSE(PCRE2_FOUND) ELSE(PCRE2_FOUND)
SET(PCRE2_LIBRARIES) SET(PCRE2_LIBRARIES)
......
...@@ -88,7 +88,6 @@ ...@@ -88,7 +88,6 @@
#include "git2/deprecated.h" #include "git2/deprecated.h"
#include "posix.h" #include "posix.h"
#include "posix_regex.h"
#define DEFAULT_BUFSIZE 65536 #define DEFAULT_BUFSIZE 65536
#define FILEIO_BUFSIZE DEFAULT_BUFSIZE #define FILEIO_BUFSIZE DEFAULT_BUFSIZE
......
...@@ -110,21 +110,6 @@ void git_error_set_str(int error_class, const char *string) ...@@ -110,21 +110,6 @@ void git_error_set_str(int error_class, const char *string)
set_error_from_buffer(error_class); 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) void git_error_clear(void)
{ {
if (GIT_GLOBAL->last_error != NULL) { if (GIT_GLOBAL->last_error != NULL) {
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#ifndef INCLUDE_errors_h__ #ifndef INCLUDE_errors_h__
#define INCLUDE_errors_h__ #define INCLUDE_errors_h__
#include "posix_regex.h"
#include "common.h" #include "common.h"
/* /*
...@@ -18,12 +17,6 @@ void git_error_set(int error_class, const char *fmt, ...) GIT_FORMAT_PRINTF(2, 3 ...@@ -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); 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. * Set error message for user callback if needed.
* *
* If the error code in non-zero and no error message is set, this * If the error code in non-zero and no error message is set, this
......
/*
* 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
...@@ -9,23 +9,12 @@ ...@@ -9,23 +9,12 @@
# endif # endif
#endif #endif
#include <locale.h>
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "futils.h" #include "futils.h"
#include "posix.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) void test_core_posix__initialize(void)
{ {
#if LC_ALL > 0
memset(&old_locales, 0, sizeof(old_locales));
#endif
#ifdef GIT_WIN32 #ifdef GIT_WIN32
/* on win32, the WSA context needs to be initialized /* on win32, the WSA context needs to be initialized
* before any socket calls can be performed */ * before any socket calls can be performed */
...@@ -156,115 +145,6 @@ void test_core_posix__utimes(void) ...@@ -156,115 +145,6 @@ void test_core_posix__utimes(void)
cl_must_pass(p_unlink("foo")); 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) void test_core_posix__unlink_removes_symlink(void)
{ {
if (!git_path_supports_symlinks(clar_sandbox_path())) if (!git_path_supports_symlinks(clar_sandbox_path()))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment