5#if !defined(SKIP_INCLUDES)
9#if !defined _GNU_SOURCE
10 #error "the gnu source macro must be defined to use cookie io"
26#define INVARIANT_CHECK(self) \
28 DC_ASSUME(DC_WHEN((self)->buf, (self)->stream && (self)->capacity > 0)); \
29 DC_ASSUME(DC_WHEN((self)->capacity == 0, !(self)->buf)); \
30 DC_ASSUME(DC_WHEN((self)->buf, (self)->size_without_null + 1 <= (self)->capacity));
41 DC_PANIC(
"cookie set in write-only mode, but read was called.");
58 if (self->
buf != NULL) {
59 size_t const growth_factor = 2;
102 .size_without_null = 0,
104 .alloc_ref = alloc_ref,
111 if (self->stream == NULL) {
112 cookie_io_functions_t
const io = {
118 self->stream = fopencookie(self,
"w", io);
119 DC_ASSERT(self->stream != NULL,
"Failed to open stream for string builder, with error: %s",
126 setvbuf(self->stream, NULL, _IONBF, 0);
135 self->size_without_null = 0;
141 if (self->size_without_null == 0) {
152 char* buf = self->buf;
153 self->size_without_null = 0;
162 return self->size_without_null;
168 fclose(self->stream);
175#undef INVARIANT_CHECK
static DC_PUBLIC void deallocate(SELF *self, void *ptr, size_t size)
static DC_PUBLIC void reset(SELF *self)
static DC_PUBLIC void * allocate_uninit(SELF *self, size_t size)
static DC_PUBLIC void * reallocate(SELF *self, void *ptr, size_t old_size, size_t new_size)
#define INVARIANT_CHECK(self)
static DC_PUBLIC VALUE const * read(SELF const *self, INDEX index)
static DC_PUBLIC VALUE * write(SELF *self, INDEX index)
static DC_PUBLIC size_t size(SELF const *self)
static DC_PUBLIC ITEM * data(SELF *self)
static DC_PUBLIC void dc_memory_tracker_set(dc_memory_tracker_level level, dc_memory_tracker_capability cap, const volatile void *addr, size_t size)
@ DC_MEMORY_TRACKER_LVL_NONE
@ DC_MEMORY_TRACKER_CAP_READ_WRITE
#define DC_PANIC(str,...)
#define DC_ASSERT(expr,...)
#define DC_ASSUME(expr,...)
static size_t const additional_alloc_size
static int PRIV close(void *capture)
static DC_PUBLIC FILE * stream(SELF *self)
static int PRIV seek(void *capture, off_t *offset, int whence)
static DC_PUBLIC char * release_string(SELF *self)
static DC_PUBLIC size_t string_size(SELF *self)