Compare commits
3 Commits
30c141f587
...
d6436d0833
| Author | SHA1 | Date | |
|---|---|---|---|
| d6436d0833 | |||
| ee2b88a412 | |||
| dbe8924466 |
@ -25,7 +25,7 @@ Error* Error_create(const char* msg, bool is_msg_on_heap, ErrorCallPos p);
|
||||
void Error_free(Error* e);
|
||||
void Error_addCallPos(Error* e, ErrorCallPos p);
|
||||
str Error_toStr(Error* e);
|
||||
void Error_printAndExit(Error* e) __attribute__ ((__noreturn__));
|
||||
void Error_printAndExit(Error* e) ATTRIBUTE_NORETURN;
|
||||
|
||||
typedef struct Result_ {
|
||||
Error* error;
|
||||
@ -38,8 +38,13 @@ typedef struct Result_ {
|
||||
};
|
||||
} Result_;
|
||||
|
||||
#define Result(T) Result_
|
||||
|
||||
///Use this macro only to specify function return type.
|
||||
/// To declare variable, use ResultVar().
|
||||
/// Warning can be suppressed by IGNORE_RESULT
|
||||
#define Result(T) Result_ ATTRIBUTE_WARN_UNUSED_RESULT
|
||||
#define ResultVar(T) Result_
|
||||
///USAGE: IGNORE_RESULT trySomething();
|
||||
#define IGNORE_RESULT Result_ __ignored_##__LINE__ ATTRIBUTE_UNUSED =
|
||||
|
||||
#define RESULT_ERROR(MSG, IS_MSG_ON_HEAP) (Result_){ .error = Error_create(MSG, IS_MSG_ON_HEAP, ErrorCallPos_here()) }
|
||||
#define RESULT_ERROR_FMT(FORMAT, ARGS...) RESULT_ERROR(sprintf_malloc(4096, FORMAT ,##ARGS), true)
|
||||
|
||||
@ -64,6 +64,27 @@ typedef const char* cstr;
|
||||
/// @warning pointer can be null
|
||||
#define NULLABLE(NAME) NAME
|
||||
|
||||
#define ATTRIBUTE_PACKED \
|
||||
__attribute__((__packed__))
|
||||
|
||||
#define ATTRIBUTE_ALIGNED(BYTE_N) \
|
||||
__attribute__((aligned(BYTE_N)))
|
||||
|
||||
#define ATTRIBUTE_NORETURN \
|
||||
__attribute__ ((__noreturn__))
|
||||
|
||||
#define ATTRIBUTE_WARN_UNUSED_RESULT \
|
||||
__attribute__((warn_unused_result))
|
||||
|
||||
#define ATTRIBUTE_UNUSED \
|
||||
__attribute__ ((unused))
|
||||
|
||||
///@brief https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/Common-Function-Attributes.html#index-format-function-attribute
|
||||
///@param FMT_ARG_INDEX Index of format literal argument. First argument is 1.
|
||||
///@param VARIADIC_ARGS_INDEX Index of variadic arguments.
|
||||
#define ATTRIBUTE_CHECK_FORMAT_PRINTF(FMT_ARG_INDEX, VARIADIC_ARGS_INDEX) \
|
||||
__attribute__((__format__(__printf__, FMT_ARG_INDEX, VARIADIC_ARGS_INDEX)))
|
||||
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@ -5,5 +5,5 @@
|
||||
char* _strcat_malloc(size_t n, cstr str0, ...);
|
||||
char* _vstrcat_malloc(size_t n, cstr str0, va_list argv);
|
||||
|
||||
char* NULLABLE(sprintf_malloc)(size_t buffer_size, cstr format, ...) __attribute__((__format__(__printf__, 2, 3)));
|
||||
char* NULLABLE(sprintf_malloc)(size_t buffer_size, cstr format, ...) ATTRIBUTE_CHECK_FORMAT_PRINTF(2, 3);
|
||||
char* NULLABLE(vsprintf_malloc)(size_t buffer_size, cstr format, va_list argv);
|
||||
|
||||
@ -12,6 +12,8 @@ typedef u64 nsec_t;
|
||||
typedef u64 usec_t;
|
||||
/// miliseconds
|
||||
typedef u64 msec_t;
|
||||
/// seconds
|
||||
typedef u64 sec_t;
|
||||
|
||||
/// system time now in nanoseconds
|
||||
///@return u64 will overflow in 13 years
|
||||
|
||||
@ -27,7 +27,7 @@ str Error_toStr(Error* e){
|
||||
u32 len = List_len(&e->call_stack, ErrorCallPos);
|
||||
StringBuilder b = StringBuilder_alloc(e->msg.size + 80 * len);
|
||||
|
||||
StringBuilder_append_str(&b, STR("Error: "));
|
||||
StringBuilder_append_str(&b, STR("Catched Error: "));
|
||||
StringBuilder_append_str(&b, e->msg);
|
||||
for(u32 i = 0; i < len; i++){
|
||||
ErrorCallPos* ep = (ErrorCallPos*)e->call_stack.data + i;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user