bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GLR init


From: Paul Eggert
Subject: Re: GLR init
Date: Thu, 21 Jul 2005 21:58:06 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

address@hidden writes:

> When malloc() returns 0 there is a reason for it.
> Then doing 2nd malloc()? risky.

No, it's not risky in practice, in my experience.  However, to save
time arguing about it, I installed this:

2005-07-21  Paul Eggert  <address@hidden>

        * data/glr.c (yyinitGLRStack, yyreturn): Don't call malloc
        again if the first call fails.

--- glr.c       21 Jul 2005 20:53:03 -0000      1.107
+++ glr.c       22 Jul 2005 04:56:14 -0000      1.108
@@ -1018,11 +1018,14 @@ yyinitGLRStack (yyGLRStack* yystack, siz
   yystack->yyerrState = 0;
   yynerrs = 0;
   yystack->yyspaceLeft = yysize;
-  yystack->yynextFree = yystack->yyitems =
+  yystack->yyitems =
     (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystack->yynextFree[0]);
+  if (!yystack->yyitems)
+    return yyfalse;
+  yystack->yynextFree = yystack->yyitems;
   yystack->yysplitPoint = NULL;
   yystack->yylastDeleted = NULL;
-  return yyinitStateSet (&yystack->yytops) && yystack->yyitems;
+  return yyinitStateSet (&yystack->yytops);
 }
 
 #define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
@@ -2154,24 +2157,27 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
     yydestruct ("Error: discarding lookahead",
                 yytoken, yylvalp]b4_location_if([, yyllocp])[);
 
-  /* Now pop stack until empty, destroying its entries as we go.  */
-  {
-    yyGLRState** yystates = yystack.yytops.yystates;
-    if (yystates)
-      while (yystates[0])
-       {
-         yyGLRState *yys = yystates[0];
+  /* If the stack is well-formed, pop the stack until it is empty,
+     destroying its entries as we go.  But free the stack regardless
+     of whether it is well-formed.  */
+  if (yystack.yyitems)
+    {
+      yyGLRState** yystates = yystack.yytops.yystates;
+      if (yystates)
+       while (yystates[0])
+         {
+           yyGLRState *yys = yystates[0];
 ]b4_location_if([[       yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
-)[       yydestruct ("Error: popping",
-                     yystos[yys->yylrState],
-                     &yys->yysemantics.yysval]b4_location_if([, 
&yys->yyloc])[);
-         yystates[0] = yys->yypred;
-         yystack.yynextFree -= 1;
-         yystack.yyspaceLeft += 1;
-       }
-  }
+)[         yydestruct ("Error: popping",
+                       yystos[yys->yylrState],
+                       &yys->yysemantics.yysval]b4_location_if([, 
&yys->yyloc])[);
+           yystates[0] = yys->yypred;
+           yystack.yynextFree -= 1;
+           yystack.yyspaceLeft += 1;
+         }
+      yyfreeGLRStack (&yystack);
+    }
 
-  yyfreeGLRStack (&yystack);
   return yyresult;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]