Array_null and List_null

This commit is contained in:
Timerix 2025-11-13 02:29:55 +05:00
parent 77589878c1
commit 1775b27980
4 changed files with 7 additions and 3 deletions

View File

@ -14,9 +14,12 @@ typedef struct Array_ {
#define Array_construct(DATA, T, COUNT) Array_construct_size(DATA, (COUNT) * sizeof(T)) #define Array_construct(DATA, T, COUNT) Array_construct_size(DATA, (COUNT) * sizeof(T))
#define Array_construct_size(DATA, LEN) ((Array_){ .data = (DATA), .size = (LEN) }) #define Array_construct_size(DATA, LEN) ((Array_){ .data = (DATA), .size = (LEN) })
#define Array_alloc(T, COUNT) Array_alloc_size((COUNT) * sizeof(T)) #define Array_null Array_construct_size(NULL, 0)
#define Array_alloc(T, COUNT) Array_alloc_size((COUNT) * sizeof(T))
static inline Array_ Array_alloc_size(u32 size){ static inline Array_ Array_alloc_size(u32 size){
if(size == 0)
return Array_null;
return Array_construct_size(size > 0 ? malloc(size) : NULL, size); return Array_construct_size(size > 0 ? malloc(size) : NULL, size);
} }

View File

@ -15,6 +15,7 @@ typedef struct List_ {
static inline List_ List_construct_size(void* data_ptr, u32 occupied_size, u32 allocated_size) { static inline List_ List_construct_size(void* data_ptr, u32 occupied_size, u32 allocated_size) {
return (List_){ .data = data_ptr, .size = occupied_size, .allocated_size = allocated_size }; return (List_){ .data = data_ptr, .size = occupied_size, .allocated_size = allocated_size };
} }
#define List_null List_construct_size(NULL, 0, 0)
#define List_alloc(T, INITIAL_COUNT) List_alloc_size((INITIAL_COUNT) * sizeof(T)) #define List_alloc(T, INITIAL_COUNT) List_alloc_size((INITIAL_COUNT) * sizeof(T))
List_ List_alloc_size(u32 initial_size); List_ List_alloc_size(u32 initial_size);

View File

@ -122,7 +122,7 @@ typedef struct Result_ {
#define try_stderrcode(CALL) do {\ #define try_stderrcode(CALL) do {\
int r = CALL;\ int r = CALL;\
if(r != 0){\ if(r != 0){\
Return RESULT_ERROR(strerror(r), false);\ Return RESULT_ERROR_CODE(LIBC_ERRNO, r, strerror(r), false);\
}\ }\
} while(0) } while(0)

View File

@ -2,7 +2,7 @@
List_ List_alloc_size(u32 initial_size){ List_ List_alloc_size(u32 initial_size){
if(initial_size == 0) if(initial_size == 0)
return List_construct_size(NULL, 0, 0); return List_null;
u32 allocated_size = ALIGN_TO(initial_size, sizeof(void*)); u32 allocated_size = ALIGN_TO(initial_size, sizeof(void*));
return List_construct_size(malloc(allocated_size), 0, allocated_size); return List_construct_size(malloc(allocated_size), 0, allocated_size);
} }