From 654dde3b3f2fafddb9139cc53af0633689b1d2b7 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 22 Nov 2025 10:22:37 +0100 Subject: lex: move token data from tmp to glob arena when used in a macro body maybe introduce per-macro arenas to tie their lifetimes to that. but most macros have global lifetime (i.e. aren't #undef'd) so there probably wouldn't be much benefit to that --- c/lex.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'c') diff --git a/c/lex.c b/c/lex.c index 176231e..e016a6a 100644 --- a/c/lex.c +++ b/c/lex.c @@ -561,8 +561,11 @@ Begin: } tmp[n] = 0; tk->len = n; - if (n == lx->chridx - idx) tk->s = (char *)&lx->dat[idx]; - else { + if (n == lx->chridx - idx) { + tk->litlit = 1; + tk->s = (char *)&lx->dat[idx]; + } else { + tk->litlit = 0; tk->s = alloccopy(lx->tmparena, tmp, n, 1); } RET(TKNUMLIT); @@ -890,6 +893,8 @@ ppdefine(struct lexer *lx) continue; } } + if (in_range(tk.t, TKNUMLIT, TKSTRLIT) && !tk.litlit) + tk.s = alloccopy(&globarena, tk.s, tk.len << tk.wide, 1); vpush(&rlist, tk); Next:; } -- cgit v1.2.3