From 9bf6d941428e9fd2ba84dd1ebf1a4f7abd7f5642 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 31 Mar 2025 17:02:52 +0300 Subject: Move line outside --- executor.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/executor.c b/executor.c index 5806981..144ad2c 100644 --- a/executor.c +++ b/executor.c @@ -13,6 +13,12 @@ static struct cccl_Variables globals = {0}; static struct cccl_Function functions[52] = {0}; static struct cccl_Stack stack = {0}; +static struct +{ + char *buf; + size_t length; +} line = {0}; + static void expand_stack(void) { if (!stack.buffer) @@ -71,12 +77,10 @@ enum cccl_ExecutorStatus cccl_execute(struct cccl_Node *code, struct cccl_Variab fprintf(stderr, "Executing %s, %lu nodes, depth %lu\n", strnode(code->type), code->in_length, depth); if (interactive) { - char *line = NULL; - size_t lsize = 0; - ssize_t length = getline(&line, &lsize, stdin); + ssize_t length = getline(&line.buf, &line.length, stdin); if (length == -1 && ferror(stdin)) err(1, "getline()"); - if (!strcmp(line, "d\n")) + if (!strcmp(line.buf, "d\n")) { fputs("Locals:\n", stderr); for (size_t i = 0; i < 52; ++i) -- cgit 1.4.1