Skip to content
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

read: Allow comdat names to be borrowed for 'data #622

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/read/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,11 @@ impl<'data, 'file, R: ReadRef<'data>> ObjectComdat<'data> for Comdat<'data, 'fil
with_inner!(self.inner, ComdatInternal, |x| x.symbol())
}

fn name_bytes(&self) -> Result<&[u8]> {
fn name_bytes(&self) -> Result<&'data [u8]> {
with_inner!(self.inner, ComdatInternal, |x| x.name_bytes())
}

fn name(&self) -> Result<&str> {
fn name(&self) -> Result<&'data str> {
with_inner!(self.inner, ComdatInternal, |x| x.name())
}

Expand Down
4 changes: 2 additions & 2 deletions src/read/coff/comdat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ impl<'data, 'file, R: ReadRef<'data>, Coff: CoffHeader> ObjectComdat<'data>
}

#[inline]
fn name_bytes(&self) -> Result<&[u8]> {
fn name_bytes(&self) -> Result<&'data [u8]> {
// Find the name of first symbol referring to the section.
self.symbol.name(self.file.common.symbols.strings())
}

#[inline]
fn name(&self) -> Result<&str> {
fn name(&self) -> Result<&'data str> {
let bytes = self.name_bytes()?;
str::from_utf8(bytes)
.ok()
Expand Down
4 changes: 2 additions & 2 deletions src/read/elf/comdat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ where
SymbolIndex(self.section.sh_info(self.file.endian) as usize)
}

fn name_bytes(&self) -> read::Result<&[u8]> {
fn name_bytes(&self) -> read::Result<&'data [u8]> {
// FIXME: check sh_link
let index = self.section.sh_info(self.file.endian) as usize;
let symbol = self.file.symbols.symbol(index)?;
symbol.name(self.file.endian, self.file.symbols.strings())
}

fn name(&self) -> read::Result<&str> {
fn name(&self) -> read::Result<&'data str> {
let name = self.name_bytes()?;
str::from_utf8(name)
.ok()
Expand Down
4 changes: 2 additions & 2 deletions src/read/macho/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,12 @@ where
}

#[inline]
fn name_bytes(&self) -> Result<&[u8]> {
fn name_bytes(&self) -> Result<&'data [u8]> {
unreachable!();
}

#[inline]
fn name(&self) -> Result<&str> {
fn name(&self) -> Result<&'data str> {
unreachable!();
}

Expand Down
4 changes: 2 additions & 2 deletions src/read/pe/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ where
}

#[inline]
fn name_bytes(&self) -> Result<&[u8]> {
fn name_bytes(&self) -> Result<&'data [u8]> {
unreachable!();
}

#[inline]
fn name(&self) -> Result<&str> {
fn name(&self) -> Result<&'data str> {
unreachable!();
}

Expand Down
4 changes: 2 additions & 2 deletions src/read/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,12 @@ pub trait ObjectComdat<'data>: read::private::Sealed {
fn symbol(&self) -> SymbolIndex;

/// Returns the name of the COMDAT section group.
fn name_bytes(&self) -> Result<&[u8]>;
fn name_bytes(&self) -> Result<&'data [u8]>;

/// Returns the name of the COMDAT section group.
///
/// Returns an error if the name is not UTF-8.
fn name(&self) -> Result<&str>;
fn name(&self) -> Result<&'data str>;

/// Get the sections in this section group.
fn sections(&self) -> Self::SectionIterator;
Expand Down
4 changes: 2 additions & 2 deletions src/read/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,12 +772,12 @@ impl<'data, 'file, R> ObjectComdat<'data> for WasmComdat<'data, 'file, R> {
}

#[inline]
fn name_bytes(&self) -> Result<&[u8]> {
fn name_bytes(&self) -> Result<&'data [u8]> {
unreachable!();
}

#[inline]
fn name(&self) -> Result<&str> {
fn name(&self) -> Result<&'data str> {
unreachable!();
}

Expand Down
4 changes: 2 additions & 2 deletions src/read/xcoff/comdat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ where
}

#[inline]
fn name_bytes(&self) -> Result<&[u8]> {
fn name_bytes(&self) -> Result<&'data [u8]> {
unreachable!();
}

#[inline]
fn name(&self) -> Result<&str> {
fn name(&self) -> Result<&'data str> {
unreachable!();
}

Expand Down