5#if !defined(SKIP_INCLUDES)
9#if !defined _GNU_SOURCE
10 #error "_GNU_SOURCE must be defined (is in the src/derive-c CMakeLists.txt) to use cookie_io"
26#define INVARIANT_CHECK(self) \
28 DC_ASSUME((self)->alloc); \
29 DC_ASSUME(DC_WHEN((self)->buf, (self)->stream && (self)->capacity > 0)); \
30 DC_ASSUME(DC_WHEN((self)->capacity == 0, !(self)->buf)); \
31 DC_ASSUME(DC_WHEN((self)->buf, (self)->size_without_null + 1 <= (self)->capacity));
42 DC_PANIC(
"cookie set in write-only mode, but read was called.");
52 if (self->
buf != NULL) {
53 size_t const growth_factor = 2;
100 .size_without_null = 0,
110 if (self->stream == NULL) {
111 cookie_io_functions_t
const io = {
117 self->stream = fopencookie(self,
"w", io);
118 DC_ASSERT(self->stream != NULL,
"Failed to open stream for string builder, with error: %s",
125 setvbuf(self->stream, NULL, _IONBF, 0);
134 self->size_without_null = 0;
140 if (self->size_without_null == 0) {
149 char* buf = self->buf;
150 self->size_without_null = 0;
159 return self->size_without_null;
165 fclose(self->stream);
172#undef INVARIANT_CHECK
static void free(SELF *self, void *ptr)
static void * realloc(SELF *self, void *ptr, size_t size)
static void * malloc(SELF *self, size_t size)
static INDEX_TYPE size(SELF const *self)
#define INVARIANT_CHECK(self)
SLOT PRIV(block)[DC_ARENA_CHUNKED_BLOCK_SIZE(BLOCK_INDEX_BITS)]
static VALUE const * read(SELF const *self, INDEX index)
static VALUE * write(SELF *self, INDEX index)
static ITEM * data(SELF *self)
#define DC_ASSERT(expr,...)
#define DC_ASSUME(expr,...)
static char * release_string(SELF *self)
Disowns the current string, free/management with chosen allocator determined by user.
static size_t const additional_alloc_size
static int PRIV close(void *capture)
static size_t string_size(SELF *self)
static FILE * stream(SELF *self)
Opens a file for.
static int PRIV seek(void *capture, off_t *offset, int whence)
static void reset(SELF *self)
Resets the string, but keps the same stream pointer alive.