From a01d4de1e2feda34a20bb8dd65ec76fef3c20d6b Mon Sep 17 00:00:00 2001 From: pommicket Date: Sun, 15 Oct 2023 15:23:58 -0400 Subject: use reference-counted strings for string settings this lets us remove the length limitations which were previously imposed --- util.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'util.h') diff --git a/util.h b/util.h index edbcbe3..1d60cf9 100644 --- a/util.h +++ b/util.h @@ -41,7 +41,26 @@ typedef struct { size_t len; } String32; +/// reference-counted string +typedef struct RcStr RcStr; +/// allocate new ref-counted string +/// +/// if `len == -1`, `s` is assumed to be null-terminated. otherwise, +/// at most `len` bytes are copied from `s`. +RcStr *rc_str_new(const char *s, i64 len); +/// increases the reference count of `str`. +/// +/// does nothing if `str` is `NULL`. +void rc_str_incref(RcStr *str); +/// decrease reference count of `*str` and set `*str` to `NULL`. +/// +/// this frees `*str` if the reference count hits 0. +/// +/// does nothing if `*str` is NULL. +void rc_str_decref(RcStr **str); +/// get rc string with default value if `s == NULL` +const char *rc_str(RcStr *s, const char *value_if_null); /// `isword` for 32-bit chars. bool is32_word(char32_t c); /// `isspace` for 32-bit chars. -- cgit v1.2.3