Replace Success with Result<(), ()>

This commit is contained in:
Simon Ask Ulsnes 2024-01-26 11:04:48 +01:00
parent fbdff989b5
commit dc639b92b5
11 changed files with 510 additions and 494 deletions

View file

@ -1,6 +1,6 @@
use crate::externs::{free, malloc, memcpy, memmove, memset, realloc, strdup, strlen};
use crate::ops::{ForceAdd as _, ForceMul as _};
use crate::success::{Success, FAIL, OK};
use crate::success::{FAIL, OK};
use crate::yaml::{size_t, yaml_char_t};
use crate::{
libc, yaml_break_t, yaml_document_t, yaml_emitter_state_t, yaml_emitter_t, yaml_encoding_t,
@ -164,7 +164,7 @@ pub(crate) unsafe fn yaml_queue_extend(
///
/// 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) -> Success {
pub unsafe fn yaml_parser_initialize(parser: *mut yaml_parser_t) -> Result<(), ()> {
__assert!(!parser.is_null());
memset(
parser as *mut libc::c_void,
@ -296,7 +296,7 @@ pub unsafe fn yaml_parser_set_encoding(parser: *mut yaml_parser_t, encoding: yam
///
/// This function creates a new emitter object. An application is responsible
/// for destroying the object using the yaml_emitter_delete() function.
pub unsafe fn yaml_emitter_initialize(emitter: *mut yaml_emitter_t) -> Success {
pub unsafe fn yaml_emitter_initialize(emitter: *mut yaml_emitter_t) -> Result<(), ()> {
__assert!(!emitter.is_null());
memset(
emitter as *mut libc::c_void,
@ -494,7 +494,7 @@ pub unsafe fn yaml_token_delete(token: *mut yaml_token_t) {
);
}
unsafe fn yaml_check_utf8(start: *const yaml_char_t, length: size_t) -> Success {
unsafe fn yaml_check_utf8(start: *const yaml_char_t, length: size_t) -> Result<(), ()> {
let end: *const yaml_char_t = start.wrapping_offset(length as isize);
let mut pointer: *const yaml_char_t = start;
while pointer < end {
@ -555,7 +555,7 @@ unsafe fn yaml_check_utf8(start: *const yaml_char_t, length: size_t) -> Success
pub unsafe fn yaml_stream_start_event_initialize(
event: *mut yaml_event_t,
encoding: yaml_encoding_t,
) -> Success {
) -> Result<(), ()> {
let mark = yaml_mark_t {
index: 0_u64,
line: 0_u64,
@ -575,7 +575,7 @@ pub unsafe fn yaml_stream_start_event_initialize(
}
/// Create the STREAM-END event.
pub unsafe fn yaml_stream_end_event_initialize(event: *mut yaml_event_t) -> Success {
pub unsafe fn yaml_stream_end_event_initialize(event: *mut yaml_event_t) -> Result<(), ()> {
let mark = yaml_mark_t {
index: 0_u64,
line: 0_u64,
@ -603,7 +603,7 @@ pub unsafe fn yaml_document_start_event_initialize(
tag_directives_start: *mut yaml_tag_directive_t,
tag_directives_end: *mut yaml_tag_directive_t,
implicit: bool,
) -> Success {
) -> Result<(), ()> {
let current_block: u64;
let mark = yaml_mark_t {
index: 0_u64,
@ -652,7 +652,7 @@ pub unsafe fn yaml_document_start_event_initialize(
(*tag_directive).handle,
strlen((*tag_directive).handle as *mut libc::c_char),
)
.fail
.is_err()
{
current_block = 14964981520188694172;
break;
@ -661,7 +661,7 @@ pub unsafe fn yaml_document_start_event_initialize(
(*tag_directive).prefix,
strlen((*tag_directive).prefix as *mut libc::c_char),
)
.fail
.is_err()
{
current_block = 14964981520188694172;
break;
@ -717,7 +717,7 @@ pub unsafe fn yaml_document_start_event_initialize(
pub unsafe fn yaml_document_end_event_initialize(
event: *mut yaml_event_t,
implicit: bool,
) -> Success {
) -> Result<(), ()> {
let mark = yaml_mark_t {
index: 0_u64,
line: 0_u64,
@ -740,7 +740,7 @@ pub unsafe fn yaml_document_end_event_initialize(
pub unsafe fn yaml_alias_event_initialize(
event: *mut yaml_event_t,
anchor: *const yaml_char_t,
) -> Success {
) -> Result<(), ()> {
let mark = yaml_mark_t {
index: 0_u64,
line: 0_u64,
@ -748,7 +748,7 @@ pub unsafe fn yaml_alias_event_initialize(
};
__assert!(!event.is_null());
__assert!(!anchor.is_null());
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char)).fail {
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char)).is_err() {
return FAIL;
}
let anchor_copy: *mut yaml_char_t = yaml_strdup(anchor);
@ -784,7 +784,7 @@ pub unsafe fn yaml_scalar_event_initialize(
plain_implicit: bool,
quoted_implicit: bool,
style: yaml_scalar_style_t,
) -> Success {
) -> Result<(), ()> {
let mut current_block: u64;
let mark = yaml_mark_t {
index: 0_u64,
@ -797,7 +797,7 @@ pub unsafe fn yaml_scalar_event_initialize(
__assert!(!event.is_null());
__assert!(!value.is_null());
if !anchor.is_null() {
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char)).fail {
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char)).is_err() {
current_block = 16285396129609901221;
} else {
anchor_copy = yaml_strdup(anchor);
@ -812,7 +812,7 @@ pub unsafe fn yaml_scalar_event_initialize(
}
if current_block == 8515828400728868193 {
if !tag.is_null() {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).fail {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).is_err() {
current_block = 16285396129609901221;
} else {
tag_copy = yaml_strdup(tag);
@ -829,7 +829,7 @@ pub unsafe fn yaml_scalar_event_initialize(
if length < 0 {
length = strlen(value as *mut libc::c_char) as libc::c_int;
}
if yaml_check_utf8(value, length as size_t).ok {
if yaml_check_utf8(value, length as size_t).is_ok() {
value_copy = yaml_malloc(length.force_add(1) as size_t) as *mut yaml_char_t;
memcpy(
value_copy as *mut libc::c_void,
@ -876,7 +876,7 @@ pub unsafe fn yaml_sequence_start_event_initialize(
tag: *const yaml_char_t,
implicit: bool,
style: yaml_sequence_style_t,
) -> Success {
) -> Result<(), ()> {
let mut current_block: u64;
let mark = yaml_mark_t {
index: 0_u64,
@ -887,7 +887,7 @@ pub unsafe fn yaml_sequence_start_event_initialize(
let mut tag_copy: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
__assert!(!event.is_null());
if !anchor.is_null() {
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char)).fail {
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char)).is_err() {
current_block = 8817775685815971442;
} else {
anchor_copy = yaml_strdup(anchor);
@ -903,7 +903,7 @@ pub unsafe fn yaml_sequence_start_event_initialize(
match current_block {
11006700562992250127 => {
if !tag.is_null() {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).fail {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).is_err() {
current_block = 8817775685815971442;
} else {
tag_copy = yaml_strdup(tag);
@ -942,7 +942,7 @@ pub unsafe fn yaml_sequence_start_event_initialize(
}
/// Create a SEQUENCE-END event.
pub unsafe fn yaml_sequence_end_event_initialize(event: *mut yaml_event_t) -> Success {
pub unsafe fn yaml_sequence_end_event_initialize(event: *mut yaml_event_t) -> Result<(), ()> {
let mark = yaml_mark_t {
index: 0_u64,
line: 0_u64,
@ -971,7 +971,7 @@ pub unsafe fn yaml_mapping_start_event_initialize(
tag: *const yaml_char_t,
implicit: bool,
style: yaml_mapping_style_t,
) -> Success {
) -> Result<(), ()> {
let mut current_block: u64;
let mark = yaml_mark_t {
index: 0_u64,
@ -982,7 +982,7 @@ pub unsafe fn yaml_mapping_start_event_initialize(
let mut tag_copy: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
__assert!(!event.is_null());
if !anchor.is_null() {
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char)).fail {
if yaml_check_utf8(anchor, strlen(anchor as *mut libc::c_char)).is_err() {
current_block = 14748279734549812740;
} else {
anchor_copy = yaml_strdup(anchor);
@ -997,7 +997,7 @@ pub unsafe fn yaml_mapping_start_event_initialize(
}
if current_block == 11006700562992250127 {
if !tag.is_null() {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).fail {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).is_err() {
current_block = 14748279734549812740;
} else {
tag_copy = yaml_strdup(tag);
@ -1034,7 +1034,7 @@ pub unsafe fn yaml_mapping_start_event_initialize(
}
/// Create a MAPPING-END event.
pub unsafe fn yaml_mapping_end_event_initialize(event: *mut yaml_event_t) -> Success {
pub unsafe fn yaml_mapping_end_event_initialize(event: *mut yaml_event_t) -> Result<(), ()> {
let mark = yaml_mark_t {
index: 0_u64,
line: 0_u64,
@ -1100,7 +1100,7 @@ pub unsafe fn yaml_document_initialize(
tag_directives_end: *mut yaml_tag_directive_t,
start_implicit: bool,
end_implicit: bool,
) -> Success {
) -> Result<(), ()> {
let current_block: u64;
struct Nodes {
start: *mut yaml_node_t,
@ -1160,7 +1160,7 @@ pub unsafe fn yaml_document_initialize(
(*tag_directive).handle,
strlen((*tag_directive).handle as *mut libc::c_char),
)
.fail
.is_err()
{
current_block = 8142820162064489797;
break;
@ -1169,7 +1169,7 @@ pub unsafe fn yaml_document_initialize(
(*tag_directive).prefix,
strlen((*tag_directive).prefix as *mut libc::c_char),
)
.fail
.is_err()
{
current_block = 8142820162064489797;
break;
@ -1330,13 +1330,13 @@ pub unsafe fn yaml_document_add_scalar(
if tag.is_null() {
tag = b"tag:yaml.org,2002:str\0" as *const u8 as *const libc::c_char as *mut yaml_char_t;
}
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).ok {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).is_ok() {
tag_copy = yaml_strdup(tag);
if !tag_copy.is_null() {
if length < 0 {
length = strlen(value as *mut libc::c_char) as libc::c_int;
}
if yaml_check_utf8(value, length as size_t).ok {
if yaml_check_utf8(value, length as size_t).is_ok() {
value_copy = yaml_malloc(length.force_add(1) as size_t) as *mut yaml_char_t;
memcpy(
value_copy as *mut libc::c_void,
@ -1399,7 +1399,7 @@ pub unsafe fn yaml_document_add_sequence(
if tag.is_null() {
tag = b"tag:yaml.org,2002:seq\0" as *const u8 as *const libc::c_char as *mut yaml_char_t;
}
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).ok {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).is_ok() {
tag_copy = yaml_strdup(tag);
if !tag_copy.is_null() {
STACK_INIT!(items, yaml_node_item_t);
@ -1458,7 +1458,7 @@ pub unsafe fn yaml_document_add_mapping(
if tag.is_null() {
tag = b"tag:yaml.org,2002:map\0" as *const u8 as *const libc::c_char as *mut yaml_char_t;
}
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).ok {
if yaml_check_utf8(tag, strlen(tag as *mut libc::c_char)).is_ok() {
tag_copy = yaml_strdup(tag);
if !tag_copy.is_null() {
STACK_INIT!(pairs, yaml_node_pair_t);
@ -1489,7 +1489,7 @@ pub unsafe fn yaml_document_append_sequence_item(
document: *mut yaml_document_t,
sequence: libc::c_int,
item: libc::c_int,
) -> Success {
) -> Result<(), ()> {
__assert!(!document.is_null());
__assert!(
sequence > 0
@ -1520,7 +1520,7 @@ pub unsafe fn yaml_document_append_mapping_pair(
mapping: libc::c_int,
key: libc::c_int,
value: libc::c_int,
) -> Success {
) -> Result<(), ()> {
__assert!(!document.is_null());
__assert!(
mapping > 0

View file

@ -47,7 +47,7 @@ pub(crate) unsafe fn unsafe_main(
) -> Result<(), Box<dyn Error>> {
let mut emitter = MaybeUninit::<yaml_emitter_t>::uninit();
let emitter = emitter.as_mut_ptr();
if yaml_emitter_initialize(emitter).fail {
if yaml_emitter_initialize(emitter).is_err() {
return Err("Could not initalize the emitter object".into());
}
@ -133,10 +133,10 @@ pub(crate) unsafe fn unsafe_main(
break Err(format!("Unknown event: '{}'", CStr::from_ptr(line)).into());
};
if result.fail {
if result.is_err() {
break Err("Memory error: Not enough memory for creating an event".into());
}
if yaml_emitter_emit(emitter, event).fail {
if yaml_emitter_emit(emitter, event).is_err() {
break Err(match (*emitter).error {
YAML_MEMORY_ERROR => "Memory error: Not enough memory for emitting".into(),
YAML_WRITER_ERROR => {

View file

@ -40,7 +40,7 @@ pub(crate) unsafe fn unsafe_main(
) -> Result<(), Box<dyn Error>> {
let mut parser = MaybeUninit::<yaml_parser_t>::uninit();
let parser = parser.as_mut_ptr();
if yaml_parser_initialize(parser).fail {
if yaml_parser_initialize(parser).is_err() {
return Err("Could not initialize the parser object".into());
}
@ -66,7 +66,7 @@ pub(crate) unsafe fn unsafe_main(
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
loop {
if yaml_parser_parse(parser, event).fail {
if yaml_parser_parse(parser, event).is_err() {
let mut error = format!("Parse error: {}", CStr::from_ptr((*parser).problem));
if (*parser).problem_mark.line != 0 || (*parser).problem_mark.column != 0 {
let _ = write!(

View file

@ -2,7 +2,7 @@ use crate::api::{yaml_free, yaml_malloc};
use crate::externs::{memset, strcmp};
use crate::fmt::WriteToPtr;
use crate::ops::ForceMul as _;
use crate::success::{Success, FAIL, OK};
use crate::success::{FAIL, OK};
use crate::yaml::{
yaml_anchors_t, yaml_char_t, yaml_document_t, yaml_emitter_t, yaml_event_t, yaml_mark_t,
yaml_node_item_t, yaml_node_pair_t, yaml_node_t, YAML_ALIAS_EVENT, YAML_ANY_ENCODING,
@ -17,7 +17,7 @@ use core::ptr::{self, addr_of_mut};
/// Start a YAML stream.
///
/// This function should be used before yaml_emitter_dump() is called.
pub unsafe fn yaml_emitter_open(emitter: *mut yaml_emitter_t) -> Success {
pub unsafe fn yaml_emitter_open(emitter: *mut yaml_emitter_t) -> Result<(), ()> {
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
let mark = yaml_mark_t {
@ -36,7 +36,7 @@ pub unsafe fn yaml_emitter_open(emitter: *mut yaml_emitter_t) -> Success {
(*event).start_mark = mark;
(*event).end_mark = mark;
(*event).data.stream_start.encoding = YAML_ANY_ENCODING;
if yaml_emitter_emit(emitter, event).fail {
if yaml_emitter_emit(emitter, event).is_err() {
return FAIL;
}
(*emitter).opened = true;
@ -46,7 +46,7 @@ pub unsafe fn yaml_emitter_open(emitter: *mut yaml_emitter_t) -> Success {
/// Finish a YAML stream.
///
/// This function should be used after yaml_emitter_dump() is called.
pub unsafe fn yaml_emitter_close(emitter: *mut yaml_emitter_t) -> Success {
pub unsafe fn yaml_emitter_close(emitter: *mut yaml_emitter_t) -> Result<(), ()> {
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
let mark = yaml_mark_t {
@ -67,7 +67,7 @@ pub unsafe fn yaml_emitter_close(emitter: *mut yaml_emitter_t) -> Success {
(*event).type_ = YAML_STREAM_END_EVENT;
(*event).start_mark = mark;
(*event).end_mark = mark;
if yaml_emitter_emit(emitter, event).fail {
if yaml_emitter_emit(emitter, event).is_err() {
return FAIL;
}
(*emitter).closed = true;
@ -83,7 +83,7 @@ pub unsafe fn yaml_emitter_close(emitter: *mut yaml_emitter_t) -> Success {
pub unsafe fn yaml_emitter_dump(
emitter: *mut yaml_emitter_t,
document: *mut yaml_document_t,
) -> Success {
) -> Result<(), ()> {
let current_block: u64;
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
@ -97,7 +97,7 @@ pub unsafe fn yaml_emitter_dump(
let fresh0 = addr_of_mut!((*emitter).document);
*fresh0 = document;
if !(*emitter).opened {
if yaml_emitter_open(emitter).fail {
if yaml_emitter_open(emitter).is_err() {
current_block = 5018439318894558507;
} else {
current_block = 15619007995458559411;
@ -108,7 +108,7 @@ pub unsafe fn yaml_emitter_dump(
match current_block {
15619007995458559411 => {
if STACK_EMPTY!((*document).nodes) {
if yaml_emitter_close(emitter).ok {
if yaml_emitter_close(emitter).is_ok() {
yaml_emitter_delete_document_and_anchors(emitter);
return OK;
}
@ -140,9 +140,9 @@ pub unsafe fn yaml_emitter_dump(
(*document).tag_directives.start;
(*event).data.document_start.tag_directives.end = (*document).tag_directives.end;
(*event).data.document_start.implicit = (*document).start_implicit;
if yaml_emitter_emit(emitter, event).ok {
if yaml_emitter_emit(emitter, event).is_ok() {
yaml_emitter_anchor_node(emitter, 1);
if yaml_emitter_dump_node(emitter, 1).ok {
if yaml_emitter_dump_node(emitter, 1).is_ok() {
memset(
event as *mut libc::c_void,
0,
@ -152,7 +152,7 @@ pub unsafe fn yaml_emitter_dump(
(*event).start_mark = mark;
(*event).end_mark = mark;
(*event).data.document_end.implicit = (*document).end_implicit;
if yaml_emitter_emit(emitter, event).ok {
if yaml_emitter_emit(emitter, event).is_ok() {
yaml_emitter_delete_document_and_anchors(emitter);
return OK;
}
@ -262,7 +262,10 @@ unsafe fn yaml_emitter_generate_anchor(
anchor
}
unsafe fn yaml_emitter_dump_node(emitter: *mut yaml_emitter_t, index: libc::c_int) -> Success {
unsafe fn yaml_emitter_dump_node(
emitter: *mut yaml_emitter_t,
index: libc::c_int,
) -> Result<(), ()> {
let node: *mut yaml_node_t = (*(*emitter).document)
.nodes
.start
@ -288,7 +291,7 @@ unsafe fn yaml_emitter_dump_node(emitter: *mut yaml_emitter_t, index: libc::c_in
unsafe fn yaml_emitter_dump_alias(
emitter: *mut yaml_emitter_t,
anchor: *mut yaml_char_t,
) -> Success {
) -> Result<(), ()> {
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
let mark = yaml_mark_t {
@ -312,7 +315,7 @@ unsafe fn yaml_emitter_dump_scalar(
emitter: *mut yaml_emitter_t,
node: *mut yaml_node_t,
anchor: *mut yaml_char_t,
) -> Success {
) -> Result<(), ()> {
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
let mark = yaml_mark_t {
@ -350,7 +353,7 @@ unsafe fn yaml_emitter_dump_sequence(
emitter: *mut yaml_emitter_t,
node: *mut yaml_node_t,
anchor: *mut yaml_char_t,
) -> Success {
) -> Result<(), ()> {
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
let mark = yaml_mark_t {
@ -375,12 +378,12 @@ unsafe fn yaml_emitter_dump_sequence(
(*event).data.sequence_start.tag = (*node).tag;
(*event).data.sequence_start.implicit = implicit;
(*event).data.sequence_start.style = (*node).data.sequence.style;
if yaml_emitter_emit(emitter, event).fail {
if yaml_emitter_emit(emitter, event).is_err() {
return FAIL;
}
item = (*node).data.sequence.items.start;
while item < (*node).data.sequence.items.top {
if yaml_emitter_dump_node(emitter, *item).fail {
if yaml_emitter_dump_node(emitter, *item).is_err() {
return FAIL;
}
item = item.wrapping_offset(1);
@ -400,7 +403,7 @@ unsafe fn yaml_emitter_dump_mapping(
emitter: *mut yaml_emitter_t,
node: *mut yaml_node_t,
anchor: *mut yaml_char_t,
) -> Success {
) -> Result<(), ()> {
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
let mark = yaml_mark_t {
@ -425,15 +428,15 @@ unsafe fn yaml_emitter_dump_mapping(
(*event).data.mapping_start.tag = (*node).tag;
(*event).data.mapping_start.implicit = implicit;
(*event).data.mapping_start.style = (*node).data.mapping.style;
if yaml_emitter_emit(emitter, event).fail {
if yaml_emitter_emit(emitter, event).is_err() {
return FAIL;
}
pair = (*node).data.mapping.pairs.start;
while pair < (*node).data.mapping.pairs.top {
if yaml_emitter_dump_node(emitter, (*pair).key).fail {
if yaml_emitter_dump_node(emitter, (*pair).key).is_err() {
return FAIL;
}
if yaml_emitter_dump_node(emitter, (*pair).value).fail {
if yaml_emitter_dump_node(emitter, (*pair).value).is_err() {
return FAIL;
}
pair = pair.wrapping_offset(1);

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
use crate::api::{yaml_free, yaml_malloc, yaml_stack_extend, yaml_strdup};
use crate::externs::{memset, strcmp};
use crate::success::{Success, FAIL, OK};
use crate::success::{FAIL, OK};
use crate::yaml::yaml_char_t;
use crate::{
libc, yaml_alias_data_t, yaml_document_delete, yaml_document_t, yaml_event_t, yaml_mark_t,
@ -37,7 +37,7 @@ struct loader_ctx {
pub unsafe fn yaml_parser_load(
parser: *mut yaml_parser_t,
document: *mut yaml_document_t,
) -> Success {
) -> Result<(), ()> {
let current_block: u64;
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
@ -50,7 +50,7 @@ pub unsafe fn yaml_parser_load(
);
STACK_INIT!((*document).nodes, yaml_node_t);
if !(*parser).stream_start_produced {
if yaml_parser_parse(parser, event).fail {
if yaml_parser_parse(parser, event).is_err() {
current_block = 6234624449317607669;
} else {
__assert!((*event).type_ == YAML_STREAM_START_EVENT);
@ -63,14 +63,14 @@ pub unsafe fn yaml_parser_load(
if (*parser).stream_end_produced {
return OK;
}
if yaml_parser_parse(parser, event).ok {
if yaml_parser_parse(parser, event).is_ok() {
if (*event).type_ == YAML_STREAM_END_EVENT {
return OK;
}
STACK_INIT!((*parser).aliases, yaml_alias_data_t);
let fresh6 = addr_of_mut!((*parser).document);
*fresh6 = document;
if yaml_parser_load_document(parser, event).ok {
if yaml_parser_load_document(parser, event).is_ok() {
yaml_parser_delete_aliases(parser);
let fresh7 = addr_of_mut!((*parser).document);
*fresh7 = ptr::null_mut::<yaml_document_t>();
@ -89,7 +89,7 @@ unsafe fn yaml_parser_set_composer_error(
parser: *mut yaml_parser_t,
problem: *const libc::c_char,
problem_mark: yaml_mark_t,
) -> Success {
) -> Result<(), ()> {
(*parser).error = YAML_COMPOSER_ERROR;
let fresh9 = addr_of_mut!((*parser).problem);
*fresh9 = problem;
@ -103,7 +103,7 @@ unsafe fn yaml_parser_set_composer_error_context(
context_mark: yaml_mark_t,
problem: *const libc::c_char,
problem_mark: yaml_mark_t,
) -> Success {
) -> Result<(), ()> {
(*parser).error = YAML_COMPOSER_ERROR;
let fresh10 = addr_of_mut!((*parser).context);
*fresh10 = context;
@ -124,7 +124,7 @@ unsafe fn yaml_parser_delete_aliases(parser: *mut yaml_parser_t) {
unsafe fn yaml_parser_load_document(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
let mut ctx = loader_ctx {
start: ptr::null_mut::<libc::c_int>(),
end: ptr::null_mut::<libc::c_int>(),
@ -140,7 +140,7 @@ unsafe fn yaml_parser_load_document(
(*(*parser).document).start_implicit = (*event).data.document_start.implicit;
(*(*parser).document).start_mark = (*event).start_mark;
STACK_INIT!(ctx, libc::c_int);
if yaml_parser_load_nodes(parser, addr_of_mut!(ctx)).fail {
if yaml_parser_load_nodes(parser, addr_of_mut!(ctx)).is_err() {
STACK_DEL!(ctx);
return FAIL;
}
@ -148,41 +148,44 @@ unsafe fn yaml_parser_load_document(
OK
}
unsafe fn yaml_parser_load_nodes(parser: *mut yaml_parser_t, ctx: *mut loader_ctx) -> Success {
unsafe fn yaml_parser_load_nodes(
parser: *mut yaml_parser_t,
ctx: *mut loader_ctx,
) -> Result<(), ()> {
let mut event = MaybeUninit::<yaml_event_t>::uninit();
let event = event.as_mut_ptr();
loop {
if yaml_parser_parse(parser, event).fail {
if yaml_parser_parse(parser, event).is_err() {
return FAIL;
}
match (*event).type_ {
YAML_ALIAS_EVENT => {
if yaml_parser_load_alias(parser, event, ctx).fail {
if yaml_parser_load_alias(parser, event, ctx).is_err() {
return FAIL;
}
}
YAML_SCALAR_EVENT => {
if yaml_parser_load_scalar(parser, event, ctx).fail {
if yaml_parser_load_scalar(parser, event, ctx).is_err() {
return FAIL;
}
}
YAML_SEQUENCE_START_EVENT => {
if yaml_parser_load_sequence(parser, event, ctx).fail {
if yaml_parser_load_sequence(parser, event, ctx).is_err() {
return FAIL;
}
}
YAML_SEQUENCE_END_EVENT => {
if yaml_parser_load_sequence_end(parser, event, ctx).fail {
if yaml_parser_load_sequence_end(parser, event, ctx).is_err() {
return FAIL;
}
}
YAML_MAPPING_START_EVENT => {
if yaml_parser_load_mapping(parser, event, ctx).fail {
if yaml_parser_load_mapping(parser, event, ctx).is_err() {
return FAIL;
}
}
YAML_MAPPING_END_EVENT => {
if yaml_parser_load_mapping_end(parser, event, ctx).fail {
if yaml_parser_load_mapping_end(parser, event, ctx).is_err() {
return FAIL;
}
}
@ -204,7 +207,7 @@ unsafe fn yaml_parser_register_anchor(
parser: *mut yaml_parser_t,
index: libc::c_int,
anchor: *mut yaml_char_t,
) -> Success {
) -> Result<(), ()> {
let mut data = MaybeUninit::<yaml_alias_data_t>::uninit();
let data = data.as_mut_ptr();
let mut alias_data: *mut yaml_alias_data_t;
@ -244,7 +247,7 @@ unsafe fn yaml_parser_load_node_add(
parser: *mut yaml_parser_t,
ctx: *mut loader_ctx,
index: libc::c_int,
) -> Success {
) -> Result<(), ()> {
if STACK_EMPTY!(*ctx) {
return OK;
}
@ -255,7 +258,7 @@ unsafe fn yaml_parser_load_node_add(
let current_block_17: u64;
match (*parent).type_ {
YAML_SEQUENCE_NODE => {
if STACK_LIMIT!(parser, (*parent).data.sequence.items).fail {
if STACK_LIMIT!(parser, (*parent).data.sequence.items).is_err() {
return FAIL;
}
PUSH!((*parent).data.sequence.items, index);
@ -280,7 +283,7 @@ unsafe fn yaml_parser_load_node_add(
_ => {
(*pair).key = index;
(*pair).value = 0;
if STACK_LIMIT!(parser, (*parent).data.mapping.pairs).fail {
if STACK_LIMIT!(parser, (*parent).data.mapping.pairs).is_err() {
return FAIL;
}
PUSH!((*parent).data.mapping.pairs, *pair);
@ -298,7 +301,7 @@ unsafe fn yaml_parser_load_alias(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
ctx: *mut loader_ctx,
) -> Success {
) -> Result<(), ()> {
let anchor: *mut yaml_char_t = (*event).data.alias.anchor;
let mut alias_data: *mut yaml_alias_data_t;
alias_data = (*parser).aliases.start;
@ -325,13 +328,13 @@ unsafe fn yaml_parser_load_scalar(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
ctx: *mut loader_ctx,
) -> Success {
) -> Result<(), ()> {
let current_block: u64;
let mut node = MaybeUninit::<yaml_node_t>::uninit();
let node = node.as_mut_ptr();
let index: libc::c_int;
let mut tag: *mut yaml_char_t = (*event).data.scalar.tag;
if STACK_LIMIT!(parser, (*(*parser).document).nodes).ok {
if STACK_LIMIT!(parser, (*(*parser).document).nodes).is_ok() {
if tag.is_null()
|| strcmp(
tag as *mut libc::c_char,
@ -369,7 +372,7 @@ unsafe fn yaml_parser_load_scalar(
.top
.c_offset_from((*(*parser).document).nodes.start)
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).is_err() {
return FAIL;
}
return yaml_parser_load_node_add(parser, ctx, index);
@ -385,7 +388,7 @@ unsafe fn yaml_parser_load_sequence(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
ctx: *mut loader_ctx,
) -> Success {
) -> Result<(), ()> {
let current_block: u64;
let mut node = MaybeUninit::<yaml_node_t>::uninit();
let node = node.as_mut_ptr();
@ -401,7 +404,7 @@ unsafe fn yaml_parser_load_sequence(
};
let index: libc::c_int;
let mut tag: *mut yaml_char_t = (*event).data.sequence_start.tag;
if STACK_LIMIT!(parser, (*(*parser).document).nodes).ok {
if STACK_LIMIT!(parser, (*(*parser).document).nodes).is_ok() {
if tag.is_null()
|| strcmp(
tag as *mut libc::c_char,
@ -441,14 +444,15 @@ unsafe fn yaml_parser_load_sequence(
.top
.c_offset_from((*(*parser).document).nodes.start)
as libc::c_int;
if yaml_parser_register_anchor(parser, index, (*event).data.sequence_start.anchor).fail
if yaml_parser_register_anchor(parser, index, (*event).data.sequence_start.anchor)
.is_err()
{
return FAIL;
}
if yaml_parser_load_node_add(parser, ctx, index).fail {
if yaml_parser_load_node_add(parser, ctx, index).is_err() {
return FAIL;
}
if STACK_LIMIT!(parser, *ctx).fail {
if STACK_LIMIT!(parser, *ctx).is_err() {
return FAIL;
}
PUSH!(*ctx, index);
@ -464,7 +468,7 @@ unsafe fn yaml_parser_load_sequence_end(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
ctx: *mut loader_ctx,
) -> Success {
) -> Result<(), ()> {
__assert!(((*ctx).top).c_offset_from((*ctx).start) as libc::c_long > 0_i64);
let index: libc::c_int = *(*ctx).top.wrapping_offset(-1_isize);
__assert!(
@ -484,7 +488,7 @@ unsafe fn yaml_parser_load_mapping(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
ctx: *mut loader_ctx,
) -> Success {
) -> Result<(), ()> {
let current_block: u64;
let mut node = MaybeUninit::<yaml_node_t>::uninit();
let node = node.as_mut_ptr();
@ -500,7 +504,7 @@ unsafe fn yaml_parser_load_mapping(
};
let index: libc::c_int;
let mut tag: *mut yaml_char_t = (*event).data.mapping_start.tag;
if STACK_LIMIT!(parser, (*(*parser).document).nodes).ok {
if STACK_LIMIT!(parser, (*(*parser).document).nodes).is_ok() {
if tag.is_null()
|| strcmp(
tag as *mut libc::c_char,
@ -540,13 +544,15 @@ unsafe fn yaml_parser_load_mapping(
.top
.c_offset_from((*(*parser).document).nodes.start)
as libc::c_int;
if yaml_parser_register_anchor(parser, index, (*event).data.mapping_start.anchor).fail {
if yaml_parser_register_anchor(parser, index, (*event).data.mapping_start.anchor)
.is_err()
{
return FAIL;
}
if yaml_parser_load_node_add(parser, ctx, index).fail {
if yaml_parser_load_node_add(parser, ctx, index).is_err() {
return FAIL;
}
if STACK_LIMIT!(parser, *ctx).fail {
if STACK_LIMIT!(parser, *ctx).is_err() {
return FAIL;
}
PUSH!(*ctx, index);
@ -562,7 +568,7 @@ unsafe fn yaml_parser_load_mapping_end(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
ctx: *mut loader_ctx,
) -> Success {
) -> Result<(), ()> {
__assert!(((*ctx).top).c_offset_from((*ctx).start) as libc::c_long > 0_i64);
let index: libc::c_int = *(*ctx).top.wrapping_offset(-1_isize);
__assert!(

View file

@ -2,7 +2,7 @@ use crate::api::{yaml_free, yaml_malloc, yaml_stack_extend, yaml_strdup};
use crate::externs::{memcpy, memset, strcmp, strlen};
use crate::ops::ForceAdd as _;
use crate::scanner::yaml_parser_fetch_more_tokens;
use crate::success::{Success, FAIL, OK};
use crate::success::{FAIL, OK};
use crate::yaml::{size_t, yaml_char_t};
use crate::{
libc, yaml_event_t, yaml_mark_t, yaml_parser_t, yaml_tag_directive_t, yaml_token_t,
@ -35,7 +35,7 @@ use core::mem::size_of;
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).ok {
if (*parser).token_available || yaml_parser_fetch_more_tokens(parser).is_ok() {
(*parser).tokens.head
} else {
ptr::null_mut::<yaml_token_t>()
@ -63,7 +63,10 @@ unsafe fn SKIP_TOKEN(parser: *mut yaml_parser_t) {
/// An application must not alternate the calls of yaml_parser_parse() with the
/// calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the
/// parser.
pub unsafe fn yaml_parser_parse(parser: *mut yaml_parser_t, event: *mut yaml_event_t) -> Success {
pub unsafe fn yaml_parser_parse(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Result<(), ()> {
__assert!(!parser.is_null());
__assert!(!event.is_null());
memset(
@ -110,7 +113,7 @@ unsafe fn yaml_parser_set_parser_error_context(
unsafe fn yaml_parser_state_machine(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
match (*parser).state {
YAML_PARSE_STREAM_START_STATE => yaml_parser_parse_stream_start(parser, event),
YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE => {
@ -176,7 +179,7 @@ unsafe fn yaml_parser_state_machine(
unsafe fn yaml_parser_parse_stream_start(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
let token: *mut yaml_token_t = PEEK_TOKEN(parser);
if token.is_null() {
return FAIL;
@ -207,7 +210,7 @@ unsafe fn yaml_parser_parse_document_start(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
implicit: bool,
) -> Success {
) -> Result<(), ()> {
let mut token: *mut yaml_token_t;
let mut version_directive: *mut yaml_version_directive_t =
ptr::null_mut::<yaml_version_directive_t>();
@ -244,7 +247,7 @@ unsafe fn yaml_parser_parse_document_start(
ptr::null_mut::<*mut yaml_tag_directive_t>(),
ptr::null_mut::<*mut yaml_tag_directive_t>(),
)
.fail
.is_err()
{
return FAIL;
}
@ -275,7 +278,7 @@ unsafe fn yaml_parser_parse_document_start(
addr_of_mut!(tag_directives.start),
addr_of_mut!(tag_directives.end),
)
.fail
.is_err()
{
return FAIL;
}
@ -338,7 +341,7 @@ unsafe fn yaml_parser_parse_document_start(
unsafe fn yaml_parser_parse_document_content(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
let token: *mut yaml_token_t = PEEK_TOKEN(parser);
if token.is_null() {
return FAIL;
@ -359,7 +362,7 @@ unsafe fn yaml_parser_parse_document_content(
unsafe fn yaml_parser_parse_document_end(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
let mut end_mark: yaml_mark_t;
let mut implicit = true;
let token: *mut yaml_token_t = PEEK_TOKEN(parser);
@ -396,7 +399,7 @@ unsafe fn yaml_parser_parse_node(
event: *mut yaml_event_t,
block: bool,
indentless_sequence: bool,
) -> Success {
) -> Result<(), ()> {
let mut current_block: u64;
let mut token: *mut yaml_token_t;
let mut anchor: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
@ -724,7 +727,7 @@ unsafe fn yaml_parser_parse_block_sequence_entry(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
first: bool,
) -> Success {
) -> Result<(), ()> {
let mut token: *mut yaml_token_t;
if first {
token = PEEK_TOKEN(parser);
@ -777,7 +780,7 @@ unsafe fn yaml_parser_parse_block_sequence_entry(
unsafe fn yaml_parser_parse_indentless_sequence_entry(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
let mut token: *mut yaml_token_t;
token = PEEK_TOKEN(parser);
if token.is_null() {
@ -819,7 +822,7 @@ unsafe fn yaml_parser_parse_block_mapping_key(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
first: bool,
) -> Success {
) -> Result<(), ()> {
let mut token: *mut yaml_token_t;
if first {
token = PEEK_TOKEN(parser);
@ -875,7 +878,7 @@ unsafe fn yaml_parser_parse_block_mapping_key(
unsafe fn yaml_parser_parse_block_mapping_value(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
let mut token: *mut yaml_token_t;
token = PEEK_TOKEN(parser);
if token.is_null() {
@ -908,7 +911,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
first: bool,
) -> Success {
) -> Result<(), ()> {
let mut token: *mut yaml_token_t;
if first {
token = PEEK_TOKEN(parser);
@ -978,7 +981,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry(
unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_key(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
let token: *mut yaml_token_t = PEEK_TOKEN(parser);
if token.is_null() {
return FAIL;
@ -1003,7 +1006,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_key(
unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_value(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
let mut token: *mut yaml_token_t;
token = PEEK_TOKEN(parser);
if token.is_null() {
@ -1031,7 +1034,7 @@ unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_value(
unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_end(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
) -> Success {
) -> Result<(), ()> {
let token: *mut yaml_token_t = PEEK_TOKEN(parser);
if token.is_null() {
return FAIL;
@ -1052,7 +1055,7 @@ unsafe fn yaml_parser_parse_flow_mapping_key(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
first: bool,
) -> Success {
) -> Result<(), ()> {
let mut token: *mut yaml_token_t;
if first {
token = PEEK_TOKEN(parser);
@ -1121,7 +1124,7 @@ unsafe fn yaml_parser_parse_flow_mapping_value(
parser: *mut yaml_parser_t,
event: *mut yaml_event_t,
empty: bool,
) -> Success {
) -> Result<(), ()> {
let mut token: *mut yaml_token_t;
token = PEEK_TOKEN(parser);
if token.is_null() {
@ -1147,7 +1150,10 @@ unsafe fn yaml_parser_parse_flow_mapping_value(
yaml_parser_process_empty_scalar(event, (*token).start_mark)
}
unsafe fn yaml_parser_process_empty_scalar(event: *mut yaml_event_t, mark: yaml_mark_t) -> Success {
unsafe fn yaml_parser_process_empty_scalar(
event: *mut yaml_event_t,
mark: yaml_mark_t,
) -> Result<(), ()> {
let value: *mut yaml_char_t = yaml_malloc(1_u64) as *mut yaml_char_t;
*value = b'\0';
memset(
@ -1176,7 +1182,7 @@ unsafe fn yaml_parser_process_directives(
version_directive_ref: *mut *mut yaml_version_directive_t,
tag_directives_start_ref: *mut *mut yaml_tag_directive_t,
tag_directives_end_ref: *mut *mut yaml_tag_directive_t,
) -> Success {
) -> Result<(), ()> {
let mut current_block: u64;
let mut default_tag_directives: [yaml_tag_directive_t; 3] = [
yaml_tag_directive_t {
@ -1248,7 +1254,8 @@ 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)
.is_err()
{
current_block = 17143798186130252483;
break;
@ -1275,7 +1282,7 @@ unsafe fn yaml_parser_process_directives(
true,
(*token).start_mark,
)
.fail
.is_err()
{
current_block = 17143798186130252483;
break;
@ -1320,7 +1327,7 @@ unsafe fn yaml_parser_append_tag_directive(
value: yaml_tag_directive_t,
allow_duplicates: bool,
mark: yaml_mark_t,
) -> Success {
) -> Result<(), ()> {
let mut tag_directive: *mut yaml_tag_directive_t;
let mut copy = yaml_tag_directive_t {
handle: ptr::null_mut::<yaml_char_t>(),

View file

@ -1,6 +1,6 @@
use crate::externs::{memcmp, memmove};
use crate::ops::ForceAdd as _;
use crate::success::{Success, FAIL, OK};
use crate::success::{FAIL, OK};
use crate::yaml::{size_t, yaml_char_t};
use crate::{
libc, yaml_parser_t, PointerExt, YAML_ANY_ENCODING, YAML_READER_ERROR, YAML_UTF16BE_ENCODING,
@ -13,7 +13,7 @@ unsafe fn yaml_parser_set_reader_error(
problem: *const libc::c_char,
offset: size_t,
value: libc::c_int,
) -> Success {
) -> Result<(), ()> {
(*parser).error = YAML_READER_ERROR;
let fresh0 = addr_of_mut!((*parser).problem);
*fresh0 = problem;
@ -26,7 +26,7 @@ const BOM_UTF8: *const libc::c_char = b"\xEF\xBB\xBF\0" as *const u8 as *const l
const BOM_UTF16LE: *const libc::c_char = b"\xFF\xFE\0" as *const u8 as *const libc::c_char;
const BOM_UTF16BE: *const libc::c_char = b"\xFE\xFF\0" as *const u8 as *const libc::c_char;
unsafe fn yaml_parser_determine_encoding(parser: *mut yaml_parser_t) -> Success {
unsafe fn yaml_parser_determine_encoding(parser: *mut yaml_parser_t) -> Result<(), ()> {
while !(*parser).eof
&& ((*parser)
.raw_buffer
@ -34,7 +34,7 @@ unsafe fn yaml_parser_determine_encoding(parser: *mut yaml_parser_t) -> Success
.c_offset_from((*parser).raw_buffer.pointer) as libc::c_long)
< 3_i64
{
if yaml_parser_update_raw_buffer(parser).fail {
if yaml_parser_update_raw_buffer(parser).is_err() {
return FAIL;
}
}
@ -92,7 +92,7 @@ unsafe fn yaml_parser_determine_encoding(parser: *mut yaml_parser_t) -> Success
OK
}
unsafe fn yaml_parser_update_raw_buffer(parser: *mut yaml_parser_t) -> Success {
unsafe fn yaml_parser_update_raw_buffer(parser: *mut yaml_parser_t) -> Result<(), ()> {
let mut size_read: size_t = 0_u64;
if (*parser).raw_buffer.start == (*parser).raw_buffer.pointer
&& (*parser).raw_buffer.last == (*parser).raw_buffer.end
@ -152,7 +152,7 @@ unsafe fn yaml_parser_update_raw_buffer(parser: *mut yaml_parser_t) -> Success {
pub(crate) unsafe fn yaml_parser_update_buffer(
parser: *mut yaml_parser_t,
length: size_t,
) -> Success {
) -> Result<(), ()> {
let mut first = true;
__assert!(((*parser).read_handler).is_some());
if (*parser).eof && (*parser).raw_buffer.pointer == (*parser).raw_buffer.last {
@ -162,7 +162,7 @@ pub(crate) unsafe fn yaml_parser_update_buffer(
return OK;
}
if (*parser).encoding == YAML_ANY_ENCODING {
if yaml_parser_determine_encoding(parser).fail {
if yaml_parser_determine_encoding(parser).is_err() {
return FAIL;
}
}
@ -190,7 +190,7 @@ pub(crate) unsafe fn yaml_parser_update_buffer(
}
while (*parser).unread < length {
if !first || (*parser).raw_buffer.pointer == (*parser).raw_buffer.last {
if yaml_parser_update_raw_buffer(parser).fail {
if yaml_parser_update_raw_buffer(parser).is_err() {
return FAIL;
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,25 +1,4 @@
use core::ops::Deref;
pub const OK: Success = Success { ok: true };
pub const FAIL: Success = Success { ok: false };
#[must_use]
pub struct Success {
pub ok: bool,
}
pub struct Failure {
pub fail: bool,
}
impl Deref for Success {
type Target = Failure;
fn deref(&self) -> &Self::Target {
if self.ok {
&Failure { fail: false }
} else {
&Failure { fail: true }
}
}
}
pub const OK: Result<(), ()> = Ok(());
pub const FAIL: Result<(), ()> = Err(());

View file

@ -1,5 +1,5 @@
use crate::ops::ForceAdd as _;
use crate::success::{Success, FAIL, OK};
use crate::success::{FAIL, OK};
use crate::yaml::size_t;
use crate::{
libc, yaml_emitter_t, PointerExt, YAML_ANY_ENCODING, YAML_UTF16LE_ENCODING, YAML_UTF8_ENCODING,
@ -10,7 +10,7 @@ use core::ptr::addr_of_mut;
unsafe fn yaml_emitter_set_writer_error(
emitter: *mut yaml_emitter_t,
problem: *const libc::c_char,
) -> Success {
) -> Result<(), ()> {
(*emitter).error = YAML_WRITER_ERROR;
let fresh0 = addr_of_mut!((*emitter).problem);
*fresh0 = problem;
@ -18,7 +18,7 @@ unsafe fn yaml_emitter_set_writer_error(
}
/// Flush the accumulated characters to the output.
pub unsafe fn yaml_emitter_flush(emitter: *mut yaml_emitter_t) -> Success {
pub unsafe fn yaml_emitter_flush(emitter: *mut yaml_emitter_t) -> Result<(), ()> {
__assert!(!emitter.is_null());
__assert!(((*emitter).write_handler).is_some());
__assert!((*emitter).encoding != YAML_ANY_ENCODING);