Skip to content

Commit 48411d5

Browse files
committed
Rename ElfParser::open_*() constructors
Using the "open" terminology in some of the ElfParser::open_*() constructors doesn't really make sense. We are not opening a file, because an already opened file gets passed in. Rename the constructors to something using from_file*() instead. Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent e2e8bcd commit 48411d5

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

src/elf/parser.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,9 @@ where
923923
}
924924

925925
impl ElfParser<File> {
926-
fn open_file_io<P>(file: File, path: P) -> Self
926+
/// Create an `ElfParser` that uses regular file I/O on the provided
927+
/// file.
928+
fn from_file_io<P>(file: File, path: P) -> Self
927929
where
928930
P: Into<PathBuf>,
929931
{
@@ -938,15 +940,16 @@ impl ElfParser<File> {
938940
parser
939941
}
940942

941-
/// Create an `ElfParser` from an open file.
942-
pub(crate) fn open_non_mmap<P>(path: P) -> Result<Self>
943+
/// Create an `ElfParser` employing regular file I/O, opening the
944+
/// file at `path`.
945+
pub(crate) fn open_file_io<P>(path: P) -> Result<Self>
943946
where
944947
P: Into<PathBuf>,
945948
{
946949
let path = path.into();
947950
let file =
948951
File::open(&path).with_context(|| format!("failed to open `{}`", path.display()))?;
949-
let slf = Self::open_file_io(file, path);
952+
let slf = Self::from_file_io(file, path);
950953
Ok(slf)
951954
}
952955

@@ -958,7 +961,7 @@ impl ElfParser<File> {
958961

959962
impl ElfParser<Mmap> {
960963
/// Create an `ElfParser` from an open file.
961-
pub(crate) fn open_file<P>(file: &File, path: P) -> Result<Self>
964+
pub(crate) fn from_file<P>(file: &File, path: P) -> Result<Self>
962965
where
963966
P: Into<PathBuf>,
964967
{
@@ -987,7 +990,7 @@ impl ElfParser<Mmap> {
987990
pub(crate) fn open(path: &Path) -> Result<ElfParser> {
988991
let file =
989992
File::open(path).with_context(|| format!("failed to open {}", path.display()))?;
990-
Self::open_file(&file, path)
993+
Self::from_file(&file, path)
991994
}
992995
}
993996

@@ -1434,10 +1437,10 @@ mod tests {
14341437
}
14351438

14361439
let path = file.path().to_path_buf();
1437-
let parser_mmap = ElfParser::open_file(file.as_file(), &path).unwrap();
1440+
let parser_mmap = ElfParser::from_file(file.as_file(), &path).unwrap();
14381441
let () = test(parser_mmap);
14391442

1440-
let parser_io = ElfParser::open_file_io(file.into_file(), &path);
1443+
let parser_io = ElfParser::from_file_io(file.into_file(), &path);
14411444
let () = test(parser_io);
14421445
}
14431446

@@ -1502,10 +1505,10 @@ mod tests {
15021505
}
15031506

15041507
let path = file.path().to_path_buf();
1505-
let parser_mmap = ElfParser::open_file(file.as_file(), &path).unwrap();
1508+
let parser_mmap = ElfParser::from_file(file.as_file(), &path).unwrap();
15061509
let () = test(parser_mmap);
15071510

1508-
let parser_io = ElfParser::open_file_io(file.into_file(), &path);
1511+
let parser_io = ElfParser::from_file_io(file.into_file(), &path);
15091512
let () = test(parser_io);
15101513
}
15111514

@@ -1708,10 +1711,10 @@ mod tests {
17081711
}
17091712

17101713
let path = file.path().to_path_buf();
1711-
let parser_mmap = ElfParser::open_file(file.as_file(), &path).unwrap();
1714+
let parser_mmap = ElfParser::from_file(file.as_file(), &path).unwrap();
17121715
let () = test(parser_mmap);
17131716

1714-
let parser_io = ElfParser::open_file_io(file.into_file(), &path);
1717+
let parser_io = ElfParser::from_file_io(file.into_file(), &path);
17151718
let () = test(parser_io);
17161719
}
17171720

src/elf/resolver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl FileCache<ElfResolverData> {
8282
};
8383
Rc::clone(resolver)
8484
} else {
85-
let parser = Rc::new(ElfParser::open_file(file, path)?);
85+
let parser = Rc::new(ElfParser::from_file(file, path)?);
8686
let resolver = ElfResolver::from_parser(parser, debug_dirs)?;
8787
Rc::new(resolver)
8888
};

src/kernel/kaslr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn find_kcore_kaslr_offset() -> Result<Option<u64>> {
9898
// Note that we cannot use the regular mmap based ELF parser
9999
// backend for this file, as it cannot be mmap'ed. We have to
100100
// fall back to using regular I/O instead.
101-
let parser = match ElfParser::open_non_mmap(PROC_KCORE) {
101+
let parser = match ElfParser::open_file_io(PROC_KCORE) {
102102
Ok(parser) => parser,
103103
Err(err) if err.kind() == ErrorKind::NotFound => return Ok(None),
104104
Err(err) => return Err(err),

src/normalize/normalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl Normalizer {
346346
if self.cache_build_ids {
347347
let (file, cell) = self.build_id_cache.entry(path)?;
348348
cell.get_or_try_init(|| {
349-
let parser = ElfParser::open_file(file, path)?;
349+
let parser = ElfParser::from_file(file, path)?;
350350
let build_id =
351351
read_build_id(&parser)?.map(|build_id| Cow::Owned(build_id.to_vec()));
352352
Result::<_, Error>::Ok(build_id)

src/zip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ mod tests {
472472
let mut file = NamedTempFile::new().unwrap();
473473
let () = file.write_all(entry.data).unwrap();
474474

475-
let elf = ElfParser::open_file(file.as_file(), file.path()).unwrap();
475+
let elf = ElfParser::from_file(file.as_file(), file.path()).unwrap();
476476
assert!(elf.find_section(".text").is_ok());
477477
}
478478

0 commit comments

Comments
 (0)