1 #define YAML_VERSION_MAJOR 0 2 #define YAML_VERSION_MINOR 2 3 #define YAML_VERSION_PATCH 5 4 #define YAML_VERSION_STRING "0.2.5" 5 6 #include <yaml.h> 7 8 #include <assert.h> 9 #include <limits.h> 10 #include <stddef.h> 11 12 /* 13 * Memory management. 14 */ 15 16 YAML_DECLARE(void *) 17 yaml_malloc(size_t size); 18 19 YAML_DECLARE(void *) 20 yaml_realloc(void *ptr, size_t size); 21 22 YAML_DECLARE(void) 23 yaml_free(void *ptr); 24 25 YAML_DECLARE(yaml_char_t *) 26 yaml_strdup(const yaml_char_t *); 27 28 /* 29 * Reader: Ensure that the buffer contains at least `length` characters. 30 */ 31 32 YAML_DECLARE(int) 33 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); 34 35 /* 36 * Scanner: Ensure that the token stack contains at least one token ready. 37 */ 38 39 YAML_DECLARE(int) 40 yaml_parser_fetch_more_tokens(yaml_parser_t *parser); 41 42 /* 43 * The size of the input raw buffer. 44 */ 45 46 #define INPUT_RAW_BUFFER_SIZE 16384 47 48 /* 49 * The size of the input buffer. 50 * 51 * It should be possible to decode the whole raw buffer. 52 */ 53 54 #define INPUT_BUFFER_SIZE (INPUT_RAW_BUFFER_SIZE*3) 55 56 /* 57 * The size of the output buffer. 58 */ 59 60 #define OUTPUT_BUFFER_SIZE 16384 61 62 /* 63 * The size of the output raw buffer. 64 * 65 * It should be possible to encode the whole output buffer. 66 */ 67 68 #define OUTPUT_RAW_BUFFER_SIZE (OUTPUT_BUFFER_SIZE*2+2) 69 70 /* 71 * The maximum size of a YAML input file. 72 * This used to be PTRDIFF_MAX, but that's not entirely portable 73 * because stdint.h isn't available on all platforms. 74 * It is not entirely clear why this isn't the maximum value 75 * that can fit into the parser->offset field. 76 */ 77 78 #define MAX_FILE_SIZE (~(size_t)0 / 2) 79 80 81 /* 82 * The size of other stacks and queues. 83 */ 84 85 #define INITIAL_STACK_SIZE 16 86 #define INITIAL_QUEUE_SIZE 16 87 #define INITIAL_STRING_SIZE 16 88 89 /* 90 * Buffer management. 91 */ 92 93 #define BUFFER_INIT(context,buffer,size) \ 94 (((buffer).start = (yaml_char_t *)yaml_malloc(size)) ? \ 95 ((buffer).last = (buffer).pointer = (buffer).start, \ 96 (buffer).end = (buffer).start+(size), \ 97 1) : \ 98 ((context)->error = YAML_MEMORY_ERROR, \ 99 0)) 100 101 #define BUFFER_DEL(context,buffer) \ 102 (yaml_free((buffer).start), \ 103 (buffer).start = (buffer).pointer = (buffer).end = 0) 104 105 /* 106 * String management. 107 */ 108 109 typedef struct { 110 yaml_char_t *start; 111 yaml_char_t *end; 112 yaml_char_t *pointer; 113 } yaml_string_t; 114 115 YAML_DECLARE(int) 116 yaml_string_extend(yaml_char_t **start, 117 yaml_char_t **pointer, yaml_char_t **end); 118 119 YAML_DECLARE(int) 120 yaml_string_join( 121 yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end, 122 yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end); 123 124 #define NULL_STRING { NULL, NULL, NULL } 125 126 #define STRING(string,length) { (string), (string)+(length), (string) } 127 128 #define STRING_ASSIGN(value,string,length) \ 129 ((value).start = (string), \ 130 (value).end = (string)+(length), \ 131 (value).pointer = (string)) 132 133 #define STRING_INIT(context,string,size) \ 134 (((string).start = YAML_MALLOC(size)) ? \ 135 ((string).pointer = (string).start, \ 136 (string).end = (string).start+(size), \ 137 memset((string).start, 0, (size)), \ 138 1) : \ 139 ((context)->error = YAML_MEMORY_ERROR, \ 140 0)) 141 142 #define STRING_DEL(context,string) \ 143 (yaml_free((string).start), \ 144 (string).start = (string).pointer = (string).end = 0) 145 146 #define STRING_EXTEND(context,string) \ 147 ((((string).pointer+5 < (string).end) \ 148 || yaml_string_extend(&(string).start, \ 149 &(string).pointer, &(string).end)) ? \ 150 1 : \ 151 ((context)->error = YAML_MEMORY_ERROR, \ 152 0)) 153 154 #define CLEAR(context,string) \ 155 ((string).pointer = (string).start, \ 156 memset((string).start, 0, (string).end-(string).start)) 157 158 #define JOIN(context,string_a,string_b) \ 159 ((yaml_string_join(&(string_a).start, &(string_a).pointer, \ 160 &(string_a).end, &(string_b).start, \ 161 &(string_b).pointer, &(string_b).end)) ? \ 162 ((string_b).pointer = (string_b).start, \ 163 1) : \ 164 ((context)->error = YAML_MEMORY_ERROR, \ 165 0)) 166 167 /* 168 * String check operations. 169 */ 170 171 /* 172 * Check the octet at the specified position. 173 */ 174 175 #define CHECK_AT(string,octet,offset) \ 176 ((string).pointer[offset] == (yaml_char_t)(octet)) 177 178 /* 179 * Check the current octet in the buffer. 180 */ 181 182 #define CHECK(string,octet) (CHECK_AT((string),(octet),0)) 183 184 /* 185 * Check if the character at the specified position is an alphabetical 186 * character, a digit, '_', or '-'. 187 */ 188 189 #define IS_ALPHA_AT(string,offset) \ 190 (((string).pointer[offset] >= (yaml_char_t) '0' && \ 191 (string).pointer[offset] <= (yaml_char_t) '9') || \ 192 ((string).pointer[offset] >= (yaml_char_t) 'A' && \ 193 (string).pointer[offset] <= (yaml_char_t) 'Z') || \ 194 ((string).pointer[offset] >= (yaml_char_t) 'a' && \ 195 (string).pointer[offset] <= (yaml_char_t) 'z') || \ 196 (string).pointer[offset] == '_' || \ 197 (string).pointer[offset] == '-') 198 199 #define IS_ALPHA(string) IS_ALPHA_AT((string),0) 200 201 /* 202 * Check if the character at the specified position is a digit. 203 */ 204 205 #define IS_DIGIT_AT(string,offset) \ 206 (((string).pointer[offset] >= (yaml_char_t) '0' && \ 207 (string).pointer[offset] <= (yaml_char_t) '9')) 208 209 #define IS_DIGIT(string) IS_DIGIT_AT((string),0) 210 211 /* 212 * Get the value of a digit. 213 */ 214 215 #define AS_DIGIT_AT(string,offset) \ 216 ((string).pointer[offset] - (yaml_char_t) '0') 217 218 #define AS_DIGIT(string) AS_DIGIT_AT((string),0) 219 220 /* 221 * Check if the character at the specified position is a hex-digit. 222 */ 223 224 #define IS_HEX_AT(string,offset) \ 225 (((string).pointer[offset] >= (yaml_char_t) '0' && \ 226 (string).pointer[offset] <= (yaml_char_t) '9') || \ 227 ((string).pointer[offset] >= (yaml_char_t) 'A' && \ 228 (string).pointer[offset] <= (yaml_char_t) 'F') || \ 229 ((string).pointer[offset] >= (yaml_char_t) 'a' && \ 230 (string).pointer[offset] <= (yaml_char_t) 'f')) 231 232 #define IS_HEX(string) IS_HEX_AT((string),0) 233 234 /* 235 * Get the value of a hex-digit. 236 */ 237 238 #define AS_HEX_AT(string,offset) \ 239 (((string).pointer[offset] >= (yaml_char_t) 'A' && \ 240 (string).pointer[offset] <= (yaml_char_t) 'F') ? \ 241 ((string).pointer[offset] - (yaml_char_t) 'A' + 10) : \ 242 ((string).pointer[offset] >= (yaml_char_t) 'a' && \ 243 (string).pointer[offset] <= (yaml_char_t) 'f') ? \ 244 ((string).pointer[offset] - (yaml_char_t) 'a' + 10) : \ 245 ((string).pointer[offset] - (yaml_char_t) '0')) 246 247 #define AS_HEX(string) AS_HEX_AT((string),0) 248 249 /* 250 * Check if the character is ASCII. 251 */ 252 253 #define IS_ASCII_AT(string,offset) \ 254 ((string).pointer[offset] <= (yaml_char_t) '\x7F') 255 256 #define IS_ASCII(string) IS_ASCII_AT((string),0) 257 258 /* 259 * Check if the character can be printed unescaped. 260 */ 261 262 #define IS_PRINTABLE_AT(string,offset) \ 263 (((string).pointer[offset] == 0x0A) /* . == #x0A */ \ 264 || ((string).pointer[offset] >= 0x20 /* #x20 <= . <= #x7E */ \ 265 && (string).pointer[offset] <= 0x7E) \ 266 || ((string).pointer[offset] == 0xC2 /* #0xA0 <= . <= #xD7FF */ \ 267 && (string).pointer[offset+1] >= 0xA0) \ 268 || ((string).pointer[offset] > 0xC2 \ 269 && (string).pointer[offset] < 0xED) \ 270 || ((string).pointer[offset] == 0xED \ 271 && (string).pointer[offset+1] < 0xA0) \ 272 || ((string).pointer[offset] == 0xEE) \ 273 || ((string).pointer[offset] == 0xEF /* #xE000 <= . <= #xFFFD */ \ 274 && !((string).pointer[offset+1] == 0xBB /* && . != #xFEFF */ \ 275 && (string).pointer[offset+2] == 0xBF) \ 276 && !((string).pointer[offset+1] == 0xBF \ 277 && ((string).pointer[offset+2] == 0xBE \ 278 || (string).pointer[offset+2] == 0xBF)))) 279 280 #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string),0) 281 282 /* 283 * Check if the character at the specified position is NUL. 284 */ 285 286 #define IS_Z_AT(string,offset) CHECK_AT((string),'\0',(offset)) 287 288 #define IS_Z(string) IS_Z_AT((string),0) 289 290 /* 291 * Check if the character at the specified position is BOM. 292 */ 293 294 #define IS_BOM_AT(string,offset) \ 295 (CHECK_AT((string),'\xEF',(offset)) \ 296 && CHECK_AT((string),'\xBB',(offset)+1) \ 297 && CHECK_AT((string),'\xBF',(offset)+2)) /* BOM (#xFEFF) */ 298 299 #define IS_BOM(string) IS_BOM_AT(string,0) 300 301 /* 302 * Check if the character at the specified position is space. 303 */ 304 305 #define IS_SPACE_AT(string,offset) CHECK_AT((string),' ',(offset)) 306 307 #define IS_SPACE(string) IS_SPACE_AT((string),0) 308 309 /* 310 * Check if the character at the specified position is tab. 311 */ 312 313 #define IS_TAB_AT(string,offset) CHECK_AT((string),'\t',(offset)) 314 315 #define IS_TAB(string) IS_TAB_AT((string),0) 316 317 /* 318 * Check if the character at the specified position is blank (space or tab). 319 */ 320 321 #define IS_BLANK_AT(string,offset) \ 322 (IS_SPACE_AT((string),(offset)) || IS_TAB_AT((string),(offset))) 323 324 #define IS_BLANK(string) IS_BLANK_AT((string),0) 325 326 /* 327 * Check if the character at the specified position is a line break. 328 */ 329 330 #define IS_BREAK_AT(string,offset) \ 331 (CHECK_AT((string),'\r',(offset)) /* CR (#xD)*/ \ 332 || CHECK_AT((string),'\n',(offset)) /* LF (#xA) */ \ 333 || (CHECK_AT((string),'\xC2',(offset)) \ 334 && CHECK_AT((string),'\x85',(offset)+1)) /* NEL (#x85) */ \ 335 || (CHECK_AT((string),'\xE2',(offset)) \ 336 && CHECK_AT((string),'\x80',(offset)+1) \ 337 && CHECK_AT((string),'\xA8',(offset)+2)) /* LS (#x2028) */ \ 338 || (CHECK_AT((string),'\xE2',(offset)) \ 339 && CHECK_AT((string),'\x80',(offset)+1) \ 340 && CHECK_AT((string),'\xA9',(offset)+2))) /* PS (#x2029) */ 341 342 #define IS_BREAK(string) IS_BREAK_AT((string),0) 343 344 #define IS_CRLF_AT(string,offset) \ 345 (CHECK_AT((string),'\r',(offset)) && CHECK_AT((string),'\n',(offset)+1)) 346 347 #define IS_CRLF(string) IS_CRLF_AT((string),0) 348 349 /* 350 * Check if the character is a line break or NUL. 351 */ 352 353 #define IS_BREAKZ_AT(string,offset) \ 354 (IS_BREAK_AT((string),(offset)) || IS_Z_AT((string),(offset))) 355 356 #define IS_BREAKZ(string) IS_BREAKZ_AT((string),0) 357 358 /* 359 * Check if the character is a line break, space, or NUL. 360 */ 361 362 #define IS_SPACEZ_AT(string,offset) \ 363 (IS_SPACE_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset))) 364 365 #define IS_SPACEZ(string) IS_SPACEZ_AT((string),0) 366 367 /* 368 * Check if the character is a line break, space, tab, or NUL. 369 */ 370 371 #define IS_BLANKZ_AT(string,offset) \ 372 (IS_BLANK_AT((string),(offset)) || IS_BREAKZ_AT((string),(offset))) 373 374 #define IS_BLANKZ(string) IS_BLANKZ_AT((string),0) 375 376 /* 377 * Determine the width of the character. 378 */ 379 380 #define WIDTH_AT(string,offset) \ 381 (((string).pointer[offset] & 0x80) == 0x00 ? 1 : \ 382 ((string).pointer[offset] & 0xE0) == 0xC0 ? 2 : \ 383 ((string).pointer[offset] & 0xF0) == 0xE0 ? 3 : \ 384 ((string).pointer[offset] & 0xF8) == 0xF0 ? 4 : 0) 385 386 #define WIDTH(string) WIDTH_AT((string),0) 387 388 /* 389 * Move the string pointer to the next character. 390 */ 391 392 #define MOVE(string) ((string).pointer += WIDTH((string))) 393 394 /* 395 * Copy a character and move the pointers of both strings. 396 */ 397 398 #define COPY(string_a,string_b) \ 399 ((*(string_b).pointer & 0x80) == 0x00 ? \ 400 (*((string_a).pointer++) = *((string_b).pointer++)) : \ 401 (*(string_b).pointer & 0xE0) == 0xC0 ? \ 402 (*((string_a).pointer++) = *((string_b).pointer++), \ 403 *((string_a).pointer++) = *((string_b).pointer++)) : \ 404 (*(string_b).pointer & 0xF0) == 0xE0 ? \ 405 (*((string_a).pointer++) = *((string_b).pointer++), \ 406 *((string_a).pointer++) = *((string_b).pointer++), \ 407 *((string_a).pointer++) = *((string_b).pointer++)) : \ 408 (*(string_b).pointer & 0xF8) == 0xF0 ? \ 409 (*((string_a).pointer++) = *((string_b).pointer++), \ 410 *((string_a).pointer++) = *((string_b).pointer++), \ 411 *((string_a).pointer++) = *((string_b).pointer++), \ 412 *((string_a).pointer++) = *((string_b).pointer++)) : 0) 413 414 /* 415 * Stack and queue management. 416 */ 417 418 YAML_DECLARE(int) 419 yaml_stack_extend(void **start, void **top, void **end); 420 421 YAML_DECLARE(int) 422 yaml_queue_extend(void **start, void **head, void **tail, void **end); 423 424 #define STACK_INIT(context,stack,type) \ 425 (((stack).start = (type)yaml_malloc(INITIAL_STACK_SIZE*sizeof(*(stack).start))) ? \ 426 ((stack).top = (stack).start, \ 427 (stack).end = (stack).start+INITIAL_STACK_SIZE, \ 428 1) : \ 429 ((context)->error = YAML_MEMORY_ERROR, \ 430 0)) 431 432 #define STACK_DEL(context,stack) \ 433 (yaml_free((stack).start), \ 434 (stack).start = (stack).top = (stack).end = 0) 435 436 #define STACK_EMPTY(context,stack) \ 437 ((stack).start == (stack).top) 438 439 #define STACK_LIMIT(context,stack,size) \ 440 ((stack).top - (stack).start < (size) ? \ 441 1 : \ 442 ((context)->error = YAML_MEMORY_ERROR, \ 443 0)) 444 445 #define PUSH(context,stack,value) \ 446 (((stack).top != (stack).end \ 447 || yaml_stack_extend((void **)&(stack).start, \ 448 (void **)&(stack).top, (void **)&(stack).end)) ? \ 449 (*((stack).top++) = value, \ 450 1) : \ 451 ((context)->error = YAML_MEMORY_ERROR, \ 452 0)) 453 454 #define POP(context,stack) \ 455 (*(--(stack).top)) 456 457 #define QUEUE_INIT(context,queue,size,type) \ 458 (((queue).start = (type)yaml_malloc((size)*sizeof(*(queue).start))) ? \ 459 ((queue).head = (queue).tail = (queue).start, \ 460 (queue).end = (queue).start+(size), \ 461 1) : \ 462 ((context)->error = YAML_MEMORY_ERROR, \ 463 0)) 464 465 #define QUEUE_DEL(context,queue) \ 466 (yaml_free((queue).start), \ 467 (queue).start = (queue).head = (queue).tail = (queue).end = 0) 468 469 #define QUEUE_EMPTY(context,queue) \ 470 ((queue).head == (queue).tail) 471 472 #define ENQUEUE(context,queue,value) \ 473 (((queue).tail != (queue).end \ 474 || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \ 475 (void **)&(queue).tail, (void **)&(queue).end)) ? \ 476 (*((queue).tail++) = value, \ 477 1) : \ 478 ((context)->error = YAML_MEMORY_ERROR, \ 479 0)) 480 481 #define DEQUEUE(context,queue) \ 482 (*((queue).head++)) 483 484 #define QUEUE_INSERT(context,queue,index,value) \ 485 (((queue).tail != (queue).end \ 486 || yaml_queue_extend((void **)&(queue).start, (void **)&(queue).head, \ 487 (void **)&(queue).tail, (void **)&(queue).end)) ? \ 488 (memmove((queue).head+(index)+1,(queue).head+(index), \ 489 ((queue).tail-(queue).head-(index))*sizeof(*(queue).start)), \ 490 *((queue).head+(index)) = value, \ 491 (queue).tail++, \ 492 1) : \ 493 ((context)->error = YAML_MEMORY_ERROR, \ 494 0)) 495 496 /* 497 * Token initializers. 498 */ 499 500 #define TOKEN_INIT(token,token_type,token_start_mark,token_end_mark) \ 501 (memset(&(token), 0, sizeof(yaml_token_t)), \ 502 (token).type = (token_type), \ 503 (token).start_mark = (token_start_mark), \ 504 (token).end_mark = (token_end_mark)) 505 506 #define STREAM_START_TOKEN_INIT(token,token_encoding,start_mark,end_mark) \ 507 (TOKEN_INIT((token),YAML_STREAM_START_TOKEN,(start_mark),(end_mark)), \ 508 (token).data.stream_start.encoding = (token_encoding)) 509 510 #define STREAM_END_TOKEN_INIT(token,start_mark,end_mark) \ 511 (TOKEN_INIT((token),YAML_STREAM_END_TOKEN,(start_mark),(end_mark))) 512 513 #define ALIAS_TOKEN_INIT(token,token_value,start_mark,end_mark) \ 514 (TOKEN_INIT((token),YAML_ALIAS_TOKEN,(start_mark),(end_mark)), \ 515 (token).data.alias.value = (token_value)) 516 517 #define ANCHOR_TOKEN_INIT(token,token_value,start_mark,end_mark) \ 518 (TOKEN_INIT((token),YAML_ANCHOR_TOKEN,(start_mark),(end_mark)), \ 519 (token).data.anchor.value = (token_value)) 520 521 #define TAG_TOKEN_INIT(token,token_handle,token_suffix,start_mark,end_mark) \ 522 (TOKEN_INIT((token),YAML_TAG_TOKEN,(start_mark),(end_mark)), \ 523 (token).data.tag.handle = (token_handle), \ 524 (token).data.tag.suffix = (token_suffix)) 525 526 #define SCALAR_TOKEN_INIT(token,token_value,token_length,token_style,start_mark,end_mark) \ 527 (TOKEN_INIT((token),YAML_SCALAR_TOKEN,(start_mark),(end_mark)), \ 528 (token).data.scalar.value = (token_value), \ 529 (token).data.scalar.length = (token_length), \ 530 (token).data.scalar.style = (token_style)) 531 532 #define VERSION_DIRECTIVE_TOKEN_INIT(token,token_major,token_minor,start_mark,end_mark) \ 533 (TOKEN_INIT((token),YAML_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \ 534 (token).data.version_directive.major = (token_major), \ 535 (token).data.version_directive.minor = (token_minor)) 536 537 #define TAG_DIRECTIVE_TOKEN_INIT(token,token_handle,token_prefix,start_mark,end_mark) \ 538 (TOKEN_INIT((token),YAML_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \ 539 (token).data.tag_directive.handle = (token_handle), \ 540 (token).data.tag_directive.prefix = (token_prefix)) 541 542 /* 543 * Event initializers. 544 */ 545 546 #define EVENT_INIT(event,event_type,event_start_mark,event_end_mark) \ 547 (memset(&(event), 0, sizeof(yaml_event_t)), \ 548 (event).type = (event_type), \ 549 (event).start_mark = (event_start_mark), \ 550 (event).end_mark = (event_end_mark)) 551 552 #define STREAM_START_EVENT_INIT(event,event_encoding,start_mark,end_mark) \ 553 (EVENT_INIT((event),YAML_STREAM_START_EVENT,(start_mark),(end_mark)), \ 554 (event).data.stream_start.encoding = (event_encoding)) 555 556 #define STREAM_END_EVENT_INIT(event,start_mark,end_mark) \ 557 (EVENT_INIT((event),YAML_STREAM_END_EVENT,(start_mark),(end_mark))) 558 559 #define DOCUMENT_START_EVENT_INIT(event,event_version_directive, \ 560 event_tag_directives_start,event_tag_directives_end,event_implicit,start_mark,end_mark) \ 561 (EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)), \ 562 (event).data.document_start.version_directive = (event_version_directive), \ 563 (event).data.document_start.tag_directives.start = (event_tag_directives_start), \ 564 (event).data.document_start.tag_directives.end = (event_tag_directives_end), \ 565 (event).data.document_start.implicit = (event_implicit)) 566 567 #define DOCUMENT_END_EVENT_INIT(event,event_implicit,start_mark,end_mark) \ 568 (EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)), \ 569 (event).data.document_end.implicit = (event_implicit)) 570 571 #define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark) \ 572 (EVENT_INIT((event),YAML_ALIAS_EVENT,(start_mark),(end_mark)), \ 573 (event).data.alias.anchor = (event_anchor)) 574 575 #define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value,event_length, \ 576 event_plain_implicit, event_quoted_implicit,event_style,start_mark,end_mark) \ 577 (EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)), \ 578 (event).data.scalar.anchor = (event_anchor), \ 579 (event).data.scalar.tag = (event_tag), \ 580 (event).data.scalar.value = (event_value), \ 581 (event).data.scalar.length = (event_length), \ 582 (event).data.scalar.plain_implicit = (event_plain_implicit), \ 583 (event).data.scalar.quoted_implicit = (event_quoted_implicit), \ 584 (event).data.scalar.style = (event_style)) 585 586 #define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag, \ 587 event_implicit,event_style,start_mark,end_mark) \ 588 (EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)), \ 589 (event).data.sequence_start.anchor = (event_anchor), \ 590 (event).data.sequence_start.tag = (event_tag), \ 591 (event).data.sequence_start.implicit = (event_implicit), \ 592 (event).data.sequence_start.style = (event_style)) 593 594 #define SEQUENCE_END_EVENT_INIT(event,start_mark,end_mark) \ 595 (EVENT_INIT((event),YAML_SEQUENCE_END_EVENT,(start_mark),(end_mark))) 596 597 #define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag, \ 598 event_implicit,event_style,start_mark,end_mark) \ 599 (EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)), \ 600 (event).data.mapping_start.anchor = (event_anchor), \ 601 (event).data.mapping_start.tag = (event_tag), \ 602 (event).data.mapping_start.implicit = (event_implicit), \ 603 (event).data.mapping_start.style = (event_style)) 604 605 #define MAPPING_END_EVENT_INIT(event,start_mark,end_mark) \ 606 (EVENT_INIT((event),YAML_MAPPING_END_EVENT,(start_mark),(end_mark))) 607 608 /* 609 * Document initializer. 610 */ 611 612 #define DOCUMENT_INIT(document,document_nodes_start,document_nodes_end, \ 613 document_version_directive,document_tag_directives_start, \ 614 document_tag_directives_end,document_start_implicit, \ 615 document_end_implicit,document_start_mark,document_end_mark) \ 616 (memset(&(document), 0, sizeof(yaml_document_t)), \ 617 (document).nodes.start = (document_nodes_start), \ 618 (document).nodes.end = (document_nodes_end), \ 619 (document).nodes.top = (document_nodes_start), \ 620 (document).version_directive = (document_version_directive), \ 621 (document).tag_directives.start = (document_tag_directives_start), \ 622 (document).tag_directives.end = (document_tag_directives_end), \ 623 (document).start_implicit = (document_start_implicit), \ 624 (document).end_implicit = (document_end_implicit), \ 625 (document).start_mark = (document_start_mark), \ 626 (document).end_mark = (document_end_mark)) 627 628 /* 629 * Node initializers. 630 */ 631 632 #define NODE_INIT(node,node_type,node_tag,node_start_mark,node_end_mark) \ 633 (memset(&(node), 0, sizeof(yaml_node_t)), \ 634 (node).type = (node_type), \ 635 (node).tag = (node_tag), \ 636 (node).start_mark = (node_start_mark), \ 637 (node).end_mark = (node_end_mark)) 638 639 #define SCALAR_NODE_INIT(node,node_tag,node_value,node_length, \ 640 node_style,start_mark,end_mark) \ 641 (NODE_INIT((node),YAML_SCALAR_NODE,(node_tag),(start_mark),(end_mark)), \ 642 (node).data.scalar.value = (node_value), \ 643 (node).data.scalar.length = (node_length), \ 644 (node).data.scalar.style = (node_style)) 645 646 #define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end, \ 647 node_style,start_mark,end_mark) \ 648 (NODE_INIT((node),YAML_SEQUENCE_NODE,(node_tag),(start_mark),(end_mark)), \ 649 (node).data.sequence.items.start = (node_items_start), \ 650 (node).data.sequence.items.end = (node_items_end), \ 651 (node).data.sequence.items.top = (node_items_start), \ 652 (node).data.sequence.style = (node_style)) 653 654 #define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end, \ 655 node_style,start_mark,end_mark) \ 656 (NODE_INIT((node),YAML_MAPPING_NODE,(node_tag),(start_mark),(end_mark)), \ 657 (node).data.mapping.pairs.start = (node_pairs_start), \ 658 (node).data.mapping.pairs.end = (node_pairs_end), \ 659 (node).data.mapping.pairs.top = (node_pairs_start), \ 660 (node).data.mapping.style = (node_style)) 661 662 /* Strict C compiler warning helpers */ 663 664 #if defined(__clang__) || defined(__GNUC__) 665 # define HASATTRIBUTE_UNUSED 666 #endif 667 #ifdef HASATTRIBUTE_UNUSED 668 # define __attribute__unused__ __attribute__((__unused__)) 669 #else 670 # define __attribute__unused__ 671 #endif 672 673 /* Shim arguments are arguments that must be included in your function, 674 * but serve no purpose inside. Silence compiler warnings. */ 675 #define SHIM(a) /*@unused@*/ a __attribute__unused__ 676 677 /* UNUSED_PARAM() marks a shim argument in the body to silence compiler warnings */ 678 #ifdef __clang__ 679 # define UNUSED_PARAM(a) (void)(a); 680 #else 681 # define UNUSED_PARAM(a) /*@-noeffect*/if (0) (void)(a)/*@=noeffect*/; 682 #endif 683 684 #define YAML_MALLOC_STATIC(type) (type*)yaml_malloc(sizeof(type)) 685 #define YAML_MALLOC(size) (yaml_char_t *)yaml_malloc(size) 686