From 7d70f7993e2e6e465ac216bc21ec15ed7b7d9ff5 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 23 Oct 2015 17:28:27 +0200 Subject: [PATCH] orderlist: Replace qsort() by thread-safe std::sort() Gbp-Dch: ignore --- apt-pkg/orderlist.cc | 39 +++++++++++++++++------------------- apt-pkg/orderlist.h | 5 ++--- debian/libapt-pkg5.0.symbols | 1 - 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index d1118e319..a61c2b06a 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -74,13 +74,12 @@ #include #include +#include #include /*}}}*/ using namespace std; -pkgOrderList *pkgOrderList::Me = 0; - // OrderList::pkgOrderList - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -186,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; @@ -239,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; @@ -382,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; }*/ @@ -408,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; @@ -424,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) @@ -437,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) @@ -445,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; diff --git a/apt-pkg/orderlist.h b/apt-pkg/orderlist.h index 7b35b2955..80876e3f9 100644 --- a/apt-pkg/orderlist.h +++ b/apt-pkg/orderlist.h @@ -69,9 +69,8 @@ class pkgOrderList : protected pkgCache::Namespace bool DoRun(); // For pre sorting - static pkgOrderList *Me; - static int OrderCompareA(const void *a, const void *b) APT_PURE; - static int OrderCompareB(const void *a, const void *b) APT_PURE; + int OrderCompareA(Package *a, Package *b) APT_PURE; + int OrderCompareB(Package *a, Package *b) APT_PURE; int FileCmp(PkgIterator A,PkgIterator B) APT_PURE; public: diff --git a/debian/libapt-pkg5.0.symbols b/debian/libapt-pkg5.0.symbols index 5ff1fa2cd..d2d54f925 100644 --- a/debian/libapt-pkg5.0.symbols +++ b/debian/libapt-pkg5.0.symbols @@ -274,7 +274,6 @@ libapt-pkg.so.5.0 libapt-pkg5.0 #MINVER# (c++)"pkgOrderList::VisitProvides(pkgCache::DepIterator, bool)@APTPKG_5.0" 0.8.0 (c++)"pkgOrderList::OrderConfigure()@APTPKG_5.0" 0.8.0 (c++)"pkgOrderList::VisitRProvides(bool (pkgOrderList::*)(pkgCache::DepIterator), pkgCache::VerIterator)@APTPKG_5.0" 0.8.0 - (c++)"pkgOrderList::Me@APTPKG_5.0" 0.8.0 (c++)"pkgOrderList::DoRun()@APTPKG_5.0" 0.8.0 (c++)"pkgOrderList::Score(pkgCache::PkgIterator)@APTPKG_5.0" 0.8.0 (c++)"pkgOrderList::AddLoop(pkgCache::DepIterator)@APTPKG_5.0" 0.8.0 -- 2.45.2