aboutsummaryrefslogtreecommitdiff
path: root/posix
diff options
context:
space:
mode:
Diffstat (limited to 'posix')
-rw-r--r--posix/regex_internal.c29
-rw-r--r--posix/regex_internal.h26
-rw-r--r--posix/regexec.c36
3 files changed, 45 insertions, 46 deletions
diff --git a/posix/regex_internal.c b/posix/regex_internal.c
index 25e7b7e..c4400a8 100644
--- a/posix/regex_internal.c
+++ b/posix/regex_internal.c
@@ -57,8 +57,8 @@
#include "regex.h"
#include "regex_internal.h"
-static void re_string_construct_common (const unsigned char *str,
- int len, re_string_t *pstr,
+static void re_string_construct_common (const char *str, int len,
+ re_string_t *pstr,
RE_TRANSLATE_TYPE trans, int icase);
#ifdef RE_ENABLE_I18N
static int re_string_skip_chars (re_string_t *pstr, int new_raw_idx);
@@ -86,7 +86,7 @@ static unsigned int inline calc_state_hash (const re_node_set *nodes,
static reg_errcode_t
re_string_allocate (pstr, str, len, init_len, trans, icase)
re_string_t *pstr;
- const unsigned char *str;
+ const char *str;
int len, init_len, icase;
RE_TRANSLATE_TYPE trans;
{
@@ -99,8 +99,7 @@ re_string_allocate (pstr, str, len, init_len, trans, icase)
if (BE (ret != REG_NOERROR, 0))
return ret;
- pstr->mbs_case = (MBS_CASE_ALLOCATED (pstr) ? pstr->mbs_case
- : (unsigned char *)str);
+ pstr->mbs_case = (MBS_CASE_ALLOCATED (pstr) ? pstr->mbs_case : (char *) str);
pstr->mbs = MBS_ALLOCATED (pstr) ? pstr->mbs : pstr->mbs_case;
pstr->valid_len = (MBS_CASE_ALLOCATED (pstr) || MBS_ALLOCATED (pstr)
|| MB_CUR_MAX > 1) ? pstr->valid_len : len;
@@ -112,7 +111,7 @@ re_string_allocate (pstr, str, len, init_len, trans, icase)
static reg_errcode_t
re_string_construct (pstr, str, len, trans, icase)
re_string_t *pstr;
- const unsigned char *str;
+ const char *str;
int len, icase;
RE_TRANSLATE_TYPE trans;
{
@@ -128,8 +127,7 @@ re_string_construct (pstr, str, len, trans, icase)
if (BE (ret != REG_NOERROR, 0))
return ret;
}
- pstr->mbs_case = (MBS_CASE_ALLOCATED (pstr) ? pstr->mbs_case
- : (unsigned char *)str);
+ pstr->mbs_case = (MBS_CASE_ALLOCATED (pstr) ? pstr->mbs_case : (char *) str);
pstr->mbs = MBS_ALLOCATED (pstr) ? pstr->mbs : pstr->mbs_case;
if (icase)
@@ -178,13 +176,13 @@ re_string_realloc_buffers (pstr, new_buf_len)
#endif /* RE_ENABLE_I18N */
if (MBS_ALLOCATED (pstr))
{
- pstr->mbs = re_realloc (pstr->mbs, unsigned char, new_buf_len);
+ pstr->mbs = re_realloc (pstr->mbs, char, new_buf_len);
if (BE (pstr->mbs == NULL, 0))
return REG_ESPACE;
}
if (MBS_CASE_ALLOCATED (pstr))
{
- pstr->mbs_case = re_realloc (pstr->mbs_case, unsigned char, new_buf_len);
+ pstr->mbs_case = re_realloc (pstr->mbs_case, char, new_buf_len);
if (BE (pstr->mbs_case == NULL, 0))
return REG_ESPACE;
if (!MBS_ALLOCATED (pstr))
@@ -197,7 +195,7 @@ re_string_realloc_buffers (pstr, new_buf_len)
static void
re_string_construct_common (str, len, pstr, trans, icase)
- const unsigned char *str;
+ const char *str;
int len;
re_string_t *pstr;
RE_TRANSLATE_TYPE trans;
@@ -256,8 +254,9 @@ build_wcs_buffer (pstr)
/* Apply the translateion if we need. */
if (pstr->trans != NULL && mbclen == 1)
{
- int ch = pstr->trans[pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]];
- pstr->mbs_case[byte_idx] = ch;
+ int ch = *((unsigned char *) pstr->raw_mbs + pstr->raw_mbs_idx
+ + byte_idx);
+ pstr->mbs_case[byte_idx] = pstr->trans[ch];
}
/* Write wide character and padding. */
pstr->wcs[byte_idx++] = wc;
@@ -421,9 +420,9 @@ re_string_reconstruct (pstr, idx, eflags, newline)
pstr->tip_context = ((eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
: CONTEXT_NEWLINE | CONTEXT_BEGBUF);
if (!MBS_CASE_ALLOCATED (pstr))
- pstr->mbs_case = (unsigned char *)pstr->raw_mbs;
+ pstr->mbs_case = (char *) pstr->raw_mbs;
if (!MBS_ALLOCATED (pstr) && !MBS_CASE_ALLOCATED (pstr))
- pstr->mbs = (unsigned char *)pstr->raw_mbs;
+ pstr->mbs = (char *) pstr->raw_mbs;
offset = idx;
}
diff --git a/posix/regex_internal.h b/posix/regex_internal.h
index a7f6042..574bf65 100644
--- a/posix/regex_internal.h
+++ b/posix/regex_internal.h
@@ -228,15 +228,15 @@ struct re_string_t
{
/* Indicate the raw buffer which is the original string passed as an
argument of regexec(), re_search(), etc.. */
- const unsigned char *raw_mbs;
+ const char *raw_mbs;
/* Store the multibyte string. In case of "case insensitive mode" like
REG_ICASE, upper cases of the string are stored, otherwise MBS points
the same address that RAW_MBS points. */
- unsigned char *mbs;
+ char *mbs;
/* Store the case sensitive multibyte string. In case of
"case insensitive mode", the original string are stored,
otherwise MBS_CASE points the same address that MBS points. */
- unsigned char *mbs_case;
+ char *mbs_case;
#ifdef RE_ENABLE_I18N
/* Store the wide character string which is corresponding to MBS. */
wint_t *wcs;
@@ -275,13 +275,12 @@ typedef struct re_string_t re_string_t;
#define MBS_CASE_ALLOCATED(pstr) (pstr->trans != NULL)
-static reg_errcode_t re_string_allocate (re_string_t *pstr,
- const unsigned char *str, int len,
- int init_len,
+static reg_errcode_t re_string_allocate (re_string_t *pstr, const char *str,
+ int len, int init_len,
RE_TRANSLATE_TYPE trans, int icase);
-static reg_errcode_t re_string_construct (re_string_t *pstr,
- const unsigned char *str, int len,
- RE_TRANSLATE_TYPE trans, int icase);
+static reg_errcode_t re_string_construct (re_string_t *pstr, const char *str,
+ int len, RE_TRANSLATE_TYPE trans,
+ int icase);
static reg_errcode_t re_string_reconstruct (re_string_t *pstr, int idx,
int eflags, int newline);
static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
@@ -513,7 +512,7 @@ typedef struct
union
{
unsigned char ch;
- unsigned char *name;
+ char *name;
wchar_t wch;
} opr;
} bracket_elem_t;
@@ -581,8 +580,7 @@ re_string_elem_size_at (pstr, idx)
int idx;
{
#ifdef _LIBC
- const unsigned char *p;
- const char *extra;
+ const char *extra, *p;
const int32_t *table, *indirect;
int32_t tmp;
# include <locale/weight.h>
@@ -595,8 +593,8 @@ re_string_elem_size_at (pstr, idx)
indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
_NL_COLLATE_INDIRECTMB);
p = pstr->mbs + idx;
- tmp = findidx (&p);
- return p - (const unsigned char *) pstr->mbs - idx;
+ tmp = findidx ((const unsigned char **) &p);
+ return p - pstr->mbs - idx;
}
else
#endif /* _LIBC */
diff --git a/posix/regexec.c b/posix/regexec.c
index f9b162b..4a9c64a 100644
--- a/posix/regexec.c
+++ b/posix/regexec.c
@@ -123,7 +123,7 @@ static re_dfastate_t **build_trtable (const regex_t *dfa,
static int check_node_accept_bytes (const regex_t *preg, int node_idx,
const re_string_t *input, int idx);
# ifdef _LIBC
-static unsigned int find_collation_sequence_value (const unsigned char *mbs,
+static unsigned int find_collation_sequence_value (const char *mbs,
size_t name_len);
# endif /* _LIBC */
#endif /* RE_ENABLE_I18N */
@@ -153,8 +153,8 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx);
int
regexec (preg, string, nmatch, pmatch, eflags)
- const regex_t *preg;
- const char *string;
+ const regex_t *__restrict preg;
+ const char *__restrict string;
size_t nmatch;
regmatch_t pmatch[];
int eflags;
@@ -1621,7 +1621,7 @@ transit_state_bkref_loop (preg, nodes, work_state_log, mctx)
for (i = 0; i < nodes->nelem; ++i)
{
- unsigned char *buf;
+ char *buf;
int dest_str_idx, subexp_idx, prev_nelem, subexp_len;
int node_idx = nodes->elems[i];
unsigned int context;
@@ -2069,7 +2069,7 @@ check_node_accept_bytes (preg, node_idx, input, str_idx)
{
const re_charset_t *cset = node->opr.mbcset;
# ifdef _LIBC
- const unsigned char *pin = re_string_get_buffer (input) + str_idx;
+ const char *pin = re_string_get_buffer (input) + str_idx;
# endif /* _LIBC */
int match_len = 0;
wchar_t wc = ((cset->nranges || cset->nchar_classes || cset->nmbchars)
@@ -2098,18 +2098,17 @@ check_node_accept_bytes (preg, node_idx, input, str_idx)
{
unsigned int in_collseq = 0;
const int32_t *table, *indirect;
- const unsigned char *weights, *extra, *collseqwc;
+ const char *weights, *extra, *collseqwc;
int32_t idx;
/* This #include defines a local function! */
# include <locale/weight.h>
/* match with collating_symbol? */
if (cset->ncoll_syms)
- extra = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
+ extra = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
for (i = 0; i < cset->ncoll_syms; ++i)
{
- const unsigned char *coll_sym = extra + cset->coll_syms[i];
+ const char *coll_sym = extra + cset->coll_syms[i];
/* Compare the length of input collating element and
the length of current collating element. */
if (*coll_sym != elem_len)
@@ -2148,13 +2147,11 @@ check_node_accept_bytes (preg, node_idx, input, str_idx)
/* match with equivalence_class? */
if (cset->nequiv_classes)
{
- const unsigned char *cp = pin;
+ const unsigned char *cp = (const unsigned char *) pin;
table = (const int32_t *)
_NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
- weights = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTMB);
- extra = (const unsigned char *)
- _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
+ weights = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTMB);
+ extra = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
indirect = (const int32_t *)
_NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
idx = findidx (&cp);
@@ -2183,7 +2180,12 @@ check_node_accept_bytes (preg, node_idx, input, str_idx)
# endif /* _LIBC */
{
/* match with range expression? */
- wchar_t cmp_buf[6] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'};
+#if __GNUC__ >= 2
+ wchar_t cmp_buf[] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'};
+#else
+ wchar_t cmp_buf[] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
+ cmp_buf[2] = wc;
+#endif
for (i = 0; i < cset->nranges; ++i)
{
cmp_buf[0] = cset->range_starts[i];
@@ -2213,7 +2215,7 @@ check_node_accept_bytes (preg, node_idx, input, str_idx)
# ifdef _LIBC
static unsigned int
find_collation_sequence_value (mbs, mbs_len)
- const unsigned char *mbs;
+ const char *mbs;
size_t mbs_len;
{
uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
@@ -2224,7 +2226,7 @@ find_collation_sequence_value (mbs, mbs_len)
/* No valid character. Match it as a single byte character. */
const unsigned char *collseq = (const unsigned char *)
_NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB);
- return collseq[mbs[0]];
+ return collseq[*(unsigned char *) mbs];
}
return UINT_MAX;
}