Refactor headers

This commit is contained in:
Gregory Lirent 2022-08-22 11:56:16 +03:00
parent 08aebcc15b
commit 2118404bfe
15 changed files with 145 additions and 303 deletions

View File

@ -1,126 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#ifndef LIBCDSB_CORE_GENERICS_H
#define LIBCDSB_CORE_GENERICS_H
#define vtypeof(x) (vtype)(_Generic((x),\
const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\
const char**: VTYPE_STRING, char**: VTYPE_STRING,\
const vtype_string*: VTYPE_STRING, vtype_string*: VTYPE_STRING,\
const vtype_array*: VTYPE_ARRAY, vtype_array*: VTYPE_ARRAY,\
const vtype_list*: VTYPE_LIST, vtype_list*: VTYPE_LIST,\
const vtype_map*: VTYPE_MAP, vtype_map*: VTYPE_MAP,\
const vtype_set*: VTYPE_SET, vtype_set*: VTYPE_SET,\
const vtype_dict*: VTYPE_DICT, vtype_dict*: VTYPE_DICT,\
vtype_bool: VTYPE_BOOLEAN,\
vtype_uint8: VTYPE_UINT8,\
vtype_uint16: VTYPE_UINT16,\
vtype_uint32: VTYPE_UINT32,\
vtype_uint64: VTYPE_UINT64,\
vtype_int8: VTYPE_INT8,\
vtype_int16: VTYPE_INT16,\
vtype_int32: VTYPE_INT32,\
vtype_int64: VTYPE_INT64,\
vtype_float: VTYPE_FLOAT,\
vtype_double: VTYPE_DOUBLE,\
vtype_ldouble: VTYPE_LDOUBLE))
#define _LIBCDSB_vtypeof(x) vtypeof(_Generic((x), default: (x), const char*: &(x), char*: &(x)))
#define _LIBCDSB_value_pointer(x) _Generic((x), default: &(x),\
vtype_string*: (x), const vtype_string*: (x),\
vtype_array*: (x), const vtype_array*: (x),\
vtype_list*: (x), const vtype_list*: (x),\
vtype_map*: (x), const vtype_map*: (x),\
vtype_set*: (x), const vtype_set*: (x),\
vtype_dict*: (x), const vtype_dict*: (x))
#define _LIBCDSB_Generic(T, f, v) _Generic((v),\
void*: T ## _ ## f ## _pointer, const void*: T ## _ ## f ## _pointer,\
char*: T ## _ ## f ## _cstring, const char*: T ## _ ## f ## _cstring,\
vtype_string*: T ## _ ## f ## _string, const vtype_string*: T ## _ ## f ## _string,\
vtype_array*: T ## _ ## f ## _array, const vtype_array*: T ## _ ## f ## _array,\
vtype_list*: T ## _ ## f ## _list, const vtype_list*: T ## _ ## f ## _list,\
vtype_map*: T ## _ ## f ## _map, const vtype_map*: T ## _ ## f ## _map,\
vtype_set*: T ## _ ## f ## _vset, const vtype_set*: T ## _ ## f ## _vset,\
vtype_dict*: T ## _ ## f ## _dict, const vtype_dict*: T ## _ ## f ## _dict,\
vtype_bool: T ## _ ## f ## _boolean,\
vtype_uint8: T ## _ ## f ## _uint8,\
vtype_uint16: T ## _ ## f ## _uint16,\
vtype_uint32: T ## _ ## f ## _uint32,\
vtype_uint64: T ## _ ## f ## _uint64,\
vtype_int8: T ## _ ## f ## _int8,\
vtype_int16: T ## _ ## f ## _int16,\
vtype_int32: T ## _ ## f ## _int32,\
vtype_int64: T ## _ ## f ## _int64,\
vtype_float: T ## _ ## f ## _float,\
vtype_double: T ## _ ## f ## _double,\
vtype_ldouble: T ## _ ## f ## _ldouble\
)
#define _LIBCDSB_Generic2(T, f, k, v) _Generic((k),\
void*: _LIBCDSB_Generic(T, f ## _pointer, v), const void*: _LIBCDSB_Generic(T, f ## _pointer, v),\
char*: _LIBCDSB_Generic(T, f ## _cstring, v), const char*: _LIBCDSB_Generic(T, f ## _cstring, v),\
vtype_string*: _LIBCDSB_Generic(T, f ## _string, v), const vtype_string*: _LIBCDSB_Generic(T, f ## _string, v),\
vtype_array*: _LIBCDSB_Generic(T, f ## _array, v), const vtype_array*: _LIBCDSB_Generic(T, f ## _array, v),\
vtype_list*: _LIBCDSB_Generic(T, f ## _list, v), const vtype_list*: _LIBCDSB_Generic(T, f ## _list, v),\
vtype_map*: _LIBCDSB_Generic(T, f ## _map, v), const vtype_map*: _LIBCDSB_Generic(T, f ## _map, v),\
vtype_set*: _LIBCDSB_Generic(T, f ## _vset, v), const vtype_set*: _LIBCDSB_Generic(T, f ## _vset, v),\
vtype_dict*: _LIBCDSB_Generic(T, f ## _dict, v), const vtype_dict*: _LIBCDSB_Generic(T, f ## _dict, v),\
vtype_bool: _LIBCDSB_Generic(T, f ## _boolean, v),\
vtype_uint8: _LIBCDSB_Generic(T, f ## _uint8, v),\
vtype_uint16: _LIBCDSB_Generic(T, f ## _uint16, v),\
vtype_uint32: _LIBCDSB_Generic(T, f ## _uint32, v),\
vtype_uint64: _LIBCDSB_Generic(T, f ## _uint64, v),\
vtype_int8: _LIBCDSB_Generic(T, f ## _int8, v),\
vtype_int16: _LIBCDSB_Generic(T, f ## _int16, v),\
vtype_int32: _LIBCDSB_Generic(T, f ## _int32, v),\
vtype_int64: _LIBCDSB_Generic(T, f ## _int64, v),\
vtype_float: _LIBCDSB_Generic(T, f ## _float, v),\
vtype_double: _LIBCDSB_Generic(T, f ## _double, v),\
vtype_ldouble: _LIBCDSB_Generic(T, f ## _ldouble, v)\
)
#define _LIBCDSB_Generic_attach(T, ins_f, att_f, v) _Generic((v),\
void*: T ## _ ## ins_f ## _pointer, const void*: T ## _ ## ins_f ## _pointer,\
char*: T ## _ ## ins_f ## _cstring, const char*: T ## _ ## ins_f ## _cstring,\
vtype_string*: T ## _ ## att_f ## _string, const vtype_string*: T ## _ ## att_f ## _string,\
vtype_array*: T ## _ ## att_f ## _array, const vtype_array*: T ## _ ## att_f ## _array,\
vtype_list*: T ## _ ## att_f ## _list, const vtype_list*: T ## _ ## att_f ## _list,\
vtype_map*: T ## _ ## att_f ## _map, const vtype_map*: T ## _ ## att_f ## _map,\
vtype_set*: T ## _ ## att_f ## _vset, const vtype_set*: T ## _ ## att_f ## _vset,\
vtype_dict*: T ## _ ## att_f ## _dict, const vtype_dict*: T ## _ ## att_f ## _dict,\
vtype_bool: T ## _ ## ins_f ## _boolean,\
vtype_uint8: T ## _ ## ins_f ## _uint8,\
vtype_uint16: T ## _ ## ins_f ## _uint16,\
vtype_uint32: T ## _ ## ins_f ## _uint32,\
vtype_uint64: T ## _ ## ins_f ## _uint64,\
vtype_int8: T ## _ ## ins_f ## _int8,\
vtype_int16: T ## _ ## ins_f ## _int16,\
vtype_int32: T ## _ ## ins_f ## _int32,\
vtype_int64: T ## _ ## ins_f ## _int64,\
vtype_float: T ## _ ## ins_f ## _float,\
vtype_double: T ## _ ## ins_f ## _double,\
vtype_ldouble: T ## _ ## ins_f ## _ldouble\
)
#define _LIBCDSB_GenericS(T, f, v) _Generic((v),\
void*: T ## _ ## f ## _cstring, const void*: T ## _ ## f ## _cstring,\
char*: T ## _ ## f ## _cstring, const char*: T ## _ ## f ## _cstring,\
vtype_string*: T ## _ ## f ## _string, const vtype_string*: T ## _ ## f ## _string,\
int: T ## _ ## f ## _char, unsigned int: T ## _ ## f ## _char,\
char: T ## _ ## f ## _char, unsigned char: T ## _ ## f ## _char,\
short: T ## _ ## f ## _char, unsigned short: T ## _ ## f ## _char\
)
#define _LIBCDSB_GenericS2(T, f, s, d) _Generic((s),\
void*: _LIBCDSB_GenericS(T, f ## _cstring, d), const void*: _LIBCDSB_GenericS(T, f ## _cstring, d),\
char*: _LIBCDSB_GenericS(T, f ## _cstring, d), const char*: _LIBCDSB_GenericS(T, f ## _cstring, d),\
vtype_string*: _LIBCDSB_GenericS(T, f ## _string, d), const vtype_string*: _LIBCDSB_GenericS(T, f ## _string, d),\
int: _LIBCDSB_GenericS(T, f ## _char, d), unsigned int: _LIBCDSB_GenericS(T, f ## _char, d),\
char: _LIBCDSB_GenericS(T, f ## _char, d), unsigned char: _LIBCDSB_GenericS(T, f ## _char, d),\
short: _LIBCDSB_GenericS(T, f ## _char, d), unsigned short: _LIBCDSB_GenericS(T, f ## _char, d)\
)
#endif /* LIBCDSB_CORE_GENERICS_H */

View File

@ -1,7 +1,6 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "__generics.h"
#include "vtype.h"
#ifndef LIBCDSB_ARRAY_H

View File

@ -1,12 +1,12 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#ifndef LIBCDSB_CORE_ATTRIBUTES_H
#define LIBCDSB_CORE_ATTRIBUTES_H
#ifndef LIBCDSB_BITS_ATTRIBUTES_H
#define LIBCDSB_BITS_ATTRIBUTES_H
#define Pure__ __attribute__ ((pure))
#define Always_inline__ __attribute__ ((always_inline))
#define Warn_unused_result__ __attribute__ ((warn_unused_result))
#define Nonnull__(...) __attribute__ ((nonnull (__VA_ARGS__)))
#endif /* LIBCDSB_CORE_ATTRIBUTES_H */
#endif /* LIBCDSB_BITS_ATTRIBUTES_H */

51
include/bits/__generics.h Normal file
View File

@ -0,0 +1,51 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#ifndef LIBCDSB_BITS_GENERICS_H
#define LIBCDSB_BITS_GENERICS_H
#define vtypeof(x) (vtype)(_Generic((x),\
const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\
const char**: VTYPE_STRING, char**: VTYPE_STRING,\
const vtype_string*: VTYPE_STRING, vtype_string*: VTYPE_STRING,\
const vtype_array*: VTYPE_ARRAY, vtype_array*: VTYPE_ARRAY,\
const vtype_list*: VTYPE_LIST, vtype_list*: VTYPE_LIST,\
const vtype_map*: VTYPE_MAP, vtype_map*: VTYPE_MAP,\
const vtype_set*: VTYPE_SET, vtype_set*: VTYPE_SET,\
const vtype_dict*: VTYPE_DICT, vtype_dict*: VTYPE_DICT,\
vtype_bool: VTYPE_BOOLEAN,\
vtype_uint8: VTYPE_UINT8,\
vtype_uint16: VTYPE_UINT16,\
vtype_uint32: VTYPE_UINT32,\
vtype_uint64: VTYPE_UINT64,\
vtype_int8: VTYPE_INT8,\
vtype_int16: VTYPE_INT16,\
vtype_int32: VTYPE_INT32,\
vtype_int64: VTYPE_INT64,\
vtype_float: VTYPE_FLOAT,\
vtype_double: VTYPE_DOUBLE,\
vtype_ldouble: VTYPE_LDOUBLE))
#define _LIBCDSB_vtypeof(x) vtypeof(_Generic((x), default: (x), const char*: &(x), char*: &(x)))
#define _LIBCDSB_value_pointer(x) _Generic((x), default: &(x),\
vtype_string*: (x), const vtype_string*: (x),\
vtype_array*: (x), const vtype_array*: (x),\
vtype_list*: (x), const vtype_list*: (x),\
vtype_map*: (x), const vtype_map*: (x),\
vtype_set*: (x), const vtype_set*: (x),\
vtype_dict*: (x), const vtype_dict*: (x))
#define _LIBCDSB_to_cstring(x) _Generic((x), default: _LIBCDSB_nothing,\
vtype_string*: _LIBCDSB_deref1, const vtype_string*: _LIBCDSB_deref1,\
int: libcdsb_char_to_cstring, unsigned int: libcdsb_char_to_cstring,\
char: libcdsb_char_to_cstring, unsigned char: libcdsb_char_to_cstring,\
short: libcdsb_char_to_cstring, unsigned short: libcdsb_char_to_cstring\
)(x)
inline const void* _LIBCDSB_nothing(const void* x) __attribute__((always_inline));
inline const void* _LIBCDSB_deref1 (const void* x) __attribute__((always_inline));
inline const void* _LIBCDSB_nothing(const void* x) { return x; }
inline const void* _LIBCDSB_deref1 (const void* x) { return *(void**)x; }
#endif /* LIBCDSB_BITS_GENERICS_H */

View File

@ -2,10 +2,12 @@
/* Copyright © 2022 Gregory Lirent */
#include <string.h>
#include "../__attributes.h"
#include "__attributes.h"
#ifndef LIBCDSB_EXTRA_CSTRING_H
#define LIBCDSB_EXTRA_CSTRING_H
#ifndef LIBCDSB_BITS_CSTRING_H
#define LIBCDSB_BITS_CSTRING_H
extern const char* libcdsb_char_to_cstring(int c) Warn_unused_result__;
extern size_t libcdsb_strlen (const char* s) Pure__ Warn_unused_result__ Nonnull__(1);
extern size_t libcdsb_strasciilen(const char* s) Pure__ Warn_unused_result__ Nonnull__(1);
@ -14,11 +16,4 @@ extern char* libcdsb_strdup (const char* s) Warn_unused_result__ Nonnu
extern char* libcdsb_strndup(const char* s, size_t n) Warn_unused_result__ Nonnull__(1);
extern void* libcdsb_memndup(const void* m, size_t n) Warn_unused_result__ Nonnull__(1);
#define strlen libcdsb_strlen
#define strasciilen libcdsb_strasciilen
#define strdup libcdsb_strdup
#define strndup libcdsb_strndup
#define memndup libcdsb_memndup
#endif /* LIBCDSB_EXTRA_CSTRING_H */
#endif /* LIBCDSB_BITS_CSTRING_H */

View File

@ -2,10 +2,10 @@
/* Copyright © 2022 Gregory Lirent */
#include <stddef.h>
#include "../__attributes.h"
#include "__attributes.h"
#ifndef LIBCDSB_EXTRA_MEMORY_H
#define LIBCDSB_EXTRA_MEMORY_H
#ifndef LIBCDSB_BITS_MEMORY_H
#define LIBCDSB_BITS_MEMORY_H
typedef struct libcdsb_stack_node {
struct libcdsb_stack_node* prev;
@ -25,16 +25,4 @@ 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
#define stack_push_many libcdsb_stack_push_many
#define stack_pop libcdsb_stack_pop
#define stack_flush libcdsb_stack_flush
#endif /* LIBCDSB_EXTRA_MEMORY_H */
#endif /* LIBCDSB_BITS_MEMORY_H */

View File

@ -1,7 +1,6 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "__generics.h"
#include "vtype.h"
#ifndef LIBCDSB_DICT_H

View File

@ -1,84 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../string.h"
#ifndef LIBCDSB_EXTRA_STRING_H
#define LIBCDSB_EXTRA_STRING_H
/*#####################################################################################################################*/
#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)
#define string_trim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg, 0)
#define string_ltrim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg, -1)
#define string_rtrim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg, 1)
extern size_t string_to_lower (vtype_string* x) Nonnull__(1);
extern size_t string_to_upper (vtype_string* x) Nonnull__(1);
extern size_t string_capitalize(vtype_string* x) Nonnull__(1);
extern size_t string_reverse (vtype_string* x) Nonnull__(1);
extern size_t string_align_center(vtype_string* x, size_t padsize, int padchr) Nonnull__(1);
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 void libcdsb_string_replace(vtype_string* x, char* dest, size_t dest_nmemb, const char* src, size_t nmemb) Nonnull__(1,2);
/*#####################################################################################################################*/
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);
extern void libcdsb_string_trim_char (vtype_string* x, int sc, int direction) Nonnull__(1);
inline size_t libcdsb_string_replace_r_string_string (vtype_string*restrict x, const vtype_string*restrict src, const vtype_string*restrict dest, size_t maxn) Nonnull__(1) Always_inline__;
inline size_t libcdsb_string_replace_r_string_cstring (vtype_string*restrict x, const vtype_string*restrict src, const char*restrict dest, size_t maxn) Nonnull__(1) Always_inline__;
inline size_t libcdsb_string_replace_r_string_char (vtype_string*restrict x, const vtype_string*restrict src, int dest, size_t maxn) Nonnull__(1) Always_inline__;
inline size_t libcdsb_string_replace_r_cstring_string (vtype_string*restrict x, const char*restrict src, const vtype_string*restrict dest, size_t maxn) Nonnull__(1) Always_inline__;
extern size_t libcdsb_string_replace_r_cstring_cstring(vtype_string*restrict x, const char*restrict src, const char*restrict dest, size_t maxn) Nonnull__(1);
extern size_t libcdsb_string_replace_r_cstring_char (vtype_string*restrict x, const char*restrict src, int dest, size_t maxn) Nonnull__(1);
inline size_t libcdsb_string_replace_r_char_string (vtype_string*restrict x, int src, const vtype_string*restrict dest, size_t maxn) Nonnull__(1) Always_inline__;
extern size_t libcdsb_string_replace_r_char_cstring (vtype_string*restrict x, int src, const char*restrict dest, size_t maxn) Nonnull__(1);
#define libcdsb_string_replace_r_char_char libcdsb_string_replace_char_char
/*#####################################################################################################################*/
inline vtype_array libcdsb_string_split_string(const vtype_string* x, const vtype_string* sep, size_t maxn) {
return string_split(x, sep->buffer, maxn);
}
inline void libcdsb_string_trim_string(vtype_string* x, const vtype_string* s, int direction) {
return libcdsb_string_trim_cstring (x, s->buffer, direction);
}
inline size_t libcdsb_string_replace_r_string_string (vtype_string*restrict x, const vtype_string*restrict src, const vtype_string*restrict dest, size_t maxn) {
return string_replace_r(x, src->buffer, dest->buffer, maxn);
}
inline size_t libcdsb_string_replace_r_string_cstring(vtype_string*restrict x, const vtype_string*restrict src, const char*restrict dest, size_t maxn) {
return string_replace_r(x, src->buffer, dest, maxn);
}
inline size_t libcdsb_string_replace_r_cstring_string(vtype_string*restrict x, const char*restrict src, const vtype_string*restrict dest, size_t maxn) {
return string_replace_r(x, src, dest->buffer, maxn);
}
inline size_t libcdsb_string_replace_r_string_char (vtype_string*restrict x, const vtype_string*restrict src, int dest, size_t maxn) {
return string_replace_r(x, src->buffer, dest, maxn);
}
inline size_t libcdsb_string_replace_r_char_string (vtype_string*restrict x, int src, const vtype_string*restrict dest, size_t maxn) {
return string_replace_r(x, src, dest->buffer, maxn);
}
#endif /* LIBCDSB_EXTRA_STRING_H */

View File

@ -1,12 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../vtype.h"
#ifndef LIBCDSB_EXTRA_VTYPE_H
#define LIBCDSB_EXTRA_VTYPE_H
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__;
#endif /* LIBCDSB_EXTRA_VTYPE_H */

View File

@ -1,7 +1,6 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "__generics.h"
#include "vtype.h"
#ifndef LIBCDSB_LIST_H

View File

@ -1,7 +1,6 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "__generics.h"
#include "vtype.h"
#ifndef LIBCDSB_MAP_H

View File

@ -1,7 +1,6 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "__generics.h"
#include "vtype.h"
#ifndef LIBCDSB_SET_H

View File

@ -5,7 +5,8 @@
#include <unistd.h>
#include <stdbool.h>
#include "__attributes.h"
#include "bits/cstring.h"
#include "bits/memory.h"
#ifndef LIBCDSB_VTYPE_H
#define LIBCDSB_VTYPE_H
@ -72,18 +73,23 @@ typedef struct libcdsb_list vtype_list;
typedef struct libcdsb_dict vtype_dict;
typedef struct libcdsb_string vtype_string;
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__;
/*#####################################################################################################################*/
extern size_t string_size (const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1);
extern size_t string_nmemb (const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1);
extern size_t array_nmemb (const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1);
extern size_t list_size (const vtype_list* x) Pure__ Warn_unused_result__ Nonnull__(1);
extern size_t map_size (const vtype_map* x) Pure__ Warn_unused_result__ Nonnull__(1);
extern size_t vset_size (const vtype_set* x) Pure__ Warn_unused_result__ Nonnull__(1);
inline size_t string_nmemb (const vtype_string* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1);
inline size_t array_size (const vtype_array* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1);
inline size_t dict_size (const vtype_dict* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1);
inline size_t dict_capacity(const vtype_dict* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1);
extern int string_case_compare(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2);
extern int string_compare (const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2);
extern int array_compare (const vtype_array* s0, const vtype_array* s1) Pure__ Warn_unused_result__ Nonnull__(1,2);
extern int list_compare (const vtype_list* s0, const vtype_list* s1) Pure__ Warn_unused_result__ Nonnull__(1,2);
@ -91,7 +97,7 @@ extern int map_compare (const vtype_map* s0, const vtype_map* s1) Pure__
extern int vset_compare (const vtype_set* s0, const vtype_set* s1) Pure__ Warn_unused_result__ Nonnull__(1,2);
extern int dict_compare (const vtype_dict* s0, const vtype_dict* s1) Pure__ Warn_unused_result__ Nonnull__(1,2);
extern vtype_string string_copy (const vtype_string* s) Pure__ Warn_unused_result__ Nonnull__(1);
inline vtype_string string_copy (const vtype_string* s) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1);
extern vtype_array array_copy (const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1);
extern vtype_list list_copy (const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1);
extern vtype_map map_copy (const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1);
@ -100,7 +106,7 @@ extern vtype_dict dict_copy (const vtype_dict* s) Pure__ Warn_unused_res
extern vtype_list dict_copy_keys(const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1);
#define map_copy_keys(s) vset_copy((vtype_set*)s)
extern vtype_string* string_duplicate (const vtype_string* s) Warn_unused_result__ Nonnull__(1);
inline vtype_string* string_duplicate (const vtype_string* s) Always_inline__ Warn_unused_result__ Nonnull__(1);
extern vtype_array* array_duplicate (const vtype_array* s) Warn_unused_result__ Nonnull__(1);
extern vtype_list* list_duplicate (const vtype_list* s) Warn_unused_result__ Nonnull__(1);
extern vtype_map* map_duplicate (const vtype_map* s) Warn_unused_result__ Nonnull__(1);
@ -109,7 +115,7 @@ extern vtype_dict* dict_duplicate (const vtype_dict* s) Warn_unused_resu
extern vtype_list* dict_duplicate_keys(const vtype_dict* s) Warn_unused_result__ Nonnull__(1);
#define map_duplicate_keys(s) vset_duplicate((vtype_set*)s)
extern void string_copy_init (vtype_string* x, const vtype_string* s) Nonnull__(1,2);
inline void string_copy_init (vtype_string* x, const vtype_string* s) Always_inline__ Nonnull__(1,2);
extern void array_copy_init (vtype_array* x, const vtype_array* s) Nonnull__(1,2);
extern void list_copy_init (vtype_list* x, const vtype_list* s) Nonnull__(1,2);
extern void map_copy_init (vtype_map* x, const vtype_map* s) Nonnull__(1,2);
@ -118,7 +124,7 @@ extern void dict_copy_init (vtype_dict* x, const vtype_dict* s) Nonnull__
extern void dict_init_keys (vtype_list* x, const vtype_dict* s) Nonnull__(1,2);
#define map_copy_init_keys(x, s) vset_duplicate(x, (vtype_set*)s)
extern void string_free(vtype_string* x);
inline void string_free(vtype_string* x) Always_inline__;
extern void array_free (vtype_array* x);
extern void list_free (vtype_list* x);
extern void map_free (vtype_map* x);
@ -137,5 +143,22 @@ extern vtype_hash dict_hash (const vtype_dict* s) Pure__ Warn_unused_result__
inline size_t array_size (const vtype_array* x) { return x->size; }
inline size_t dict_size (const vtype_dict* x) { return x->size; }
inline size_t dict_capacity(const vtype_dict* x) { return x->capacity; }
inline size_t string_nmemb (const vtype_string* x) { return (x->buffer) ? libcdsb_strlen(x->buffer) : 0; }
inline void string_free ( vtype_string* x) { libcdsb_free(x->buffer); x->buffer = 0; }
inline vtype_string string_copy(const vtype_string* s) {
vtype_string x = { .buffer = libcdsb_strdup(s->buffer) };
return x;
}
inline vtype_string* string_duplicate(const vtype_string* s) {
void** x = libcdsb_malloc(sizeof(*x));
*x = libcdsb_strdup(s->buffer);
return (void*)x;
}
inline void string_copy_init(vtype_string* x, const vtype_string* s) {
x->buffer = libcdsb_strdup(s->buffer);
}
#endif /* LIBCDSB_VTYPE_H */

View File

@ -1,7 +1,7 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../../include/__attributes.h"
#include "../../include/bits/__attributes.h"
#define pure__ Pure__
#define const__ __attribute__((const))

View File

@ -7,15 +7,11 @@
#include <stdlib.h>
#include "../../include/vtype.h"
#include "../../include/extra/memory.h"
#include "../../include/extra/cstring.h"
#include "../../include/extra/vtype.h"
#include "__attributes.h"
#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)
@ -38,7 +34,6 @@ extern const size_t LIBCDSB_VTYPE_SIZES[19];
#define abs(v) _Generic((v), ldbl_t: fabsl, dbl_t: fabs, fl_t: fabsf)(v)
#include "__attributes.h"
typedef vtype_uint8 u8_t;
typedef vtype_uint16 u16_t;
@ -64,20 +59,37 @@ typedef vtype_dict dict_t;
typedef vtype_hash hash_t;
extern const size_t LIBCDSB_VTYPE_SIZES[19];
extern int libcdsb_vtype_compare_values (const void* s0, vtype t0, const void* s1, vtype t1) pure__ wur__;
extern int libcdsb_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) pure__ wur__;
extern hash_t libcdsb_vtype_hash (const void* value, vtype type) pure__ wur__;
#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
#define stack_push_many libcdsb_stack_push_many
#define stack_pop libcdsb_stack_pop
#define stack_flush libcdsb_stack_flush
#define strlen libcdsb_strlen
#define strasciilen libcdsb_strasciilen
#define strdup libcdsb_strdup
#define strndup libcdsb_strndup
#define memndup libcdsb_memndup
#define vtype_stringify libcdsb_vtype_stringify
#define vtype_name libcdsb_vtype_name
#define vtype_compare libcdsb_vtype_compare_values
#define vtype_compare_eq libcdsb_vtype_compare_values_eq
#define vtype_hash libcdsb_vtype_hash
#define vtype_size(type) (LIBCDSB_VTYPE_SIZES[type])
#define vtypeof(x) (vtype)(_Generic((x),\
const void**: VTYPE_POINTER, void**: VTYPE_POINTER, const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\
const char**: VTYPE_STRING, char**: VTYPE_STRING, const char*: VTYPE_STRING, char*: VTYPE_STRING,\