diff options
| author | peter <peter@pmikkelsen.com> | 2026-08-30 20:52:43 +0000 |
|---|---|---|
| committer | peter <peter@pmikkelsen.com> | 2026-08-30 20:52:43 +0000 |
| commit | 729964bea692f9683860978b89848784a7fc2f46 (patch) | |
| tree | ba5b37a61206142fce18214c7af341ac837a7923 /src/bin | |
| parent | 04827577ea502a9f0edc69e00e008751c8119cbc (diff) | |
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
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/main.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/bin/main.c b/src/bin/main.c index fb75a9d..99149f6 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -4,15 +4,21 @@ #include <errno.h> #include "aplwc_repl.h" -#define MEMSIZE 20000 +static void *my_alloc(size_t min, size_t max, size_t *actual) +{ + UNUSED_PARAMETER(max); + + *actual = min; + return malloc(min); +} int main(int argc, char *argv[]) { + struct aplwc_fns fns; struct aplwc *aplwc; struct aplwc_line *line; struct aplwc_value *value; - uint8_t *data; char *input, *src; int ret, exit_code, line_number; size_t input_size, src_size, i; @@ -28,6 +34,9 @@ main(int argc, char *argv[]) exit_code = 0; line_number = 0; + memset(&fns, 0, sizeof(fns)); + fns.alloc = my_alloc; + while((opt = getopt(argc, argv, "x")) != -1){ switch(opt){ case 'x': @@ -52,16 +61,9 @@ usage: else goto usage; - data = malloc(MEMSIZE); - if(data == NULL){ - fprintf(stderr, "Couldn't allocate memory\n"); - return 1; - } - - ret = aplwc_new(&aplwc, data, MEMSIZE); + ret = aplwc_new(&aplwc, fns); if(ret){ fprintf(stderr, "Couldn't create new aplwc instance: %s\n", aplwc_errstr_rc(ret)); - free(data); return 1; } @@ -152,6 +154,5 @@ exit: aplwc_free_value(value); aplwc_destroy(aplwc); - free(data); return exit_code; } |