aboutsummaryrefslogtreecommitdiff
path: root/paludis
diff options
context:
space:
mode:
authorAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2016-12-07 10:26:02 -0800
committerAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2016-12-07 20:05:31 -0800
commit6a6d0160cf92adade62217c485ad9b49edcea62f (patch)
treeb6c56210a80bb2554b4fa70e3cdbe943846e18d3 /paludis
parentf01d4a0af068ab9cb5bc29fa3e4ee04291c1cc83 (diff)
downloadpaludis-6a6d0160cf92adade62217c485ad9b49edcea62f.tar.gz
paludis-6a6d0160cf92adade62217c485ad9b49edcea62f.tar.xz
paludis: more range loop usage (NFC)
Diffstat (limited to 'paludis')
-rw-r--r--paludis/broken_linkage_finder.cc23
-rw-r--r--paludis/elf_linkage_checker.cc76
-rw-r--r--paludis/util/elf.hh5
-rw-r--r--paludis/util/elf_dynamic_section.hh5
4 files changed, 53 insertions, 56 deletions
diff --git a/paludis/broken_linkage_finder.cc b/paludis/broken_linkage_finder.cc
index 617e8bb..e38bf5a 100644
--- a/paludis/broken_linkage_finder.cc
+++ b/paludis/broken_linkage_finder.cc
@@ -157,12 +157,10 @@ BrokenLinkageFinder::BrokenLinkageFinder(const Environment * env, const std::sha
std::bind(realpath_with_current_and_root, _1, FSPath("/"), env->preferred_root_key()->parse_value()));
std::sort(search_dirs_nosyms.begin(), search_dirs_nosyms.end(), FSPathComparator());
- for (std::vector<FSPath>::const_iterator it(search_dirs_nosyms.begin()),
- it_end(search_dirs_nosyms.end()); it_end != it; ++it)
- if (search_dirs_pruned.end() ==
- std::find_if(search_dirs_pruned.begin(), search_dirs_pruned.end(),
- ParentOf(*it)))
- search_dirs_pruned.push_back(*it);
+ for (const auto & dir : search_dirs_nosyms)
+ if (search_dirs_pruned.end() == std::find_if(search_dirs_pruned.begin(), search_dirs_pruned.end(), ParentOf(dir)))
+ search_dirs_pruned.push_back(dir);
+
Log::get_instance()->message("broken_linkage_finder.config",
ll_debug, lc_context) << "After resolving symlinks and pruning subdirectories, SEARCH_DIRS=\"" <<
join(search_dirs_pruned.begin(), search_dirs_pruned.end(), " ") << "\"";
@@ -174,13 +172,12 @@ BrokenLinkageFinder::BrokenLinkageFinder(const Environment * env, const std::sha
std::for_each(search_dirs_pruned.begin(), search_dirs_pruned.end(),
std::bind(&Imp<BrokenLinkageFinder>::search_directory, _imp.get(), _1));
- for (std::set<FSPath>::const_iterator it(_imp->extra_lib_dirs.begin()),
- it_end(_imp->extra_lib_dirs.end()); it_end != it; ++it)
+ for (const auto & dir : _imp->extra_lib_dirs)
{
Log::get_instance()->message("broken_linkage_finder.config", ll_debug, lc_context)
- << "Need to check for extra libraries in '" << (env->preferred_root_key()->parse_value() / *it) << "'";
+ << "Need to check for extra libraries in '" << (env->preferred_root_key()->parse_value() / dir) << "'";
std::for_each(indirect_iterator(_imp->checkers.begin()), indirect_iterator(_imp->checkers.end()),
- std::bind(&LinkageChecker::add_extra_lib_dir, _1, env->preferred_root_key()->parse_value() / *it));
+ std::bind(&LinkageChecker::add_extra_lib_dir, _1, env->preferred_root_key()->parse_value() / dir));
}
std::function<void (const FSPath &, const std::string &)> callback(
@@ -333,11 +330,9 @@ Imp<BrokenLinkageFinder>::gather_package(const std::shared_ptr<const PackageID>
if (! contents)
return;
- for (Contents::ConstIterator it(contents->begin()),
- it_end(contents->end()); it_end != it; ++it)
+ for (const auto & content : *contents)
{
- const ContentsFileEntry * file(visitor_cast<const ContentsFileEntry>(**it));
- if (nullptr != file)
+ if (const auto *file = visitor_cast<const ContentsFileEntry>(*content))
{
std::unique_lock<std::mutex> l(mutex);
files.insert(std::make_pair(file->location_key()->parse_value(), pkg));
diff --git a/paludis/elf_linkage_checker.cc b/paludis/elf_linkage_checker.cc
index c4e2cdf..8522b70 100644
--- a/paludis/elf_linkage_checker.cc
+++ b/paludis/elf_linkage_checker.cc
@@ -126,8 +126,8 @@ namespace paludis
Imp(const FSPath & the_root, const std::shared_ptr<const Sequence<std::string>> & the_libraries) :
root(the_root)
{
- for (auto it(the_libraries->begin()), it_end(the_libraries->end()); it_end != it; ++it)
- check_libraries.insert(*it);
+ for (const auto & library : *the_libraries)
+ check_libraries.insert(library);
}
};
}
@@ -179,19 +179,17 @@ Imp<ElfLinkageChecker>::check_elf(const FSPath & file, std::istream & stream)
if (check_libraries.empty() && ET_DYN == elf.get_type())
handle_library(file, arch);
- for (typename ElfObject<ElfType_>::SectionIterator sec_it(elf.section_begin()),
- sec_it_end(elf.section_end()); sec_it_end != sec_it; ++sec_it)
+ for (const auto & section : elf.sections())
{
- const DynamicSection<ElfType_> * dyn_sec(visitor_cast<const DynamicSection<ElfType_> >(*sec_it));
-
- if (nullptr != dyn_sec)
- for (typename DynamicSection<ElfType_>::EntryIterator ent_it(dyn_sec->entry_begin()),
- ent_it_end(dyn_sec->entry_end()); ent_it_end != ent_it; ++ent_it)
+ if (const auto *dyn_sec = visitor_cast<const DynamicSection<ElfType_>>(section))
+ {
+ for (const auto & entry : dyn_sec->entries())
{
- const DynamicEntryString<ElfType_> * ent_str(visitor_cast<const DynamicEntryString<ElfType_> >(*ent_it));
-
- if (nullptr != ent_str && "NEEDED" == ent_str->tag_name())
+ if (const auto *ent_str = visitor_cast<const DynamicEntryString<ElfType_>>(entry))
{
+ if (ent_str->tag_name() != "NEEDED")
+ continue;
+
const std::string & req((*ent_str)());
if (check_libraries.empty() || check_libraries.end() != check_libraries.find(req))
{
@@ -201,6 +199,7 @@ Imp<ElfLinkageChecker>::check_elf(const FSPath & file, std::istream & stream)
}
}
}
+ }
}
}
catch (const InvalidElfFileError & e)
@@ -270,38 +269,33 @@ ElfLinkageChecker::need_breakage_added(
typedef std::map<std::string, std::set<ElfArchitecture> > AllMissing;
AllMissing all_missing;
- for (Needed::iterator arch_it(_imp->needed.begin()),
- arch_it_end(_imp->needed.end()); arch_it_end != arch_it; ++arch_it)
+ for (const auto & arch : _imp->needed)
{
- std::sort(_imp->libraries[arch_it->first].begin(), _imp->libraries[arch_it->first].end());
- _imp->libraries[arch_it->first].erase(
- std::unique(_imp->libraries[arch_it->first].begin(),
- _imp->libraries[arch_it->first].end()),
- _imp->libraries[arch_it->first].end());
+ std::sort(_imp->libraries[arch.first].begin(), _imp->libraries[arch.first].end());
+ _imp->libraries[arch.first].erase(std::unique(_imp->libraries[arch.first].begin(),
+ _imp->libraries[arch.first].end()),
+ _imp->libraries[arch.first].end());
std::vector<std::string> missing;
- std::set_difference(first_iterator(arch_it->second.begin()),
- first_iterator(arch_it->second.end()),
- _imp->libraries[arch_it->first].begin(),
- _imp->libraries[arch_it->first].end(),
+ std::set_difference(first_iterator(arch.second.begin()),
+ first_iterator(arch.second.end()),
+ _imp->libraries[arch.first].begin(),
+ _imp->libraries[arch.first].end(),
std::back_inserter(missing));
- for (std::vector<std::string>::const_iterator it(missing.begin()),
- it_end(missing.end()); it_end != it; ++it)
- all_missing[*it].insert(arch_it->first);
+ for (const auto & item : missing)
+ all_missing[item].insert(arch.first);
}
- for (std::vector<FSPath>::const_iterator dir_it(_imp->extra_lib_dirs.begin()),
- dir_it_end(_imp->extra_lib_dirs.end()); dir_it_end != dir_it; ++dir_it)
+ for (const auto & directory : _imp->extra_lib_dirs)
{
- Context ctx("When searching for missing libraries in '" + stringify(*dir_it) + "':");
+ Context ctx("When searching for missing libraries in '" + stringify(directory) + "':");
- for (AllMissing::iterator missing_it(all_missing.begin()),
- missing_it_end(all_missing.end()); missing_it_end != missing_it; ++missing_it)
+ for (auto & missing : all_missing)
{
- if (missing_it->second.empty())
+ if (missing.second.empty())
continue;
- FSPath file(dereference_with_root(*dir_it / missing_it->first, _imp->root));
+ FSPath file(dereference_with_root(directory / missing.first, _imp->root));
if (! file.stat().is_regular_file())
{
Log::get_instance()->message("broken_linkage_finder.missing", ll_debug, lc_context)
@@ -313,8 +307,8 @@ ElfLinkageChecker::need_breakage_added(
{
SafeIFStream stream(file);
- if (! (_imp->check_extra_elf<Elf32Type>(file, stream, missing_it->second) ||
- _imp->check_extra_elf<Elf64Type>(file, stream, missing_it->second)))
+ if (! (_imp->check_extra_elf<Elf32Type>(file, stream, missing.second) ||
+ _imp->check_extra_elf<Elf64Type>(file, stream, missing.second)))
Log::get_instance()->message("broken_linkage_finder.not_an_elf", ll_debug, lc_no_context)
<< "'" << file << "' is not an ELF file";
}
@@ -327,13 +321,11 @@ ElfLinkageChecker::need_breakage_added(
}
}
- for (AllMissing::const_iterator missing_it(all_missing.begin()),
- missing_it_end(all_missing.end()); missing_it_end != missing_it; ++missing_it)
- for (std::set<ElfArchitecture>::const_iterator arch_it(missing_it->second.begin()),
- arch_it_end(missing_it->second.end()); arch_it_end != arch_it; ++arch_it)
- std::for_each(_imp->needed[*arch_it][missing_it->first].begin(),
- _imp->needed[*arch_it][missing_it->first].end(),
- std::bind(callback, _1, missing_it->first));
+ for (const auto & missing : all_missing)
+ for (const auto & arch : missing.second)
+ std::for_each(_imp->needed[arch][missing.first].begin(),
+ _imp->needed[arch][missing.first].end(),
+ std::bind(callback, _1, missing.first));
}
diff --git a/paludis/util/elf.hh b/paludis/util/elf.hh
index e98c019..ee00262 100644
--- a/paludis/util/elf.hh
+++ b/paludis/util/elf.hh
@@ -23,6 +23,7 @@
#include <paludis/util/elf_sections.hh>
#include <paludis/util/exception.hh>
+#include <paludis/util/iterator_range.hh>
#include <paludis/util/pimp.hh>
#include <paludis/util/wrapped_forward_iterator-fwd.hh>
#include <iosfwd>
@@ -115,6 +116,10 @@ namespace paludis
typedef paludis::WrappedForwardIterator<SectionIteratorTag, Section<ElfType_> > SectionIterator;
SectionIterator section_begin() const;
SectionIterator section_end() const;
+ IteratorRange<SectionIterator> sections() const noexcept
+ {
+ return {section_begin(), section_end()};
+ }
SectionIterator get_section_by_index(unsigned int index) const;
diff --git a/paludis/util/elf_dynamic_section.hh b/paludis/util/elf_dynamic_section.hh
index af01f6c..aee94b5 100644
--- a/paludis/util/elf_dynamic_section.hh
+++ b/paludis/util/elf_dynamic_section.hh
@@ -23,6 +23,7 @@
#include <paludis/util/elf_sections.hh>
#include <paludis/util/clone.hh>
+#include <paludis/util/iterator_range.hh>
#include <paludis/util/singleton.hh>
#include <paludis/util/pimp.hh>
#include <paludis/util/wrapped_forward_iterator-fwd.hh>
@@ -213,6 +214,10 @@ namespace paludis
typedef WrappedForwardIterator<EntryIteratorTag, DynamicEntry<ElfType_> > EntryIterator;
EntryIterator entry_begin() const;
EntryIterator entry_end() const;
+ IteratorRange<EntryIterator> entries() const noexcept
+ {
+ return {entry_begin(), entry_end()};
+ }
};
}