Commit c4b9cfe0 by Andreas Jaeger

backport: regex.c: Declare wcs functions only if compiling with MBS_SUPPORT.

Merge from glibc:
        * regex.c: Declare wcs functions only if compiling with
        MBS_SUPPORT.
        Don't use #elif for traditional C.

        * regex.c: Revamp memory allocation for WCHAR functions to
        not use too much stack.

From-SVN: r44471
parent 592a6d1d
2001-07-30 Andreas Jaeger <aj@suse.de>
* regex.c: Declare wcs functions only if compiling with
MBS_SUPPORT.
Don't use #elif for traditional C.
2001-07-23 Ulrich Drepper <drepper@redhat.com>
* regex.c: Revamp memory allocation for WCHAR functions to
not use too much stack.
2001-07-30 Andreas Jaeger <aj@suse.de>
* regex.c: Declare wcs functions only if compiling with
MBS_SUPPORT.
Don't use #elif for traditional C.
2001-07-25 Daniel Jacobowitz <drow@mvista.com> 2001-07-25 Daniel Jacobowitz <drow@mvista.com>
* Makefile.in (regex.o): Add dependency on config.h. * Makefile.in (regex.o): Add dependency on config.h.
......
...@@ -410,9 +410,6 @@ typedef char boolean; ...@@ -410,9 +410,6 @@ typedef char boolean;
static reg_errcode_t byte_regex_compile _RE_ARGS ((const char *pattern, size_t size, static reg_errcode_t byte_regex_compile _RE_ARGS ((const char *pattern, size_t size,
reg_syntax_t syntax, reg_syntax_t syntax,
struct re_pattern_buffer *bufp)); struct re_pattern_buffer *bufp));
static reg_errcode_t wcs_regex_compile _RE_ARGS ((const char *pattern, size_t size,
reg_syntax_t syntax,
struct re_pattern_buffer *bufp));
static int byte_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp, static int byte_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp,
const char *string1, int size1, const char *string1, int size1,
...@@ -420,6 +417,19 @@ static int byte_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp, ...@@ -420,6 +417,19 @@ static int byte_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp,
int pos, int pos,
struct re_registers *regs, struct re_registers *regs,
int stop)); int stop));
static int byte_re_search_2 PARAMS ((struct re_pattern_buffer *bufp,
const char *string1, int size1,
const char *string2, int size2,
int startpos, int range,
struct re_registers *regs, int stop));
static int byte_re_compile_fastmap PARAMS ((struct re_pattern_buffer *bufp));
#ifdef MBS_SUPPORT
static reg_errcode_t wcs_regex_compile _RE_ARGS ((const char *pattern, size_t size,
reg_syntax_t syntax,
struct re_pattern_buffer *bufp));
static int wcs_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp, static int wcs_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp,
const char *cstring1, int csize1, const char *cstring1, int csize1,
const char *cstring2, int csize2, const char *cstring2, int csize2,
...@@ -429,19 +439,13 @@ static int wcs_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp, ...@@ -429,19 +439,13 @@ static int wcs_re_match_2_internal PARAMS ((struct re_pattern_buffer *bufp,
wchar_t *string1, int size1, wchar_t *string1, int size1,
wchar_t *string2, int size2, wchar_t *string2, int size2,
int *mbs_offset1, int *mbs_offset2)); int *mbs_offset1, int *mbs_offset2));
static int byte_re_search_2 PARAMS ((struct re_pattern_buffer *bufp,
const char *string1, int size1,
const char *string2, int size2,
int startpos, int range,
struct re_registers *regs, int stop));
static int wcs_re_search_2 PARAMS ((struct re_pattern_buffer *bufp, static int wcs_re_search_2 PARAMS ((struct re_pattern_buffer *bufp,
const char *string1, int size1, const char *string1, int size1,
const char *string2, int size2, const char *string2, int size2,
int startpos, int range, int startpos, int range,
struct re_registers *regs, int stop)); struct re_registers *regs, int stop));
static int byte_re_compile_fastmap PARAMS ((struct re_pattern_buffer *bufp));
static int wcs_re_compile_fastmap PARAMS ((struct re_pattern_buffer *bufp)); static int wcs_re_compile_fastmap PARAMS ((struct re_pattern_buffer *bufp));
#endif
/* These are the command codes that appear in compiled regular /* These are the command codes that appear in compiled regular
expressions. Some opcodes are followed by argument bytes. A expressions. Some opcodes are followed by argument bytes. A
...@@ -611,7 +615,8 @@ typedef enum ...@@ -611,7 +615,8 @@ typedef enum
# define PREFIX(name) byte_##name # define PREFIX(name) byte_##name
# define ARG_PREFIX(name) name # define ARG_PREFIX(name) name
# define PUT_CHAR(c) putchar (c) # define PUT_CHAR(c) putchar (c)
#elif defined WCHAR #else
# ifdef WCHAR
# define CHAR_T wchar_t # define CHAR_T wchar_t
# define UCHAR_T wchar_t # define UCHAR_T wchar_t
# define COMPILED_BUFFER_VAR wc_buffer # define COMPILED_BUFFER_VAR wc_buffer
...@@ -623,7 +628,7 @@ typedef enum ...@@ -623,7 +628,7 @@ typedef enum
# define PUT_CHAR(c) printf ("%C", c); # define PUT_CHAR(c) printf ("%C", c);
# define TRUE 1 # define TRUE 1
# define FALSE 0 # define FALSE 0
#else # else
# ifdef MBS_SUPPORT # ifdef MBS_SUPPORT
# define WCHAR # define WCHAR
# define INSIDE_RECURSION # define INSIDE_RECURSION
...@@ -634,6 +639,7 @@ typedef enum ...@@ -634,6 +639,7 @@ typedef enum
# define INSIDE_RECURSION # define INSIDE_RECURSION
# include "regex.c" # include "regex.c"
# undef INSIDE_RECURSION # undef INSIDE_RECURSION
# endif
#endif #endif
#ifdef INSIDE_RECURSION #ifdef INSIDE_RECURSION
...@@ -5076,16 +5082,35 @@ weak_alias (__re_search_2, re_search_2) ...@@ -5076,16 +5082,35 @@ weak_alias (__re_search_2, re_search_2)
#endif #endif
#ifdef WCHAR #ifdef WCHAR
# define MAX_ALLOCA_SIZE 2000
# define FREE_WCS_BUFFERS() \ # define FREE_WCS_BUFFERS() \
do { \ do { \
FREE_VAR (string1); \ if (size1 > MAX_ALLOCA_SIZE) \
FREE_VAR (string2); \ { \
free (wcs_string1); \
free (mbs_offset1); \
} \
else \
{ \
FREE_VAR (wcs_string1); \
FREE_VAR (mbs_offset1); \ FREE_VAR (mbs_offset1); \
} \
if (size2 > MAX_ALLOCA_SIZE) \
{ \
free (wcs_string2); \
free (mbs_offset2); \
} \
else \
{ \
FREE_VAR (wcs_string2); \
FREE_VAR (mbs_offset2); \ FREE_VAR (mbs_offset2); \
} \
} while (0) } while (0)
#endif #endif
static int static int
PREFIX(re_search_2) (bufp, string1, size1, string2, size2, startpos, range, PREFIX(re_search_2) (bufp, string1, size1, string2, size2, startpos, range,
regs, stop) regs, stop)
...@@ -5160,35 +5185,71 @@ PREFIX(re_search_2) (bufp, string1, size1, string2, size2, startpos, range, ...@@ -5160,35 +5185,71 @@ PREFIX(re_search_2) (bufp, string1, size1, string2, size2, startpos, range,
fill them with converted string. */ fill them with converted string. */
if (size1 != 0) if (size1 != 0)
{ {
if (size1 > MAX_ALLOCA_SIZE)
{
wcs_string1 = TALLOC (size1 + 1, CHAR_T);
mbs_offset1 = TALLOC (size1 + 1, int);
is_binary = TALLOC (size1 + 1, char);
}
else
{
wcs_string1 = REGEX_TALLOC (size1 + 1, CHAR_T); wcs_string1 = REGEX_TALLOC (size1 + 1, CHAR_T);
mbs_offset1 = REGEX_TALLOC (size1 + 1, int); mbs_offset1 = REGEX_TALLOC (size1 + 1, int);
is_binary = REGEX_TALLOC (size1 + 1, char); is_binary = REGEX_TALLOC (size1 + 1, char);
}
if (!wcs_string1 || !mbs_offset1 || !is_binary) if (!wcs_string1 || !mbs_offset1 || !is_binary)
{ {
if (size1 > MAX_ALLOCA_SIZE)
{
free (wcs_string1);
free (mbs_offset1);
free (is_binary);
}
else
{
FREE_VAR (wcs_string1); FREE_VAR (wcs_string1);
FREE_VAR (mbs_offset1); FREE_VAR (mbs_offset1);
FREE_VAR (is_binary); FREE_VAR (is_binary);
}
return -2; return -2;
} }
wcs_size1 = convert_mbs_to_wcs(wcs_string1, string1, size1, wcs_size1 = convert_mbs_to_wcs(wcs_string1, string1, size1,
mbs_offset1, is_binary); mbs_offset1, is_binary);
wcs_string1[wcs_size1] = L'\0'; /* for a sentinel */ wcs_string1[wcs_size1] = L'\0'; /* for a sentinel */
if (size1 > MAX_ALLOCA_SIZE)
free (is_binary);
else
FREE_VAR (is_binary); FREE_VAR (is_binary);
} }
if (size2 != 0) if (size2 != 0)
{ {
if (size2 > MAX_ALLOCA_SIZE)
{
wcs_string2 = TALLOC (size2 + 1, CHAR_T);
mbs_offset2 = TALLOC (size2 + 1, int);
is_binary = TALLOC (size2 + 1, char);
}
else
{
wcs_string2 = REGEX_TALLOC (size2 + 1, CHAR_T); wcs_string2 = REGEX_TALLOC (size2 + 1, CHAR_T);
mbs_offset2 = REGEX_TALLOC (size2 + 1, int); mbs_offset2 = REGEX_TALLOC (size2 + 1, int);
is_binary = REGEX_TALLOC (size2 + 1, char); is_binary = REGEX_TALLOC (size2 + 1, char);
}
if (!wcs_string2 || !mbs_offset2 || !is_binary) if (!wcs_string2 || !mbs_offset2 || !is_binary)
{ {
FREE_WCS_BUFFERS (); FREE_WCS_BUFFERS ();
if (size2 > MAX_ALLOCA_SIZE)
free (is_binary);
else
FREE_VAR (is_binary); FREE_VAR (is_binary);
return -2; return -2;
} }
wcs_size2 = convert_mbs_to_wcs(wcs_string2, string2, size2, wcs_size2 = convert_mbs_to_wcs(wcs_string2, string2, size2,
mbs_offset2, is_binary); mbs_offset2, is_binary);
wcs_string2[wcs_size2] = L'\0'; /* for a sentinel */ wcs_string2[wcs_size2] = L'\0'; /* for a sentinel */
if (size2 > MAX_ALLOCA_SIZE)
free (is_binary);
else
FREE_VAR (is_binary); FREE_VAR (is_binary);
} }
#endif /* WCHAR */ #endif /* WCHAR */
......
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