15 yaml_malloc(size_t size);
18 yaml_realloc(void *ptr, size_t size);
24 yaml_strdup(const char *);
27 * Reader: Ensure that the buffer contains at least `length` characters.
31 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length);
34 * Scanner: Ensure that the token stack contains at least one token ready.
38 yaml_parser_fetch_more_tokens(yaml_parser_t *parser);
41 * The size of the raw buffer.
44 #define RAW_BUFFER_SIZE 16384
47 * The size of the buffer.
49 * It should be possible to decode the whole raw buffer.
52 #define BUFFER_SIZE (RAW_BUFFER_SIZE*3)
55 * The size of other stacks and queues.
58 #define INITIAL_STACK_SIZE 16
59 #define INITIAL_QUEUE_SIZE 16
60 #define INITIAL_STRING_SIZE 16
66 #define BUFFER_INIT(context,buffer,size) \
67 (((buffer).start = yaml_malloc(size)) ? \
68 ((buffer).last = (buffer).pointer = (buffer).start, \
69 (buffer).end = (buffer).start+(size), \
71 ((context)->error = YAML_MEMORY_ERROR, \
74 #define BUFFER_DEL(context,buffer) \
75 (yaml_free((buffer).start), \
76 (buffer).start = (buffer).pointer = (buffer).end = 0)
89 yaml_string_extend(yaml_char_t **start,
90 yaml_char_t **pointer, yaml_char_t **end);
94 yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
95 yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end);
97 #define NULL_STRING { NULL, NULL, NULL }
99 #define STRING_INIT(context,string,size) \
100 (((string).start = yaml_malloc(size)) ? \
101 ((string).pointer = (string).start, \
102 (string).end = (string).start+(size), \
103 memset((string).start, 0, (size)), \
105 ((context)->error = YAML_MEMORY_ERROR, \
108 #define STRING_DEL(context,string) \
109 (yaml_free((string).start), \
110 (string).start = (string).pointer = (string).end = 0)
112 #define STRING_EXTEND(context,string) \
113 (((string).pointer+5 < (string).end) \
114 || yaml_string_extend(&(string).start, \
115 &(string).pointer, &(string).end))
117 #define CLEAR(context,string) \
118 ((string).pointer = (string).start, \
119 memset((string).start, 0, (string).end-(string).start))
121 #define JOIN(context,string_a,string_b) \
122 ((yaml_string_join(&(string_a).start, &(string_a).pointer, \
123 &(string_a).end, &(string_b).start, \
124 &(string_b).pointer, &(string_b).end)) ? \
125 ((string_b).pointer = (string_b).start, \
127 ((context)->error = YAML_MEMORY_ERROR, \
131 * Stack and queue management.
135 yaml_stack_extend(void **start, void **top, void **end);
138 yaml_queue_extend(void **start, void **head, void **tail, void **end);
140 #define STACK_INIT(context,stack,size) \
141 (((stack).start = yaml_malloc((size)*sizeof(*(stack).start))) ? \
142 ((stack).top = (stack).start, \
143 (stack).end = (stack).start+(size), \
145 ((context)->error = YAML_MEMORY_ERROR, \
148 #define STACK_DEL(context,stack) \
149 (yaml_free((stack).start), \
150 (stack).start = (stack).top = (stack).end = 0)
152 #define STACK_EMPTY(context,stack) \
153 ((stack).start == (stack).top)
155 #define PUSH(context,stack,value) \
156 (((stack).top != (stack).end \
157 || yaml_stack_extend((void **)&(stack).start, \
158 (void **)&(stack).top, (void **)&(stack).end)) ? \
159 (*((stack).top++) = value, \
161 ((context)->error = YAML_MEMORY_ERROR, \
164 #define POP(context,stack) \
167 #define QUEUE_INIT(context,queue,size) \
168 (((queue).start = yaml_malloc((size)*sizeof(*(queue).start))) ? \
169 ((queue).head = (queue).tail = (queue).start, \
170 (queue).end = (queue).start+(size), \
172 ((context)->error = YAML_MEMORY_ERROR, \
175 #define QUEUE_DEL(context,queue) \
176 (yaml_free((queue).start), \
177 (queue).start = (queue).head = (queue).tail = (queue).end = 0)
179 #define QUEUE_EMPTY(context,queue) \
180 ((queue).head == (queue).tail)
182 #define ENQUEUE(context,queue,value) \
183 (((queue).tail != (queue).end \
184 || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
185 (void **)&(queue).tail, (void **)&(queue).end)) ? \
186 (*((queue).tail++) = value, \
188 ((context)->error = YAML_MEMORY_ERROR, \
191 #define DEQUEUE(context,queue) \
194 #define QUEUE_INSERT(context,queue,index,value) \
195 (((queue).tail != (queue).end \
196 || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \
197 (void **)&(queue).tail, (void **)&(queue).end)) ? \
198 (memmove((queue).head+(index)+1,(queue).head+(index), \
199 ((queue).tail-(queue).head-(index))*sizeof(*(queue).start)), \
200 *((queue).head+(index)) = value, \
203 ((context)->error = YAML_MEMORY_ERROR, \