Re: CRT in generated parser

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.bugs
Message-ID <[email protected]>
Hi Kovalex,

> Le 22 août 2020 à 17:55, [email protected] a écrit :
> 
> Hi folks, I'm working on a tool that uses flex/bison and runs in rather
> scarce environment thus needs C runtime substitution.
> 
> Tool employs reentrant scanner/parser. As far as I can see bison 3.0.4
> (default on Ubuntu 18.04) and latest git version both
> generates yypstate_new/yypstate_delete using straightforward calls to
> malloc() and free(). Is it possible to override this?
> 
> I see YYMALLOC/YYFREE used in other parts of generated parser's code,
> perhaps, they could be used in yypstate* routines as well?

You are right, it should have been this way from the start...

Thanks for reporting.  I'm installing the patch below.


> Is there any best known method for substituting runtime in generated parser
> code? (besides, SED-like search-replace).

Besides updating to a future version of Bison?  I'm afraid not.

Cheers!


commit 629902bc603d4bd07bb5c45c7ed638f4fbf3b91f
Author: Akim Demaille <[email protected]>
Date:   Sun Aug 30 09:45:34 2020 +0200

    c: always use YYMALLOC/YYFREE
    
    Reported by Kovalex <[email protected]>.
    https://lists.gnu.org/r/bug-bison/2020-08/msg00015.html
    
    * data/skeletons/yacc.c: Don't make direct calls to malloc/free.

diff --git a/NEWS b/NEWS
index 68bbbb81..a5c59f0d 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ GNU Bison NEWS
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Bug fixes
+
+  Push parsers use YYMALLOC/YYFREE instead of direct calls to malloc/free.
 
 * Noteworthy changes in release 3.7.1 (2020-08-02) [stable]
 
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 9ec153ac..c695a039 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -1486,7 +1486,7 @@ yypstate_new (void)
   yypstate *yyps;]b4_pure_if([], [[
   if (yypstate_allocated)
     return YY_NULLPTR;]])[
-  yyps = YY_CAST (yypstate *, malloc (sizeof *yyps));
+  yyps = YY_CAST (yypstate *, YYMALLOC (sizeof *yyps));
   if (!yyps)
     return YY_NULLPTR;]b4_pure_if([], [[
   yypstate_allocated = 1;]])[
@@ -1515,7 +1515,7 @@ yypstate_delete (yypstate *yyps)
 #endif]b4_lac_if([[
       if (yyes != yyesa)
         YYSTACK_FREE (yyes);]])[
-      free (yyps);]b4_pure_if([], [[
+      YYFREE (yyps);]b4_pure_if([], [[
       yypstate_allocated = 0;]])[
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.