Compare commits
2 Commits
3034e4d186
...
1775b27980
| Author | SHA1 | Date | |
|---|---|---|---|
| 1775b27980 | |||
| 77589878c1 |
@@ -14,10 +14,13 @@ typedef struct Array_ {
|
||||
#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_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){
|
||||
return Array_construct_size(malloc(size), size);
|
||||
if(size == 0)
|
||||
return Array_null;
|
||||
return Array_construct_size(size > 0 ? malloc(size) : NULL, size);
|
||||
}
|
||||
|
||||
#define Array_realloc(SELF, T, COUNT) Array_realloc_size(SELF, (COUNT) * sizeof(T))
|
||||
|
||||
@@ -15,6 +15,7 @@ typedef struct List_ {
|
||||
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 };
|
||||
}
|
||||
#define List_null List_construct_size(NULL, 0, 0)
|
||||
|
||||
#define List_alloc(T, INITIAL_COUNT) List_alloc_size((INITIAL_COUNT) * sizeof(T))
|
||||
List_ List_alloc_size(u32 initial_size);
|
||||
|
||||
@@ -122,7 +122,7 @@ typedef struct Result_ {
|
||||
#define try_stderrcode(CALL) do {\
|
||||
int r = CALL;\
|
||||
if(r != 0){\
|
||||
Return RESULT_ERROR(strerror(r), false);\
|
||||
Return RESULT_ERROR_CODE(LIBC_ERRNO, r, strerror(r), false);\
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
List_ List_alloc_size(u32 initial_size){
|
||||
if(initial_size == 0)
|
||||
return List_construct_size(NULL, 0, 0);
|
||||
return List_null;
|
||||
u32 allocated_size = ALIGN_TO(initial_size, sizeof(void*));
|
||||
return List_construct_size(malloc(allocated_size), 0, allocated_size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user