mirror of
https://github.com/simonask/libyaml-safer
synced 2025-02-16 20:38:30 +00:00
Replace yaml_queue_t with VecDeque
This commit is contained in:
parent
4a917d95ee
commit
6861a5e703
8 changed files with 378 additions and 320 deletions
63
src/api.rs
63
src/api.rs
|
@ -1,4 +1,4 @@
|
|||
use crate::externs::{free, malloc, memcpy, memmove, memset, realloc, strdup, strlen};
|
||||
use crate::externs::{free, malloc, memcpy, memset, realloc, strdup, strlen};
|
||||
use crate::ops::{ForceAdd as _, ForceMul as _};
|
||||
use crate::yaml::{size_t, yaml_char_t, YamlEventData, YamlNodeData, YamlTokenData};
|
||||
use crate::{
|
||||
|
@ -109,58 +109,13 @@ pub(crate) unsafe fn yaml_stack_extend(
|
|||
*start = new_start;
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn yaml_queue_extend(
|
||||
start: *mut *mut libc::c_void,
|
||||
head: *mut *mut libc::c_void,
|
||||
tail: *mut *mut libc::c_void,
|
||||
end: *mut *mut libc::c_void,
|
||||
) {
|
||||
if *start == *head && *tail == *end {
|
||||
let new_start: *mut libc::c_void = yaml_realloc(
|
||||
*start,
|
||||
(((*end as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char)
|
||||
as libc::c_long)
|
||||
.force_mul(2_i64)) as size_t,
|
||||
);
|
||||
*head = (new_start as *mut libc::c_char).wrapping_offset(
|
||||
(*head as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char) as libc::c_long
|
||||
as isize,
|
||||
) as *mut libc::c_void;
|
||||
*tail = (new_start as *mut libc::c_char).wrapping_offset(
|
||||
(*tail as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char) as libc::c_long
|
||||
as isize,
|
||||
) as *mut libc::c_void;
|
||||
*end = (new_start as *mut libc::c_char).wrapping_offset(
|
||||
(((*end as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char)
|
||||
as libc::c_long)
|
||||
.force_mul(2_i64)) as isize,
|
||||
) as *mut libc::c_void;
|
||||
*start = new_start;
|
||||
}
|
||||
if *tail == *end {
|
||||
if *head != *tail {
|
||||
memmove(
|
||||
*start,
|
||||
*head,
|
||||
(*tail as *mut libc::c_char).c_offset_from(*head as *mut libc::c_char)
|
||||
as libc::c_ulong,
|
||||
);
|
||||
}
|
||||
*tail = (*start as *mut libc::c_char).wrapping_offset(
|
||||
(*tail as *mut libc::c_char).c_offset_from(*head as *mut libc::c_char) as libc::c_long
|
||||
as isize,
|
||||
) as *mut libc::c_void;
|
||||
*head = *start;
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize a parser.
|
||||
///
|
||||
/// This function creates a new parser object. An application is responsible
|
||||
/// for destroying the object using the yaml_parser_delete() function.
|
||||
pub unsafe fn yaml_parser_initialize(parser: *mut yaml_parser_t) -> Result<(), ()> {
|
||||
__assert!(!parser.is_null());
|
||||
*parser = core::mem::MaybeUninit::zeroed().assume_init();
|
||||
core::ptr::write(parser, yaml_parser_t::default());
|
||||
let parser = &mut *parser;
|
||||
BUFFER_INIT!(parser.raw_buffer, INPUT_RAW_BUFFER_SIZE);
|
||||
BUFFER_INIT!(parser.buffer, INPUT_BUFFER_SIZE);
|
||||
|
@ -177,10 +132,9 @@ pub unsafe fn yaml_parser_initialize(parser: *mut yaml_parser_t) -> Result<(), (
|
|||
pub unsafe fn yaml_parser_delete(parser: &mut yaml_parser_t) {
|
||||
BUFFER_DEL!(parser.raw_buffer);
|
||||
BUFFER_DEL!(parser.buffer);
|
||||
while !QUEUE_EMPTY!(parser.tokens) {
|
||||
yaml_token_delete(&mut DEQUEUE!(parser.tokens));
|
||||
for mut token in parser.tokens.drain(..) {
|
||||
yaml_token_delete(&mut token);
|
||||
}
|
||||
QUEUE_DEL!(parser.tokens);
|
||||
STACK_DEL!(parser.indents);
|
||||
STACK_DEL!(parser.simple_keys);
|
||||
STACK_DEL!(parser.states);
|
||||
|
@ -191,7 +145,6 @@ pub unsafe fn yaml_parser_delete(parser: &mut yaml_parser_t) {
|
|||
yaml_free(tag_directive.prefix as *mut libc::c_void);
|
||||
}
|
||||
STACK_DEL!(parser.tag_directives);
|
||||
*parser = core::mem::MaybeUninit::zeroed().assume_init();
|
||||
}
|
||||
|
||||
unsafe fn yaml_string_read_handler(
|
||||
|
@ -261,7 +214,7 @@ pub fn yaml_parser_set_encoding(parser: &mut yaml_parser_t, encoding: yaml_encod
|
|||
/// for destroying the object using the yaml_emitter_delete() function.
|
||||
pub unsafe fn yaml_emitter_initialize(emitter: *mut yaml_emitter_t) -> Result<(), ()> {
|
||||
__assert!(!emitter.is_null());
|
||||
*emitter = core::mem::MaybeUninit::zeroed().assume_init();
|
||||
core::ptr::write(emitter, yaml_emitter_t::default());
|
||||
let emitter = &mut *emitter;
|
||||
BUFFER_INIT!(emitter.buffer, OUTPUT_BUFFER_SIZE);
|
||||
BUFFER_INIT!(emitter.raw_buffer, OUTPUT_RAW_BUFFER_SIZE);
|
||||
|
@ -277,11 +230,9 @@ pub unsafe fn yaml_emitter_delete(emitter: &mut yaml_emitter_t) {
|
|||
BUFFER_DEL!(emitter.buffer);
|
||||
BUFFER_DEL!(emitter.raw_buffer);
|
||||
STACK_DEL!(emitter.states);
|
||||
while !QUEUE_EMPTY!(emitter.events) {
|
||||
let mut event = DEQUEUE!(emitter.events);
|
||||
while let Some(mut event) = emitter.events.pop_front() {
|
||||
yaml_event_delete(&mut event);
|
||||
}
|
||||
QUEUE_DEL!(emitter.events);
|
||||
STACK_DEL!(emitter.indents);
|
||||
while !STACK_EMPTY!(emitter.tag_directives) {
|
||||
let tag_directive = POP!(emitter.tag_directives);
|
||||
|
@ -290,7 +241,7 @@ pub unsafe fn yaml_emitter_delete(emitter: &mut yaml_emitter_t) {
|
|||
}
|
||||
STACK_DEL!(emitter.tag_directives);
|
||||
yaml_free(emitter.anchors as *mut libc::c_void);
|
||||
*emitter = core::mem::MaybeUninit::zeroed().assume_init();
|
||||
*emitter = yaml_emitter_t::default();
|
||||
}
|
||||
|
||||
unsafe fn yaml_string_write_handler(
|
||||
|
|
|
@ -65,9 +65,10 @@ pub(crate) unsafe fn unsafe_main(
|
|||
yaml_emitter_set_unicode(&mut emitter, false);
|
||||
|
||||
let mut buf = ReadBuf::new();
|
||||
let mut event = yaml_event_t::default();
|
||||
|
||||
let result = loop {
|
||||
let mut event = yaml_event_t::default();
|
||||
|
||||
let line = match buf.get_line(stdin) {
|
||||
Some(line) => line,
|
||||
None => break Ok(()),
|
||||
|
@ -136,7 +137,7 @@ pub(crate) unsafe fn unsafe_main(
|
|||
if result.is_err() {
|
||||
break Err("Memory error: Not enough memory for creating an event".into());
|
||||
}
|
||||
if yaml_emitter_emit(&mut emitter, &event).is_err() {
|
||||
if yaml_emitter_emit(&mut emitter, event).is_err() {
|
||||
break Err(match (*emitter).error {
|
||||
YAML_MEMORY_ERROR => "Memory error: Not enough memory for emitting".into(),
|
||||
YAML_WRITER_ERROR => {
|
||||
|
|
|
@ -21,7 +21,7 @@ pub unsafe fn yaml_emitter_open(emitter: &mut yaml_emitter_t) -> Result<(), ()>
|
|||
},
|
||||
..Default::default()
|
||||
};
|
||||
yaml_emitter_emit(emitter, &event)?;
|
||||
yaml_emitter_emit(emitter, event)?;
|
||||
emitter.opened = true;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ pub unsafe fn yaml_emitter_close(emitter: &mut yaml_emitter_t) -> Result<(), ()>
|
|||
data: YamlEventData::StreamEnd,
|
||||
..Default::default()
|
||||
};
|
||||
yaml_emitter_emit(emitter, &event)?;
|
||||
yaml_emitter_emit(emitter, event)?;
|
||||
emitter.closed = true;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ pub unsafe fn yaml_emitter_dump(
|
|||
},
|
||||
..Default::default()
|
||||
};
|
||||
if let Ok(()) = yaml_emitter_emit(emitter, &event) {
|
||||
if let Ok(()) = yaml_emitter_emit(emitter, event) {
|
||||
yaml_emitter_anchor_node(emitter, 1);
|
||||
if let Ok(()) = yaml_emitter_dump_node(emitter, 1) {
|
||||
let event = yaml_event_t {
|
||||
|
@ -104,7 +104,7 @@ pub unsafe fn yaml_emitter_dump(
|
|||
},
|
||||
..Default::default()
|
||||
};
|
||||
if let Ok(()) = yaml_emitter_emit(emitter, &event) {
|
||||
if let Ok(()) = yaml_emitter_emit(emitter, event) {
|
||||
yaml_emitter_delete_document_and_anchors(emitter);
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ unsafe fn yaml_emitter_dump_alias(
|
|||
data: YamlEventData::Alias { anchor },
|
||||
..Default::default()
|
||||
};
|
||||
yaml_emitter_emit(emitter, &event)
|
||||
yaml_emitter_emit(emitter, event)
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_dump_scalar(
|
||||
|
@ -279,7 +279,7 @@ unsafe fn yaml_emitter_dump_scalar(
|
|||
},
|
||||
..Default::default()
|
||||
};
|
||||
yaml_emitter_emit(emitter, &event)
|
||||
yaml_emitter_emit(emitter, event)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ unsafe fn yaml_emitter_dump_sequence(
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
yaml_emitter_emit(emitter, &event)?;
|
||||
yaml_emitter_emit(emitter, event)?;
|
||||
item = items.start;
|
||||
while item < items.top {
|
||||
yaml_emitter_dump_node(emitter, *item)?;
|
||||
|
@ -317,7 +317,7 @@ unsafe fn yaml_emitter_dump_sequence(
|
|||
data: YamlEventData::SequenceEnd,
|
||||
..Default::default()
|
||||
};
|
||||
yaml_emitter_emit(emitter, &event)
|
||||
yaml_emitter_emit(emitter, event)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ unsafe fn yaml_emitter_dump_mapping(
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
yaml_emitter_emit(emitter, &event)?;
|
||||
yaml_emitter_emit(emitter, event)?;
|
||||
pair = pairs.start;
|
||||
while pair < pairs.top {
|
||||
yaml_emitter_dump_node(emitter, (*pair).key)?;
|
||||
|
@ -356,7 +356,7 @@ unsafe fn yaml_emitter_dump_mapping(
|
|||
data: YamlEventData::MappingEnd,
|
||||
..Default::default()
|
||||
};
|
||||
yaml_emitter_emit(emitter, &event)
|
||||
yaml_emitter_emit(emitter, event)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
|
248
src/emitter.rs
248
src/emitter.rs
|
@ -1,4 +1,4 @@
|
|||
use crate::api::{yaml_free, yaml_queue_extend, yaml_stack_extend, yaml_strdup};
|
||||
use crate::api::{yaml_free, yaml_stack_extend, yaml_strdup};
|
||||
use crate::externs::{strcmp, strlen, strncmp};
|
||||
use crate::ops::{ForceAdd as _, ForceMul as _};
|
||||
use crate::yaml::{size_t, yaml_char_t, yaml_string_t, YamlEventData};
|
||||
|
@ -102,38 +102,34 @@ fn yaml_emitter_set_emitter_error(
|
|||
/// function fails.
|
||||
pub unsafe fn yaml_emitter_emit(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event: yaml_event_t,
|
||||
) -> Result<(), ()> {
|
||||
ENQUEUE!(emitter.events, *event);
|
||||
emitter.events.push_back(event);
|
||||
while let Err(()) = yaml_emitter_need_more_events(emitter) {
|
||||
yaml_emitter_analyze_event(emitter, &*emitter.events.head)?;
|
||||
yaml_emitter_state_machine(emitter, &*emitter.events.head)?;
|
||||
yaml_event_delete(&mut DEQUEUE!(emitter.events));
|
||||
yaml_emitter_analyze_event(emitter, 0)?;
|
||||
yaml_emitter_state_machine(emitter, 0)?;
|
||||
yaml_event_delete(&mut emitter.events.pop_front().unwrap());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_need_more_events(emitter: &mut yaml_emitter_t) -> Result<(), ()> {
|
||||
let mut level: libc::c_int = 0;
|
||||
let mut event: *mut yaml_event_t;
|
||||
if QUEUE_EMPTY!(emitter.events) {
|
||||
if emitter.events.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let accumulate = match &(*emitter.events.head).data {
|
||||
let accumulate = match &emitter.events.front().unwrap().data {
|
||||
YamlEventData::DocumentStart { .. } => 1,
|
||||
YamlEventData::SequenceStart { .. } => 2,
|
||||
YamlEventData::MappingStart { .. } => 3,
|
||||
_ => return Err(()),
|
||||
};
|
||||
|
||||
if emitter.events.tail.c_offset_from(emitter.events.head) as libc::c_long
|
||||
> accumulate as libc::c_long
|
||||
{
|
||||
if emitter.events.len() as libc::c_long > accumulate as libc::c_long {
|
||||
return Err(());
|
||||
}
|
||||
event = emitter.events.head;
|
||||
while event != emitter.events.tail {
|
||||
match (*event).data {
|
||||
for event in &emitter.events {
|
||||
match event.data {
|
||||
YamlEventData::StreamStart { .. }
|
||||
| YamlEventData::DocumentStart { .. }
|
||||
| YamlEventData::SequenceStart { .. }
|
||||
|
@ -153,7 +149,6 @@ unsafe fn yaml_emitter_need_more_events(emitter: &mut yaml_emitter_t) -> Result<
|
|||
if level == 0 {
|
||||
return Err(());
|
||||
}
|
||||
event = event.wrapping_offset(1);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -199,51 +194,55 @@ unsafe fn yaml_emitter_increase_indent(emitter: &mut yaml_emitter_t, flow: bool,
|
|||
|
||||
unsafe fn yaml_emitter_state_machine(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
match emitter.state {
|
||||
YAML_EMIT_STREAM_START_STATE => yaml_emitter_emit_stream_start(emitter, event),
|
||||
YAML_EMIT_STREAM_START_STATE => yaml_emitter_emit_stream_start(emitter, event_index),
|
||||
YAML_EMIT_FIRST_DOCUMENT_START_STATE => {
|
||||
yaml_emitter_emit_document_start(emitter, event, true)
|
||||
yaml_emitter_emit_document_start(emitter, event_index, true)
|
||||
}
|
||||
YAML_EMIT_DOCUMENT_START_STATE => yaml_emitter_emit_document_start(emitter, event, false),
|
||||
YAML_EMIT_DOCUMENT_CONTENT_STATE => yaml_emitter_emit_document_content(emitter, event),
|
||||
YAML_EMIT_DOCUMENT_END_STATE => yaml_emitter_emit_document_end(emitter, event),
|
||||
YAML_EMIT_DOCUMENT_START_STATE => {
|
||||
yaml_emitter_emit_document_start(emitter, event_index, false)
|
||||
}
|
||||
YAML_EMIT_DOCUMENT_CONTENT_STATE => {
|
||||
yaml_emitter_emit_document_content(emitter, event_index)
|
||||
}
|
||||
YAML_EMIT_DOCUMENT_END_STATE => yaml_emitter_emit_document_end(emitter, event_index),
|
||||
YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE => {
|
||||
yaml_emitter_emit_flow_sequence_item(emitter, event, true)
|
||||
yaml_emitter_emit_flow_sequence_item(emitter, event_index, true)
|
||||
}
|
||||
YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE => {
|
||||
yaml_emitter_emit_flow_sequence_item(emitter, event, false)
|
||||
yaml_emitter_emit_flow_sequence_item(emitter, event_index, false)
|
||||
}
|
||||
YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE => {
|
||||
yaml_emitter_emit_flow_mapping_key(emitter, event, true)
|
||||
yaml_emitter_emit_flow_mapping_key(emitter, event_index, true)
|
||||
}
|
||||
YAML_EMIT_FLOW_MAPPING_KEY_STATE => {
|
||||
yaml_emitter_emit_flow_mapping_key(emitter, event, false)
|
||||
yaml_emitter_emit_flow_mapping_key(emitter, event_index, false)
|
||||
}
|
||||
YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE => {
|
||||
yaml_emitter_emit_flow_mapping_value(emitter, event, true)
|
||||
yaml_emitter_emit_flow_mapping_value(emitter, event_index, true)
|
||||
}
|
||||
YAML_EMIT_FLOW_MAPPING_VALUE_STATE => {
|
||||
yaml_emitter_emit_flow_mapping_value(emitter, event, false)
|
||||
yaml_emitter_emit_flow_mapping_value(emitter, event_index, false)
|
||||
}
|
||||
YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE => {
|
||||
yaml_emitter_emit_block_sequence_item(emitter, event, true)
|
||||
yaml_emitter_emit_block_sequence_item(emitter, event_index, true)
|
||||
}
|
||||
YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE => {
|
||||
yaml_emitter_emit_block_sequence_item(emitter, event, false)
|
||||
yaml_emitter_emit_block_sequence_item(emitter, event_index, false)
|
||||
}
|
||||
YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE => {
|
||||
yaml_emitter_emit_block_mapping_key(emitter, event, true)
|
||||
yaml_emitter_emit_block_mapping_key(emitter, event_index, true)
|
||||
}
|
||||
YAML_EMIT_BLOCK_MAPPING_KEY_STATE => {
|
||||
yaml_emitter_emit_block_mapping_key(emitter, event, false)
|
||||
yaml_emitter_emit_block_mapping_key(emitter, event_index, false)
|
||||
}
|
||||
YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE => {
|
||||
yaml_emitter_emit_block_mapping_value(emitter, event, true)
|
||||
yaml_emitter_emit_block_mapping_value(emitter, event_index, true)
|
||||
}
|
||||
YAML_EMIT_BLOCK_MAPPING_VALUE_STATE => {
|
||||
yaml_emitter_emit_block_mapping_value(emitter, event, false)
|
||||
yaml_emitter_emit_block_mapping_value(emitter, event_index, false)
|
||||
}
|
||||
YAML_EMIT_END_STATE => {
|
||||
yaml_emitter_set_emitter_error(emitter, "expected nothing after STREAM-END")
|
||||
|
@ -253,10 +252,10 @@ unsafe fn yaml_emitter_state_machine(
|
|||
|
||||
unsafe fn yaml_emitter_emit_stream_start(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
emitter.open_ended = 0;
|
||||
if let YamlEventData::StreamStart { ref encoding } = event.data {
|
||||
if let YamlEventData::StreamStart { ref encoding } = emitter.events[event_index].data {
|
||||
if emitter.encoding == YAML_ANY_ENCODING {
|
||||
emitter.encoding = *encoding;
|
||||
}
|
||||
|
@ -291,7 +290,7 @@ unsafe fn yaml_emitter_emit_stream_start(
|
|||
|
||||
unsafe fn yaml_emitter_emit_document_start(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
first: bool,
|
||||
) -> Result<(), ()> {
|
||||
if let YamlEventData::DocumentStart {
|
||||
|
@ -299,8 +298,15 @@ unsafe fn yaml_emitter_emit_document_start(
|
|||
tag_directives_start,
|
||||
tag_directives_end,
|
||||
implicit,
|
||||
} = &event.data
|
||||
} = &emitter.events[event_index].data
|
||||
{
|
||||
let (version_directive, tag_directives_start, tag_directives_end, implicit) = (
|
||||
*version_directive,
|
||||
*tag_directives_start,
|
||||
*tag_directives_end,
|
||||
*implicit,
|
||||
);
|
||||
|
||||
let mut default_tag_directives: [yaml_tag_directive_t; 3] = [
|
||||
yaml_tag_directive_t {
|
||||
handle: b"!\0" as *const u8 as *const libc::c_char as *mut yaml_char_t,
|
||||
|
@ -317,12 +323,12 @@ unsafe fn yaml_emitter_emit_document_start(
|
|||
},
|
||||
];
|
||||
let mut tag_directive: *mut yaml_tag_directive_t;
|
||||
let mut implicit = *implicit;
|
||||
let mut implicit = implicit;
|
||||
if !version_directive.is_null() {
|
||||
yaml_emitter_analyze_version_directive(emitter, &**version_directive)?;
|
||||
yaml_emitter_analyze_version_directive(emitter, &*version_directive)?;
|
||||
}
|
||||
tag_directive = *tag_directives_start;
|
||||
while tag_directive != *tag_directives_end {
|
||||
tag_directive = tag_directives_start;
|
||||
while tag_directive != tag_directives_end {
|
||||
yaml_emitter_analyze_tag_directive(emitter, &*tag_directive)?;
|
||||
yaml_emitter_append_tag_directive(emitter, &*tag_directive, false)?;
|
||||
tag_directive = tag_directive.wrapping_offset(1);
|
||||
|
@ -335,7 +341,7 @@ unsafe fn yaml_emitter_emit_document_start(
|
|||
if !first || emitter.canonical {
|
||||
implicit = false;
|
||||
}
|
||||
if (!version_directive.is_null() || *tag_directives_start != *tag_directives_end)
|
||||
if (!version_directive.is_null() || tag_directives_start != tag_directives_end)
|
||||
&& emitter.open_ended != 0
|
||||
{
|
||||
yaml_emitter_write_indicator(
|
||||
|
@ -357,7 +363,7 @@ unsafe fn yaml_emitter_emit_document_start(
|
|||
false,
|
||||
false,
|
||||
)?;
|
||||
if (**version_directive).minor == 1 {
|
||||
if (*version_directive).minor == 1 {
|
||||
yaml_emitter_write_indicator(
|
||||
emitter,
|
||||
b"1.1\0" as *const u8 as *const libc::c_char,
|
||||
|
@ -376,10 +382,10 @@ unsafe fn yaml_emitter_emit_document_start(
|
|||
}
|
||||
yaml_emitter_write_indent(emitter)?;
|
||||
}
|
||||
if *tag_directives_start != *tag_directives_end {
|
||||
if tag_directives_start != tag_directives_end {
|
||||
implicit = false;
|
||||
tag_directive = *tag_directives_start;
|
||||
while tag_directive != *tag_directives_end {
|
||||
tag_directive = tag_directives_start;
|
||||
while tag_directive != tag_directives_end {
|
||||
yaml_emitter_write_indicator(
|
||||
emitter,
|
||||
b"%TAG\0" as *const u8 as *const libc::c_char,
|
||||
|
@ -421,7 +427,7 @@ unsafe fn yaml_emitter_emit_document_start(
|
|||
emitter.state = YAML_EMIT_DOCUMENT_CONTENT_STATE;
|
||||
emitter.open_ended = 0;
|
||||
return Ok(());
|
||||
} else if let YamlEventData::StreamEnd = &event.data {
|
||||
} else if let YamlEventData::StreamEnd = &emitter.events[event_index].data {
|
||||
if emitter.open_ended == 2 {
|
||||
yaml_emitter_write_indicator(
|
||||
emitter,
|
||||
|
@ -443,19 +449,20 @@ unsafe fn yaml_emitter_emit_document_start(
|
|||
|
||||
unsafe fn yaml_emitter_emit_document_content(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
PUSH!(emitter.states, YAML_EMIT_DOCUMENT_END_STATE);
|
||||
yaml_emitter_emit_node(emitter, event, true, false, false, false)
|
||||
yaml_emitter_emit_node(emitter, event_index, true, false, false, false)
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_emit_document_end(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
if let YamlEventData::DocumentEnd { implicit } = &event.data {
|
||||
if let YamlEventData::DocumentEnd { implicit } = &emitter.events[event_index].data {
|
||||
let implicit = *implicit;
|
||||
yaml_emitter_write_indent(emitter)?;
|
||||
if !*implicit {
|
||||
if !implicit {
|
||||
yaml_emitter_write_indicator(
|
||||
emitter,
|
||||
b"...\0" as *const u8 as *const libc::c_char,
|
||||
|
@ -483,7 +490,7 @@ unsafe fn yaml_emitter_emit_document_end(
|
|||
|
||||
unsafe fn yaml_emitter_emit_flow_sequence_item(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
first: bool,
|
||||
) -> Result<(), ()> {
|
||||
if first {
|
||||
|
@ -497,7 +504,7 @@ unsafe fn yaml_emitter_emit_flow_sequence_item(
|
|||
yaml_emitter_increase_indent(emitter, true, false);
|
||||
emitter.flow_level += 1;
|
||||
}
|
||||
if let YamlEventData::SequenceEnd = &event.data {
|
||||
if let YamlEventData::SequenceEnd = &emitter.events[event_index].data {
|
||||
emitter.flow_level -= 1;
|
||||
emitter.indent = POP!(emitter.indents);
|
||||
if emitter.canonical && !first {
|
||||
|
@ -533,12 +540,12 @@ unsafe fn yaml_emitter_emit_flow_sequence_item(
|
|||
yaml_emitter_write_indent(emitter)?;
|
||||
}
|
||||
PUSH!(emitter.states, YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE);
|
||||
yaml_emitter_emit_node(emitter, event, false, true, false, false)
|
||||
yaml_emitter_emit_node(emitter, event_index, false, true, false, false)
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_emit_flow_mapping_key(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
first: bool,
|
||||
) -> Result<(), ()> {
|
||||
if first {
|
||||
|
@ -552,7 +559,7 @@ unsafe fn yaml_emitter_emit_flow_mapping_key(
|
|||
yaml_emitter_increase_indent(emitter, true, false);
|
||||
emitter.flow_level += 1;
|
||||
}
|
||||
if let YamlEventData::MappingEnd = &event.data {
|
||||
if let YamlEventData::MappingEnd = &emitter.events[event_index].data {
|
||||
if STACK_EMPTY!(emitter.indents) {
|
||||
return Err(());
|
||||
}
|
||||
|
@ -592,7 +599,7 @@ unsafe fn yaml_emitter_emit_flow_mapping_key(
|
|||
}
|
||||
if !emitter.canonical && yaml_emitter_check_simple_key(emitter) {
|
||||
PUSH!(emitter.states, YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE);
|
||||
yaml_emitter_emit_node(emitter, event, false, false, true, true)
|
||||
yaml_emitter_emit_node(emitter, event_index, false, false, true, true)
|
||||
} else {
|
||||
yaml_emitter_write_indicator(
|
||||
emitter,
|
||||
|
@ -602,13 +609,13 @@ unsafe fn yaml_emitter_emit_flow_mapping_key(
|
|||
false,
|
||||
)?;
|
||||
PUSH!(emitter.states, YAML_EMIT_FLOW_MAPPING_VALUE_STATE);
|
||||
yaml_emitter_emit_node(emitter, event, false, false, true, false)
|
||||
yaml_emitter_emit_node(emitter, event_index, false, false, true, false)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_emit_flow_mapping_value(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
simple: bool,
|
||||
) -> Result<(), ()> {
|
||||
if simple {
|
||||
|
@ -632,12 +639,12 @@ unsafe fn yaml_emitter_emit_flow_mapping_value(
|
|||
)?;
|
||||
}
|
||||
PUSH!(emitter.states, YAML_EMIT_FLOW_MAPPING_KEY_STATE);
|
||||
yaml_emitter_emit_node(emitter, event, false, false, true, false)
|
||||
yaml_emitter_emit_node(emitter, event_index, false, false, true, false)
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_emit_block_sequence_item(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
first: bool,
|
||||
) -> Result<(), ()> {
|
||||
if first {
|
||||
|
@ -647,7 +654,7 @@ unsafe fn yaml_emitter_emit_block_sequence_item(
|
|||
emitter.mapping_context && !emitter.indention,
|
||||
);
|
||||
}
|
||||
if let YamlEventData::SequenceEnd = &event.data {
|
||||
if let YamlEventData::SequenceEnd = &emitter.events[event_index].data {
|
||||
emitter.indent = POP!(emitter.indents);
|
||||
emitter.state = POP!(emitter.states);
|
||||
return Ok(());
|
||||
|
@ -661,18 +668,18 @@ unsafe fn yaml_emitter_emit_block_sequence_item(
|
|||
true,
|
||||
)?;
|
||||
PUSH!(emitter.states, YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE);
|
||||
yaml_emitter_emit_node(emitter, event, false, true, false, false)
|
||||
yaml_emitter_emit_node(emitter, event_index, false, true, false, false)
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_emit_block_mapping_key(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
first: bool,
|
||||
) -> Result<(), ()> {
|
||||
if first {
|
||||
yaml_emitter_increase_indent(emitter, false, false);
|
||||
}
|
||||
if let YamlEventData::MappingEnd = &event.data {
|
||||
if let YamlEventData::MappingEnd = &emitter.events[event_index].data {
|
||||
emitter.indent = POP!(emitter.indents);
|
||||
emitter.state = POP!(emitter.states);
|
||||
return Ok(());
|
||||
|
@ -680,7 +687,7 @@ unsafe fn yaml_emitter_emit_block_mapping_key(
|
|||
yaml_emitter_write_indent(emitter)?;
|
||||
if yaml_emitter_check_simple_key(emitter) {
|
||||
PUSH!(emitter.states, YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE);
|
||||
yaml_emitter_emit_node(emitter, event, false, false, true, true)
|
||||
yaml_emitter_emit_node(emitter, event_index, false, false, true, true)
|
||||
} else {
|
||||
yaml_emitter_write_indicator(
|
||||
emitter,
|
||||
|
@ -690,13 +697,13 @@ unsafe fn yaml_emitter_emit_block_mapping_key(
|
|||
true,
|
||||
)?;
|
||||
PUSH!(emitter.states, YAML_EMIT_BLOCK_MAPPING_VALUE_STATE);
|
||||
yaml_emitter_emit_node(emitter, event, false, false, true, false)
|
||||
yaml_emitter_emit_node(emitter, event_index, false, false, true, false)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_emit_block_mapping_value(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
simple: bool,
|
||||
) -> Result<(), ()> {
|
||||
if simple {
|
||||
|
@ -718,12 +725,12 @@ unsafe fn yaml_emitter_emit_block_mapping_value(
|
|||
)?;
|
||||
}
|
||||
PUSH!(emitter.states, YAML_EMIT_BLOCK_MAPPING_KEY_STATE);
|
||||
yaml_emitter_emit_node(emitter, event, false, false, true, false)
|
||||
yaml_emitter_emit_node(emitter, event_index, false, false, true, false)
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_emit_node(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
root: bool,
|
||||
sequence: bool,
|
||||
mapping: bool,
|
||||
|
@ -734,11 +741,13 @@ unsafe fn yaml_emitter_emit_node(
|
|||
emitter.mapping_context = mapping;
|
||||
emitter.simple_key_context = simple_key;
|
||||
|
||||
match event.data {
|
||||
YamlEventData::Alias { .. } => yaml_emitter_emit_alias(emitter, event),
|
||||
YamlEventData::Scalar { .. } => yaml_emitter_emit_scalar(emitter, event),
|
||||
YamlEventData::SequenceStart { .. } => yaml_emitter_emit_sequence_start(emitter, event),
|
||||
YamlEventData::MappingStart { .. } => yaml_emitter_emit_mapping_start(emitter, event),
|
||||
match emitter.events[event_index].data {
|
||||
YamlEventData::Alias { .. } => yaml_emitter_emit_alias(emitter, event_index),
|
||||
YamlEventData::Scalar { .. } => yaml_emitter_emit_scalar(emitter, event_index),
|
||||
YamlEventData::SequenceStart { .. } => {
|
||||
yaml_emitter_emit_sequence_start(emitter, event_index)
|
||||
}
|
||||
YamlEventData::MappingStart { .. } => yaml_emitter_emit_mapping_start(emitter, event_index),
|
||||
_ => yaml_emitter_set_emitter_error(
|
||||
emitter,
|
||||
"expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS",
|
||||
|
@ -748,7 +757,7 @@ unsafe fn yaml_emitter_emit_node(
|
|||
|
||||
unsafe fn yaml_emitter_emit_alias(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
_event: &yaml_event_t,
|
||||
_event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
yaml_emitter_process_anchor(emitter)?;
|
||||
if emitter.simple_key_context {
|
||||
|
@ -760,9 +769,9 @@ unsafe fn yaml_emitter_emit_alias(
|
|||
|
||||
unsafe fn yaml_emitter_emit_scalar(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
yaml_emitter_select_scalar_style(emitter, event)?;
|
||||
yaml_emitter_select_scalar_style(emitter, event_index)?;
|
||||
yaml_emitter_process_anchor(emitter)?;
|
||||
yaml_emitter_process_tag(emitter)?;
|
||||
yaml_emitter_increase_indent(emitter, true, false);
|
||||
|
@ -774,16 +783,17 @@ unsafe fn yaml_emitter_emit_scalar(
|
|||
|
||||
unsafe fn yaml_emitter_emit_sequence_start(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
yaml_emitter_process_anchor(emitter)?;
|
||||
yaml_emitter_process_tag(emitter)?;
|
||||
|
||||
let style = if let YamlEventData::SequenceStart { style, .. } = &event.data {
|
||||
*style
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
let style =
|
||||
if let YamlEventData::SequenceStart { style, .. } = &emitter.events[event_index].data {
|
||||
*style
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
if emitter.flow_level != 0
|
||||
|| emitter.canonical
|
||||
|
@ -799,12 +809,13 @@ unsafe fn yaml_emitter_emit_sequence_start(
|
|||
|
||||
unsafe fn yaml_emitter_emit_mapping_start(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
yaml_emitter_process_anchor(emitter)?;
|
||||
yaml_emitter_process_tag(emitter)?;
|
||||
|
||||
let style = if let YamlEventData::MappingStart { style, .. } = &event.data {
|
||||
let style = if let YamlEventData::MappingStart { style, .. } = &emitter.events[event_index].data
|
||||
{
|
||||
*style
|
||||
} else {
|
||||
unreachable!()
|
||||
|
@ -822,20 +833,20 @@ unsafe fn yaml_emitter_emit_mapping_start(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_check_empty_document(_emitter: &mut yaml_emitter_t) -> bool {
|
||||
unsafe fn yaml_emitter_check_empty_document(_emitter: &yaml_emitter_t) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_check_empty_sequence(emitter: &mut yaml_emitter_t) -> bool {
|
||||
if (emitter.events.tail.c_offset_from(emitter.events.head) as libc::c_long) < 2_i64 {
|
||||
unsafe fn yaml_emitter_check_empty_sequence(emitter: &yaml_emitter_t) -> bool {
|
||||
if emitter.events.len() < 2 {
|
||||
return false;
|
||||
}
|
||||
let start = if let YamlEventData::SequenceStart { .. } = (*emitter.events.head).data {
|
||||
let start = if let YamlEventData::SequenceStart { .. } = emitter.events[0].data {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let end = if let YamlEventData::SequenceEnd = (*emitter.events.head.wrapping_offset(1)).data {
|
||||
let end = if let YamlEventData::SequenceEnd = emitter.events[1].data {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -843,16 +854,16 @@ unsafe fn yaml_emitter_check_empty_sequence(emitter: &mut yaml_emitter_t) -> boo
|
|||
start && end
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_check_empty_mapping(emitter: &mut yaml_emitter_t) -> bool {
|
||||
if (emitter.events.tail.c_offset_from(emitter.events.head) as libc::c_long) < 2_i64 {
|
||||
unsafe fn yaml_emitter_check_empty_mapping(emitter: &yaml_emitter_t) -> bool {
|
||||
if emitter.events.len() < 2 {
|
||||
return false;
|
||||
}
|
||||
let start = if let YamlEventData::MappingStart { .. } = (*emitter.events.head).data {
|
||||
let start = if let YamlEventData::MappingStart { .. } = emitter.events[0].data {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let end = if let YamlEventData::MappingEnd = (*emitter.events.head.wrapping_offset(1)).data {
|
||||
let end = if let YamlEventData::MappingEnd = emitter.events[1].data {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -860,8 +871,8 @@ unsafe fn yaml_emitter_check_empty_mapping(emitter: &mut yaml_emitter_t) -> bool
|
|||
start && end
|
||||
}
|
||||
|
||||
unsafe fn yaml_emitter_check_simple_key(emitter: &mut yaml_emitter_t) -> bool {
|
||||
let event = &*emitter.events.head;
|
||||
unsafe fn yaml_emitter_check_simple_key(emitter: &yaml_emitter_t) -> bool {
|
||||
let event = &emitter.events[0];
|
||||
let mut length: size_t = 0_u64;
|
||||
|
||||
match event.data {
|
||||
|
@ -909,14 +920,14 @@ unsafe fn yaml_emitter_check_simple_key(emitter: &mut yaml_emitter_t) -> bool {
|
|||
|
||||
unsafe fn yaml_emitter_select_scalar_style(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
if let YamlEventData::Scalar {
|
||||
plain_implicit,
|
||||
quoted_implicit,
|
||||
style,
|
||||
..
|
||||
} = &event.data
|
||||
} = &emitter.events[event_index].data
|
||||
{
|
||||
let mut style: yaml_scalar_style_t = *style;
|
||||
let no_tag = emitter.tag_data.handle.is_null() && emitter.tag_data.suffix.is_null();
|
||||
|
@ -1369,7 +1380,7 @@ unsafe fn yaml_emitter_analyze_scalar(
|
|||
|
||||
unsafe fn yaml_emitter_analyze_event(
|
||||
emitter: &mut yaml_emitter_t,
|
||||
event: &yaml_event_t,
|
||||
event_index: usize,
|
||||
) -> Result<(), ()> {
|
||||
emitter.anchor_data.anchor = ptr::null_mut::<yaml_char_t>();
|
||||
emitter.anchor_data.anchor_length = 0_u64;
|
||||
|
@ -1380,7 +1391,7 @@ unsafe fn yaml_emitter_analyze_event(
|
|||
emitter.scalar_data.value = ptr::null_mut::<yaml_char_t>();
|
||||
emitter.scalar_data.length = 0_u64;
|
||||
|
||||
match &event.data {
|
||||
match &emitter.events[event_index].data {
|
||||
YamlEventData::Alias { anchor } => yaml_emitter_analyze_anchor(emitter, *anchor, true),
|
||||
YamlEventData::Scalar {
|
||||
anchor,
|
||||
|
@ -1391,13 +1402,21 @@ unsafe fn yaml_emitter_analyze_event(
|
|||
quoted_implicit,
|
||||
..
|
||||
} => {
|
||||
let (anchor, tag, value, length, plain_implicit, quoted_implicit) = (
|
||||
*anchor,
|
||||
*tag,
|
||||
*value,
|
||||
*length,
|
||||
*plain_implicit,
|
||||
*quoted_implicit,
|
||||
);
|
||||
if !anchor.is_null() {
|
||||
yaml_emitter_analyze_anchor(emitter, *anchor, false)?;
|
||||
yaml_emitter_analyze_anchor(emitter, anchor, false)?;
|
||||
}
|
||||
if !tag.is_null() && (emitter.canonical || !*plain_implicit && !*quoted_implicit) {
|
||||
yaml_emitter_analyze_tag(emitter, *tag)?;
|
||||
if !tag.is_null() && (emitter.canonical || !plain_implicit && !quoted_implicit) {
|
||||
yaml_emitter_analyze_tag(emitter, tag)?;
|
||||
}
|
||||
yaml_emitter_analyze_scalar(emitter, *value, *length)
|
||||
yaml_emitter_analyze_scalar(emitter, value, length)
|
||||
}
|
||||
YamlEventData::SequenceStart {
|
||||
anchor,
|
||||
|
@ -1405,11 +1424,13 @@ unsafe fn yaml_emitter_analyze_event(
|
|||
implicit,
|
||||
..
|
||||
} => {
|
||||
let (anchor, tag, implicit) = (*anchor, *tag, *implicit);
|
||||
|
||||
if !anchor.is_null() {
|
||||
yaml_emitter_analyze_anchor(emitter, *anchor, false)?;
|
||||
yaml_emitter_analyze_anchor(emitter, anchor, false)?;
|
||||
}
|
||||
if !tag.is_null() && (emitter.canonical || !*implicit) {
|
||||
yaml_emitter_analyze_tag(emitter, *tag)?;
|
||||
if !tag.is_null() && (emitter.canonical || !implicit) {
|
||||
yaml_emitter_analyze_tag(emitter, tag)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1419,11 +1440,12 @@ unsafe fn yaml_emitter_analyze_event(
|
|||
implicit,
|
||||
..
|
||||
} => {
|
||||
let (anchor, tag, implicit) = (*anchor, *tag, *implicit);
|
||||
if !anchor.is_null() {
|
||||
yaml_emitter_analyze_anchor(emitter, *anchor, false)?;
|
||||
yaml_emitter_analyze_anchor(emitter, anchor, false)?;
|
||||
}
|
||||
if !tag.is_null() && (emitter.canonical || !*implicit) {
|
||||
yaml_emitter_analyze_tag(emitter, *tag)?;
|
||||
if !tag.is_null() && (emitter.canonical || !implicit) {
|
||||
yaml_emitter_analyze_tag(emitter, tag)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -450,80 +450,6 @@ macro_rules! POP {
|
|||
|
||||
macro_rules! QUEUE_INIT {
|
||||
($queue:expr, $type:ty) => {{
|
||||
$queue.start = yaml_malloc(16 * size_of::<$type>() as libc::c_ulong) as *mut $type;
|
||||
$queue.tail = $queue.start;
|
||||
$queue.head = $queue.tail;
|
||||
$queue.end = $queue.start.offset(16_isize);
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! QUEUE_DEL {
|
||||
($queue:expr) => {
|
||||
yaml_free($queue.start as *mut libc::c_void);
|
||||
$queue.end = ptr::null_mut();
|
||||
$queue.tail = ptr::null_mut();
|
||||
$queue.head = ptr::null_mut();
|
||||
$queue.start = ptr::null_mut();
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! QUEUE_EMPTY {
|
||||
($queue:expr) => {
|
||||
$queue.head == $queue.tail
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! ENQUEUE {
|
||||
(do $queue:expr, $enqueue:expr) => {{
|
||||
if $queue.tail == $queue.end {
|
||||
yaml_queue_extend(
|
||||
addr_of_mut!($queue.start) as *mut *mut libc::c_void,
|
||||
addr_of_mut!($queue.head) as *mut *mut libc::c_void,
|
||||
addr_of_mut!($queue.tail) as *mut *mut libc::c_void,
|
||||
addr_of_mut!($queue.end) as *mut *mut libc::c_void,
|
||||
);
|
||||
}
|
||||
$enqueue;
|
||||
$queue.tail = $queue.tail.wrapping_offset(1);
|
||||
}};
|
||||
($queue:expr, *$value:expr) => {
|
||||
ENQUEUE!(do $queue, ptr::copy_nonoverlapping($value, $queue.tail, 1))
|
||||
};
|
||||
($queue:expr, $value:expr) => {
|
||||
ENQUEUE!(do $queue, ptr::write($queue.tail, $value))
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! DEQUEUE {
|
||||
($queue:expr) => {{
|
||||
let head = $queue.head;
|
||||
$queue.head = $queue.head.wrapping_offset(1);
|
||||
core::ptr::read(head)
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! QUEUE_INSERT {
|
||||
($queue:expr, $index:expr, $value:expr) => {{
|
||||
if $queue.tail == $queue.end {
|
||||
yaml_queue_extend(
|
||||
addr_of_mut!($queue.start) as *mut *mut libc::c_void,
|
||||
addr_of_mut!($queue.head) as *mut *mut libc::c_void,
|
||||
addr_of_mut!($queue.tail) as *mut *mut libc::c_void,
|
||||
addr_of_mut!($queue.end) as *mut *mut libc::c_void,
|
||||
);
|
||||
}
|
||||
memmove(
|
||||
$queue
|
||||
.head
|
||||
.wrapping_offset($index as isize)
|
||||
.wrapping_offset(1_isize) as *mut libc::c_void,
|
||||
$queue.head.wrapping_offset($index as isize) as *const libc::c_void,
|
||||
($queue.tail.c_offset_from($queue.head) as libc::c_ulong)
|
||||
.wrapping_sub($index)
|
||||
.wrapping_mul(size_of::<yaml_token_t>() as libc::c_ulong),
|
||||
);
|
||||
*$queue.head.wrapping_offset($index as isize) = $value;
|
||||
let tail = &mut $queue.tail;
|
||||
*tail = (*tail).wrapping_offset(1);
|
||||
$queue.reserve(16);
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ use core::ptr::{self, addr_of_mut};
|
|||
|
||||
unsafe fn PEEK_TOKEN(parser: &mut yaml_parser_t) -> *mut yaml_token_t {
|
||||
if parser.token_available || yaml_parser_fetch_more_tokens(parser).is_ok() {
|
||||
parser.tokens.head
|
||||
parser.tokens.front_mut().unwrap() as *mut _
|
||||
} else {
|
||||
ptr::null_mut::<yaml_token_t>()
|
||||
}
|
||||
|
@ -35,12 +35,14 @@ unsafe fn PEEK_TOKEN(parser: &mut yaml_parser_t) -> *mut yaml_token_t {
|
|||
unsafe fn SKIP_TOKEN(parser: &mut yaml_parser_t) {
|
||||
parser.token_available = false;
|
||||
parser.tokens_parsed = parser.tokens_parsed.wrapping_add(1);
|
||||
parser.stream_end_produced = if let YamlTokenData::StreamEnd = &(*parser.tokens.head).data {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
parser.tokens.head = parser.tokens.head.wrapping_offset(1);
|
||||
let skipped = parser.tokens.pop_front();
|
||||
parser.stream_end_produced = matches!(
|
||||
skipped,
|
||||
Some(yaml_token_t {
|
||||
data: YamlTokenData::StreamEnd,
|
||||
..
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/// Parse the input stream and produce the next parsing event.
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
use crate::api::{
|
||||
yaml_free, yaml_malloc, yaml_queue_extend, yaml_stack_extend, yaml_string_extend,
|
||||
yaml_string_join,
|
||||
};
|
||||
use crate::externs::{memcpy, memmove, memset, strcmp, strlen};
|
||||
use crate::api::{yaml_free, yaml_malloc, yaml_stack_extend, yaml_string_extend, yaml_string_join};
|
||||
use crate::externs::{memcpy, memset, strcmp, strlen};
|
||||
use crate::ops::{ForceAdd as _, ForceMul as _};
|
||||
use crate::reader::yaml_parser_update_buffer;
|
||||
use crate::yaml::{ptrdiff_t, size_t, yaml_char_t, yaml_string_t, YamlTokenData, NULL_STRING};
|
||||
|
@ -12,7 +9,6 @@ use crate::{
|
|||
YAML_MEMORY_ERROR, YAML_NO_ERROR, YAML_PLAIN_SCALAR_STYLE, YAML_SCANNER_ERROR,
|
||||
YAML_SINGLE_QUOTED_SCALAR_STYLE,
|
||||
};
|
||||
use core::mem::size_of;
|
||||
use core::ptr::{self, addr_of_mut};
|
||||
|
||||
unsafe fn CACHE(parser: &mut yaml_parser_t, length: size_t) -> Result<(), ()> {
|
||||
|
@ -128,13 +124,18 @@ pub unsafe fn yaml_parser_scan(
|
|||
return Err(());
|
||||
}
|
||||
}
|
||||
*token = DEQUEUE!(parser.tokens);
|
||||
parser.token_available = false;
|
||||
parser.tokens_parsed = parser.tokens_parsed.force_add(1);
|
||||
if let YamlTokenData::StreamEnd = &(*token).data {
|
||||
parser.stream_end_produced = true;
|
||||
if let Some(popped) = parser.tokens.pop_front() {
|
||||
*token = popped;
|
||||
parser.token_available = false;
|
||||
parser.tokens_parsed = parser.tokens_parsed.force_add(1);
|
||||
if let YamlTokenData::StreamEnd = &(*token).data {
|
||||
parser.stream_end_produced = true;
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
// token_available should have been false
|
||||
unreachable!()
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn yaml_parser_set_scanner_error(
|
||||
|
@ -154,7 +155,7 @@ pub(crate) unsafe fn yaml_parser_fetch_more_tokens(parser: &mut yaml_parser_t) -
|
|||
let mut need_more_tokens;
|
||||
loop {
|
||||
need_more_tokens = false;
|
||||
if parser.tokens.head == parser.tokens.tail {
|
||||
if parser.tokens.is_empty() {
|
||||
need_more_tokens = true;
|
||||
} else {
|
||||
let mut simple_key: *mut yaml_simple_key_t;
|
||||
|
@ -336,7 +337,7 @@ unsafe fn yaml_parser_save_simple_key(parser: &mut yaml_parser_t) -> Result<(),
|
|||
required,
|
||||
token_number: parser
|
||||
.tokens_parsed
|
||||
.force_add(parser.tokens.tail.c_offset_from(parser.tokens.head) as libc::c_ulong),
|
||||
.force_add(parser.tokens.len() as libc::c_ulong),
|
||||
mark: parser.mark,
|
||||
};
|
||||
if yaml_parser_remove_simple_key(parser).is_err() {
|
||||
|
@ -414,12 +415,11 @@ unsafe fn yaml_parser_roll_indent(
|
|||
end_mark: mark,
|
||||
};
|
||||
if number == -1_i64 {
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
} else {
|
||||
QUEUE_INSERT!(
|
||||
parser.tokens,
|
||||
(number as libc::c_ulong).wrapping_sub(parser.tokens_parsed),
|
||||
token
|
||||
parser.tokens.insert(
|
||||
(number as libc::c_ulong).wrapping_sub(parser.tokens_parsed) as usize,
|
||||
token,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ unsafe fn yaml_parser_unroll_indent(parser: &mut yaml_parser_t, column: ptrdiff_
|
|||
start_mark: parser.mark,
|
||||
end_mark: parser.mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
parser.indent = POP!(parser.indents);
|
||||
}
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ unsafe fn yaml_parser_fetch_stream_start(parser: &mut yaml_parser_t) {
|
|||
start_mark: parser.mark,
|
||||
end_mark: parser.mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
}
|
||||
|
||||
unsafe fn yaml_parser_fetch_stream_end(parser: &mut yaml_parser_t) -> Result<(), ()> {
|
||||
|
@ -481,7 +481,7 @@ unsafe fn yaml_parser_fetch_stream_end(parser: &mut yaml_parser_t) -> Result<(),
|
|||
start_mark: parser.mark,
|
||||
end_mark: parser.mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -495,7 +495,7 @@ unsafe fn yaml_parser_fetch_directive(parser: &mut yaml_parser_t) -> Result<(),
|
|||
if yaml_parser_scan_directive(parser, &mut token).is_err() {
|
||||
return Err(());
|
||||
}
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -519,7 +519,7 @@ unsafe fn yaml_parser_fetch_document_indicator(
|
|||
start_mark,
|
||||
end_mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -542,7 +542,7 @@ unsafe fn yaml_parser_fetch_flow_collection_start(
|
|||
start_mark,
|
||||
end_mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ unsafe fn yaml_parser_fetch_flow_collection_end(
|
|||
start_mark,
|
||||
end_mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -580,7 +580,7 @@ unsafe fn yaml_parser_fetch_flow_entry(parser: &mut yaml_parser_t) -> Result<(),
|
|||
start_mark,
|
||||
end_mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -619,7 +619,7 @@ unsafe fn yaml_parser_fetch_block_entry(parser: &mut yaml_parser_t) -> Result<()
|
|||
start_mark,
|
||||
end_mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -658,7 +658,7 @@ unsafe fn yaml_parser_fetch_key(parser: &mut yaml_parser_t) -> Result<(), ()> {
|
|||
start_mark,
|
||||
end_mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -670,10 +670,9 @@ unsafe fn yaml_parser_fetch_value(parser: &mut yaml_parser_t) -> Result<(), ()>
|
|||
start_mark: (*simple_key).mark,
|
||||
end_mark: (*simple_key).mark,
|
||||
};
|
||||
QUEUE_INSERT!(
|
||||
parser.tokens,
|
||||
((*simple_key).token_number).wrapping_sub(parser.tokens_parsed),
|
||||
token
|
||||
parser.tokens.insert(
|
||||
((*simple_key).token_number).wrapping_sub(parser.tokens_parsed) as usize,
|
||||
token,
|
||||
);
|
||||
yaml_parser_roll_indent(
|
||||
parser,
|
||||
|
@ -713,7 +712,7 @@ unsafe fn yaml_parser_fetch_value(parser: &mut yaml_parser_t) -> Result<(), ()>
|
|||
start_mark,
|
||||
end_mark,
|
||||
};
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -727,7 +726,7 @@ unsafe fn yaml_parser_fetch_anchor(
|
|||
}
|
||||
parser.simple_key_allowed = false;
|
||||
yaml_parser_scan_anchor(parser, &mut token, fetch_alias_instead_of_anchor)?;
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -738,7 +737,7 @@ unsafe fn yaml_parser_fetch_tag(parser: &mut yaml_parser_t) -> Result<(), ()> {
|
|||
}
|
||||
parser.simple_key_allowed = false;
|
||||
yaml_parser_scan_tag(parser, &mut token)?;
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -750,7 +749,7 @@ unsafe fn yaml_parser_fetch_block_scalar(
|
|||
yaml_parser_remove_simple_key(parser)?;
|
||||
parser.simple_key_allowed = true;
|
||||
yaml_parser_scan_block_scalar(parser, &mut token, literal)?;
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -762,7 +761,7 @@ unsafe fn yaml_parser_fetch_flow_scalar(
|
|||
yaml_parser_save_simple_key(parser)?;
|
||||
parser.simple_key_allowed = false;
|
||||
yaml_parser_scan_flow_scalar(parser, &mut token, single)?;
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -771,7 +770,7 @@ unsafe fn yaml_parser_fetch_plain_scalar(parser: &mut yaml_parser_t) -> Result<(
|
|||
yaml_parser_save_simple_key(parser)?;
|
||||
parser.simple_key_allowed = false;
|
||||
yaml_parser_scan_plain_scalar(parser, &mut token)?;
|
||||
ENQUEUE!(parser.tokens, token);
|
||||
parser.tokens.push_back(token);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
193
src/yaml.rs
193
src/yaml.rs
|
@ -1,3 +1,5 @@
|
|||
use alloc::collections::VecDeque;
|
||||
|
||||
use crate::libc;
|
||||
use core::ops::Deref;
|
||||
use core::ptr::{self, addr_of};
|
||||
|
@ -26,11 +28,12 @@ pub struct yaml_tag_directive_t {
|
|||
}
|
||||
|
||||
/// The stream encoding.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[repr(u32)]
|
||||
#[non_exhaustive]
|
||||
pub enum yaml_encoding_t {
|
||||
/// Let the parser choose the encoding.
|
||||
#[default]
|
||||
YAML_ANY_ENCODING = 0,
|
||||
/// The default UTF-8 encoding.
|
||||
YAML_UTF8_ENCODING = 1,
|
||||
|
@ -41,11 +44,12 @@ pub enum yaml_encoding_t {
|
|||
}
|
||||
|
||||
/// Line break type.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[repr(u32)]
|
||||
#[non_exhaustive]
|
||||
pub enum yaml_break_t {
|
||||
/// Let the parser choose the break type.
|
||||
#[default]
|
||||
YAML_ANY_BREAK = 0,
|
||||
/// Use CR for line breaks (Mac style).
|
||||
YAML_CR_BREAK = 1,
|
||||
|
@ -56,11 +60,12 @@ pub enum yaml_break_t {
|
|||
}
|
||||
|
||||
/// Many bad things could happen with the parser and emitter.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[repr(u32)]
|
||||
#[non_exhaustive]
|
||||
pub enum yaml_error_type_t {
|
||||
/// No error is produced.
|
||||
#[default]
|
||||
YAML_NO_ERROR = 0,
|
||||
/// Cannot allocate or reallocate a block of memory.
|
||||
YAML_MEMORY_ERROR = 1,
|
||||
|
@ -92,11 +97,12 @@ pub struct yaml_mark_t {
|
|||
}
|
||||
|
||||
/// Scalar styles.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[repr(u32)]
|
||||
#[non_exhaustive]
|
||||
pub enum yaml_scalar_style_t {
|
||||
/// Let the emitter choose the style.
|
||||
#[default]
|
||||
YAML_ANY_SCALAR_STYLE = 0,
|
||||
/// The plain scalar style.
|
||||
YAML_PLAIN_SCALAR_STYLE = 1,
|
||||
|
@ -602,11 +608,12 @@ pub struct yaml_simple_key_t {
|
|||
}
|
||||
|
||||
/// The states of the parser.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[repr(u32)]
|
||||
#[non_exhaustive]
|
||||
pub enum yaml_parser_state_t {
|
||||
/// Expect STREAM-START.
|
||||
#[default]
|
||||
YAML_PARSE_STREAM_START_STATE = 0,
|
||||
/// Expect the beginning of an implicit document.
|
||||
YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE = 1,
|
||||
|
@ -737,7 +744,7 @@ pub struct yaml_parser_t {
|
|||
/// The number of unclosed '[' and '{' indicators.
|
||||
pub(crate) flow_level: libc::c_int,
|
||||
/// The tokens queue.
|
||||
pub(crate) tokens: yaml_queue_t<yaml_token_t>,
|
||||
pub(crate) tokens: VecDeque<yaml_token_t>,
|
||||
/// The number of tokens fetched from the queue.
|
||||
pub(crate) tokens_parsed: size_t,
|
||||
/// Does the tokens queue contain a token ready for dequeueing.
|
||||
|
@ -764,6 +771,46 @@ pub struct yaml_parser_t {
|
|||
pub(crate) document: *mut yaml_document_t,
|
||||
}
|
||||
|
||||
impl Default for yaml_parser_t {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
error: Default::default(),
|
||||
problem: Default::default(),
|
||||
problem_offset: Default::default(),
|
||||
problem_value: Default::default(),
|
||||
problem_mark: Default::default(),
|
||||
context: Default::default(),
|
||||
context_mark: Default::default(),
|
||||
read_handler: Default::default(),
|
||||
read_handler_data: ptr::null_mut(),
|
||||
input: Default::default(),
|
||||
eof: Default::default(),
|
||||
buffer: Default::default(),
|
||||
unread: Default::default(),
|
||||
raw_buffer: Default::default(),
|
||||
encoding: Default::default(),
|
||||
offset: Default::default(),
|
||||
mark: Default::default(),
|
||||
stream_start_produced: Default::default(),
|
||||
stream_end_produced: Default::default(),
|
||||
flow_level: Default::default(),
|
||||
tokens: Default::default(),
|
||||
tokens_parsed: Default::default(),
|
||||
token_available: Default::default(),
|
||||
indents: Default::default(),
|
||||
indent: Default::default(),
|
||||
simple_key_allowed: Default::default(),
|
||||
simple_keys: Default::default(),
|
||||
states: Default::default(),
|
||||
state: Default::default(),
|
||||
marks: Default::default(),
|
||||
tag_directives: Default::default(),
|
||||
aliases: Default::default(),
|
||||
document: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[non_exhaustive]
|
||||
pub struct yaml_parser_t_prefix {
|
||||
|
@ -801,6 +848,16 @@ pub(crate) struct unnamed_yaml_parser_t_input_string {
|
|||
pub current: *const libc::c_uchar,
|
||||
}
|
||||
|
||||
impl Default for unnamed_yaml_parser_t_input_string {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
start: ptr::null(),
|
||||
end: ptr::null(),
|
||||
current: ptr::null(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The prototype of a write handler.
|
||||
///
|
||||
/// The write handler is called when the emitter needs to flush the accumulated
|
||||
|
@ -813,11 +870,12 @@ pub type yaml_write_handler_t =
|
|||
unsafe fn(data: *mut libc::c_void, buffer: *mut libc::c_uchar, size: size_t) -> libc::c_int;
|
||||
|
||||
/// The emitter states.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[repr(u32)]
|
||||
#[non_exhaustive]
|
||||
pub enum yaml_emitter_state_t {
|
||||
/// Expect STREAM-START.
|
||||
#[default]
|
||||
YAML_EMIT_STREAM_START_STATE = 0,
|
||||
/// Expect the first DOCUMENT-START or STREAM-END.
|
||||
YAML_EMIT_FIRST_DOCUMENT_START_STATE = 1,
|
||||
|
@ -907,7 +965,7 @@ pub struct yaml_emitter_t {
|
|||
/// The current emitter state.
|
||||
pub(crate) state: yaml_emitter_state_t,
|
||||
/// The event queue.
|
||||
pub(crate) events: yaml_queue_t<yaml_event_t>,
|
||||
pub(crate) events: VecDeque<yaml_event_t>,
|
||||
/// The stack of indentation levels.
|
||||
pub(crate) indents: yaml_stack_t<libc::c_int>,
|
||||
/// The list of tag directives.
|
||||
|
@ -953,6 +1011,50 @@ pub struct yaml_emitter_t {
|
|||
pub(crate) document: *mut yaml_document_t,
|
||||
}
|
||||
|
||||
impl Default for yaml_emitter_t {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
error: Default::default(),
|
||||
problem: Default::default(),
|
||||
write_handler: Default::default(),
|
||||
write_handler_data: ptr::null_mut(),
|
||||
output: Default::default(),
|
||||
buffer: Default::default(),
|
||||
raw_buffer: Default::default(),
|
||||
encoding: Default::default(),
|
||||
canonical: Default::default(),
|
||||
best_indent: Default::default(),
|
||||
best_width: Default::default(),
|
||||
unicode: Default::default(),
|
||||
line_break: Default::default(),
|
||||
states: Default::default(),
|
||||
state: Default::default(),
|
||||
events: Default::default(),
|
||||
indents: Default::default(),
|
||||
tag_directives: Default::default(),
|
||||
indent: Default::default(),
|
||||
flow_level: Default::default(),
|
||||
root_context: Default::default(),
|
||||
sequence_context: Default::default(),
|
||||
mapping_context: Default::default(),
|
||||
simple_key_context: Default::default(),
|
||||
line: Default::default(),
|
||||
column: Default::default(),
|
||||
whitespace: Default::default(),
|
||||
indention: Default::default(),
|
||||
open_ended: Default::default(),
|
||||
anchor_data: Default::default(),
|
||||
tag_data: Default::default(),
|
||||
scalar_data: Default::default(),
|
||||
opened: Default::default(),
|
||||
closed: Default::default(),
|
||||
anchors: ptr::null_mut(),
|
||||
last_anchor_id: Default::default(),
|
||||
document: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[non_exhaustive]
|
||||
pub struct yaml_emitter_t_prefix {
|
||||
|
@ -980,6 +1082,16 @@ pub(crate) struct unnamed_yaml_emitter_t_output_string {
|
|||
pub size_written: *mut size_t,
|
||||
}
|
||||
|
||||
impl Default for unnamed_yaml_emitter_t_output_string {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
buffer: ptr::null_mut(),
|
||||
size: 0,
|
||||
size_written: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub(crate) struct unnamed_yaml_emitter_t_anchor_data {
|
||||
/// The anchor value.
|
||||
|
@ -990,6 +1102,16 @@ pub(crate) struct unnamed_yaml_emitter_t_anchor_data {
|
|||
pub alias: bool,
|
||||
}
|
||||
|
||||
impl Default for unnamed_yaml_emitter_t_anchor_data {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
anchor: ptr::null_mut(),
|
||||
anchor_length: 0,
|
||||
alias: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub(crate) struct unnamed_yaml_emitter_t_tag_data {
|
||||
/// The tag handle.
|
||||
|
@ -1002,6 +1124,17 @@ pub(crate) struct unnamed_yaml_emitter_t_tag_data {
|
|||
pub suffix_length: size_t,
|
||||
}
|
||||
|
||||
impl Default for unnamed_yaml_emitter_t_tag_data {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
handle: ptr::null_mut(),
|
||||
handle_length: 0,
|
||||
suffix: ptr::null_mut(),
|
||||
suffix_length: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub(crate) struct unnamed_yaml_emitter_t_scalar_data {
|
||||
/// The scalar value.
|
||||
|
@ -1022,6 +1155,21 @@ pub(crate) struct unnamed_yaml_emitter_t_scalar_data {
|
|||
pub style: yaml_scalar_style_t,
|
||||
}
|
||||
|
||||
impl Default for unnamed_yaml_emitter_t_scalar_data {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
value: ptr::null_mut(),
|
||||
length: 0,
|
||||
multiline: false,
|
||||
flow_plain_allowed: false,
|
||||
block_plain_allowed: false,
|
||||
single_quoted_allowed: false,
|
||||
block_allowed: false,
|
||||
style: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub(crate) struct yaml_string_t {
|
||||
pub start: *mut yaml_char_t,
|
||||
|
@ -1057,14 +1205,23 @@ pub struct yaml_stack_t<T> {
|
|||
pub top: *mut T,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub(crate) struct yaml_queue_t<T> {
|
||||
/// The beginning of the queue.
|
||||
pub start: *mut T,
|
||||
/// The end of the queue.
|
||||
pub end: *mut T,
|
||||
/// The head of the queue.
|
||||
pub head: *mut T,
|
||||
/// The tail of the queue.
|
||||
pub tail: *mut T,
|
||||
impl<T> Default for yaml_buffer_t<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
start: ptr::null_mut(),
|
||||
end: ptr::null_mut(),
|
||||
pointer: ptr::null_mut(),
|
||||
last: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for yaml_stack_t<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
start: ptr::null_mut(),
|
||||
end: ptr::null_mut(),
|
||||
top: ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue