From 8521b6a69deab8cdabe1c87b09ecdc93d75af98e Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 30 Aug 2026 14:20:55 +0000 Subject: Remove the struct memory struct FossilOrigin-Name: 38568a34f631b2a4eef72542e2988a9fe081f85d3248194c2ff995a9eed6bd5d --- src/lib/syntax.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/syntax.c') diff --git a/src/lib/syntax.c b/src/lib/syntax.c index 395c75e..9888bef 100644 --- a/src/lib/syntax.c +++ b/src/lib/syntax.c @@ -246,7 +246,7 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline) return NULL; } - tokens = memory_alloc_token_list(&aplwc->memory, n); + tokens = memory_alloc_token_list(aplwc, n); if(tokens == NULL){ aplwc->last_error = APLWC_OUT_OF_MEMORY; return NULL; @@ -261,7 +261,7 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline) for(i++; i < n; i++){ if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE){ - memory_free_token_list(&aplwc->memory, tokens); + memory_free_token_list(aplwc, tokens); return NULL; } } -- cgit v1.2.3 From 2261ffa04ddf30a7c8eae6e64129b293fc8bffd9 Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 30 Aug 2026 14:25:56 +0000 Subject: Let the memory allocation code set the last_error to APLWC_OUT_OF_MEMORY, instead of the callers FossilOrigin-Name: 46c74e207a84e861636dbfebc4ba8bb9e7b17401dfd2c4fb9bdeae0fa98fd530 --- src/lib/syntax.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/lib/syntax.c') diff --git a/src/lib/syntax.c b/src/lib/syntax.c index 9888bef..16d0363 100644 --- a/src/lib/syntax.c +++ b/src/lib/syntax.c @@ -247,10 +247,8 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline) } tokens = memory_alloc_token_list(aplwc, n); - if(tokens == NULL){ - aplwc->last_error = APLWC_OUT_OF_MEMORY; + if(tokens == NULL) return NULL; - } tokens->text = text; tokens->length = n; scan(text, tokens); -- cgit v1.2.3 From 04827577ea502a9f0edc69e00e008751c8119cbc Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 30 Aug 2026 14:46:38 +0000 Subject: Remove a lot of functions for manually freeing memory (they were not implemented) FossilOrigin-Name: 693765728e62a74a0ab15d657f7d1dd83702a9371fb042dafe6250f84a252959 --- src/lib/syntax.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/lib/syntax.c') diff --git a/src/lib/syntax.c b/src/lib/syntax.c index 16d0363..75d6c14 100644 --- a/src/lib/syntax.c +++ b/src/lib/syntax.c @@ -258,10 +258,8 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline) continue; for(i++; i < n; i++){ - if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE){ - memory_free_token_list(aplwc, tokens); + if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE) return NULL; - } } } -- cgit v1.2.3 From 729964bea692f9683860978b89848784a7fc2f46 Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 30 Aug 2026 20:52:43 +0000 Subject: Still a lot to be done, but I'm going to bed. Two remaining big issues: * aplwc (the parameter passed "everywhere") - should it move or not? * values returned from the public API should not move. FossilOrigin-Name: 31ab3154b8f3d5ac167218496e9e204324bf0ac9d36b7bada8fe2a6c8f93d51c --- src/lib/syntax.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/lib/syntax.c') diff --git a/src/lib/syntax.c b/src/lib/syntax.c index 75d6c14..ae52343 100644 --- a/src/lib/syntax.c +++ b/src/lib/syntax.c @@ -240,15 +240,17 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline) struct token_list *tokens; size_t n, i; + MEMPTRS(aplwc, 1); + MEMPTR(0, text); + + tokens = NULL; rc = check(text, &n); - if(rc != APLWC_OK){ - aplwc->last_error = rc; - return NULL; - } + if(rc != APLWC_OK) + goto end; tokens = memory_alloc_token_list(aplwc, n); if(tokens == NULL) - return NULL; + goto end; tokens->text = text; tokens->length = n; scan(text, tokens); @@ -258,11 +260,17 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline) continue; for(i++; i < n; i++){ - if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE) - return NULL; + if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE){ + rc = APLWC_INVALID_SYNTAX; + tokens = NULL; + goto end; + } } } +end: + aplwc->last_error = rc; + MEMPTRS_EXIT(aplwc); return tokens; } -- cgit v1.2.3