+
Skip to content

Replace fallible-iterator with tryiterator #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ object = { version = "0.27.1", features = ["wasm"] }
rayon = "1.0"
regex = "1"
test-assembler = "0.1.3"
tryiterator = { git = "https://github.com/Pernosco/tryiterator" }
typed-arena = "2"

[features]
read-core = []
read = ["read-core"]
endian-reader = ["read", "stable_deref_trait"]
write = ["indexmap"]
std = ["fallible-iterator/std", "stable_deref_trait/std"]
default = ["read", "write", "std", "fallible-iterator", "endian-reader"]
std = ["stable_deref_trait/std"]
default = ["read", "write", "std", "endian-reader"]

# Internal feature, only used when building as part of libstd, not part of the
# stable interface of this crate.
Expand Down
12 changes: 6 additions & 6 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Allow clippy lints when building without clippy.
#![allow(unknown_lints)]

use fallible_iterator::FallibleIterator;
use gimli::{Section, UnitHeader, UnitOffset, UnitSectionOffset, UnitType, UnwindSection};
use object::{Object, ObjectSection, ObjectSymbol};
use regex::bytes::Regex;
Expand All @@ -18,6 +17,7 @@ use std::mem;
use std::process;
use std::result;
use std::sync::{Condvar, Mutex};
use tryiterator::TryIteratorExt;
use typed_arena::Arena;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -639,8 +639,8 @@ where
Some(
match dwo_parent
.units()
.map(|unit_header| dwo_parent.unit(unit_header))
.filter_map(|unit| Ok(unit.dwo_id.map(|dwo_id| (dwo_id, unit))))
.and_then(|unit_header| dwo_parent.unit(unit_header))
.try_filter_map(|unit| Ok(unit.dwo_id.map(|dwo_id| (dwo_id, unit))))
.collect()
{
Ok(units) => units,
Expand Down Expand Up @@ -1157,7 +1157,7 @@ where
{
writeln!(w, "\n.debug_info")?;

let units = match dwarf.units().collect::<Vec<_>>() {
let units = match dwarf.units().try_collect::<Vec<_>>() {
Ok(units) => units,
Err(err) => {
writeln_error(
Expand Down Expand Up @@ -1866,7 +1866,7 @@ fn dump_loc_list<R: Reader, W: Write>(
dwarf: &gimli::Dwarf<R>,
) -> Result<()> {
let raw_locations = dwarf.raw_locations(unit, offset)?;
let raw_locations: Vec<_> = raw_locations.collect()?;
let raw_locations = raw_locations.try_collect::<Vec<_>>()?;
let mut locations = dwarf.locations(unit, offset)?;
writeln!(
w,
Expand Down Expand Up @@ -1994,7 +1994,7 @@ fn dump_range_list<R: Reader, W: Write>(
dwarf: &gimli::Dwarf<R>,
) -> Result<()> {
let raw_ranges = dwarf.raw_ranges(unit, offset)?;
let raw_ranges: Vec<_> = raw_ranges.collect()?;
let raw_ranges = raw_ranges.try_collect::<Vec<_>>()?;
let mut ranges = dwarf.ranges(unit, offset)?;
writeln!(
w,
Expand Down
16 changes: 16 additions & 0 deletions src/read/aranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ impl<R: Reader> fallible_iterator::FallibleIterator for ArangeHeaderIter<R> {
}
}

impl<R: Reader> Iterator for ArangeHeaderIter<R> {
type Item = Result<ArangeHeader<R>>;

fn next(&mut self) -> Option<Self::Item> {
ArangeHeaderIter::next(self).transpose()
}
}

/// A header for a set of entries in the `.debug_arange` section.
///
/// These entries all belong to a single unit.
Expand Down Expand Up @@ -295,6 +303,14 @@ impl<R: Reader> fallible_iterator::FallibleIterator for ArangeEntryIter<R> {
}
}

impl<R: Reader> Iterator for ArangeEntryIter<R> {
type Item = Result<ArangeEntry>;

fn next(&mut self) -> Option<Self::Item> {
ArangeEntryIter::next(self).transpose()
}
}

/// A single parsed arange.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct ArangeEntry {
Expand Down
40 changes: 40 additions & 0 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@ impl<'a, 'bases, R: Reader> fallible_iterator::FallibleIterator for EhHdrTableIt
}
}

impl<'a, 'bases, R: Reader> Iterator for EhHdrTableIter<'a, 'bases, R> {
type Item = Result<(Pointer, Pointer)>;

fn next(&mut self) -> Option<Self::Item> {
EhHdrTableIter::next(self).transpose()
}

fn size_hint(&self) -> (usize, Option<usize>) {
use core::convert::TryInto;
(
self.remain.try_into().unwrap_or(0),
self.remain.try_into().ok(),
)
}

fn nth(&mut self, n: usize) -> Option<Self::Item> {
EhHdrTableIter::nth(self, n).transpose()
}
}

/// The CFI binary search table that is an optional part of the `.eh_frame_hdr` section.
#[derive(Debug, Clone)]
pub struct EhHdrTable<'a, R: Reader> {
Expand Down Expand Up @@ -1043,6 +1063,18 @@ where
}
}

impl<'bases, Section, R> Iterator for CfiEntriesIter<'bases, Section, R>
where
R: Reader,
Section: UnwindSection<R>,
{
type Item = Result<CieOrFde<'bases, Section, R>>;

fn next(&mut self) -> Option<Self::Item> {
CfiEntriesIter::next(self).transpose()
}
}

/// Either a `CommonInformationEntry` (CIE) or a `FrameDescriptionEntry` (FDE).
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CieOrFde<'bases, Section, R>
Expand Down Expand Up @@ -3358,6 +3390,14 @@ impl<'a, R: Reader> fallible_iterator::FallibleIterator for CallFrameInstruction
}
}

impl<'a, R: Reader> Iterator for CallFrameInstructionIter<'a, R> {
type Item = Result<CallFrameInstruction<R>>;

fn next(&mut self) -> Option<Self::Item> {
CallFrameInstructionIter::next(self).transpose()
}
}

/// Parse a `DW_EH_PE_*` pointer encoding.
#[doc(hidden)]
#[inline]
Expand Down
9 changes: 9 additions & 0 deletions src/read/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,15 @@ impl<R: Reader> fallible_iterator::FallibleIterator for RangeIter<R> {
}
}

impl<R: Reader> Iterator for RangeIter<R> {
type Item = Result<Range>;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
RangeIter::next(self).transpose()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
16 changes: 16 additions & 0 deletions src/read/loclists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,14 @@ impl<R: Reader> fallible_iterator::FallibleIterator for RawLocListIter<R> {
}
}

impl<R: Reader> Iterator for RawLocListIter<R> {
type Item = Result<RawLocListEntry<R>>;

fn next(&mut self) -> Option<Self::Item> {
RawLocListIter::next(self).transpose()
}
}

/// An iterator over a location list.
///
/// This iterator internally handles processing of base address selection entries
Expand Down Expand Up @@ -622,6 +630,14 @@ impl<R: Reader> fallible_iterator::FallibleIterator for LocListIter<R> {
}
}

impl<R: Reader> Iterator for LocListIter<R> {
type Item = Result<LocationListEntry<R>>;

fn next(&mut self) -> Option<Self::Item> {
LocListIter::next(self).transpose()
}
}

/// A location list entry from the `.debug_loc` or `.debug_loclists` sections.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LocationListEntry<R: Reader> {
Expand Down
8 changes: 8 additions & 0 deletions src/read/pubnames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,11 @@ impl<R: Reader> fallible_iterator::FallibleIterator for PubNamesEntryIter<R> {
self.0.next()
}
}

impl<R: Reader> Iterator for PubNamesEntryIter<R> {
type Item = Result<PubNamesEntry<R>>;

fn next(&mut self) -> Option<Self::Item> {
self.0.next().transpose()
}
}
8 changes: 8 additions & 0 deletions src/read/pubtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,11 @@ impl<R: Reader> fallible_iterator::FallibleIterator for PubTypesEntryIter<R> {
self.0.next()
}
}

impl<R: Reader> Iterator for PubTypesEntryIter<R> {
type Item = Result<PubTypesEntry<R>>;

fn next(&mut self) -> Option<Self::Item> {
self.0.next().transpose()
}
}
16 changes: 16 additions & 0 deletions src/read/rnglists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ impl<R: Reader> fallible_iterator::FallibleIterator for RawRngListIter<R> {
}
}

impl<R: Reader> Iterator for RawRngListIter<R> {
type Item = Result<RawRngListEntry<R::Offset>>;

fn next(&mut self) -> Option<Self::Item> {
RawRngListIter::next(self).transpose()
}
}

/// An iterator over an address range list.
///
/// This iterator internally handles processing of base addresses and different
Expand Down Expand Up @@ -541,6 +549,14 @@ impl<R: Reader> fallible_iterator::FallibleIterator for RngListIter<R> {
}
}

impl<R: Reader> Iterator for RngListIter<R> {
type Item = Result<Range>;

fn next(&mut self) -> Option<Self::Item> {
RngListIter::next(self).transpose()
}
}

/// A raw address range from the `.debug_ranges` section.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct RawRange {
Expand Down
26 changes: 26 additions & 0 deletions src/read/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ impl<R: Reader> fallible_iterator::FallibleIterator for DebugInfoUnitHeadersIter
}
}

impl<R: Reader> Iterator for DebugInfoUnitHeadersIter<R> {
type Item = Result<UnitHeader<R>>;

fn next(&mut self) -> Option<Self::Item> {
DebugInfoUnitHeadersIter::next(self).transpose()
}
}


/// Parse the unit type from the unit header.
fn parse_unit_type<R: Reader>(input: &mut R) -> Result<constants::DwUt> {
let val = input.read_u8()?;
Expand Down Expand Up @@ -2340,6 +2349,15 @@ impl<'abbrev, 'entry, 'unit, R: Reader> fallible_iterator::FallibleIterator
}
}

impl<'abbrev, 'entry, 'unit, R: Reader> Iterator for AttrsIter<'abbrev, 'entry, 'unit, R>
{
type Item = Result<Attribute<R>>;

fn next(&mut self) -> Option<Self::Item> {
AttrsIter::next(self).transpose()
}
}

/// A raw reader of the data that defines the Debugging Information Entries.
///
/// `EntriesRaw` provides primitives to read the components of Debugging Information
Expand Down Expand Up @@ -3210,6 +3228,14 @@ impl<R: Reader> fallible_iterator::FallibleIterator for DebugTypesUnitHeadersIte
}
}

impl<R: Reader> Iterator for DebugTypesUnitHeadersIter<R> {
type Item = Result<UnitHeader<R>>;

fn next(&mut self) -> Option<Self::Item> {
DebugTypesUnitHeadersIter::next(self).transpose()
}
}

#[cfg(test)]
// Tests require leb128::write.
#[cfg(feature = "write")]
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载