开发者

heap handling in a bison push pure parser

开发者 https://www.devze.com 2023-02-19 04:09 出处:网络
Is there any w开发者_Python百科ay to specify my own allocator/deallocator functions for heap management instead of malloc()/free() for a pure push parser in bison?Most of Bison\'s memory allocations c

Is there any w开发者_Python百科ay to specify my own allocator/deallocator functions for heap management instead of malloc()/free() for a pure push parser in bison?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消