diff options
| author | Syndamia <kamen@syndamia.com> | 2026-04-28 14:06:44 +0300 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2026-05-12 07:08:56 +0300 |
| commit | 0d249b1d47a7f84cfe5f09ad070d1affd26566da (patch) | |
| tree | f395f67eecb27daea3fc4a9ad8e59bf40f988984 /Types.h | |
| parent | 5c36b582ad60a569ed996fe188ed92ef6bd7fc5f (diff) | |
| download | foollib-0d249b1d47a7f84cfe5f09ad070d1affd26566da.tar foollib-0d249b1d47a7f84cfe5f09ad070d1affd26566da.tar.gz foollib-0d249b1d47a7f84cfe5f09ad070d1affd26566da.zip | |
feat!: Refactor using MemoryManager
The idea is to provide a universal memory management "API", through
which you allocate and deallocate. This allows our implementations (for
String and Vector) to be more generic.
It does also allow usage of different allocators depending on situation.
Diffstat (limited to 'Types.h')
| -rw-r--r-- | Types.h | 40 |
1 files changed, 39 insertions, 1 deletions
@@ -15,15 +15,53 @@ typedef uint_fast64_t u64; typedef size_t usize; typedef enum Result { + /* Generic */ R_Ok = 0, R_Err, - R_Invalid, + R_NotImplemented, + /* Values */ R_Uninitialized, + R_InvalidValue, R_OutOfBounds, + /* Functions */ + R_InvalidArgument, + R_NullArgument, + /* Memory */ + R_OutOfMemory, + /* Resources */ + R_NotFound, + R_PermissionDenied, + R_Unreachable, + R_Unavailable, + /* Other */ R_PRIVATE } Result; +#if defined(__has_warning) +# if __has_warning("-Wc99-designator") +# pragma clang diagnostic ignored "-Wc99-designator" +# endif +#endif + +const static char* Result_TO_STR[R_PRIVATE+1] = { + [R_Ok] = "Ok", + [R_Err] = "Error", + [R_NotImplemented] = "Not implemented", + [R_Uninitialized] = "Uninitialized", + [R_InvalidValue] = "Invalid value", + [R_OutOfBounds] = "Out of bounds", + [R_InvalidArgument] = "Invalid argument", + [R_NullArgument] = "NULL argument", + [R_OutOfMemory] = "Out of memory", + [R_NotFound] = "Not found", + [R_PermissionDenied] = "Permission denied", + [R_Unreachable] = "Not reachable", + [R_Unavailable] = "Not available", + [R_PRIVATE] = "Unknown", +}; + #define RETURN_NOTOK(x) { Result r = x; if (R_Ok != r) return r; } +#define PRINT_NOTOK(x) { Result r = x; if (R_Ok != r) fprintf(stderr, "%s:%d %s() Error: %s (%d)\n", __FILE__, __LINE__, __func__, Result_TO_STR[r], r); } #define B(x) ((x) * 8) #define KiB(x) ((x) * 1024) |
