summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHerman Semenoff <GermanAizek@yandex.ru>2026-04-08 12:58:55 +0300
committerJulian Andres Klode <jak@debian.org>2026-04-08 10:41:43 +0000
commit23dba65f031954df896bc3c6dfb1a9705574886b (patch)
tree1f40f2afce10e3b793540e9905b624f113c2ee15
parentfbde7ea4ce304a30e155a2bd9d014d196abbb496 (diff)
apt: modernize to make_unique C++17
References: - https://stackoverflow.com/questions/79700634/pros-and-cons-of-make-unique-vs-direct-constructor-call-in-c17 - https://towardsdev.com/why-std-make-unique-beats-new-in-modern-c-7e2ba653737e - https://www.sololearn.com/en/Discuss/3334779/where-make_unique-is-better-than-unique_ptrraw-pointer
-rw-r--r--apt-pkg/acquire.cc2
-rw-r--r--apt-pkg/algorithms.cc6
-rw-r--r--apt-pkg/contrib/fileutl.cc2
-rw-r--r--apt-pkg/orderlist.cc4
-rw-r--r--apt-pkg/pkgcachegen.cc10
-rw-r--r--apt-pkg/policy.cc2
-rw-r--r--cmdline/apt-sortpkgs.cc2
-rw-r--r--methods/http.cc2
8 files changed, 15 insertions, 15 deletions
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index 7a60c4476..95b6391cd 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -636,7 +636,7 @@ static void CheckDropPrivsMustBeDisabled(pkgAcquire const &Fetcher)
gid_t const old_egid = getegid();
long const ngroups_max = sysconf(_SC_NGROUPS_MAX);
- std::unique_ptr<gid_t[]> old_gidlist(new gid_t[ngroups_max]);
+ auto old_gidlist = std::make_unique<gid_t[]>(ngroups_max);
if (unlikely(old_gidlist == NULL))
return;
ssize_t old_gidlist_nr;
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc
index a08ecd2c6..44f186a82 100644
--- a/apt-pkg/algorithms.cc
+++ b/apt-pkg/algorithms.cc
@@ -554,7 +554,7 @@ void pkgProblemResolver::MakeScores()
}
// Copy the scores to advoid additive looping
- std::unique_ptr<int[]> OldScores(new int[Size]);
+ auto OldScores = std::make_unique<int[]>(Size);
memcpy(&OldScores[0],&Scores[0],sizeof(Scores[0])*Size);
/* Now we cause 1 level of dependency inheritance, that is we add the
@@ -797,7 +797,7 @@ bool pkgProblemResolver::ResolveInternal(bool const BrokenFix)
operates from highest score to lowest. This prevents problems when
high score packages cause the removal of lower score packages that
would cause the removal of even lower score packages. */
- std::unique_ptr<pkgCache::Package *[]> PList(new pkgCache::Package *[Size]);
+ auto PList = std::make_unique<pkgCache::Package *[]>(Size);
pkgCache::Package **PEnd = &PList[0];
for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
*PEnd++ = I;
@@ -1291,7 +1291,7 @@ bool pkgProblemResolver::ResolveByKeepInternal()
high score packages cause the removal of lower score packages that
would cause the removal of even lower score packages. */
auto Size = Cache.Head().PackageCount;
- std::unique_ptr<pkgCache::Package *[]> PList{new pkgCache::Package *[Size]};
+ auto PList = std::make_unique<pkgCache::Package *[]>(Size);
pkgCache::Package **PEnd = &PList[0];
for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I)
*PEnd++ = I;
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 74f5ec8bc..832e87127 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -3346,7 +3346,7 @@ bool DropPrivileges() /*{{{*/
{
// Verify that the user isn't still in any supplementary groups
long const ngroups_max = sysconf(_SC_NGROUPS_MAX);
- std::unique_ptr<gid_t[]> gidlist(new gid_t[ngroups_max]);
+ auto gidlist = std::make_unique<gid_t[]>(ngroups_max);
if (unlikely(gidlist == NULL))
return _error->Error("Allocation of a list of size %lu for getgroups failed", ngroups_max);
ssize_t gidlist_nr;
diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc
index 33d17fcec..83d2f2fb4 100644
--- a/apt-pkg/orderlist.cc
+++ b/apt-pkg/orderlist.cc
@@ -137,8 +137,8 @@ bool pkgOrderList::DoRun()
{
// Temp list
unsigned long Size = Cache.Head().PackageCount;
- std::unique_ptr<Package *[]> NList(new Package *[Size]);
- std::unique_ptr<Package *[]> AfterList(new Package *[Size]);
+ auto NList = std::make_unique<Package *[]>(Size);
+ auto AfterList = std::make_unique<Package *[]>(Size);
AfterEnd = AfterList.get();
Depth = 0;
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 7bf635972..82b88d6b0 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -1502,10 +1502,10 @@ static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName,
}
// Map it
- std::unique_ptr<MMap> Map(new MMap(CacheFile,0));
+ auto Map = std::make_unique<MMap>(CacheFile,0);
if (unlikely(Map->validData()) == false)
return false;
- std::unique_ptr<pkgCache> CacheP(new pkgCache(Map.get()));
+ auto CacheP = std::make_unique<pkgCache>(Map.get());
pkgCache &Cache = *CacheP.get();
if (_error->PendingError() || Map->Size() == 0)
{
@@ -1514,7 +1514,7 @@ static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName,
return false;
}
- std::unique_ptr<bool[]> RlsVisited(new bool[Cache.HeaderP->ReleaseFileCount]);
+ auto RlsVisited = std::make_unique<bool[]>(Cache.HeaderP->ReleaseFileCount);
memset(RlsVisited.get(),0,sizeof(RlsVisited[0])*Cache.HeaderP->ReleaseFileCount);
std::vector<pkgIndexFile *> Files;
for (pkgSourceList::const_iterator i = List.begin(); i != List.end(); ++i)
@@ -1549,7 +1549,7 @@ static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName,
/* 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.. */
- std::unique_ptr<bool[]> Visited(new bool[Cache.HeaderP->PackageFileCount]);
+ auto Visited = std::make_unique<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)
{
@@ -1927,7 +1927,7 @@ bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **O
return false;
ScopedErrorMerge sem;
- std::unique_ptr<DynamicMMap> Map(CreateDynamicMMap(NULL, 0));
+ auto Map = std::make_unique<DynamicMMap>(NULL, 0);
if (unlikely(Map->validData()) == false)
return false;
map_filesize_t CurrentSize = 0;
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index 7d11ba898..d91277d3b 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -109,7 +109,7 @@ bool pkgPolicy::InitDefaults()
}
// Apply the defaults..
- std::unique_ptr<bool[]> Fixed(new bool[Cache->HeaderP->PackageFileCount]);
+ auto Fixed = std::make_unique<bool[]>(Cache->HeaderP->PackageFileCount);
memset(Fixed.get(),0,sizeof(Fixed[0])*Cache->HeaderP->PackageFileCount);
StatusOverride = false;
for (vector<Pin>::const_iterator I = Defaults.begin(); I != Defaults.end(); ++I)
diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc
index 8442a959d..f493ad0cb 100644
--- a/cmdline/apt-sortpkgs.cc
+++ b/cmdline/apt-sortpkgs.cc
@@ -115,7 +115,7 @@ static bool DoIt(string InFile)
// Emit
FileFd stdoutfd;
stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false);
- auto const Buffer = std::unique_ptr<unsigned char[]>(new unsigned char[Largest+1]);
+ auto const Buffer = std::make_unique<unsigned char[]>(Largest+1);
for (vector<PkgName>::iterator I = List.begin(); I != List.end(); ++I)
{
// Read in the Record.
diff --git a/methods/http.cc b/methods/http.cc
index 85350785e..09bca47dd 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -397,7 +397,7 @@ static ResultState UnwrapHTTPConnect(std::string Host, int Port, URI Proxy, std:
if (In.WriteSpace())
{
// Maybe there is actual data already read, if so we need to buffer it
- std::unique_ptr<HttpConnectFd> NewFd(new HttpConnectFd());
+ auto NewFd = std::make_unique<HttpConnectFd>();
In.Write(NewFd->Buffer);
NewFd->UnderlyingFd = std::move(Fd);
Fd = std::move(NewFd);