From 9f83f595029d67794952d29b1faa10db09918b90 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Wed, 17 Aug 2022 22:20:04 +0300 Subject: [PATCH] Update headers --- include/dict.h | 6 ++++++ include/extra/dict.h | 2 +- include/extra/memory.h | 3 +++ include/extra/string.h | 12 ++++++------ include/extra/vtype.h | 2 -- include/list.h | 4 ++-- include/map.h | 6 ++++++ include/set.h | 7 ++++++- include/string.h | 4 ++-- include/vtype.h | 2 -- src/__internal/include.h | 2 ++ 11 files changed, 34 insertions(+), 16 deletions(-) diff --git a/include/dict.h b/include/dict.h index 8ff850c..d6f9963 100644 --- a/include/dict.h +++ b/include/dict.h @@ -7,6 +7,8 @@ #ifndef LIBCDSB_DICT_H #define LIBCDSB_DICT_H +/*#####################################################################################################################*/ + typedef int (*dict_access_callback)(const void* key, vtype key_type, void* value, vtype value_type, void* data); extern void dict_init(vtype_dict* x) Nonnull__(1); @@ -16,6 +18,10 @@ extern void dict_init(vtype_dict* x) Nonnull__(1); #define dict_update(x, key, value) _LIBCDSB_Generic2(libcdsb_dict, update, key, value)(x, key, value) #define dict_remove(x, key) dict_pop(x, key, 0, 0) +#define in_dict(x, key) (dict_get(&x, key, 0, 0) == 0) + +/*#####################################################################################################################*/ + extern int libcdsb_dict_get_by_pointer(vtype_dict* x, const void* key, void* data, dict_access_callback, bool cut) Nonnull__(1); extern int libcdsb_dict_get_by_cstring(vtype_dict* x, const char* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2); extern int libcdsb_dict_get_by_string (vtype_dict* x, const vtype_string* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2); diff --git a/include/extra/dict.h b/include/extra/dict.h index 47bc976..972b77b 100644 --- a/include/extra/dict.h +++ b/include/extra/dict.h @@ -9,7 +9,7 @@ #define dict_foreach(x, data, callback) libcdsb_dict_foreach(x, data, callback, 0) extern bool libcdsb_dict_update (vtype_dict* x, const void* key, vtype key_type, const void* value, vtype value_type) Nonnull__(1); -extern int libcdsb_dict_get (vtype_dict* x, const void* key, vtype key_type, void* data, dict_access_callback, bool cut) Nonnull__(1); +extern int libcdsb_dict_find (vtype_dict* x, const void* key, vtype key_type, void* data, dict_access_callback, bool cut) Nonnull__(1); extern int libcdsb_dict_foreach (vtype_dict* x, void* data, dict_access_callback, bool flush) Nonnull__(1,3); extern bool libcdsb_dict_shrink_to_fit(vtype_dict* x) Nonnull__(1); diff --git a/include/extra/memory.h b/include/extra/memory.h index b21b43e..e27f73b 100644 --- a/include/extra/memory.h +++ b/include/extra/memory.h @@ -22,10 +22,13 @@ extern void* libcdsb_malloc (size_t n) Warn_unused_result__; extern void* libcdsb_calloc (size_t n, size_t c) Warn_unused_result__; extern void* libcdsb_realloc(void *p, size_t n) Warn_unused_result__; +extern void libcdsb_free(void* s); + #define aligned_alloc libcdsb_aalloc #define malloc libcdsb_malloc #define calloc libcdsb_calloc #define realloc libcdsb_realloc +#define free libcdsb_free #define stack_init libcdsb_stack_init #define stack_push libcdsb_stack_push diff --git a/include/extra/string.h b/include/extra/string.h index 64490ef..283df4b 100644 --- a/include/extra/string.h +++ b/include/extra/string.h @@ -8,7 +8,7 @@ /*#####################################################################################################################*/ -#define string_split(x, sep, maxn) _LIBCDSB_GenericS(libcdsb_string, split, sep)(x, sep, maxn) +#define string_split(s, sep, maxn) _LIBCDSB_GenericS(libcdsb_string, split, sep)(s, sep, maxn) #define string_case_compare string_compare_case_insensitive #define string_replace_r(x, src, dest, maxn) _LIBCDSB_GenericS2(libcdsb_string, replace_r, src, dest)(x, src, dest, maxn) @@ -27,15 +27,15 @@ extern size_t string_align_center(vtype_string* x, size_t padsize, int padchr) N extern size_t string_align_right (vtype_string* x, size_t padsize, int padchr) Nonnull__(1); extern size_t string_align_left (vtype_string* x, size_t padsize, int padchr) Nonnull__(1); -extern int string_compare_case_insensitive(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); - extern void libcdsb_string_replace(vtype_string* x, char* dest, size_t dest_nmemb, const char* src, size_t nmemb) Nonnull__(1,2); /*#####################################################################################################################*/ -inline vtype_array libcdsb_string_split_string (const vtype_string* x, const vtype_string* sep, size_t maxn) Nonnull__(1) Always_inline__; -extern vtype_array libcdsb_string_split_cstring(const vtype_string* string, const char* sep, size_t maxn) Nonnull__(1); -extern vtype_array libcdsb_string_split_char (const vtype_string* string, int chr, size_t maxn) Nonnull__(1); +extern int string_compare_case_insensitive(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); + +inline vtype_array libcdsb_string_split_string (const vtype_string* s, const vtype_string* sep, size_t maxn) Nonnull__(1) Always_inline__; +extern vtype_array libcdsb_string_split_cstring(const vtype_string* s, const char* sep, size_t maxn) Nonnull__(1); +extern vtype_array libcdsb_string_split_char (const vtype_string* s, int chr, size_t maxn) Nonnull__(1); inline void libcdsb_string_trim_string (vtype_string* x, const vtype_string* s, int direction) Nonnull__(1) Always_inline__; extern void libcdsb_string_trim_cstring(vtype_string* x, const char* s, int direction) Nonnull__(1); diff --git a/include/extra/vtype.h b/include/extra/vtype.h index 7c5aec9..af4307d 100644 --- a/include/extra/vtype.h +++ b/include/extra/vtype.h @@ -6,8 +6,6 @@ #ifndef LIBCDSB_EXTRA_VTYPE_H #define LIBCDSB_EXTRA_VTYPE_H -extern const size_t LIBCDSB_VTYPE_SIZES[18]; - extern const char* libcdsb_vtype_name(vtype t) Warn_unused_result__; extern const char* libcdsb_vtype_stringify(const void* value, vtype t) Warn_unused_result__; diff --git a/include/list.h b/include/list.h index 219e04e..2cde5b4 100644 --- a/include/list.h +++ b/include/list.h @@ -11,8 +11,8 @@ typedef int (*list_access_callback)(void* value, ssize_t index, vtype type, void* data); -extern void list_init (vtype_list* x) Nonnull__(1); -extern void list_extend(vtype_list* x, const vtype_list* s) Nonnull__(1,2); +extern void list_init (vtype_list* x) Nonnull__(1); +extern void list_extend (vtype_list* x, const vtype_list* s) Nonnull__(1,2); extern size_t list_slice (vtype_list* x, vtype_list* src, ssize_t index, size_t count, bool cut) Nonnull__(1,2); extern void list_sort (vtype_list* x) Nonnull__(1); extern void list_reverse(vtype_list* x) Nonnull__(1); diff --git a/include/map.h b/include/map.h index 4248050..85755bf 100644 --- a/include/map.h +++ b/include/map.h @@ -7,6 +7,8 @@ #ifndef LIBCDSB_MAP_H #define LIBCDSB_MAP_H +/*#####################################################################################################################*/ + typedef int (*map_access_callback)(const void* key, vtype key_type, void* value, vtype value_type, void* data); extern void map_init(vtype_map* x, vtype key_type) Nonnull__(1); @@ -16,6 +18,10 @@ extern void map_init(vtype_map* x, vtype key_type) Nonnull__(1); #define map_update(x, key, value) _LIBCDSB_Generic2(libcdsb_map, update, key, value)(x, key, value) #define map_remove(x, key) map_pop(x, key, 0, 0) +#define in_map(x, key) (map_get(&x, key, 0, 0) == 0) + +/*#####################################################################################################################*/ + extern int libcdsb_map_find_pointer(vtype_map* x, const void* key, void* data, map_access_callback, bool cut) Nonnull__(1); extern int libcdsb_map_find_cstring(vtype_map* x, const char* key, void* data, map_access_callback, bool cut) Nonnull__(1,2); extern int libcdsb_map_find_string (vtype_map* x, const vtype_string* key, void* data, map_access_callback, bool cut) Nonnull__(1,2); diff --git a/include/set.h b/include/set.h index 238c910..d679c98 100644 --- a/include/set.h +++ b/include/set.h @@ -7,6 +7,8 @@ #ifndef LIBCDSB_SET_H #define LIBCDSB_SET_H +/*#####################################################################################################################*/ + typedef int (*vset_access_callback)(const void* value, vtype type, void* data); extern void vset_init(vtype_set* x, vtype type) Nonnull__(1); @@ -14,8 +16,11 @@ extern void vset_init(vtype_set* x, vtype type) Nonnull__(1); #define vset_pop(x, value, data, callback) _LIBCDSB_Generic (libcdsb_vset, find, value)(x, value, data, callback, 1) #define vset_get(x, value, data, callback) _LIBCDSB_Generic (libcdsb_vset, find, value)(x, value, data, callback, 0) #define vset_push(x, value) _LIBCDSB_Generic (libcdsb_vset, push, value)(x, value) +#define vset_remove(x, value) vset_pop(x, value, 0, 0) -#define in_vset(x, value) (vset_get(&x, value, 0, 0, 0) == 0) +#define in_vset(x, value) (vset_get(&x, value, 0, 0) == 0) + +/*#####################################################################################################################*/ extern bool libcdsb_vset_push_pointer(vtype_set* x, const void* value) Nonnull__(1); extern bool libcdsb_vset_push_cstring(vtype_set* x, const char* value) Nonnull__(1,2); diff --git a/include/string.h b/include/string.h index aeb51fd..b8e8474 100644 --- a/include/string.h +++ b/include/string.h @@ -13,11 +13,11 @@ extern void string_init(vtype_string* x, const char* value) Nonnull__(1); extern char* string_at(const vtype_string* s, ssize_t index) Nonnull__(1); -extern bool string_slice(vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) Nonnull__(1,2); +extern size_t string_slice(vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) Nonnull__(1,2); #define string_indexof(s, arg) _LIBCDSB_GenericS(libcdsb_string, indexof, arg)(s, arg) #define string_count(s, arg) _LIBCDSB_GenericS(libcdsb_string, count, arg)(s, arg) -#define string_concat(s, value) _LIBCDSB_GenericS(libcdsb_string, concat, value)(s, value) +#define string_concat(x, value) _LIBCDSB_GenericS(libcdsb_string, concat, value)(x, value) #define string_trim_spaces(x) libcdsb_string_trim_spaces(x, 0) #define string_ltrim_spaces(x) libcdsb_string_trim_spaces(x, -1) diff --git a/include/vtype.h b/include/vtype.h index 8238a19..4ec686c 100644 --- a/include/vtype.h +++ b/include/vtype.h @@ -31,8 +31,6 @@ typedef enum libcdsb_value_types { VTYPE_LIST = 16, VTYPE_SET = 17, VTYPE_DICT = 18, - - LIBCDSB_VTYPE_TERMINATION, /* It must be at the end of the enum. Never be used */ } vtype; diff --git a/src/__internal/include.h b/src/__internal/include.h index 76f096d..dbefa85 100644 --- a/src/__internal/include.h +++ b/src/__internal/include.h @@ -14,6 +14,8 @@ #ifndef LIBCDSB_SRC_INTERNAL_INCLUDE #define LIBCDSB_SRC_INTERNAL_INCLUDE +extern const size_t LIBCDSB_VTYPE_SIZES[19]; + #define is_x64 (sizeof(void*) == sizeof(vtype_uint64)) #define is_big_endian (*((unsigned int*)"\0\0\0\1") < (unsigned int)0xffff) #define is_little_endian (!is_big_endian)