From dbe892446672ef0c94bfd0e58c824561b99807e5 Mon Sep 17 00:00:00 2001 From: Timerix Date: Sat, 8 Nov 2025 20:54:41 +0500 Subject: [PATCH] compiler attributes were hidden behind ATTRIBUTE_* macros --- include/tlibc/errors.h | 2 +- include/tlibc/std.h | 15 +++++++++++++++ include/tlibc/string/cstr.h | 2 +- src/errors.c | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/tlibc/errors.h b/include/tlibc/errors.h index ef37432..81b744e 100755 --- a/include/tlibc/errors.h +++ b/include/tlibc/errors.h @@ -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; diff --git a/include/tlibc/std.h b/include/tlibc/std.h index 5d7c09f..2565afd 100755 --- a/include/tlibc/std.h +++ b/include/tlibc/std.h @@ -64,6 +64,21 @@ 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__)) + +///@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 } diff --git a/include/tlibc/string/cstr.h b/include/tlibc/string/cstr.h index f6a7429..1f62a5b 100755 --- a/include/tlibc/string/cstr.h +++ b/include/tlibc/string/cstr.h @@ -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); diff --git a/src/errors.c b/src/errors.c index 72ec4a3..96995e7 100755 --- a/src/errors.c +++ b/src/errors.c @@ -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;