aboutsummaryrefslogtreecommitdiff
path: root/src/gb
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-11-19 15:06:56 +0000
committergingerBill <bill@gingerbill.org>2017-11-19 15:06:56 +0000
commitcec9f7abfe55a70fc7e56960eda1870aee596cbb (patch)
treec29bf4b61514704af30a36d09967f8c0e57a04a4 /src/gb
parent284a9cd4c3f22be3b66b0a45406a0ea10fe508bf (diff)
Add `-debug` command (still in development)
Diffstat (limited to 'src/gb')
-rw-r--r--src/gb/gb.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/gb/gb.h b/src/gb/gb.h
index dfd701b8d..3e3f147dc 100644
--- a/src/gb/gb.h
+++ b/src/gb/gb.h
@@ -1515,6 +1515,7 @@ typedef struct gbStringHeader {
#define GB_STRING_HEADER(str) (cast(gbStringHeader *)(str) - 1)
+GB_DEF gbString gb_string_make_reserve (gbAllocator a, isize capacity);
GB_DEF gbString gb_string_make (gbAllocator a, char const *str);
GB_DEF gbString gb_string_make_length (gbAllocator a, void const *str, isize num_bytes);
GB_DEF void gb_string_free (gbString str);
@@ -6504,6 +6505,27 @@ gb_inline void gb__set_string_length (gbString str, isize len) { GB_STRING_HEAD
gb_inline void gb__set_string_capacity(gbString str, isize cap) { GB_STRING_HEADER(str)->capacity = cap; }
+gbString gb_string_make_reserve(gbAllocator a, isize capacity) {
+ isize header_size = gb_size_of(gbStringHeader);
+ void *ptr = gb_alloc(a, header_size + capacity + 1);
+
+ gbString str;
+ gbStringHeader *header;
+
+ if (ptr == NULL) return NULL;
+ gb_zero_size(ptr, header_size + capacity + 1);
+
+ str = cast(char *)ptr + header_size;
+ header = GB_STRING_HEADER(str);
+ header->allocator = a;
+ header->length = 0;
+ header->capacity = capacity;
+ str[capacity] = '\0';
+
+ return str;
+}
+
+
gb_inline gbString gb_string_make(gbAllocator a, char const *str) {
isize len = str ? gb_strlen(str) : 0;
return gb_string_make_length(a, str, len);
@@ -6516,8 +6538,8 @@ gbString gb_string_make_length(gbAllocator a, void const *init_str, isize num_by
gbString str;
gbStringHeader *header;
- if (!init_str) gb_zero_size(ptr, header_size + num_bytes + 1);
if (ptr == NULL) return NULL;
+ if (!init_str) gb_zero_size(ptr, header_size + num_bytes + 1);
str = cast(char *)ptr + header_size;
header = GB_STRING_HEADER(str);