Compare commits
2 Commits
0d422cd7e5
...
08d45faa83
| Author | SHA1 | Date | |
|---|---|---|---|
| 08d45faa83 | |||
| af0931c727 |
@@ -27,12 +27,14 @@ static inline List(T) List_##T##_construct(T* data_ptr, u32 occupied_len, u32 ca
|
||||
\
|
||||
static inline List(T) List_##T##_alloc(u32 initial_capacity) { \
|
||||
List_ l = _List_alloc(initial_capacity, sizeof(T)); \
|
||||
return *(List(T)*)(void*)&l; \
|
||||
void* l_ptr = &l; \
|
||||
return *(List(T)*)l_ptr; \
|
||||
} \
|
||||
\
|
||||
static inline List(T) List_##T##_copy(const List(T)* src) { \
|
||||
List_ l = _List_copy((void*)src); \
|
||||
return *(List(T)*)(void*)&l; \
|
||||
void* l_ptr = &l; \
|
||||
return *(List(T)*)l_ptr; \
|
||||
} \
|
||||
\
|
||||
static inline void List_##T##_destroy(List(T)* self) { _List_destroy((void*)self); } \
|
||||
|
||||
@@ -26,7 +26,7 @@ typedef struct Error {
|
||||
List(ErrorCallPos) call_stack;
|
||||
} Error;
|
||||
|
||||
Error* Error_create(const char* msg, bool is_msg_on_heap, ErrorCallPos p,
|
||||
Error* Error_create(str msg, bool is_msg_on_heap, ErrorCallPos p,
|
||||
u16 error_code_page, u32 error_code);
|
||||
void Error_free(Error* e);
|
||||
void Error_addCallPos(Error* e, ErrorCallPos p);
|
||||
@@ -83,14 +83,16 @@ typedef struct Result_ {
|
||||
.u = 0 \
|
||||
}
|
||||
#define RESULT_ERROR_CODE_FMT(CODE_PAGE, CODE, FORMAT, ARGS...) \
|
||||
RESULT_ERROR_CODE(CODE_PAGE, CODE, sprintf_malloc(FORMAT ,##ARGS), true)
|
||||
RESULT_ERROR_CODE(CODE_PAGE, CODE, str_from_cstr(sprintf_malloc(FORMAT ,##ARGS)), true)
|
||||
#define RESULT_ERROR(MSG, IS_MSG_ON_HEAP) \
|
||||
RESULT_ERROR_CODE(NONE, 0, MSG, IS_MSG_ON_HEAP);
|
||||
#define RESULT_ERROR_LITERAL(MSG) \
|
||||
RESULT_ERROR(STR((MSG)), false)
|
||||
#define RESULT_ERROR_FMT(FORMAT, ARGS...) \
|
||||
RESULT_ERROR_CODE_FMT(NONE, 0, FORMAT ,##ARGS)
|
||||
|
||||
#define RESULT_ERROR_ERRNO() \
|
||||
RESULT_ERROR_CODE(LIBC_ERRNO, errno, strerror_malloc(errno), true)
|
||||
RESULT_ERROR_CODE(LIBC_ERRNO, errno, str_from_cstr(strerror_malloc(errno)), true)
|
||||
|
||||
#define RESULT_VOID (Result_){ .error = NULL, .u = 0 }
|
||||
#define RESULT_VALUE(FIELD, V) (Result_){ .error = NULL, .FIELD = V }
|
||||
@@ -139,7 +141,7 @@ typedef struct Result_ {
|
||||
#define _try_stderrcode(CALL, N) do {\
|
||||
int _rname(N) = CALL;\
|
||||
if(_rname(N) != 0){\
|
||||
Return RESULT_ERROR_CODE(LIBC_ERRNO, _rname(N), strerror_malloc(_rname(N)), true);\
|
||||
Return RESULT_ERROR_CODE(LIBC_ERRNO, _rname(N), str_from_cstr(strerror_malloc(_rname(N))), true);\
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
@@ -153,4 +155,4 @@ typedef struct Result_ {
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
#define try_assert(EXPR) if(!(EXPR)) { Return RESULT_ERROR(("assertion must be true: " #EXPR), false); }
|
||||
#define try_assert(EXPR) if(!(EXPR)) { Return RESULT_ERROR_LITERAL("assertion must be true: " #EXPR); }
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
#define ERRMSG_LENGTH 1024
|
||||
|
||||
Error* Error_create(const char* msg, bool is_msg_on_heap, ErrorCallPos p,
|
||||
Error* Error_create(str msg, bool is_msg_on_heap, ErrorCallPos p,
|
||||
u16 error_code_page, u32 error_code)
|
||||
{
|
||||
Error* e = (Error*)malloc(sizeof(Error));
|
||||
e->msg = str_construct((char*)(void*)msg, strlen(msg), true);
|
||||
e->msg = msg;
|
||||
e->is_msg_on_heap = is_msg_on_heap;
|
||||
e->error_code_page = error_code_page;
|
||||
e->error_code = error_code;
|
||||
|
||||
Reference in New Issue
Block a user