summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter <peter@pmikkelsen.com>2026-08-30 14:46:38 +0000
committerpeter <peter@pmikkelsen.com>2026-08-30 14:46:38 +0000
commit04827577ea502a9f0edc69e00e008751c8119cbc (patch)
treee09a4f12628b85c4bc3713b00bb0bf8bb5291400 /src
parent2261ffa04ddf30a7c8eae6e64129b293fc8bffd9 (diff)
Remove a lot of functions for manually freeing memory (they were not implemented)
FossilOrigin-Name: 693765728e62a74a0ab15d657f7d1dd83702a9371fb042dafe6250f84a252959
Diffstat (limited to 'src')
-rw-r--r--src/lib/aplwc_internal.h7
-rw-r--r--src/lib/main.c41
-rw-r--r--src/lib/memory.c51
-rw-r--r--src/lib/module.c2
-rw-r--r--src/lib/syntax.c4
5 files changed, 22 insertions, 83 deletions
diff --git a/src/lib/aplwc_internal.h b/src/lib/aplwc_internal.h
index 2e3e274..23b26f9 100644
--- a/src/lib/aplwc_internal.h
+++ b/src/lib/aplwc_internal.h
@@ -87,12 +87,7 @@ struct token_list *memory_alloc_token_list(struct aplwc *, size_t);
struct aplwc_value *memory_alloc_aplwc_value(struct aplwc *);
struct aplwc_module *memory_alloc_aplwc_module(struct aplwc *);
struct module_imports *memory_alloc_module_imports(struct aplwc *, size_t);
-void memory_free_aplwc(struct aplwc *, struct aplwc *);
-void memory_free_aplwc_line(struct aplwc *, struct aplwc_line *);
-void memory_free_string(struct aplwc *, struct string *);
-void memory_free_token_list(struct aplwc *, struct token_list *);
-void memory_free_aplwc_value(struct aplwc *, struct aplwc_value *);
-void memory_free_aplwc_module(struct aplwc *, struct aplwc_module *);
+void memory_free_root(struct aplwc *, void *);
/* string.c */
struct string *chars_to_string(struct aplwc *, const char *, int len);
diff --git a/src/lib/main.c b/src/lib/main.c
index 2bd374b..81cd6bb 100644
--- a/src/lib/main.c
+++ b/src/lib/main.c
@@ -19,8 +19,7 @@ aplwc_new(struct aplwc **p, uint8_t *data, size_t size)
void
aplwc_destroy(struct aplwc *p)
{
- if(p)
- memory_free_aplwc(p, p);
+ UNUSED_PARAMETER(p);
}
const char *
@@ -97,9 +96,8 @@ aplwc_read(struct aplwc *aplwc, const char *line)
void
aplwc_free_line(struct aplwc_line *line)
{
- if(line == NULL)
- return;
- memory_free_aplwc_line(line->aplwc, line);
+ if(line)
+ memory_free_root(line->aplwc, line);
}
struct aplwc_value *
@@ -112,9 +110,8 @@ aplwc_eval(struct aplwc_line *line)
void
aplwc_free_value(struct aplwc_value *value)
{
- if(value == NULL)
- return;
- memory_free_aplwc_value(value->aplwc, value);
+ if(value)
+ memory_free_root(value->aplwc, value);
}
const char *
@@ -134,32 +131,16 @@ aplwc_load_module(struct aplwc *aplwc, const char *name, const char *src, int sr
struct string *text, *namestr;
struct token_list *tokens;
- namestr = NULL;
- text = NULL;
- tokens = NULL;
-
- namestr = chars_to_string(aplwc, name, -1);
- if(namestr == NULL)
+ if((namestr = chars_to_string(aplwc, name, -1)) == NULL)
goto error;
-
- text = chars_to_string(aplwc, src, srclen);
- if(text == NULL)
+ if((text = chars_to_string(aplwc, src, srclen)) == NULL)
goto error;
-
- tokens = scan_string(aplwc, text, 0);
- if(tokens == NULL)
+ if((tokens = scan_string(aplwc, text, 0)) == NULL)
goto error;
-
- if(load_module(aplwc, namestr, tokens) == APLWC_OK)
- return APLWC_OK;
- else{
+ if(load_module(aplwc, namestr, tokens) != APLWC_OK){
error:
- if(tokens != NULL)
- memory_free_token_list(aplwc, tokens);
- if(text != NULL)
- memory_free_string(aplwc, text);
- if(namestr != NULL)
- memory_free_string(aplwc, namestr);
return aplwc_last_error(aplwc);
}
+
+ return APLWC_OK;
}
diff --git a/src/lib/memory.c b/src/lib/memory.c
index ca4babf..94f903c 100644
--- a/src/lib/memory.c
+++ b/src/lib/memory.c
@@ -38,6 +38,15 @@ alloc(struct aplwc *aplwc, size_t size, size_t align)
return p;
}
+void
+memory_free_root(struct aplwc *aplwc, void *p)
+{
+ if(NEVER(p == NULL))
+ return;
+
+ UNUSED_PARAMETER(aplwc);
+}
+
struct aplwc *
memory_alloc_aplwc(struct aplwc *aplwc)
{
@@ -47,13 +56,6 @@ memory_alloc_aplwc(struct aplwc *aplwc)
return p;
}
-void
-memory_free_aplwc(struct aplwc *aplwc, struct aplwc *p)
-{
- UNUSED_PARAMETER(aplwc);
- UNUSED_PARAMETER(p);
-}
-
struct aplwc_line *
memory_alloc_aplwc_line(struct aplwc *aplwc)
{
@@ -63,13 +65,6 @@ memory_alloc_aplwc_line(struct aplwc *aplwc)
return p;
}
-void
-memory_free_aplwc_line(struct aplwc *aplwc, struct aplwc_line *p)
-{
- UNUSED_PARAMETER(aplwc);
- UNUSED_PARAMETER(p);
-}
-
struct string *
memory_alloc_string(struct aplwc *aplwc, size_t bytes)
{
@@ -79,13 +74,6 @@ memory_alloc_string(struct aplwc *aplwc, size_t bytes)
return p;
}
-void
-memory_free_string(struct aplwc *aplwc, struct string *p)
-{
- UNUSED_PARAMETER(aplwc);
- UNUSED_PARAMETER(p);
-}
-
struct token_list *
memory_alloc_token_list(struct aplwc *aplwc, size_t tokens)
{
@@ -95,13 +83,6 @@ memory_alloc_token_list(struct aplwc *aplwc, size_t tokens)
return p;
}
-void
-memory_free_token_list(struct aplwc *aplwc, struct token_list *p)
-{
- UNUSED_PARAMETER(aplwc);
- UNUSED_PARAMETER(p);
-}
-
struct aplwc_value *
memory_alloc_aplwc_value(struct aplwc *aplwc)
{
@@ -111,13 +92,6 @@ memory_alloc_aplwc_value(struct aplwc *aplwc)
return p;
}
-void
-memory_free_aplwc_value(struct aplwc *aplwc, struct aplwc_value *p)
-{
- UNUSED_PARAMETER(aplwc);
- UNUSED_PARAMETER(p);
-}
-
struct aplwc_module *
memory_alloc_aplwc_module(struct aplwc *aplwc)
{
@@ -126,10 +100,3 @@ memory_alloc_aplwc_module(struct aplwc *aplwc)
p = alloc(aplwc, sizeof(struct aplwc_module), alignof(struct aplwc_module));
return p;
}
-
-void
-memory_free_aplwc_module(struct aplwc *aplwc, struct aplwc_module *p)
-{
- UNUSED_PARAMETER(aplwc);
- UNUSED_PARAMETER(p);
-}
diff --git a/src/lib/module.c b/src/lib/module.c
index db5dc78..f559f00 100644
--- a/src/lib/module.c
+++ b/src/lib/module.c
@@ -70,8 +70,6 @@ load_module(struct aplwc *aplwc, struct string *name, struct token_list *tokens)
if(rc == APLWC_OK){
module->link = aplwc->modules;
aplwc->modules = module;
- }else{
- memory_free_aplwc_module(aplwc, module);
}
return rc;
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;
- }
}
}