Go to the source code of this file.
|
| struct | SELF |
| | An allocator that prints to stdout when it allocates or frees memory. More...
|
|
| static ssize_t PRIV | read (void *capture, char *buf, size_t size) |
| static ssize_t PRIV | write (void *capture, const char *data, size_t size) |
| static int PRIV | seek (void *capture, off_t *offset, int whence) |
| static int PRIV | close (void *capture) |
| static SELF | new (ALLOC *alloc) |
| static FILE * | stream (SELF *self) |
| | Opens a file for.
|
| static void | reset (SELF *self) |
| | Resets the string, but keps the same stream pointer alive.
|
| static char const * | string (SELF const *self) |
| | Gets access to the null terminated string.
|
| static char * | release_string (SELF *self) |
| | Disowns the current string, free/management with chosen allocator determined by user.
|
| static size_t | string_size (SELF *self) |
| static void | delete (SELF *self) |
◆ INVARIANT_CHECK
| #define INVARIANT_CHECK |
( |
| self | ) |
|
Value:
DC_ASSUME((self)->alloc); \
DC_ASSUME(
DC_WHEN((self)->buf, (self)->size_without_null + 1 <= (self)->
capacity));
#define DC_WHEN(cond, expr)
#define DC_ASSUME(expr,...)
static FILE * stream(SELF *self)
Opens a file for.
Definition at line 26 of file template.h.
26#define INVARIANT_CHECK(self) \
27 DC_ASSUME(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));
◆ close()
| int PRIV close |
( |
void * | capture | ) |
|
|
static |
Definition at line 90 of file template.h.
90 {
93 return 0;
94}
#define INVARIANT_CHECK(self)
◆ delete()
| void delete |
( |
SELF * | self | ) |
|
|
static |
Definition at line 162 of file template.h.
162 {
166 }
169 }
170}
static void free(SELF *self, void *ptr)
◆ new()
Definition at line 96 of file template.h.
96 {
98 .stream = NULL,
99 .buf = NULL,
100 .size_without_null = 0,
101 .capacity = 0,
102 .alloc = alloc,
103 };
104}
◆ read()
| ssize_t PRIV read |
( |
void * | capture, |
|
|
char * | buf, |
|
|
size_t | size ) |
|
static |
Definition at line 33 of file template.h.
35 {
38
39 (void)buf;
41
42 DC_PANIC(
"cookie set in write-only mode, but read was called.");
43}
static INDEX_TYPE size(SELF const *self)
◆ release_string()
| char * release_string |
( |
SELF * | self | ) |
|
|
static |
Disowns the current string, free/management with chosen allocator determined by user.
Definition at line 147 of file template.h.
147 {
149 char* buf = self->
buf;
153
154 return buf;
155}
◆ reset()
| void reset |
( |
SELF * | self | ) |
|
|
static |
Resets the string, but keps the same stream pointer alive.
Definition at line 132 of file template.h.
◆ seek()
| int PRIV seek |
( |
void * | capture, |
|
|
off_t * | offset, |
|
|
int | whence ) |
|
static |
Definition at line 78 of file template.h.
80 {
83 (void)offset;
84 (void)whence;
85
86 errno = EPERM;
87 return -1;
88}
◆ stream()
| FILE * stream |
( |
SELF * | self | ) |
|
|
static |
Opens a file for.
- Examples
- complex/employees.c, container/arena/basic.c, container/map/decomposed.c, container/vector/dynamic.c, and utils/option.c.
Definition at line 107 of file template.h.
107 {
109
110 if (self->
stream == NULL) {
111 cookie_io_functions_t const io = {
116 };
117 self->
stream = fopencookie(self,
"w", io);
118 DC_ASSERT(self->
stream != NULL,
"Failed to open stream for string builder, with error: %s",
119 strerror(errno));
120
121
122
123
124
125 setvbuf(self->
stream, NULL, _IONBF, 0);
126 }
127
129}
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)
#define DC_ASSERT(expr,...)
static int PRIV close(void *capture)
static int PRIV seek(void *capture, off_t *offset, int whence)
◆ string()
| char const * string |
( |
SELF const * | self | ) |
|
|
static |
Gets access to the null terminated string.
Definition at line 138 of file template.h.
138 {
140 if (self->size_without_null == 0) {
141 return "";
142 }
143 return self->buf;
144}
◆ string_size()
| size_t string_size |
( |
SELF * | self | ) |
|
|
static |
◆ write()
| ssize_t PRIV write |
( |
void * | capture, |
|
|
const char * | data, |
|
|
size_t | size ) |
|
static |
Definition at line 45 of file template.h.
45 {
48
50 size_t new_capacity;
51 char* new_buf;
52 if (self->
buf != NULL) {
53 size_t const growth_factor = 2;
54 new_capacity =
57 } else {
61 }
62
63 if (!new_buf) {
64 errno = ENOMEM;
65 return -1;
66 }
67
70 }
71
76}
static void * realloc(SELF *self, void *ptr, size_t size)
static void * malloc(SELF *self, size_t size)
static ITEM * data(SELF *self)
static size_t const additional_alloc_size
◆ additional_alloc_size
| size_t const additional_alloc_size = 32 |
|
static |