Skip to content

Commit ec91759

Browse files
committed
Use MakeUnique<T>(...) instead of std::unique_ptr<T>(new T(...))
>>> backports bitcoin/bitcoin@3e09b39 +bitcoin@a357293
1 parent 93487b1 commit ec91759

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/httprpc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
#include "chainparams.h"
99
#include "crypto/hmac_sha256.h"
10+
#include "guiinterface.h"
1011
#include "httpserver.h"
1112
#include "key_io.h"
1213
#include "rpc/protocol.h"
1314
#include "rpc/server.h"
1415
#include "random.h"
1516
#include "sync.h"
17+
#include "util/memory.h"
1618
#include "util/system.h"
1719
#include "utilstrencodings.h"
18-
#include "guiinterface.h"
1920

2021
#include <boost/algorithm/string.hpp> // boost::trim
2122

@@ -233,7 +234,7 @@ bool StartHTTPRPC()
233234
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
234235
#endif
235236
assert(EventBase());
236-
httpRPCTimerInterface = std::unique_ptr<HTTPRPCTimerInterface>(new HTTPRPCTimerInterface(EventBase()));
237+
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(EventBase());
237238
RPCSetTimerInterface(httpRPCTimerInterface.get());
238239
return true;
239240
}

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "primitives/transaction.h"
2424
#include "random.h"
2525
#include "scheduler.h"
26+
#include "util/memory.h"
2627
#include "validation.h"
2728

2829
#ifdef WIN32
@@ -1985,7 +1986,7 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c
19851986

19861987
if (semOutbound == nullptr) {
19871988
// initialize semaphore
1988-
semOutbound = std::unique_ptr<CSemaphore>(new CSemaphore(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections)));
1989+
semOutbound = MakeUnique<CSemaphore>(std::min((nMaxOutbound + nMaxFeeler), nMaxConnections));
19891990
}
19901991

19911992
if (pnodeLocalHost == nullptr) {
@@ -2332,7 +2333,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
23322333
nNextLocalAddrSend = 0;
23332334
nNextAddrSend = 0;
23342335
fRelayTxes = false;
2335-
pfilter = std::unique_ptr<CBloomFilter>(new CBloomFilter());
2336+
pfilter = MakeUnique<CBloomFilter>();
23362337
timeLastMempoolReq = 0;
23372338
nPingNonceSent = 0;
23382339
nPingUsecStart = 0;

src/test/test_pivx.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "sporkdb.h"
2222
#include "txmempool.h"
2323
#include "txdb.h"
24+
#include "util/memory.h"
2425
#include "validation.h"
2526

2627
#include <boost/test/unit_test.hpp>
@@ -83,7 +84,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
8384
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
8485

8586
// Register EvoNotificationInterface
86-
g_connman = std::unique_ptr<CConnman>(new CConnman(0x1337, 0x1337)); // Deterministic randomness for tests.
87+
g_connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
8788
connman = g_connman.get();
8889
pEvoNotificationInterface = new EvoNotificationInterface(*connman);
8990
RegisterValidationInterface(pEvoNotificationInterface);

src/wallet/db.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "guiinterfaceutil.h"
1111
#include "hash.h"
1212
#include "protocol.h"
13+
#include "util/memory.h"
1314
#include "util/system.h"
1415
#include "utilstrencodings.h"
1516
#include "wallet/walletutil.h"
@@ -462,7 +463,7 @@ CDB::CDB(CWalletDBWrapper& dbw, const char* pszMode, bool fFlushOnCloseIn) : pdb
462463
pdb = env->mapDb[strFilename];
463464
if (pdb == nullptr) {
464465
int ret;
465-
std::unique_ptr<Db> pdb_temp(new Db(env->dbenv.get(), 0));
466+
std::unique_ptr<Db> pdb_temp = MakeUnique<Db>(env->dbenv.get(), 0);
466467

467468
bool fMockDb = env->IsMock();
468469
if (fMockDb) {
@@ -589,7 +590,7 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
589590
std::string strFileRes = strFile + ".rewrite";
590591
{ // surround usage of db with extra {}
591592
CDB db(dbw, "r");
592-
std::unique_ptr<Db> pdbCopy = std::unique_ptr<Db>(new Db(env->dbenv.get(), 0));
593+
std::unique_ptr<Db> pdbCopy = MakeUnique<Db>(env->dbenv.get(), 0);
593594

594595
int ret = pdbCopy->open(NULL, // Txn pointer
595596
strFileRes.c_str(), // Filename

0 commit comments

Comments
 (0)