[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: calc.at workaround for current test failures
From: |
Paul Eggert |
Subject: |
Re: calc.at workaround for current test failures |
Date: |
30 Jun 2003 23:40:36 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
Frank Heckenbach <address@hidden> writes:
> Paul Eggert wrote:
> > Could you please do it? That would save me a bit of time.
>
> Patch attached....
> I'm also doing it for abort (YY_ABORT) since programs may like to
> provide their own version.
That's a different change, which should be addressed in a separate
patch. I don't offhand see the need for it, though. Perhaps you
can elaborate?
> Besides YYSTACK_ALLOC and YYSTACK_FREE (copied from yacc.c), glr.c
> also needs permant allocation. I used the macro names YY_MALLOC,
> YY_REALLOC and YY_FREE, is this ok?
I'd prefer a 'YY' prefix instead of a 'YY_' prefix, since that's the
convention. (YY_ABORT would be a special case, though, since YYABORT
is taken.)
Also, yacc.c should be modified similarly, and glr.c can remove a few
casts. I don't think we need the awkward and portability-challenged
YYSTACK_* macros in glr.c, as the only place they can be used is in a
rarely-used location, so the efficiency motivation for them isn't
there.
So, how about the following change instead? (I'm trying to illustrate
the preferred form for discussing patches: a single subject, or at
least closely related subjects, with a ChangeLog entry before the
patch.)
2003-06-30 Paul Eggert <address@hidden>
Let the user specify how to allocate and free memory.
Derived from a suggestion by Frank Heckenbach in
<http://mail.gnu.org/archive/html/bison-patches/2003-06/msg00041.html>.
* data/glr.c (YYFREE, YYMALLOC, YYREALLOC): New macros.
All uses of free, malloc, realloc changed to use these macros,
and unnecessary casts removed.
* data/yacc.c (YYFREE, YYMALLOC): Likewise.
Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.60
diff -p -u -r1.60 glr.c
--- data/glr.c 20 Jun 2003 22:52:12 -0000 1.60
+++ data/glr.c 1 Jul 2003 06:11:06 -0000
@@ -219,6 +219,16 @@ static YYLTYPE yyloc_default;
]/* Line __line__ of glr.c. */
b4_syncline(address@hidden@], address@hidden@])
[
+#ifndef YYFREE
+# define YYFREE free
+#endif
+#ifndef YYMALLOC
+# define YYMALLOC malloc
+#endif
+#ifndef YYREALLOC
+# define YYREALLOC realloc
+#endif
+
#ifdef __cplusplus
typedef bool yybool;
#else
@@ -865,13 +875,13 @@ yyinitStateSet (yyGLRStateSet* yyset)
{
yyset->yysize = 1;
yyset->yycapacity = 16;
- yyset->yystates = (yyGLRState**) malloc (16 * sizeof (yyset->yystates[0]));
+ yyset->yystates = YYMALLOC (16 * sizeof yyset->yystates[0]);
yyset->yystates[0] = NULL;
}
static void yyfreeStateSet (yyGLRStateSet* yyset)
{
- free (yyset->yystates);
+ YYFREE (yyset->yystates);
}
/** Initialize STACK to a single empty stack, with total maximum
@@ -884,7 +894,7 @@ yyinitGLRStack (yyGLRStack* yystack, siz
yynerrs = 0;
yystack->yyspaceLeft = yysize;
yystack->yynextFree = yystack->yyitems =
- (yyGLRStackItem*) malloc (yysize * sizeof (yystack->yynextFree[0]));
+ YYMALLOC (yysize * sizeof yystack->yynextFree[0]);
yystack->yysplitPoint = NULL;
yystack->yylastDeleted = NULL;
yyinitStateSet (&yystack->yytops);
@@ -948,7 +958,7 @@ yyexpandGLRStack (yyGLRStack* yystack]b4
yystack->yytops.yystates[yyn] =
YYRELOC (yystack->yyitems, yynewStack.yyitems,
yystack->yytops.yystates[yyn], yystate);
- free (yystack->yyitems);
+ YYFREE (yystack->yyitems);
yystack->yyitems = yynewStack.yyitems;
yystack->yynextFree = yynewStack.yynextFree + yysize;
yystack->yyspaceLeft = yynewStack.yyspaceLeft - yysize;
@@ -962,7 +972,7 @@ yyexpandGLRStack (yyGLRStack* yystack]b4
static void
yyfreeGLRStack (yyGLRStack* yystack)
{
- free (yystack->yyitems);
+ YYFREE (yystack->yyitems);
yyfreeStateSet (&yystack->yytops);
}
@@ -1231,9 +1241,9 @@ yysplitStack (yyGLRStack* yystack, int y
{
yystack->yytops.yycapacity *= 2;
yystack->yytops.yystates =
- (yyGLRState**) realloc (yystack->yytops.yystates,
- yystack->yytops.yycapacity
- * sizeof (yyGLRState*));
+ YYREALLOC (yystack->yytops.yystates,
+ (yystack->yytops.yycapacity
+ * sizeof yystack->yytops.yystates[0]));
}
yystack->yytops.yystates[yystack->yytops.yysize]
= yystack->yytops.yystates[yyk];
@@ -1644,7 +1654,7 @@ yyreportSyntaxError (yyGLRStack* yystack
}
yysize += (sizeof ("syntax error, unexpected ")
+ strlen (yytokenName (*yytokenp)));
- yymsg = (char*) malloc (yysize);
+ yymsg = YYMALLOC (yysize);
if (yymsg != 0)
{
char* yyp = yymsg;
@@ -1663,7 +1673,7 @@ yyreportSyntaxError (yyGLRStack* yystack
}
}
yyerror (]b4_lyyerror_args[yymsg);
- free (yymsg);
+ YYFREE (yymsg);
}
else
yyerror (]b4_lyyerror_args["syntax error; also virtual memory
exhausted");
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.59
diff -p -u -r1.59 yacc.c
--- data/yacc.c 20 Jun 2003 22:52:12 -0000 1.59
+++ data/yacc.c 1 Jul 2003 06:11:08 -0000
@@ -216,6 +216,13 @@ b4_syncline(address@hidden@], address@hidden@])[
#if ! defined (yyoverflow) || YYERROR_VERBOSE
+# ifndef YYFREE
+# define YYFREE free
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# endif
+
/* The parser invokes alloca or malloc; define the necessary symbols. */
# ifdef YYSTACK_USE_ALLOCA
@@ -240,8 +247,8 @@ b4_syncline(address@hidden@], address@hidden@])[
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# endif
-# define YYSTACK_ALLOC malloc
-# define YYSTACK_FREE free
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
# endif
#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
- Re: calc.at workaround for current test failures,
Paul Eggert <=