Commit 02683b20 by Edward Thomson

regexec: prefix all regexec function calls with p_

Prefix all the calls to the the regexec family of functions with `p_`.
This allows us to swap out all the regular expression functions with our
own implementation.  Move the declarations to `posix_regex.h` for
simpler inclusion.
parent c9f116f1
...@@ -85,7 +85,8 @@ ...@@ -85,7 +85,8 @@
*/ */
#include "git2/deprecated.h" #include "git2/deprecated.h"
#include <regex.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
...@@ -118,7 +119,7 @@ void git_error_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2 ...@@ -118,7 +119,7 @@ void git_error_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2
* Set the error message for a regex failure, using the internal regex * Set the error message for a regex failure, using the internal regex
* error code lookup and return a libgit error code. * error code lookup and return a libgit error code.
*/ */
int git_error_set_regex(const regex_t *regex, int 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.
......
...@@ -345,7 +345,7 @@ typedef struct { ...@@ -345,7 +345,7 @@ typedef struct {
git_config_iterator parent; git_config_iterator parent;
git_config_iterator *current; git_config_iterator *current;
const git_config *cfg; const git_config *cfg;
regex_t regex; p_regex_t regex;
size_t i; size_t i;
} all_iter; } all_iter;
...@@ -423,7 +423,7 @@ static int all_iter_glob_next(git_config_entry **entry, git_config_iterator *_it ...@@ -423,7 +423,7 @@ static int all_iter_glob_next(git_config_entry **entry, git_config_iterator *_it
*/ */
while ((error = all_iter_next(entry, _iter)) == 0) { while ((error = all_iter_next(entry, _iter)) == 0) {
/* skip non-matching keys if regexp was provided */ /* skip non-matching keys if regexp was provided */
if (regexec(&iter->regex, (*entry)->name, 0, NULL, 0) != 0) if (p_regexec(&iter->regex, (*entry)->name, 0, NULL, 0) != 0)
continue; continue;
/* and simply return if we like the entry's name */ /* and simply return if we like the entry's name */
...@@ -447,7 +447,7 @@ static void all_iter_glob_free(git_config_iterator *_iter) ...@@ -447,7 +447,7 @@ static void all_iter_glob_free(git_config_iterator *_iter)
{ {
all_iter *iter = (all_iter *) _iter; all_iter *iter = (all_iter *) _iter;
regfree(&iter->regex); p_regfree(&iter->regex);
all_iter_free(_iter); all_iter_free(_iter);
} }
...@@ -480,7 +480,7 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf ...@@ -480,7 +480,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));
GIT_ERROR_CHECK_ALLOC(iter); GIT_ERROR_CHECK_ALLOC(iter);
if ((result = p_regcomp(&iter->regex, regexp, REG_EXTENDED)) != 0) { if ((result = p_regcomp(&iter->regex, regexp, P_REG_EXTENDED)) != 0) {
git_error_set_regex(&iter->regex, result); git_error_set_regex(&iter->regex, result);
git__free(iter); git__free(iter);
return -1; return -1;
...@@ -510,15 +510,15 @@ int git_config_backend_foreach_match( ...@@ -510,15 +510,15 @@ int git_config_backend_foreach_match(
{ {
git_config_entry *entry; git_config_entry *entry;
git_config_iterator* iter; git_config_iterator* iter;
regex_t regex; p_regex_t regex;
int error = 0; int error = 0;
assert(backend && cb); assert(backend && cb);
if (regexp != NULL) { if (regexp != NULL) {
if ((error = p_regcomp(&regex, regexp, REG_EXTENDED)) != 0) { if ((error = p_regcomp(&regex, regexp, P_REG_EXTENDED)) != 0) {
git_error_set_regex(&regex, error); git_error_set_regex(&regex, error);
regfree(&regex); p_regfree(&regex);
return -1; return -1;
} }
} }
...@@ -530,7 +530,7 @@ int git_config_backend_foreach_match( ...@@ -530,7 +530,7 @@ int git_config_backend_foreach_match(
while (!(iter->next(&entry, iter) < 0)) { while (!(iter->next(&entry, iter) < 0)) {
/* skip non-matching keys if regexp was provided */ /* skip non-matching keys if regexp was provided */
if (regexp && regexec(&regex, entry->name, 0, NULL, 0) != 0) if (regexp && p_regexec(&regex, entry->name, 0, NULL, 0) != 0)
continue; continue;
/* abort iterator on non-zero return value */ /* abort iterator on non-zero return value */
...@@ -541,7 +541,7 @@ int git_config_backend_foreach_match( ...@@ -541,7 +541,7 @@ int git_config_backend_foreach_match(
} }
if (regexp != NULL) if (regexp != NULL)
regfree(&regex); p_regfree(&regex);
iter->free(iter); iter->free(iter);
...@@ -981,7 +981,7 @@ typedef struct { ...@@ -981,7 +981,7 @@ typedef struct {
git_config_iterator parent; git_config_iterator parent;
git_config_iterator *iter; git_config_iterator *iter;
char *name; char *name;
regex_t regex; p_regex_t regex;
int have_regex; int have_regex;
} multivar_iter; } multivar_iter;
...@@ -997,7 +997,7 @@ static int multivar_iter_next(git_config_entry **entry, git_config_iterator *_it ...@@ -997,7 +997,7 @@ static int multivar_iter_next(git_config_entry **entry, git_config_iterator *_it
if (!iter->have_regex) if (!iter->have_regex)
return 0; return 0;
if (regexec(&iter->regex, (*entry)->value, 0, NULL, 0) == 0) if (p_regexec(&iter->regex, (*entry)->value, 0, NULL, 0) == 0)
return 0; return 0;
} }
...@@ -1012,7 +1012,7 @@ void multivar_iter_free(git_config_iterator *_iter) ...@@ -1012,7 +1012,7 @@ void multivar_iter_free(git_config_iterator *_iter)
git__free(iter->name); git__free(iter->name);
if (iter->have_regex) if (iter->have_regex)
regfree(&iter->regex); p_regfree(&iter->regex);
git__free(iter); git__free(iter);
} }
...@@ -1032,11 +1032,11 @@ int git_config_multivar_iterator_new(git_config_iterator **out, const git_config ...@@ -1032,11 +1032,11 @@ 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 = p_regcomp(&iter->regex, regexp, REG_EXTENDED); error = p_regcomp(&iter->regex, regexp, P_REG_EXTENDED);
if (error != 0) { if (error != 0) {
git_error_set_regex(&iter->regex, error); git_error_set_regex(&iter->regex, error);
error = -1; error = -1;
regfree(&iter->regex); p_regfree(&iter->regex);
goto on_error; goto on_error;
} }
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
#include <regex.h>
/* Max depth for [include] directives */ /* Max depth for [include] directives */
#define MAX_INCLUDE_DEPTH 10 #define MAX_INCLUDE_DEPTH 10
...@@ -62,7 +61,7 @@ typedef struct { ...@@ -62,7 +61,7 @@ typedef struct {
} diskfile_parse_state; } diskfile_parse_state;
static int config_read(git_config_entries *entries, const git_repository *repo, git_config_file *file, git_config_level_t level, int depth); static int config_read(git_config_entries *entries, const git_repository *repo, git_config_file *file, git_config_level_t level, int depth);
static int config_write(diskfile_backend *cfg, const char *orig_key, const char *key, const regex_t *preg, const char *value); static int config_write(diskfile_backend *cfg, const char *orig_key, const char *key, const p_regex_t *preg, const char *value);
static char *escape_value(const char *ptr); static char *escape_value(const char *ptr);
static int config_snapshot(git_config_backend **out, git_config_backend *in); static int config_snapshot(git_config_backend **out, git_config_backend *in);
...@@ -329,7 +328,7 @@ static int config_set_multivar( ...@@ -329,7 +328,7 @@ static int config_set_multivar(
{ {
diskfile_backend *b = (diskfile_backend *)cfg; diskfile_backend *b = (diskfile_backend *)cfg;
char *key; char *key;
regex_t preg; p_regex_t preg;
int result; int result;
assert(regexp); assert(regexp);
...@@ -337,7 +336,7 @@ static int config_set_multivar( ...@@ -337,7 +336,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 = p_regcomp(&preg, regexp, REG_EXTENDED); result = p_regcomp(&preg, regexp, P_REG_EXTENDED);
if (result != 0) { if (result != 0) {
git_error_set_regex(&preg, result); git_error_set_regex(&preg, result);
result = -1; result = -1;
...@@ -352,7 +351,7 @@ static int config_set_multivar( ...@@ -352,7 +351,7 @@ static int config_set_multivar(
out: out:
git__free(key); git__free(key);
regfree(&preg); p_regfree(&preg);
return result; return result;
} }
...@@ -395,7 +394,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con ...@@ -395,7 +394,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
diskfile_backend *b = (diskfile_backend *)cfg; diskfile_backend *b = (diskfile_backend *)cfg;
git_config_entries *entries = NULL; git_config_entries *entries = NULL;
git_config_entry *entry = NULL; git_config_entry *entry = NULL;
regex_t preg = { 0 }; p_regex_t preg = { 0 };
char *key = NULL; char *key = NULL;
int result; int result;
...@@ -413,7 +412,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con ...@@ -413,7 +412,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
goto out; goto out;
} }
if ((result = p_regcomp(&preg, regexp, REG_EXTENDED)) != 0) { if ((result = p_regcomp(&preg, regexp, P_REG_EXTENDED)) != 0) {
git_error_set_regex(&preg, result); git_error_set_regex(&preg, result);
result = -1; result = -1;
goto out; goto out;
...@@ -428,7 +427,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con ...@@ -428,7 +427,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
out: out:
git_config_entries_free(entries); git_config_entries_free(entries);
git__free(key); git__free(key);
regfree(&preg); p_regfree(&preg);
return result; return result;
} }
...@@ -954,7 +953,7 @@ struct write_data { ...@@ -954,7 +953,7 @@ struct write_data {
const char *section; const char *section;
const char *orig_name; const char *orig_name;
const char *name; const char *name;
const regex_t *preg; const p_regex_t *preg;
const char *value; const char *value;
}; };
...@@ -1059,7 +1058,7 @@ static int write_on_variable( ...@@ -1059,7 +1058,7 @@ static int write_on_variable(
/* If we have a regex to match the value, see if it matches */ /* If we have a regex to match the value, see if it matches */
if (has_matched && write_data->preg != NULL) if (has_matched && write_data->preg != NULL)
has_matched = (regexec(write_data->preg, var_value, 0, NULL, 0) == 0); has_matched = (p_regexec(write_data->preg, var_value, 0, NULL, 0) == 0);
/* If this isn't the name/value we're looking for, simply dump the /* If this isn't the name/value we're looking for, simply dump the
* existing data back out and continue on. * existing data back out and continue on.
...@@ -1120,7 +1119,7 @@ static int write_on_eof( ...@@ -1120,7 +1119,7 @@ static int write_on_eof(
/* /*
* This is pretty much the parsing, except we write out anything we don't have * This is pretty much the parsing, except we write out anything we don't have
*/ */
static int config_write(diskfile_backend *cfg, const char *orig_key, const char *key, const regex_t *preg, const char* value) static int config_write(diskfile_backend *cfg, const char *orig_key, const char *key, const p_regex_t *preg, const char* value)
{ {
int result; int result;
char *orig_section, *section, *orig_name, *name, *ldot; char *orig_section, *section, *orig_name, *name, *ldot;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "git2/attr.h" #include "git2/attr.h"
#include "common.h"
#include "diff.h" #include "diff.h"
#include "strmap.h" #include "strmap.h"
#include "map.h" #include "map.h"
...@@ -24,7 +25,7 @@ typedef enum { ...@@ -24,7 +25,7 @@ typedef enum {
} git_diff_driver_t; } git_diff_driver_t;
typedef struct { typedef struct {
regex_t re; p_regex_t re;
int flags; int flags;
} git_diff_driver_pattern; } git_diff_driver_pattern;
...@@ -38,7 +39,7 @@ struct git_diff_driver { ...@@ -38,7 +39,7 @@ struct git_diff_driver {
uint32_t binary_flags; uint32_t binary_flags;
uint32_t other_flags; uint32_t other_flags;
git_array_t(git_diff_driver_pattern) fn_patterns; git_array_t(git_diff_driver_pattern) fn_patterns;
regex_t word_pattern; p_regex_t word_pattern;
char name[GIT_FLEX_ARRAY]; char name[GIT_FLEX_ARRAY];
}; };
...@@ -129,7 +130,7 @@ static int diff_driver_add_patterns( ...@@ -129,7 +130,7 @@ static int diff_driver_add_patterns(
static int diff_driver_xfuncname(const git_config_entry *entry, void *payload) static int diff_driver_xfuncname(const git_config_entry *entry, void *payload)
{ {
return diff_driver_add_patterns(payload, entry->value, REG_EXTENDED); return diff_driver_add_patterns(payload, entry->value, P_REG_EXTENDED);
} }
static int diff_driver_funcname(const git_config_entry *entry, void *payload) static int diff_driver_funcname(const git_config_entry *entry, void *payload)
...@@ -204,12 +205,12 @@ static int git_diff_driver_builtin( ...@@ -204,12 +205,12 @@ static int git_diff_driver_builtin(
if (ddef->fns && if (ddef->fns &&
(error = diff_driver_add_patterns( (error = diff_driver_add_patterns(
drv, ddef->fns, ddef->flags | REG_EXTENDED)) < 0) drv, ddef->fns, ddef->flags | P_REG_EXTENDED)) < 0)
goto done; goto done;
if (ddef->words && if (ddef->words &&
(error = p_regcomp( (error = p_regcomp(
&drv->word_pattern, ddef->words, ddef->flags | REG_EXTENDED))) &drv->word_pattern, ddef->words, ddef->flags | P_REG_EXTENDED)))
{ {
error = git_error_set_regex(&drv->word_pattern, error); error = git_error_set_regex(&drv->word_pattern, error);
goto done; goto done;
...@@ -309,7 +310,7 @@ static int git_diff_driver_load( ...@@ -309,7 +310,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 = p_regcomp(&drv->word_pattern, ce->value, REG_EXTENDED))) else if (!(error = p_regcomp(&drv->word_pattern, ce->value, P_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 */
...@@ -393,10 +394,10 @@ void git_diff_driver_free(git_diff_driver *driver) ...@@ -393,10 +394,10 @@ void git_diff_driver_free(git_diff_driver *driver)
return; return;
for (i = 0; i < git_array_size(driver->fn_patterns); ++i) for (i = 0; i < git_array_size(driver->fn_patterns); ++i)
regfree(& git_array_get(driver->fn_patterns, i)->re); p_regfree(& git_array_get(driver->fn_patterns, i)->re);
git_array_clear(driver->fn_patterns); git_array_clear(driver->fn_patterns);
regfree(&driver->word_pattern); p_regfree(&driver->word_pattern);
git__free(driver); git__free(driver);
} }
...@@ -444,12 +445,12 @@ static int diff_context_line__pattern_match( ...@@ -444,12 +445,12 @@ static int diff_context_line__pattern_match(
git_diff_driver *driver, git_buf *line) git_diff_driver *driver, git_buf *line)
{ {
size_t i, maxi = git_array_size(driver->fn_patterns); size_t i, maxi = git_array_size(driver->fn_patterns);
regmatch_t pmatch[2]; p_regmatch_t pmatch[2];
for (i = 0; i < maxi; ++i) { for (i = 0; i < maxi; ++i) {
git_diff_driver_pattern *pat = git_array_get(driver->fn_patterns, i); git_diff_driver_pattern *pat = git_array_get(driver->fn_patterns, i);
if (!regexec(&pat->re, line->ptr, 2, pmatch, 0)) { if (!p_regexec(&pat->re, line->ptr, 2, pmatch, 0)) {
if (pat->flags & REG_NEGATE) if (pat->flags & REG_NEGATE)
return false; return false;
......
...@@ -105,16 +105,16 @@ void git_error_set_str(int error_class, const char *string) ...@@ -105,16 +105,16 @@ 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 regex_t *regex, int error_code) int git_error_set_regex(const p_regex_t *regex, int error_code)
{ {
char error_buf[1024]; char error_buf[1024];
assert(error_code); assert(error_code);
regerror(error_code, regex, error_buf, sizeof(error_buf)); p_regerror(error_code, regex, error_buf, sizeof(error_buf));
git_error_set_str(GIT_ERROR_REGEX, error_buf); git_error_set_str(GIT_ERROR_REGEX, error_buf);
if (error_code == REG_NOMATCH) if (error_code == P_REG_NOMATCH)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
return GIT_EINVALIDSPEC; return GIT_EINVALIDSPEC;
......
/*
* 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"
#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.
*/
#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_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);
}
#else
# define p_regcomp regcomp
#endif
#endif
...@@ -42,7 +42,7 @@ static int maybe_abbrev(git_object** out, git_repository *repo, const char *spec ...@@ -42,7 +42,7 @@ static int maybe_abbrev(git_object** out, git_repository *repo, const char *spec
return maybe_sha_or_abbrev(out, repo, spec, speclen); return maybe_sha_or_abbrev(out, repo, spec, speclen);
} }
static int build_regex(regex_t *regex, const char *pattern) static int build_regex(p_regex_t *regex, const char *pattern)
{ {
int error; int error;
...@@ -51,13 +51,13 @@ static int build_regex(regex_t *regex, const char *pattern) ...@@ -51,13 +51,13 @@ static int build_regex(regex_t *regex, const char *pattern)
return GIT_EINVALIDSPEC; return GIT_EINVALIDSPEC;
} }
error = p_regcomp(regex, pattern, REG_EXTENDED); error = p_regcomp(regex, pattern, P_REG_EXTENDED);
if (!error) if (!error)
return 0; return 0;
error = git_error_set_regex(regex, error); error = git_error_set_regex(regex, error);
regfree(regex); p_regfree(regex);
return error; return error;
} }
...@@ -66,7 +66,7 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe ...@@ -66,7 +66,7 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe
{ {
const char *substr; const char *substr;
int error; int error;
regex_t regex; p_regex_t regex;
substr = strstr(spec, "-g"); substr = strstr(spec, "-g");
...@@ -76,8 +76,8 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe ...@@ -76,8 +76,8 @@ static int maybe_describe(git_object**out, git_repository *repo, const char *spe
if (build_regex(&regex, ".+-[0-9]+-g[0-9a-fA-F]+") < 0) if (build_regex(&regex, ".+-[0-9]+-g[0-9a-fA-F]+") < 0)
return -1; return -1;
error = regexec(&regex, spec, 0, NULL, 0); error = p_regexec(&regex, spec, 0, NULL, 0);
regfree(&regex); p_regfree(&regex);
if (error) if (error)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
...@@ -143,12 +143,12 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out, ...@@ -143,12 +143,12 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
{ {
git_reference *ref = NULL; git_reference *ref = NULL;
git_reflog *reflog = NULL; git_reflog *reflog = NULL;
regex_t preg; p_regex_t preg;
int error = -1; int error = -1;
size_t i, numentries, cur; size_t i, numentries, cur;
const git_reflog_entry *entry; const git_reflog_entry *entry;
const char *msg; const char *msg;
regmatch_t regexmatches[2]; p_regmatch_t regexmatches[2];
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
cur = position; cur = position;
...@@ -173,7 +173,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out, ...@@ -173,7 +173,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
if (!msg) if (!msg)
continue; continue;
if (regexec(&preg, msg, 2, regexmatches, 0)) if (p_regexec(&preg, msg, 2, regexmatches, 0))
continue; continue;
cur--; cur--;
...@@ -199,7 +199,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out, ...@@ -199,7 +199,7 @@ static int retrieve_previously_checked_out_branch_or_revision(git_object **out,
cleanup: cleanup:
git_reference_free(ref); git_reference_free(ref);
git_buf_dispose(&buf); git_buf_dispose(&buf);
regfree(&preg); p_regfree(&preg);
git_reflog_free(reflog); git_reflog_free(reflog);
return error; return error;
} }
...@@ -448,7 +448,7 @@ cleanup: ...@@ -448,7 +448,7 @@ cleanup:
return error; return error;
} }
static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex) static int walk_and_search(git_object **out, git_revwalk *walk, p_regex_t *regex)
{ {
int error; int error;
git_oid oid; git_oid oid;
...@@ -460,7 +460,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex) ...@@ -460,7 +460,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex)
if ((error < 0) && (error != GIT_ENOTFOUND)) if ((error < 0) && (error != GIT_ENOTFOUND))
return -1; return -1;
if (!regexec(regex, git_commit_message((git_commit*)obj), 0, NULL, 0)) { if (!p_regexec(regex, git_commit_message((git_commit*)obj), 0, NULL, 0)) {
*out = obj; *out = obj;
return 0; return 0;
} }
...@@ -476,7 +476,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex) ...@@ -476,7 +476,7 @@ static int walk_and_search(git_object **out, git_revwalk *walk, regex_t *regex)
static int handle_grep_syntax(git_object **out, git_repository *repo, const git_oid *spec_oid, const char *pattern) static int handle_grep_syntax(git_object **out, git_repository *repo, const git_oid *spec_oid, const char *pattern)
{ {
regex_t preg; p_regex_t preg;
git_revwalk *walk = NULL; git_revwalk *walk = NULL;
int error; int error;
...@@ -497,7 +497,7 @@ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_ ...@@ -497,7 +497,7 @@ static int handle_grep_syntax(git_object **out, git_repository *repo, const git_
error = walk_and_search(out, walk, &preg); error = walk_and_search(out, walk, &preg);
cleanup: cleanup:
regfree(&preg); p_regfree(&preg);
git_revwalk_free(walk); git_revwalk_free(walk);
return error; return error;
......
...@@ -89,14 +89,4 @@ GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2]) ...@@ -89,14 +89,4 @@ GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2])
# define p_futimes futimes # define p_futimes futimes
#endif #endif
#ifdef GIT_USE_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
...@@ -29,7 +29,7 @@ typedef struct { ...@@ -29,7 +29,7 @@ typedef struct {
#define PATTERNS(NAME, FN_PATS, WORD_PAT) \ #define PATTERNS(NAME, FN_PATS, WORD_PAT) \
{ NAME, FN_PATS, WORD_PAT WORD_DEFAULT, 0 } { NAME, FN_PATS, WORD_PAT WORD_DEFAULT, 0 }
#define IPATTERN(NAME, FN_PATS, WORD_PAT) \ #define IPATTERN(NAME, FN_PATS, WORD_PAT) \
{ NAME, FN_PATS, WORD_PAT WORD_DEFAULT, REG_ICASE } { NAME, FN_PATS, WORD_PAT WORD_DEFAULT, P_REG_ICASE }
/* /*
* The table of diff driver patterns * The table of diff driver patterns
......
...@@ -60,7 +60,4 @@ extern int p_lstat_posixly(const char *filename, struct stat *buf); ...@@ -60,7 +60,4 @@ 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
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
#include "clar.h" #include "clar.h"
#include <git2.h> #include <git2.h>
#include <posix.h>
#include "common.h" #include "common.h"
#include "posix.h"
/** /**
* Replace for `clar_must_pass` that passes the last library error as the * Replace for `clar_must_pass` that passes the last library error as the
......
...@@ -154,7 +154,7 @@ void test_core_posix__utimes(void) ...@@ -154,7 +154,7 @@ void test_core_posix__utimes(void)
void test_core_posix__p_regcomp_ignores_global_locale_ctype(void) void test_core_posix__p_regcomp_ignores_global_locale_ctype(void)
{ {
regex_t preg; p_regex_t preg;
int error = 0; int error = 0;
const char* oldlocale = setlocale(LC_CTYPE, NULL); const char* oldlocale = setlocale(LC_CTYPE, NULL);
...@@ -169,8 +169,8 @@ void test_core_posix__p_regcomp_ignores_global_locale_ctype(void) ...@@ -169,8 +169,8 @@ void test_core_posix__p_regcomp_ignores_global_locale_ctype(void)
cl_fail("Expected locale to be switched to multibyte"); cl_fail("Expected locale to be switched to multibyte");
} }
p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED); p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", P_REG_EXTENDED);
regfree(&preg); p_regfree(&preg);
setlocale(LC_CTYPE, oldlocale); setlocale(LC_CTYPE, oldlocale);
...@@ -184,14 +184,14 @@ void test_core_posix__p_regcomp_compile_userdiff_regexps(void) ...@@ -184,14 +184,14 @@ void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) { for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) {
git_diff_driver_definition ddef = builtin_defs[idx]; git_diff_driver_definition ddef = builtin_defs[idx];
int error = 0; int error = 0;
regex_t preg; p_regex_t preg;
error = p_regcomp(&preg, ddef.fns, REG_EXTENDED | ddef.flags); error = p_regcomp(&preg, ddef.fns, P_REG_EXTENDED | ddef.flags);
regfree(&preg); p_regfree(&preg);
cl_must_pass(error); cl_must_pass(error);
error = p_regcomp(&preg, ddef.words, REG_EXTENDED); error = p_regcomp(&preg, ddef.words, P_REG_EXTENDED);
regfree(&preg); p_regfree(&preg);
cl_must_pass(error); cl_must_pass(error);
} }
} }
......
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