Refactor headers
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#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_BITS_ATTRIBUTES_H */
|
||||
@@ -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 */
|
||||
@@ -0,0 +1,19 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#include <string.h>
|
||||
#include "__attributes.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);
|
||||
|
||||
extern char* libcdsb_strdup (const char* s) Warn_unused_result__ Nonnull__(1);
|
||||
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);
|
||||
|
||||
#endif /* LIBCDSB_BITS_CSTRING_H */
|
||||
@@ -0,0 +1,28 @@
|
||||
/* This software is licensed by the MIT License, see LICENSE file */
|
||||
/* Copyright © 2022 Gregory Lirent */
|
||||
|
||||
#include <stddef.h>
|
||||
#include "__attributes.h"
|
||||
|
||||
#ifndef LIBCDSB_BITS_MEMORY_H
|
||||
#define LIBCDSB_BITS_MEMORY_H
|
||||
|
||||
typedef struct libcdsb_stack_node {
|
||||
struct libcdsb_stack_node* prev;
|
||||
void* value;
|
||||
} stack_t;
|
||||
|
||||
extern void libcdsb_stack_init (stack_t* stack) Nonnull__(1);
|
||||
extern void libcdsb_stack_push (stack_t* stack, void* value) Nonnull__(1);
|
||||
extern void libcdsb_stack_push_many(stack_t* stack, size_t n, ...) Nonnull__(1);
|
||||
extern void* libcdsb_stack_pop (stack_t* stack) Nonnull__(1);
|
||||
extern void libcdsb_stack_flush (stack_t* stack) Nonnull__(1);
|
||||
|
||||
extern void* libcdsb_aalloc (size_t a, size_t n) Warn_unused_result__;
|
||||
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);
|
||||
|
||||
#endif /* LIBCDSB_BITS_MEMORY_H */
|
||||
Reference in New Issue
Block a user