]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/pkgcachegen.cc
Prevent double remapping of iterators and string views
[apt.git] / apt-pkg / pkgcachegen.cc
index 02ec39e0cbbd0a78d80b4bcd3c57554da66c9e5c..f9d8a8b4b2bfcb4865fdcec8007f08eb814b2012 100644 (file)
@@ -40,8 +40,8 @@
 #include <unistd.h>
 
 #include <apti18n.h>
-
-template<class T> using Dynamic = pkgCacheGenerator::Dynamic<T>;                                                       /*}}}*/
+                                                                       /*}}}*/
+template<class T> using Dynamic = pkgCacheGenerator::Dynamic<T>;
 typedef std::vector<pkgIndexFile *>::iterator FileIterator;
 template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap;
 
@@ -49,6 +49,7 @@ static bool IsDuplicateDescription(pkgCache::DescIterator Desc,
                            MD5SumValue const &CurMd5, std::string const &CurLang);
 
 using std::string;
+using APT::StringView;
 
 // CacheGenerator::pkgCacheGenerator - Constructor                     /*{{{*/
 // ---------------------------------------------------------------------
@@ -56,6 +57,9 @@ using std::string;
 pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
                    Map(*pMap), Cache(pMap,false), Progress(Prog),
                     CurrentRlsFile(NULL), CurrentFile(NULL), d(NULL)
+{
+}
+bool pkgCacheGenerator::Start()
 {
    if (Map.Size() == 0)
    {
@@ -66,7 +70,9 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
       bool const newError = _error->PendingError();
       _error->MergeWithStack();
       if (newError)
-        return;
+        return false;
+      if (Map.Size() <= 0)
+        return false;
 
       Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
 
@@ -75,16 +81,15 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
 
       // make room for the hashtables for packages and groups
       if (Map.RawAllocate(2 * (Cache.HeaderP->GetHashTableSize() * sizeof(map_pointer_t))) == 0)
-        return;
+        return false;
 
       map_stringitem_t const idxVerSysName = WriteStringInMap(_system->VS->Label);
       if (unlikely(idxVerSysName == 0))
-        return;
-      Cache.HeaderP->VerSysName = idxVerSysName;
+        return false;
       map_stringitem_t const idxArchitecture = StoreString(MIXED, _config->Find("APT::Architecture"));
       if (unlikely(idxArchitecture == 0))
-        return;
-      Cache.HeaderP->Architecture = idxArchitecture;
+        return false;
+      map_stringitem_t idxArchitectures;
 
       std::vector<std::string> archs = APT::Configuration::getArchitectures();
       if (archs.size() > 1)
@@ -93,13 +98,17 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
         std::string list = *a;
         for (++a; a != archs.end(); ++a)
            list.append(",").append(*a);
-        map_stringitem_t const idxArchitectures = WriteStringInMap(list);
+        idxArchitectures = WriteStringInMap(list);
         if (unlikely(idxArchitectures == 0))
-           return;
-        Cache.HeaderP->SetArchitectures(idxArchitectures);
+           return false;
       }
       else
-        Cache.HeaderP->SetArchitectures(idxArchitecture);
+        idxArchitectures = idxArchitecture;
+
+      Cache.HeaderP = (pkgCache::Header *)Map.Data();
+      Cache.HeaderP->VerSysName = idxVerSysName;
+      Cache.HeaderP->Architecture = idxArchitecture;
+      Cache.HeaderP->SetArchitectures(idxArchitectures);
 
       // Calculate the hash for the empty map, so ReMap does not fail
       Cache.HeaderP->CacheFileSize = Cache.CacheHash();
@@ -111,14 +120,12 @@ pkgCacheGenerator::pkgCacheGenerator(DynamicMMap *pMap,OpProgress *Prog) :
       Cache.ReMap(); 
       Map.UsePools(*Cache.HeaderP->Pools,sizeof(Cache.HeaderP->Pools)/sizeof(Cache.HeaderP->Pools[0]));
       if (Cache.VS != _system->VS)
-      {
-        _error->Error(_("Cache has an incompatible versioning system"));
-        return;
-      }
+        return _error->Error(_("Cache has an incompatible versioning system"));
    }
 
    Cache.HeaderP->Dirty = true;
    Map.Sync(0,sizeof(pkgCache::Header));
+   return true;
 }
                                                                        /*}}}*/
 // CacheGenerator::~pkgCacheGenerator - Destructor                     /*{{{*/
@@ -140,7 +147,11 @@ pkgCacheGenerator::~pkgCacheGenerator()
    Map.Sync(0,sizeof(pkgCache::Header));
 }
                                                                        /*}}}*/
-void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newMap) {/*{{{*/
+void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newMap, size_t oldSize) {/*{{{*/
+   // Prevent multiple remaps of the same iterator. If seen.insert(iterator)
+   // returns (something, true) the iterator was not yet seen and we can
+   // remap it.
+   std::unordered_set<void *> seen;
    if (oldMap == newMap)
       return;
 
@@ -154,53 +165,74 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM
 
    for (std::vector<pkgCache::GrpIterator*>::const_iterator i = Dynamic<pkgCache::GrpIterator>::toReMap.begin();
        i != Dynamic<pkgCache::GrpIterator>::toReMap.end(); ++i)
-      (*i)->ReMap(oldMap, newMap);
+      if (std::get<1>(seen.insert(*i)) == true)
+        (*i)->ReMap(oldMap, newMap);
    for (std::vector<pkgCache::PkgIterator*>::const_iterator i = Dynamic<pkgCache::PkgIterator>::toReMap.begin();
        i != Dynamic<pkgCache::PkgIterator>::toReMap.end(); ++i)
-      (*i)->ReMap(oldMap, newMap);
+      if (std::get<1>(seen.insert(*i)) == true)
+        (*i)->ReMap(oldMap, newMap);
    for (std::vector<pkgCache::VerIterator*>::const_iterator i = Dynamic<pkgCache::VerIterator>::toReMap.begin();
        i != Dynamic<pkgCache::VerIterator>::toReMap.end(); ++i)
-      (*i)->ReMap(oldMap, newMap);
+      if (std::get<1>(seen.insert(*i)) == true)
+        (*i)->ReMap(oldMap, newMap);
    for (std::vector<pkgCache::DepIterator*>::const_iterator i = Dynamic<pkgCache::DepIterator>::toReMap.begin();
        i != Dynamic<pkgCache::DepIterator>::toReMap.end(); ++i)
-      (*i)->ReMap(oldMap, newMap);
+       if (std::get<1>(seen.insert(*i)) == true)
+        (*i)->ReMap(oldMap, newMap);
    for (std::vector<pkgCache::DescIterator*>::const_iterator i = Dynamic<pkgCache::DescIterator>::toReMap.begin();
        i != Dynamic<pkgCache::DescIterator>::toReMap.end(); ++i)
-      (*i)->ReMap(oldMap, newMap);
+      if (std::get<1>(seen.insert(*i)) == true)
+        (*i)->ReMap(oldMap, newMap);
    for (std::vector<pkgCache::PrvIterator*>::const_iterator i = Dynamic<pkgCache::PrvIterator>::toReMap.begin();
        i != Dynamic<pkgCache::PrvIterator>::toReMap.end(); ++i)
-      (*i)->ReMap(oldMap, newMap);
+      if (std::get<1>(seen.insert(*i)) == true)
+        (*i)->ReMap(oldMap, newMap);
    for (std::vector<pkgCache::PkgFileIterator*>::const_iterator i = Dynamic<pkgCache::PkgFileIterator>::toReMap.begin();
        i != Dynamic<pkgCache::PkgFileIterator>::toReMap.end(); ++i)
-      (*i)->ReMap(oldMap, newMap);
+      if (std::get<1>(seen.insert(*i)) == true)
+        (*i)->ReMap(oldMap, newMap);
    for (std::vector<pkgCache::RlsFileIterator*>::const_iterator i = Dynamic<pkgCache::RlsFileIterator>::toReMap.begin();
        i != Dynamic<pkgCache::RlsFileIterator>::toReMap.end(); ++i)
-      (*i)->ReMap(oldMap, newMap);
+      if (std::get<1>(seen.insert(*i)) == true)
+        (*i)->ReMap(oldMap, newMap);
+   for (APT::StringView* ViewP : Dynamic<APT::StringView>::toReMap) {
+      if (std::get<1>(seen.insert(ViewP)) == false)
+        continue;
+      // Ignore views outside of the cache.
+      if (ViewP->data() < static_cast<const char*>(oldMap)
+        || ViewP->data() > static_cast<const char*>(oldMap) + oldSize)
+        continue;
+      const char *data = ViewP->data() + (static_cast<const char*>(newMap) - static_cast<const char*>(oldMap));
+      *ViewP = StringView(data , ViewP->size());
+   }
 }                                                                      /*}}}*/
 // CacheGenerator::WriteStringInMap                                    /*{{{*/
 map_stringitem_t pkgCacheGenerator::WriteStringInMap(const char *String,
                                        const unsigned long &Len) {
+   size_t oldSize = Map.Size();
    void const * const oldMap = Map.Data();
    map_stringitem_t const index = Map.WriteString(String, Len);
    if (index != 0)
-      ReMap(oldMap, Map.Data());
+      ReMap(oldMap, Map.Data(), oldSize);
    return index;
 }
                                                                        /*}}}*/
 // CacheGenerator::WriteStringInMap                                    /*{{{*/
 map_stringitem_t pkgCacheGenerator::WriteStringInMap(const char *String) {
+   size_t oldSize = Map.Size();
    void const * const oldMap = Map.Data();
    map_stringitem_t const index = Map.WriteString(String);
    if (index != 0)
-      ReMap(oldMap, Map.Data());
+      ReMap(oldMap, Map.Data(), oldSize);
    return index;
 }
                                                                        /*}}}*/
 map_pointer_t pkgCacheGenerator::AllocateInMap(const unsigned long &size) {/*{{{*/
+   size_t oldSize = Map.Size();
    void const * const oldMap = Map.Data();
    map_pointer_t const index = Map.Allocate(size);
    if (index != 0)
-      ReMap(oldMap, Map.Data());
+      ReMap(oldMap, Map.Data(), oldSize);
    return index;
 }
                                                                        /*}}}*/
@@ -224,8 +256,10 @@ bool pkgCacheGenerator::MergeList(ListParser &List,
       if (Counter % 100 == 0 && Progress != 0)
         Progress->Progress(List.Offset());
 
-      string Arch = List.Architecture();
-      string const Version = List.Version();
+      APT::StringView Arch = List.Architecture();
+      Dynamic<APT::StringView> DynArch(Arch);
+      APT::StringView Version = List.Version();
+      Dynamic<APT::StringView> DynVersion(Version);
       if (Version.empty() == true && Arch.empty() == true)
       {
         // package descriptions
@@ -307,8 +341,6 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator
 
    // Find the right version to write the description
    MD5SumValue CurMd5 = List.Description_md5();
-   if (CurMd5.Value().empty() == true && List.Description("").empty() == true)
-      return true;
    std::vector<std::string> availDesc = List.AvailableDescriptionLanguages();
    for (Ver = Pkg.VersionList(); Ver.end() == false; ++Ver)
    {
@@ -338,7 +370,7 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator
                                                                        /*}}}*/
 // CacheGenerator::MergeListVersion                                    /*{{{*/
 bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg,
-                                        std::string const &Version, pkgCache::VerIterator* &OutVer)
+                                        APT::StringView const &Version, pkgCache::VerIterator* &OutVer)
 {
    pkgCache::VerIterator Ver = Pkg.VersionList();
    Dynamic<pkgCache::VerIterator> DynVer(Ver);
@@ -353,7 +385,9 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
       int Res = 1;
       for (; Ver.end() == false; LastVer = &Ver->NextVer, ++Ver)
       {
-        Res = Cache.VS->CmpVersion(Version,Ver.VerStr());
+        char const * const VerStr = Ver.VerStr();
+        Res = Cache.VS->DoCmpVersion(Version.data(), Version.data() + Version.length(),
+              VerStr, VerStr + strlen(VerStr));
         // Version is higher as current version - insert here
         if (Res > 0)
            break;
@@ -443,8 +477,6 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
 
    /* Record the Description(s) based on their master md5sum */
    MD5SumValue CurMd5 = List.Description_md5();
-   if (CurMd5.Value().empty() == true && List.Description("").empty() == true)
-      return true;
 
    /* Before we add a new description we first search in the group for
       a version with a description of the same MD5 - if so we reuse this
@@ -501,8 +533,9 @@ bool pkgCacheGenerator::AddNewDescription(ListParser &List, pkgCache::VerIterato
 // CacheGenerator::NewGroup - Add a new group                          /*{{{*/
 // ---------------------------------------------------------------------
 /* This creates a new group structure and adds it to the hash table */
-bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name)
+bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, StringView Name)
 {
+   Dynamic<StringView> DName(Name);
    Grp = Cache.FindGrp(Name);
    if (Grp.end() == false)
       return true;
@@ -521,7 +554,8 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name)
    // Insert it into the hash table
    unsigned long const Hash = Cache.Hash(Name);
    map_pointer_t *insertAt = &Cache.HeaderP->GrpHashTableP()[Hash];
-   while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.GrpP + *insertAt)->Name) > 0)
+
+   while (*insertAt != 0 && Name.compare(Cache.ViewString((Cache.GrpP + *insertAt)->Name)) > 0)
       insertAt = &(Cache.GrpP + *insertAt)->Next;
    Grp->Next = *insertAt;
    *insertAt = Group;
@@ -533,9 +567,11 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, const string &Name)
 // CacheGenerator::NewPackage - Add a new package                      /*{{{*/
 // ---------------------------------------------------------------------
 /* This creates a new package structure and adds it to the hash table */
-bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name,
-                                       const string &Arch) {
+bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg, StringView Name,
+                                       StringView Arch) {
    pkgCache::GrpIterator Grp;
+   Dynamic<StringView> DName(Name);
+   Dynamic<StringView> DArch(Arch);
    Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
    if (unlikely(NewGroup(Grp, Name) == false))
       return false;
@@ -567,15 +603,14 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name
       // Insert it into the hash table
       map_id_t const Hash = Cache.Hash(Name);
       map_pointer_t *insertAt = &Cache.HeaderP->PkgHashTableP()[Hash];
-      while (*insertAt != 0 && strcasecmp(Name.c_str(), Cache.StrP + (Cache.GrpP + (Cache.PkgP + *insertAt)->Group)->Name) > 0)
+      while (*insertAt != 0 && Name.compare(Cache.StrP + (Cache.GrpP + (Cache.PkgP + *insertAt)->Group)->Name) > 0)
         insertAt = &(Cache.PkgP + *insertAt)->NextPackage;
       Pkg->NextPackage = *insertAt;
       *insertAt = Package;
    }
    else // Group the Packages together
    {
-      // but first get implicit provides done
-      if (APT::Configuration::checkArchitecture(Pkg.Arch()) == true)
+      // if sibling is provided by another package, this one is too
       {
         pkgCache::PkgIterator const M = Grp.FindPreferredPkg(false); // native or any foreign pkg will do
         if (M.end() == false) {
@@ -590,22 +625,31 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name
               if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed ||
                   ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign &&
                        (Prv->Flags & pkgCache::Flag::MultiArchImplicit) == 0))
+              {
+                 if (APT::Configuration::checkArchitecture(Ver.ParentPkg().Arch()) == false)
+                    continue;
                  if (NewProvides(Ver, Pkg, Prv->ProvideVersion, Prv->Flags) == false)
                     return false;
+              }
            }
         }
-
-
+      }
+      // let M-A:foreign package siblings provide this package
+      {
         pkgCache::PkgIterator P;
         pkgCache::VerIterator Ver;
         Dynamic<pkgCache::PkgIterator> DynP(P);
         Dynamic<pkgCache::VerIterator> DynVer(Ver);
 
         for (P = Grp.PackageList(); P.end() == false;  P = Grp.NextPkg(P))
+        {
+           if (APT::Configuration::checkArchitecture(P.Arch()) == false)
+              continue;
            for (Ver = P.VersionList(); Ver.end() == false; ++Ver)
               if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
                  if (NewProvides(Ver, Pkg, Ver->VerStr, pkgCache::Flag::MultiArchImplicit) == false)
                     return false;
+        }
       }
       // and negative dependencies, don't forget negative dependencies
       {
@@ -639,30 +683,45 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg,const string &Name
    // lazy-create foo (of amd64) provides foo:amd64 at the time we first need it
    if (Arch == "any")
    {
-      size_t const found = Name.find(':');
-      std::string const NameA = Name.substr(0, found);
-      std::string const ArchA = Name.substr(found + 1);
-      pkgCache::PkgIterator PkgA = Cache.FindPkg(NameA, ArchA);
-      if (PkgA.end() == false)
+      size_t const found = Name.rfind(':');
+      StringView ArchA = Name.substr(found + 1);
+      if (ArchA != "any")
       {
+        // ArchA is used inside the loop which might remap (NameA is not used)
+        Dynamic<StringView> DynArchA(ArchA);
+        StringView NameA = Name.substr(0, found);
+        pkgCache::PkgIterator PkgA = Cache.FindPkg(NameA, ArchA);
         Dynamic<pkgCache::PkgIterator> DynPkgA(PkgA);
-        pkgCache::PrvIterator Prv = PkgA.ProvidesList();
-        for (; Prv.end() == false; ++Prv)
+        if (PkgA.end())
         {
-           if (Prv.IsMultiArchImplicit())
-              continue;
-           pkgCache::VerIterator V = Prv.OwnerVer();
-           if (ArchA != V.ParentPkg().Arch())
-              continue;
-           if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false)
+           Dynamic<StringView> DynNameA(NameA);
+           if (NewPackage(PkgA, NameA, ArchA) == false)
               return false;
         }
-        pkgCache::VerIterator V = PkgA.VersionList();
-        Dynamic<pkgCache::VerIterator> DynV(V);
-        for (; V.end() == false; ++V)
+        if (unlikely(PkgA.end()))
+           return _error->Fatal("NewPackage was successful for %s:%s,"
+                 "but the package doesn't exist anyhow!",
+                 NameA.to_string().c_str(), ArchA.to_string().c_str());
+        else
         {
-           if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false)
-              return false;
+           pkgCache::PrvIterator Prv = PkgA.ProvidesList();
+           for (; Prv.end() == false; ++Prv)
+           {
+              if (Prv.IsMultiArchImplicit())
+                 continue;
+              pkgCache::VerIterator V = Prv.OwnerVer();
+              if (ArchA != V.ParentPkg().Arch())
+                 continue;
+              if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false)
+                 return false;
+           }
+           pkgCache::VerIterator V = PkgA.VersionList();
+           Dynamic<pkgCache::VerIterator> DynV(V);
+           for (; V.end() == false; ++V)
+           {
+              if (NewProvides(V, Pkg, V->VerStr, pkgCache::Flag::MultiArchImplicit | pkgCache::Flag::ArchSpecific) == false)
+                 return false;
+           }
         }
       }
    }
@@ -674,9 +733,8 @@ bool pkgCacheGenerator::AddImplicitDepends(pkgCache::GrpIterator &G,
                                           pkgCache::PkgIterator &P,
                                           pkgCache::VerIterator &V)
 {
-   // copy P.Arch() into a string here as a cache remap
-   // in NewDepends() later may alter the pointer location
-   string Arch = P.Arch() == NULL ? "" : P.Arch();
+   APT::StringView Arch = P.Arch() == NULL ? "" : P.Arch();
+   Dynamic<APT::StringView> DynArch(Arch);
    map_pointer_t *OldDepLast = NULL;
    /* MultiArch handling introduces a lot of implicit Dependencies:
       - MultiArch: same → Co-Installable if they have the same version
@@ -777,7 +835,7 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
 // ---------------------------------------------------------------------
 /* This puts a version structure in the linked list */
 map_pointer_t pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
-                                           const string &VerStr,
+                                           APT::StringView const &VerStr,
                                            map_pointer_t const ParentPkg,
                                            unsigned short const Hash,
                                            map_pointer_t const Next)
@@ -806,8 +864,8 @@ map_pointer_t pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
            continue;
         for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V)
         {
-           int const cmp = strcmp(V.VerStr(), VerStr.c_str());
-           if (cmp == 0)
+           int const cmp = strncmp(V.VerStr(), VerStr.data(), VerStr.length());
+           if (cmp == 0 && V.VerStr()[VerStr.length()] == '\0')
            {
               Ver->VerStr = V->VerStr;
               return Version;
@@ -997,14 +1055,17 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg,
 /* This creates a Group and the Package to link this dependency to if
    needed and handles also the caching of the old endpoint */
 bool pkgCacheListParser::NewDepends(pkgCache::VerIterator &Ver,
-                                              const string &PackageName,
-                                              const string &Arch,
-                                              const string &Version,
+                                              StringView PackageName,
+                                              StringView Arch,
+                                              StringView Version,
                                               uint8_t const Op,
                                               uint8_t const Type)
 {
    pkgCache::GrpIterator Grp;
    Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
+   Dynamic<StringView> DynPackageName(PackageName);
+   Dynamic<StringView> DynArch(Arch);
+   Dynamic<StringView> DynVersion(Version);
    if (unlikely(Owner->NewGroup(Grp, PackageName) == false))
       return false;
 
@@ -1013,7 +1074,7 @@ bool pkgCacheListParser::NewDepends(pkgCache::VerIterator &Ver,
    {
       int const CmpOp = Op & 0x0F;
       // =-deps are used (79:1) for lockstep on same-source packages (e.g. data-packages)
-      if (CmpOp == pkgCache::Dep::Equals && strcmp(Version.c_str(), Ver.VerStr()) == 0)
+      if (CmpOp == pkgCache::Dep::Equals && Version == Ver.VerStr())
         idxVersion = Ver->VerStr;
 
       if (idxVersion == 0)
@@ -1066,12 +1127,15 @@ bool pkgCacheListParser::NewDepends(pkgCache::VerIterator &Ver,
                                                                        /*}}}*/
 // ListParser::NewProvides - Create a Provides element                 /*{{{*/
 bool pkgCacheListParser::NewProvides(pkgCache::VerIterator &Ver,
-                                               const string &PkgName,
-                                               const string &PkgArch,
-                                               const string &Version,
+                                               StringView PkgName,
+                                               StringView PkgArch,
+                                               StringView Version,
                                                uint8_t const Flags)
 {
    pkgCache const &Cache = Owner->Cache;
+   Dynamic<StringView> DynPkgName(PkgName);
+   Dynamic<StringView> DynArch(PkgArch);
+   Dynamic<StringView> DynVersion(Version);
 
    // We do not add self referencing provides
    if (Ver.ParentPkg().Name() == PkgName && (PkgArch == Ver.ParentPkg().Arch() ||
@@ -1120,11 +1184,13 @@ bool pkgCacheGenerator::NewProvides(pkgCache::VerIterator &Ver,
 }
                                                                        /*}}}*/
 // ListParser::NewProvidesAllArch - add provides for all architectures /*{{{*/
-bool pkgCacheListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package,
-                               string const &Version, uint8_t const Flags) {
+bool pkgCacheListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, StringView Package,
+                               StringView Version, uint8_t const Flags) {
    pkgCache &Cache = Owner->Cache;
    pkgCache::GrpIterator Grp = Cache.FindGrp(Package);
    Dynamic<pkgCache::GrpIterator> DynGrp(Grp);
+   Dynamic<StringView> DynPackage(Package);
+   Dynamic<StringView> DynVersion(Version);
 
    if (Grp.end() == true)
       return NewProvides(Ver, Package, Cache.NativeArch(), Version, Flags);
@@ -1256,23 +1322,21 @@ bool pkgCacheGenerator::SelectFile(std::string const &File,
 map_stringitem_t pkgCacheGenerator::StoreString(enum StringType const type, const char *S,
                                                 unsigned int Size)
 {
-   std::string const key(S, Size);
-
-   std::unordered_map<std::string,map_stringitem_t> * strings;
+   auto strings = &strMixed;
    switch(type) {
       case MIXED: strings = &strMixed; break;
       case PKGNAME: strings = &strPkgNames; break;
       case VERSIONNUMBER: strings = &strVersions; break;
       case SECTION: strings = &strSections; break;
-      default: _error->Fatal("Unknown enum type used for string storage of '%s'", key.c_str()); return 0;
+      default: _error->Fatal("Unknown enum type used for string storage of '%.*s'", Size, S); return 0;
    }
 
-   std::unordered_map<std::string,map_stringitem_t>::const_iterator const item = strings->find(key);
+   auto const item = strings->find({S, Size, nullptr, 0});
    if (item != strings->end())
-      return item->second;
+      return item->item;
 
    map_stringitem_t const idxString = WriteStringInMap(S,Size);
-   strings->insert(std::make_pair(key, idxString));
+   strings->insert({nullptr, Size, this, idxString});
    return idxString;
 }
                                                                        /*}}}*/
@@ -1563,7 +1627,7 @@ static bool loadBackMMapFromFile(std::unique_ptr<pkgCacheGenerator> &Gen,
    if (CacheF.Read((unsigned char *)Map->Data() + alloc, CacheF.Size()) == false)
       return false;
    Gen.reset(new pkgCacheGenerator(Map.get(),Progress));
-   return true;
+   return Gen->Start();
 }
 bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
                        MMap **OutMap, bool AllowMem)
@@ -1669,6 +1733,8 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
       if (Debug == true)
         std::clog << "srcpkgcache.bin is NOT valid - rebuild" << std::endl;
       Gen.reset(new pkgCacheGenerator(Map.get(),Progress));
+      if (Gen->Start() == false)
+        return false;
 
       TotalSize += ComputeSize(&List, Files.begin(),Files.end());
       if (BuildCache(*Gen, Progress, CurrentSize, TotalSize, &List,
@@ -1694,7 +1760,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress
    }
 
    if (Debug == true)
-      std::clog << "Caches done. Now bring in the volatile files (if any)" << std::endl;
+      std::clog << "Caches done. " << (volatile_fine ? "No volatile files, so we are done here." : "Now bring in the volatile files") << std::endl;
 
    if (volatile_fine == false)
    {
@@ -1746,7 +1812,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O
    if (Progress != NULL)
       Progress->OverallProgress(0,1,1,_("Reading package lists"));
    pkgCacheGenerator Gen(Map.get(),Progress);
-   if (_error->PendingError() == true)
+   if (Gen.Start() == false || _error->PendingError() == true)
       return false;
    if (BuildCache(Gen,Progress,CurrentSize,TotalSize, NULL,
                  Files.begin(), Files.end()) == false)