commit 0ca17073690e6ad9e5b1069a0e02f66b88d83506
parent 8900544bc321d13f4f9d16dae3e30ba5d1ab3b1d
Author: Jake Koroman <jake@jakekoroman.com>
Date: Tue, 28 Oct 2025 13:00:55 -0400
remove most jrk_die paths.
Most functions will never crash the program now. StringBuilder and da
functions can still cause crashes. I am okay with allowing these to
crash as I am okay with assuming mallocs/reallocs will never fail,
which isn't ideal.
Properly fixing this requires some major changes to the da_rerserve
functions as I cannot figure out a way to properly propagate errors out
of those macros. See the arena_da/sb macros on how I did it for those.
But the api isn't consistent. Some calls you can directly test against
the functions return value and others you have to manually check the
pointer after calling the macro. I wish I could figure out a better way
of doing this, but for now it will do.
Diffstat:
| M | jrk.h | | | 32 | ++++++++++++-------------------- |
1 file changed, 12 insertions(+), 20 deletions(-)
diff --git a/jrk.h b/jrk.h
@@ -1,22 +1,14 @@
/*
* TODO:
- * - remove assertions from here
- * nothing in here should crash the program.
- * jrk_die macros should always die, just don't call it here
- * remove JRK_NO_EXIT_ON_DIE, i dont think its elegant. it is
- * just a bandaid fix for the above issues.
- *
* - look at at the jrk_sv_chop_delim_loop stuff. there must
* must be a better way of handling things.
*
* NOTES:
- * To avoid the application from crashing when calling the die macros
- * you can define JRK_NO_EXIT_ON_DIE. This will convert all die macros
- * to log calls. It is now up to the caller to handle the errors properly.
- * Most functions that can fail will return a bool and will log themselves,
- * which should make error handling easy. Be aware that some will return a
- * negative int to indicate failure. These are normally functions that call
- * into POSIX and return sizes as to be conformant to those POSIX syscalls.
+ * - arena function failures will not crash the program but generic sb/da
+ * functions will. this isn't the most elegant but im ok with assuming
+ * mallocs will never fail and if they do you have bigger problems.
+ * however arena allocs can and will fail as they are sized by the user,
+ * so these shouldn't crash the program.
*/
#include <stdbool.h>
@@ -393,7 +385,7 @@ jrk_ecalloc(u64 nmemb, u64 size)
void *p;
if (!(p = calloc(nmemb, size)))
- jrk_ediev("jrk_ecalloc(%ld, %ld)", nmemb, size);
+ jrk_ediev("jrk_ecalloc(%ld, %ld): buy more ram lol", nmemb, size);
return p;
}
@@ -403,7 +395,7 @@ jrk_erealloc(void *ptr, u64 size)
void *p;
if (!(p = realloc(ptr, size)))
- jrk_ediev("jrk_erealloc(%p, %ld)", ptr, size);
+ jrk_ediev("jrk_erealloc(%p, %ld): buy more ram lol", ptr, size);
return p;
}
@@ -645,7 +637,7 @@ jrk_sb_fd_read_all(jrk_StringBuilder *sb, i32 fd)
u64 sz = jrk_fd_size(fd);
jrk_da_reserve(sb, sz);
if (read(fd, sb->items, sz) < 0) {
- jrk_ediev("jrk_sb_fd_read_all(%p, %d)", (void *)sb, fd);
+ jrk_errorv("jrk_sb_fd_read_all(%p, %d)", (void *)sb, fd);
return false;
}
@@ -659,7 +651,7 @@ jrk_sb_fd_write_all(jrk_StringBuilder *sb, i32 fd)
i64 result;
result = write(fd, (void *) sb->items, sb->count);
if (result < 0) {
- jrk_ediev("jrk_sb_fd_write_all(%p, %d)", (void *)sb, fd);
+ jrk_errorv("jrk_sb_fd_write_all(%p, %d)", (void *)sb, fd);
return -1;
}
@@ -699,7 +691,7 @@ jrk_fd_open_read(char *path)
i32 result = open(path, O_RDONLY);
if (result < 0) {
- jrk_ediev("jrk_fd_open_read(%s)", path);
+ jrk_errorv("jrk_fd_open_read(%s)", path);
return -1;
}
@@ -714,7 +706,7 @@ jrk_fd_open_write(char *path)
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (result < 0) {
- jrk_ediev("jrk_fd_open_write(%s)", path);
+ jrk_errorv("jrk_fd_open_write(%s)", path);
return -1;
}
@@ -729,7 +721,7 @@ jrk_fd_open_write_append(char *path)
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (result < 0) {
- jrk_ediev("jrk_fd_open_write_append(%s)", path);
+ jrk_errorv("jrk_fd_open_write_append(%s)", path);
return -1;
}