Explorar o código

Deprecate SPtrArray<T> and convert everyone to unique_ptr<T[]>

More standardization
Julian Andres Klode %!s(int64=11) %!d(string=hai) anos
pai
achega
98cc7fd2c1

+ 12 - 12
apt-pkg/algorithms.cc

@@ -476,8 +476,8 @@ void pkgProblemResolver::MakeScores()
    }
    }
 
 
    // Copy the scores to advoid additive looping
    // Copy the scores to advoid additive looping
-   SPtrArray<int> OldScores = new int[Size];
-   memcpy(OldScores,Scores,sizeof(*Scores)*Size);
+   std::unique_ptr<int[]> OldScores(new int[Size]);
+   memcpy(OldScores.get(),Scores,sizeof(*Scores)*Size);
       
       
    /* Now we cause 1 level of dependency inheritance, that is we add the 
    /* Now we cause 1 level of dependency inheritance, that is we add the 
       score of the packages that depend on the target Package. This 
       score of the packages that depend on the target Package. This 
@@ -702,17 +702,17 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
       operates from highest score to lowest. This prevents problems when
       operates from highest score to lowest. This prevents problems when
       high score packages cause the removal of lower score packages that
       high score packages cause the removal of lower score packages that
       would cause the removal of even lower score packages. */
       would cause the removal of even lower score packages. */
-   SPtrArray<pkgCache::Package *> PList = new pkgCache::Package *[Size];
-   pkgCache::Package **PEnd = PList;
+   std::unique_ptr<pkgCache::Package *[]> PList(new pkgCache::Package *[Size]);
+   pkgCache::Package **PEnd = PList.get();
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
    for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
       *PEnd++ = I;
       *PEnd++ = I;
    This = this;
    This = this;
-   qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
+   qsort(PList.get(),PEnd - PList.get(),sizeof(PList[0]),&ScoreSort);
 
 
    if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true)
    if (_config->FindB("Debug::pkgProblemResolver::ShowScores",false) == true)
    {
    {
       clog << "Show Scores" << endl;
       clog << "Show Scores" << endl;
-      for (pkgCache::Package **K = PList; K != PEnd; K++)
+      for (pkgCache::Package **K = PList.get(); K != PEnd; K++)
          if (Scores[(*K)->ID] != 0)
          if (Scores[(*K)->ID] != 0)
          {
          {
            pkgCache::PkgIterator Pkg(Cache,*K);
            pkgCache::PkgIterator Pkg(Cache,*K);
@@ -734,7 +734,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
    for (int Counter = 0; Counter != 10 && Change == true; Counter++)
    for (int Counter = 0; Counter != 10 && Change == true; Counter++)
    {
    {
       Change = false;
       Change = false;
-      for (pkgCache::Package **K = PList; K != PEnd; K++)
+      for (pkgCache::Package **K = PList.get(); K != PEnd; K++)
       {
       {
 	 pkgCache::PkgIterator I(Cache,*K);
 	 pkgCache::PkgIterator I(Cache,*K);
 
 
@@ -845,8 +845,8 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
 	    /* Look across the version list. If there are no possible
 	    /* Look across the version list. If there are no possible
 	       targets then we keep the package and bail. This is necessary
 	       targets then we keep the package and bail. This is necessary
 	       if a package has a dep on another package that can't be found */
 	       if a package has a dep on another package that can't be found */
-	    SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
-	    if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
+	    std::unique_ptr<pkgCache::Version *[]> VList(Start.AllTargets());
+	    if (VList[0] == 0 && (Flags[I->ID] & Protected) != Protected &&
 		Start.IsNegative() == false &&
 		Start.IsNegative() == false &&
 		Cache[I].NowBroken() == false)
 		Cache[I].NowBroken() == false)
 	    {	       
 	    {	       
@@ -863,7 +863,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
 	    }
 	    }
 	    
 	    
 	    bool Done = false;
 	    bool Done = false;
-	    for (pkgCache::Version **V = VList; *V != 0; V++)
+	    for (pkgCache::Version **V = VList.get(); *V != 0; V++)
 	    {
 	    {
 	       pkgCache::VerIterator Ver(Cache,*V);
 	       pkgCache::VerIterator Ver(Cache,*V);
 	       pkgCache::PkgIterator Pkg = Ver.ParentPkg();
 	       pkgCache::PkgIterator Pkg = Ver.ParentPkg();
@@ -1233,8 +1233,8 @@ bool pkgProblemResolver::ResolveByKeepInternal()
 	       clog << "Package " << I.FullName(false) << " " << Start << endl;
 	       clog << "Package " << I.FullName(false) << " " << Start << endl;
 
 
 	    // Look at all the possible provides on this package
 	    // Look at all the possible provides on this package
-	    SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
-	    for (pkgCache::Version **V = VList; *V != 0; V++)
+	    std::unique_ptr<pkgCache::Version *[]> VList(Start.AllTargets());
+	    for (pkgCache::Version **V = VList.get(); *V != 0; V++)
 	    {
 	    {
 	       pkgCache::VerIterator Ver(Cache,*V);
 	       pkgCache::VerIterator Ver(Cache,*V);
 	       pkgCache::PkgIterator Pkg = Ver.ParentPkg();
 	       pkgCache::PkgIterator Pkg = Ver.ParentPkg();

+ 4 - 3
apt-pkg/contrib/fileutl.cc

@@ -52,6 +52,7 @@
 
 
 #include <set>
 #include <set>
 #include <algorithm>
 #include <algorithm>
+#include <memory>
 
 
 #ifdef HAVE_ZLIB
 #ifdef HAVE_ZLIB
 	#include <zlib.h>
 	#include <zlib.h>
@@ -159,7 +160,7 @@ bool CopyFile(FileFd &From,FileFd &To)
       return false;
       return false;
    
    
    // Buffered copy between fds
    // Buffered copy between fds
-   SPtrArray<unsigned char> Buf = new unsigned char[64000];
+   std::unique_ptr<unsigned char[]> Buf(new unsigned char[64000]);
    unsigned long long Size = From.Size();
    unsigned long long Size = From.Size();
    while (Size != 0)
    while (Size != 0)
    {
    {
@@ -167,8 +168,8 @@ bool CopyFile(FileFd &From,FileFd &To)
       if (Size > 64000)
       if (Size > 64000)
 	 ToRead = 64000;
 	 ToRead = 64000;
       
       
-      if (From.Read(Buf,ToRead) == false || 
-	  To.Write(Buf,ToRead) == false)
+      if (From.Read(Buf.get(),ToRead) == false ||
+	  To.Write(Buf.get(),ToRead) == false)
 	 return false;
 	 return false;
       
       
       Size -= ToRead;
       Size -= ToRead;

+ 1 - 1
apt-pkg/contrib/sptr.h

@@ -43,7 +43,7 @@ class APT_DEPRECATED SPtr
 };
 };
 
 
 template <class T>
 template <class T>
-class SPtrArray
+class APT_DEPRECATED SPtrArray
 {
 {
    public:
    public:
    T *Ptr;
    T *Ptr;

+ 2 - 2
apt-pkg/depcache.cc

@@ -1281,9 +1281,9 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst,
 	 Otherwise we remove the offender if needed */
 	 Otherwise we remove the offender if needed */
       else if (Start.IsNegative() == true && Start->Type != pkgCache::Dep::Obsoletes)
       else if (Start.IsNegative() == true && Start->Type != pkgCache::Dep::Obsoletes)
       {
       {
-	 SPtrArray<Version *> List = Start.AllTargets();
+	 std::unique_ptr<Version *[]> List(Start.AllTargets());
 	 pkgCache::PkgIterator TrgPkg = Start.TargetPkg();
 	 pkgCache::PkgIterator TrgPkg = Start.TargetPkg();
-	 for (Version **I = List; *I != 0; I++)
+	 for (Version **I = List.get(); *I != 0; I++)
 	 {
 	 {
 	    VerIterator Ver(*this,*I);
 	    VerIterator Ver(*this,*I);
 	    PkgIterator Pkg = Ver.ParentPkg();
 	    PkgIterator Pkg = Ver.ParentPkg();

+ 11 - 11
apt-pkg/orderlist.cc

@@ -142,9 +142,9 @@ bool pkgOrderList::DoRun()
 {   
 {   
    // Temp list
    // Temp list
    unsigned long Size = Cache.Head().PackageCount;
    unsigned long Size = Cache.Head().PackageCount;
-   SPtrArray<Package *> NList = new Package *[Size];
-   SPtrArray<Package *> AfterList = new Package *[Size];
-   AfterEnd = AfterList;
+   std::unique_ptr<Package *[]> NList(new Package *[Size]);
+   std::unique_ptr<Package *[]> AfterList(new Package *[Size]);
+   AfterEnd = AfterList.get();
    
    
    Depth = 0;
    Depth = 0;
    WipeFlags(Added | AddPending | Loop | InList);
    WipeFlags(Added | AddPending | Loop | InList);
@@ -154,7 +154,7 @@ bool pkgOrderList::DoRun()
 
 
    // Rebuild the main list into the temp list.
    // Rebuild the main list into the temp list.
    iterator OldEnd = End;
    iterator OldEnd = End;
-   End = NList;
+   End = NList.get();
    for (iterator I = List; I != OldEnd; ++I)
    for (iterator I = List; I != OldEnd; ++I)
       if (VisitNode(PkgIterator(Cache,*I), "DoRun") == false)
       if (VisitNode(PkgIterator(Cache,*I), "DoRun") == false)
       {
       {
@@ -163,12 +163,12 @@ bool pkgOrderList::DoRun()
       }
       }
    
    
    // Copy the after list to the end of the main list
    // 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;
       *End++ = *I;
    
    
    // Swap the main list to the new list
    // Swap the main list to the new list
    delete [] List;
    delete [] List;
-   List = NList.UnGuard();
+   List = NList.release();
    return true;
    return true;
 }
 }
 									/*}}}*/
 									/*}}}*/
@@ -512,8 +512,8 @@ bool pkgOrderList::VisitRProvides(DepFunc F,VerIterator Ver)
    against it! */
    against it! */
 bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
 bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
 {
 {
-   SPtrArray<Version *> List = D.AllTargets();
-   for (Version **I = List; *I != 0; ++I)
+   std::unique_ptr<Version *[]> List(D.AllTargets());
+   for (Version **I = List.get(); *I != 0; ++I)
    {
    {
       VerIterator Ver(Cache,*I);
       VerIterator Ver(Cache,*I);
       PkgIterator Pkg = Ver.ParentPkg();
       PkgIterator Pkg = Ver.ParentPkg();
@@ -541,7 +541,7 @@ bool pkgOrderList::VisitProvides(DepIterator D,bool Critical)
    }
    }
    if (D.IsNegative() == false)
    if (D.IsNegative() == false)
       return true;
       return true;
-   for (Version **I = List; *I != 0; ++I)
+   for (Version **I = List.get(); *I != 0; ++I)
    {
    {
       VerIterator Ver(Cache,*I);
       VerIterator Ver(Cache,*I);
       PkgIterator Pkg = Ver.ParentPkg();
       PkgIterator Pkg = Ver.ParentPkg();
@@ -1075,9 +1075,9 @@ void pkgOrderList::WipeFlags(unsigned long F)
    this fails to produce a suitable result. */
    this fails to produce a suitable result. */
 bool pkgOrderList::CheckDep(DepIterator D)
 bool pkgOrderList::CheckDep(DepIterator D)
 {
 {
-   SPtrArray<Version *> List = D.AllTargets();
+   std::unique_ptr<Version *[]> List(D.AllTargets());
    bool Hit = false;
    bool Hit = false;
-   for (Version **I = List; *I != 0; I++)
+   for (Version **I = List.get(); *I != 0; I++)
    {
    {
       VerIterator Ver(Cache,*I);
       VerIterator Ver(Cache,*I);
       PkgIterator Pkg = Ver.ParentPkg();
       PkgIterator Pkg = Ver.ParentPkg();

+ 12 - 12
apt-pkg/packagemanager.cc

@@ -390,9 +390,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
          // to do anything at all
          // to do anything at all
 	 for (DepIterator Cur = Start; true; ++Cur)
 	 for (DepIterator Cur = Start; true; ++Cur)
 	 {
 	 {
-	    SPtrArray<Version *> VList = Cur.AllTargets();
+	    std::unique_ptr<Version *> VList(Cur.AllTargets());
 
 
-	    for (Version **I = VList; *I != 0; ++I)
+	    for (Version **I = VList.get(); *I != 0; ++I)
 	    {
 	    {
 	       VerIterator Ver(Cache,*I);
 	       VerIterator Ver(Cache,*I);
 	       PkgIterator DepPkg = Ver.ParentPkg();
 	       PkgIterator DepPkg = Ver.ParentPkg();
@@ -440,9 +440,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
          // probably due to loops.
          // probably due to loops.
 	 for (DepIterator Cur = Start; true; ++Cur)
 	 for (DepIterator Cur = Start; true; ++Cur)
 	 {
 	 {
-	    SPtrArray<Version *> VList = Cur.AllTargets();
+	    std::unique_ptr<Version *> VList(Cur.AllTargets());
 
 
-	    for (Version **I = VList; *I != 0; ++I)
+	    for (Version **I = VList.get(); *I != 0; ++I)
 	    {
 	    {
 	       VerIterator Ver(Cache,*I);
 	       VerIterator Ver(Cache,*I);
 	       PkgIterator DepPkg = Ver.ParentPkg();
 	       PkgIterator DepPkg = Ver.ParentPkg();
@@ -515,9 +515,9 @@ bool pkgPackageManager::SmartConfigure(PkgIterator Pkg, int const Depth)
 	 // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
 	 // Search for dependencies which are unpacked but aren't configured yet (maybe loops)
 	 for (DepIterator Cur = Start; true; ++Cur)
 	 for (DepIterator Cur = Start; true; ++Cur)
 	 {
 	 {
-	    SPtrArray<Version *> VList = Cur.AllTargets();
+	    std::unique_ptr<Version *> VList(Cur.AllTargets());
 
 
-	    for (Version **I = VList; *I != 0; ++I)
+	    for (Version **I = VList.get(); *I != 0; ++I)
 	    {
 	    {
 	       VerIterator Ver(Cache,*I);
 	       VerIterator Ver(Cache,*I);
 	       PkgIterator DepPkg = Ver.ParentPkg();
 	       PkgIterator DepPkg = Ver.ParentPkg();
@@ -726,8 +726,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
 	    // Look for easy targets: packages that are already okay
 	    // Look for easy targets: packages that are already okay
 	    for (DepIterator Cur = Start; Bad == true; ++Cur)
 	    for (DepIterator Cur = Start; Bad == true; ++Cur)
 	    {
 	    {
-	       SPtrArray<Version *> VList = Cur.AllTargets();
-	       for (Version **I = VList; *I != 0; ++I)
+	       std::unique_ptr<Version *> VList(Cur.AllTargets());
+	       for (Version **I = VList.get(); *I != 0; ++I)
 	       {
 	       {
 		  VerIterator Ver(Cache,*I);
 		  VerIterator Ver(Cache,*I);
 		  PkgIterator Pkg = Ver.ParentPkg();
 		  PkgIterator Pkg = Ver.ParentPkg();
@@ -750,8 +750,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
 	    // Look for something that could be configured.
 	    // Look for something that could be configured.
 	    for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
 	    for (DepIterator Cur = Start; Bad == true && Cur.end() == false; ++Cur)
 	    {
 	    {
-	       SPtrArray<Version *> VList = Cur.AllTargets();
-	       for (Version **I = VList; *I != 0; ++I)
+	       std::unique_ptr<Version *[]> VList(Cur.AllTargets());
+	       for (Version **I = VList.get(); *I != 0; ++I)
 	       {
 	       {
 		  VerIterator Ver(Cache,*I);
 		  VerIterator Ver(Cache,*I);
 		  PkgIterator DepPkg = Ver.ParentPkg();
 		  PkgIterator DepPkg = Ver.ParentPkg();
@@ -806,8 +806,8 @@ bool pkgPackageManager::SmartUnPack(PkgIterator Pkg, bool const Immediate, int c
 		  End->Type == pkgCache::Dep::Obsoletes ||
 		  End->Type == pkgCache::Dep::Obsoletes ||
 		  End->Type == pkgCache::Dep::DpkgBreaks)
 		  End->Type == pkgCache::Dep::DpkgBreaks)
 	 {
 	 {
-	    SPtrArray<Version *> VList = End.AllTargets();
-	    for (Version **I = VList; *I != 0; ++I)
+	    std::unique_ptr<Version *[]> VList(End.AllTargets());
+	    for (Version **I = VList.get(); *I != 0; ++I)
 	    {
 	    {
 	       VerIterator Ver(Cache,*I);
 	       VerIterator Ver(Cache,*I);
 	       PkgIterator ConflictPkg = Ver.ParentPkg();
 	       PkgIterator ConflictPkg = Ver.ParentPkg();

+ 4 - 4
apt-pkg/pkgcachegen.cc

@@ -1260,8 +1260,8 @@ static bool CheckValidity(const string &CacheFile,
       return false;
       return false;
    }
    }
 
 
-   SPtrArray<bool> RlsVisited = new bool[Cache.HeaderP->ReleaseFileCount];
-   memset(RlsVisited,0,sizeof(*RlsVisited)*Cache.HeaderP->ReleaseFileCount);
+   std::unique_ptr<bool[]> RlsVisited(new bool[Cache.HeaderP->ReleaseFileCount]);
+   memset(RlsVisited.get(),0,sizeof(RlsVisited[0])*Cache.HeaderP->ReleaseFileCount);
    std::vector<pkgIndexFile *> Files;
    std::vector<pkgIndexFile *> Files;
    for (pkgSourceList::const_iterator i = List.begin(); i != List.end(); ++i)
    for (pkgSourceList::const_iterator i = List.begin(); i != List.end(); ++i)
    {
    {
@@ -1295,8 +1295,8 @@ static bool CheckValidity(const string &CacheFile,
 
 
    /* Now we check every index file, see if it is in the cache,
    /* Now we check every index file, see if it is in the cache,
       verify the IMS data and check that it is on the disk too.. */
       verify the IMS data and check that it is on the disk too.. */
-   SPtrArray<bool> Visited = new bool[Cache.HeaderP->PackageFileCount];
-   memset(Visited,0,sizeof(*Visited)*Cache.HeaderP->PackageFileCount);
+   std::unique_ptr<bool[]> Visited(new bool[Cache.HeaderP->PackageFileCount]);
+   memset(Visited.get(),0,sizeof(Visited[0])*Cache.HeaderP->PackageFileCount);
    for (std::vector<pkgIndexFile *>::const_reverse_iterator PkgFile = Files.rbegin(); PkgFile != Files.rend(); ++PkgFile)
    for (std::vector<pkgIndexFile *>::const_reverse_iterator PkgFile = Files.rbegin(); PkgFile != Files.rend(); ++PkgFile)
    {
    {
       if (Debug == true)
       if (Debug == true)

+ 2 - 2
apt-pkg/policy.cc

@@ -100,8 +100,8 @@ bool pkgPolicy::InitDefaults()
    }
    }
 
 
    // Apply the defaults..
    // Apply the defaults..
-   SPtrArray<bool> Fixed = new bool[Cache->HeaderP->PackageFileCount];
-   memset(Fixed,0,sizeof(*Fixed)*Cache->HeaderP->PackageFileCount);
+   std::unique_ptr<bool[]> Fixed(new bool[Cache->HeaderP->PackageFileCount]);
+   memset(Fixed.get(),0,sizeof(Fixed[0])*Cache->HeaderP->PackageFileCount);
    StatusOverride = false;
    StatusOverride = false;
    for (vector<Pin>::const_iterator I = Defaults.begin(); I != Defaults.end(); ++I)
    for (vector<Pin>::const_iterator I = Defaults.begin(); I != Defaults.end(); ++I)
    {
    {

+ 3 - 3
cmdline/apt-cache.cc

@@ -749,9 +749,9 @@ static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
 	      }
 	      }
 	    
 	    
 	    // Display all solutions
 	    // Display all solutions
-	    SPtrArray<pkgCache::Version *> List = D.AllTargets();
-	    pkgPrioSortList(*Cache,List);
-	    for (pkgCache::Version **I = List; *I != 0; I++)
+	    std::unique_ptr<pkgCache::Version *[]> List(D.AllTargets());
+	    pkgPrioSortList(*Cache,List.get());
+	    for (pkgCache::Version **I = List.get(); *I != 0; I++)
 	    {
 	    {
 	       pkgCache::VerIterator V(*Cache,*I);
 	       pkgCache::VerIterator V(*Cache,*I);
 	       if (V != Cache->VerP + V.ParentPkg()->VersionList ||
 	       if (V != Cache->VerP + V.ParentPkg()->VersionList ||

+ 1 - 1
cmdline/apt-get.cc

@@ -701,7 +701,7 @@ static bool DoSource(CommandLine &CmdL)
    AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
    AcqTextStatus Stat(std::cout, ScreenWidth,_config->FindI("quiet",0));
    pkgAcquire Fetcher(&Stat);
    pkgAcquire Fetcher(&Stat);
 
 
-   SPtrArray<DscFile> Dsc = new DscFile[CmdL.FileSize()];
+   std::unique_ptr<DscFile[]> Dsc(new DscFile[CmdL.FileSize()]);
    
    
    // insert all downloaded uris into this set to avoid downloading them
    // insert all downloaded uris into this set to avoid downloading them
    // twice
    // twice