aboutsummaryrefslogtreecommitdiffhomepage
path: root/c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-11-22 10:22:37 +0100
committerlemon <lsof@mailbox.org>2025-11-22 10:22:37 +0100
commit654dde3b3f2fafddb9139cc53af0633689b1d2b7 (patch)
treebea64af651eaf9e730bde8bea4e8b3effd197293 /c
parent79272697e025663d7a4e7972019f318fea8d18bf (diff)
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
Diffstat (limited to 'c')
-rw-r--r--c/lex.c9
1 files changed, 7 insertions, 2 deletions
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:;
}