From c3587c0d9de852eca11d9bbc004095d54115eda4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 24 Feb 2020 17:08:34 +0100 Subject: Replace map_pointer_t with map_pointer This is a first step to a type safe cache, adding typing information everywhere. Next, we'll replace map_pointer implementation with a type safe one. --- apt-pkg/pkgcache.h | 96 +++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'apt-pkg/pkgcache.h') diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 84fc56db8..e5a1a81eb 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -93,9 +93,9 @@ typedef uint32_t map_id_t; // some files get an id, too, but in far less absolute numbers typedef uint16_t map_fileid_t; // relative pointer from cache start -typedef uint32_t map_pointer_t; +template using map_pointer = uint32_t; // same as the previous, but documented to be to a string item -typedef map_pointer_t map_stringitem_t; +typedef map_pointer map_stringitem_t; // we have only a small amount of flags for each item typedef uint8_t map_flags_t; typedef uint8_t map_number_t; @@ -325,16 +325,16 @@ struct pkgCache::Header The PackageFile structures are singly linked lists that represent all package files that have been merged into the cache. */ - map_pointer_t FileList; + map_pointer FileList; /** \brief index of the first ReleaseFile structure */ - map_pointer_t RlsFileList; + map_pointer RlsFileList; /** \brief String representing the version system used */ - map_pointer_t VerSysName; + map_stringitem_t VerSysName; /** \brief native architecture the cache was built against */ - map_pointer_t Architecture; + map_stringitem_t Architecture; /** \brief all architectures the cache was built against */ - map_pointer_t Architectures; + map_stringitem_t Architectures; /** \brief The maximum size of a raw entry from the original Package file */ map_filesize_t MaxVerFileSize; /** \brief The maximum size of a raw entry from the original Translation file */ @@ -363,10 +363,10 @@ struct pkgCache::Header uint32_t HashTableSize; uint32_t GetHashTableSize() const { return HashTableSize; } void SetHashTableSize(unsigned int const sz) { HashTableSize = sz; } - map_pointer_t GetArchitectures() const { return Architectures; } - void SetArchitectures(map_pointer_t const idx) { Architectures = idx; } - map_pointer_t * PkgHashTableP() const { return (map_pointer_t*) (this + 1); } - map_pointer_t * GrpHashTableP() const { return PkgHashTableP() + GetHashTableSize(); } + map_stringitem_t GetArchitectures() const { return Architectures; } + void SetArchitectures(map_stringitem_t const idx) { Architectures = idx; } + map_pointer * PkgHashTableP() const { return (map_pointer*) (this + 1); } + map_pointer * GrpHashTableP() const { return reinterpret_cast *>(PkgHashTableP() + GetHashTableSize()); } /** \brief Hash of the file (TODO: Rename) */ map_filesize_small_t CacheFileSize; @@ -393,17 +393,17 @@ struct pkgCache::Group // Linked List /** \brief Link to the first package which belongs to the group */ - map_pointer_t FirstPackage; // Package + map_pointer FirstPackage; /** \brief Link to the last package which belongs to the group */ - map_pointer_t LastPackage; // Package + map_pointer LastPackage; /** \brief Link to the next Group */ - map_pointer_t Next; // Group + map_pointer Next; /** \brief unique sequel ID */ map_id_t ID; /** \brief List of binary produces by source package with this name. */ - map_pointer_t VersionsInSource; // Version + map_pointer VersionsInSource; }; /*}}}*/ @@ -432,19 +432,19 @@ struct pkgCache::Package versions of a package can be cleanly handled by the system. Furthermore, this linked list is guaranteed to be sorted from Highest version to lowest version with no duplicate entries. */ - map_pointer_t VersionList; // Version + map_pointer VersionList; /** \brief index to the installed version */ - map_pointer_t CurrentVer; // Version + map_pointer CurrentVer; /** \brief index of the group this package belongs to */ - map_pointer_t Group; // Group the Package belongs to + map_pointer Group; // Linked list /** \brief Link to the next package in the same bucket */ - map_pointer_t NextPackage; // Package + map_pointer NextPackage; /** \brief List of all dependencies on this package */ - map_pointer_t RevDepends; // Dependency + map_pointer RevDepends; /** \brief List of all "packages" this package provide */ - map_pointer_t ProvidesList; // Provides + map_pointer ProvidesList; // Install/Remove/Purge etc /** \brief state that the user wishes the package to be in */ @@ -504,7 +504,7 @@ struct pkgCache::ReleaseFile // Linked list /** \brief Link to the next ReleaseFile in the Cache */ - map_pointer_t NextFile; + map_pointer NextFile; /** \brief unique sequel ID */ map_fileid_t ID; }; @@ -520,7 +520,7 @@ struct pkgCache::PackageFile /** \brief physical disk file that this PackageFile represents */ map_stringitem_t FileName; /** \brief the release information */ - map_pointer_t Release; + map_pointer Release; map_stringitem_t Component; map_stringitem_t Architecture; @@ -543,7 +543,7 @@ struct pkgCache::PackageFile // Linked list /** \brief Link to the next PackageFile in the Cache */ - map_pointer_t NextFile; // PackageFile + map_pointer NextFile; /** \brief unique sequel ID */ map_fileid_t ID; }; @@ -556,9 +556,9 @@ struct pkgCache::PackageFile struct pkgCache::VerFile { /** \brief index of the package file that this version was found in */ - map_pointer_t File; // PackageFile + map_pointer File; /** \brief next step in the linked list */ - map_pointer_t NextFile; // PkgVerFile + map_pointer NextFile; /** \brief position in the package file */ map_filesize_t Offset; // File offset /** @TODO document pkgCache::VerFile::Size */ @@ -570,9 +570,9 @@ struct pkgCache::VerFile struct pkgCache::DescFile { /** \brief index of the file that this description was found in */ - map_pointer_t File; // PackageFile + map_pointer File; /** \brief next step in the linked list */ - map_pointer_t NextFile; // PkgVerFile + map_pointer NextFile; /** \brief position in the file */ map_filesize_t Offset; // File offset /** @TODO document pkgCache::DescFile::Size */ @@ -619,19 +619,19 @@ struct pkgCache::Version applies to. If FileList is 0 then this is a blank version. The structure should also have a 0 in all other fields excluding pkgCache::Version::VerStr and Possibly pkgCache::Version::NextVer. */ - map_pointer_t FileList; // VerFile + map_pointer FileList; /** \brief next (lower or equal) version in the linked list */ - map_pointer_t NextVer; // Version + map_pointer NextVer; /** \brief next description in the linked list */ - map_pointer_t DescriptionList; // Description + map_pointer DescriptionList; /** \brief base of the dependency list */ - map_pointer_t DependsList; // Dependency + map_pointer DependsList; /** \brief links to the owning package This allows reverse dependencies to determine the package */ - map_pointer_t ParentPkg; // Package + map_pointer ParentPkg; /** \brief list of pkgCache::Provides */ - map_pointer_t ProvidesList; // Provides + map_pointer ProvidesList; /** \brief archive size for this version @@ -649,7 +649,7 @@ struct pkgCache::Version /** \brief parsed priority value */ map_number_t Priority; /** \brief next version in the source package (might be different binary) */ - map_pointer_t NextInSource; // Version + map_pointer NextInSource; }; /*}}}*/ // Description structure /*{{{*/ @@ -668,11 +668,11 @@ struct pkgCache::Description map_stringitem_t md5sum; /** @TODO document pkgCache::Description::FileList */ - map_pointer_t FileList; // DescFile + map_pointer FileList; /** \brief next translation for this description */ - map_pointer_t NextDesc; // Description + map_pointer NextDesc; /** \brief the text is a description of this package */ - map_pointer_t ParentPkg; // Package + map_pointer ParentPkg; /** \brief unique sequel ID */ map_id_t ID; @@ -693,7 +693,7 @@ struct pkgCache::DependencyData The generator will - if the package does not already exist - create a blank (no version records) package. */ - map_pointer_t Package; // Package + map_pointer Package; /** \brief Dependency type - Depends, Recommends, Conflicts, etc */ map_number_t Type; @@ -702,17 +702,17 @@ struct pkgCache::DependencyData If the high bit is set then it is a logical OR with the previous record. */ map_flags_t CompareOp; - map_pointer_t NextData; + map_pointer NextData; }; struct pkgCache::Dependency { - map_pointer_t DependencyData; // DependencyData + map_pointer DependencyData; /** \brief version of the package which has the depends */ - map_pointer_t ParentVer; // Version + map_pointer ParentVer; /** \brief next reverse dependency of this package */ - map_pointer_t NextRevDepends; // Dependency + map_pointer NextRevDepends; /** \brief next dependency of this version */ - map_pointer_t NextDepends; // Dependency + map_pointer NextDepends; /** \brief unique sequel ID */ map_id_t ID; @@ -730,9 +730,9 @@ struct pkgCache::Dependency struct pkgCache::Provides { /** \brief index of the package providing this */ - map_pointer_t ParentPkg; // Package + map_pointer ParentPkg; /** \brief index of the version this provide line applies to */ - map_pointer_t Version; // Version + map_pointer Version; /** \brief version in the provides line (if any) This version allows dependencies to depend on specific versions of a @@ -740,9 +740,9 @@ struct pkgCache::Provides map_stringitem_t ProvideVersion; map_flags_t Flags; /** \brief next provides (based of package) */ - map_pointer_t NextProvides; // Provides + map_pointer NextProvides; /** \brief next provides (based of version) */ - map_pointer_t NextPkgProv; // Provides + map_pointer NextPkgProv; }; /*}}}*/ -- cgit v1.2.3-70-g09d2 From 4fad7262291a8af1415fb9a3693678bd9610f0d6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 24 Feb 2020 17:46:10 +0100 Subject: Make map_pointer typesafe Instead of just using uint32_t, which would allow you to assign e.g. a map_pointer to a map_pointer, use our own smarter struct that has strict type checking. We allow creating a map_pointer from a nullptr, and we allow comparing map_pointer to nullptr, which also deals with comparisons against 0 which are often used, as 0 will be implictly converted to nullptr. --- apt-pkg/cacheiterators.h | 9 +++++---- apt-pkg/deb/deblistparser.cc | 4 ++-- apt-pkg/edsp/edsplistparser.cc | 4 ++-- apt-pkg/pkgcache.cc | 2 +- apt-pkg/pkgcache.h | 22 +++++++++++++++++++- apt-pkg/pkgcachegen.cc | 43 ++++++++++++++++++++-------------------- apt-pkg/pkgcachegen.h | 2 +- apt-private/private-cachefile.cc | 2 +- cmdline/apt-cache.cc | 4 ++-- 9 files changed, 57 insertions(+), 35 deletions(-) (limited to 'apt-pkg/pkgcache.h') diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index 7f853558b..d2e4f7f90 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -80,6 +80,7 @@ template class pkgCache::Iterator : // Mixed stuff inline bool IsGood() const { return S && Owner && ! end();} inline unsigned long Index() const {return S - OwnerPointer();} + inline map_pointer MapPointer() const {return map_pointer(Index()) ;} void ReMap(void const * const oldMap, void const * const newMap) { if (Owner == 0 || S == 0) @@ -293,7 +294,7 @@ class pkgCache::DepIterator : public Iterator { inline PkgIterator TargetPkg() const {return PkgIterator(*Owner,Owner->PkgP + S2->Package);} inline PkgIterator SmartTargetPkg() const {PkgIterator R(*Owner,0);SmartTargetPkg(R);return R;} inline VerIterator ParentVer() const {return VerIterator(*Owner,Owner->VerP + S->ParentVer);} - inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->ParentVer].ParentPkg);} + inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[uint32_t(S->ParentVer)].ParentPkg);} inline bool Reverse() const {return Type == DepRev;} bool IsCritical() const APT_PURE; bool IsNegative() const APT_PURE; @@ -378,7 +379,7 @@ class pkgCache::PrvIterator : public Iterator { inline const char *ProvideVersion() const {return S->ProvideVersion == 0?0:Owner->StrP + S->ProvideVersion;} inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);} inline VerIterator OwnerVer() const {return VerIterator(*Owner,Owner->VerP + S->Version);} - inline PkgIterator OwnerPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[S->Version].ParentPkg);} + inline PkgIterator OwnerPkg() const {return PkgIterator(*Owner,Owner->PkgP + Owner->VerP[uint32_t(S->Version)].ParentPkg);} /* MultiArch can be translated to SingleArch for an resolver and we did so, by adding provides to help the resolver understand the problem, but @@ -475,7 +476,7 @@ class pkgCache::VerFileIterator : public pkgCache::IteratorFile + Owner->PkgFileP);} + inline PkgFileIterator File() const {return PkgFileIterator(*Owner, Owner->PkgFileP + S->File);} inline VerFileIterator() : Iterator() {} inline VerFileIterator(pkgCache &Owner,VerFile *Trg) : Iterator(Owner, Trg) {} @@ -493,7 +494,7 @@ class pkgCache::DescFileIterator : public Iterator { inline DescFileIterator operator++(int) { DescFileIterator const tmp(*this); operator++(); return tmp; } // Accessors - inline PkgFileIterator File() const {return PkgFileIterator(*Owner,S->File + Owner->PkgFileP);} + inline PkgFileIterator File() const {return PkgFileIterator(*Owner, Owner->PkgFileP + S->File);} inline DescFileIterator() : Iterator() {} inline DescFileIterator(pkgCache &Owner,DescFile *Trg) : Iterator(Owner, Trg) {} diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index eaa9dfda9..ab957a01a 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -208,7 +208,7 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver) // Link into by source package group. Ver->SourcePkgName = G->Name; Ver->NextInSource = G->VersionsInSource; - G->VersionsInSource = Ver.Index(); + G->VersionsInSource = Ver.MapPointer(); Ver->MultiArch = ParseMultiArch(true); // Archive Size @@ -469,7 +469,7 @@ bool debStatusListParser::ParseStatus(pkgCache::PkgIterator &Pkg, if (Ver.end() == true) _error->Warning("Encountered status field in a non-version description"); else - Pkg->CurrentVer = Ver.Index(); + Pkg->CurrentVer = Ver.MapPointer(); } return true; diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc index 45abdbc61..34b9ec934 100644 --- a/apt-pkg/edsp/edsplistparser.cc +++ b/apt-pkg/edsp/edsplistparser.cc @@ -87,7 +87,7 @@ bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg, if (state != 0) { Pkg->CurrentState = pkgCache::State::Installed; - Pkg->CurrentVer = Ver.Index(); + Pkg->CurrentVer = Ver.MapPointer(); } if (Section.FindB("APT-Automatic", false)) @@ -162,7 +162,7 @@ bool eippListParser::ParseStatus(pkgCache::PkgIterator &Pkg, case pkgCache::State::TriggersAwaited: case pkgCache::State::TriggersPending: case pkgCache::State::Installed: - Pkg->CurrentVer = Ver.Index(); + Pkg->CurrentVer = Ver.MapPointer(); break; } break; diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 59f4256ea..02448a073 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -451,7 +451,7 @@ pkgCache::PkgIterator pkgCache::GrpIterator::NextPkg(pkgCache::PkgIterator const LastPkg.end() == true)) return PkgIterator(*Owner, 0); - if (S->LastPackage == LastPkg.Index()) + if (S->LastPackage == LastPkg.MapPointer()) return PkgIterator(*Owner, 0); return PkgIterator(*Owner, Owner->PkgP + LastPkg->NextPackage); diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index e5a1a81eb..ef22a78a0 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -77,6 +77,7 @@ #include #include +#include // required for nullptr_t #include #include #include @@ -92,10 +93,29 @@ typedef uint32_t map_filesize_small_t; typedef uint32_t map_id_t; // some files get an id, too, but in far less absolute numbers typedef uint16_t map_fileid_t; + // relative pointer from cache start -template using map_pointer = uint32_t; +template class map_pointer { + uint32_t val; +public: + map_pointer() noexcept : val(0) {} + map_pointer(nullptr_t) noexcept : val(0) {} + explicit map_pointer(uint32_t n) noexcept : val(n) {} + explicit operator uint32_t() noexcept { return val; } +}; + +template inline T *operator +(T *p, map_pointer m) { return p + uint32_t(m); } +template inline bool operator ==(map_pointer u, map_pointer m) { return uint32_t(u) == uint32_t(m); } +template inline bool operator !=(map_pointer u, map_pointer m) { return uint32_t(u) != uint32_t(m); } +template inline bool operator <(map_pointer u, map_pointer m) { return uint32_t(u) < uint32_t(m); } +template inline bool operator >(map_pointer u, map_pointer m) { return uint32_t(u) > uint32_t(m); } +template inline uint32_t operator -(map_pointer u, map_pointer m) { return uint32_t(u) - uint32_t(m); } +template bool operator ==(map_pointer m, nullptr_t) { return uint32_t(m) == 0; } +template bool operator !=(map_pointer m, nullptr_t) { return uint32_t(m) != 0; } + // same as the previous, but documented to be to a string item typedef map_pointer map_stringitem_t; + // we have only a small amount of flags for each item typedef uint8_t map_flags_t; typedef uint8_t map_number_t; diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index a1e6ca745..83a8c2e63 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -210,7 +210,7 @@ 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); + map_stringitem_t const index{Map.WriteString(String, Len)}; if (index != 0) ReMap(oldMap, Map.Data(), oldSize); return index; @@ -220,7 +220,7 @@ map_stringitem_t pkgCacheGenerator::WriteStringInMap(const char *String, 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); + map_stringitem_t const index{Map.WriteString(String)}; if (index != 0) ReMap(oldMap, Map.Data(), oldSize); return index; @@ -375,7 +375,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator { pkgCache::VerIterator Ver = Pkg.VersionList(); Dynamic DynVer(Ver); - map_pointer *LastVer = &Pkg->VersionList; + map_pointer *LastVer = &Pkg->VersionList; void const * oldMap = Map.Data(); auto Hash = List.VersionHash(); @@ -435,7 +435,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator } // Add a new version - map_pointer const verindex = NewVersion(Ver, Version, Pkg.Index(), Hash, *LastVer); + map_pointer const verindex = NewVersion(Ver, Version, Pkg.MapPointer(), Hash, *LastVer); if (unlikely(verindex == 0)) return _error->Error(_("Error occurred while processing %s (%s%d)"), Pkg.Name(), "NewVersion", 1); @@ -527,7 +527,7 @@ bool pkgCacheGenerator::AddNewDescription(ListParser &List, pkgCache::VerIterato Ver.ParentPkg().Name(), "NewDescription", 1); md5idx = Desc->md5sum; - Desc->ParentPkg = Ver.ParentPkg().Index(); + Desc->ParentPkg = Ver.ParentPkg().MapPointer(); // we add at the end, so that the start is constant as we need // that to be able to efficiently share these lists @@ -602,7 +602,7 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg, StringView Name, Pkg = pkgCache::PkgIterator(Cache,Cache.PkgP + Package); // Set the name, arch and the ID - Pkg->Group = Grp.Index(); + Pkg->Group = Grp.MapPointer(); // all is mapped to the native architecture map_stringitem_t const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : StoreString(MIXED, Arch); if (unlikely(idxArch == 0)) @@ -827,14 +827,14 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver, return false; pkgCache::VerFileIterator VF(Cache,Cache.VerFileP + VerFile); - VF->File = CurrentFile - Cache.PkgFileP; + VF->File = map_pointer{CurrentFile - Cache.PkgFileP}; // Link it to the end of the list map_pointer *Last = &Ver->FileList; for (pkgCache::VerFileIterator V = Ver.FileList(); V.end() == false; ++V) Last = &V->NextFile; VF->NextFile = *Last; - *Last = VF.Index(); + *Last = VF.MapPointer(); VF->Offset = List.Offset(); VF->Size = List.Size(); @@ -912,7 +912,7 @@ bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc, return false; pkgCache::DescFileIterator DF(Cache,Cache.DescFileP + DescFile); - DF->File = CurrentFile - Cache.PkgFileP; + DF->File = map_pointer{CurrentFile - Cache.PkgFileP}; // Link it to the end of the list map_pointer *Last = &Desc->FileList; @@ -920,7 +920,7 @@ bool pkgCacheGenerator::NewFileDesc(pkgCache::DescIterator &Desc, Last = &D->NextFile; DF->NextFile = *Last; - *Last = DF.Index(); + *Last = DF.MapPointer(); DF->Offset = List.Offset(); DF->Size = List.Size(); @@ -971,7 +971,7 @@ map_pointer pkgCacheGenerator::NewDescription(pkgCache::D version and to the package that it is pointing to. */ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, - map_pointer const Version, + map_stringitem_t const Version, uint8_t const Op, uint8_t const Type, map_pointer * &OldDepLast) @@ -1011,7 +1011,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, } pkgCache::Dependency * Link = Cache.DepP + Dependency; - Link->ParentVer = Ver.Index(); + Link->ParentVer = Ver.MapPointer(); Link->DependencyData = DependencyData; Link->ID = Cache.HeaderP->DependsCount++; @@ -1021,7 +1021,7 @@ bool pkgCacheGenerator::NewDepends(pkgCache::PkgIterator &Pkg, Dep->Type = Type; Dep->CompareOp = Op; Dep->Version = Version; - Dep->Package = Pkg.Index(); + Dep->Package = Pkg.MapPointer(); ++Cache.HeaderP->DependsDataCount; if (PreviousData != 0) { @@ -1184,16 +1184,16 @@ bool pkgCacheGenerator::NewProvides(pkgCache::VerIterator &Ver, // Fill it in pkgCache::PrvIterator Prv(Cache,Cache.ProvideP + Provides,Cache.PkgP); - Prv->Version = Ver.Index(); + Prv->Version = Ver.MapPointer(); Prv->ProvideVersion = ProvideVersion; Prv->Flags = Flags; Prv->NextPkgProv = Ver->ProvidesList; - Ver->ProvidesList = Prv.Index(); + Ver->ProvidesList = Prv.MapPointer(); // Link it to the package - Prv->ParentPkg = Pkg.Index(); + Prv->ParentPkg = Pkg.MapPointer(); Prv->NextProvides = Pkg->ProvidesList; - Pkg->ProvidesList = Prv.Index(); + Pkg->ProvidesList = Prv.MapPointer(); return true; } /*}}}*/ @@ -1267,7 +1267,7 @@ bool pkgCacheGenerator::SelectReleaseFile(const string &File,const string &Site, CurrentRlsFile->Flags = Flags; CurrentRlsFile->ID = Cache.HeaderP->ReleaseFileCount; RlsFileName = File; - Cache.HeaderP->RlsFileList = CurrentRlsFile - Cache.RlsFileP; + Cache.HeaderP->RlsFileList = map_pointer{CurrentRlsFile - Cache.RlsFileP}; Cache.HeaderP->ReleaseFileCount++; return true; @@ -1316,11 +1316,11 @@ bool pkgCacheGenerator::SelectFile(std::string const &File, CurrentFile->Component = component; CurrentFile->Flags = Flags; if (CurrentRlsFile != nullptr) - CurrentFile->Release = CurrentRlsFile - Cache.RlsFileP; + CurrentFile->Release = map_pointer{CurrentRlsFile - Cache.RlsFileP}; else CurrentFile->Release = 0; PkgFileName = File; - Cache.HeaderP->FileList = CurrentFile - Cache.PkgFileP; + Cache.HeaderP->FileList = map_pointer{CurrentFile - Cache.PkgFileP}; Cache.HeaderP->PackageFileCount++; if (Progress != 0) @@ -1362,6 +1362,7 @@ public: ScopedErrorRevert() { _error->PushToStack(); } ~ScopedErrorRevert() { _error->RevertToStack(); } }; + static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName, pkgSourceList &List, FileIterator const Start, @@ -1632,7 +1633,7 @@ static bool loadBackMMapFromFile(std::unique_ptr &Gen, if (CacheF.IsOpen() == false || CacheF.Seek(0) == false || CacheF.Failed()) return false; _error->PushToStack(); - map_pointer const alloc = Map->RawAllocate(CacheF.Size()); + uint32_t const alloc = Map->RawAllocate(CacheF.Size()); bool const newError = _error->PendingError(); _error->MergeWithStack(); if (alloc == 0 && newError) diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index c042625c4..f5b4c80b3 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -118,7 +118,7 @@ class APT_HIDDEN pkgCacheGenerator /*{{{*/ bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, - map_pointer const Version, uint8_t const Op, + map_stringitem_t const Version, uint8_t const Op, uint8_t const Type, map_pointer* &OldDepLast); bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg, map_stringitem_t const ProvidesVersion, uint8_t const Flags); diff --git a/apt-private/private-cachefile.cc b/apt-private/private-cachefile.cc index 4becc147e..9d875b4a7 100644 --- a/apt-private/private-cachefile.cc +++ b/apt-private/private-cachefile.cc @@ -22,7 +22,7 @@ using namespace std; static bool SortPackagesByName(pkgCache * const Owner, - map_pointer const A, map_pointer const B) + map_pointer const A, map_pointer const B) { if (A == 0) return false; diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 2d6c1a91e..23ab7e47f 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -467,7 +467,7 @@ static bool DumpAvail(CommandLine &) char *Buffer = new char[Cache->HeaderP->MaxVerFileSize+10]; for (pkgCache::VerFile **J = VFList; *J != 0;) { - pkgCache::PkgFileIterator File(*Cache,(*J)->File + Cache->PkgFileP); + pkgCache::PkgFileIterator File(*Cache, Cache->PkgFileP + (*J)->File); // FIXME: Add support for volatile/with-source files FileFd PkgF(File.FileName(),FileFd::ReadOnly, FileFd::Extension); if (_error->PendingError() == true) @@ -481,7 +481,7 @@ static bool DumpAvail(CommandLine &) unsigned long Pos = 0; for (; *J != 0; J++) { - if ((*J)->File + Cache->PkgFileP != File) + if (Cache->PkgFileP + (*J)->File != File) break; const pkgCache::VerFile &VF = **J; -- cgit v1.2.3-70-g09d2 From d8c6ea90784ecb4dabbf8c2cb7b631add50ae177 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 25 Feb 2020 11:44:16 +0100 Subject: Add d-pointers to groups, packages, versions, and files This allows us to extend those in-cache objects with more data later on without breaking the ABI. Reserve 12 pointers for private data in the pkgCache class, and double the size of pools to 24. --- apt-pkg/pkgcache.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'apt-pkg/pkgcache.h') diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index ef22a78a0..f68736ddc 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -230,6 +230,7 @@ class pkgCache /*{{{*/ Dependency *DepP; DependencyData *DepDataP; char *StrP; + void *reserved[12]; virtual bool ReMap(bool const &Errorchecks = true); inline bool Sync() {return Map.Sync();} @@ -365,10 +366,10 @@ struct pkgCache::Header Start indicates the first byte of the pool, Count is the number of objects remaining in the pool and ItemSize is the structure size (alignment factor) of the pool. An ItemSize of 0 indicates the pool is empty. There should be - the same number of pools as there are structure types. The generator + twice the number of pools as there are non-private structure types. The generator stores this information so future additions can make use of any unused pool blocks. */ - DynamicMMap::Pool Pools[12]; + DynamicMMap::Pool Pools[2 * 12]; /** \brief hash tables providing rapid group/package name lookup @@ -425,6 +426,8 @@ struct pkgCache::Group /** \brief List of binary produces by source package with this name. */ map_pointer VersionsInSource; + /** \brief Private pointer */ + map_pointer d; }; /*}}}*/ // Package structure /*{{{*/ @@ -487,6 +490,9 @@ struct pkgCache::Package map_id_t ID; /** \brief some useful indicators of the package's state */ map_flags_t Flags; + + /** \brief Private pointer */ + map_pointer d; }; /*}}}*/ // Release File structure /*{{{*/ @@ -527,6 +533,9 @@ struct pkgCache::ReleaseFile map_pointer NextFile; /** \brief unique sequel ID */ map_fileid_t ID; + + /** \brief Private pointer */ + map_pointer d; }; /*}}}*/ // Package File structure /*{{{*/ @@ -566,6 +575,9 @@ struct pkgCache::PackageFile map_pointer NextFile; /** \brief unique sequel ID */ map_fileid_t ID; + + /** \brief Private pointer */ + map_pointer d; }; /*}}}*/ // VerFile structure /*{{{*/ @@ -670,6 +682,9 @@ struct pkgCache::Version map_number_t Priority; /** \brief next version in the source package (might be different binary) */ map_pointer NextInSource; + + /** \brief Private pointer */ + map_pointer d; }; /*}}}*/ // Description structure /*{{{*/ -- cgit v1.2.3-70-g09d2