diff options
| author | 2024-07-08 19:58:22 -0400 | |
|---|---|---|
| committer | 2024-07-08 19:58:22 -0400 | |
| commit | 4f7847b2c0219995c4fe2d0858b5030e73581a3c (patch) | |
| tree | 9b84a1fc5698a4f8b97c0580fccf2b26c000d748 /examples/string/test_large.c | |
| parent | delete for hashtables (diff) | |
Major API reorganization, test infrastructure
The API is now hidden behind functions. The GC struct can have an
unstable layout without affecting any compiled binaries (users of
Universal Service or collectors hidden behind the API). The
collectors can be called directly if desired.
The API now allows for different allocation flags. These will be
used in future extensions (like weak pointers). For now none are
used.
Tests are compiled for each collector. I can't think of a good
solution that will encompass everything I want to write, but for
now this will work on POSIX systems.
Diffstat (limited to 'examples/string/test_large.c')
| -rw-r--r-- | examples/string/test_large.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/examples/string/test_large.c b/examples/string/test_large.c index 2ba7a8a..58e6b8c 100644 --- a/examples/string/test_large.c +++ b/examples/string/test_large.c @@ -24,49 +24,48 @@ */ #include <stdio.h> +#include <string.h> #include "uns.h" #include "uns_string.h" -int test(struct uns_gc *gc) +int test(Uns_GC gc) { struct uns_ctr r = {0}; - int i; + int i, j; /* MistralAI 8x7B 0.1: * Prompt: "write a sonnet about garbage collectors (the memory management kind)" - * - * This string constant is larger than the standard's minimum. If - * this test doesn't compile, get a better compiler. */ - const char s[] = - "To the humble garbagemen of code's dark night,\n" - "Who tread through bits and bytes with steady hand.\n" - "They roam the heap, in dimly lit sight,\n" - "And rescue order from chaos unplanned.\n" + const char *s[] = { + "To the humble garbagemen of code's dark night,\n", + "Who tread through bits and bytes with steady hand.\n", + "They roam the heap, in dimly lit sight,\n", + "And rescue order from chaos unplanned.\n", - "With algorithms precise and swift they glide,\n" - "Through malloc'd arrays and pointers vast.\n" - "Their work essential to keep programs wide,\n" - "From crashing down upon us too soon passed.\n" + "With algorithms precise and swift they glide,\n", + "Through malloc'd arrays and pointers vast.\n", + "Their work essential to keep programs wide,\n", + "From crashing down upon us too soon passed.\n", - "Yet often left unsung are these brave knights,\n" - "Whose vigilance keeps our software clean.\n" - "In shadows cast by CPUs might,\n" - "Unseen forces that make sense of unseen.\n" + "Yet often left unsung are these brave knights,\n", + "Whose vigilance keeps our software clean.\n", + "In shadows cast by CPUs might,\n", + "Unseen forces that make sense of unseen.\n", - "So here's to you, dear Garbage Collectors all,\n" + "So here's to you, dear Garbage Collectors all,\n", "Thank you for keeping coding dreams enthralled.\n" - ; + }; /* generate lots of garbage */ uns_string_alloc(gc, &r, 32); uns_root_add(gc, &r); for (i = 0; i < 100; i++) { - uns_string_append_bytes(gc, &r, s, sizeof(s) - 1); + for (j = 0; j < sizeof(s)/sizeof(s[0]); j++) + uns_string_append_bytes(gc, &r, s[j], strlen(s[j])); } - gc->collect(gc); + uns_collect(gc); uns_root_remove(gc, &r); - gc->collect(gc); + uns_collect(gc); return 0; } |
