Commit ab96ca55 by Arthur Schreiber

Make sure we use the `C` locale for `regcomp` on macOS.

parent e8ab13b3
...@@ -20,6 +20,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Mo ...@@ -20,6 +20,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Mo
INCLUDE(CheckLibraryExists) INCLUDE(CheckLibraryExists)
INCLUDE(CheckFunctionExists) INCLUDE(CheckFunctionExists)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckStructHasMember) INCLUDE(CheckStructHasMember)
INCLUDE(AddCFlagIfSupported) INCLUDE(AddCFlagIfSupported)
INCLUDE(FindPkgConfig) INCLUDE(FindPkgConfig)
...@@ -507,6 +508,11 @@ ELSE () ...@@ -507,6 +508,11 @@ ELSE ()
ENDIF () ENDIF ()
ENDIF() ENDIF()
CHECK_SYMBOL_EXISTS(regcomp_l "xlocale.h" HAVE_REGCOMP_L)
IF (HAVE_REGCOMP_L)
ADD_DEFINITIONS(-DHAVE_REGCOMP_L)
ENDIF ()
CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS) CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS)
IF (HAVE_FUTIMENS) IF (HAVE_FUTIMENS)
ADD_DEFINITIONS(-DHAVE_FUTIMENS) ADD_DEFINITIONS(-DHAVE_FUTIMENS)
......
...@@ -478,7 +478,7 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf ...@@ -478,7 +478,7 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf
iter = git__calloc(1, sizeof(all_iter)); iter = git__calloc(1, sizeof(all_iter));
GITERR_CHECK_ALLOC(iter); GITERR_CHECK_ALLOC(iter);
if ((result = regcomp(&iter->regex, regexp, REG_EXTENDED)) != 0) { if ((result = p_regcomp(&iter->regex, regexp, REG_EXTENDED)) != 0) {
giterr_set_regex(&iter->regex, result); giterr_set_regex(&iter->regex, result);
git__free(iter); git__free(iter);
return -1; return -1;
...@@ -512,7 +512,7 @@ int git_config_backend_foreach_match( ...@@ -512,7 +512,7 @@ int git_config_backend_foreach_match(
int error = 0; int error = 0;
if (regexp != NULL) { if (regexp != NULL) {
if ((error = regcomp(&regex, regexp, REG_EXTENDED)) != 0) { if ((error = p_regcomp(&regex, regexp, REG_EXTENDED)) != 0) {
giterr_set_regex(&regex, error); giterr_set_regex(&regex, error);
regfree(&regex); regfree(&regex);
return -1; return -1;
...@@ -1003,7 +1003,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config ...@@ -1003,7 +1003,7 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config
goto on_error; goto on_error;
if (regexp != NULL) { if (regexp != NULL) {
error = regcomp(&iter->regex, regexp, REG_EXTENDED); error = p_regcomp(&iter->regex, regexp, REG_EXTENDED);
if (error != 0) { if (error != 0) {
giterr_set_regex(&iter->regex, error); giterr_set_regex(&iter->regex, error);
error = -1; error = -1;
......
...@@ -570,7 +570,7 @@ static int config_set_multivar( ...@@ -570,7 +570,7 @@ static int config_set_multivar(
if ((result = git_config__normalize_name(name, &key)) < 0) if ((result = git_config__normalize_name(name, &key)) < 0)
return result; return result;
result = regcomp(&preg, regexp, REG_EXTENDED); result = p_regcomp(&preg, regexp, REG_EXTENDED);
if (result != 0) { if (result != 0) {
giterr_set_regex(&preg, result); giterr_set_regex(&preg, result);
result = -1; result = -1;
...@@ -657,7 +657,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con ...@@ -657,7 +657,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
refcounted_strmap_free(map); refcounted_strmap_free(map);
result = regcomp(&preg, regexp, REG_EXTENDED); result = p_regcomp(&preg, regexp, REG_EXTENDED);
if (result != 0) { if (result != 0) {
giterr_set_regex(&preg, result); giterr_set_regex(&preg, result);
result = -1; result = -1;
...@@ -1957,4 +1957,3 @@ done: ...@@ -1957,4 +1957,3 @@ done:
git_buf_free(&reader->buffer); git_buf_free(&reader->buffer);
return result; return result;
} }
...@@ -114,7 +114,7 @@ static int diff_driver_add_patterns( ...@@ -114,7 +114,7 @@ static int diff_driver_add_patterns(
if (error < 0) if (error < 0)
break; break;
if ((error = regcomp(&pat->re, buf.ptr, regex_flags)) != 0) { if ((error = p_regcomp(&pat->re, buf.ptr, regex_flags)) != 0) {
/* /*
* TODO: issue a warning * TODO: issue a warning
*/ */
...@@ -210,7 +210,7 @@ static int git_diff_driver_builtin( ...@@ -210,7 +210,7 @@ static int git_diff_driver_builtin(
goto done; goto done;
if (ddef->words && if (ddef->words &&
(error = regcomp( (error = p_regcomp(
&drv->word_pattern, ddef->words, ddef->flags | REG_EXTENDED))) &drv->word_pattern, ddef->words, ddef->flags | REG_EXTENDED)))
{ {
error = giterr_set_regex(&drv->word_pattern, error); error = giterr_set_regex(&drv->word_pattern, error);
...@@ -314,7 +314,7 @@ static int git_diff_driver_load( ...@@ -314,7 +314,7 @@ static int git_diff_driver_load(
goto done; goto done;
if (!ce || !ce->value) if (!ce || !ce->value)
/* no diff.<driver>.wordregex, so just continue */; /* no diff.<driver>.wordregex, so just continue */;
else if (!(error = regcomp(&drv->word_pattern, ce->value, REG_EXTENDED))) else if (!(error = p_regcomp(&drv->word_pattern, ce->value, REG_EXTENDED)))
found_driver = true; found_driver = true;
else { else {
/* TODO: warn about bad regex instead of failure */ /* TODO: warn about bad regex instead of failure */
...@@ -519,4 +519,3 @@ void git_diff_find_context_clear(git_diff_find_context_payload *payload) ...@@ -519,4 +519,3 @@ void git_diff_find_context_clear(git_diff_find_context_payload *payload)
payload->driver = NULL; payload->driver = NULL;
} }
} }
...@@ -50,7 +50,7 @@ static int build_regex(regex_t *regex, const char *pattern) ...@@ -50,7 +50,7 @@ static int build_regex(regex_t *regex, const char *pattern)
return GIT_EINVALIDSPEC; return GIT_EINVALIDSPEC;
} }
error = regcomp(regex, pattern, REG_EXTENDED); error = p_regcomp(regex, pattern, REG_EXTENDED);
if (!error) if (!error)
return 0; return 0;
......
...@@ -80,4 +80,14 @@ GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2]) ...@@ -80,4 +80,14 @@ GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2])
# define p_futimes futimes # define p_futimes futimes
#endif #endif
#ifdef HAVE_REGCOMP_L
#include <xlocale.h>
GIT_INLINE(int) p_regcomp(regex_t *preg, const char *pattern, int cflags)
{
return regcomp_l(preg, pattern, cflags, (locale_t) 0);
}
#else
# define p_regcomp regcomp
#endif
#endif #endif
...@@ -57,4 +57,7 @@ extern int p_lstat_posixly(const char *filename, struct stat *buf); ...@@ -57,4 +57,7 @@ extern int p_lstat_posixly(const char *filename, struct stat *buf);
extern struct tm * p_localtime_r(const time_t *timer, struct tm *result); extern struct tm * p_localtime_r(const time_t *timer, struct tm *result);
extern struct tm * p_gmtime_r(const time_t *timer, struct tm *result); extern struct tm * p_gmtime_r(const time_t *timer, struct tm *result);
/* Use the bundled regcomp */
#define p_regcomp regcomp
#endif #endif
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "posix.h" #include "posix.h"
#include "userdiff.h"
void test_core_posix__initialize(void) void test_core_posix__initialize(void)
{ {
...@@ -146,3 +147,27 @@ void test_core_posix__utimes(void) ...@@ -146,3 +147,27 @@ void test_core_posix__utimes(void)
p_unlink("foo"); p_unlink("foo");
} }
void test_core_posix__p_regcomp_compile_single_byte_regexps(void)
{
regex_t preg;
cl_must_pass(p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED));
regfree(&preg);
}
void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
{
regex_t preg;
size_t idx;
for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) {
git_diff_driver_definition ddef = builtin_defs[idx];
cl_must_pass(p_regcomp(&preg, ddef.fns, REG_EXTENDED | ddef.flags));
cl_must_pass(p_regcomp(&preg, ddef.words, REG_EXTENDED));
}
regfree(&preg);
}
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