Replace libc integer types with Rust integer types

This commit is contained in:
Simon Ask Ulsnes 2024-02-02 11:10:04 +01:00
parent ac00cee574
commit 11c9cd60c9
9 changed files with 215 additions and 239 deletions

View file

@ -3,7 +3,7 @@ use alloc::vec::Vec;
use crate::yaml::{YamlEventData, YamlNodeData}; use crate::yaml::{YamlEventData, YamlNodeData};
use crate::{ use crate::{
libc, yaml_break_t, yaml_document_t, yaml_emitter_state_t, yaml_emitter_t, yaml_encoding_t, yaml_break_t, yaml_document_t, yaml_emitter_state_t, yaml_emitter_t, yaml_encoding_t,
yaml_event_t, yaml_mapping_style_t, yaml_mark_t, yaml_node_pair_t, yaml_node_t, yaml_event_t, yaml_mapping_style_t, yaml_mark_t, yaml_node_pair_t, yaml_node_t,
yaml_parser_state_t, yaml_parser_t, yaml_scalar_style_t, yaml_sequence_style_t, yaml_parser_state_t, yaml_parser_t, yaml_scalar_style_t, yaml_sequence_style_t,
yaml_tag_directive_t, yaml_version_directive_t, YAML_ANY_ENCODING, YAML_UTF8_ENCODING, yaml_tag_directive_t, yaml_version_directive_t, YAML_ANY_ENCODING, YAML_UTF8_ENCODING,
@ -172,12 +172,12 @@ pub fn yaml_emitter_set_canonical(emitter: &mut yaml_emitter_t, canonical: bool)
} }
/// Set the indentation increment. /// Set the indentation increment.
pub fn yaml_emitter_set_indent(emitter: &mut yaml_emitter_t, indent: libc::c_int) { pub fn yaml_emitter_set_indent(emitter: &mut yaml_emitter_t, indent: i32) {
emitter.best_indent = if 1 < indent && indent < 10 { indent } else { 2 }; emitter.best_indent = if 1 < indent && indent < 10 { indent } else { 2 };
} }
/// Set the preferred line width. -1 means unlimited. /// Set the preferred line width. -1 means unlimited.
pub fn yaml_emitter_set_width(emitter: &mut yaml_emitter_t, width: libc::c_int) { pub fn yaml_emitter_set_width(emitter: &mut yaml_emitter_t, width: i32) {
emitter.best_width = if width >= 0 { width } else { -1 }; emitter.best_width = if width >= 0 { width } else { -1 };
} }
@ -408,10 +408,7 @@ pub fn yaml_document_delete(document: &mut yaml_document_t) {
/// modifying the documents are called. /// modifying the documents are called.
/// ///
/// Returns the node object or NULL if `index` is out of range. /// Returns the node object or NULL if `index` is out of range.
pub fn yaml_document_get_node( pub fn yaml_document_get_node(document: &mut yaml_document_t, index: i32) -> *mut yaml_node_t {
document: &mut yaml_document_t,
index: libc::c_int,
) -> *mut yaml_node_t {
if index > 0 && index as usize <= document.nodes.len() { if index > 0 && index as usize <= document.nodes.len() {
return std::ptr::addr_of_mut!(document.nodes[index as usize - 1]); return std::ptr::addr_of_mut!(document.nodes[index as usize - 1]);
} }
@ -447,7 +444,7 @@ pub fn yaml_document_add_scalar(
tag: Option<&str>, tag: Option<&str>,
value: &str, value: &str,
style: yaml_scalar_style_t, style: yaml_scalar_style_t,
) -> libc::c_int { ) -> i32 {
let mark = yaml_mark_t { let mark = yaml_mark_t {
index: 0_u64, index: 0_u64,
line: 0_u64, line: 0_u64,
@ -466,7 +463,7 @@ pub fn yaml_document_add_scalar(
end_mark: mark, end_mark: mark,
}; };
document.nodes.push(node); document.nodes.push(node);
document.nodes.len() as libc::c_int document.nodes.len() as i32
} }
/// Create a SEQUENCE node and attach it to the document. /// Create a SEQUENCE node and attach it to the document.
@ -479,7 +476,7 @@ pub fn yaml_document_add_sequence(
document: &mut yaml_document_t, document: &mut yaml_document_t,
tag: Option<&str>, tag: Option<&str>,
style: yaml_sequence_style_t, style: yaml_sequence_style_t,
) -> libc::c_int { ) -> i32 {
let mark = yaml_mark_t { let mark = yaml_mark_t {
index: 0_u64, index: 0_u64,
line: 0_u64, line: 0_u64,
@ -496,7 +493,7 @@ pub fn yaml_document_add_sequence(
end_mark: mark, end_mark: mark,
}; };
document.nodes.push(node); document.nodes.push(node);
document.nodes.len() as libc::c_int document.nodes.len() as i32
} }
/// Create a MAPPING node and attach it to the document. /// Create a MAPPING node and attach it to the document.
@ -509,7 +506,7 @@ pub fn yaml_document_add_mapping(
document: &mut yaml_document_t, document: &mut yaml_document_t,
tag: Option<&str>, tag: Option<&str>,
style: yaml_mapping_style_t, style: yaml_mapping_style_t,
) -> libc::c_int { ) -> i32 {
let mark = yaml_mark_t { let mark = yaml_mark_t {
index: 0_u64, index: 0_u64,
line: 0_u64, line: 0_u64,
@ -527,14 +524,14 @@ pub fn yaml_document_add_mapping(
}; };
document.nodes.push(node); document.nodes.push(node);
document.nodes.len() as libc::c_int document.nodes.len() as i32
} }
/// Add an item to a SEQUENCE node. /// Add an item to a SEQUENCE node.
pub fn yaml_document_append_sequence_item( pub fn yaml_document_append_sequence_item(
document: &mut yaml_document_t, document: &mut yaml_document_t,
sequence: libc::c_int, sequence: i32,
item: libc::c_int, item: i32,
) { ) {
__assert!(sequence > 0 && sequence as usize - 1 < document.nodes.len()); __assert!(sequence > 0 && sequence as usize - 1 < document.nodes.len());
__assert!(matches!( __assert!(matches!(
@ -552,9 +549,9 @@ pub fn yaml_document_append_sequence_item(
/// Add a pair of a key and a value to a MAPPING node. /// Add a pair of a key and a value to a MAPPING node.
pub fn yaml_document_append_mapping_pair( pub fn yaml_document_append_mapping_pair(
document: &mut yaml_document_t, document: &mut yaml_document_t,
mapping: libc::c_int, mapping: i32,
key: libc::c_int, key: i32,
value: libc::c_int, value: i32,
) { ) {
__assert!(mapping > 0 && mapping as usize - 1 < document.nodes.len()); __assert!(mapping > 0 && mapping as usize - 1 < document.nodes.len());
__assert!(matches!( __assert!(matches!(

View file

@ -5,7 +5,7 @@ use crate::yaml::{
yaml_anchors_t, yaml_document_t, yaml_emitter_t, yaml_event_t, yaml_node_t, YamlEventData, yaml_anchors_t, yaml_document_t, yaml_emitter_t, yaml_event_t, yaml_node_t, YamlEventData,
YamlNodeData, YAML_ANY_ENCODING, YamlNodeData, YAML_ANY_ENCODING,
}; };
use crate::{libc, yaml_document_delete, yaml_emitter_emit, EmitterError}; use crate::{yaml_document_delete, yaml_emitter_emit, EmitterError};
/// Start a YAML stream. /// Start a YAML stream.
/// ///
@ -112,7 +112,7 @@ fn yaml_emitter_delete_document_and_anchors(
emitter.last_anchor_id = 0; emitter.last_anchor_id = 0;
} }
fn yaml_emitter_anchor_node_sub(emitter: &mut yaml_emitter_t, index: libc::c_int) { fn yaml_emitter_anchor_node_sub(emitter: &mut yaml_emitter_t, index: i32) {
emitter.anchors[index as usize - 1].references += 1; emitter.anchors[index as usize - 1].references += 1;
if emitter.anchors[index as usize - 1].references == 2 { if emitter.anchors[index as usize - 1].references == 2 {
emitter.last_anchor_id += 1; emitter.last_anchor_id += 1;
@ -123,7 +123,7 @@ fn yaml_emitter_anchor_node_sub(emitter: &mut yaml_emitter_t, index: libc::c_int
fn yaml_emitter_anchor_node( fn yaml_emitter_anchor_node(
emitter: &mut yaml_emitter_t, emitter: &mut yaml_emitter_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
index: libc::c_int, index: i32,
) { ) {
let node = &document.nodes[index as usize - 1]; let node = &document.nodes[index as usize - 1];
emitter.anchors[index as usize - 1].references += 1; emitter.anchors[index as usize - 1].references += 1;
@ -148,17 +148,17 @@ fn yaml_emitter_anchor_node(
} }
} }
fn yaml_emitter_generate_anchor(_emitter: &mut yaml_emitter_t, anchor_id: libc::c_int) -> String { fn yaml_emitter_generate_anchor(_emitter: &mut yaml_emitter_t, anchor_id: i32) -> String {
alloc::format!("id{anchor_id:03}") alloc::format!("id{anchor_id:03}")
} }
fn yaml_emitter_dump_node( fn yaml_emitter_dump_node(
emitter: &mut yaml_emitter_t, emitter: &mut yaml_emitter_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
index: libc::c_int, index: i32,
) -> Result<(), EmitterError> { ) -> Result<(), EmitterError> {
let node = &mut document.nodes[index as usize - 1]; let node = &mut document.nodes[index as usize - 1];
let anchor_id: libc::c_int = emitter.anchors[index as usize - 1].anchor; let anchor_id: i32 = emitter.anchors[index as usize - 1].anchor;
let mut anchor: Option<String> = None; let mut anchor: Option<String> = None;
if anchor_id != 0 { if anchor_id != 0 {
anchor = Some(yaml_emitter_generate_anchor(emitter, anchor_id)); anchor = Some(yaml_emitter_generate_anchor(emitter, anchor_id));

View file

@ -7,20 +7,20 @@ use crate::macros::{
use crate::ops::ForceMul as _; use crate::ops::ForceMul as _;
use crate::yaml::YamlEventData; use crate::yaml::YamlEventData;
use crate::{ use crate::{
libc, yaml_emitter_flush, yaml_emitter_t, yaml_event_t, yaml_scalar_style_t, yaml_emitter_flush, yaml_emitter_t, yaml_event_t, yaml_scalar_style_t, yaml_tag_directive_t,
yaml_tag_directive_t, yaml_version_directive_t, EmitterError, WriterError, YAML_ANY_BREAK, yaml_version_directive_t, EmitterError, WriterError, YAML_ANY_BREAK, YAML_ANY_ENCODING,
YAML_ANY_ENCODING, YAML_ANY_SCALAR_STYLE, YAML_CRLN_BREAK, YAML_CR_BREAK, YAML_ANY_SCALAR_STYLE, YAML_CRLN_BREAK, YAML_CR_BREAK, YAML_DOUBLE_QUOTED_SCALAR_STYLE,
YAML_DOUBLE_QUOTED_SCALAR_STYLE, YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE, YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE, YAML_EMIT_BLOCK_MAPPING_KEY_STATE,
YAML_EMIT_BLOCK_MAPPING_KEY_STATE, YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE, YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE, YAML_EMIT_BLOCK_MAPPING_VALUE_STATE,
YAML_EMIT_BLOCK_MAPPING_VALUE_STATE, YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE, YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE, YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE,
YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE, YAML_EMIT_DOCUMENT_CONTENT_STATE, YAML_EMIT_DOCUMENT_CONTENT_STATE, YAML_EMIT_DOCUMENT_END_STATE, YAML_EMIT_DOCUMENT_START_STATE,
YAML_EMIT_DOCUMENT_END_STATE, YAML_EMIT_DOCUMENT_START_STATE, YAML_EMIT_END_STATE, YAML_EMIT_END_STATE, YAML_EMIT_FIRST_DOCUMENT_START_STATE,
YAML_EMIT_FIRST_DOCUMENT_START_STATE, YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE, YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE, YAML_EMIT_FLOW_MAPPING_KEY_STATE,
YAML_EMIT_FLOW_MAPPING_KEY_STATE, YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE, YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE, YAML_EMIT_FLOW_MAPPING_VALUE_STATE,
YAML_EMIT_FLOW_MAPPING_VALUE_STATE, YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE, YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE, YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE,
YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE, YAML_EMIT_STREAM_START_STATE, YAML_FLOW_MAPPING_STYLE, YAML_EMIT_STREAM_START_STATE, YAML_FLOW_MAPPING_STYLE, YAML_FLOW_SEQUENCE_STYLE,
YAML_FLOW_SEQUENCE_STYLE, YAML_FOLDED_SCALAR_STYLE, YAML_LITERAL_SCALAR_STYLE, YAML_LN_BREAK, YAML_FOLDED_SCALAR_STYLE, YAML_LITERAL_SCALAR_STYLE, YAML_LN_BREAK, YAML_PLAIN_SCALAR_STYLE,
YAML_PLAIN_SCALAR_STYLE, YAML_SINGLE_QUOTED_SCALAR_STYLE, YAML_UTF8_ENCODING, YAML_SINGLE_QUOTED_SCALAR_STYLE, YAML_UTF8_ENCODING,
}; };
fn FLUSH(emitter: &mut yaml_emitter_t) -> Result<(), WriterError> { fn FLUSH(emitter: &mut yaml_emitter_t) -> Result<(), WriterError> {
@ -291,7 +291,7 @@ fn yaml_emitter_emit_stream_start(
emitter.best_width = 80; emitter.best_width = 80;
} }
if emitter.best_width < 0 { if emitter.best_width < 0 {
emitter.best_width = libc::c_int::MAX; emitter.best_width = i32::MAX;
} }
if emitter.line_break == YAML_ANY_BREAK { if emitter.line_break == YAML_ANY_BREAK {
emitter.line_break = YAML_LN_BREAK; emitter.line_break = YAML_LN_BREAK;
@ -1264,7 +1264,7 @@ fn yaml_emitter_write_bom(emitter: &mut yaml_emitter_t) -> Result<(), EmitterErr
} }
fn yaml_emitter_write_indent(emitter: &mut yaml_emitter_t) -> Result<(), EmitterError> { fn yaml_emitter_write_indent(emitter: &mut yaml_emitter_t) -> Result<(), EmitterError> {
let indent: libc::c_int = if emitter.indent >= 0 { let indent = if emitter.indent >= 0 {
emitter.indent emitter.indent
} else { } else {
0 0

View file

@ -21,7 +21,7 @@ pub enum ReaderError {
#[error("{problem}")] #[error("{problem}")]
Problem { Problem {
problem: &'static str, problem: &'static str,
offset: u64, offset: usize,
value: i32, value: i32,
}, },
#[error(transparent)] #[error(transparent)]

View file

@ -38,12 +38,6 @@ extern crate alloc;
use core::mem::size_of; use core::mem::size_of;
mod libc {
pub use core::primitive::{
i32 as c_int, i64 as c_long, u32 as c_uint, u64 as c_ulong, u8 as c_uchar,
};
}
#[macro_use] #[macro_use]
mod externs { mod externs {
macro_rules! __assert { macro_rules! __assert {

View file

@ -3,7 +3,7 @@ use alloc::{vec, vec::Vec};
use crate::yaml::{YamlEventData, YamlNodeData}; use crate::yaml::{YamlEventData, YamlNodeData};
use crate::{ use crate::{
libc, yaml_alias_data_t, yaml_document_new, yaml_document_t, yaml_event_t, yaml_mark_t, yaml_alias_data_t, yaml_document_new, yaml_document_t, yaml_event_t, yaml_mark_t,
yaml_node_pair_t, yaml_node_t, yaml_parser_parse, yaml_parser_t, ComposerError, yaml_node_pair_t, yaml_node_t, yaml_parser_parse, yaml_parser_t, ComposerError,
}; };
@ -118,7 +118,7 @@ fn yaml_parser_load_document(
fn yaml_parser_load_nodes( fn yaml_parser_load_nodes(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
ctx: &mut Vec<libc::c_int>, ctx: &mut Vec<i32>,
) -> Result<(), ComposerError> { ) -> Result<(), ComposerError> {
let end_implicit; let end_implicit;
let end_mark; let end_mark;
@ -163,7 +163,7 @@ fn yaml_parser_load_nodes(
fn yaml_parser_register_anchor( fn yaml_parser_register_anchor(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
index: libc::c_int, index: i32,
anchor: Option<String>, anchor: Option<String>,
) -> Result<(), ComposerError> { ) -> Result<(), ComposerError> {
let Some(anchor) = anchor else { let Some(anchor) = anchor else {
@ -190,13 +190,13 @@ fn yaml_parser_register_anchor(
fn yaml_parser_load_node_add( fn yaml_parser_load_node_add(
document: &mut yaml_document_t, document: &mut yaml_document_t,
ctx: &mut Vec<libc::c_int>, ctx: &mut Vec<i32>,
index: libc::c_int, index: i32,
) -> Result<(), ComposerError> { ) -> Result<(), ComposerError> {
if ctx.is_empty() { if ctx.is_empty() {
return Ok(()); return Ok(());
} }
let parent_index: libc::c_int = *ctx.last().unwrap(); let parent_index: i32 = *ctx.last().unwrap();
let parent = &mut document.nodes[parent_index as usize - 1]; let parent = &mut document.nodes[parent_index as usize - 1];
match parent.data { match parent.data {
YamlNodeData::Sequence { ref mut items, .. } => { YamlNodeData::Sequence { ref mut items, .. } => {
@ -229,7 +229,7 @@ fn yaml_parser_load_alias(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
event: yaml_event_t, event: yaml_event_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
ctx: &mut Vec<libc::c_int>, ctx: &mut Vec<i32>,
) -> Result<(), ComposerError> { ) -> Result<(), ComposerError> {
let anchor: &str = if let YamlEventData::Alias { anchor } = &event.data { let anchor: &str = if let YamlEventData::Alias { anchor } = &event.data {
anchor anchor
@ -250,7 +250,7 @@ fn yaml_parser_load_scalar(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
event: yaml_event_t, event: yaml_event_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
ctx: &mut Vec<libc::c_int>, ctx: &mut Vec<i32>,
) -> Result<(), ComposerError> { ) -> Result<(), ComposerError> {
let YamlEventData::Scalar { let YamlEventData::Scalar {
mut tag, mut tag,
@ -273,7 +273,7 @@ fn yaml_parser_load_scalar(
end_mark: event.end_mark, end_mark: event.end_mark,
}; };
document.nodes.push(node); document.nodes.push(node);
let index: libc::c_int = document.nodes.len() as libc::c_int; let index: i32 = document.nodes.len() as i32;
yaml_parser_register_anchor(parser, document, index, anchor)?; yaml_parser_register_anchor(parser, document, index, anchor)?;
yaml_parser_load_node_add(document, ctx, index) yaml_parser_load_node_add(document, ctx, index)
} }
@ -282,7 +282,7 @@ fn yaml_parser_load_sequence(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
event: yaml_event_t, event: yaml_event_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
ctx: &mut Vec<libc::c_int>, ctx: &mut Vec<i32>,
) -> Result<(), ComposerError> { ) -> Result<(), ComposerError> {
let YamlEventData::SequenceStart { let YamlEventData::SequenceStart {
anchor, anchor,
@ -311,7 +311,7 @@ fn yaml_parser_load_sequence(
}; };
document.nodes.push(node); document.nodes.push(node);
let index: libc::c_int = document.nodes.len() as libc::c_int; let index: i32 = document.nodes.len() as i32;
yaml_parser_register_anchor(parser, document, index, anchor.clone())?; yaml_parser_register_anchor(parser, document, index, anchor.clone())?;
yaml_parser_load_node_add(document, ctx, index)?; yaml_parser_load_node_add(document, ctx, index)?;
ctx.push(index); ctx.push(index);
@ -322,10 +322,10 @@ fn yaml_parser_load_sequence_end(
_parser: &mut yaml_parser_t, _parser: &mut yaml_parser_t,
event: yaml_event_t, event: yaml_event_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
ctx: &mut Vec<libc::c_int>, ctx: &mut Vec<i32>,
) -> Result<(), ComposerError> { ) -> Result<(), ComposerError> {
__assert!(!ctx.is_empty()); __assert!(!ctx.is_empty());
let index: libc::c_int = *ctx.last().unwrap(); let index: i32 = *ctx.last().unwrap();
__assert!(matches!( __assert!(matches!(
document.nodes[index as usize - 1].data, document.nodes[index as usize - 1].data,
YamlNodeData::Sequence { .. } YamlNodeData::Sequence { .. }
@ -339,7 +339,7 @@ fn yaml_parser_load_mapping(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
event: yaml_event_t, event: yaml_event_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
ctx: &mut Vec<libc::c_int>, ctx: &mut Vec<i32>,
) -> Result<(), ComposerError> { ) -> Result<(), ComposerError> {
let YamlEventData::MappingStart { let YamlEventData::MappingStart {
anchor, anchor,
@ -366,7 +366,7 @@ fn yaml_parser_load_mapping(
end_mark: event.end_mark, end_mark: event.end_mark,
}; };
document.nodes.push(node); document.nodes.push(node);
let index: libc::c_int = document.nodes.len() as libc::c_int; let index: i32 = document.nodes.len() as i32;
yaml_parser_register_anchor(parser, document, index, anchor)?; yaml_parser_register_anchor(parser, document, index, anchor)?;
yaml_parser_load_node_add(document, ctx, index)?; yaml_parser_load_node_add(document, ctx, index)?;
ctx.push(index); ctx.push(index);
@ -377,10 +377,10 @@ fn yaml_parser_load_mapping_end(
_parser: &mut yaml_parser_t, _parser: &mut yaml_parser_t,
event: yaml_event_t, event: yaml_event_t,
document: &mut yaml_document_t, document: &mut yaml_document_t,
ctx: &mut Vec<libc::c_int>, ctx: &mut Vec<i32>,
) -> Result<(), ComposerError> { ) -> Result<(), ComposerError> {
__assert!(!ctx.is_empty()); __assert!(!ctx.is_empty());
let index: libc::c_int = *ctx.last().unwrap(); let index: i32 = *ctx.last().unwrap();
__assert!(matches!( __assert!(matches!(
document.nodes[index as usize - 1].data, document.nodes[index as usize - 1].data,
YamlNodeData::Mapping { .. } YamlNodeData::Mapping { .. }

View file

@ -2,16 +2,15 @@ use alloc::collections::VecDeque;
use crate::api::INPUT_RAW_BUFFER_SIZE; use crate::api::INPUT_RAW_BUFFER_SIZE;
use crate::macros::vecdeque_starts_with; use crate::macros::vecdeque_starts_with;
use crate::yaml::size_t;
use crate::{ use crate::{
libc, yaml_parser_t, ReaderError, YAML_ANY_ENCODING, YAML_UTF16BE_ENCODING, yaml_parser_t, ReaderError, YAML_ANY_ENCODING, YAML_UTF16BE_ENCODING, YAML_UTF16LE_ENCODING,
YAML_UTF16LE_ENCODING, YAML_UTF8_ENCODING, YAML_UTF8_ENCODING,
}; };
fn yaml_parser_set_reader_error<T>( fn yaml_parser_set_reader_error<T>(
_parser: &mut yaml_parser_t, _parser: &mut yaml_parser_t,
problem: &'static str, problem: &'static str,
offset: u64, offset: usize,
value: i32, value: i32,
) -> Result<T, ReaderError> { ) -> Result<T, ReaderError> {
Err(ReaderError::Problem { Err(ReaderError::Problem {
@ -200,14 +199,14 @@ fn push_char(parser: &mut yaml_parser_t, ch: char) -> Result<(), ReaderError> {
); );
} }
parser.buffer.push_back(ch); parser.buffer.push_back(ch);
parser.offset += ch.len_utf8() as u64; parser.offset += ch.len_utf8();
parser.unread += 1; parser.unread += 1;
Ok(()) Ok(())
} }
pub(crate) fn yaml_parser_update_buffer( pub(crate) fn yaml_parser_update_buffer(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
length: size_t, length: usize,
) -> Result<(), ReaderError> { ) -> Result<(), ReaderError> {
let mut first = true; let mut first = true;
__assert!((parser.read_handler).is_some()); __assert!((parser.read_handler).is_some());
@ -259,7 +258,7 @@ pub(crate) fn yaml_parser_update_buffer(
return yaml_parser_set_reader_error( return yaml_parser_set_reader_error(
parser, parser,
"invalid trailing UTF-8 octet", "invalid trailing UTF-8 octet",
parser.offset + offset as u64, parser.offset + offset,
parser.raw_buffer[offset] as _, parser.raw_buffer[offset] as _,
); );
} }
@ -310,7 +309,7 @@ pub(crate) fn yaml_parser_update_buffer(
parser, parser,
"unexpected low surrogate area", "unexpected low surrogate area",
parser.offset, parser.offset,
value as libc::c_int, value as i32,
); );
} }
// Some(Err(Utf16Error::IncompleteSurrogatePair)) => { // Some(Err(Utf16Error::IncompleteSurrogatePair)) => {
@ -326,7 +325,7 @@ pub(crate) fn yaml_parser_update_buffer(
parser, parser,
"expected low surrogate area", "expected low surrogate area",
parser.offset + 2, parser.offset + 2,
value as libc::c_int, value as i32,
); );
} }
Some(Err(Utf16Error::InvalidUnicode(value))) => { Some(Err(Utf16Error::InvalidUnicode(value))) => {
@ -334,7 +333,7 @@ pub(crate) fn yaml_parser_update_buffer(
parser, parser,
"invalid Unicode character", "invalid Unicode character",
parser.offset, parser.offset,
value as libc::c_int, value as i32,
); );
} }
None => (), None => (),
@ -346,7 +345,7 @@ pub(crate) fn yaml_parser_update_buffer(
} }
} }
if parser.offset >= (!0_u64).wrapping_div(2_u64) { if parser.offset >= (!0_usize).wrapping_div(2_usize) {
return yaml_parser_set_reader_error(parser, "input is too long", parser.offset, -1); return yaml_parser_set_reader_error(parser, "input is too long", parser.offset, -1);
} }
Ok(()) Ok(())

View file

@ -3,14 +3,14 @@ use alloc::string::String;
use crate::macros::{is_blankz, is_break, vecdeque_starts_with}; use crate::macros::{is_blankz, is_break, vecdeque_starts_with};
use crate::ops::{ForceAdd as _, ForceMul as _}; use crate::ops::{ForceAdd as _, ForceMul as _};
use crate::reader::yaml_parser_update_buffer; use crate::reader::yaml_parser_update_buffer;
use crate::yaml::{ptrdiff_t, size_t, YamlTokenData}; use crate::yaml::YamlTokenData;
use crate::{ use crate::{
libc, yaml_mark_t, yaml_parser_t, yaml_simple_key_t, yaml_token_t, ReaderError, ScannerError, yaml_mark_t, yaml_parser_t, yaml_simple_key_t, yaml_token_t, ReaderError, ScannerError,
YAML_DOUBLE_QUOTED_SCALAR_STYLE, YAML_FOLDED_SCALAR_STYLE, YAML_LITERAL_SCALAR_STYLE, YAML_DOUBLE_QUOTED_SCALAR_STYLE, YAML_FOLDED_SCALAR_STYLE, YAML_LITERAL_SCALAR_STYLE,
YAML_PLAIN_SCALAR_STYLE, YAML_SINGLE_QUOTED_SCALAR_STYLE, YAML_PLAIN_SCALAR_STYLE, YAML_SINGLE_QUOTED_SCALAR_STYLE,
}; };
fn CACHE(parser: &mut yaml_parser_t, length: size_t) -> Result<(), ReaderError> { fn CACHE(parser: &mut yaml_parser_t, length: usize) -> Result<(), ReaderError> {
if parser.unread >= length { if parser.unread >= length {
Ok(()) Ok(())
} else { } else {
@ -160,15 +160,15 @@ pub(crate) fn yaml_parser_fetch_more_tokens(
} }
fn yaml_parser_fetch_next_token(parser: &mut yaml_parser_t) -> Result<(), ScannerError> { fn yaml_parser_fetch_next_token(parser: &mut yaml_parser_t) -> Result<(), ScannerError> {
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if !parser.stream_start_produced { if !parser.stream_start_produced {
yaml_parser_fetch_stream_start(parser); yaml_parser_fetch_stream_start(parser);
return Ok(()); return Ok(());
} }
yaml_parser_scan_to_next_token(parser)?; yaml_parser_scan_to_next_token(parser)?;
yaml_parser_stale_simple_keys(parser)?; yaml_parser_stale_simple_keys(parser)?;
yaml_parser_unroll_indent(parser, parser.mark.column as ptrdiff_t); yaml_parser_unroll_indent(parser, parser.mark.column as i64);
CACHE(parser, 4_u64)?; CACHE(parser, 4)?;
if IS_Z!(parser.buffer) { if IS_Z!(parser.buffer) {
return yaml_parser_fetch_stream_end(parser); return yaml_parser_fetch_stream_end(parser);
} }
@ -293,15 +293,12 @@ fn yaml_parser_stale_simple_keys(parser: &mut yaml_parser_t) -> Result<(), Scann
} }
fn yaml_parser_save_simple_key(parser: &mut yaml_parser_t) -> Result<(), ScannerError> { fn yaml_parser_save_simple_key(parser: &mut yaml_parser_t) -> Result<(), ScannerError> {
let required = let required = parser.flow_level == 0 && parser.indent as u64 == parser.mark.column as u64;
parser.flow_level == 0 && parser.indent as libc::c_long == parser.mark.column as ptrdiff_t;
if parser.simple_key_allowed { if parser.simple_key_allowed {
let simple_key = yaml_simple_key_t { let simple_key = yaml_simple_key_t {
possible: true, possible: true,
required, required,
token_number: parser token_number: parser.tokens_parsed.force_add(parser.tokens.len()),
.tokens_parsed
.force_add(parser.tokens.len() as libc::c_ulong),
mark: parser.mark, mark: parser.mark,
}; };
yaml_parser_remove_simple_key(parser)?; yaml_parser_remove_simple_key(parser)?;
@ -331,7 +328,7 @@ fn yaml_parser_increase_flow_level(parser: &mut yaml_parser_t) -> Result<(), Sca
let empty_simple_key = yaml_simple_key_t { let empty_simple_key = yaml_simple_key_t {
possible: false, possible: false,
required: false, required: false,
token_number: 0_u64, token_number: 0,
mark: yaml_mark_t { mark: yaml_mark_t {
index: 0_u64, index: 0_u64,
line: 0_u64, line: 0_u64,
@ -340,7 +337,7 @@ fn yaml_parser_increase_flow_level(parser: &mut yaml_parser_t) -> Result<(), Sca
}; };
parser.simple_keys.push(empty_simple_key); parser.simple_keys.push(empty_simple_key);
assert!( assert!(
!(parser.flow_level == libc::c_int::MAX), !(parser.flow_level == i32::MAX),
"parser.flow_level integer overflow" "parser.flow_level integer overflow"
); );
parser.flow_level += 1; parser.flow_level += 1;
@ -356,21 +353,18 @@ fn yaml_parser_decrease_flow_level(parser: &mut yaml_parser_t) {
fn yaml_parser_roll_indent( fn yaml_parser_roll_indent(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
column: ptrdiff_t, column: i64,
number: ptrdiff_t, number: i64,
data: YamlTokenData, data: YamlTokenData,
mark: yaml_mark_t, mark: yaml_mark_t,
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
if parser.flow_level != 0 { if parser.flow_level != 0 {
return Ok(()); return Ok(());
} }
if (parser.indent as libc::c_long) < column { if parser.indent < column as i32 {
parser.indents.push(parser.indent); parser.indents.push(parser.indent);
assert!( assert!(!(column > i32::MAX as i64), "integer overflow");
!(column > ptrdiff_t::from(libc::c_int::MAX)), parser.indent = column as i32;
"integer overflow"
);
parser.indent = column as libc::c_int;
let token = yaml_token_t { let token = yaml_token_t {
data, data,
start_mark: mark, start_mark: mark,
@ -380,7 +374,7 @@ fn yaml_parser_roll_indent(
parser.tokens.push_back(token); parser.tokens.push_back(token);
} else { } else {
parser.tokens.insert( parser.tokens.insert(
(number as libc::c_ulong).wrapping_sub(parser.tokens_parsed) as usize, (number as usize).wrapping_sub(parser.tokens_parsed) as usize,
token, token,
); );
} }
@ -388,11 +382,11 @@ fn yaml_parser_roll_indent(
Ok(()) Ok(())
} }
fn yaml_parser_unroll_indent(parser: &mut yaml_parser_t, column: ptrdiff_t) { fn yaml_parser_unroll_indent(parser: &mut yaml_parser_t, column: i64) {
if parser.flow_level != 0 { if parser.flow_level != 0 {
return; return;
} }
while parser.indent as libc::c_long > column { while parser.indent as i64 > column {
let token = yaml_token_t { let token = yaml_token_t {
data: YamlTokenData::BlockEnd, data: YamlTokenData::BlockEnd,
start_mark: parser.mark, start_mark: parser.mark,
@ -407,11 +401,11 @@ fn yaml_parser_fetch_stream_start(parser: &mut yaml_parser_t) {
let simple_key = yaml_simple_key_t { let simple_key = yaml_simple_key_t {
possible: false, possible: false,
required: false, required: false,
token_number: 0_u64, token_number: 0,
mark: yaml_mark_t { mark: yaml_mark_t {
index: 0_u64, index: 0,
line: 0_u64, line: 0,
column: 0_u64, column: 0,
}, },
}; };
parser.indent = -1; parser.indent = -1;
@ -542,7 +536,7 @@ fn yaml_parser_fetch_block_entry(parser: &mut yaml_parser_t) -> Result<(), Scann
} }
yaml_parser_roll_indent( yaml_parser_roll_indent(
parser, parser,
parser.mark.column as ptrdiff_t, parser.mark.column as _,
-1_i64, -1_i64,
YamlTokenData::BlockSequenceStart, YamlTokenData::BlockSequenceStart,
parser.mark, parser.mark,
@ -574,7 +568,7 @@ fn yaml_parser_fetch_key(parser: &mut yaml_parser_t) -> Result<(), ScannerError>
} }
yaml_parser_roll_indent( yaml_parser_roll_indent(
parser, parser,
parser.mark.column as ptrdiff_t, parser.mark.column as _,
-1_i64, -1_i64,
YamlTokenData::BlockMappingStart, YamlTokenData::BlockMappingStart,
parser.mark, parser.mark,
@ -606,8 +600,8 @@ fn yaml_parser_fetch_value(parser: &mut yaml_parser_t) -> Result<(), ScannerErro
simple_key.token_number.wrapping_sub(parser.tokens_parsed) as usize, simple_key.token_number.wrapping_sub(parser.tokens_parsed) as usize,
token, token,
); );
let mark_column = simple_key.mark.column as ptrdiff_t; let mark_column = simple_key.mark.column as _;
let token_number = simple_key.token_number as ptrdiff_t; let token_number = simple_key.token_number as _;
let mark = simple_key.mark; let mark = simple_key.mark;
simple_key.possible = false; simple_key.possible = false;
yaml_parser_roll_indent( yaml_parser_roll_indent(
@ -630,7 +624,7 @@ fn yaml_parser_fetch_value(parser: &mut yaml_parser_t) -> Result<(), ScannerErro
} }
yaml_parser_roll_indent( yaml_parser_roll_indent(
parser, parser,
parser.mark.column as ptrdiff_t, parser.mark.column as _,
-1_i64, -1_i64,
YamlTokenData::BlockMappingStart, YamlTokenData::BlockMappingStart,
parser.mark, parser.mark,
@ -706,27 +700,27 @@ fn yaml_parser_fetch_plain_scalar(parser: &mut yaml_parser_t) -> Result<(), Scan
fn yaml_parser_scan_to_next_token(parser: &mut yaml_parser_t) -> Result<(), ScannerError> { fn yaml_parser_scan_to_next_token(parser: &mut yaml_parser_t) -> Result<(), ScannerError> {
loop { loop {
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if parser.mark.column == 0_u64 && IS_BOM!(parser.buffer) { if parser.mark.column == 0 && IS_BOM!(parser.buffer) {
SKIP(parser); SKIP(parser);
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
while CHECK!(parser.buffer, ' ') while CHECK!(parser.buffer, ' ')
|| (parser.flow_level != 0 || !parser.simple_key_allowed) && CHECK!(parser.buffer, '\t') || (parser.flow_level != 0 || !parser.simple_key_allowed) && CHECK!(parser.buffer, '\t')
{ {
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if CHECK!(parser.buffer, '#') { if CHECK!(parser.buffer, '#') {
while !IS_BREAKZ!(parser.buffer) { while !IS_BREAKZ!(parser.buffer) {
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
} }
if !IS_BREAK!(parser.buffer) { if !IS_BREAK!(parser.buffer) {
break; break;
} }
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
SKIP_LINE(parser); SKIP_LINE(parser);
if parser.flow_level == 0 { if parser.flow_level == 0 {
parser.simple_key_allowed = true; parser.simple_key_allowed = true;
@ -740,8 +734,8 @@ fn yaml_parser_scan_directive(
token: &mut yaml_token_t, token: &mut yaml_token_t,
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
let end_mark: yaml_mark_t; let end_mark: yaml_mark_t;
let mut major: libc::c_int = 0; let mut major: i32 = 0;
let mut minor: libc::c_int = 0; let mut minor: i32 = 0;
let start_mark: yaml_mark_t = parser.mark; let start_mark: yaml_mark_t = parser.mark;
SKIP(parser); SKIP(parser);
let name = yaml_parser_scan_directive_name(parser, start_mark)?; let name = yaml_parser_scan_directive_name(parser, start_mark)?;
@ -770,13 +764,13 @@ fn yaml_parser_scan_directive(
"found unknown directive name", "found unknown directive name",
); );
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
loop { loop {
if !IS_BLANK!(parser.buffer) { if !IS_BLANK!(parser.buffer) {
break; break;
} }
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if CHECK!(parser.buffer, '#') { if CHECK!(parser.buffer, '#') {
@ -785,7 +779,7 @@ fn yaml_parser_scan_directive(
break; break;
} }
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
} }
@ -798,7 +792,7 @@ fn yaml_parser_scan_directive(
) )
} else { } else {
if IS_BREAK!(parser.buffer) { if IS_BREAK!(parser.buffer) {
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
SKIP_LINE(parser); SKIP_LINE(parser);
} }
Ok(()) Ok(())
@ -810,14 +804,14 @@ fn yaml_parser_scan_directive_name(
start_mark: yaml_mark_t, start_mark: yaml_mark_t,
) -> Result<String, ScannerError> { ) -> Result<String, ScannerError> {
let mut string = String::new(); let mut string = String::new();
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
loop { loop {
if !IS_ALPHA!(parser.buffer) { if !IS_ALPHA!(parser.buffer) {
break; break;
} }
READ_STRING(parser, &mut string); READ_STRING(parser, &mut string);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if string.is_empty() { if string.is_empty() {
@ -842,13 +836,13 @@ fn yaml_parser_scan_directive_name(
fn yaml_parser_scan_version_directive_value( fn yaml_parser_scan_version_directive_value(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
start_mark: yaml_mark_t, start_mark: yaml_mark_t,
major: &mut libc::c_int, major: &mut i32,
minor: &mut libc::c_int, minor: &mut i32,
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
while IS_BLANK!(parser.buffer) { while IS_BLANK!(parser.buffer) {
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
yaml_parser_scan_version_directive_number(parser, start_mark, major)?; yaml_parser_scan_version_directive_number(parser, start_mark, major)?;
if !CHECK!(parser.buffer, '.') { if !CHECK!(parser.buffer, '.') {
@ -868,11 +862,11 @@ const MAX_NUMBER_LENGTH: u64 = 9_u64;
fn yaml_parser_scan_version_directive_number( fn yaml_parser_scan_version_directive_number(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
start_mark: yaml_mark_t, start_mark: yaml_mark_t,
number: &mut libc::c_int, number: &mut i32,
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
let mut value: libc::c_int = 0; let mut value: i32 = 0;
let mut length: size_t = 0_u64; let mut length = 0;
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
while IS_DIGIT!(parser.buffer) { while IS_DIGIT!(parser.buffer) {
length = length.force_add(1); length = length.force_add(1);
if length > MAX_NUMBER_LENGTH { if length > MAX_NUMBER_LENGTH {
@ -887,7 +881,7 @@ fn yaml_parser_scan_version_directive_number(
.force_mul(10) .force_mul(10)
.force_add(AS_DIGIT!(parser.buffer) as i32); .force_add(AS_DIGIT!(parser.buffer) as i32);
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if length == 0 { if length == 0 {
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
@ -906,16 +900,16 @@ fn yaml_parser_scan_tag_directive_value(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
start_mark: yaml_mark_t, start_mark: yaml_mark_t,
) -> Result<(String, String), ScannerError> { ) -> Result<(String, String), ScannerError> {
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
loop { loop {
if IS_BLANK!(parser.buffer) { if IS_BLANK!(parser.buffer) {
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} else { } else {
let handle_value = yaml_parser_scan_tag_handle(parser, true, start_mark)?; let handle_value = yaml_parser_scan_tag_handle(parser, true, start_mark)?;
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if !IS_BLANK!(parser.buffer) { if !IS_BLANK!(parser.buffer) {
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
@ -927,11 +921,11 @@ fn yaml_parser_scan_tag_directive_value(
} else { } else {
while IS_BLANK!(parser.buffer) { while IS_BLANK!(parser.buffer) {
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
let prefix_value = yaml_parser_scan_tag_uri(parser, true, true, None, start_mark)?; let prefix_value = yaml_parser_scan_tag_uri(parser, true, true, None, start_mark)?;
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if !IS_BLANKZ!(parser.buffer) { if !IS_BLANKZ!(parser.buffer) {
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
@ -953,19 +947,19 @@ fn yaml_parser_scan_anchor(
token: &mut yaml_token_t, token: &mut yaml_token_t,
scan_alias_instead_of_anchor: bool, scan_alias_instead_of_anchor: bool,
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
let mut length: libc::c_int = 0; let mut length: i32 = 0;
let mut string = String::new(); let mut string = String::new();
let start_mark: yaml_mark_t = parser.mark; let start_mark: yaml_mark_t = parser.mark;
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
loop { loop {
if !IS_ALPHA!(parser.buffer) { if !IS_ALPHA!(parser.buffer) {
break; break;
} }
READ_STRING(parser, &mut string); READ_STRING(parser, &mut string);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
length += 1; length += 1;
} }
let end_mark: yaml_mark_t = parser.mark; let end_mark: yaml_mark_t = parser.mark;
@ -1013,7 +1007,7 @@ fn yaml_parser_scan_tag(
let start_mark: yaml_mark_t = parser.mark; let start_mark: yaml_mark_t = parser.mark;
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
if CHECK_AT!(parser.buffer, '<', 1) { if CHECK_AT!(parser.buffer, '<', 1) {
handle = String::new(); handle = String::new();
@ -1044,7 +1038,7 @@ fn yaml_parser_scan_tag(
} }
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if !IS_BLANKZ!(parser.buffer) { if !IS_BLANKZ!(parser.buffer) {
if parser.flow_level == 0 || !CHECK!(parser.buffer, ',') { if parser.flow_level == 0 || !CHECK!(parser.buffer, ',') {
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
@ -1074,7 +1068,7 @@ fn yaml_parser_scan_tag_handle(
start_mark: yaml_mark_t, start_mark: yaml_mark_t,
) -> Result<String, ScannerError> { ) -> Result<String, ScannerError> {
let mut string = String::new(); let mut string = String::new();
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if !CHECK!(parser.buffer, '!') { if !CHECK!(parser.buffer, '!') {
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
@ -1090,13 +1084,13 @@ fn yaml_parser_scan_tag_handle(
} }
READ_STRING(parser, &mut string); READ_STRING(parser, &mut string);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
loop { loop {
if !IS_ALPHA!(parser.buffer) { if !IS_ALPHA!(parser.buffer) {
break; break;
} }
READ_STRING(parser, &mut string); READ_STRING(parser, &mut string);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if CHECK!(parser.buffer, '!') { if CHECK!(parser.buffer, '!') {
READ_STRING(parser, &mut string); READ_STRING(parser, &mut string);
@ -1125,7 +1119,7 @@ fn yaml_parser_scan_tag_uri(
if length > 1 { if length > 1 {
string = String::from(&head[1..]); string = String::from(&head[1..]);
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
while IS_ALPHA!(parser.buffer) while IS_ALPHA!(parser.buffer)
|| CHECK!(parser.buffer, ';') || CHECK!(parser.buffer, ';')
@ -1156,7 +1150,7 @@ fn yaml_parser_scan_tag_uri(
READ_STRING(parser, &mut string); READ_STRING(parser, &mut string);
} }
length = length.force_add(1); length = length.force_add(1);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if length == 0 { if length == 0 {
yaml_parser_set_scanner_error( yaml_parser_set_scanner_error(
@ -1180,9 +1174,9 @@ fn yaml_parser_scan_uri_escapes(
start_mark: yaml_mark_t, start_mark: yaml_mark_t,
string: &mut String, string: &mut String,
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
let mut width: libc::c_int = 0; let mut width: i32 = 0;
loop { loop {
CACHE(parser, 3_u64)?; CACHE(parser, 3)?;
if !(CHECK!(parser.buffer, '%') if !(CHECK!(parser.buffer, '%')
&& IS_HEX_AT!(parser.buffer, 1) && IS_HEX_AT!(parser.buffer, 1)
&& IS_HEX_AT!(parser.buffer, 2)) && IS_HEX_AT!(parser.buffer, 2))
@ -1198,8 +1192,7 @@ fn yaml_parser_scan_uri_escapes(
"did not find URI escaped octet", "did not find URI escaped octet",
); );
} }
let octet: libc::c_uchar = let octet = ((AS_HEX_AT!(parser.buffer, 1) << 4) + AS_HEX_AT!(parser.buffer, 2)) as u8;
((AS_HEX_AT!(parser.buffer, 1) << 4) + AS_HEX_AT!(parser.buffer, 2)) as libc::c_uchar;
if width == 0 { if width == 0 {
width = if octet & 0x80 == 0 { width = if octet & 0x80 == 0 {
1 1
@ -1258,19 +1251,19 @@ fn yaml_parser_scan_block_scalar(
let mut string = String::new(); let mut string = String::new();
let mut leading_break = String::new(); let mut leading_break = String::new();
let mut trailing_breaks = String::new(); let mut trailing_breaks = String::new();
let mut chomping: libc::c_int = 0; let mut chomping: i32 = 0;
let mut increment: libc::c_int = 0; let mut increment: i32 = 0;
let mut indent: libc::c_int = 0; let mut indent: i32 = 0;
let mut leading_blank: libc::c_int = 0; let mut leading_blank: i32 = 0;
let mut trailing_blank: libc::c_int; let mut trailing_blank: i32;
let start_mark: yaml_mark_t = parser.mark; let start_mark: yaml_mark_t = parser.mark;
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if CHECK!(parser.buffer, '+') || CHECK!(parser.buffer, '-') { if CHECK!(parser.buffer, '+') || CHECK!(parser.buffer, '-') {
chomping = if CHECK!(parser.buffer, '+') { 1 } else { -1 }; chomping = if CHECK!(parser.buffer, '+') { 1 } else { -1 };
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if IS_DIGIT!(parser.buffer) { if IS_DIGIT!(parser.buffer) {
if CHECK!(parser.buffer, '0') { if CHECK!(parser.buffer, '0') {
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
@ -1295,7 +1288,7 @@ fn yaml_parser_scan_block_scalar(
} else { } else {
increment = AS_DIGIT!(parser.buffer) as i32; increment = AS_DIGIT!(parser.buffer) as i32;
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if CHECK!(parser.buffer, '+') || CHECK!(parser.buffer, '-') { if CHECK!(parser.buffer, '+') || CHECK!(parser.buffer, '-') {
chomping = if CHECK!(parser.buffer, '+') { 1 } else { -1 }; chomping = if CHECK!(parser.buffer, '+') { 1 } else { -1 };
SKIP(parser); SKIP(parser);
@ -1303,13 +1296,13 @@ fn yaml_parser_scan_block_scalar(
} }
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
loop { loop {
if !IS_BLANK!(parser.buffer) { if !IS_BLANK!(parser.buffer) {
break; break;
} }
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if CHECK!(parser.buffer, '#') { if CHECK!(parser.buffer, '#') {
@ -1318,7 +1311,7 @@ fn yaml_parser_scan_block_scalar(
break; break;
} }
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
} }
@ -1332,7 +1325,7 @@ fn yaml_parser_scan_block_scalar(
} }
if IS_BREAK!(parser.buffer) { if IS_BREAK!(parser.buffer) {
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
SKIP_LINE(parser); SKIP_LINE(parser);
} }
@ -1352,13 +1345,13 @@ fn yaml_parser_scan_block_scalar(
&mut end_mark, &mut end_mark,
)?; )?;
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
loop { loop {
if !(parser.mark.column as libc::c_int == indent && !IS_Z!(parser.buffer)) { if !(parser.mark.column as i32 == indent && !IS_Z!(parser.buffer)) {
break; break;
} }
trailing_blank = IS_BLANK!(parser.buffer) as libc::c_int; trailing_blank = IS_BLANK!(parser.buffer) as i32;
if !literal && leading_break.starts_with('\n') && leading_blank == 0 && trailing_blank == 0 if !literal && leading_break.starts_with('\n') && leading_blank == 0 && trailing_blank == 0
{ {
if trailing_breaks.is_empty() { if trailing_breaks.is_empty() {
@ -1371,12 +1364,12 @@ fn yaml_parser_scan_block_scalar(
} }
string.push_str(&trailing_breaks); string.push_str(&trailing_breaks);
trailing_breaks.clear(); trailing_breaks.clear();
leading_blank = IS_BLANK!(parser.buffer) as libc::c_int; leading_blank = IS_BLANK!(parser.buffer) as i32;
while !IS_BREAKZ!(parser.buffer) { while !IS_BREAKZ!(parser.buffer) {
READ_STRING(parser, &mut string); READ_STRING(parser, &mut string);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
READ_LINE_STRING(parser, &mut leading_break); READ_LINE_STRING(parser, &mut leading_break);
yaml_parser_scan_block_scalar_breaks( yaml_parser_scan_block_scalar_breaks(
parser, parser,
@ -1413,26 +1406,23 @@ fn yaml_parser_scan_block_scalar(
fn yaml_parser_scan_block_scalar_breaks( fn yaml_parser_scan_block_scalar_breaks(
parser: &mut yaml_parser_t, parser: &mut yaml_parser_t,
indent: &mut libc::c_int, indent: &mut i32,
breaks: &mut String, breaks: &mut String,
start_mark: yaml_mark_t, start_mark: yaml_mark_t,
end_mark: &mut yaml_mark_t, end_mark: &mut yaml_mark_t,
) -> Result<(), ScannerError> { ) -> Result<(), ScannerError> {
let mut max_indent: libc::c_int = 0; let mut max_indent: i32 = 0;
*end_mark = parser.mark; *end_mark = parser.mark;
loop { loop {
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
while (*indent == 0 || (parser.mark.column as libc::c_int) < *indent) while (*indent == 0 || (parser.mark.column as i32) < *indent) && IS_SPACE!(parser.buffer) {
&& IS_SPACE!(parser.buffer)
{
SKIP(parser); SKIP(parser);
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if parser.mark.column as libc::c_int > max_indent { if parser.mark.column as i32 > max_indent {
max_indent = parser.mark.column as libc::c_int; max_indent = parser.mark.column as i32;
} }
if (*indent == 0 || (parser.mark.column as libc::c_int) < *indent) && IS_TAB!(parser.buffer) if (*indent == 0 || (parser.mark.column as i32) < *indent) && IS_TAB!(parser.buffer) {
{
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
parser, parser,
"while scanning a block scalar", "while scanning a block scalar",
@ -1443,7 +1433,7 @@ fn yaml_parser_scan_block_scalar_breaks(
if !IS_BREAK!(parser.buffer) { if !IS_BREAK!(parser.buffer) {
break; break;
} }
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
READ_LINE_STRING(parser, breaks); READ_LINE_STRING(parser, breaks);
*end_mark = parser.mark; *end_mark = parser.mark;
} }
@ -1473,9 +1463,9 @@ fn yaml_parser_scan_flow_scalar(
let start_mark: yaml_mark_t = parser.mark; let start_mark: yaml_mark_t = parser.mark;
SKIP(parser); SKIP(parser);
loop { loop {
CACHE(parser, 4_u64)?; CACHE(parser, 4)?;
if parser.mark.column == 0_u64 if parser.mark.column == 0
&& (CHECK_AT!(parser.buffer, '-', 0) && (CHECK_AT!(parser.buffer, '-', 0)
&& CHECK_AT!(parser.buffer, '-', 1) && CHECK_AT!(parser.buffer, '-', 1)
&& CHECK_AT!(parser.buffer, '-', 2) && CHECK_AT!(parser.buffer, '-', 2)
@ -1498,7 +1488,7 @@ fn yaml_parser_scan_flow_scalar(
"found unexpected end of stream", "found unexpected end of stream",
); );
} else { } else {
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
leading_blanks = false; leading_blanks = false;
while !IS_BLANKZ!(parser.buffer) { while !IS_BLANKZ!(parser.buffer) {
if single && CHECK_AT!(parser.buffer, '\'', 0) && CHECK_AT!(parser.buffer, '\'', 1) if single && CHECK_AT!(parser.buffer, '\'', 0) && CHECK_AT!(parser.buffer, '\'', 1)
@ -1511,13 +1501,13 @@ fn yaml_parser_scan_flow_scalar(
break; break;
} }
if !single && CHECK!(parser.buffer, '\\') && IS_BREAK_AT!(parser.buffer, 1) { if !single && CHECK!(parser.buffer, '\\') && IS_BREAK_AT!(parser.buffer, 1) {
CACHE(parser, 3_u64)?; CACHE(parser, 3)?;
SKIP(parser); SKIP(parser);
SKIP_LINE(parser); SKIP_LINE(parser);
leading_blanks = true; leading_blanks = true;
break; break;
} else if !single && CHECK!(parser.buffer, '\\') { } else if !single && CHECK!(parser.buffer, '\\') {
let mut code_length: size_t = 0_u64; let mut code_length = 0usize;
match parser.buffer.get(1).copied().unwrap() { match parser.buffer.get(1).copied().unwrap() {
'0' => { '0' => {
string.push('\0'); string.push('\0');
@ -1583,13 +1573,13 @@ fn yaml_parser_scan_flow_scalar(
// string.push('\xA9'); // string.push('\xA9');
} }
'x' => { 'x' => {
code_length = 2_u64; code_length = 2;
} }
'u' => { 'u' => {
code_length = 4_u64; code_length = 4;
} }
'U' => { 'U' => {
code_length = 8_u64; code_length = 8;
} }
_ => { _ => {
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
@ -1603,10 +1593,9 @@ fn yaml_parser_scan_flow_scalar(
SKIP(parser); SKIP(parser);
SKIP(parser); SKIP(parser);
if code_length != 0 { if code_length != 0 {
let mut value: libc::c_uint = 0; let mut value: u32 = 0;
let mut k: size_t; let mut k = 0;
CACHE(parser, code_length)?; CACHE(parser, code_length)?;
k = 0_u64;
while k < code_length { while k < code_length {
if !IS_HEX_AT!(parser.buffer, k as usize) { if !IS_HEX_AT!(parser.buffer, k as usize) {
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
@ -1632,7 +1621,7 @@ fn yaml_parser_scan_flow_scalar(
); );
} }
k = 0_u64; k = 0;
while k < code_length { while k < code_length {
SKIP(parser); SKIP(parser);
k = k.force_add(1); k = k.force_add(1);
@ -1642,13 +1631,13 @@ fn yaml_parser_scan_flow_scalar(
READ_STRING(parser, &mut string); READ_STRING(parser, &mut string);
} }
} }
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
if CHECK!(parser.buffer, if single { '\'' } else { '"' }) { if CHECK!(parser.buffer, if single { '\'' } else { '"' }) {
break; break;
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
while IS_BLANK!(parser.buffer) || IS_BREAK!(parser.buffer) { while IS_BLANK!(parser.buffer) || IS_BREAK!(parser.buffer) {
if IS_BLANK!(parser.buffer) { if IS_BLANK!(parser.buffer) {
if !leading_blanks { if !leading_blanks {
@ -1657,7 +1646,7 @@ fn yaml_parser_scan_flow_scalar(
SKIP(parser); SKIP(parser);
} }
} else { } else {
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
if !leading_blanks { if !leading_blanks {
whitespaces.clear(); whitespaces.clear();
READ_LINE_STRING(parser, &mut leading_break); READ_LINE_STRING(parser, &mut leading_break);
@ -1666,7 +1655,7 @@ fn yaml_parser_scan_flow_scalar(
READ_LINE_STRING(parser, &mut trailing_breaks); READ_LINE_STRING(parser, &mut trailing_breaks);
} }
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if leading_blanks { if leading_blanks {
if leading_break.starts_with('\n') { if leading_break.starts_with('\n') {
@ -1717,12 +1706,12 @@ fn yaml_parser_scan_plain_scalar(
let mut trailing_breaks = String::new(); let mut trailing_breaks = String::new();
let mut whitespaces = String::new(); let mut whitespaces = String::new();
let mut leading_blanks = false; let mut leading_blanks = false;
let indent: libc::c_int = parser.indent + 1; let indent: i32 = parser.indent + 1;
end_mark = parser.mark; end_mark = parser.mark;
let start_mark: yaml_mark_t = end_mark; let start_mark: yaml_mark_t = end_mark;
loop { loop {
CACHE(parser, 4_u64)?; CACHE(parser, 4)?;
if parser.mark.column == 0_u64 if parser.mark.column == 0
&& (CHECK_AT!(parser.buffer, '-', 0) && (CHECK_AT!(parser.buffer, '-', 0)
&& CHECK_AT!(parser.buffer, '-', 1) && CHECK_AT!(parser.buffer, '-', 1)
&& CHECK_AT!(parser.buffer, '-', 2) && CHECK_AT!(parser.buffer, '-', 2)
@ -1787,19 +1776,17 @@ fn yaml_parser_scan_plain_scalar(
} }
READ_STRING(parser, &mut string); READ_STRING(parser, &mut string);
end_mark = parser.mark; end_mark = parser.mark;
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
} }
} }
if !(IS_BLANK!(parser.buffer) || IS_BREAK!(parser.buffer)) { if !(IS_BLANK!(parser.buffer) || IS_BREAK!(parser.buffer)) {
break; break;
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
while IS_BLANK!(parser.buffer) || IS_BREAK!(parser.buffer) { while IS_BLANK!(parser.buffer) || IS_BREAK!(parser.buffer) {
if IS_BLANK!(parser.buffer) { if IS_BLANK!(parser.buffer) {
if leading_blanks if leading_blanks && (parser.mark.column as i32) < indent && IS_TAB!(parser.buffer)
&& (parser.mark.column as libc::c_int) < indent
&& IS_TAB!(parser.buffer)
{ {
return yaml_parser_set_scanner_error( return yaml_parser_set_scanner_error(
parser, parser,
@ -1813,7 +1800,7 @@ fn yaml_parser_scan_plain_scalar(
SKIP(parser); SKIP(parser);
} }
} else { } else {
CACHE(parser, 2_u64)?; CACHE(parser, 2)?;
if !leading_blanks { if !leading_blanks {
whitespaces.clear(); whitespaces.clear();
@ -1823,9 +1810,9 @@ fn yaml_parser_scan_plain_scalar(
READ_LINE_STRING(parser, &mut trailing_breaks); READ_LINE_STRING(parser, &mut trailing_breaks);
} }
} }
CACHE(parser, 1_u64)?; CACHE(parser, 1)?;
} }
if parser.flow_level == 0 && (parser.mark.column as libc::c_int) < indent { if parser.flow_level == 0 && (parser.mark.column as i32) < indent {
break; break;
} }
} }

View file

@ -2,10 +2,9 @@ use alloc::collections::VecDeque;
use alloc::string::String; use alloc::string::String;
use alloc::vec::Vec; use alloc::vec::Vec;
use crate::{api::yaml_parser_new, libc, yaml_emitter_new}; use crate::{api::yaml_parser_new, yaml_emitter_new};
pub use self::yaml_encoding_t::*; pub use self::yaml_encoding_t::*;
pub use core::primitive::{i64 as ptrdiff_t, u64 as size_t};
/// The version directive data. /// The version directive data.
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
@ -13,9 +12,9 @@ pub use core::primitive::{i64 as ptrdiff_t, u64 as size_t};
#[non_exhaustive] #[non_exhaustive]
pub struct yaml_version_directive_t { pub struct yaml_version_directive_t {
/// The major version number. /// The major version number.
pub major: libc::c_int, pub major: i32,
/// The minor version number. /// The minor version number.
pub minor: libc::c_int, pub minor: i32,
} }
/// The tag directive data. /// The tag directive data.
@ -67,11 +66,11 @@ pub enum yaml_break_t {
#[non_exhaustive] #[non_exhaustive]
pub struct yaml_mark_t { pub struct yaml_mark_t {
/// The position index. /// The position index.
pub index: size_t, pub index: u64,
/// The position line. /// The position line.
pub line: size_t, pub line: u64,
/// The position column. /// The position column.
pub column: size_t, pub column: u64,
} }
/// Scalar styles. /// Scalar styles.
@ -199,9 +198,9 @@ pub enum YamlTokenData {
/// A VERSION-DIRECTIVE token. /// A VERSION-DIRECTIVE token.
VersionDirective { VersionDirective {
/// The major version number. /// The major version number.
major: libc::c_int, major: i32,
/// The minor version number. /// The minor version number.
minor: libc::c_int, minor: i32,
}, },
/// A TAG-DIRECTIVE token. /// A TAG-DIRECTIVE token.
TagDirective { TagDirective {
@ -495,16 +494,16 @@ pub enum YamlNodeData {
} }
/// An element of a sequence node. /// An element of a sequence node.
pub type yaml_node_item_t = libc::c_int; pub type yaml_node_item_t = i32;
/// An element of a mapping node. /// An element of a mapping node.
#[derive(Copy, Clone, Default)] #[derive(Copy, Clone, Default)]
#[repr(C)] #[repr(C)]
#[non_exhaustive] #[non_exhaustive]
pub struct yaml_node_pair_t { pub struct yaml_node_pair_t {
/// The key of the element. /// The key of the element.
pub key: libc::c_int, pub key: i32,
/// The value of the element. /// The value of the element.
pub value: libc::c_int, pub value: i32,
} }
/// The document structure. /// The document structure.
@ -548,7 +547,7 @@ pub struct yaml_simple_key_t {
/// Is a simple key required? /// Is a simple key required?
pub required: bool, pub required: bool,
/// The number of the token. /// The number of the token.
pub token_number: size_t, pub token_number: usize,
/// The position mark. /// The position mark.
pub mark: yaml_mark_t, pub mark: yaml_mark_t,
} }
@ -616,7 +615,7 @@ pub struct yaml_alias_data_t {
/// The anchor. /// The anchor.
pub anchor: String, pub anchor: String,
/// The node id. /// The node id.
pub index: libc::c_int, pub index: i32,
/// The anchor mark. /// The anchor mark.
pub mark: yaml_mark_t, pub mark: yaml_mark_t,
} }
@ -637,7 +636,7 @@ pub struct yaml_parser_t<'r> {
/// This always contains valid UTF-8. /// This always contains valid UTF-8.
pub(crate) buffer: VecDeque<char>, pub(crate) buffer: VecDeque<char>,
/// The number of unread characters in the buffer. /// The number of unread characters in the buffer.
pub(crate) unread: size_t, pub(crate) unread: usize,
/// The raw buffer. /// The raw buffer.
/// ///
/// This is the raw unchecked input from the read handler (for example, it /// This is the raw unchecked input from the read handler (for example, it
@ -647,7 +646,7 @@ pub struct yaml_parser_t<'r> {
/// The input encoding. /// The input encoding.
pub(crate) encoding: yaml_encoding_t, pub(crate) encoding: yaml_encoding_t,
/// The offset of the current position (in bytes). /// The offset of the current position (in bytes).
pub(crate) offset: size_t, pub(crate) offset: usize,
/// The mark of the current position. /// The mark of the current position.
pub(crate) mark: yaml_mark_t, pub(crate) mark: yaml_mark_t,
/// Have we started to scan the input stream? /// Have we started to scan the input stream?
@ -655,17 +654,17 @@ pub struct yaml_parser_t<'r> {
/// Have we reached the end of the input stream? /// Have we reached the end of the input stream?
pub(crate) stream_end_produced: bool, pub(crate) stream_end_produced: bool,
/// The number of unclosed '[' and '{' indicators. /// The number of unclosed '[' and '{' indicators.
pub(crate) flow_level: libc::c_int, pub(crate) flow_level: i32,
/// The tokens queue. /// The tokens queue.
pub(crate) tokens: VecDeque<yaml_token_t>, pub(crate) tokens: VecDeque<yaml_token_t>,
/// The number of tokens fetched from the queue. /// The number of tokens fetched from the queue.
pub(crate) tokens_parsed: size_t, pub(crate) tokens_parsed: usize,
/// Does the tokens queue contain a token ready for dequeueing. /// Does the tokens queue contain a token ready for dequeueing.
pub(crate) token_available: bool, pub(crate) token_available: bool,
/// The indentation levels stack. /// The indentation levels stack.
pub(crate) indents: Vec<libc::c_int>, pub(crate) indents: Vec<i32>,
/// The current indentation level. /// The current indentation level.
pub(crate) indent: libc::c_int, pub(crate) indent: i32,
/// May a simple key occur at the current position? /// May a simple key occur at the current position?
pub(crate) simple_key_allowed: bool, pub(crate) simple_key_allowed: bool,
/// The stack of simple keys. /// The stack of simple keys.
@ -736,9 +735,9 @@ pub enum yaml_emitter_state_t {
#[repr(C)] #[repr(C)]
pub(crate) struct yaml_anchors_t { pub(crate) struct yaml_anchors_t {
/// The number of references. /// The number of references.
pub references: libc::c_int, pub references: i32,
/// The anchor id. /// The anchor id.
pub anchor: libc::c_int, pub anchor: i32,
/// If the node has been emitted? /// If the node has been emitted?
pub serialized: bool, pub serialized: bool,
} }
@ -766,9 +765,9 @@ pub struct yaml_emitter_t<'w> {
/// If the output is in the canonical style? /// If the output is in the canonical style?
pub(crate) canonical: bool, pub(crate) canonical: bool,
/// The number of indentation spaces. /// The number of indentation spaces.
pub(crate) best_indent: libc::c_int, pub(crate) best_indent: i32,
/// The preferred width of the output lines. /// The preferred width of the output lines.
pub(crate) best_width: libc::c_int, pub(crate) best_width: i32,
/// Allow unescaped non-ASCII characters? /// Allow unescaped non-ASCII characters?
pub(crate) unicode: bool, pub(crate) unicode: bool,
/// The preferred line break. /// The preferred line break.
@ -780,13 +779,13 @@ pub struct yaml_emitter_t<'w> {
/// The event queue. /// The event queue.
pub(crate) events: VecDeque<yaml_event_t>, pub(crate) events: VecDeque<yaml_event_t>,
/// The stack of indentation levels. /// The stack of indentation levels.
pub(crate) indents: Vec<libc::c_int>, pub(crate) indents: Vec<i32>,
/// The list of tag directives. /// The list of tag directives.
pub(crate) tag_directives: Vec<yaml_tag_directive_t>, pub(crate) tag_directives: Vec<yaml_tag_directive_t>,
/// The current indentation level. /// The current indentation level.
pub(crate) indent: libc::c_int, pub(crate) indent: i32,
/// The current flow level. /// The current flow level.
pub(crate) flow_level: libc::c_int, pub(crate) flow_level: i32,
/// Is it the document root context? /// Is it the document root context?
pub(crate) root_context: bool, pub(crate) root_context: bool,
/// Is it a sequence context? /// Is it a sequence context?
@ -796,15 +795,15 @@ pub struct yaml_emitter_t<'w> {
/// Is it a simple mapping key context? /// Is it a simple mapping key context?
pub(crate) simple_key_context: bool, pub(crate) simple_key_context: bool,
/// The current line. /// The current line.
pub(crate) line: libc::c_int, pub(crate) line: i32,
/// The current column. /// The current column.
pub(crate) column: libc::c_int, pub(crate) column: i32,
/// If the last character was a whitespace? /// If the last character was a whitespace?
pub(crate) whitespace: bool, pub(crate) whitespace: bool,
/// If the last character was an indentation character (' ', '-', '?', ':')? /// If the last character was an indentation character (' ', '-', '?', ':')?
pub(crate) indention: bool, pub(crate) indention: bool,
/// If an explicit document end is required? /// If an explicit document end is required?
pub(crate) open_ended: libc::c_int, pub(crate) open_ended: i32,
/// If the stream was already opened? /// If the stream was already opened?
pub(crate) opened: bool, pub(crate) opened: bool,
/// If the stream was already closed? /// If the stream was already closed?
@ -813,7 +812,7 @@ pub struct yaml_emitter_t<'w> {
// Note: Same length as `document.nodes`. // Note: Same length as `document.nodes`.
pub(crate) anchors: Vec<yaml_anchors_t>, pub(crate) anchors: Vec<yaml_anchors_t>,
/// The last assigned anchor id. /// The last assigned anchor id.
pub(crate) last_anchor_id: libc::c_int, pub(crate) last_anchor_id: i32,
} }
impl<'a> Default for yaml_emitter_t<'a> { impl<'a> Default for yaml_emitter_t<'a> {