diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2022-12-02 01:22:03 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2022-12-02 01:22:03 +0100 |
commit | 08fbad18d2987d1c719142a3b810dc8c728ca3d8 (patch) | |
tree | 0b4fc2f7a2037ce4f316803d92ffda413cb51cad | |
parent | 3232effeba2bf5ddc7cce1ac8b4c9650b07c66e1 (diff) | |
download | kit-08fbad18d2987d1c719142a3b810dc8c728ca3d8.zip |
Clean up dynamic_array interface
-rw-r--r-- | source/kit/dynamic_array.h | 31 | ||||
-rw-r--r-- | source/kit/file.h | 2 | ||||
-rw-r--r-- | source/kit/input_buffer.c | 2 | ||||
-rw-r--r-- | source/kit/input_buffer.h | 8 |
4 files changed, 16 insertions, 27 deletions
diff --git a/source/kit/dynamic_array.h b/source/kit/dynamic_array.h index cc35a28..62695f4 100644 --- a/source/kit/dynamic_array.h +++ b/source/kit/dynamic_array.h @@ -20,25 +20,15 @@ void kit_da_init(kit_da_void_t *array, ptrdiff_t element_size, void kit_da_resize(kit_da_void_t *array, ptrdiff_t element_size, ptrdiff_t size); -/* Declare dynamic array type. +/* Dynamic array type definition. */ -#define KIT_DA_TYPE(name_, element_type_) \ - typedef struct { \ - ptrdiff_t capacity; \ - ptrdiff_t size; \ - element_type_ *values; \ - kit_allocator_t alloc; \ - } name_ - -/* Declare dynamic array. - */ -#define KIT_DA(name_, element_type_) \ - struct { \ - ptrdiff_t capacity; \ - ptrdiff_t size; \ - element_type_ *values; \ - kit_allocator_t alloc; \ - } name_ +#define KIT_DA(element_type_) \ + struct { \ + ptrdiff_t capacity; \ + ptrdiff_t size; \ + element_type_ *values; \ + kit_allocator_t alloc; \ + } /* Initialize dynamic array. */ @@ -49,7 +39,7 @@ void kit_da_resize(kit_da_void_t *array, ptrdiff_t element_size, /* Declare and initialize dynamic array. */ #define KIT_DA_CREATE(name_, element_type_, size_) \ - KIT_DA(name_, element_type_); \ + KIT_DA(element_type_) name_; \ KIT_DA_INIT(name_, (size_), kit_alloc_default()) /* Destroy dynamic array. @@ -101,7 +91,7 @@ void kit_da_resize(kit_da_void_t *array, ptrdiff_t element_size, KIT_DA_RESIZE((array_), (array_).size - 1); \ } while (0) -KIT_DA_TYPE(kit_string_t, char); +typedef KIT_DA(char) kit_string_t; #ifndef KIT_DISABLE_SHORT_NAMES # define da_void_t kit_da_void_t @@ -109,7 +99,6 @@ KIT_DA_TYPE(kit_string_t, char); # define da_resize kit_da_resize # define string_t kit_string_t -# define DA_TYPE KIT_DA_TYPE # define DA KIT_DA # define DA_INIT KIT_DA_INIT # define DA_CREATE KIT_DA_CREATE diff --git a/source/kit/file.h b/source/kit/file.h index ef58d37..68abea0 100644 --- a/source/kit/file.h +++ b/source/kit/file.h @@ -50,7 +50,7 @@ int kit_path_type(kit_str_t path); ptrdiff_t kit_file_size(kit_str_t path); -DA_TYPE(kit_path_list_t, kit_string_t); +typedef KIT_DA(kit_string_t) kit_path_list_t; kit_path_list_t kit_file_enum_folder(kit_str_t path, kit_allocator_t alloc); diff --git a/source/kit/input_buffer.c b/source/kit/input_buffer.c index 2f3bd07..eae0f1a 100644 --- a/source/kit/input_buffer.c +++ b/source/kit/input_buffer.c @@ -6,7 +6,7 @@ typedef struct { ptrdiff_t ref_count; kit_is_handle_t upstream; kit_allocator_t alloc; - DA(data, char); + kit_string_t data; } internal_buffer_t; static internal_buffer_t *buf_init(kit_is_handle_t upstream, diff --git a/source/kit/input_buffer.h b/source/kit/input_buffer.h index 1b47c4a..7c81da1 100644 --- a/source/kit/input_buffer.h +++ b/source/kit/input_buffer.h @@ -9,10 +9,10 @@ extern "C" { #endif typedef struct { - int error; - ptrdiff_t offset; - void *internal; - KIT_DA(data, char); + int error; + ptrdiff_t offset; + void *internal; + kit_string_t data; } kit_ib_handle_t; kit_ib_handle_t kit_ib_wrap(kit_is_handle_t upstream, |