bison-patches
[Top][All Lists]
Advanced

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

01-fyi-yystack-realloc.patch


From: Akim Demaille
Subject: 01-fyi-yystack-realloc.patch
Date: Mon, 12 Nov 2001 10:06:35 +0100

I intend to apply the following patches on both branches.

I'll keep you informed if there are patches I can't apply on the trunk.


Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/bison.simple (YYSTACK_REALLOC): New.
        (yyparse) [!yyoverflow]: Use it and free the old stack.
        Reported by FIXME: Who.

Index: src/bison.simple
--- src/bison.simple Thu, 11 Oct 2001 19:02:23 +0200 akim
+++ src/bison.simple Sat, 10 Nov 2001 11:20:48 +0100 akim
@@ -76,10 +76,27 @@
 # define YYSTACK_USE_ALLOCA 0
 #endif

+/* Realloc WHAT from SIZE to YYSTACKSIZE elements of TYPE.
+   If WHAT was malloc'ed (not the original automatic ARRAY), free it. */
 #if YYSTACK_USE_ALLOCA
-# define YYSTACK_ALLOC alloca
+# define YYSTACK_REALLOC(Type, What, Array)                            \
+do {                                                                   \
+  Type *old = What;                                                    \
+  What = (Type *) malloc (yystacksize * sizeof (Type));                        
\
+  __yy_memcpy ((char *) What, (char *) old,                            \
+              (size) * (unsigned int) sizeof (Type));                  \
+  yyfree_stacks = 1;                                                   \
+  if (old != Array)                                                    \
+    free (old);                                                                
\
+} while (0)
 #else
-# define YYSTACK_ALLOC malloc
+# define YYSTACK_REALLOC(Type, What, Array)                            \
+do {                                                                   \
+  Type *old = What;                                                    \
+  What = (Type *) alloca (yystacksize * sizeof (Type));                        
\
+  __yy_memcpy ((char *) What, (char *) old,                            \
+              (size) * (unsigned int) sizeof (Type));                  \
+} while (0)
 #endif

 #define yyerrok                (yyerrstatus = 0)
@@ -291,7 +308,7 @@

   /* Three stacks and their tools:
      `yyss': related to states,
-     `yysv': related to semantic values,
+     `yyvs': related to semantic values,
      `yyls': related to locations.

      Refer to the stacks thru separate pointers, to allow yyoverflow
@@ -420,19 +437,11 @@
       yystacksize *= 2;
       if (yystacksize > YYMAXDEPTH)
        yystacksize = YYMAXDEPTH;
-# if !YYSTACK_USE_ALLOCA
-      yyfree_stacks = 1;
-# endif
-      yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
-      __yy_memcpy ((char *)yyss, (char *)yyss1,
-                  size * (unsigned int) sizeof (*yyssp));
-      yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
-      __yy_memcpy ((char *)yyvs, (char *)yyvs1,
-                  size * (unsigned int) sizeof (*yyvsp));
+
+      YYSTACK_REALLOC (short, yyss, yyssa);
+      YYSTACK_REALLOC (YYSTYPE, yyvs, yyvsa);
 # if YYLSP_NEEDED
-      yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
-      __yy_memcpy ((char *)yyls, (char *)yyls1,
-                  size * (unsigned int) sizeof (*yylsp));
+      YYSTACK_REALLOC (YYLTYPE, yyls, yylsa);
 # endif
 #endif /* no yyoverflow */



reply via email to

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