summaryrefslogtreecommitdiff
path: root/src/search.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-08-31 20:16:32 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2016-08-31 20:18:13 -0700
commit368d38f6c4118cfb7db1fd6500c45db1f53c0216 (patch)
treeb9e57607ba41ac7c3591b0e3c271f3a6d2395a81 /src/search.h
parente3c694ca3729d04baa2320e58753d10bc1cf867a (diff)
downloadgrep-368d38f6c4118cfb7db1fd6500c45db1f53c0216.tar.gz
dfa: make dfa.c fully thread-safe
This follows up on Zev Weiss’s recent patches to make the DFA code thread-safe (Bug#24249). It removes the remaining static variables used by dfa.c. These variables are locale-dependent, so they would cause problems in multithreaded code where different threads are in different locales (e.g., via uselocale). I abstracted most of the variables into a new localeinfo module. * src/Makefile.am (grep_SOURCES): Add localeinfo.c. (noinst_HEADERS): Add localeinfo.h. * src/dfa.c: Include localeinfo.h. (struct dfa): Remove multibyte member, as it is now part of localeinfo. New members simple_locale and localeinfo. Put locale-related members at the end. (mbrtowc_cache): Remove; now part of dfa->localeinfo. (charclass_index): Rename back from dfa_charclass_index, since it's private. (unibyte_word_constituent): New arg DFA; use its sbctowc member. (using_utf8, dfa_using_utf8, init_mbrtowc_cache, check_utf8): Remove; now done by localeinfo members. All uses changed. (dfasyntax): New localeinfo arg. Move to end to avoid forward decls. Initialize the entire DFA. (unibyte_c, check_unibyte_c): Remove; now in simple_locale member. (using_simple_locale): Now takes bool instead of DFA. Do the locale check here, rather than in the caller, as the result is now cached in dfa->simple_locale. (dfaalloc): Just allocate the DFA. dfasyntax now initializes it. * src/dfa.h: Add forward decl of struct localeinfo. Adjust to new dfa.c API. * src/dfasearch.c (localeinfo): New var, replacing former static vars like mbrtowc_cache. * src/localeinfo.c, src/localeinfo.h: New files. * src/search.h: Include localeinfo.h. (localeinfo): New decl. * src/searchutils.c (mbclen_cache, build_mbclen_cache): Remove. All uses changed to localeinfo. * tests/Makefile.am (dfa_match_aux_LDADD): Add localeinfo.o. * tests/dfa-match-aux.c: Include localeinfo.h. (main): Adjust to changes in DFA API.
Diffstat (limited to 'src/search.h')
-rw-r--r--src/search.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/search.h b/src/search.h
index 7dc19408..431a67da 100644
--- a/src/search.h
+++ b/src/search.h
@@ -33,6 +33,7 @@
#include "dfa.h"
#include "kwset.h"
#include "xalloc.h"
+#include "localeinfo.h"
_GL_INLINE_HEADER_BEGIN
#ifndef SEARCH_INLINE
@@ -47,14 +48,12 @@ typedef signed char mb_len_map_t;
/* searchutils.c */
extern void kwsinit (kwset_t *);
-
-extern void build_mbclen_cache (void);
-extern size_t mbclen_cache[];
extern ptrdiff_t mb_goback (char const **, char const *, char const *);
extern wint_t mb_prev_wc (char const *, char const *, char const *);
extern wint_t mb_next_wc (char const *, char const *);
/* dfasearch.c */
+extern struct localeinfo localeinfo;
extern void GEAcompile (char const *, size_t, reg_syntax_t);
extern size_t EGexecute (char *, size_t, size_t *, char const *);
@@ -73,7 +72,7 @@ extern size_t Pexecute (char *, size_t, size_t *, char const *);
SEARCH_INLINE size_t
mb_clen (char const *s, size_t n, mbstate_t *mbs)
{
- size_t len = mbclen_cache[to_uchar (*s)];
+ size_t len = localeinfo.sbclen[to_uchar (*s)];
return len == (size_t) -2 ? mbrlen (s, n, mbs) : len;
}