Skip to content

Commit e0bc27a

Browse files
author
MarcoFalke
committed
Merge #21404: refactor: Remove MakeUnique<T>()
1a6323b doc: update developer notes for removal of MakeUnique (fanquake) 3ba2840 scripted-diff: remove MakeUnique<T>() (fanquake) Pull request description: Since requiring C++17, this is just pointless abstraction. I think we should just "tear the band-aid off" and remove it. Similar to the changes happening in #21366. Also, having a comment saying this is deprecated doesn't prevent it's usage in new code. i.e : bitcoin/bitcoin#20946 (comment). The repository is fairly quiet at the moment, so any potential complaints about having to rebase should be minimal. Might as well get this over and done with. ACKs for top commit: jnewbery: utACK 1a6323b practicalswift: cr ACK 1a6323b: patch looks correct ajtowns: ACK 1a6323b -- code review only glozow: ACK bitcoin/bitcoin@1a6323b looks correct Tree-SHA512: 4a14b9611b60b9b3026b54d6f5a2dce4c5d9b63a7b93d7de1307512df736503ed84bac66e7b93372c76e3117f49bf9f29cd473d3a47cb41fb2775bc10234736f
2 parents a13a8cd + 1a6323b commit e0bc27a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+110
-161
lines changed

doc/developer-notes.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,6 @@ Common misconceptions are clarified in those sections:
595595

596596
- *Rationale*: This avoids memory and resource leaks, and ensures exception safety.
597597

598-
- Use `MakeUnique()` to construct objects owned by `unique_ptr`s.
599-
600-
- *Rationale*: `MakeUnique` is concise and ensures exception safety in complex expressions.
601-
`MakeUnique` is a temporary project local implementation of `std::make_unique` (C++14).
602-
603598
C++ data structures
604599
--------------------
605600

src/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ BITCOIN_CORE_H = \
240240
util/golombrice.h \
241241
util/hasher.h \
242242
util/macros.h \
243-
util/memory.h \
244243
util/message.h \
245244
util/moneystr.h \
246245
util/rbf.h \

src/bench/coin_selection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<st
1717
tx.nLockTime = nextLockTime++; // so all transactions get different hashes
1818
tx.vout.resize(1);
1919
tx.vout[0].nValue = nValue;
20-
wtxs.push_back(MakeUnique<CWalletTx>(&wallet, MakeTransactionRef(std::move(tx))));
20+
wtxs.push_back(std::make_unique<CWalletTx>(&wallet, MakeTransactionRef(std::move(tx))));
2121
}
2222

2323
// Simple benchmark for wallet coin selection. Note that it maybe be necessary
@@ -73,7 +73,7 @@ static void add_coin(const CAmount& nValue, int nInput, std::vector<OutputGroup>
7373
CMutableTransaction tx;
7474
tx.vout.resize(nInput + 1);
7575
tx.vout[nInput].nValue = nValue;
76-
std::unique_ptr<CWalletTx> wtx = MakeUnique<CWalletTx>(&testWallet, MakeTransactionRef(std::move(tx)));
76+
std::unique_ptr<CWalletTx> wtx = std::make_unique<CWalletTx>(&testWallet, MakeTransactionRef(std::move(tx)));
7777
set.emplace_back();
7878
set.back().Insert(COutput(wtx.get(), nInput, 0, true, true, true).GetInputCoin(), 0, true, 0, 0, false);
7979
wtxn.emplace_back(std::move(wtx));

src/chainparamsbase.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <tinyformat.h>
99
#include <util/system.h>
10-
#include <util/memory.h>
1110

1211
#include <assert.h>
1312

@@ -44,13 +43,13 @@ const CBaseChainParams& BaseParams()
4443
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
4544
{
4645
if (chain == CBaseChainParams::MAIN) {
47-
return MakeUnique<CBaseChainParams>("", 8332, 8334);
46+
return std::make_unique<CBaseChainParams>("", 8332, 8334);
4847
} else if (chain == CBaseChainParams::TESTNET) {
49-
return MakeUnique<CBaseChainParams>("testnet3", 18332, 18334);
48+
return std::make_unique<CBaseChainParams>("testnet3", 18332, 18334);
5049
} else if (chain == CBaseChainParams::SIGNET) {
51-
return MakeUnique<CBaseChainParams>("signet", 38332, 38334);
50+
return std::make_unique<CBaseChainParams>("signet", 38332, 38334);
5251
} else if (chain == CBaseChainParams::REGTEST) {
53-
return MakeUnique<CBaseChainParams>("regtest", 18443, 18445);
52+
return std::make_unique<CBaseChainParams>("regtest", 18443, 18445);
5453
}
5554
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
5655
}

src/httprpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ bool StartHTTPRPC(const util::Ref& context)
301301
}
302302
struct event_base* eventBase = EventBase();
303303
assert(eventBase);
304-
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(eventBase);
304+
httpRPCTimerInterface = std::make_unique<HTTPRPCTimerInterface>(eventBase);
305305
RPCSetTimerInterface(httpRPCTimerInterface.get());
306306
return true;
307307
}

src/index/blockfilterindex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ BlockFilterIndex::BlockFilterIndex(BlockFilterType filter_type,
102102
fs::create_directories(path);
103103

104104
m_name = filter_name + " block filter index";
105-
m_db = MakeUnique<BaseIndex::DB>(path / "db", n_cache_size, f_memory, f_wipe);
106-
m_filter_fileseq = MakeUnique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
105+
m_db = std::make_unique<BaseIndex::DB>(path / "db", n_cache_size, f_memory, f_wipe);
106+
m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
107107
}
108108

109109
bool BlockFilterIndex::Init()

src/index/txindex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ bool TxIndex::DB::MigrateData(CBlockTreeDB& block_tree_db, const CBlockLocator&
192192
}
193193

194194
TxIndex::TxIndex(size_t n_cache_size, bool f_memory, bool f_wipe)
195-
: m_db(MakeUnique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
195+
: m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
196196
{}
197197

198198
TxIndex::~TxIndex() {}

src/init.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
13501350
}
13511351

13521352
assert(!node.scheduler);
1353-
node.scheduler = MakeUnique<CScheduler>();
1353+
node.scheduler = std::make_unique<CScheduler>();
13541354

13551355
// Start the lightweight task scheduler thread
13561356
node.scheduler->m_service_thread = std::thread([&] { TraceThread("scheduler", [&] { node.scheduler->serviceQueue(); }); });
@@ -1402,9 +1402,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
14021402
const bool ignores_incoming_txs{args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)};
14031403

14041404
assert(!node.banman);
1405-
node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
1405+
node.banman = std::make_unique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
14061406
assert(!node.connman);
1407-
node.connman = MakeUnique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), args.GetBoolArg("-networkactive", true));
1407+
node.connman = std::make_unique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), args.GetBoolArg("-networkactive", true));
14081408

14091409
assert(!node.fee_estimator);
14101410
// Don't initialize fee estimation with old data if we don't relay transactions,
@@ -1800,7 +1800,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
18001800

18011801
// ********************************************************* Step 8: start indexers
18021802
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
1803-
g_txindex = MakeUnique<TxIndex>(nTxIndexCache, false, fReindex);
1803+
g_txindex = std::make_unique<TxIndex>(nTxIndexCache, false, fReindex);
18041804
g_txindex->Start();
18051805
}
18061806

src/interfaces/handler.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <interfaces/handler.h>
66

7-
#include <util/memory.h>
87

98
#include <boost/signals2/connection.hpp>
109
#include <utility>
@@ -35,12 +34,12 @@ class CleanupHandler : public Handler
3534

3635
std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection)
3736
{
38-
return MakeUnique<HandlerImpl>(std::move(connection));
37+
return std::make_unique<HandlerImpl>(std::move(connection));
3938
}
4039

4140
std::unique_ptr<Handler> MakeHandler(std::function<void()> cleanup)
4241
{
43-
return MakeUnique<CleanupHandler>(std::move(cleanup));
42+
return std::make_unique<CleanupHandler>(std::move(cleanup));
4443
}
4544

4645
} // namespace interfaces

src/net.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,11 +2466,11 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
24662466

24672467
if (semOutbound == nullptr) {
24682468
// initialize semaphore
2469-
semOutbound = MakeUnique<CSemaphore>(std::min(m_max_outbound, nMaxConnections));
2469+
semOutbound = std::make_unique<CSemaphore>(std::min(m_max_outbound, nMaxConnections));
24702470
}
24712471
if (semAddnode == nullptr) {
24722472
// initialize semaphore
2473-
semAddnode = MakeUnique<CSemaphore>(nMaxAddnode);
2473+
semAddnode = std::make_unique<CSemaphore>(nMaxAddnode);
24742474
}
24752475

24762476
//
@@ -2906,11 +2906,11 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
29062906
hSocket = hSocketIn;
29072907
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
29082908
if (conn_type_in != ConnectionType::BLOCK_RELAY) {
2909-
m_tx_relay = MakeUnique<TxRelay>();
2909+
m_tx_relay = std::make_unique<TxRelay>();
29102910
}
29112911

29122912
if (RelayAddrsWithConn()) {
2913-
m_addr_known = MakeUnique<CRollingBloomFilter>(5000, 0.001);
2913+
m_addr_known = std::make_unique<CRollingBloomFilter>(5000, 0.001);
29142914
}
29152915

29162916
for (const std::string &msg : getAllNetMessageTypes())
@@ -2923,8 +2923,8 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const
29232923
LogPrint(BCLog::NET, "Added connection peer=%d\n", id);
29242924
}
29252925

2926-
m_deserializer = MakeUnique<V1TransportDeserializer>(V1TransportDeserializer(Params(), GetId(), SER_NETWORK, INIT_PROTO_VERSION));
2927-
m_serializer = MakeUnique<V1TransportSerializer>(V1TransportSerializer());
2926+
m_deserializer = std::make_unique<V1TransportDeserializer>(V1TransportDeserializer(Params(), GetId(), SER_NETWORK, INIT_PROTO_VERSION));
2927+
m_serializer = std::make_unique<V1TransportSerializer>(V1TransportSerializer());
29282928
}
29292929

29302930
CNode::~CNode()

0 commit comments

Comments
 (0)