Re: Reporting malloc failure in actions

Joe Nelson via Users list for the GNU Bison parser generator <[email protected]> Thu, 31 Dec 2020 11:40:52 -0600
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
Christian Schoenebeck wrote:
> > #ifdef YYNOMEM
> > 	/* newer bison version */
> > 	YYNOMEM;
> > #else
> > 	/* older bison (undocumented feature) */
> > 	goto yyexhaustedlab;
> > #endif
> 
> You would be dealing with internals, but AFAICS that internal label
> already exists for decades, so it'll be okay as pragmatic solution I
> guess.

Just realized another problem -- I don't think I can use goto across
functions like this. And even if the goto was valid in parser_alloc(),
I'll need YYNOMEM for other functions, like strdup(). The simplest thing
to do is probably shim YYNOMEM in my parser and use it directly:

#ifndef YYNOMEM
#define YYNOMEM goto yyexhaustedlab
#endif