Eliminate return value of stack init

This commit is contained in:
David Tolnay 2022-07-30 01:11:31 -07:00
parent 82fd332271
commit e0a86e6089
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
4 changed files with 360 additions and 396 deletions

View file

@ -185,18 +185,13 @@ pub unsafe fn yaml_parser_initialize(parser: *mut yaml_parser_t) -> Success {
BUFFER_INIT!(parser, (*parser).raw_buffer, INPUT_RAW_BUFFER_SIZE);
BUFFER_INIT!(parser, (*parser).buffer, INPUT_BUFFER_SIZE);
if QUEUE_INIT!(parser, (*parser).tokens, yaml_token_t).ok {
if STACK_INIT!(parser, (*parser).indents, libc::c_int).ok {
if STACK_INIT!(parser, (*parser).simple_keys, yaml_simple_key_t).ok {
if STACK_INIT!(parser, (*parser).states, yaml_parser_state_t).ok {
if STACK_INIT!(parser, (*parser).marks, yaml_mark_t).ok {
if STACK_INIT!(parser, (*parser).tag_directives, yaml_tag_directive_t).ok {
STACK_INIT!(parser, (*parser).indents, libc::c_int);
STACK_INIT!(parser, (*parser).simple_keys, yaml_simple_key_t);
STACK_INIT!(parser, (*parser).states, yaml_parser_state_t);
STACK_INIT!(parser, (*parser).marks, yaml_mark_t);
STACK_INIT!(parser, (*parser).tag_directives, yaml_tag_directive_t);
return OK;
}
}
}
}
}
}
BUFFER_DEL!((*parser).raw_buffer);
BUFFER_DEL!((*parser).buffer);
QUEUE_DEL!((*parser).tokens);
@ -331,15 +326,12 @@ pub unsafe fn yaml_emitter_initialize(mut emitter: *mut yaml_emitter_t) -> Succe
);
BUFFER_INIT!(emitter, (*emitter).buffer, OUTPUT_BUFFER_SIZE);
BUFFER_INIT!(emitter, (*emitter).raw_buffer, OUTPUT_RAW_BUFFER_SIZE);
if STACK_INIT!(emitter, (*emitter).states, yaml_emitter_state_t).ok {
STACK_INIT!(emitter, (*emitter).states, yaml_emitter_state_t);
if QUEUE_INIT!(emitter, (*emitter).events, yaml_event_t).ok {
if STACK_INIT!(emitter, (*emitter).indents, libc::c_int).ok {
if STACK_INIT!(emitter, (*emitter).tag_directives, yaml_tag_directive_t).ok {
STACK_INIT!(emitter, (*emitter).indents, libc::c_int);
STACK_INIT!(emitter, (*emitter).tag_directives, yaml_tag_directive_t);
return OK;
}
}
}
}
BUFFER_DEL!((*emitter).buffer);
BUFFER_DEL!((*emitter).raw_buffer);
STACK_DEL!((*emitter).states);
@ -687,15 +679,11 @@ pub unsafe fn yaml_document_start_event_initialize(
1394248824506584008 => {
if tag_directives_start != tag_directives_end {
let mut tag_directive: *mut yaml_tag_directive_t;
if STACK_INIT!(
STACK_INIT!(
addr_of_mut!(context),
tag_directives_copy,
yaml_tag_directive_t
)
.fail
{
current_block = 14964981520188694172;
} else {
);
tag_directive = tag_directives_start;
loop {
if !(tag_directive != tag_directives_end) {
@ -736,7 +724,6 @@ pub unsafe fn yaml_document_start_event_initialize(
value.prefix = ptr::null_mut::<yaml_char_t>();
tag_directive = tag_directive.wrapping_offset(1);
}
}
} else {
current_block = 16203760046146113240;
}
@ -1222,10 +1209,9 @@ pub unsafe fn yaml_document_initialize(
!tag_directives_start.is_null() && !tag_directives_end.is_null()
|| tag_directives_start == tag_directives_end
);
if STACK_INIT!(addr_of_mut!(context), nodes, yaml_node_t).ok {
STACK_INIT!(addr_of_mut!(context), nodes, yaml_node_t);
if !version_directive.is_null() {
version_directive_copy =
yaml_malloc(size_of::<yaml_version_directive_t>() as libc::c_ulong)
version_directive_copy = yaml_malloc(size_of::<yaml_version_directive_t>() as libc::c_ulong)
as *mut yaml_version_directive_t;
(*version_directive_copy).major = (*version_directive).major;
(*version_directive_copy).minor = (*version_directive).minor;
@ -1238,15 +1224,11 @@ pub unsafe fn yaml_document_initialize(
_ => {
if tag_directives_start != tag_directives_end {
let mut tag_directive: *mut yaml_tag_directive_t;
if STACK_INIT!(
STACK_INIT!(
addr_of_mut!(context),
tag_directives_copy,
yaml_tag_directive_t
)
.fail
{
current_block = 8142820162064489797;
} else {
);
tag_directive = tag_directives_start;
loop {
if !(tag_directive != tag_directives_end) {
@ -1287,7 +1269,6 @@ pub unsafe fn yaml_document_initialize(
value.prefix = ptr::null_mut::<yaml_char_t>();
tag_directive = tag_directive.wrapping_offset(1);
}
}
} else {
current_block = 14818589718467733107;
}
@ -1320,7 +1301,6 @@ pub unsafe fn yaml_document_initialize(
}
}
}
}
STACK_DEL!(nodes);
yaml_free(version_directive_copy as *mut libc::c_void);
while !STACK_EMPTY!(tag_directives_copy) {
@ -1519,7 +1499,7 @@ pub unsafe fn yaml_document_add_sequence(
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).ok {
tag_copy = yaml_strdup(tag);
if !tag_copy.is_null() {
if STACK_INIT!(addr_of_mut!(context), items, yaml_node_item_t).ok {
STACK_INIT!(addr_of_mut!(context), items, yaml_node_item_t);
memset(
node as *mut libc::c_void,
0,
@ -1534,9 +1514,7 @@ pub unsafe fn yaml_document_add_sequence(
(*node).data.sequence.items.top = items.start;
(*node).data.sequence.style = style;
if PUSH!(addr_of_mut!(context), (*document).nodes, *node).ok {
return (*document).nodes.top.c_offset_from((*document).nodes.start)
as libc::c_int;
}
return (*document).nodes.top.c_offset_from((*document).nodes.start) as libc::c_int;
}
}
}
@ -1584,7 +1562,7 @@ pub unsafe fn yaml_document_add_mapping(
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).ok {
tag_copy = yaml_strdup(tag);
if !tag_copy.is_null() {
if STACK_INIT!(addr_of_mut!(context), pairs, yaml_node_pair_t).ok {
STACK_INIT!(addr_of_mut!(context), pairs, yaml_node_pair_t);
memset(
node as *mut libc::c_void,
0,
@ -1599,9 +1577,7 @@ pub unsafe fn yaml_document_add_mapping(
(*node).data.mapping.pairs.top = pairs.start;
(*node).data.mapping.style = style;
if PUSH!(addr_of_mut!(context), (*document).nodes, *node).ok {
return (*document).nodes.top.c_offset_from((*document).nodes.start)
as libc::c_int;
}
return (*document).nodes.top.c_offset_from((*document).nodes.start) as libc::c_int;
}
}
}

View file

@ -48,7 +48,7 @@ pub unsafe fn yaml_parser_load(
0,
size_of::<yaml_document_t>() as libc::c_ulong,
);
if STACK_INIT!(parser, (*document).nodes, yaml_node_t).ok {
STACK_INIT!(parser, (*document).nodes, yaml_node_t);
if !(*parser).stream_start_produced {
if yaml_parser_parse(parser, event).fail {
current_block = 6234624449317607669;
@ -69,7 +69,7 @@ pub unsafe fn yaml_parser_load(
if (*event).type_ == YAML_STREAM_END_EVENT {
return OK;
}
if STACK_INIT!(parser, (*parser).aliases, yaml_alias_data_t).ok {
STACK_INIT!(parser, (*parser).aliases, yaml_alias_data_t);
let fresh6 = addr_of_mut!((*parser).document);
*fresh6 = document;
if yaml_parser_load_document(parser, event).ok {
@ -81,8 +81,6 @@ pub unsafe fn yaml_parser_load(
}
}
}
}
}
yaml_parser_delete_aliases(parser);
yaml_document_delete(document);
let fresh8 = addr_of_mut!((*parser).document);
@ -144,9 +142,7 @@ unsafe fn yaml_parser_load_document(
*fresh18 = (*event).data.document_start.tag_directives.end;
(*(*parser).document).start_implicit = (*event).data.document_start.implicit;
(*(*parser).document).start_mark = (*event).start_mark;
if STACK_INIT!(parser, ctx, libc::c_int).fail {
return FAIL;
}
STACK_INIT!(parser, ctx, libc::c_int);
if yaml_parser_load_nodes(parser, addr_of_mut!(ctx)).fail {
STACK_DEL!(ctx);
return FAIL;
@ -442,7 +438,7 @@ unsafe fn yaml_parser_load_sequence(
match current_block {
13474536459355229096 => {}
_ => {
if STACK_INIT!(parser, items, yaml_node_item_t).ok {
STACK_INIT!(parser, items, yaml_node_item_t);
memset(
node as *mut libc::c_void,
0,
@ -485,7 +481,6 @@ unsafe fn yaml_parser_load_sequence(
}
}
}
}
yaml_free(tag as *mut libc::c_void);
yaml_free((*event).data.sequence_start.anchor as *mut libc::c_void);
FAIL
@ -553,7 +548,7 @@ unsafe fn yaml_parser_load_mapping(
match current_block {
13635467803606088781 => {}
_ => {
if STACK_INIT!(parser, pairs, yaml_node_pair_t).ok {
STACK_INIT!(parser, pairs, yaml_node_pair_t);
memset(
node as *mut libc::c_void,
0,
@ -596,7 +591,6 @@ unsafe fn yaml_parser_load_mapping(
}
}
}
}
yaml_free(tag as *mut libc::c_void);
yaml_free((*event).data.mapping_start.anchor as *mut libc::c_void);
FAIL

View file

@ -365,7 +365,6 @@ macro_rules! STACK_INIT {
$stack.start = yaml_malloc(16 * size_of::<$type>() as libc::c_ulong) as *mut $type;
$stack.top = $stack.start;
$stack.end = $stack.start.offset(16_isize);
OK
}};
}

View file

@ -1307,7 +1307,7 @@ unsafe fn yaml_parser_process_directives(
top: ptr::null_mut::<yaml_tag_directive_t>(),
};
let mut token: *mut yaml_token_t;
if STACK_INIT!(parser, tag_directives, yaml_tag_directive_t).ok {
STACK_INIT!(parser, tag_directives, yaml_tag_directive_t);
token = PEEK_TOKEN(parser);
if !token.is_null() {
loop {
@ -1321,8 +1321,7 @@ unsafe fn yaml_parser_process_directives(
if !version_directive.is_null() {
yaml_parser_set_parser_error(
parser,
b"found duplicate %YAML directive\0" as *const u8
as *const libc::c_char,
b"found duplicate %YAML directive\0" as *const u8 as *const libc::c_char,
(*token).start_mark,
);
current_block = 17143798186130252483;
@ -1333,8 +1332,7 @@ unsafe fn yaml_parser_process_directives(
{
yaml_parser_set_parser_error(
parser,
b"found incompatible YAML document\0" as *const u8
as *const libc::c_char,
b"found incompatible YAML document\0" as *const u8 as *const libc::c_char,
(*token).start_mark,
);
current_block = 17143798186130252483;
@ -1351,8 +1349,7 @@ unsafe fn yaml_parser_process_directives(
handle: (*token).data.tag_directive.handle,
prefix: (*token).data.tag_directive.prefix,
};
if yaml_parser_append_tag_directive(parser, value, false, (*token).start_mark)
.fail
if yaml_parser_append_tag_directive(parser, value, false, (*token).start_mark).fail
{
current_block = 17143798186130252483;
break;
@ -1399,8 +1396,7 @@ unsafe fn yaml_parser_process_directives(
}
if !tag_directives_start_ref.is_null() {
if STACK_EMPTY!(tag_directives) {
*tag_directives_end_ref =
ptr::null_mut::<yaml_tag_directive_t>();
*tag_directives_end_ref = ptr::null_mut::<yaml_tag_directive_t>();
*tag_directives_start_ref = *tag_directives_end_ref;
STACK_DEL!(tag_directives);
} else {
@ -1419,7 +1415,6 @@ unsafe fn yaml_parser_process_directives(
}
}
}
}
yaml_free(version_directive as *mut libc::c_void);
while !STACK_EMPTY!(tag_directives) {
let tag_directive = POP!(tag_directives);