about summary refs log tree commit diff
path: root/posix/regcomp.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-11-06 19:57:50 +0000
committerUlrich Drepper <drepper@redhat.com>2002-11-06 19:57:50 +0000
commit1b2c2628354003bd97af125a164e830c9d295e3a (patch)
tree32abaefed6d40cf6c559bcd6e0b47016419e7dc3 /posix/regcomp.c
parentb14993a2356cd7b8c3f74ca2b8e743c056f9401d (diff)
downloadglibc-1b2c2628354003bd97af125a164e830c9d295e3a.tar.gz
glibc-1b2c2628354003bd97af125a164e830c9d295e3a.tar.xz
glibc-1b2c2628354003bd97af125a164e830c9d295e3a.zip
Update.
2002-11-06  Jakub Jelinek  <jakub@redhat.com>

	* posix/regcomp.c (re_compile_pattern): Don't set regs_allocated
	here.
	(regcomp): Don't set can_be_null here.
	(re_comp): Clear whole re_comp_buf with the exception of fastmap.
	(re_compile_internal): Clear can_be_null, set regs_allocated.

	* posix/regcomp.c (re_set_fastmap): New function.
	(re_compile_fastmap_iter): Use it.  Remove redundant type ==
	COMPLEX_BRACKET check.
	* posix/regexec.c (re_search_internal): Optimize searching with
	fastmap.  Call re_string_reconstruct even if match_first is
	smaller than raw_mbs_idx.

2002-11-06  Isamu Hasegawa  <isamu@yamato.ibm.com>

	* posix/regcomp (free_dfa_content): Use free_state.
	* posix/regex_internal.c (re_string_realloc_buffers): Don't edit
	pointers in case that realloc failed.
	(re_node_set_merge): Likewise.
	(register_state): Likewise.
	(create_newstate_common): Invoke memory release functions in case of
	error conditions.
	(create_ci_newstate): Likewise.
	(create_cd_newstate): Likewise.
	(free_state): New function.
	* posix/regexec.c (re_search_internal): Invoke memory release
	functions in case of error conditions.
	(sift_states_backward): Likewise.
	(merge_state_array): Likewise.
	(add_epsilon_src_nodes): Likewise.
	(sub_epsilon_src_nodes): Likewise.
	(search_subexp): Likewise.
	(sift_states_bkref): Likewise.
	(transit_state_sb): Likewise.
	(transit_state_mb): Likewise.
	(transit_state_bkref_loop): Likewise.
	(group_nodes_into_DFAstates): Likewise.
	(push_fail_stack): Don't edit pointers in case that realloc failed.
	(extend_buffers): Likewise.
	(match_ctx_add_entry): Likewise.
Diffstat (limited to 'posix/regcomp.c')
-rw-r--r--posix/regcomp.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/posix/regcomp.c b/posix/regcomp.c
index 3cf07b17d4..03d5cfce14 100644
--- a/posix/regcomp.c
+++ b/posix/regcomp.c
@@ -267,10 +267,6 @@ re_compile_pattern (pattern, length, bufp)
 {
   reg_errcode_t ret;
 
-  /* GNU code is written to assume at least RE_NREGS registers will be set
-     (and at least one extra will be -1).  */
-  bufp->regs_allocated = REGS_UNALLOCATED;
-
   /* And GNU code determines whether or not to get register information
      by passing null for the REGS argument to re_match, etc., not by
      setting no_sub.  */
@@ -339,6 +335,14 @@ re_compile_fastmap (bufp)
 weak_alias (__re_compile_fastmap, re_compile_fastmap)
 #endif
 
+static inline void
+re_set_fastmap (char *fastmap, int icase, int ch)
+{
+  fastmap[ch] = 1;
+  if (icase)
+    fastmap[tolower (ch)] = 1;
+}
+
 /* Helper function for re_compile_fastmap.
    Compile fastmap for the initial_state INIT_STATE.  */
 
@@ -350,20 +354,21 @@ re_compile_fastmap_iter (bufp, init_state, fastmap)
 {
   re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
   int node_cnt;
+  int icase = (MB_CUR_MAX == 1 && (bufp->syntax & RE_ICASE));
   for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
     {
       int node = init_state->nodes.elems[node_cnt];
       re_token_type_t type = dfa->nodes[node].type;
 
       if (type == CHARACTER)
-        fastmap[dfa->nodes[node].opr.c] = 1;
+	re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c);
       else if (type == SIMPLE_BRACKET)
         {
           int i, j, ch;
           for (i = 0, ch = 0; i < BITSET_UINTS; ++i)
             for (j = 0; j < UINT_BITS; ++j, ++ch)
               if (dfa->nodes[node].opr.sbcset[i] & (1 << j))
-                fastmap[ch] = 1;
+                re_set_fastmap (fastmap, icase, ch);
         }
 #ifdef RE_ENABLE_I18N
       else if (type == COMPLEX_BRACKET)
@@ -388,28 +393,24 @@ re_compile_fastmap_iter (bufp, init_state, fastmap)
                   for (i = 0, ch = 0; i < BITSET_UINTS; ++i)
                     for (j = 0; j < UINT_BITS; ++j, ++ch)
                       if (table[ch] < 0)
-                        fastmap[ch] = 1;
+                        re_set_fastmap (fastmap, icase, ch);
                 }
 # else
               if (MB_CUR_MAX > 1)
                 for (i = 0; i < SBC_MAX; ++i)
                   if (__btowc (i) == WEOF)
-                    fastmap[i] = 1;
+                    re_set_fastmap (fastmap, icase, i);
 # endif /* not _LIBC */
             }
           for (i = 0; i < cset->nmbchars; ++i)
             {
               char buf[256];
               wctomb (buf, cset->mbchars[i]);
-              fastmap[*(unsigned char *) buf] = 1;
+              re_set_fastmap (fastmap, icase, *(unsigned char *) buf);
             }
         }
 #endif /* RE_ENABLE_I18N */
-      else if (type == END_OF_RE || type == OP_PERIOD
-#ifdef RE_ENABLE_I18N
-               || type == COMPLEX_BRACKET
-#endif /* RE_ENABLE_I18N */
-              )
+      else if (type == END_OF_RE || type == OP_PERIOD)
         {
           memset (fastmap, '\1', sizeof (char) * SBC_MAX);
           if (type == END_OF_RE)
@@ -468,7 +469,6 @@ regcomp (preg, pattern, cflags)
   preg->buffer = NULL;
   preg->allocated = 0;
   preg->used = 0;
-  preg->can_be_null = 0;
 
   /* Try to allocate space for the fastmap.  */
   preg->fastmap = re_malloc (char, SBC_MAX);
@@ -667,8 +667,7 @@ re_comp (s)
       fastmap = re_comp_buf.fastmap;
       re_comp_buf.fastmap = NULL;
       __regfree (&re_comp_buf);
-      re_comp_buf.buffer = NULL;
-      re_comp_buf.allocated = 0;
+      memset (&re_comp_buf, '\0', sizeof (re_comp_buf));
       re_comp_buf.fastmap = fastmap;
     }
 
@@ -725,6 +724,8 @@ re_compile_internal (preg, pattern, length, syntax)
   preg->not_bol = preg->not_eol = 0;
   preg->used = 0;
   preg->re_nsub = 0;
+  preg->can_be_null = 0;
+  preg->regs_allocated = REGS_UNALLOCATED;
 
   /* Initialize the dfa.  */
   dfa = (re_dfa_t *) preg->buffer;