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