1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
use crate::{
externs::{memcpy, memset, strlen},
internal::yaml_check_utf8,
libc,
memory::{yaml_free, yaml_malloc, yaml_strdup},
ops::ForceAdd as _,
success::{Success, FAIL, OK},
yaml::{size_t, yaml_char_t},
PointerExt, YamlAliasEvent, YamlAliasToken, YamlAnchorToken,
YamlAnyEncoding, YamlBreakT, YamlEmitterStateT, YamlEmitterT,
YamlEncodingT, YamlEventT,
YamlEventTypeT::{
YamlDocumentStartEvent, YamlScalarEvent, YamlStreamEndEvent,
},
YamlMappingEndEvent, YamlMappingStartEvent, YamlMappingStyleT,
YamlMarkT, YamlParserT, YamlReadHandlerT, YamlScalarStyleT,
YamlScalarToken, YamlSequenceEndEvent, YamlSequenceStartEvent,
YamlSequenceStyleT, YamlStreamStartEvent, YamlTagDirectiveT,
YamlTagDirectiveToken, YamlTagToken, YamlTokenT, YamlWriteHandlerT,
};
use core::{
mem::size_of,
ptr::{self, addr_of_mut},
};
const OUTPUT_BUFFER_SIZE: usize = 16384;
const OUTPUT_RAW_BUFFER_SIZE: usize = OUTPUT_BUFFER_SIZE * 2 + 2;
unsafe fn yaml_string_read_handler(
data: *mut libc::c_void,
buffer: *mut libc::c_uchar,
mut size: size_t,
size_read: *mut size_t,
) -> libc::c_int {
let parser: *mut YamlParserT = data as *mut YamlParserT;
if (*parser).input.string.current == (*parser).input.string.end {
*size_read = 0_u64;
return 1;
}
if size
> (*parser)
.input
.string
.end
.c_offset_from((*parser).input.string.current)
as size_t
{
size = (*parser)
.input
.string
.end
.c_offset_from((*parser).input.string.current)
as size_t;
}
let _ = memcpy(
buffer as *mut libc::c_void,
(*parser).input.string.current as *const libc::c_void,
size,
);
let fresh80 = addr_of_mut!((*parser).input.string.current);
*fresh80 = (*fresh80).wrapping_offset(size as isize);
*size_read = size;
1
}
/// Set a string input.
///
/// This function sets the input source for the parser to a string buffer.
/// Note that the `input` pointer must be valid while the `parser` object
/// exists. The application is responsible for destroying `input` after
/// destroying the `parser`.
///
/// # Safety
///
/// - `parser` must be a valid, non-null pointer to a properly initialized `YamlParserT` struct.
/// - The `YamlParserT` struct must not have an input handler already set.
/// - `input` must be a valid, non-null pointer to a null-terminated string buffer.
/// - The `input` string buffer must remain valid and unmodified until the `parser` object is destroyed.
/// - The `YamlParserT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_parser_set_input_string(
parser: *mut YamlParserT,
input: *const libc::c_uchar,
size: size_t,
) {
assert!(!parser.is_null());
assert!((*parser).read_handler.is_none());
assert!(!input.is_null());
(*parser).read_handler = Some(yaml_string_read_handler);
(*parser).read_handler_data = parser as *mut libc::c_void;
(*parser).input.string.start = input;
(*parser).input.string.current = input;
(*parser).input.string.end = input.wrapping_offset(size as isize);
}
/// Set a generic input handler.
///
/// This function sets a custom input handler for the parser.
///
/// # Safety
///
/// - `parser` must be a valid, non-null pointer to a properly initialized `YamlParserT` struct.
/// - The `YamlParserT` struct must not have an input handler already set.
/// - `handler` must be a valid function pointer that follows the signature of `YamlReadHandlerT`.
/// - `data` must be a valid pointer that will be passed to the `handler` function.
/// - The `YamlParserT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_parser_set_input(
parser: *mut YamlParserT,
handler: YamlReadHandlerT,
data: *mut libc::c_void,
) {
__assert!(!parser.is_null());
__assert!(((*parser).read_handler).is_none());
let fresh89 = addr_of_mut!((*parser).read_handler);
*fresh89 = Some(handler);
let fresh90 = addr_of_mut!((*parser).read_handler_data);
*fresh90 = data;
}
/// Set the source encoding.
///
/// This function sets the expected encoding of the input source for the parser.
///
/// # Safety
///
/// - `parser` must be a valid, non-null pointer to a properly initialized `YamlParserT` struct.
/// - The `YamlParserT` struct must not have an encoding already set, or the encoding must be `YamlAnyEncoding`.
/// - The `YamlParserT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_parser_set_encoding(
parser: *mut YamlParserT,
encoding: YamlEncodingT,
) {
__assert!(!parser.is_null());
__assert!((*parser).encoding == YamlAnyEncoding);
(*parser).encoding = encoding;
}
/// Initialize an emitter.
///
/// This function creates a new emitter object. An application is responsible
/// for destroying the object using the yaml_emitter_delete() function.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to an uninitialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct must be properly aligned and have the expected memory layout.
/// - The caller is responsible for properly destroying the emitter object using `yaml_emitter_delete`.
///
pub unsafe fn yaml_emitter_initialize(
emitter: *mut YamlEmitterT,
) -> Success {
__assert!(!emitter.is_null());
let _ = memset(
emitter as *mut libc::c_void,
0,
size_of::<YamlEmitterT>() as libc::c_ulong,
);
BUFFER_INIT!((*emitter).buffer, OUTPUT_BUFFER_SIZE);
BUFFER_INIT!((*emitter).raw_buffer, OUTPUT_RAW_BUFFER_SIZE);
STACK_INIT!((*emitter).states, YamlEmitterStateT);
QUEUE_INIT!((*emitter).events, YamlEventT);
STACK_INIT!((*emitter).indents, libc::c_int);
STACK_INIT!((*emitter).tag_directives, YamlTagDirectiveT);
OK
}
/// Destroy an emitter.
///
/// This function frees all memory associated with an emitter object, including
/// any dynamically allocated buffers, events, and other data structures.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to a properly initialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct and its associated data structures must have been properly initialized and their memory allocated correctly.
/// - The `YamlEmitterT` struct and its associated data structures must be properly aligned and have the expected memory layout.
/// - After calling this function, the `emitter` pointer should be considered invalid and should not be used again.
///
pub unsafe fn yaml_emitter_delete(emitter: *mut YamlEmitterT) {
__assert!(!emitter.is_null());
BUFFER_DEL!((*emitter).buffer);
BUFFER_DEL!((*emitter).raw_buffer);
STACK_DEL!((*emitter).states);
while !QUEUE_EMPTY!((*emitter).events) {
yaml_event_delete(addr_of_mut!(DEQUEUE!((*emitter).events)));
}
QUEUE_DEL!((*emitter).events);
STACK_DEL!((*emitter).indents);
while !STACK_EMPTY!((*emitter).tag_directives) {
let tag_directive = POP!((*emitter).tag_directives);
yaml_free(tag_directive.handle as *mut libc::c_void);
yaml_free(tag_directive.prefix as *mut libc::c_void);
}
STACK_DEL!((*emitter).tag_directives);
yaml_free((*emitter).anchors as *mut libc::c_void);
let _ = memset(
emitter as *mut libc::c_void,
0,
size_of::<YamlEmitterT>() as libc::c_ulong,
);
}
unsafe fn yaml_string_write_handler(
data: *mut libc::c_void,
buffer: *mut libc::c_uchar,
size: size_t,
) -> libc::c_int {
let emitter: *mut YamlEmitterT = data as *mut YamlEmitterT;
if (*emitter)
.output
.string
.size
.wrapping_sub(*(*emitter).output.string.size_written)
< size
{
let _ =
memcpy(
(*emitter).output.string.buffer.wrapping_offset(
*(*emitter).output.string.size_written as isize,
) as *mut libc::c_void,
buffer as *const libc::c_void,
(*emitter).output.string.size.wrapping_sub(
*(*emitter).output.string.size_written,
),
);
*(*emitter).output.string.size_written =
(*emitter).output.string.size;
return 0;
}
let _ = memcpy(
(*emitter).output.string.buffer.wrapping_offset(
*(*emitter).output.string.size_written as isize,
) as *mut libc::c_void,
buffer as *const libc::c_void,
size,
);
let fresh153 =
addr_of_mut!((*(*emitter).output.string.size_written));
*fresh153 = (*fresh153).wrapping_add(size);
1
}
/// Set a string output.
///
/// This function sets the output destination for the emitter to a string buffer.
/// The emitter will write the output characters to the `output` buffer of the
/// specified `size`. The emitter will set `size_written` to the number of written
/// bytes. If the buffer is smaller than required, the emitter produces the
/// YAML_write_ERROR error.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to a properly initialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct must not have an output handler already set.
/// - `output` must be a valid, non-null pointer to a writeable buffer of size `size`.
/// - `size_written` must be a valid, non-null pointer to a `size_t` variable.
/// - The `output` buffer must remain valid and unmodified until the emitter is destroyed or the output is reset.
/// - The `YamlEmitterT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_emitter_set_output_string(
emitter: *mut YamlEmitterT,
output: *mut libc::c_uchar,
size: size_t,
size_written: *mut size_t,
) {
assert!(!emitter.is_null());
assert!((*emitter).write_handler.is_none());
assert!(!output.is_null());
(*emitter).write_handler = Some(yaml_string_write_handler);
(*emitter).write_handler_data = emitter as *mut libc::c_void;
(*emitter).output.string.buffer = output;
(*emitter).output.string.size = size;
*size_written = 0;
}
/// Set a generic output handler.
///
/// This function sets a custom output handler for the emitter.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to a properly initialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct must not have an output handler already set.
/// - `handler` must be a valid function pointer that follows the signature of `YamlWriteHandlerT`.
/// - `data` must be a valid pointer that will be passed to the `handler` function.
/// - The `YamlEmitterT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_emitter_set_output(
emitter: *mut YamlEmitterT,
handler: YamlWriteHandlerT,
data: *mut libc::c_void,
) {
__assert!(!emitter.is_null());
__assert!(((*emitter).write_handler).is_none());
let fresh161 = addr_of_mut!((*emitter).write_handler);
*fresh161 = Some(handler);
let fresh162 = addr_of_mut!((*emitter).write_handler_data);
*fresh162 = data;
}
/// Set the output encoding.
///
/// This function sets the encoding to be used for the output by the emitter.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to a properly initialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct must not have an encoding already set, or the encoding must be `YamlAnyEncoding`.
/// - The `YamlEmitterT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_emitter_set_encoding(
emitter: *mut YamlEmitterT,
encoding: YamlEncodingT,
) {
__assert!(!emitter.is_null());
__assert!((*emitter).encoding == YamlAnyEncoding);
(*emitter).encoding = encoding;
}
/// Set if the output should be in the "canonical" format as in the YAML
/// specification.
///
/// This function sets whether the emitter should produce output in the canonical
/// format, as defined by the YAML specification.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to a properly initialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_emitter_set_canonical(
emitter: *mut YamlEmitterT,
canonical: bool,
) {
__assert!(!emitter.is_null());
(*emitter).canonical = canonical;
}
/// Set the indentation increment.
///
/// This function sets the indentation increment to be used by the emitter when
/// emitting indented content.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to a properly initialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_emitter_set_indent(
emitter: *mut YamlEmitterT,
indent: libc::c_int,
) {
__assert!(!emitter.is_null());
(*emitter).best_indent =
if 1 < indent && indent < 10 { indent } else { 2 };
}
/// Set the preferred line width. -1 means unlimited.
///
/// This function sets the preferred line width for the emitter's output.
/// A value of -1 means that the line width is unlimited.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to a properly initialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_emitter_set_width(
emitter: *mut YamlEmitterT,
width: libc::c_int,
) {
__assert!(!emitter.is_null());
(*emitter).best_width = if width >= 0 { width } else { -1 };
}
/// Set if unescaped non-ASCII characters are allowed.
///
/// This function sets whether the emitter should allow unescaped non-ASCII
/// characters in its output.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to a properly initialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_emitter_set_unicode(
emitter: *mut YamlEmitterT,
unicode: bool,
) {
__assert!(!emitter.is_null());
(*emitter).unicode = unicode;
}
/// Set the preferred line break.
///
/// This function sets the preferred line break character to be used by the emitter.
///
/// # Safety
///
/// - `emitter` must be a valid, non-null pointer to a properly initialized `YamlEmitterT` struct.
/// - The `YamlEmitterT` struct and its associated data structures must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_emitter_set_break(
emitter: *mut YamlEmitterT,
line_break: YamlBreakT,
) {
__assert!(!emitter.is_null());
(*emitter).line_break = line_break;
}
/// Free any memory allocated for a token object.
///
/// This function frees the dynamically allocated memory associated with a `YamlTokenT` struct,
/// such as strings for tag directives, aliases, anchors, tags, and scalar values.
///
/// # Safety
///
/// - `token` must be a valid, non-null pointer to a `YamlTokenT` struct.
/// - The `YamlTokenT` struct must have been properly initialized and its memory allocated correctly.
/// - The `YamlTokenT` struct must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_token_delete(token: *mut YamlTokenT) {
__assert!(!token.is_null());
match (*token).type_ {
YamlTagDirectiveToken => {
yaml_free(
(*token).data.tag_directive.handle as *mut libc::c_void,
);
yaml_free(
(*token).data.tag_directive.prefix as *mut libc::c_void,
);
}
YamlAliasToken => {
yaml_free((*token).data.alias.value as *mut libc::c_void);
}
YamlAnchorToken => {
yaml_free((*token).data.anchor.value as *mut libc::c_void);
}
YamlTagToken => {
yaml_free((*token).data.tag.handle as *mut libc::c_void);
yaml_free((*token).data.tag.suffix as *mut libc::c_void);
}
YamlScalarToken => {
yaml_free((*token).data.scalar.value as *mut libc::c_void);
}
_ => {}
}
let _ = memset(
token as *mut libc::c_void,
0,
size_of::<YamlTokenT>() as libc::c_ulong,
);
}
/// Create the STREAM-START event.
///
/// This function initializes a `YamlEventT` struct with the type `YamlStreamStartEvent`.
/// It is used to signal the start of a YAML stream being emitted.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct that can be safely written to.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_stream_start_event_initialize(
event: *mut YamlEventT,
encoding: YamlEncodingT,
) -> Success {
let mark = YamlMarkT {
index: 0_u64,
line: 0_u64,
column: 0_u64,
};
__assert!(!event.is_null());
let _ = memset(
event as *mut libc::c_void,
0,
size_of::<YamlEventT>() as libc::c_ulong,
);
(*event).type_ = YamlStreamStartEvent;
(*event).start_mark = mark;
(*event).end_mark = mark;
(*event).data.stream_start.encoding = encoding;
OK
}
/// Create the STREAM-END event.
///
/// This function initializes a `YamlEventT` struct with the type `YamlStreamEndEvent`.
/// It is used to signal the end of a YAML stream being emitted.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct that can be safely written to.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_stream_end_event_initialize(
event: *mut YamlEventT,
) -> Success {
let mark = YamlMarkT {
index: 0_u64,
line: 0_u64,
column: 0_u64,
};
__assert!(!event.is_null());
let _ = memset(
event as *mut libc::c_void,
0,
size_of::<YamlEventT>() as libc::c_ulong,
);
(*event).type_ = YamlStreamEndEvent;
(*event).start_mark = mark;
(*event).end_mark = mark;
OK
}
/// Create an ALIAS event.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct that can be safely written to.
/// - `anchor` must be a valid, non-null pointer to a null-terminated UTF-8 string.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
/// - The caller is responsible for freeing any dynamically allocated memory associated with the event using `yaml_event_delete`.
///
pub unsafe fn yaml_alias_event_initialize(
event: *mut YamlEventT,
anchor: *const yaml_char_t,
) -> Success {
let mark = YamlMarkT {
index: 0_u64,
line: 0_u64,
column: 0_u64,
};
__assert!(!event.is_null());
__assert!(!anchor.is_null());
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char)).fail
{
return FAIL;
}
let anchor_copy: *mut yaml_char_t = yaml_strdup(anchor);
if anchor_copy.is_null() {
return FAIL;
}
let _ = memset(
event as *mut libc::c_void,
0,
size_of::<YamlEventT>() as libc::c_ulong,
);
(*event).type_ = YamlAliasEvent;
(*event).start_mark = mark;
(*event).end_mark = mark;
let fresh167 = addr_of_mut!((*event).data.alias.anchor);
*fresh167 = anchor_copy;
OK
}
/// Create a SCALAR event.
///
/// The `style` argument may be ignored by the emitter.
///
/// Either the `tag` attribute or one of the `plain_implicit` and
/// `quoted_implicit` flags must be set.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct that can be safely written to.
/// - `data.value` must be a valid, non-null pointer to a null-terminated UTF-8 string.
/// - `data.anchor`, if not null, must be a valid pointer to a null-terminated UTF-8 string.
/// - `data.tag`, if not null, must be a valid pointer to a null-terminated UTF-8 string.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
/// - The caller is responsible for freeing any dynamically allocated memory associated with the event using `yaml_event_delete`.
///
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct ScalarEventData<'a> {
/// Anchor name or null.
pub anchor: *const yaml_char_t,
/// Tag or null.
pub tag: *const yaml_char_t,
/// Value.
pub value: *const yaml_char_t,
/// Value length.
pub length: libc::c_int,
/// Is the tag optional for the plain style?
pub plain_implicit: bool,
/// Is the tag optional for any non-plain style?
pub quoted_implicit: bool,
/// Scalar style.
pub style: YamlScalarStyleT,
/// Lifetime marker.
pub _marker: core::marker::PhantomData<&'a ()>,
}
/// Create a SCALAR event.
///
/// The `style` argument may be ignored by the emitter.
///
/// Either the `tag` attribute or one of the `plain_implicit` and
/// `quoted_implicit` flags must be set.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct that can be safely written to.
/// - `value` must be a valid, non-null pointer to a null-terminated UTF-8 string.
/// - `anchor`, if not null, must be a valid pointer to a null-terminated UTF-8 string.
/// - `tag`, if not null, must be a valid pointer to a null-terminated UTF-8 string.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
/// - The caller is responsible for freeing any dynamically allocated memory associated with the event using `yaml_event_delete`.
///
pub unsafe fn yaml_scalar_event_initialize(
event: *mut YamlEventT,
mut data: ScalarEventData<'_>,
) -> Success {
let mut current_block: u64;
let mark = YamlMarkT {
index: 0_u64,
line: 0_u64,
column: 0_u64,
};
let mut anchor_copy: *mut yaml_char_t =
ptr::null_mut::<yaml_char_t>();
let mut tag_copy: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
let mut value_copy: *mut yaml_char_t =
ptr::null_mut::<yaml_char_t>();
__assert!(!event.is_null());
__assert!(!data.value.is_null());
if !data.anchor.is_null() {
if yaml_check_utf8(
data.anchor,
strlen(data.anchor as *mut libc::c_char),
)
.fail
{
current_block = 16285396129609901221;
} else {
anchor_copy = yaml_strdup(data.anchor);
if anchor_copy.is_null() {
current_block = 16285396129609901221;
} else {
current_block = 8515828400728868193;
}
}
} else {
current_block = 8515828400728868193;
}
if current_block == 8515828400728868193 {
if !data.tag.is_null() {
if yaml_check_utf8(
data.tag,
strlen(data.tag as *mut libc::c_char),
)
.fail
{
current_block = 16285396129609901221;
} else {
tag_copy = yaml_strdup(data.tag);
if tag_copy.is_null() {
current_block = 16285396129609901221;
} else {
current_block = 12800627514080957624;
}
}
} else {
current_block = 12800627514080957624;
}
if current_block != 16285396129609901221 {
if data.length < 0 {
data.length = strlen(data.value as *mut libc::c_char)
as libc::c_int;
}
if yaml_check_utf8(data.value, data.length as size_t).ok {
value_copy =
yaml_malloc(data.length.force_add(1) as size_t)
as *mut yaml_char_t;
let _ = memcpy(
value_copy as *mut libc::c_void,
data.value as *const libc::c_void,
data.length as libc::c_ulong,
);
*value_copy.wrapping_offset(data.length as isize) =
b'\0';
let _ = memset(
event as *mut libc::c_void,
0,
size_of::<YamlEventT>() as libc::c_ulong,
);
(*event).type_ = YamlScalarEvent;
(*event).start_mark = mark;
(*event).end_mark = mark;
let fresh168 =
addr_of_mut!((*event).data.scalar.anchor);
*fresh168 = anchor_copy;
let fresh169 = addr_of_mut!((*event).data.scalar.tag);
*fresh169 = tag_copy;
let fresh170 = addr_of_mut!((*event).data.scalar.value);
*fresh170 = value_copy;
(*event).data.scalar.length = data.length as size_t;
(*event).data.scalar.plain_implicit =
data.plain_implicit;
(*event).data.scalar.quoted_implicit =
data.quoted_implicit;
(*event).data.scalar.style = data.style;
return OK;
}
}
}
yaml_free(anchor_copy as *mut libc::c_void);
yaml_free(tag_copy as *mut libc::c_void);
yaml_free(value_copy as *mut libc::c_void);
FAIL
}
/// Create a SEQUENCE-START event.
///
/// The `style` argument may be ignored by the emitter.
///
/// Either the `tag` attribute or the `implicit` flag must be set.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct that can be safely written to.
/// - `anchor`, if not null, must be a valid pointer to a null-terminated UTF-8 string.
/// - `tag`, if not null, must be a valid pointer to a null-terminated UTF-8 string.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
/// - The caller is responsible for freeing any dynamically allocated memory associated with the event using `yaml_event_delete`.
///
pub unsafe fn yaml_sequence_start_event_initialize(
event: *mut YamlEventT,
anchor: *const yaml_char_t,
tag: *const yaml_char_t,
implicit: bool,
style: YamlSequenceStyleT,
) -> Success {
let mut current_block: u64;
let mark = YamlMarkT {
index: 0_u64,
line: 0_u64,
column: 0_u64,
};
let mut anchor_copy: *mut yaml_char_t =
ptr::null_mut::<yaml_char_t>();
let mut tag_copy: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
__assert!(!event.is_null());
if !anchor.is_null() {
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char))
.fail
{
current_block = 8817775685815971442;
} else {
anchor_copy = yaml_strdup(anchor);
if anchor_copy.is_null() {
current_block = 8817775685815971442;
} else {
current_block = 11006700562992250127;
}
}
} else {
current_block = 11006700562992250127;
}
if current_block == 11006700562992250127 {
if !tag.is_null() {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char))
.fail
{
current_block = 8817775685815971442;
} else {
tag_copy = yaml_strdup(tag);
if tag_copy.is_null() {
current_block = 8817775685815971442;
} else {
current_block = 7651349459974463963;
}
}
} else {
current_block = 7651349459974463963;
}
if current_block != 8817775685815971442 {
let _ = memset(
event as *mut libc::c_void,
0,
size_of::<YamlEventT>() as libc::c_ulong,
);
(*event).type_ = YamlSequenceStartEvent;
(*event).start_mark = mark;
(*event).end_mark = mark;
let fresh171 =
addr_of_mut!((*event).data.sequence_start.anchor);
*fresh171 = anchor_copy;
let fresh172 =
addr_of_mut!((*event).data.sequence_start.tag);
*fresh172 = tag_copy;
(*event).data.sequence_start.implicit = implicit;
(*event).data.sequence_start.style = style;
return OK;
}
}
yaml_free(anchor_copy as *mut libc::c_void);
yaml_free(tag_copy as *mut libc::c_void);
FAIL
}
/// Create a SEQUENCE-END event.
///
/// This function initializes a `YamlEventT` struct with the type `YamlSequenceEndEvent`.
/// It is used to signal the end of a sequence in the YAML document being emitted.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct that can be safely written to.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_sequence_end_event_initialize(
event: *mut YamlEventT,
) -> Success {
let mark = YamlMarkT {
index: 0_u64,
line: 0_u64,
column: 0_u64,
};
__assert!(!event.is_null());
let _ = memset(
event as *mut libc::c_void,
0,
size_of::<YamlEventT>() as libc::c_ulong,
);
(*event).type_ = YamlSequenceEndEvent;
(*event).start_mark = mark;
(*event).end_mark = mark;
OK
}
/// Create a MAPPING-START event.
///
/// This function initializes a `YamlEventT` struct with the type `YamlMappingStartEvent`.
/// It is used to signal the start of a mapping (key-value pairs) in the YAML document being emitted.
///
/// The `style` argument may be ignored by the emitter.
///
/// Either the `tag` attribute or the `implicit` flag must be set.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct that can be safely written to.
/// - `anchor`, if not null, must be a valid pointer to a null-terminated UTF-8 string.
/// - `tag`, if not null, must be a valid pointer to a null-terminated UTF-8 string.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
/// - The caller is responsible for freeing any dynamically allocated memory associated with the event using `yaml_event_delete`.
///
pub unsafe fn yaml_mapping_start_event_initialize(
event: *mut YamlEventT,
anchor: *const yaml_char_t,
tag: *const yaml_char_t,
implicit: bool,
style: YamlMappingStyleT,
) -> Success {
let mut current_block: u64;
let mark = YamlMarkT {
index: 0_u64,
line: 0_u64,
column: 0_u64,
};
let mut anchor_copy: *mut yaml_char_t =
ptr::null_mut::<yaml_char_t>();
let mut tag_copy: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
__assert!(!event.is_null());
if !anchor.is_null() {
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char))
.fail
{
current_block = 14748279734549812740;
} else {
anchor_copy = yaml_strdup(anchor);
if anchor_copy.is_null() {
current_block = 14748279734549812740;
} else {
current_block = 11006700562992250127;
}
}
} else {
current_block = 11006700562992250127;
}
if current_block == 11006700562992250127 {
if !tag.is_null() {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char))
.fail
{
current_block = 14748279734549812740;
} else {
tag_copy = yaml_strdup(tag);
if tag_copy.is_null() {
current_block = 14748279734549812740;
} else {
current_block = 7651349459974463963;
}
}
} else {
current_block = 7651349459974463963;
}
if current_block != 14748279734549812740 {
let _ = memset(
event as *mut libc::c_void,
0,
size_of::<YamlEventT>() as libc::c_ulong,
);
(*event).type_ = YamlMappingStartEvent;
(*event).start_mark = mark;
(*event).end_mark = mark;
let fresh173 =
addr_of_mut!((*event).data.mapping_start.anchor);
*fresh173 = anchor_copy;
let fresh174 =
addr_of_mut!((*event).data.mapping_start.tag);
*fresh174 = tag_copy;
(*event).data.mapping_start.implicit = implicit;
(*event).data.mapping_start.style = style;
return OK;
}
}
yaml_free(anchor_copy as *mut libc::c_void);
yaml_free(tag_copy as *mut libc::c_void);
FAIL
}
/// Create a MAPPING-END event.
///
/// This function initializes a `YamlEventT` struct with the type `YamlMappingEndEvent`.
/// It is used to signal the end of a mapping (key-value pairs) in the YAML document being emitted.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct that can be safely written to.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_mapping_end_event_initialize(
event: *mut YamlEventT,
) -> Success {
let mark = YamlMarkT {
index: 0_u64,
line: 0_u64,
column: 0_u64,
};
__assert!(!event.is_null());
let _ = memset(
event as *mut libc::c_void,
0,
size_of::<YamlEventT>() as libc::c_ulong,
);
(*event).type_ = YamlMappingEndEvent;
(*event).start_mark = mark;
(*event).end_mark = mark;
OK
}
/// Free any memory allocated for an event object.
///
/// This function frees the dynamically allocated memory associated with a `YamlEventT` struct,
/// such as strings for anchors, tags, and scalar values.
///
/// # Safety
///
/// - `event` must be a valid, non-null pointer to a `YamlEventT` struct.
/// - The `YamlEventT` struct must have been properly initialized and its memory allocated correctly.
/// - The `YamlEventT` struct must be properly aligned and have the expected memory layout.
///
pub unsafe fn yaml_event_delete(event: *mut YamlEventT) {
let mut tag_directive: *mut YamlTagDirectiveT;
__assert!(!event.is_null());
match (*event).type_ {
YamlDocumentStartEvent => {
yaml_free(
(*event).data.document_start.version_directive
as *mut libc::c_void,
);
tag_directive =
(*event).data.document_start.tag_directives.start;
while tag_directive
!= (*event).data.document_start.tag_directives.end
{
yaml_free((*tag_directive).handle as *mut libc::c_void);
yaml_free((*tag_directive).prefix as *mut libc::c_void);
tag_directive = tag_directive.wrapping_offset(1);
}
yaml_free(
(*event).data.document_start.tag_directives.start
as *mut libc::c_void,
);
}
YamlAliasEvent => {
yaml_free((*event).data.alias.anchor as *mut libc::c_void);
}
YamlScalarEvent => {
yaml_free((*event).data.scalar.anchor as *mut libc::c_void);
yaml_free((*event).data.scalar.tag as *mut libc::c_void);
yaml_free((*event).data.scalar.value as *mut libc::c_void);
}
YamlSequenceStartEvent => {
yaml_free(
(*event).data.sequence_start.anchor
as *mut libc::c_void,
);
yaml_free(
(*event).data.sequence_start.tag as *mut libc::c_void,
);
}
YamlMappingStartEvent => {
yaml_free(
(*event).data.mapping_start.anchor as *mut libc::c_void,
);
yaml_free(
(*event).data.mapping_start.tag as *mut libc::c_void,
);
}
_ => {}
}
let _ = memset(
event as *mut libc::c_void,
0,
size_of::<YamlEventT>() as libc::c_ulong,
);
}