From MAILER-DAEMON Tue Jul 12 12:45:06 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Qgg53-0006W0-Cd
	for mharc-grep-commit@gnu.org; Tue, 12 Jul 2011 12:45:05 -0400
Received: from eggs.gnu.org ([140.186.70.92]:53046)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1Qgg4w-0006TG-OG
	for grep-commit@gnu.org; Tue, 12 Jul 2011 12:45:03 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1Qgg4r-0003ID-Sd
	for grep-commit@gnu.org; Tue, 12 Jul 2011 12:44:58 -0400
Received: from colonialone.fsf.org ([140.186.70.51]:56183)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1Qgg4r-0003I7-FZ
	for grep-commit@gnu.org; Tue, 12 Jul 2011 12:44:53 -0400
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by colonialone.fsf.org with esmtp (Exim 4.69)
	(envelope-from <jim@meyering.net>) id 1Qgg4r-0007sO-Bi
	for grep-commit@gnu.org; Tue, 12 Jul 2011 16:44:53 +0000
Received: from meyering by vcs-noshell.in.savannah.gnu.org with local (Exim
	4.72) (envelope-from <meyering@savannah.gnu.org>) id 1Qgg4q-0003DM-2d
	for grep-commit@gnu.org; Tue, 12 Jul 2011 16:44:52 +0000
Date: Tue, 12 Jul 2011 16:44:52 +0000
Message-Id: <E1Qgg4q-0003DM-2d@vcs-noshell.in.savannah.gnu.org>
To: grep-commit@gnu.org
Subject: grep branch, master, updated. v2.9-12-gb2d9a6f
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 406ab56cdd977fbd05216392ac655dd7204a307a
X-Git-Newrev: b2d9a6f8c9e71007181eb1d7be4cae096e0da655
From: Jim Meyering <jim@meyering.net>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.51
X-BeenThere: grep-commit@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
Reply-To: bug-grep@gnu.org
List-Id: CVS commit notices for GNU grep <grep-commit.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/grep-commit>,
	<mailto:grep-commit-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/grep-commit>
List-Post: <mailto:grep-commit@gnu.org>
List-Help: <mailto:grep-commit-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/grep-commit>,
	<mailto:grep-commit-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 12 Jul 2011 16:45:04 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  b2d9a6f8c9e71007181eb1d7be4cae096e0da655 (commit)
       via  4158429fde2a56a590e78915e6c19bfa468f597d (commit)
       via  20abce9298cf56fd14a1d2361566827b8dc256c9 (commit)
       via  bc7b0852e60cc0679dae82014b79d05006932874 (commit)
       via  3abe897119cb46e3cbd7be02fdf9598c2758b461 (commit)
      from  406ab56cdd977fbd05216392ac655dd7204a307a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=b2d9a6f8c9e71007181eb1d7be4cae096e0da655


commit b2d9a6f8c9e71007181eb1d7be4cae096e0da655
Author: Jim Meyering <meyering@redhat.com>
Date:   Tue Jul 12 17:08:05 2011 +0200

    dfa: simplify use of *ALLOC macros
    
    * src/dfa.c (XNMALLOC, XCALLOC): Redefine without outer cast-to-(t *).
    (CALLOC, MALLOC, REALLOC): Remove type "t" parameter and adjust callers.

diff --git a/src/dfa.c b/src/dfa.c
index febe43b..611003d 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -29,6 +29,7 @@
 #include <limits.h>
 #include <string.h>
 #include <locale.h>
+#include "verify.h"
 
 #define STREQ(a, b) (strcmp (a, b) == 0)
 
@@ -396,9 +397,26 @@ struct dfa
 static void dfamust (struct dfa *dfa);
 static void regexp (void);
 
-#define CALLOC(p, t, n) ((p) = XCALLOC (n, t))
-#define MALLOC(p, t, n) ((p) = XNMALLOC (n, t))
-#define REALLOC(p, t, n) ((p) = xnrealloc (p, n, sizeof (t)))
+/* These two macros are identical to the ones in gnulib's xalloc.h,
+   except that they not to case the result to "(t *)", and thus may
+   be used via type-free CALLOC and MALLOC macros.  */
+#undef XNMALLOC
+#undef XCALLOC
+
+/* Allocate memory for N elements of type T, with error checking.  */
+/* extern t *XNMALLOC (size_t n, typename t); */
+# define XNMALLOC(n, t) \
+    (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))
+
+/* Allocate memory for N elements of type T, with error checking,
+   and zero it.  */
+/* extern t *XCALLOC (size_t n, typename t); */
+# define XCALLOC(n, t) \
+    (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))
+
+#define CALLOC(p, n) do { (p) = XCALLOC (n, *(p)); } while (0)
+#define MALLOC(p, n) do { (p) = XNMALLOC (n, *(p)); } while (0)
+#define REALLOC(p, n) do {(p) = xnrealloc (p, n, sizeof (*(p))); } while (0)
 
 /* Reallocate an array of type *P if N_ALLOC is <= N_REQUIRED. */
 #define REALLOC_IF_NECESSARY(p, n_alloc, n_required)		\
@@ -866,7 +884,7 @@ parse_bracket_exp (void)
                       wctype_t wt = wctype (class);
 
                       if (ch_classes_al == 0)
-                        MALLOC(work_mbc->ch_classes, wctype_t, ++ch_classes_al);
+                        MALLOC(work_mbc->ch_classes, ++ch_classes_al);
                       REALLOC_IF_NECESSARY(work_mbc->ch_classes,
                                            ch_classes_al,
                                            work_mbc->nch_classes + 1);
@@ -883,14 +901,14 @@ parse_bracket_exp (void)
               else if (c1 == '=' || c1 == '.')
                 {
                   char *elem;
-                  MALLOC(elem, char, len + 1);
+                  MALLOC(elem, len + 1);
                   strncpy(elem, str, len + 1);
 
                   if (c1 == '=')
                     /* build equivalent class.  */
                     {
                       if (equivs_al == 0)
-                        MALLOC(work_mbc->equivs, char*, ++equivs_al);
+                        MALLOC(work_mbc->equivs, ++equivs_al);
                       REALLOC_IF_NECESSARY(work_mbc->equivs,
                                            equivs_al,
                                            work_mbc->nequivs + 1);
@@ -901,7 +919,7 @@ parse_bracket_exp (void)
                     /* build collating element.  */
                     {
                       if (coll_elems_al == 0)
-                        MALLOC(work_mbc->coll_elems, char*, ++coll_elems_al);
+                        MALLOC(work_mbc->coll_elems, ++coll_elems_al);
                       REALLOC_IF_NECESSARY(work_mbc->coll_elems,
                                            coll_elems_al,
                                            work_mbc->ncoll_elems + 1);
@@ -952,8 +970,8 @@ parse_bracket_exp (void)
                  to the pair of ranges, [m-z] [M-Z].  */
               if (range_sts_al == 0)
                 {
-                  MALLOC(work_mbc->range_sts, wchar_t, ++range_sts_al);
-                  MALLOC(work_mbc->range_ends, wchar_t, ++range_ends_al);
+                  MALLOC(work_mbc->range_sts, ++range_sts_al);
+                  MALLOC(work_mbc->range_ends, ++range_ends_al);
                 }
               REALLOC_IF_NECESSARY(work_mbc->range_sts,
                                    range_sts_al, work_mbc->nranges + 1);
@@ -1940,7 +1958,7 @@ state_index (struct dfa *d, position_set const *s, int newline, int letter)
   /* We'll have to create a new state. */
   REALLOC_IF_NECESSARY(d->states, d->salloc, d->sindex + 1);
   d->states[i].hash = hash;
-  MALLOC(d->states[i].elems.elems, position, s->nelem);
+  MALLOC(d->states[i].elems.elems, s->nelem);
   copy(s, &d->states[i].elems);
   d->states[i].newline = newline;
   d->states[i].letter = letter;
@@ -1986,7 +2004,7 @@ epsclosure (position_set *s, struct dfa const *d)
   char *visited;	/* array of booleans, enough to use char, not int */
   position p, old;
 
-  CALLOC(visited, char, d->tindex);
+  CALLOC(visited, d->tindex);
 
   for (i = 0; i < s->nelem; ++i)
     if (d->tokens[s->elems[i].index] >= NOTCHAR
@@ -2123,20 +2141,20 @@ dfaanalyze (struct dfa *d, int searchflag)
 
   d->searchflag = searchflag;
 
-  MALLOC(nullable, int, d->depth);
+  MALLOC(nullable, d->depth);
   o_nullable = nullable;
-  MALLOC(nfirstpos, int, d->depth);
+  MALLOC(nfirstpos, d->depth);
   o_nfirst = nfirstpos;
-  MALLOC(firstpos, position, d->nleaves);
+  MALLOC(firstpos, d->nleaves);
   o_firstpos = firstpos, firstpos += d->nleaves;
-  MALLOC(nlastpos, int, d->depth);
+  MALLOC(nlastpos, d->depth);
   o_nlast = nlastpos;
-  MALLOC(lastpos, position, d->nleaves);
+  MALLOC(lastpos, d->nleaves);
   o_lastpos = lastpos, lastpos += d->nleaves;
-  CALLOC(nalloc, int, d->tindex);
-  MALLOC(merged.elems, position, d->nleaves);
+  CALLOC(nalloc, d->tindex);
+  MALLOC(merged.elems, d->nleaves);
 
-  CALLOC(d->follows, position_set, d->tindex);
+  CALLOC(d->follows, d->tindex);
 
   for (i = 0; i < d->tindex; ++i)
 #ifdef DEBUG
@@ -2244,7 +2262,7 @@ dfaanalyze (struct dfa *d, int searchflag)
 
         /* Allocate the follow set for this position. */
         nalloc[i] = 1;
-        MALLOC(d->follows[i].elems, position, nalloc[i]);
+        MALLOC(d->follows[i].elems, nalloc[i]);
         break;
       }
 #ifdef DEBUG
@@ -2293,7 +2311,7 @@ dfaanalyze (struct dfa *d, int searchflag)
         copy(&d->follows[i], &merged);
         epsclosure(&merged, d);
         if (d->follows[i].nelem < merged.nelem)
-          REALLOC(d->follows[i].elems, position, merged.nelem);
+          REALLOC(d->follows[i].elems, merged.nelem);
         copy(&merged, &d->follows[i]);
       }
 
@@ -2313,7 +2331,7 @@ dfaanalyze (struct dfa *d, int searchflag)
   /* Build the initial state. */
   d->salloc = 1;
   d->sindex = 0;
-  MALLOC(d->states, dfa_state, d->salloc);
+  MALLOC(d->states, d->salloc);
   state_index(d, &merged, wants_newline, 0);
 
   free(o_nullable);
@@ -2415,8 +2433,7 @@ dfastate (int s, struct dfa *d, int trans[])
              which can match with a single character not a byte.  */
           if (d->states[s].mbps.nelem == 0)
             {
-              MALLOC(d->states[s].mbps.elems, position,
-                     d->states[s].elems.nelem);
+              MALLOC(d->states[s].mbps.elems, d->states[s].elems.nelem);
             }
           insert(pos, &(d->states[s].mbps));
           continue;
@@ -2485,7 +2502,7 @@ dfastate (int s, struct dfa *d, int trans[])
             {
               copyset(leftovers, labels[ngrps]);
               copyset(intersect, labels[j]);
-              MALLOC(grps[ngrps].elems, position, d->nleaves);
+              MALLOC(grps[ngrps].elems, d->nleaves);
               copy(&grps[j], &grps[ngrps]);
               ++ngrps;
             }
@@ -2506,15 +2523,15 @@ dfastate (int s, struct dfa *d, int trans[])
         {
           copyset(matches, labels[ngrps]);
           zeroset(matches);
-          MALLOC(grps[ngrps].elems, position, d->nleaves);
+          MALLOC(grps[ngrps].elems, d->nleaves);
           grps[ngrps].nelem = 1;
           grps[ngrps].elems[0] = pos;
           ++ngrps;
         }
     }
 
-  MALLOC(follows.elems, position, d->nleaves);
-  MALLOC(tmp.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
+  MALLOC(tmp.elems, d->nleaves);
 
   /* If we are a searching matcher, the default transition is to a state
      containing the positions of state 0, otherwise the default transition
@@ -2694,7 +2711,7 @@ build_state (int s, struct dfa *d)
       s, *d))
     d->success[s] |= 1;
 
-  MALLOC(trans, int, NOTCHAR);
+  MALLOC(trans, NOTCHAR);
   dfastate(s, d, trans);
 
   /* Now go through the new transition table, and make sure that the trans
@@ -2707,11 +2724,11 @@ build_state (int s, struct dfa *d)
 
         while (trans[i] >= d->tralloc)
           d->tralloc *= 2;
-        REALLOC(d->realtrans, int *, d->tralloc + 1);
+        REALLOC(d->realtrans, d->tralloc + 1);
         d->trans = d->realtrans + 1;
-        REALLOC(d->fails, int *, d->tralloc);
-        REALLOC(d->success, int, d->tralloc);
-        REALLOC(d->newlines, int, d->tralloc);
+        REALLOC(d->fails, d->tralloc);
+        REALLOC(d->success, d->tralloc);
+        REALLOC(d->newlines, d->tralloc);
         while (oldalloc < d->tralloc)
           {
             d->trans[oldalloc] = NULL;
@@ -2735,11 +2752,11 @@ build_state_zero (struct dfa *d)
 {
   d->tralloc = 1;
   d->trcount = 0;
-  CALLOC(d->realtrans, int *, d->tralloc + 1);
+  CALLOC(d->realtrans, d->tralloc + 1);
   d->trans = d->realtrans + 1;
-  CALLOC(d->fails, int *, d->tralloc);
-  MALLOC(d->success, int, d->tralloc);
-  MALLOC(d->newlines, int, d->tralloc);
+  CALLOC(d->fails, d->tralloc);
+  MALLOC(d->success, d->tralloc);
+  MALLOC(d->newlines, d->tralloc);
   build_state(0, d);
 }
 
@@ -2780,11 +2797,11 @@ realloc_trans_if_necessary(struct dfa *d, int new_state)
 
       while (new_state >= d->tralloc)
         d->tralloc *= 2;
-      REALLOC(d->realtrans, int *, d->tralloc + 1);
+      REALLOC(d->realtrans, d->tralloc + 1);
       d->trans = d->realtrans + 1;
-      REALLOC(d->fails, int *, d->tralloc);
-      REALLOC(d->success, int, d->tralloc);
-      REALLOC(d->newlines, int, d->tralloc);
+      REALLOC(d->fails, d->tralloc);
+      REALLOC(d->success, d->tralloc);
+      REALLOC(d->newlines, d->tralloc);
       while (oldalloc < d->tralloc)
         {
           d->trans[oldalloc] = NULL;
@@ -3018,7 +3035,7 @@ check_matching_with_multibyte_ops (struct dfa *d, int s, int idx)
   int i;
   int* rarray;
 
-  MALLOC(rarray, int, d->states[s].mbps.nelem);
+  MALLOC(rarray, d->states[s].mbps.nelem);
   for (i = 0; i < d->states[s].mbps.nelem; ++i)
     {
       position pos = d->states[s].mbps.elems[i];
@@ -3139,7 +3156,7 @@ transit_state (struct dfa *d, int s, unsigned char const **pp)
 
   /* This state has some operators which can match a multibyte character.  */
   follows.nelem = 0;
-  MALLOC(follows.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
 
   /* `maxlen' may be longer than the length of a character, because it may
      not be a character but a (multi character) collating element.
@@ -3270,8 +3287,8 @@ dfaexec (struct dfa *d, char const *begin, char *end,
 #if MBS_SUPPORT
   if (d->mb_cur_max > 1)
     {
-      MALLOC(mblen_buf, unsigned char, end - begin + 2);
-      MALLOC(inputwcs, wchar_t, end - begin + 2);
+      MALLOC(mblen_buf, end - begin + 2);
+      MALLOC(inputwcs, end - begin + 2);
       memset(&mbs, 0, sizeof(mbstate_t));
       prepare_wc_buf ((const char *) p, end);
     }
@@ -3439,19 +3456,19 @@ dfainit (struct dfa *d)
   memset (d, 0, sizeof *d);
 
   d->calloc = 1;
-  MALLOC(d->charclasses, charclass, d->calloc);
+  MALLOC(d->charclasses, d->calloc);
 
   d->talloc = 1;
-  MALLOC(d->tokens, token, d->talloc);
+  MALLOC(d->tokens, d->talloc);
 
 #if MBS_SUPPORT
   d->mb_cur_max = MB_CUR_MAX;
   if (d->mb_cur_max > 1)
     {
       d->nmultibyte_prop = 1;
-      MALLOC(d->multibyte_prop, int, d->nmultibyte_prop);
+      MALLOC(d->multibyte_prop, d->nmultibyte_prop);
       d->mbcsets_alloc = 1;
-      MALLOC(d->mbcsets, struct mb_char_classes, d->mbcsets_alloc);
+      MALLOC(d->mbcsets, d->mbcsets_alloc);
     }
 #endif
 }
@@ -4038,9 +4055,9 @@ dfamust (struct dfa *d)
  done:
   if (strlen(result))
     {
-      MALLOC(dm, struct dfamust, 1);
+      MALLOC(dm, 1);
       dm->exact = exact;
-      MALLOC(dm->must, char, strlen(result) + 1);
+      MALLOC(dm->must, strlen(result) + 1);
       strcpy(dm->must, result);
       dm->next = d->musts;
       d->musts = dm;

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=4158429fde2a56a590e78915e6c19bfa468f597d


commit b2d9a6f8c9e71007181eb1d7be4cae096e0da655
Author: Jim Meyering <meyering@redhat.com>
Date:   Tue Jul 12 17:08:05 2011 +0200

    dfa: simplify use of *ALLOC macros
    
    * src/dfa.c (XNMALLOC, XCALLOC): Redefine without outer cast-to-(t *).
    (CALLOC, MALLOC, REALLOC): Remove type "t" parameter and adjust callers.

diff --git a/src/dfa.c b/src/dfa.c
index febe43b..611003d 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -29,6 +29,7 @@
 #include <limits.h>
 #include <string.h>
 #include <locale.h>
+#include "verify.h"
 
 #define STREQ(a, b) (strcmp (a, b) == 0)
 
@@ -396,9 +397,26 @@ struct dfa
 static void dfamust (struct dfa *dfa);
 static void regexp (void);
 
-#define CALLOC(p, t, n) ((p) = XCALLOC (n, t))
-#define MALLOC(p, t, n) ((p) = XNMALLOC (n, t))
-#define REALLOC(p, t, n) ((p) = xnrealloc (p, n, sizeof (t)))
+/* These two macros are identical to the ones in gnulib's xalloc.h,
+   except that they not to case the result to "(t *)", and thus may
+   be used via type-free CALLOC and MALLOC macros.  */
+#undef XNMALLOC
+#undef XCALLOC
+
+/* Allocate memory for N elements of type T, with error checking.  */
+/* extern t *XNMALLOC (size_t n, typename t); */
+# define XNMALLOC(n, t) \
+    (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))
+
+/* Allocate memory for N elements of type T, with error checking,
+   and zero it.  */
+/* extern t *XCALLOC (size_t n, typename t); */
+# define XCALLOC(n, t) \
+    (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))
+
+#define CALLOC(p, n) do { (p) = XCALLOC (n, *(p)); } while (0)
+#define MALLOC(p, n) do { (p) = XNMALLOC (n, *(p)); } while (0)
+#define REALLOC(p, n) do {(p) = xnrealloc (p, n, sizeof (*(p))); } while (0)
 
 /* Reallocate an array of type *P if N_ALLOC is <= N_REQUIRED. */
 #define REALLOC_IF_NECESSARY(p, n_alloc, n_required)		\
@@ -866,7 +884,7 @@ parse_bracket_exp (void)
                       wctype_t wt = wctype (class);
 
                       if (ch_classes_al == 0)
-                        MALLOC(work_mbc->ch_classes, wctype_t, ++ch_classes_al);
+                        MALLOC(work_mbc->ch_classes, ++ch_classes_al);
                       REALLOC_IF_NECESSARY(work_mbc->ch_classes,
                                            ch_classes_al,
                                            work_mbc->nch_classes + 1);
@@ -883,14 +901,14 @@ parse_bracket_exp (void)
               else if (c1 == '=' || c1 == '.')
                 {
                   char *elem;
-                  MALLOC(elem, char, len + 1);
+                  MALLOC(elem, len + 1);
                   strncpy(elem, str, len + 1);
 
                   if (c1 == '=')
                     /* build equivalent class.  */
                     {
                       if (equivs_al == 0)
-                        MALLOC(work_mbc->equivs, char*, ++equivs_al);
+                        MALLOC(work_mbc->equivs, ++equivs_al);
                       REALLOC_IF_NECESSARY(work_mbc->equivs,
                                            equivs_al,
                                            work_mbc->nequivs + 1);
@@ -901,7 +919,7 @@ parse_bracket_exp (void)
                     /* build collating element.  */
                     {
                       if (coll_elems_al == 0)
-                        MALLOC(work_mbc->coll_elems, char*, ++coll_elems_al);
+                        MALLOC(work_mbc->coll_elems, ++coll_elems_al);
                       REALLOC_IF_NECESSARY(work_mbc->coll_elems,
                                            coll_elems_al,
                                            work_mbc->ncoll_elems + 1);
@@ -952,8 +970,8 @@ parse_bracket_exp (void)
                  to the pair of ranges, [m-z] [M-Z].  */
               if (range_sts_al == 0)
                 {
-                  MALLOC(work_mbc->range_sts, wchar_t, ++range_sts_al);
-                  MALLOC(work_mbc->range_ends, wchar_t, ++range_ends_al);
+                  MALLOC(work_mbc->range_sts, ++range_sts_al);
+                  MALLOC(work_mbc->range_ends, ++range_ends_al);
                 }
               REALLOC_IF_NECESSARY(work_mbc->range_sts,
                                    range_sts_al, work_mbc->nranges + 1);
@@ -1940,7 +1958,7 @@ state_index (struct dfa *d, position_set const *s, int newline, int letter)
   /* We'll have to create a new state. */
   REALLOC_IF_NECESSARY(d->states, d->salloc, d->sindex + 1);
   d->states[i].hash = hash;
-  MALLOC(d->states[i].elems.elems, position, s->nelem);
+  MALLOC(d->states[i].elems.elems, s->nelem);
   copy(s, &d->states[i].elems);
   d->states[i].newline = newline;
   d->states[i].letter = letter;
@@ -1986,7 +2004,7 @@ epsclosure (position_set *s, struct dfa const *d)
   char *visited;	/* array of booleans, enough to use char, not int */
   position p, old;
 
-  CALLOC(visited, char, d->tindex);
+  CALLOC(visited, d->tindex);
 
   for (i = 0; i < s->nelem; ++i)
     if (d->tokens[s->elems[i].index] >= NOTCHAR
@@ -2123,20 +2141,20 @@ dfaanalyze (struct dfa *d, int searchflag)
 
   d->searchflag = searchflag;
 
-  MALLOC(nullable, int, d->depth);
+  MALLOC(nullable, d->depth);
   o_nullable = nullable;
-  MALLOC(nfirstpos, int, d->depth);
+  MALLOC(nfirstpos, d->depth);
   o_nfirst = nfirstpos;
-  MALLOC(firstpos, position, d->nleaves);
+  MALLOC(firstpos, d->nleaves);
   o_firstpos = firstpos, firstpos += d->nleaves;
-  MALLOC(nlastpos, int, d->depth);
+  MALLOC(nlastpos, d->depth);
   o_nlast = nlastpos;
-  MALLOC(lastpos, position, d->nleaves);
+  MALLOC(lastpos, d->nleaves);
   o_lastpos = lastpos, lastpos += d->nleaves;
-  CALLOC(nalloc, int, d->tindex);
-  MALLOC(merged.elems, position, d->nleaves);
+  CALLOC(nalloc, d->tindex);
+  MALLOC(merged.elems, d->nleaves);
 
-  CALLOC(d->follows, position_set, d->tindex);
+  CALLOC(d->follows, d->tindex);
 
   for (i = 0; i < d->tindex; ++i)
 #ifdef DEBUG
@@ -2244,7 +2262,7 @@ dfaanalyze (struct dfa *d, int searchflag)
 
         /* Allocate the follow set for this position. */
         nalloc[i] = 1;
-        MALLOC(d->follows[i].elems, position, nalloc[i]);
+        MALLOC(d->follows[i].elems, nalloc[i]);
         break;
       }
 #ifdef DEBUG
@@ -2293,7 +2311,7 @@ dfaanalyze (struct dfa *d, int searchflag)
         copy(&d->follows[i], &merged);
         epsclosure(&merged, d);
         if (d->follows[i].nelem < merged.nelem)
-          REALLOC(d->follows[i].elems, position, merged.nelem);
+          REALLOC(d->follows[i].elems, merged.nelem);
         copy(&merged, &d->follows[i]);
       }
 
@@ -2313,7 +2331,7 @@ dfaanalyze (struct dfa *d, int searchflag)
   /* Build the initial state. */
   d->salloc = 1;
   d->sindex = 0;
-  MALLOC(d->states, dfa_state, d->salloc);
+  MALLOC(d->states, d->salloc);
   state_index(d, &merged, wants_newline, 0);
 
   free(o_nullable);
@@ -2415,8 +2433,7 @@ dfastate (int s, struct dfa *d, int trans[])
              which can match with a single character not a byte.  */
           if (d->states[s].mbps.nelem == 0)
             {
-              MALLOC(d->states[s].mbps.elems, position,
-                     d->states[s].elems.nelem);
+              MALLOC(d->states[s].mbps.elems, d->states[s].elems.nelem);
             }
           insert(pos, &(d->states[s].mbps));
           continue;
@@ -2485,7 +2502,7 @@ dfastate (int s, struct dfa *d, int trans[])
             {
               copyset(leftovers, labels[ngrps]);
               copyset(intersect, labels[j]);
-              MALLOC(grps[ngrps].elems, position, d->nleaves);
+              MALLOC(grps[ngrps].elems, d->nleaves);
               copy(&grps[j], &grps[ngrps]);
               ++ngrps;
             }
@@ -2506,15 +2523,15 @@ dfastate (int s, struct dfa *d, int trans[])
         {
           copyset(matches, labels[ngrps]);
           zeroset(matches);
-          MALLOC(grps[ngrps].elems, position, d->nleaves);
+          MALLOC(grps[ngrps].elems, d->nleaves);
           grps[ngrps].nelem = 1;
           grps[ngrps].elems[0] = pos;
           ++ngrps;
         }
     }
 
-  MALLOC(follows.elems, position, d->nleaves);
-  MALLOC(tmp.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
+  MALLOC(tmp.elems, d->nleaves);
 
   /* If we are a searching matcher, the default transition is to a state
      containing the positions of state 0, otherwise the default transition
@@ -2694,7 +2711,7 @@ build_state (int s, struct dfa *d)
       s, *d))
     d->success[s] |= 1;
 
-  MALLOC(trans, int, NOTCHAR);
+  MALLOC(trans, NOTCHAR);
   dfastate(s, d, trans);
 
   /* Now go through the new transition table, and make sure that the trans
@@ -2707,11 +2724,11 @@ build_state (int s, struct dfa *d)
 
         while (trans[i] >= d->tralloc)
           d->tralloc *= 2;
-        REALLOC(d->realtrans, int *, d->tralloc + 1);
+        REALLOC(d->realtrans, d->tralloc + 1);
         d->trans = d->realtrans + 1;
-        REALLOC(d->fails, int *, d->tralloc);
-        REALLOC(d->success, int, d->tralloc);
-        REALLOC(d->newlines, int, d->tralloc);
+        REALLOC(d->fails, d->tralloc);
+        REALLOC(d->success, d->tralloc);
+        REALLOC(d->newlines, d->tralloc);
         while (oldalloc < d->tralloc)
           {
             d->trans[oldalloc] = NULL;
@@ -2735,11 +2752,11 @@ build_state_zero (struct dfa *d)
 {
   d->tralloc = 1;
   d->trcount = 0;
-  CALLOC(d->realtrans, int *, d->tralloc + 1);
+  CALLOC(d->realtrans, d->tralloc + 1);
   d->trans = d->realtrans + 1;
-  CALLOC(d->fails, int *, d->tralloc);
-  MALLOC(d->success, int, d->tralloc);
-  MALLOC(d->newlines, int, d->tralloc);
+  CALLOC(d->fails, d->tralloc);
+  MALLOC(d->success, d->tralloc);
+  MALLOC(d->newlines, d->tralloc);
   build_state(0, d);
 }
 
@@ -2780,11 +2797,11 @@ realloc_trans_if_necessary(struct dfa *d, int new_state)
 
       while (new_state >= d->tralloc)
         d->tralloc *= 2;
-      REALLOC(d->realtrans, int *, d->tralloc + 1);
+      REALLOC(d->realtrans, d->tralloc + 1);
       d->trans = d->realtrans + 1;
-      REALLOC(d->fails, int *, d->tralloc);
-      REALLOC(d->success, int, d->tralloc);
-      REALLOC(d->newlines, int, d->tralloc);
+      REALLOC(d->fails, d->tralloc);
+      REALLOC(d->success, d->tralloc);
+      REALLOC(d->newlines, d->tralloc);
       while (oldalloc < d->tralloc)
         {
           d->trans[oldalloc] = NULL;
@@ -3018,7 +3035,7 @@ check_matching_with_multibyte_ops (struct dfa *d, int s, int idx)
   int i;
   int* rarray;
 
-  MALLOC(rarray, int, d->states[s].mbps.nelem);
+  MALLOC(rarray, d->states[s].mbps.nelem);
   for (i = 0; i < d->states[s].mbps.nelem; ++i)
     {
       position pos = d->states[s].mbps.elems[i];
@@ -3139,7 +3156,7 @@ transit_state (struct dfa *d, int s, unsigned char const **pp)
 
   /* This state has some operators which can match a multibyte character.  */
   follows.nelem = 0;
-  MALLOC(follows.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
 
   /* `maxlen' may be longer than the length of a character, because it may
      not be a character but a (multi character) collating element.
@@ -3270,8 +3287,8 @@ dfaexec (struct dfa *d, char const *begin, char *end,
 #if MBS_SUPPORT
   if (d->mb_cur_max > 1)
     {
-      MALLOC(mblen_buf, unsigned char, end - begin + 2);
-      MALLOC(inputwcs, wchar_t, end - begin + 2);
+      MALLOC(mblen_buf, end - begin + 2);
+      MALLOC(inputwcs, end - begin + 2);
       memset(&mbs, 0, sizeof(mbstate_t));
       prepare_wc_buf ((const char *) p, end);
     }
@@ -3439,19 +3456,19 @@ dfainit (struct dfa *d)
   memset (d, 0, sizeof *d);
 
   d->calloc = 1;
-  MALLOC(d->charclasses, charclass, d->calloc);
+  MALLOC(d->charclasses, d->calloc);
 
   d->talloc = 1;
-  MALLOC(d->tokens, token, d->talloc);
+  MALLOC(d->tokens, d->talloc);
 
 #if MBS_SUPPORT
   d->mb_cur_max = MB_CUR_MAX;
   if (d->mb_cur_max > 1)
     {
       d->nmultibyte_prop = 1;
-      MALLOC(d->multibyte_prop, int, d->nmultibyte_prop);
+      MALLOC(d->multibyte_prop, d->nmultibyte_prop);
       d->mbcsets_alloc = 1;
-      MALLOC(d->mbcsets, struct mb_char_classes, d->mbcsets_alloc);
+      MALLOC(d->mbcsets, d->mbcsets_alloc);
     }
 #endif
 }
@@ -4038,9 +4055,9 @@ dfamust (struct dfa *d)
  done:
   if (strlen(result))
     {
-      MALLOC(dm, struct dfamust, 1);
+      MALLOC(dm, 1);
       dm->exact = exact;
-      MALLOC(dm->must, char, strlen(result) + 1);
+      MALLOC(dm->must, strlen(result) + 1);
       strcpy(dm->must, result);
       dm->next = d->musts;
       d->musts = dm;

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=20abce9298cf56fd14a1d2361566827b8dc256c9


commit b2d9a6f8c9e71007181eb1d7be4cae096e0da655
Author: Jim Meyering <meyering@redhat.com>
Date:   Tue Jul 12 17:08:05 2011 +0200

    dfa: simplify use of *ALLOC macros
    
    * src/dfa.c (XNMALLOC, XCALLOC): Redefine without outer cast-to-(t *).
    (CALLOC, MALLOC, REALLOC): Remove type "t" parameter and adjust callers.

diff --git a/src/dfa.c b/src/dfa.c
index febe43b..611003d 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -29,6 +29,7 @@
 #include <limits.h>
 #include <string.h>
 #include <locale.h>
+#include "verify.h"
 
 #define STREQ(a, b) (strcmp (a, b) == 0)
 
@@ -396,9 +397,26 @@ struct dfa
 static void dfamust (struct dfa *dfa);
 static void regexp (void);
 
-#define CALLOC(p, t, n) ((p) = XCALLOC (n, t))
-#define MALLOC(p, t, n) ((p) = XNMALLOC (n, t))
-#define REALLOC(p, t, n) ((p) = xnrealloc (p, n, sizeof (t)))
+/* These two macros are identical to the ones in gnulib's xalloc.h,
+   except that they not to case the result to "(t *)", and thus may
+   be used via type-free CALLOC and MALLOC macros.  */
+#undef XNMALLOC
+#undef XCALLOC
+
+/* Allocate memory for N elements of type T, with error checking.  */
+/* extern t *XNMALLOC (size_t n, typename t); */
+# define XNMALLOC(n, t) \
+    (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))
+
+/* Allocate memory for N elements of type T, with error checking,
+   and zero it.  */
+/* extern t *XCALLOC (size_t n, typename t); */
+# define XCALLOC(n, t) \
+    (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))
+
+#define CALLOC(p, n) do { (p) = XCALLOC (n, *(p)); } while (0)
+#define MALLOC(p, n) do { (p) = XNMALLOC (n, *(p)); } while (0)
+#define REALLOC(p, n) do {(p) = xnrealloc (p, n, sizeof (*(p))); } while (0)
 
 /* Reallocate an array of type *P if N_ALLOC is <= N_REQUIRED. */
 #define REALLOC_IF_NECESSARY(p, n_alloc, n_required)		\
@@ -866,7 +884,7 @@ parse_bracket_exp (void)
                       wctype_t wt = wctype (class);
 
                       if (ch_classes_al == 0)
-                        MALLOC(work_mbc->ch_classes, wctype_t, ++ch_classes_al);
+                        MALLOC(work_mbc->ch_classes, ++ch_classes_al);
                       REALLOC_IF_NECESSARY(work_mbc->ch_classes,
                                            ch_classes_al,
                                            work_mbc->nch_classes + 1);
@@ -883,14 +901,14 @@ parse_bracket_exp (void)
               else if (c1 == '=' || c1 == '.')
                 {
                   char *elem;
-                  MALLOC(elem, char, len + 1);
+                  MALLOC(elem, len + 1);
                   strncpy(elem, str, len + 1);
 
                   if (c1 == '=')
                     /* build equivalent class.  */
                     {
                       if (equivs_al == 0)
-                        MALLOC(work_mbc->equivs, char*, ++equivs_al);
+                        MALLOC(work_mbc->equivs, ++equivs_al);
                       REALLOC_IF_NECESSARY(work_mbc->equivs,
                                            equivs_al,
                                            work_mbc->nequivs + 1);
@@ -901,7 +919,7 @@ parse_bracket_exp (void)
                     /* build collating element.  */
                     {
                       if (coll_elems_al == 0)
-                        MALLOC(work_mbc->coll_elems, char*, ++coll_elems_al);
+                        MALLOC(work_mbc->coll_elems, ++coll_elems_al);
                       REALLOC_IF_NECESSARY(work_mbc->coll_elems,
                                            coll_elems_al,
                                            work_mbc->ncoll_elems + 1);
@@ -952,8 +970,8 @@ parse_bracket_exp (void)
                  to the pair of ranges, [m-z] [M-Z].  */
               if (range_sts_al == 0)
                 {
-                  MALLOC(work_mbc->range_sts, wchar_t, ++range_sts_al);
-                  MALLOC(work_mbc->range_ends, wchar_t, ++range_ends_al);
+                  MALLOC(work_mbc->range_sts, ++range_sts_al);
+                  MALLOC(work_mbc->range_ends, ++range_ends_al);
                 }
               REALLOC_IF_NECESSARY(work_mbc->range_sts,
                                    range_sts_al, work_mbc->nranges + 1);
@@ -1940,7 +1958,7 @@ state_index (struct dfa *d, position_set const *s, int newline, int letter)
   /* We'll have to create a new state. */
   REALLOC_IF_NECESSARY(d->states, d->salloc, d->sindex + 1);
   d->states[i].hash = hash;
-  MALLOC(d->states[i].elems.elems, position, s->nelem);
+  MALLOC(d->states[i].elems.elems, s->nelem);
   copy(s, &d->states[i].elems);
   d->states[i].newline = newline;
   d->states[i].letter = letter;
@@ -1986,7 +2004,7 @@ epsclosure (position_set *s, struct dfa const *d)
   char *visited;	/* array of booleans, enough to use char, not int */
   position p, old;
 
-  CALLOC(visited, char, d->tindex);
+  CALLOC(visited, d->tindex);
 
   for (i = 0; i < s->nelem; ++i)
     if (d->tokens[s->elems[i].index] >= NOTCHAR
@@ -2123,20 +2141,20 @@ dfaanalyze (struct dfa *d, int searchflag)
 
   d->searchflag = searchflag;
 
-  MALLOC(nullable, int, d->depth);
+  MALLOC(nullable, d->depth);
   o_nullable = nullable;
-  MALLOC(nfirstpos, int, d->depth);
+  MALLOC(nfirstpos, d->depth);
   o_nfirst = nfirstpos;
-  MALLOC(firstpos, position, d->nleaves);
+  MALLOC(firstpos, d->nleaves);
   o_firstpos = firstpos, firstpos += d->nleaves;
-  MALLOC(nlastpos, int, d->depth);
+  MALLOC(nlastpos, d->depth);
   o_nlast = nlastpos;
-  MALLOC(lastpos, position, d->nleaves);
+  MALLOC(lastpos, d->nleaves);
   o_lastpos = lastpos, lastpos += d->nleaves;
-  CALLOC(nalloc, int, d->tindex);
-  MALLOC(merged.elems, position, d->nleaves);
+  CALLOC(nalloc, d->tindex);
+  MALLOC(merged.elems, d->nleaves);
 
-  CALLOC(d->follows, position_set, d->tindex);
+  CALLOC(d->follows, d->tindex);
 
   for (i = 0; i < d->tindex; ++i)
 #ifdef DEBUG
@@ -2244,7 +2262,7 @@ dfaanalyze (struct dfa *d, int searchflag)
 
         /* Allocate the follow set for this position. */
         nalloc[i] = 1;
-        MALLOC(d->follows[i].elems, position, nalloc[i]);
+        MALLOC(d->follows[i].elems, nalloc[i]);
         break;
       }
 #ifdef DEBUG
@@ -2293,7 +2311,7 @@ dfaanalyze (struct dfa *d, int searchflag)
         copy(&d->follows[i], &merged);
         epsclosure(&merged, d);
         if (d->follows[i].nelem < merged.nelem)
-          REALLOC(d->follows[i].elems, position, merged.nelem);
+          REALLOC(d->follows[i].elems, merged.nelem);
         copy(&merged, &d->follows[i]);
       }
 
@@ -2313,7 +2331,7 @@ dfaanalyze (struct dfa *d, int searchflag)
   /* Build the initial state. */
   d->salloc = 1;
   d->sindex = 0;
-  MALLOC(d->states, dfa_state, d->salloc);
+  MALLOC(d->states, d->salloc);
   state_index(d, &merged, wants_newline, 0);
 
   free(o_nullable);
@@ -2415,8 +2433,7 @@ dfastate (int s, struct dfa *d, int trans[])
              which can match with a single character not a byte.  */
           if (d->states[s].mbps.nelem == 0)
             {
-              MALLOC(d->states[s].mbps.elems, position,
-                     d->states[s].elems.nelem);
+              MALLOC(d->states[s].mbps.elems, d->states[s].elems.nelem);
             }
           insert(pos, &(d->states[s].mbps));
           continue;
@@ -2485,7 +2502,7 @@ dfastate (int s, struct dfa *d, int trans[])
             {
               copyset(leftovers, labels[ngrps]);
               copyset(intersect, labels[j]);
-              MALLOC(grps[ngrps].elems, position, d->nleaves);
+              MALLOC(grps[ngrps].elems, d->nleaves);
               copy(&grps[j], &grps[ngrps]);
               ++ngrps;
             }
@@ -2506,15 +2523,15 @@ dfastate (int s, struct dfa *d, int trans[])
         {
           copyset(matches, labels[ngrps]);
           zeroset(matches);
-          MALLOC(grps[ngrps].elems, position, d->nleaves);
+          MALLOC(grps[ngrps].elems, d->nleaves);
           grps[ngrps].nelem = 1;
           grps[ngrps].elems[0] = pos;
           ++ngrps;
         }
     }
 
-  MALLOC(follows.elems, position, d->nleaves);
-  MALLOC(tmp.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
+  MALLOC(tmp.elems, d->nleaves);
 
   /* If we are a searching matcher, the default transition is to a state
      containing the positions of state 0, otherwise the default transition
@@ -2694,7 +2711,7 @@ build_state (int s, struct dfa *d)
       s, *d))
     d->success[s] |= 1;
 
-  MALLOC(trans, int, NOTCHAR);
+  MALLOC(trans, NOTCHAR);
   dfastate(s, d, trans);
 
   /* Now go through the new transition table, and make sure that the trans
@@ -2707,11 +2724,11 @@ build_state (int s, struct dfa *d)
 
         while (trans[i] >= d->tralloc)
           d->tralloc *= 2;
-        REALLOC(d->realtrans, int *, d->tralloc + 1);
+        REALLOC(d->realtrans, d->tralloc + 1);
         d->trans = d->realtrans + 1;
-        REALLOC(d->fails, int *, d->tralloc);
-        REALLOC(d->success, int, d->tralloc);
-        REALLOC(d->newlines, int, d->tralloc);
+        REALLOC(d->fails, d->tralloc);
+        REALLOC(d->success, d->tralloc);
+        REALLOC(d->newlines, d->tralloc);
         while (oldalloc < d->tralloc)
           {
             d->trans[oldalloc] = NULL;
@@ -2735,11 +2752,11 @@ build_state_zero (struct dfa *d)
 {
   d->tralloc = 1;
   d->trcount = 0;
-  CALLOC(d->realtrans, int *, d->tralloc + 1);
+  CALLOC(d->realtrans, d->tralloc + 1);
   d->trans = d->realtrans + 1;
-  CALLOC(d->fails, int *, d->tralloc);
-  MALLOC(d->success, int, d->tralloc);
-  MALLOC(d->newlines, int, d->tralloc);
+  CALLOC(d->fails, d->tralloc);
+  MALLOC(d->success, d->tralloc);
+  MALLOC(d->newlines, d->tralloc);
   build_state(0, d);
 }
 
@@ -2780,11 +2797,11 @@ realloc_trans_if_necessary(struct dfa *d, int new_state)
 
       while (new_state >= d->tralloc)
         d->tralloc *= 2;
-      REALLOC(d->realtrans, int *, d->tralloc + 1);
+      REALLOC(d->realtrans, d->tralloc + 1);
       d->trans = d->realtrans + 1;
-      REALLOC(d->fails, int *, d->tralloc);
-      REALLOC(d->success, int, d->tralloc);
-      REALLOC(d->newlines, int, d->tralloc);
+      REALLOC(d->fails, d->tralloc);
+      REALLOC(d->success, d->tralloc);
+      REALLOC(d->newlines, d->tralloc);
       while (oldalloc < d->tralloc)
         {
           d->trans[oldalloc] = NULL;
@@ -3018,7 +3035,7 @@ check_matching_with_multibyte_ops (struct dfa *d, int s, int idx)
   int i;
   int* rarray;
 
-  MALLOC(rarray, int, d->states[s].mbps.nelem);
+  MALLOC(rarray, d->states[s].mbps.nelem);
   for (i = 0; i < d->states[s].mbps.nelem; ++i)
     {
       position pos = d->states[s].mbps.elems[i];
@@ -3139,7 +3156,7 @@ transit_state (struct dfa *d, int s, unsigned char const **pp)
 
   /* This state has some operators which can match a multibyte character.  */
   follows.nelem = 0;
-  MALLOC(follows.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
 
   /* `maxlen' may be longer than the length of a character, because it may
      not be a character but a (multi character) collating element.
@@ -3270,8 +3287,8 @@ dfaexec (struct dfa *d, char const *begin, char *end,
 #if MBS_SUPPORT
   if (d->mb_cur_max > 1)
     {
-      MALLOC(mblen_buf, unsigned char, end - begin + 2);
-      MALLOC(inputwcs, wchar_t, end - begin + 2);
+      MALLOC(mblen_buf, end - begin + 2);
+      MALLOC(inputwcs, end - begin + 2);
       memset(&mbs, 0, sizeof(mbstate_t));
       prepare_wc_buf ((const char *) p, end);
     }
@@ -3439,19 +3456,19 @@ dfainit (struct dfa *d)
   memset (d, 0, sizeof *d);
 
   d->calloc = 1;
-  MALLOC(d->charclasses, charclass, d->calloc);
+  MALLOC(d->charclasses, d->calloc);
 
   d->talloc = 1;
-  MALLOC(d->tokens, token, d->talloc);
+  MALLOC(d->tokens, d->talloc);
 
 #if MBS_SUPPORT
   d->mb_cur_max = MB_CUR_MAX;
   if (d->mb_cur_max > 1)
     {
       d->nmultibyte_prop = 1;
-      MALLOC(d->multibyte_prop, int, d->nmultibyte_prop);
+      MALLOC(d->multibyte_prop, d->nmultibyte_prop);
       d->mbcsets_alloc = 1;
-      MALLOC(d->mbcsets, struct mb_char_classes, d->mbcsets_alloc);
+      MALLOC(d->mbcsets, d->mbcsets_alloc);
     }
 #endif
 }
@@ -4038,9 +4055,9 @@ dfamust (struct dfa *d)
  done:
   if (strlen(result))
     {
-      MALLOC(dm, struct dfamust, 1);
+      MALLOC(dm, 1);
       dm->exact = exact;
-      MALLOC(dm->must, char, strlen(result) + 1);
+      MALLOC(dm->must, strlen(result) + 1);
       strcpy(dm->must, result);
       dm->next = d->musts;
       d->musts = dm;

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=bc7b0852e60cc0679dae82014b79d05006932874


commit b2d9a6f8c9e71007181eb1d7be4cae096e0da655
Author: Jim Meyering <meyering@redhat.com>
Date:   Tue Jul 12 17:08:05 2011 +0200

    dfa: simplify use of *ALLOC macros
    
    * src/dfa.c (XNMALLOC, XCALLOC): Redefine without outer cast-to-(t *).
    (CALLOC, MALLOC, REALLOC): Remove type "t" parameter and adjust callers.

diff --git a/src/dfa.c b/src/dfa.c
index febe43b..611003d 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -29,6 +29,7 @@
 #include <limits.h>
 #include <string.h>
 #include <locale.h>
+#include "verify.h"
 
 #define STREQ(a, b) (strcmp (a, b) == 0)
 
@@ -396,9 +397,26 @@ struct dfa
 static void dfamust (struct dfa *dfa);
 static void regexp (void);
 
-#define CALLOC(p, t, n) ((p) = XCALLOC (n, t))
-#define MALLOC(p, t, n) ((p) = XNMALLOC (n, t))
-#define REALLOC(p, t, n) ((p) = xnrealloc (p, n, sizeof (t)))
+/* These two macros are identical to the ones in gnulib's xalloc.h,
+   except that they not to case the result to "(t *)", and thus may
+   be used via type-free CALLOC and MALLOC macros.  */
+#undef XNMALLOC
+#undef XCALLOC
+
+/* Allocate memory for N elements of type T, with error checking.  */
+/* extern t *XNMALLOC (size_t n, typename t); */
+# define XNMALLOC(n, t) \
+    (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))
+
+/* Allocate memory for N elements of type T, with error checking,
+   and zero it.  */
+/* extern t *XCALLOC (size_t n, typename t); */
+# define XCALLOC(n, t) \
+    (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))
+
+#define CALLOC(p, n) do { (p) = XCALLOC (n, *(p)); } while (0)
+#define MALLOC(p, n) do { (p) = XNMALLOC (n, *(p)); } while (0)
+#define REALLOC(p, n) do {(p) = xnrealloc (p, n, sizeof (*(p))); } while (0)
 
 /* Reallocate an array of type *P if N_ALLOC is <= N_REQUIRED. */
 #define REALLOC_IF_NECESSARY(p, n_alloc, n_required)		\
@@ -866,7 +884,7 @@ parse_bracket_exp (void)
                       wctype_t wt = wctype (class);
 
                       if (ch_classes_al == 0)
-                        MALLOC(work_mbc->ch_classes, wctype_t, ++ch_classes_al);
+                        MALLOC(work_mbc->ch_classes, ++ch_classes_al);
                       REALLOC_IF_NECESSARY(work_mbc->ch_classes,
                                            ch_classes_al,
                                            work_mbc->nch_classes + 1);
@@ -883,14 +901,14 @@ parse_bracket_exp (void)
               else if (c1 == '=' || c1 == '.')
                 {
                   char *elem;
-                  MALLOC(elem, char, len + 1);
+                  MALLOC(elem, len + 1);
                   strncpy(elem, str, len + 1);
 
                   if (c1 == '=')
                     /* build equivalent class.  */
                     {
                       if (equivs_al == 0)
-                        MALLOC(work_mbc->equivs, char*, ++equivs_al);
+                        MALLOC(work_mbc->equivs, ++equivs_al);
                       REALLOC_IF_NECESSARY(work_mbc->equivs,
                                            equivs_al,
                                            work_mbc->nequivs + 1);
@@ -901,7 +919,7 @@ parse_bracket_exp (void)
                     /* build collating element.  */
                     {
                       if (coll_elems_al == 0)
-                        MALLOC(work_mbc->coll_elems, char*, ++coll_elems_al);
+                        MALLOC(work_mbc->coll_elems, ++coll_elems_al);
                       REALLOC_IF_NECESSARY(work_mbc->coll_elems,
                                            coll_elems_al,
                                            work_mbc->ncoll_elems + 1);
@@ -952,8 +970,8 @@ parse_bracket_exp (void)
                  to the pair of ranges, [m-z] [M-Z].  */
               if (range_sts_al == 0)
                 {
-                  MALLOC(work_mbc->range_sts, wchar_t, ++range_sts_al);
-                  MALLOC(work_mbc->range_ends, wchar_t, ++range_ends_al);
+                  MALLOC(work_mbc->range_sts, ++range_sts_al);
+                  MALLOC(work_mbc->range_ends, ++range_ends_al);
                 }
               REALLOC_IF_NECESSARY(work_mbc->range_sts,
                                    range_sts_al, work_mbc->nranges + 1);
@@ -1940,7 +1958,7 @@ state_index (struct dfa *d, position_set const *s, int newline, int letter)
   /* We'll have to create a new state. */
   REALLOC_IF_NECESSARY(d->states, d->salloc, d->sindex + 1);
   d->states[i].hash = hash;
-  MALLOC(d->states[i].elems.elems, position, s->nelem);
+  MALLOC(d->states[i].elems.elems, s->nelem);
   copy(s, &d->states[i].elems);
   d->states[i].newline = newline;
   d->states[i].letter = letter;
@@ -1986,7 +2004,7 @@ epsclosure (position_set *s, struct dfa const *d)
   char *visited;	/* array of booleans, enough to use char, not int */
   position p, old;
 
-  CALLOC(visited, char, d->tindex);
+  CALLOC(visited, d->tindex);
 
   for (i = 0; i < s->nelem; ++i)
     if (d->tokens[s->elems[i].index] >= NOTCHAR
@@ -2123,20 +2141,20 @@ dfaanalyze (struct dfa *d, int searchflag)
 
   d->searchflag = searchflag;
 
-  MALLOC(nullable, int, d->depth);
+  MALLOC(nullable, d->depth);
   o_nullable = nullable;
-  MALLOC(nfirstpos, int, d->depth);
+  MALLOC(nfirstpos, d->depth);
   o_nfirst = nfirstpos;
-  MALLOC(firstpos, position, d->nleaves);
+  MALLOC(firstpos, d->nleaves);
   o_firstpos = firstpos, firstpos += d->nleaves;
-  MALLOC(nlastpos, int, d->depth);
+  MALLOC(nlastpos, d->depth);
   o_nlast = nlastpos;
-  MALLOC(lastpos, position, d->nleaves);
+  MALLOC(lastpos, d->nleaves);
   o_lastpos = lastpos, lastpos += d->nleaves;
-  CALLOC(nalloc, int, d->tindex);
-  MALLOC(merged.elems, position, d->nleaves);
+  CALLOC(nalloc, d->tindex);
+  MALLOC(merged.elems, d->nleaves);
 
-  CALLOC(d->follows, position_set, d->tindex);
+  CALLOC(d->follows, d->tindex);
 
   for (i = 0; i < d->tindex; ++i)
 #ifdef DEBUG
@@ -2244,7 +2262,7 @@ dfaanalyze (struct dfa *d, int searchflag)
 
         /* Allocate the follow set for this position. */
         nalloc[i] = 1;
-        MALLOC(d->follows[i].elems, position, nalloc[i]);
+        MALLOC(d->follows[i].elems, nalloc[i]);
         break;
       }
 #ifdef DEBUG
@@ -2293,7 +2311,7 @@ dfaanalyze (struct dfa *d, int searchflag)
         copy(&d->follows[i], &merged);
         epsclosure(&merged, d);
         if (d->follows[i].nelem < merged.nelem)
-          REALLOC(d->follows[i].elems, position, merged.nelem);
+          REALLOC(d->follows[i].elems, merged.nelem);
         copy(&merged, &d->follows[i]);
       }
 
@@ -2313,7 +2331,7 @@ dfaanalyze (struct dfa *d, int searchflag)
   /* Build the initial state. */
   d->salloc = 1;
   d->sindex = 0;
-  MALLOC(d->states, dfa_state, d->salloc);
+  MALLOC(d->states, d->salloc);
   state_index(d, &merged, wants_newline, 0);
 
   free(o_nullable);
@@ -2415,8 +2433,7 @@ dfastate (int s, struct dfa *d, int trans[])
              which can match with a single character not a byte.  */
           if (d->states[s].mbps.nelem == 0)
             {
-              MALLOC(d->states[s].mbps.elems, position,
-                     d->states[s].elems.nelem);
+              MALLOC(d->states[s].mbps.elems, d->states[s].elems.nelem);
             }
           insert(pos, &(d->states[s].mbps));
           continue;
@@ -2485,7 +2502,7 @@ dfastate (int s, struct dfa *d, int trans[])
             {
               copyset(leftovers, labels[ngrps]);
               copyset(intersect, labels[j]);
-              MALLOC(grps[ngrps].elems, position, d->nleaves);
+              MALLOC(grps[ngrps].elems, d->nleaves);
               copy(&grps[j], &grps[ngrps]);
               ++ngrps;
             }
@@ -2506,15 +2523,15 @@ dfastate (int s, struct dfa *d, int trans[])
         {
           copyset(matches, labels[ngrps]);
           zeroset(matches);
-          MALLOC(grps[ngrps].elems, position, d->nleaves);
+          MALLOC(grps[ngrps].elems, d->nleaves);
           grps[ngrps].nelem = 1;
           grps[ngrps].elems[0] = pos;
           ++ngrps;
         }
     }
 
-  MALLOC(follows.elems, position, d->nleaves);
-  MALLOC(tmp.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
+  MALLOC(tmp.elems, d->nleaves);
 
   /* If we are a searching matcher, the default transition is to a state
      containing the positions of state 0, otherwise the default transition
@@ -2694,7 +2711,7 @@ build_state (int s, struct dfa *d)
       s, *d))
     d->success[s] |= 1;
 
-  MALLOC(trans, int, NOTCHAR);
+  MALLOC(trans, NOTCHAR);
   dfastate(s, d, trans);
 
   /* Now go through the new transition table, and make sure that the trans
@@ -2707,11 +2724,11 @@ build_state (int s, struct dfa *d)
 
         while (trans[i] >= d->tralloc)
           d->tralloc *= 2;
-        REALLOC(d->realtrans, int *, d->tralloc + 1);
+        REALLOC(d->realtrans, d->tralloc + 1);
         d->trans = d->realtrans + 1;
-        REALLOC(d->fails, int *, d->tralloc);
-        REALLOC(d->success, int, d->tralloc);
-        REALLOC(d->newlines, int, d->tralloc);
+        REALLOC(d->fails, d->tralloc);
+        REALLOC(d->success, d->tralloc);
+        REALLOC(d->newlines, d->tralloc);
         while (oldalloc < d->tralloc)
           {
             d->trans[oldalloc] = NULL;
@@ -2735,11 +2752,11 @@ build_state_zero (struct dfa *d)
 {
   d->tralloc = 1;
   d->trcount = 0;
-  CALLOC(d->realtrans, int *, d->tralloc + 1);
+  CALLOC(d->realtrans, d->tralloc + 1);
   d->trans = d->realtrans + 1;
-  CALLOC(d->fails, int *, d->tralloc);
-  MALLOC(d->success, int, d->tralloc);
-  MALLOC(d->newlines, int, d->tralloc);
+  CALLOC(d->fails, d->tralloc);
+  MALLOC(d->success, d->tralloc);
+  MALLOC(d->newlines, d->tralloc);
   build_state(0, d);
 }
 
@@ -2780,11 +2797,11 @@ realloc_trans_if_necessary(struct dfa *d, int new_state)
 
       while (new_state >= d->tralloc)
         d->tralloc *= 2;
-      REALLOC(d->realtrans, int *, d->tralloc + 1);
+      REALLOC(d->realtrans, d->tralloc + 1);
       d->trans = d->realtrans + 1;
-      REALLOC(d->fails, int *, d->tralloc);
-      REALLOC(d->success, int, d->tralloc);
-      REALLOC(d->newlines, int, d->tralloc);
+      REALLOC(d->fails, d->tralloc);
+      REALLOC(d->success, d->tralloc);
+      REALLOC(d->newlines, d->tralloc);
       while (oldalloc < d->tralloc)
         {
           d->trans[oldalloc] = NULL;
@@ -3018,7 +3035,7 @@ check_matching_with_multibyte_ops (struct dfa *d, int s, int idx)
   int i;
   int* rarray;
 
-  MALLOC(rarray, int, d->states[s].mbps.nelem);
+  MALLOC(rarray, d->states[s].mbps.nelem);
   for (i = 0; i < d->states[s].mbps.nelem; ++i)
     {
       position pos = d->states[s].mbps.elems[i];
@@ -3139,7 +3156,7 @@ transit_state (struct dfa *d, int s, unsigned char const **pp)
 
   /* This state has some operators which can match a multibyte character.  */
   follows.nelem = 0;
-  MALLOC(follows.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
 
   /* `maxlen' may be longer than the length of a character, because it may
      not be a character but a (multi character) collating element.
@@ -3270,8 +3287,8 @@ dfaexec (struct dfa *d, char const *begin, char *end,
 #if MBS_SUPPORT
   if (d->mb_cur_max > 1)
     {
-      MALLOC(mblen_buf, unsigned char, end - begin + 2);
-      MALLOC(inputwcs, wchar_t, end - begin + 2);
+      MALLOC(mblen_buf, end - begin + 2);
+      MALLOC(inputwcs, end - begin + 2);
       memset(&mbs, 0, sizeof(mbstate_t));
       prepare_wc_buf ((const char *) p, end);
     }
@@ -3439,19 +3456,19 @@ dfainit (struct dfa *d)
   memset (d, 0, sizeof *d);
 
   d->calloc = 1;
-  MALLOC(d->charclasses, charclass, d->calloc);
+  MALLOC(d->charclasses, d->calloc);
 
   d->talloc = 1;
-  MALLOC(d->tokens, token, d->talloc);
+  MALLOC(d->tokens, d->talloc);
 
 #if MBS_SUPPORT
   d->mb_cur_max = MB_CUR_MAX;
   if (d->mb_cur_max > 1)
     {
       d->nmultibyte_prop = 1;
-      MALLOC(d->multibyte_prop, int, d->nmultibyte_prop);
+      MALLOC(d->multibyte_prop, d->nmultibyte_prop);
       d->mbcsets_alloc = 1;
-      MALLOC(d->mbcsets, struct mb_char_classes, d->mbcsets_alloc);
+      MALLOC(d->mbcsets, d->mbcsets_alloc);
     }
 #endif
 }
@@ -4038,9 +4055,9 @@ dfamust (struct dfa *d)
  done:
   if (strlen(result))
     {
-      MALLOC(dm, struct dfamust, 1);
+      MALLOC(dm, 1);
       dm->exact = exact;
-      MALLOC(dm->must, char, strlen(result) + 1);
+      MALLOC(dm->must, strlen(result) + 1);
       strcpy(dm->must, result);
       dm->next = d->musts;
       d->musts = dm;

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=3abe897119cb46e3cbd7be02fdf9598c2758b461


commit b2d9a6f8c9e71007181eb1d7be4cae096e0da655
Author: Jim Meyering <meyering@redhat.com>
Date:   Tue Jul 12 17:08:05 2011 +0200

    dfa: simplify use of *ALLOC macros
    
    * src/dfa.c (XNMALLOC, XCALLOC): Redefine without outer cast-to-(t *).
    (CALLOC, MALLOC, REALLOC): Remove type "t" parameter and adjust callers.

diff --git a/src/dfa.c b/src/dfa.c
index febe43b..611003d 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -29,6 +29,7 @@
 #include <limits.h>
 #include <string.h>
 #include <locale.h>
+#include "verify.h"
 
 #define STREQ(a, b) (strcmp (a, b) == 0)
 
@@ -396,9 +397,26 @@ struct dfa
 static void dfamust (struct dfa *dfa);
 static void regexp (void);
 
-#define CALLOC(p, t, n) ((p) = XCALLOC (n, t))
-#define MALLOC(p, t, n) ((p) = XNMALLOC (n, t))
-#define REALLOC(p, t, n) ((p) = xnrealloc (p, n, sizeof (t)))
+/* These two macros are identical to the ones in gnulib's xalloc.h,
+   except that they not to case the result to "(t *)", and thus may
+   be used via type-free CALLOC and MALLOC macros.  */
+#undef XNMALLOC
+#undef XCALLOC
+
+/* Allocate memory for N elements of type T, with error checking.  */
+/* extern t *XNMALLOC (size_t n, typename t); */
+# define XNMALLOC(n, t) \
+    (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))
+
+/* Allocate memory for N elements of type T, with error checking,
+   and zero it.  */
+/* extern t *XCALLOC (size_t n, typename t); */
+# define XCALLOC(n, t) \
+    (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))
+
+#define CALLOC(p, n) do { (p) = XCALLOC (n, *(p)); } while (0)
+#define MALLOC(p, n) do { (p) = XNMALLOC (n, *(p)); } while (0)
+#define REALLOC(p, n) do {(p) = xnrealloc (p, n, sizeof (*(p))); } while (0)
 
 /* Reallocate an array of type *P if N_ALLOC is <= N_REQUIRED. */
 #define REALLOC_IF_NECESSARY(p, n_alloc, n_required)		\
@@ -866,7 +884,7 @@ parse_bracket_exp (void)
                       wctype_t wt = wctype (class);
 
                       if (ch_classes_al == 0)
-                        MALLOC(work_mbc->ch_classes, wctype_t, ++ch_classes_al);
+                        MALLOC(work_mbc->ch_classes, ++ch_classes_al);
                       REALLOC_IF_NECESSARY(work_mbc->ch_classes,
                                            ch_classes_al,
                                            work_mbc->nch_classes + 1);
@@ -883,14 +901,14 @@ parse_bracket_exp (void)
               else if (c1 == '=' || c1 == '.')
                 {
                   char *elem;
-                  MALLOC(elem, char, len + 1);
+                  MALLOC(elem, len + 1);
                   strncpy(elem, str, len + 1);
 
                   if (c1 == '=')
                     /* build equivalent class.  */
                     {
                       if (equivs_al == 0)
-                        MALLOC(work_mbc->equivs, char*, ++equivs_al);
+                        MALLOC(work_mbc->equivs, ++equivs_al);
                       REALLOC_IF_NECESSARY(work_mbc->equivs,
                                            equivs_al,
                                            work_mbc->nequivs + 1);
@@ -901,7 +919,7 @@ parse_bracket_exp (void)
                     /* build collating element.  */
                     {
                       if (coll_elems_al == 0)
-                        MALLOC(work_mbc->coll_elems, char*, ++coll_elems_al);
+                        MALLOC(work_mbc->coll_elems, ++coll_elems_al);
                       REALLOC_IF_NECESSARY(work_mbc->coll_elems,
                                            coll_elems_al,
                                            work_mbc->ncoll_elems + 1);
@@ -952,8 +970,8 @@ parse_bracket_exp (void)
                  to the pair of ranges, [m-z] [M-Z].  */
               if (range_sts_al == 0)
                 {
-                  MALLOC(work_mbc->range_sts, wchar_t, ++range_sts_al);
-                  MALLOC(work_mbc->range_ends, wchar_t, ++range_ends_al);
+                  MALLOC(work_mbc->range_sts, ++range_sts_al);
+                  MALLOC(work_mbc->range_ends, ++range_ends_al);
                 }
               REALLOC_IF_NECESSARY(work_mbc->range_sts,
                                    range_sts_al, work_mbc->nranges + 1);
@@ -1940,7 +1958,7 @@ state_index (struct dfa *d, position_set const *s, int newline, int letter)
   /* We'll have to create a new state. */
   REALLOC_IF_NECESSARY(d->states, d->salloc, d->sindex + 1);
   d->states[i].hash = hash;
-  MALLOC(d->states[i].elems.elems, position, s->nelem);
+  MALLOC(d->states[i].elems.elems, s->nelem);
   copy(s, &d->states[i].elems);
   d->states[i].newline = newline;
   d->states[i].letter = letter;
@@ -1986,7 +2004,7 @@ epsclosure (position_set *s, struct dfa const *d)
   char *visited;	/* array of booleans, enough to use char, not int */
   position p, old;
 
-  CALLOC(visited, char, d->tindex);
+  CALLOC(visited, d->tindex);
 
   for (i = 0; i < s->nelem; ++i)
     if (d->tokens[s->elems[i].index] >= NOTCHAR
@@ -2123,20 +2141,20 @@ dfaanalyze (struct dfa *d, int searchflag)
 
   d->searchflag = searchflag;
 
-  MALLOC(nullable, int, d->depth);
+  MALLOC(nullable, d->depth);
   o_nullable = nullable;
-  MALLOC(nfirstpos, int, d->depth);
+  MALLOC(nfirstpos, d->depth);
   o_nfirst = nfirstpos;
-  MALLOC(firstpos, position, d->nleaves);
+  MALLOC(firstpos, d->nleaves);
   o_firstpos = firstpos, firstpos += d->nleaves;
-  MALLOC(nlastpos, int, d->depth);
+  MALLOC(nlastpos, d->depth);
   o_nlast = nlastpos;
-  MALLOC(lastpos, position, d->nleaves);
+  MALLOC(lastpos, d->nleaves);
   o_lastpos = lastpos, lastpos += d->nleaves;
-  CALLOC(nalloc, int, d->tindex);
-  MALLOC(merged.elems, position, d->nleaves);
+  CALLOC(nalloc, d->tindex);
+  MALLOC(merged.elems, d->nleaves);
 
-  CALLOC(d->follows, position_set, d->tindex);
+  CALLOC(d->follows, d->tindex);
 
   for (i = 0; i < d->tindex; ++i)
 #ifdef DEBUG
@@ -2244,7 +2262,7 @@ dfaanalyze (struct dfa *d, int searchflag)
 
         /* Allocate the follow set for this position. */
         nalloc[i] = 1;
-        MALLOC(d->follows[i].elems, position, nalloc[i]);
+        MALLOC(d->follows[i].elems, nalloc[i]);
         break;
       }
 #ifdef DEBUG
@@ -2293,7 +2311,7 @@ dfaanalyze (struct dfa *d, int searchflag)
         copy(&d->follows[i], &merged);
         epsclosure(&merged, d);
         if (d->follows[i].nelem < merged.nelem)
-          REALLOC(d->follows[i].elems, position, merged.nelem);
+          REALLOC(d->follows[i].elems, merged.nelem);
         copy(&merged, &d->follows[i]);
       }
 
@@ -2313,7 +2331,7 @@ dfaanalyze (struct dfa *d, int searchflag)
   /* Build the initial state. */
   d->salloc = 1;
   d->sindex = 0;
-  MALLOC(d->states, dfa_state, d->salloc);
+  MALLOC(d->states, d->salloc);
   state_index(d, &merged, wants_newline, 0);
 
   free(o_nullable);
@@ -2415,8 +2433,7 @@ dfastate (int s, struct dfa *d, int trans[])
              which can match with a single character not a byte.  */
           if (d->states[s].mbps.nelem == 0)
             {
-              MALLOC(d->states[s].mbps.elems, position,
-                     d->states[s].elems.nelem);
+              MALLOC(d->states[s].mbps.elems, d->states[s].elems.nelem);
             }
           insert(pos, &(d->states[s].mbps));
           continue;
@@ -2485,7 +2502,7 @@ dfastate (int s, struct dfa *d, int trans[])
             {
               copyset(leftovers, labels[ngrps]);
               copyset(intersect, labels[j]);
-              MALLOC(grps[ngrps].elems, position, d->nleaves);
+              MALLOC(grps[ngrps].elems, d->nleaves);
               copy(&grps[j], &grps[ngrps]);
               ++ngrps;
             }
@@ -2506,15 +2523,15 @@ dfastate (int s, struct dfa *d, int trans[])
         {
           copyset(matches, labels[ngrps]);
           zeroset(matches);
-          MALLOC(grps[ngrps].elems, position, d->nleaves);
+          MALLOC(grps[ngrps].elems, d->nleaves);
           grps[ngrps].nelem = 1;
           grps[ngrps].elems[0] = pos;
           ++ngrps;
         }
     }
 
-  MALLOC(follows.elems, position, d->nleaves);
-  MALLOC(tmp.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
+  MALLOC(tmp.elems, d->nleaves);
 
   /* If we are a searching matcher, the default transition is to a state
      containing the positions of state 0, otherwise the default transition
@@ -2694,7 +2711,7 @@ build_state (int s, struct dfa *d)
       s, *d))
     d->success[s] |= 1;
 
-  MALLOC(trans, int, NOTCHAR);
+  MALLOC(trans, NOTCHAR);
   dfastate(s, d, trans);
 
   /* Now go through the new transition table, and make sure that the trans
@@ -2707,11 +2724,11 @@ build_state (int s, struct dfa *d)
 
         while (trans[i] >= d->tralloc)
           d->tralloc *= 2;
-        REALLOC(d->realtrans, int *, d->tralloc + 1);
+        REALLOC(d->realtrans, d->tralloc + 1);
         d->trans = d->realtrans + 1;
-        REALLOC(d->fails, int *, d->tralloc);
-        REALLOC(d->success, int, d->tralloc);
-        REALLOC(d->newlines, int, d->tralloc);
+        REALLOC(d->fails, d->tralloc);
+        REALLOC(d->success, d->tralloc);
+        REALLOC(d->newlines, d->tralloc);
         while (oldalloc < d->tralloc)
           {
             d->trans[oldalloc] = NULL;
@@ -2735,11 +2752,11 @@ build_state_zero (struct dfa *d)
 {
   d->tralloc = 1;
   d->trcount = 0;
-  CALLOC(d->realtrans, int *, d->tralloc + 1);
+  CALLOC(d->realtrans, d->tralloc + 1);
   d->trans = d->realtrans + 1;
-  CALLOC(d->fails, int *, d->tralloc);
-  MALLOC(d->success, int, d->tralloc);
-  MALLOC(d->newlines, int, d->tralloc);
+  CALLOC(d->fails, d->tralloc);
+  MALLOC(d->success, d->tralloc);
+  MALLOC(d->newlines, d->tralloc);
   build_state(0, d);
 }
 
@@ -2780,11 +2797,11 @@ realloc_trans_if_necessary(struct dfa *d, int new_state)
 
       while (new_state >= d->tralloc)
         d->tralloc *= 2;
-      REALLOC(d->realtrans, int *, d->tralloc + 1);
+      REALLOC(d->realtrans, d->tralloc + 1);
       d->trans = d->realtrans + 1;
-      REALLOC(d->fails, int *, d->tralloc);
-      REALLOC(d->success, int, d->tralloc);
-      REALLOC(d->newlines, int, d->tralloc);
+      REALLOC(d->fails, d->tralloc);
+      REALLOC(d->success, d->tralloc);
+      REALLOC(d->newlines, d->tralloc);
       while (oldalloc < d->tralloc)
         {
           d->trans[oldalloc] = NULL;
@@ -3018,7 +3035,7 @@ check_matching_with_multibyte_ops (struct dfa *d, int s, int idx)
   int i;
   int* rarray;
 
-  MALLOC(rarray, int, d->states[s].mbps.nelem);
+  MALLOC(rarray, d->states[s].mbps.nelem);
   for (i = 0; i < d->states[s].mbps.nelem; ++i)
     {
       position pos = d->states[s].mbps.elems[i];
@@ -3139,7 +3156,7 @@ transit_state (struct dfa *d, int s, unsigned char const **pp)
 
   /* This state has some operators which can match a multibyte character.  */
   follows.nelem = 0;
-  MALLOC(follows.elems, position, d->nleaves);
+  MALLOC(follows.elems, d->nleaves);
 
   /* `maxlen' may be longer than the length of a character, because it may
      not be a character but a (multi character) collating element.
@@ -3270,8 +3287,8 @@ dfaexec (struct dfa *d, char const *begin, char *end,
 #if MBS_SUPPORT
   if (d->mb_cur_max > 1)
     {
-      MALLOC(mblen_buf, unsigned char, end - begin + 2);
-      MALLOC(inputwcs, wchar_t, end - begin + 2);
+      MALLOC(mblen_buf, end - begin + 2);
+      MALLOC(inputwcs, end - begin + 2);
       memset(&mbs, 0, sizeof(mbstate_t));
       prepare_wc_buf ((const char *) p, end);
     }
@@ -3439,19 +3456,19 @@ dfainit (struct dfa *d)
   memset (d, 0, sizeof *d);
 
   d->calloc = 1;
-  MALLOC(d->charclasses, charclass, d->calloc);
+  MALLOC(d->charclasses, d->calloc);
 
   d->talloc = 1;
-  MALLOC(d->tokens, token, d->talloc);
+  MALLOC(d->tokens, d->talloc);
 
 #if MBS_SUPPORT
   d->mb_cur_max = MB_CUR_MAX;
   if (d->mb_cur_max > 1)
     {
       d->nmultibyte_prop = 1;
-      MALLOC(d->multibyte_prop, int, d->nmultibyte_prop);
+      MALLOC(d->multibyte_prop, d->nmultibyte_prop);
       d->mbcsets_alloc = 1;
-      MALLOC(d->mbcsets, struct mb_char_classes, d->mbcsets_alloc);
+      MALLOC(d->mbcsets, d->mbcsets_alloc);
     }
 #endif
 }
@@ -4038,9 +4055,9 @@ dfamust (struct dfa *d)
  done:
   if (strlen(result))
     {
-      MALLOC(dm, struct dfamust, 1);
+      MALLOC(dm, 1);
       dm->exact = exact;
-      MALLOC(dm->must, char, strlen(result) + 1);
+      MALLOC(dm->must, strlen(result) + 1);
       strcpy(dm->must, result);
       dm->next = d->musts;
       d->musts = dm;

-----------------------------------------------------------------------

Summary of changes:
 src/dfa.c |  181 ++++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 100 insertions(+), 81 deletions(-)


hooks/post-receive
-- 
grep


From MAILER-DAEMON Tue Jul 12 12:46:38 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Qgg6X-00071u-M6
	for mharc-grep-commit@gnu.org; Tue, 12 Jul 2011 12:46:37 -0400
Received: from eggs.gnu.org ([140.186.70.92]:50198)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1Qgg6R-000706-L5
	for grep-commit@gnu.org; Tue, 12 Jul 2011 12:46:36 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1Qgg6M-0003Tr-Mh
	for grep-commit@gnu.org; Tue, 12 Jul 2011 12:46:31 -0400
Received: from colonialone.fsf.org ([140.186.70.51]:56199)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <jim@meyering.net>) id 1Qgg6L-0003Tm-Ro
	for grep-commit@gnu.org; Tue, 12 Jul 2011 12:46:25 -0400
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by colonialone.fsf.org with esmtp (Exim 4.69)
	(envelope-from <jim@meyering.net>) id 1Qgg6K-0007tG-Rd
	for grep-commit@gnu.org; Tue, 12 Jul 2011 16:46:24 +0000
Received: from meyering by vcs-noshell.in.savannah.gnu.org with local (Exim
	4.72) (envelope-from <meyering@savannah.gnu.org>) id 1Qgg6K-0003b9-Nr
	for grep-commit@gnu.org; Tue, 12 Jul 2011 16:46:24 +0000
Date: Tue, 12 Jul 2011 16:46:24 +0000
Message-Id: <E1Qgg6K-0003b9-Nr@vcs-noshell.in.savannah.gnu.org>
To: grep-commit@gnu.org
Subject: grep branch, master, updated. v2.9-13-gd82e0fc
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: b2d9a6f8c9e71007181eb1d7be4cae096e0da655
X-Git-Newrev: d82e0fce03553b929dac59e3effabc54bb02058f
From: Jim Meyering <jim@meyering.net>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.51
X-BeenThere: grep-commit@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
Reply-To: bug-grep@gnu.org
List-Id: CVS commit notices for GNU grep <grep-commit.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/grep-commit>,
	<mailto:grep-commit-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/grep-commit>
List-Post: <mailto:grep-commit@gnu.org>
List-Help: <mailto:grep-commit-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/grep-commit>,
	<mailto:grep-commit-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 12 Jul 2011 16:46:36 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  d82e0fce03553b929dac59e3effabc54bb02058f (commit)
      from  b2d9a6f8c9e71007181eb1d7be4cae096e0da655 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=d82e0fce03553b929dac59e3effabc54bb02058f


commit d82e0fce03553b929dac59e3effabc54bb02058f
Author: Jim Meyering <meyering@redhat.com>
Date:   Tue Jul 12 18:45:40 2011 +0200

    dfa: remove unnecessary inclusion of verify.h
    
    * src/dfa.c: Don't include "verify.h".

diff --git a/src/dfa.c b/src/dfa.c
index 611003d..b1a5266 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -29,7 +29,6 @@
 #include <limits.h>
 #include <string.h>
 #include <locale.h>
-#include "verify.h"
 
 #define STREQ(a, b) (strcmp (a, b) == 0)
 

-----------------------------------------------------------------------

Summary of changes:
 src/dfa.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)


hooks/post-receive
-- 
grep


From MAILER-DAEMON Fri Jul 15 09:25:59 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1QhiP1-0002pV-0Q
	for mharc-grep-commit@gnu.org; Fri, 15 Jul 2011 09:25:59 -0400
Received: from eggs.gnu.org ([140.186.70.92]:52709)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bonzini@gnu.org>) id 1QhiOu-0002nh-Kw
	for grep-commit@gnu.org; Fri, 15 Jul 2011 09:25:57 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <bonzini@gnu.org>) id 1QhiOp-0002Dp-Ld
	for grep-commit@gnu.org; Fri, 15 Jul 2011 09:25:52 -0400
Received: from colonialone.fsf.org ([140.186.70.51]:40729)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <bonzini@gnu.org>) id 1QhiOp-0002Dl-AJ
	for grep-commit@gnu.org; Fri, 15 Jul 2011 09:25:47 -0400
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by colonialone.fsf.org with esmtp (Exim 4.69)
	(envelope-from <bonzini@gnu.org>) id 1QhiOp-0003GH-0v
	for grep-commit@gnu.org; Fri, 15 Jul 2011 13:25:47 +0000
Received: from bonzini by vcs-noshell.in.savannah.gnu.org with local (Exim
	4.72) (envelope-from <bonzini@savannah.gnu.org>) id 1QhiOo-000696-U8
	for grep-commit@gnu.org; Fri, 15 Jul 2011 13:25:46 +0000
Date: Fri, 15 Jul 2011 13:25:46 +0000
Message-Id: <E1QhiOo-000696-U8@vcs-noshell.in.savannah.gnu.org>
To: grep-commit@gnu.org
Subject: grep branch, master, updated. v2.9-14-g708b04a
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: d82e0fce03553b929dac59e3effabc54bb02058f
X-Git-Newrev: 708b04abffa269253b92b35686e7852b7639adb7
From: Paolo Bonzini <bonzini@gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.51
X-BeenThere: grep-commit@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
Reply-To: bug-grep@gnu.org
List-Id: CVS commit notices for GNU grep <grep-commit.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/grep-commit>,
	<mailto:grep-commit-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/grep-commit>
List-Post: <mailto:grep-commit@gnu.org>
List-Help: <mailto:grep-commit-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/grep-commit>,
	<mailto:grep-commit-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 15 Jul 2011 13:25:57 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  708b04abffa269253b92b35686e7852b7639adb7 (commit)
      from  d82e0fce03553b929dac59e3effabc54bb02058f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=708b04abffa269253b92b35686e7852b7639adb7


commit 708b04abffa269253b92b35686e7852b7639adb7
Author: Reuben Thomas <rrt@sc3d.org>
Date:   Fri Jul 15 15:23:33 2011 +0200

    doc: improve documentation of character classes in the man page
    
    * doc/grep.in.1: Reword documentation of character classes.

diff --git a/doc/grep.in.1 b/doc/grep.in.1
index e9b4589..f1f68d0 100644
--- a/doc/grep.in.1
+++ b/doc/grep.in.1
@@ -676,11 +676,10 @@ and
 .BR [:xdigit:].
 For example,
 .B [[:alnum:]]
-means
-.BR [0\-9A\-Za\-z] ,
-except the latter form depends upon the C locale and the
-\s-1ASCII\s0 character encoding, whereas the former is independent
-of locale and character set.
+means the character class of numbers and
+letters in the current locale. In the C locale and \s-1ASCII\s0
+character set encoding, this is the same as
+.BR [0\-9A\-Za\-z] .
 (Note that the brackets in these class names are part of the symbolic
 names, and must be included in addition to the brackets delimiting
 the bracket expression.)

-----------------------------------------------------------------------

Summary of changes:
 doc/grep.in.1 |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
grep


From MAILER-DAEMON Wed Jul 27 11:56:16 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Qm6T2-0008AL-8M
	for mharc-grep-commit@gnu.org; Wed, 27 Jul 2011 11:56:16 -0400
Received: from eggs.gnu.org ([140.186.70.92]:48806)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <meyering@vcs.savannah.gnu.org>) id 1Ql41v-0005j8-FN
	for grep-commit@gnu.org; Sun, 24 Jul 2011 15:08:00 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <meyering@vcs.savannah.gnu.org>) id 1Ql41t-0006iJ-Ah
	for grep-commit@gnu.org; Sun, 24 Jul 2011 15:07:59 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:50371)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <meyering@vcs.savannah.gnu.org>) id 1Ql41t-0006iF-7u
	for grep-commit@gnu.org; Sun, 24 Jul 2011 15:07:57 -0400
Received: from meyering by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <meyering@vcs.savannah.gnu.org>) id 1Ql41r-0003qX-1m
	for grep-commit@gnu.org; Sun, 24 Jul 2011 19:07:56 +0000
Date: Sun, 24 Jul 2011 19:07:55 +0000
Message-Id: <E1Ql41r-0003qX-1m@vcs.savannah.gnu.org>
To: grep-commit@gnu.org
Subject: grep branch, master, updated. v2.9-16-gf4c4b1b
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 708b04abffa269253b92b35686e7852b7639adb7
X-Git-Newrev: f4c4b1b107f014244142e9b8a27208a5f3ac52b5
From: Jim Meyering <meyering@vcs.savannah.gnu.org>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-Mailman-Approved-At: Wed, 27 Jul 2011 11:56:15 -0400
X-BeenThere: grep-commit@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
Reply-To: bug-grep@gnu.org
List-Id: CVS commit notices for GNU grep <grep-commit.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/grep-commit>,
	<mailto:grep-commit-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/grep-commit>
List-Post: <mailto:grep-commit@gnu.org>
List-Help: <mailto:grep-commit-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/grep-commit>,
	<mailto:grep-commit-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 24 Jul 2011 19:08:01 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  f4c4b1b107f014244142e9b8a27208a5f3ac52b5 (commit)
       via  5e20a38a99fe6f0380f810b602d665dec2ae7cd0 (commit)
      from  708b04abffa269253b92b35686e7852b7639adb7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=f4c4b1b107f014244142e9b8a27208a5f3ac52b5


commit f4c4b1b107f014244142e9b8a27208a5f3ac52b5
Author: Jim Meyering <meyering@redhat.com>
Date:   Sun Jul 24 12:10:31 2011 +0200

    tests: add a test to trigger the bug
    
    * tests/Makefile.am (TESTS): Add it.
    * tests/in-eq-out-infloop: Exercise the bug/fix.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index a3a0f33..1baf269 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -61,6 +61,7 @@ TESTS =						\
   grep-dir					\
   help-version					\
   ignore-mmap					\
+  in-eq-out-infloop                             \
   include-exclude				\
   inconsistent-range                            \
   khadafy					\
diff --git a/tests/in-eq-out-infloop b/tests/in-eq-out-infloop
new file mode 100755
index 0000000..726accb
--- /dev/null
+++ b/tests/in-eq-out-infloop
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Demonstrate the disk-filling infloop when redirecting to an input file.
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+require_timeout_
+
+# Use an input file large enough that the problem is reproducible in spite
+# of buffering effects.  Just larger than 256KB should be adequate.
+v=$(printf %063d 0)'
+'
+# 64 * 2^12 = 256k
+for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
+  v="$v$v"
+done
+
+echo "$v" > out || framework_failure_
+echo 'grep: input file `out'\'' is also the output' \
+    > err.exp || framework_failure_
+
+# Require an exit status of 2.
+# grep-2.8 and earlier would infloop.
+timeout 10 grep 0 out >> out 2> err; st=$?
+test $st = 2 || fail=1
+
+compare err.exp err || fail=1
+
+Exit $fail

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=5e20a38a99fe6f0380f810b602d665dec2ae7cd0


commit f4c4b1b107f014244142e9b8a27208a5f3ac52b5
Author: Jim Meyering <meyering@redhat.com>
Date:   Sun Jul 24 12:10:31 2011 +0200

    tests: add a test to trigger the bug
    
    * tests/Makefile.am (TESTS): Add it.
    * tests/in-eq-out-infloop: Exercise the bug/fix.

diff --git a/tests/Makefile.am b/tests/Makefile.am
index a3a0f33..1baf269 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -61,6 +61,7 @@ TESTS =						\
   grep-dir					\
   help-version					\
   ignore-mmap					\
+  in-eq-out-infloop                             \
   include-exclude				\
   inconsistent-range                            \
   khadafy					\
diff --git a/tests/in-eq-out-infloop b/tests/in-eq-out-infloop
new file mode 100755
index 0000000..726accb
--- /dev/null
+++ b/tests/in-eq-out-infloop
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Demonstrate the disk-filling infloop when redirecting to an input file.
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+require_timeout_
+
+# Use an input file large enough that the problem is reproducible in spite
+# of buffering effects.  Just larger than 256KB should be adequate.
+v=$(printf %063d 0)'
+'
+# 64 * 2^12 = 256k
+for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
+  v="$v$v"
+done
+
+echo "$v" > out || framework_failure_
+echo 'grep: input file `out'\'' is also the output' \
+    > err.exp || framework_failure_
+
+# Require an exit status of 2.
+# grep-2.8 and earlier would infloop.
+timeout 10 grep 0 out >> out 2> err; st=$?
+test $st = 2 || fail=1
+
+compare err.exp err || fail=1
+
+Exit $fail

-----------------------------------------------------------------------

Summary of changes:
 NEWS                    |    5 +++++
 bootstrap.conf          |    3 ++-
 src/main.c              |   26 ++++++++++++++++++++++++++
 src/system.h            |   42 +++++++++++++++++++++++++++++++++++++++++-
 tests/Makefile.am       |    1 +
 tests/in-eq-out-infloop |   26 ++++++++++++++++++++++++++
 6 files changed, 101 insertions(+), 2 deletions(-)
 create mode 100755 tests/in-eq-out-infloop


hooks/post-receive
-- 
grep


