Eliminate return value of stack push

This commit is contained in:
David Tolnay 2022-07-30 02:00:06 -07:00
parent 560f7b2032
commit 44b9e9795a
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
6 changed files with 126 additions and 289 deletions

View file

@ -3,23 +3,19 @@ use crate::success::{Success, FAIL, OK};
use crate::yaml::{size_t, yaml_char_t}; use crate::yaml::{size_t, yaml_char_t};
use crate::{ use crate::{
libc, yaml_break_t, yaml_document_t, yaml_emitter_state_t, yaml_emitter_t, yaml_encoding_t, libc, yaml_break_t, yaml_document_t, yaml_emitter_state_t, yaml_emitter_t, yaml_encoding_t,
yaml_error_type_t, yaml_event_t, yaml_mapping_style_t, yaml_mark_t, yaml_node_item_t, yaml_event_t, yaml_mapping_style_t, yaml_mark_t, yaml_node_item_t, yaml_node_pair_t,
yaml_node_pair_t, yaml_node_t, yaml_parser_state_t, yaml_parser_t, yaml_read_handler_t, yaml_node_t, yaml_parser_state_t, yaml_parser_t, yaml_read_handler_t, yaml_scalar_style_t,
yaml_scalar_style_t, yaml_sequence_style_t, yaml_simple_key_t, yaml_tag_directive_t, yaml_sequence_style_t, yaml_simple_key_t, yaml_tag_directive_t, yaml_token_t,
yaml_token_t, yaml_version_directive_t, yaml_write_handler_t, PointerExt, YAML_ALIAS_EVENT, yaml_version_directive_t, yaml_write_handler_t, PointerExt, YAML_ALIAS_EVENT, YAML_ALIAS_TOKEN,
YAML_ALIAS_TOKEN, YAML_ANCHOR_TOKEN, YAML_ANY_ENCODING, YAML_DOCUMENT_END_EVENT, YAML_ANCHOR_TOKEN, YAML_ANY_ENCODING, YAML_DOCUMENT_END_EVENT, YAML_DOCUMENT_START_EVENT,
YAML_DOCUMENT_START_EVENT, YAML_MAPPING_END_EVENT, YAML_MAPPING_NODE, YAML_MAPPING_START_EVENT, YAML_MAPPING_END_EVENT, YAML_MAPPING_NODE, YAML_MAPPING_START_EVENT, YAML_SCALAR_EVENT,
YAML_MEMORY_ERROR, YAML_NO_ERROR, YAML_SCALAR_EVENT, YAML_SCALAR_NODE, YAML_SCALAR_TOKEN, YAML_SCALAR_NODE, YAML_SCALAR_TOKEN, YAML_SEQUENCE_END_EVENT, YAML_SEQUENCE_NODE,
YAML_SEQUENCE_END_EVENT, YAML_SEQUENCE_NODE, YAML_SEQUENCE_START_EVENT, YAML_STREAM_END_EVENT, YAML_SEQUENCE_START_EVENT, YAML_STREAM_END_EVENT, YAML_STREAM_START_EVENT,
YAML_STREAM_START_EVENT, YAML_TAG_DIRECTIVE_TOKEN, YAML_TAG_TOKEN, YAML_TAG_DIRECTIVE_TOKEN, YAML_TAG_TOKEN,
}; };
use core::mem::{size_of, MaybeUninit}; use core::mem::{size_of, MaybeUninit};
use core::ptr::{self, addr_of_mut}; use core::ptr::{self, addr_of_mut};
struct api_context {
error: yaml_error_type_t,
}
const INPUT_RAW_BUFFER_SIZE: usize = 16384; const INPUT_RAW_BUFFER_SIZE: usize = 16384;
const INPUT_BUFFER_SIZE: usize = INPUT_RAW_BUFFER_SIZE * 3; const INPUT_BUFFER_SIZE: usize = INPUT_RAW_BUFFER_SIZE * 3;
const OUTPUT_BUFFER_SIZE: usize = 16384; const OUTPUT_BUFFER_SIZE: usize = 16384;
@ -100,12 +96,7 @@ pub(crate) unsafe fn yaml_stack_extend(
start: *mut *mut libc::c_void, start: *mut *mut libc::c_void,
top: *mut *mut libc::c_void, top: *mut *mut libc::c_void,
end: *mut *mut libc::c_void, end: *mut *mut libc::c_void,
) -> Success { ) {
if (*end as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char) as libc::c_long
>= (2147483647 / 2) as libc::c_long
{
return FAIL;
}
let new_start: *mut libc::c_void = yaml_realloc( let new_start: *mut libc::c_void = yaml_realloc(
*start, *start,
((*end as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char) as libc::c_long ((*end as *mut libc::c_char).c_offset_from(*start as *mut libc::c_char) as libc::c_long
@ -120,7 +111,6 @@ pub(crate) unsafe fn yaml_stack_extend(
* 2_i64) as isize, * 2_i64) as isize,
) as *mut libc::c_void; ) as *mut libc::c_void;
*start = new_start; *start = new_start;
OK
} }
pub(crate) unsafe fn yaml_queue_extend( pub(crate) unsafe fn yaml_queue_extend(
@ -614,9 +604,6 @@ pub unsafe fn yaml_document_start_event_initialize(
implicit: bool, implicit: bool,
) -> Success { ) -> Success {
let mut current_block: u64; let mut current_block: u64;
let mut context = api_context {
error: YAML_NO_ERROR,
};
let mark = yaml_mark_t { let mark = yaml_mark_t {
index: 0_u64, index: 0_u64,
line: 0_u64, line: 0_u64,
@ -693,10 +680,7 @@ pub unsafe fn yaml_document_start_event_initialize(
current_block = 14964981520188694172; current_block = 14964981520188694172;
break; break;
} }
if PUSH!(addr_of_mut!(context), tag_directives_copy, value).fail { PUSH!(addr_of_mut!(context), tag_directives_copy, value);
current_block = 14964981520188694172;
break;
}
value.handle = ptr::null_mut::<yaml_char_t>(); value.handle = ptr::null_mut::<yaml_char_t>();
value.prefix = ptr::null_mut::<yaml_char_t>(); value.prefix = ptr::null_mut::<yaml_char_t>();
tag_directive = tag_directive.wrapping_offset(1); tag_directive = tag_directive.wrapping_offset(1);
@ -1147,9 +1131,6 @@ pub unsafe fn yaml_document_initialize(
end_implicit: bool, end_implicit: bool,
) -> Success { ) -> Success {
let mut current_block: u64; let mut current_block: u64;
let mut context = api_context {
error: YAML_NO_ERROR,
};
struct Nodes { struct Nodes {
start: *mut yaml_node_t, start: *mut yaml_node_t,
end: *mut yaml_node_t, end: *mut yaml_node_t,
@ -1238,10 +1219,7 @@ pub unsafe fn yaml_document_initialize(
current_block = 8142820162064489797; current_block = 8142820162064489797;
break; break;
} }
if PUSH!(addr_of_mut!(context), tag_directives_copy, value).fail { PUSH!(addr_of_mut!(context), tag_directives_copy, value);
current_block = 8142820162064489797;
break;
}
value.handle = ptr::null_mut::<yaml_char_t>(); value.handle = ptr::null_mut::<yaml_char_t>();
value.prefix = ptr::null_mut::<yaml_char_t>(); value.prefix = ptr::null_mut::<yaml_char_t>();
tag_directive = tag_directive.wrapping_offset(1); tag_directive = tag_directive.wrapping_offset(1);
@ -1382,9 +1360,6 @@ pub unsafe fn yaml_document_add_scalar(
mut length: libc::c_int, mut length: libc::c_int,
style: yaml_scalar_style_t, style: yaml_scalar_style_t,
) -> libc::c_int { ) -> libc::c_int {
let mut context = api_context {
error: YAML_NO_ERROR,
};
let mark = yaml_mark_t { let mark = yaml_mark_t {
index: 0_u64, index: 0_u64,
line: 0_u64, line: 0_u64,
@ -1425,10 +1400,8 @@ pub unsafe fn yaml_document_add_scalar(
(*node).data.scalar.value = value_copy; (*node).data.scalar.value = value_copy;
(*node).data.scalar.length = length as size_t; (*node).data.scalar.length = length as size_t;
(*node).data.scalar.style = style; (*node).data.scalar.style = style;
if PUSH!(addr_of_mut!(context), (*document).nodes, *node).ok { PUSH!(addr_of_mut!(context), (*document).nodes, *node);
return (*document).nodes.top.c_offset_from((*document).nodes.start) return (*document).nodes.top.c_offset_from((*document).nodes.start) as libc::c_int;
as libc::c_int;
}
} }
} }
} }
@ -1448,9 +1421,6 @@ pub unsafe fn yaml_document_add_sequence(
mut tag: *const yaml_char_t, mut tag: *const yaml_char_t,
style: yaml_sequence_style_t, style: yaml_sequence_style_t,
) -> libc::c_int { ) -> libc::c_int {
let mut context = api_context {
error: YAML_NO_ERROR,
};
let mark = yaml_mark_t { let mark = yaml_mark_t {
index: 0_u64, index: 0_u64,
line: 0_u64, line: 0_u64,
@ -1490,9 +1460,8 @@ pub unsafe fn yaml_document_add_sequence(
(*node).data.sequence.items.end = items.end; (*node).data.sequence.items.end = items.end;
(*node).data.sequence.items.top = items.start; (*node).data.sequence.items.top = items.start;
(*node).data.sequence.style = style; (*node).data.sequence.style = style;
if PUSH!(addr_of_mut!(context), (*document).nodes, *node).ok { PUSH!(addr_of_mut!(context), (*document).nodes, *node);
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;
}
} }
} }
STACK_DEL!(items); STACK_DEL!(items);
@ -1511,9 +1480,6 @@ pub unsafe fn yaml_document_add_mapping(
mut tag: *const yaml_char_t, mut tag: *const yaml_char_t,
style: yaml_mapping_style_t, style: yaml_mapping_style_t,
) -> libc::c_int { ) -> libc::c_int {
let mut context = api_context {
error: YAML_NO_ERROR,
};
let mark = yaml_mark_t { let mark = yaml_mark_t {
index: 0_u64, index: 0_u64,
line: 0_u64, line: 0_u64,
@ -1553,9 +1519,8 @@ pub unsafe fn yaml_document_add_mapping(
(*node).data.mapping.pairs.end = pairs.end; (*node).data.mapping.pairs.end = pairs.end;
(*node).data.mapping.pairs.top = pairs.start; (*node).data.mapping.pairs.top = pairs.start;
(*node).data.mapping.style = style; (*node).data.mapping.style = style;
if PUSH!(addr_of_mut!(context), (*document).nodes, *node).ok { PUSH!(addr_of_mut!(context), (*document).nodes, *node);
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;
}
} }
} }
STACK_DEL!(pairs); STACK_DEL!(pairs);
@ -1569,9 +1534,6 @@ pub unsafe fn yaml_document_append_sequence_item(
sequence: libc::c_int, sequence: libc::c_int,
item: libc::c_int, item: libc::c_int,
) -> Success { ) -> Success {
let mut context = api_context {
error: YAML_NO_ERROR,
};
__assert!(!document.is_null()); __assert!(!document.is_null());
__assert!( __assert!(
sequence > 0 sequence > 0
@ -1586,18 +1548,14 @@ pub unsafe fn yaml_document_append_sequence_item(
item > 0 item > 0
&& ((*document).nodes.start).wrapping_offset(item as isize) <= (*document).nodes.top && ((*document).nodes.start).wrapping_offset(item as isize) <= (*document).nodes.top
); );
if PUSH!( PUSH!(
addr_of_mut!(context), addr_of_mut!(context),
(*((*document).nodes.start).wrapping_offset((sequence - 1) as isize)) (*((*document).nodes.start).wrapping_offset((sequence - 1) as isize))
.data .data
.sequence .sequence
.items, .items,
item item
) );
.fail
{
return FAIL;
}
OK OK
} }
@ -1608,9 +1566,6 @@ pub unsafe fn yaml_document_append_mapping_pair(
key: libc::c_int, key: libc::c_int,
value: libc::c_int, value: libc::c_int,
) -> Success { ) -> Success {
let mut context = api_context {
error: YAML_NO_ERROR,
};
__assert!(!document.is_null()); __assert!(!document.is_null());
__assert!( __assert!(
mapping > 0 mapping > 0
@ -1628,17 +1583,13 @@ pub unsafe fn yaml_document_append_mapping_pair(
&& ((*document).nodes.start).wrapping_offset(value as isize) <= (*document).nodes.top && ((*document).nodes.start).wrapping_offset(value as isize) <= (*document).nodes.top
); );
let pair = yaml_node_pair_t { key, value }; let pair = yaml_node_pair_t { key, value };
if PUSH!( PUSH!(
addr_of_mut!(context), addr_of_mut!(context),
(*((*document).nodes.start).wrapping_offset((mapping - 1) as isize)) (*((*document).nodes.start).wrapping_offset((mapping - 1) as isize))
.data .data
.mapping .mapping
.pairs, .pairs,
pair pair
) );
.fail
{
return FAIL;
}
OK OK
} }

View file

@ -218,7 +218,8 @@ unsafe fn yaml_emitter_append_tag_directive(
copy.prefix = yaml_strdup(value.prefix); copy.prefix = yaml_strdup(value.prefix);
if copy.handle.is_null() || copy.prefix.is_null() { if copy.handle.is_null() || copy.prefix.is_null() {
(*emitter).error = YAML_MEMORY_ERROR; (*emitter).error = YAML_MEMORY_ERROR;
} else if PUSH!(emitter, (*emitter).tag_directives, copy).ok { } else {
PUSH!(emitter, (*emitter).tag_directives, copy);
return OK; return OK;
} }
yaml_free(copy.handle as *mut libc::c_void); yaml_free(copy.handle as *mut libc::c_void);
@ -231,9 +232,7 @@ unsafe fn yaml_emitter_increase_indent(
flow: bool, flow: bool,
indentless: bool, indentless: bool,
) -> Success { ) -> Success {
if PUSH!(emitter, (*emitter).indents, (*emitter).indent).fail { PUSH!(emitter, (*emitter).indents, (*emitter).indent);
return FAIL;
}
if (*emitter).indent < 0 { if (*emitter).indent < 0 {
(*emitter).indent = if flow { (*emitter).best_indent } else { 0 }; (*emitter).indent = if flow { (*emitter).best_indent } else { 0 };
} else if !indentless { } else if !indentless {
@ -558,9 +557,7 @@ unsafe fn yaml_emitter_emit_document_content(
mut emitter: *mut yaml_emitter_t, mut emitter: *mut yaml_emitter_t,
event: *mut yaml_event_t, event: *mut yaml_event_t,
) -> Success { ) -> Success {
if PUSH!(emitter, (*emitter).states, YAML_EMIT_DOCUMENT_END_STATE).fail { PUSH!(emitter, (*emitter).states, YAML_EMIT_DOCUMENT_END_STATE);
return FAIL;
}
yaml_emitter_emit_node(emitter, event, true, false, false, false) yaml_emitter_emit_node(emitter, event, true, false, false, false)
} }
@ -683,15 +680,11 @@ unsafe fn yaml_emitter_emit_flow_sequence_item(
return FAIL; return FAIL;
} }
} }
if PUSH!( PUSH!(
emitter, emitter,
(*emitter).states, (*emitter).states,
YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE
) );
.fail
{
return FAIL;
}
yaml_emitter_emit_node(emitter, event, false, true, false, false) yaml_emitter_emit_node(emitter, event, false, true, false, false)
} }
@ -774,15 +767,11 @@ unsafe fn yaml_emitter_emit_flow_mapping_key(
} }
} }
if !(*emitter).canonical && yaml_emitter_check_simple_key(emitter) { if !(*emitter).canonical && yaml_emitter_check_simple_key(emitter) {
if PUSH!( PUSH!(
emitter, emitter,
(*emitter).states, (*emitter).states,
YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE
) );
.fail
{
return FAIL;
}
yaml_emitter_emit_node(emitter, event, false, false, true, true) yaml_emitter_emit_node(emitter, event, false, false, true, true)
} else { } else {
if yaml_emitter_write_indicator( if yaml_emitter_write_indicator(
@ -796,15 +785,11 @@ unsafe fn yaml_emitter_emit_flow_mapping_key(
{ {
return FAIL; return FAIL;
} }
if PUSH!( PUSH!(
emitter, emitter,
(*emitter).states, (*emitter).states,
YAML_EMIT_FLOW_MAPPING_VALUE_STATE YAML_EMIT_FLOW_MAPPING_VALUE_STATE
) );
.fail
{
return FAIL;
}
yaml_emitter_emit_node(emitter, event, false, false, true, false) yaml_emitter_emit_node(emitter, event, false, false, true, false)
} }
} }
@ -844,9 +829,7 @@ unsafe fn yaml_emitter_emit_flow_mapping_value(
return FAIL; return FAIL;
} }
} }
if PUSH!(emitter, (*emitter).states, YAML_EMIT_FLOW_MAPPING_KEY_STATE).fail { PUSH!(emitter, (*emitter).states, YAML_EMIT_FLOW_MAPPING_KEY_STATE);
return FAIL;
}
yaml_emitter_emit_node(emitter, event, false, false, true, false) yaml_emitter_emit_node(emitter, event, false, false, true, false)
} }
@ -885,15 +868,11 @@ unsafe fn yaml_emitter_emit_block_sequence_item(
{ {
return FAIL; return FAIL;
} }
if PUSH!( PUSH!(
emitter, emitter,
(*emitter).states, (*emitter).states,
YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE
) );
.fail
{
return FAIL;
}
yaml_emitter_emit_node(emitter, event, false, true, false, false) yaml_emitter_emit_node(emitter, event, false, true, false, false)
} }
@ -916,15 +895,11 @@ unsafe fn yaml_emitter_emit_block_mapping_key(
return FAIL; return FAIL;
} }
if yaml_emitter_check_simple_key(emitter) { if yaml_emitter_check_simple_key(emitter) {
if PUSH!( PUSH!(
emitter, emitter,
(*emitter).states, (*emitter).states,
YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE
) );
.fail
{
return FAIL;
}
yaml_emitter_emit_node(emitter, event, false, false, true, true) yaml_emitter_emit_node(emitter, event, false, false, true, true)
} else { } else {
if yaml_emitter_write_indicator( if yaml_emitter_write_indicator(
@ -938,15 +913,11 @@ unsafe fn yaml_emitter_emit_block_mapping_key(
{ {
return FAIL; return FAIL;
} }
if PUSH!( PUSH!(
emitter, emitter,
(*emitter).states, (*emitter).states,
YAML_EMIT_BLOCK_MAPPING_VALUE_STATE YAML_EMIT_BLOCK_MAPPING_VALUE_STATE
) );
.fail
{
return FAIL;
}
yaml_emitter_emit_node(emitter, event, false, false, true, false) yaml_emitter_emit_node(emitter, event, false, false, true, false)
} }
} }
@ -984,15 +955,11 @@ unsafe fn yaml_emitter_emit_block_mapping_value(
return FAIL; return FAIL;
} }
} }
if PUSH!( PUSH!(
emitter, emitter,
(*emitter).states, (*emitter).states,
YAML_EMIT_BLOCK_MAPPING_KEY_STATE YAML_EMIT_BLOCK_MAPPING_KEY_STATE
) );
.fail
{
return FAIL;
}
yaml_emitter_emit_node(emitter, event, false, false, true, false) yaml_emitter_emit_node(emitter, event, false, false, true, false)
} }

View file

@ -239,10 +239,7 @@ unsafe fn yaml_parser_register_anchor(
} }
alias_data = alias_data.wrapping_offset(1); alias_data = alias_data.wrapping_offset(1);
} }
if PUSH!(parser, (*parser).aliases, *data).fail { PUSH!(parser, (*parser).aliases, *data);
yaml_free(anchor as *mut libc::c_void);
return FAIL;
}
OK OK
} }
@ -264,9 +261,7 @@ unsafe fn yaml_parser_load_node_add(
if STACK_LIMIT!(parser, (*parent).data.sequence.items).fail { if STACK_LIMIT!(parser, (*parent).data.sequence.items).fail {
return FAIL; return FAIL;
} }
if PUSH!(parser, (*parent).data.sequence.items, index).fail { PUSH!(parser, (*parent).data.sequence.items, index);
return FAIL;
}
} }
YAML_MAPPING_NODE => { YAML_MAPPING_NODE => {
let mut pair = MaybeUninit::<yaml_node_pair_t>::uninit(); let mut pair = MaybeUninit::<yaml_node_pair_t>::uninit();
@ -291,9 +286,7 @@ unsafe fn yaml_parser_load_node_add(
if STACK_LIMIT!(parser, (*parent).data.mapping.pairs).fail { if STACK_LIMIT!(parser, (*parent).data.mapping.pairs).fail {
return FAIL; return FAIL;
} }
if PUSH!(parser, (*parent).data.mapping.pairs, *pair).fail { PUSH!(parser, (*parent).data.mapping.pairs, *pair);
return FAIL;
}
} }
} }
} }
@ -375,18 +368,16 @@ unsafe fn yaml_parser_load_scalar(
(*node).data.scalar.value = (*event).data.scalar.value; (*node).data.scalar.value = (*event).data.scalar.value;
(*node).data.scalar.length = (*event).data.scalar.length; (*node).data.scalar.length = (*event).data.scalar.length;
(*node).data.scalar.style = (*event).data.scalar.style; (*node).data.scalar.style = (*event).data.scalar.style;
if PUSH!(parser, (*(*parser).document).nodes, *node).ok { PUSH!(parser, (*(*parser).document).nodes, *node);
index = (*(*parser).document) index = (*(*parser).document)
.nodes .nodes
.top .top
.c_offset_from((*(*parser).document).nodes.start) .c_offset_from((*(*parser).document).nodes.start)
as libc::c_int; as libc::c_int;
if yaml_parser_register_anchor(parser, index, (*event).data.scalar.anchor).fail if yaml_parser_register_anchor(parser, index, (*event).data.scalar.anchor).fail {
{ return FAIL;
return FAIL;
}
return yaml_parser_load_node_add(parser, ctx, index);
} }
return yaml_parser_load_node_add(parser, ctx, index);
} }
} }
} }
@ -452,32 +443,25 @@ unsafe fn yaml_parser_load_sequence(
(*node).data.sequence.items.end = items.end; (*node).data.sequence.items.end = items.end;
(*node).data.sequence.items.top = items.start; (*node).data.sequence.items.top = items.start;
(*node).data.sequence.style = (*event).data.sequence_start.style; (*node).data.sequence.style = (*event).data.sequence_start.style;
if PUSH!(parser, (*(*parser).document).nodes, *node).ok { PUSH!(parser, (*(*parser).document).nodes, *node);
index = (*(*parser).document) index = (*(*parser).document)
.nodes .nodes
.top .top
.c_offset_from((*(*parser).document).nodes.start) .c_offset_from((*(*parser).document).nodes.start)
as libc::c_int; as libc::c_int;
if yaml_parser_register_anchor( if yaml_parser_register_anchor(parser, index, (*event).data.sequence_start.anchor)
parser,
index,
(*event).data.sequence_start.anchor,
)
.fail .fail
{ {
return FAIL; return FAIL;
}
if yaml_parser_load_node_add(parser, ctx, index).fail {
return FAIL;
}
if STACK_LIMIT!(parser, *ctx).fail {
return FAIL;
}
if PUSH!(parser, *ctx, index).fail {
return FAIL;
}
return OK;
} }
if yaml_parser_load_node_add(parser, ctx, index).fail {
return FAIL;
}
if STACK_LIMIT!(parser, *ctx).fail {
return FAIL;
}
PUSH!(parser, *ctx, index);
return OK;
} }
} }
} }
@ -562,32 +546,25 @@ unsafe fn yaml_parser_load_mapping(
(*node).data.mapping.pairs.end = pairs.end; (*node).data.mapping.pairs.end = pairs.end;
(*node).data.mapping.pairs.top = pairs.start; (*node).data.mapping.pairs.top = pairs.start;
(*node).data.mapping.style = (*event).data.mapping_start.style; (*node).data.mapping.style = (*event).data.mapping_start.style;
if PUSH!(parser, (*(*parser).document).nodes, *node).ok { PUSH!(parser, (*(*parser).document).nodes, *node);
index = (*(*parser).document) index = (*(*parser).document)
.nodes .nodes
.top .top
.c_offset_from((*(*parser).document).nodes.start) .c_offset_from((*(*parser).document).nodes.start)
as libc::c_int; as libc::c_int;
if yaml_parser_register_anchor( if yaml_parser_register_anchor(parser, index, (*event).data.mapping_start.anchor)
parser,
index,
(*event).data.mapping_start.anchor,
)
.fail .fail
{ {
return FAIL; return FAIL;
}
if yaml_parser_load_node_add(parser, ctx, index).fail {
return FAIL;
}
if STACK_LIMIT!(parser, *ctx).fail {
return FAIL;
}
if PUSH!(parser, *ctx, index).fail {
return FAIL;
}
return OK;
} }
if yaml_parser_load_node_add(parser, ctx, index).fail {
return FAIL;
}
if STACK_LIMIT!(parser, *ctx).fail {
return FAIL;
}
PUSH!(parser, *ctx, index);
return OK;
} }
} }
} }

View file

@ -381,22 +381,17 @@ macro_rules! STACK_LIMIT {
} }
macro_rules! PUSH { macro_rules! PUSH {
(do $context:expr, $stack:expr, $push:expr) => { (do $context:expr, $stack:expr, $push:expr) => {{
if $stack.top != $stack.end if $stack.top == $stack.end {
|| yaml_stack_extend( yaml_stack_extend(
addr_of_mut!($stack.start) as *mut *mut libc::c_void, addr_of_mut!($stack.start) as *mut *mut libc::c_void,
addr_of_mut!($stack.top) as *mut *mut libc::c_void, addr_of_mut!($stack.top) as *mut *mut libc::c_void,
addr_of_mut!($stack.end) as *mut *mut libc::c_void, addr_of_mut!($stack.end) as *mut *mut libc::c_void,
).ok );
{
$push;
$stack.top = $stack.top.wrapping_offset(1);
OK
} else {
(*$context).error = YAML_MEMORY_ERROR;
FAIL
} }
}; $push;
$stack.top = $stack.top.wrapping_offset(1);
}};
($context:expr, $stack:expr, *$value:expr) => { ($context:expr, $stack:expr, *$value:expr) => {
PUSH!(do $context, $stack, ptr::copy_nonoverlapping($value, $stack.top, 1)) PUSH!(do $context, $stack, ptr::copy_nonoverlapping($value, $stack.top, 1))
}; };

View file

@ -257,9 +257,7 @@ unsafe fn yaml_parser_parse_document_start(
{ {
return FAIL; return FAIL;
} }
if PUSH!(parser, (*parser).states, YAML_PARSE_DOCUMENT_END_STATE).fail { PUSH!(parser, (*parser).states, YAML_PARSE_DOCUMENT_END_STATE);
return FAIL;
}
(*parser).state = YAML_PARSE_BLOCK_NODE_STATE; (*parser).state = YAML_PARSE_BLOCK_NODE_STATE;
memset( memset(
event as *mut libc::c_void, event as *mut libc::c_void,
@ -298,7 +296,8 @@ unsafe fn yaml_parser_parse_document_start(
b"did not find expected <document start>\0" as *const u8 as *const libc::c_char, b"did not find expected <document start>\0" as *const u8 as *const libc::c_char,
(*token).start_mark, (*token).start_mark,
); );
} else if PUSH!(parser, (*parser).states, YAML_PARSE_DOCUMENT_END_STATE).ok { } else {
PUSH!(parser, (*parser).states, YAML_PARSE_DOCUMENT_END_STATE);
(*parser).state = YAML_PARSE_DOCUMENT_CONTENT_STATE; (*parser).state = YAML_PARSE_DOCUMENT_CONTENT_STATE;
end_mark = (*token).end_mark; end_mark = (*token).end_mark;
memset( memset(
@ -756,9 +755,7 @@ unsafe fn yaml_parser_parse_block_sequence_entry(
let mut token: *mut yaml_token_t; let mut token: *mut yaml_token_t;
if first { if first {
token = PEEK_TOKEN(parser); token = PEEK_TOKEN(parser);
if PUSH!(parser, (*parser).marks, (*token).start_mark).fail { PUSH!(parser, (*parser).marks, (*token).start_mark);
return FAIL;
}
SKIP_TOKEN(parser); SKIP_TOKEN(parser);
} }
token = PEEK_TOKEN(parser); token = PEEK_TOKEN(parser);
@ -773,15 +770,11 @@ unsafe fn yaml_parser_parse_block_sequence_entry(
return FAIL; return FAIL;
} }
if (*token).type_ != YAML_BLOCK_ENTRY_TOKEN && (*token).type_ != YAML_BLOCK_END_TOKEN { if (*token).type_ != YAML_BLOCK_ENTRY_TOKEN && (*token).type_ != YAML_BLOCK_END_TOKEN {
if PUSH!( PUSH!(
parser, parser,
(*parser).states, (*parser).states,
YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE
) );
.fail
{
return FAIL;
}
yaml_parser_parse_node(parser, event, true, false) yaml_parser_parse_node(parser, event, true, false)
} else { } else {
(*parser).state = YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE; (*parser).state = YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE;
@ -833,15 +826,11 @@ unsafe fn yaml_parser_parse_indentless_sequence_entry(
&& (*token).type_ != YAML_VALUE_TOKEN && (*token).type_ != YAML_VALUE_TOKEN
&& (*token).type_ != YAML_BLOCK_END_TOKEN && (*token).type_ != YAML_BLOCK_END_TOKEN
{ {
if PUSH!( PUSH!(
parser, parser,
(*parser).states, (*parser).states,
YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE
) );
.fail
{
return FAIL;
}
yaml_parser_parse_node(parser, event, true, false) yaml_parser_parse_node(parser, event, true, false)
} else { } else {
(*parser).state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE; (*parser).state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE;
@ -869,9 +858,7 @@ unsafe fn yaml_parser_parse_block_mapping_key(
let mut token: *mut yaml_token_t; let mut token: *mut yaml_token_t;
if first { if first {
token = PEEK_TOKEN(parser); token = PEEK_TOKEN(parser);
if PUSH!(parser, (*parser).marks, (*token).start_mark).fail { PUSH!(parser, (*parser).marks, (*token).start_mark);
return FAIL;
}
SKIP_TOKEN(parser); SKIP_TOKEN(parser);
} }
token = PEEK_TOKEN(parser); token = PEEK_TOKEN(parser);
@ -889,15 +876,11 @@ unsafe fn yaml_parser_parse_block_mapping_key(
&& (*token).type_ != YAML_VALUE_TOKEN && (*token).type_ != YAML_VALUE_TOKEN
&& (*token).type_ != YAML_BLOCK_END_TOKEN && (*token).type_ != YAML_BLOCK_END_TOKEN
{ {
if PUSH!( PUSH!(
parser, parser,
(*parser).states, (*parser).states,
YAML_PARSE_BLOCK_MAPPING_VALUE_STATE YAML_PARSE_BLOCK_MAPPING_VALUE_STATE
) );
.fail
{
return FAIL;
}
yaml_parser_parse_node(parser, event, true, true) yaml_parser_parse_node(parser, event, true, true)
} else { } else {
(*parser).state = YAML_PARSE_BLOCK_MAPPING_VALUE_STATE; (*parser).state = YAML_PARSE_BLOCK_MAPPING_VALUE_STATE;
@ -948,9 +931,7 @@ unsafe fn yaml_parser_parse_block_mapping_value(
&& (*token).type_ != YAML_VALUE_TOKEN && (*token).type_ != YAML_VALUE_TOKEN
&& (*token).type_ != YAML_BLOCK_END_TOKEN && (*token).type_ != YAML_BLOCK_END_TOKEN
{ {
if PUSH!(parser, (*parser).states, YAML_PARSE_BLOCK_MAPPING_KEY_STATE).fail { PUSH!(parser, (*parser).states, YAML_PARSE_BLOCK_MAPPING_KEY_STATE);
return FAIL;
}
yaml_parser_parse_node(parser, event, true, true) yaml_parser_parse_node(parser, event, true, true)
} else { } else {
(*parser).state = YAML_PARSE_BLOCK_MAPPING_KEY_STATE; (*parser).state = YAML_PARSE_BLOCK_MAPPING_KEY_STATE;
@ -970,9 +951,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry(
let mut token: *mut yaml_token_t; let mut token: *mut yaml_token_t;
if first { if first {
token = PEEK_TOKEN(parser); token = PEEK_TOKEN(parser);
if PUSH!(parser, (*parser).marks, (*token).start_mark).fail { PUSH!(parser, (*parser).marks, (*token).start_mark);
return FAIL;
}
SKIP_TOKEN(parser); SKIP_TOKEN(parser);
} }
token = PEEK_TOKEN(parser); token = PEEK_TOKEN(parser);
@ -1017,15 +996,11 @@ unsafe fn yaml_parser_parse_flow_sequence_entry(
SKIP_TOKEN(parser); SKIP_TOKEN(parser);
return OK; return OK;
} else if (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN { } else if (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN {
if PUSH!( PUSH!(
parser, parser,
(*parser).states, (*parser).states,
YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE
) );
.fail
{
return FAIL;
}
return yaml_parser_parse_node(parser, event, false, false); return yaml_parser_parse_node(parser, event, false, false);
} }
} }
@ -1055,15 +1030,11 @@ unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_key(
&& (*token).type_ != YAML_FLOW_ENTRY_TOKEN && (*token).type_ != YAML_FLOW_ENTRY_TOKEN
&& (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN && (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN
{ {
if PUSH!( PUSH!(
parser, parser,
(*parser).states, (*parser).states,
YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE
) );
.fail
{
return FAIL;
}
yaml_parser_parse_node(parser, event, false, false) yaml_parser_parse_node(parser, event, false, false)
} else { } else {
let mark: yaml_mark_t = (*token).end_mark; let mark: yaml_mark_t = (*token).end_mark;
@ -1090,15 +1061,11 @@ unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_value(
} }
if (*token).type_ != YAML_FLOW_ENTRY_TOKEN && (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN if (*token).type_ != YAML_FLOW_ENTRY_TOKEN && (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN
{ {
if PUSH!( PUSH!(
parser, parser,
(*parser).states, (*parser).states,
YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE
) );
.fail
{
return FAIL;
}
return yaml_parser_parse_node(parser, event, false, false); return yaml_parser_parse_node(parser, event, false, false);
} }
} }
@ -1134,9 +1101,7 @@ unsafe fn yaml_parser_parse_flow_mapping_key(
let mut token: *mut yaml_token_t; let mut token: *mut yaml_token_t;
if first { if first {
token = PEEK_TOKEN(parser); token = PEEK_TOKEN(parser);
if PUSH!(parser, (*parser).marks, (*token).start_mark).fail { PUSH!(parser, (*parser).marks, (*token).start_mark);
return FAIL;
}
SKIP_TOKEN(parser); SKIP_TOKEN(parser);
} }
token = PEEK_TOKEN(parser); token = PEEK_TOKEN(parser);
@ -1172,30 +1137,22 @@ unsafe fn yaml_parser_parse_flow_mapping_key(
&& (*token).type_ != YAML_FLOW_ENTRY_TOKEN && (*token).type_ != YAML_FLOW_ENTRY_TOKEN
&& (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN && (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN
{ {
if PUSH!( PUSH!(
parser, parser,
(*parser).states, (*parser).states,
YAML_PARSE_FLOW_MAPPING_VALUE_STATE YAML_PARSE_FLOW_MAPPING_VALUE_STATE
) );
.fail
{
return FAIL;
}
return yaml_parser_parse_node(parser, event, false, false); return yaml_parser_parse_node(parser, event, false, false);
} else { } else {
(*parser).state = YAML_PARSE_FLOW_MAPPING_VALUE_STATE; (*parser).state = YAML_PARSE_FLOW_MAPPING_VALUE_STATE;
return yaml_parser_process_empty_scalar(event, (*token).start_mark); return yaml_parser_process_empty_scalar(event, (*token).start_mark);
} }
} else if (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN { } else if (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN {
if PUSH!( PUSH!(
parser, parser,
(*parser).states, (*parser).states,
YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE
) );
.fail
{
return FAIL;
}
return yaml_parser_parse_node(parser, event, false, false); return yaml_parser_parse_node(parser, event, false, false);
} }
} }
@ -1235,9 +1192,7 @@ unsafe fn yaml_parser_parse_flow_mapping_value(
} }
if (*token).type_ != YAML_FLOW_ENTRY_TOKEN && (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN if (*token).type_ != YAML_FLOW_ENTRY_TOKEN && (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN
{ {
if PUSH!(parser, (*parser).states, YAML_PARSE_FLOW_MAPPING_KEY_STATE).fail { PUSH!(parser, (*parser).states, YAML_PARSE_FLOW_MAPPING_KEY_STATE);
return FAIL;
}
return yaml_parser_parse_node(parser, event, false, false); return yaml_parser_parse_node(parser, event, false, false);
} }
} }
@ -1273,7 +1228,7 @@ unsafe fn yaml_parser_process_empty_scalar(
} }
unsafe fn yaml_parser_process_directives( unsafe fn yaml_parser_process_directives(
mut parser: *mut yaml_parser_t, parser: *mut yaml_parser_t,
version_directive_ref: *mut *mut yaml_version_directive_t, version_directive_ref: *mut *mut yaml_version_directive_t,
tag_directives_start_ref: *mut *mut yaml_tag_directive_t, tag_directives_start_ref: *mut *mut yaml_tag_directive_t,
tag_directives_end_ref: *mut *mut yaml_tag_directive_t, tag_directives_end_ref: *mut *mut yaml_tag_directive_t,
@ -1354,10 +1309,7 @@ unsafe fn yaml_parser_process_directives(
current_block = 17143798186130252483; current_block = 17143798186130252483;
break; break;
} }
if PUSH!(parser, tag_directives, value).fail { PUSH!(parser, tag_directives, value);
current_block = 17143798186130252483;
break;
}
} }
SKIP_TOKEN(parser); SKIP_TOKEN(parser);
token = PEEK_TOKEN(parser); token = PEEK_TOKEN(parser);
@ -1459,7 +1411,8 @@ unsafe fn yaml_parser_append_tag_directive(
copy.prefix = yaml_strdup(value.prefix); copy.prefix = yaml_strdup(value.prefix);
if copy.handle.is_null() || copy.prefix.is_null() { if copy.handle.is_null() || copy.prefix.is_null() {
(*parser).error = YAML_MEMORY_ERROR; (*parser).error = YAML_MEMORY_ERROR;
} else if PUSH!(parser, (*parser).tag_directives, copy).ok { } else {
PUSH!(parser, (*parser).tag_directives, copy);
return OK; return OK;
} }
yaml_free(copy.handle as *mut libc::c_void); yaml_free(copy.handle as *mut libc::c_void);

View file

@ -409,9 +409,7 @@ unsafe fn yaml_parser_increase_flow_level(mut parser: *mut yaml_parser_t) -> Suc
column: 0_u64, column: 0_u64,
}, },
}; };
if PUSH!(parser, (*parser).simple_keys, empty_simple_key).fail { PUSH!(parser, (*parser).simple_keys, empty_simple_key);
return FAIL;
}
if (*parser).flow_level == 2147483647 { if (*parser).flow_level == 2147483647 {
(*parser).error = YAML_MEMORY_ERROR; (*parser).error = YAML_MEMORY_ERROR;
return FAIL; return FAIL;
@ -443,9 +441,7 @@ unsafe fn yaml_parser_roll_indent(
return OK; return OK;
} }
if ((*parser).indent as libc::c_long) < column { if ((*parser).indent as libc::c_long) < column {
if PUSH!(parser, (*parser).indents, (*parser).indent).fail { PUSH!(parser, (*parser).indents, (*parser).indent);
return FAIL;
}
if column > 2147483647_i64 { if column > 2147483647_i64 {
(*parser).error = YAML_MEMORY_ERROR; (*parser).error = YAML_MEMORY_ERROR;
return FAIL; return FAIL;
@ -508,9 +504,7 @@ unsafe fn yaml_parser_fetch_stream_start(mut parser: *mut yaml_parser_t) -> Succ
let mut token = MaybeUninit::<yaml_token_t>::uninit(); let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr(); let token = token.as_mut_ptr();
(*parser).indent = -1; (*parser).indent = -1;
if PUSH!(parser, (*parser).simple_keys, simple_key).fail { PUSH!(parser, (*parser).simple_keys, simple_key);
return FAIL;
}
(*parser).simple_key_allowed = true; (*parser).simple_key_allowed = true;
(*parser).stream_start_produced = true; (*parser).stream_start_produced = true;
memset( memset(