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/cacheiterators.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'apt-pkg/cacheiterators.h') diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index ff2b65cdf..7f853558b 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -321,15 +321,15 @@ class pkgCache::DepIterator : public Iterator { struct DependencyProxy { map_stringitem_t &Version; - map_pointer_t &Package; + map_pointer &Package; map_id_t &ID; unsigned char &Type; unsigned char &CompareOp; - map_pointer_t &ParentVer; - map_pointer_t &DependencyData; - map_pointer_t &NextRevDepends; - map_pointer_t &NextDepends; - map_pointer_t &NextData; + map_pointer &ParentVer; + map_pointer &DependencyData; + map_pointer &NextRevDepends; + map_pointer &NextDepends; + map_pointer &NextData; DependencyProxy const * operator->() const { return this; } DependencyProxy * operator->() { return this; } }; -- cgit v1.2.3 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 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'apt-pkg/cacheiterators.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) {} -- cgit v1.2.3