From 961bf54ec108d0a487c158ca4338c1aa45d497f3 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Wed, 25 Feb 2026 18:27:51 +0100 Subject: [PATCH] CE allocate tokens with arena --- ce/Makefile | 1 + ce/ce.c | 18 +++++++----------- libarena/arena.h | 1 + 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ce/Makefile b/ce/Makefile index 0dbcb5f..f8abfbd 100644 --- a/ce/Makefile +++ b/ce/Makefile @@ -3,6 +3,7 @@ include ../make/ufuncs.mk $(eval $(call add_lib,libstring)) $(eval $(call add_lib,libprocess)) $(eval $(call add_lib,libaux)) +$(eval $(call add_lib,libarena)) $(eval $(call add_include,libterminal)) cflags += -DPRINTF_INCLUDE_CONFIG_H=1 diff --git a/ce/ce.c b/ce/ce.c index 9aab7b7..877d631 100644 --- a/ce/ce.c +++ b/ce/ce.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -27,13 +28,15 @@ static int e_pgid; static bool run = true; +static struct arena arena; + static void putch (char ch) { mail_send (e_pgid, &ch, 1); } void putchar_ (char ch) { putch (ch); } static bool tokenize_line (void* ctx, const char* start, size_t len) { struct list_node_link** head = ctx; - struct token* token = malloc (sizeof (*token)); + struct token* token = arena_malloc (&arena, sizeof (*token)); if (token == NULL) return false; @@ -46,15 +49,6 @@ static bool tokenize_line (void* ctx, const char* start, size_t len) { return true; } -static void free_tokens (struct list_node_link* tokens) { - struct list_node_link *token_link, *token_tmp_link; - list_foreach (tokens, token_link, token_tmp_link) { - struct token* token = list_entry (token_link, struct token, tokens_link); - list_remove (tokens, &token->tokens_link); - free (token); - } -} - static void cmd_echo (struct list_node_link* tokens) { struct list_node_link *token_link, *token_tmp_link; list_foreach (tokens, token_link, token_tmp_link) { @@ -190,7 +184,7 @@ static void exec_line (const char* line) { if (tokens != NULL) exec_tokens (tokens); - free_tokens (tokens); + arena_reset (&arena); } void app_main (void) { @@ -223,4 +217,6 @@ void app_main (void) { line_cursor = 0; memset (line_buffer, 0, sizeof (line_buffer)); } + + arena_destroy (&arena); } diff --git a/libarena/arena.h b/libarena/arena.h index 31ef78a..d50de5f 100644 --- a/libarena/arena.h +++ b/libarena/arena.h @@ -2,6 +2,7 @@ #define _LIBARENA_ARENA_H #include +#include #define ARENA_CHUNK_CAPACITY (8 * 1024)