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