Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

heap handling in a bison push pure parser

Is there any way to specify my own allocator/deallocator functions for heap management instead of malloc()/free() for a pure push parser in bison?

like image 772
Flavius Avatar asked Mar 21 '11 11:03

Flavius


1 Answers

Most of Bison's memory allocations can be redirected with macros - in the prologue (between %{ and %}) you can write

#define YYMALLOC mymalloc
#define YYFREE myfree

and Bison will then call mymalloc and myfree instead of malloc and free. However, it expects whatever functions you provide to have exactly the same type signature as the standard malloc and free; there is no way to get it to pass extra/different arguments. And I wouldn't use function-like macros if I were you. Worse, in my copy (Bison 2.4.1) yypstate_new calls malloc directly, with no override possible -- this is arguably a bug.

like image 116
zwol Avatar answered Nov 06 '22 19:11

zwol