X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/f39daeb1f66b8910f91274055bf07c3d008cdc50..d4cfc24887851fa55f93a1a3c09f662b80f97729:/apt-pkg/orderlist.cc diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index 984ae1d10..bfdc50e6c 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -68,21 +68,22 @@ #include #include #include -#include -#include #include +#include +#include +#include +#include +#include #include /*}}}*/ using namespace std; -pkgOrderList *pkgOrderList::Me = 0; - // OrderList::pkgOrderList - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgOrderList::pkgOrderList(pkgDepCache *pCache) : Cache(*pCache), +pkgOrderList::pkgOrderList(pkgDepCache *pCache) : d(NULL), Cache(*pCache), Primary(NULL), Secondary(NULL), RevDepends(NULL), Remove(NULL), AfterEnd(NULL), FileList(NULL), @@ -138,9 +139,9 @@ bool pkgOrderList::DoRun() { // Temp list unsigned long Size = Cache.Head().PackageCount; - SPtrArray NList = new Package *[Size]; - SPtrArray AfterList = new Package *[Size]; - AfterEnd = AfterList; + std::unique_ptr NList(new Package *[Size]); + std::unique_ptr AfterList(new Package *[Size]); + AfterEnd = AfterList.get(); Depth = 0; WipeFlags(Added | AddPending | Loop | InList); @@ -150,7 +151,7 @@ bool pkgOrderList::DoRun() // Rebuild the main list into the temp list. iterator OldEnd = End; - End = NList; + End = NList.get(); for (iterator I = List; I != OldEnd; ++I) if (VisitNode(PkgIterator(Cache,*I), "DoRun") == false) { @@ -159,12 +160,12 @@ bool pkgOrderList::DoRun() } // Copy the after list to the end of the main list - for (Package **I = AfterList; I != AfterEnd; I++) + for (Package **I = AfterList.get(); I != AfterEnd; I++) *End++ = *I; // Swap the main list to the new list delete [] List; - List = NList.UnGuard(); + List = NList.release(); return true; } /*}}}*/ @@ -184,8 +185,7 @@ bool pkgOrderList::OrderCritical() LoopCount = 0; // Sort - Me = this; - qsort(List,End - List,sizeof(*List),&OrderCompareB); + std::sort(List,End, [this](Package *a, Package *b) { return OrderCompareB(a, b) < 0; } ); if (DoRun() == false) return false; @@ -237,8 +237,7 @@ bool pkgOrderList::OrderUnpack(string *FileList) LoopCount = -1; // Sort - Me = this; - qsort(List,End - List,sizeof(*List),&OrderCompareA); + std::sort(List,End, [this](Package *a, Package *b) { return OrderCompareA(a, b) < 0; }); if (Debug == true) clog << "** Pass A" << endl; @@ -255,7 +254,7 @@ bool pkgOrderList::OrderUnpack(string *FileList) clog << "** Pass C" << endl; LoopCount = 0; RevDepends = 0; - Remove = 0; // Otherwise the libreadline remove problem occures + Remove = 0; // Otherwise the libreadline remove problem occurs if (DoRun() == false) return false; @@ -329,7 +328,7 @@ int pkgOrderList::Score(PkgIterator Pkg) break; } - // Important Required Standard Optional Extra + // Required Important Standard Optional Extra if (Cache[Pkg].InstVerIter(Cache)->Priority <= 5) { signed short PrioMap[] = {0,5,4,3,1,0}; @@ -380,21 +379,21 @@ static int BoolCompare(bool A,bool B) // --------------------------------------------------------------------- /* This provides a first-pass sort of the list and gives a decent starting point for further complete ordering. It is used by OrderUnpack only */ -int pkgOrderList::OrderCompareA(const void *a, const void *b) +int pkgOrderList::OrderCompareA(Package *a, Package *b) { - PkgIterator A(Me->Cache,*(Package **)a); - PkgIterator B(Me->Cache,*(Package **)b); + PkgIterator A(Cache,a); + PkgIterator B(Cache,b); // We order packages with a set state toward the front int Res; - if ((Res = BoolCompare(Me->IsNow(A),Me->IsNow(B))) != 0) + if ((Res = BoolCompare(IsNow(A),IsNow(B))) != 0) return -1*Res; // We order missing files to toward the end -/* if (Me->FileList != 0) +/* if (FileList != 0) { - if ((Res = BoolCompare(Me->IsMissing(A), - Me->IsMissing(B))) != 0) + if ((Res = BoolCompare(IsMissing(A), + IsMissing(B))) != 0) return Res; }*/ @@ -406,8 +405,8 @@ int pkgOrderList::OrderCompareA(const void *a, const void *b) B.State() != pkgCache::PkgIterator::NeedsNothing) return 1; - int ScoreA = Me->Score(A); - int ScoreB = Me->Score(B); + int ScoreA = Score(A); + int ScoreB = Score(B); if (ScoreA > ScoreB) return -1; @@ -422,10 +421,10 @@ int pkgOrderList::OrderCompareA(const void *a, const void *b) // --------------------------------------------------------------------- /* This orders by installation source. This is useful to handle inter-source breaks */ -int pkgOrderList::OrderCompareB(const void *a, const void *b) +int pkgOrderList::OrderCompareB(Package *a, Package *b) { - PkgIterator A(Me->Cache,*(Package **)a); - PkgIterator B(Me->Cache,*(Package **)b); + PkgIterator A(Cache,a); + PkgIterator B(Cache,b); if (A.State() != pkgCache::PkgIterator::NeedsNothing && B.State() == pkgCache::PkgIterator::NeedsNothing) @@ -435,7 +434,7 @@ int pkgOrderList::OrderCompareB(const void *a, const void *b) B.State() != pkgCache::PkgIterator::NeedsNothing) return 1; - int F = Me->FileCmp(A,B); + int F = FileCmp(A,B); if (F != 0) { if (F > 0) @@ -443,8 +442,8 @@ int pkgOrderList::OrderCompareB(const void *a, const void *b) return 1; } - int ScoreA = Me->Score(A); - int ScoreB = Me->Score(B); + int ScoreA = Score(A); + int ScoreB = Score(B); if (ScoreA > ScoreB) return -1; @@ -508,8 +507,8 @@ bool pkgOrderList::VisitRProvides(DepFunc F,VerIterator Ver) against it! */ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical) { - SPtrArray List = D.AllTargets(); - for (Version **I = List; *I != 0; ++I) + std::unique_ptr List(D.AllTargets()); + for (Version **I = List.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); @@ -537,7 +536,7 @@ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical) } if (D.IsNegative() == false) return true; - for (Version **I = List; *I != 0; ++I) + for (Version **I = List.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); @@ -566,10 +565,10 @@ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical) // --------------------------------------------------------------------- /* This is the core ordering routine. It calls the set dependency consideration functions which then potentialy call this again. Finite - depth is achived through the colouring mechinism. */ + depth is achieved through the colouring mechinism. */ bool pkgOrderList::VisitNode(PkgIterator Pkg, char const* from) { - // Looping or irrelevent. + // Looping or irrelevant. // This should probably trancend not installed packages if (Pkg.end() == true || IsFlag(Pkg,Added) == true || IsFlag(Pkg,AddPending) == true || IsFlag(Pkg,InList) == false) @@ -824,7 +823,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D) The forwards depends loop is designed to bring the packages dependents close to the package. This helps reduce deconfigure time. - Loops are irrelevent to this. */ + Loops are irrelevant to this. */ bool pkgOrderList::DepUnPackDep(DepIterator D) { @@ -840,7 +839,7 @@ bool pkgOrderList::DepUnPackDep(DepIterator D) D.ParentPkg().CurrentVer() != D.ParentVer()) continue; - // The dep will not break so it is irrelevent. + // The dep will not break so it is irrelevant. if (CheckDep(D) == true) continue; @@ -1071,9 +1070,9 @@ void pkgOrderList::WipeFlags(unsigned long F) this fails to produce a suitable result. */ bool pkgOrderList::CheckDep(DepIterator D) { - SPtrArray List = D.AllTargets(); + std::unique_ptr List(D.AllTargets()); bool Hit = false; - for (Version **I = List; *I != 0; I++) + for (Version **I = List.get(); *I != 0; I++) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg();