Skip to content

Commit

Permalink
read: Allow comdat names to be borrowed for 'data (gimli-rs#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlattimore authored Jan 8, 2024
1 parent 689c6a5 commit d165204
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
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

0 comments on commit d165204

Please sign in to comment.