[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [patch #6569] Allow grep to work in small stack environment
From: |
Jim Meyering |
Subject: |
Re: [patch #6569] Allow grep to work in small stack environment |
Date: |
Fri, 27 Aug 2010 10:39:09 +0200 |
Paolo Bonzini wrote:
> Update of patch #6569 (project grep):
> Status: None => Ready For Test
>
> Reply to this item at:
>
> <http://savannah.gnu.org/patch/?6569>
Here's an adjusted patch:
- use xnmalloc, not malloc+test+return, so we don't ignore malloc failure.
- use sizeof *VAR, not "sizeof TYPE" -- the former is more maintainable.
- adjust indentation to retain declaration alignment
>From ced405b364654f13cb1926d7622be167436a8e36 Mon Sep 17 00:00:00 2001
From: Patrick Boyd <address@hidden>
Date: Fri, 27 Aug 2010 10:31:37 +0200
Subject: [PATCH] dfa: reduce stack usage
* src/dfa.c (dfaanalyze): Allocate GRPS and LABELS arrays from heap,
not on the stack.
---
src/dfa.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/dfa.c b/src/dfa.c
index 5da59d8..0563d8f 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -2290,8 +2290,8 @@ dfaanalyze (struct dfa *d, int searchflag)
void
dfastate (int s, struct dfa *d, int trans[])
{
- position_set grps[NOTCHAR]; /* As many as will ever be needed. */
- charclass labels[NOTCHAR]; /* Labels corresponding to the groups. */
+ position_set *grps; /* As many as will ever be needed. */
+ charclass *labels; /* Labels corresponding to the groups. */
int ngrps = 0; /* Number of groups actually used. */
position pos; /* Current position being considered. */
charclass matches; /* Set of matching characters. */
@@ -2315,6 +2315,9 @@ dfastate (int s, struct dfa *d, int trans[])
#endif
int i, j, k;
+ grps = xnmalloc (NOTCHAR, sizeof *grps);
+ labels = xnmalloc (NOTCHAR, sizeof *labels);
+
/* Initialize the set of letters, if necessary. */
if (! initialized)
{
@@ -2577,6 +2580,8 @@ dfastate (int s, struct dfa *d, int trans[])
free(grps[i].elems);
free(follows.elems);
free(tmp.elems);
+ free(grps);
+ free(labels);
}
/* Some routines for manipulating a compiled dfa's transition tables.
--
1.7.2.2.510.g7180a