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?
Asked
Active
Viewed 577 times
1 Answers
3
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.

zwol
- 135,547
- 38
- 252
- 361
-
1Yeah I've found it out already, by looking at the generated source. +1 and accepted, a good answer. It doesn't have this bug in 2.4.3. – Flavius Mar 22 '11 at 09:41