diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-11-05 15:22:02 -0500 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-11-05 15:22:02 -0500 |
| commit | 7b9204a8680539bc4795a14f3d9a34e47981d0c3 (patch) | |
| tree | 7aa69bba0c9cbee0cafb638fd49af64958dbb228 /source/string.c | |
| parent | faa937cb09cd01f4ea94f5d7722a20e9c1246df0 (diff) | |
more objects and special slab for gc
Diffstat (limited to 'source/string.c')
| -rw-r--r-- | source/string.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/source/string.c b/source/string.c new file mode 100644 index 0000000..e2d19ed --- /dev/null +++ b/source/string.c @@ -0,0 +1,24 @@ + +#include "kpl.h" + +static const kpl_interface object_string_interface = { + .gc_mark_object_fn = NULL, + .native_free_fn = NULL, + .log_fn = NULL +}; + +kpl_object_string *kpl_object_string_create(kpl_thread *thread, int32_t bytes_size) { + if (bytes_size < 0) + return NULL; + bytes_size++; + kpl_object_string *object_string = kpl_gc_new(thread, &object_string_interface, + sizeof(kpl_object_string) + sizeof(uint8_t) * bytes_size); + object_string->bytes_length = 0; + object_string->bytes_size = object_string->object_size - sizeof(kpl_object_string); + memset(object_string->bytes, '\0', object_string->bytes_size); + return object_string; +} + +extern inline kpl_object_string *kpl_object_string_from_c_string(kpl_thread *thread, const char *c_string); + +extern inline void kpl_object_string_destroy(kpl_thread *thread, kpl_object_string *object_string); |
