Skip to content

Commit 7a19e69

Browse files
committed
express: support modern Lemon allocator callbacks
Modern Lemon accepts allocator callbacks with a context parameter. Adapt the standard C allocator functions so generated EXPRESS parsers remain compatible.
1 parent 0b950dd commit 7a19e69

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/express/expparse.y

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
/** Lemon grammar for Express parser, based on SCL's expparse.y. */
22
%include {
33
#include <assert.h>
4+
#include <stdlib.h>
45
#include "token_type.h"
56
#include "parse_data.h"
67

8+
/* Wrapper functions for modern lemon compatibility
9+
* Modern lemon from starseeker/lemon uses a 3-parameter signature for memory
10+
* allocation functions: void* realloc(void*, size_t, void*) and void free(void*, void*)
11+
* The third parameter is a context pointer for custom allocators.
12+
* These wrappers adapt the standard C library malloc/free/realloc to this signature
13+
* by ignoring the context parameter. Error handling (NULL checks) is performed by
14+
* the generated lemon code, not in these wrappers.
15+
*/
16+
static void *exp_realloc(void *ptr, size_t size, void *ctx) {
17+
(void)ctx; /* unused - no custom allocator context needed */
18+
return realloc(ptr, size);
19+
}
20+
21+
static void exp_free(void *ptr, void *ctx) {
22+
(void)ctx; /* unused - no custom allocator context needed */
23+
free(ptr);
24+
}
25+
726
int yyerrstatus = 0;
827
#define yyerrok (yyerrstatus = 0)
928

@@ -120,6 +139,8 @@ void parserInitState( void )
120139
} /* include */
121140

122141
%extra_argument { parse_data_t parseData }
142+
%realloc exp_realloc
143+
%free exp_free
123144

124145
%destructor statement_list {
125146
if (parseData.scanner == NULL) {

0 commit comments

Comments
 (0)