Remove more c2rust artifacts (gotos)

This commit is contained in:
Simon Ask Ulsnes 2024-01-31 09:02:16 +01:00
parent edf4843cae
commit 9f681e6306
3 changed files with 98 additions and 156 deletions

View file

@ -50,55 +50,39 @@ pub unsafe fn yaml_emitter_dump(
emitter: &mut yaml_emitter_t,
document: &mut yaml_document_t,
) -> Result<(), ()> {
let current_block: u64;
if !emitter.opened {
if yaml_emitter_open(emitter).is_err() {
current_block = 5018439318894558507;
} else {
current_block = 15619007995458559411;
if let Err(()) = yaml_emitter_open(emitter) {
yaml_emitter_delete_document_and_anchors(emitter, document);
return Err(());
}
}
if document.nodes.is_empty() {
yaml_emitter_close(emitter)?;
} else {
current_block = 15619007995458559411;
}
match current_block {
15619007995458559411 => {
if document.nodes.is_empty() {
if let Ok(()) = yaml_emitter_close(emitter) {
yaml_emitter_delete_document_and_anchors(emitter, document);
return Ok(());
}
} else {
__assert!(emitter.opened);
emitter.anchors = vec![yaml_anchors_t::default(); (*document).nodes.len()];
let event = yaml_event_t {
data: YamlEventData::DocumentStart {
version_directive: (*document).version_directive,
tag_directives: core::mem::take(&mut (*document).tag_directives),
implicit: (*document).start_implicit,
},
..Default::default()
};
if let Ok(()) = yaml_emitter_emit(emitter, event) {
yaml_emitter_anchor_node(emitter, document, 1);
if let Ok(()) = yaml_emitter_dump_node(emitter, document, 1) {
let event = yaml_event_t {
data: YamlEventData::DocumentEnd {
implicit: document.end_implicit,
},
..Default::default()
};
if let Ok(()) = yaml_emitter_emit(emitter, event) {
yaml_emitter_delete_document_and_anchors(emitter, document);
return Ok(());
}
}
}
}
}
_ => {}
__assert!(emitter.opened);
emitter.anchors = vec![yaml_anchors_t::default(); (*document).nodes.len()];
let event = yaml_event_t {
data: YamlEventData::DocumentStart {
version_directive: (*document).version_directive,
tag_directives: core::mem::take(&mut (*document).tag_directives),
implicit: (*document).start_implicit,
},
..Default::default()
};
yaml_emitter_emit(emitter, event)?;
yaml_emitter_anchor_node(emitter, document, 1);
yaml_emitter_dump_node(emitter, document, 1)?;
let event = yaml_event_t {
data: YamlEventData::DocumentEnd {
implicit: document.end_implicit,
},
..Default::default()
};
yaml_emitter_emit(emitter, event)?;
}
yaml_emitter_delete_document_and_anchors(emitter, document);
Err(())
Ok(())
}
unsafe fn yaml_emitter_delete_document_and_anchors(

View file

@ -28,7 +28,6 @@ pub unsafe fn yaml_parser_load(
parser: &mut yaml_parser_t,
document: *mut yaml_document_t,
) -> Result<(), ()> {
let current_block: u64;
let mut event = yaml_event_t::default();
core::ptr::write(document, yaml_document_t::default());
let document = &mut *document;
@ -36,32 +35,30 @@ pub unsafe fn yaml_parser_load(
if !parser.stream_start_produced {
if let Err(()) = yaml_parser_parse(parser, &mut event) {
current_block = 6234624449317607669;
yaml_parser_delete_aliases(parser);
yaml_document_delete(document);
parser.document = ptr::null_mut::<yaml_document_t>();
return Err(());
} else {
if let YamlEventData::StreamStart { .. } = &event.data {
} else {
panic!("expected stream start");
}
current_block = 7815301370352969686;
}
} else {
current_block = 7815301370352969686;
}
if current_block != 6234624449317607669 {
if parser.stream_end_produced {
if parser.stream_end_produced {
return Ok(());
}
if let Ok(()) = yaml_parser_parse(parser, &mut event) {
if let YamlEventData::StreamEnd = &event.data {
return Ok(());
}
if let Ok(()) = yaml_parser_parse(parser, &mut event) {
if let YamlEventData::StreamEnd = &event.data {
return Ok(());
}
parser.aliases.reserve(16);
parser.document = document;
if let Ok(()) = yaml_parser_load_document(parser, &mut event) {
yaml_parser_delete_aliases(parser);
parser.document = ptr::null_mut::<yaml_document_t>();
return Ok(());
}
parser.aliases.reserve(16);
parser.document = document;
if let Ok(()) = yaml_parser_load_document(parser, &mut event) {
yaml_parser_delete_aliases(parser);
parser.document = ptr::null_mut::<yaml_document_t>();
return Ok(());
}
}
yaml_parser_delete_aliases(parser);
@ -210,7 +207,6 @@ unsafe fn yaml_parser_load_node_add(
}
let parent_index: libc::c_int = *ctx.last().unwrap();
let parent = &mut (*parser.document).nodes[parent_index as usize - 1];
let current_block_17: u64;
match parent.data {
YamlNodeData::Sequence { ref mut items, .. } => {
STACK_LIMIT!(parser, items)?;
@ -219,25 +215,19 @@ unsafe fn yaml_parser_load_node_add(
YamlNodeData::Mapping { ref mut pairs, .. } => {
let mut pair = MaybeUninit::<yaml_node_pair_t>::uninit();
let pair = pair.as_mut_ptr();
let mut do_push = true;
if !pairs.is_empty() {
let p: &mut yaml_node_pair_t = pairs.last_mut().unwrap();
if p.key != 0 && p.value == 0 {
p.value = index;
current_block_17 = 11307063007268554308;
} else {
current_block_17 = 17407779659766490442;
do_push = false;
}
} else {
current_block_17 = 17407779659766490442;
}
match current_block_17 {
11307063007268554308 => {}
_ => {
(*pair).key = index;
(*pair).value = 0;
STACK_LIMIT!(parser, pairs)?;
pairs.push(*pair);
}
if do_push {
(*pair).key = index;
(*pair).value = 0;
STACK_LIMIT!(parser, pairs)?;
pairs.push(*pair);
}
}
_ => {

View file

@ -838,7 +838,6 @@ unsafe fn yaml_parser_scan_directive(
parser: &mut yaml_parser_t,
token: &mut yaml_token_t,
) -> Result<(), ()> {
let mut current_block: u64;
let end_mark: yaml_mark_t;
let mut major: libc::c_int = 0;
let mut minor: libc::c_int = 0;
@ -846,31 +845,22 @@ unsafe fn yaml_parser_scan_directive(
SKIP(parser);
if let Ok(name) = yaml_parser_scan_directive_name(parser, start_mark) {
if name == "YAML" {
if let Err(()) =
yaml_parser_scan_version_directive_value(parser, start_mark, &mut major, &mut minor)
{
current_block = 11397968426844348457;
} else {
end_mark = parser.mark;
*token = yaml_token_t {
data: YamlTokenData::VersionDirective { major, minor },
start_mark,
end_mark,
};
current_block = 17407779659766490442;
}
yaml_parser_scan_version_directive_value(parser, start_mark, &mut major, &mut minor)?;
end_mark = parser.mark;
*token = yaml_token_t {
data: YamlTokenData::VersionDirective { major, minor },
start_mark,
end_mark,
};
} else if name == "TAG" {
if let Ok((handle, prefix)) = yaml_parser_scan_tag_directive_value(parser, start_mark) {
end_mark = parser.mark;
*token = yaml_token_t {
data: YamlTokenData::TagDirective { handle, prefix },
start_mark,
end_mark,
};
current_block = 17407779659766490442;
} else {
current_block = 11397968426844348457;
}
let (handle, prefix) = yaml_parser_scan_tag_directive_value(parser, start_mark)?;
end_mark = parser.mark;
*token = yaml_token_t {
data: YamlTokenData::TagDirective { handle, prefix },
start_mark,
end_mark,
};
} else {
yaml_parser_set_scanner_error(
parser,
@ -878,63 +868,41 @@ unsafe fn yaml_parser_scan_directive(
start_mark,
"found unknown directive name",
);
current_block = 11397968426844348457;
return Err(());
}
if current_block != 11397968426844348457 {
if let Ok(()) = CACHE(parser, 1_u64) {
loop {
if !IS_BLANK!(parser.buffer) {
current_block = 11584701595673473500;
break;
}
SKIP(parser);
if let Err(()) = CACHE(parser, 1_u64) {
current_block = 11397968426844348457;
break;
}
}
if current_block != 11397968426844348457 {
if CHECK!(parser.buffer, b'#') {
loop {
if IS_BREAKZ!(parser.buffer) {
current_block = 6669252993407410313;
break;
}
SKIP(parser);
if let Err(()) = CACHE(parser, 1_u64) {
current_block = 11397968426844348457;
break;
}
}
} else {
current_block = 6669252993407410313;
}
if current_block != 11397968426844348457 {
if !IS_BREAKZ!(parser.buffer) {
yaml_parser_set_scanner_error(
parser,
"while scanning a directive",
start_mark,
"did not find expected comment or line break",
);
} else {
if IS_BREAK!(parser.buffer) {
if let Err(()) = CACHE(parser, 2_u64) {
current_block = 11397968426844348457;
} else {
SKIP_LINE(parser);
current_block = 652864300344834934;
}
} else {
current_block = 652864300344834934;
}
if current_block != 11397968426844348457 {
return Ok(());
}
}
}
}
CACHE(parser, 1_u64)?;
loop {
if !IS_BLANK!(parser.buffer) {
break;
}
SKIP(parser);
CACHE(parser, 1_u64)?;
}
if CHECK!(parser.buffer, b'#') {
loop {
if IS_BREAKZ!(parser.buffer) {
break;
}
SKIP(parser);
CACHE(parser, 1_u64)?;
}
}
if !IS_BREAKZ!(parser.buffer) {
yaml_parser_set_scanner_error(
parser,
"while scanning a directive",
start_mark,
"did not find expected comment or line break",
);
return Err(());
} else {
if IS_BREAK!(parser.buffer) {
CACHE(parser, 2_u64)?;
SKIP_LINE(parser);
}
return Ok(());
}
}
Err(())