Page MenuHomePhabricator

D4612.id.diff
No OneTemporary

D4612.id.diff

diff --git a/doc/developer-notes.md b/doc/developer-notes.md
--- a/doc/developer-notes.md
+++ b/doc/developer-notes.md
@@ -464,6 +464,10 @@
- *Rationale*: This avoids memory and resource leaks, and ensures exception safety
+- Use `std::make_unique()` to construct objects owned by `unique_ptr`s
+
+ - *Rationale*: `std::make_unique` is concise and ensures exception safety in complex expressions.
+
C++ data structures
--------------------
diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp
--- a/src/bench/bench_bitcoin.cpp
+++ b/src/bench/bench_bitcoin.cpp
@@ -110,8 +110,8 @@
return EXIT_FAILURE;
}
- std::unique_ptr<benchmark::Printer> printer(
- new benchmark::ConsolePrinter());
+ std::unique_ptr<benchmark::Printer> printer =
+ std::make_unique<benchmark::ConsolePrinter>();
std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER);
if ("plot" == printer_arg) {
printer.reset(new benchmark::PlotlyPrinter(
diff --git a/src/test/allocator_tests.cpp b/src/test/allocator_tests.cpp
--- a/src/test/allocator_tests.cpp
+++ b/src/test/allocator_tests.cpp
@@ -171,7 +171,7 @@
BOOST_AUTO_TEST_CASE(lockedpool_tests_mock) {
// Test over three virtual arenas, of which one will succeed being locked
- std::unique_ptr<LockedPageAllocator> x(new TestLockedPageAllocator(3, 1));
+ auto x = std::make_unique<TestLockedPageAllocator>(3, 1);
LockedPool pool(std::move(x));
BOOST_CHECK(pool.stats().total == 0);
BOOST_CHECK(pool.stats().locked == 0);
diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp
--- a/src/test/checkqueue_tests.cpp
+++ b/src/test/checkqueue_tests.cpp
@@ -127,8 +127,7 @@
* with each specified size_t Checks pushed.
*/
static void Correct_Queue_range(std::vector<size_t> range) {
- auto small_queue =
- std::unique_ptr<Correct_Queue>(new Correct_Queue{QUEUE_BATCH_SIZE});
+ auto small_queue = std::make_unique<Correct_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg;
for (auto x = 0; x < nScriptCheckThreads; ++x) {
tg.create_thread([&] { small_queue->Thread(); });
@@ -189,8 +188,7 @@
/** Test that failing checks are caught */
BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) {
- auto fail_queue =
- std::unique_ptr<Failing_Queue>(new Failing_Queue{QUEUE_BATCH_SIZE});
+ auto fail_queue = std::make_unique<Failing_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg;
for (auto x = 0; x < nScriptCheckThreads; ++x) {
@@ -223,8 +221,7 @@
// Test that a block validation which fails does not interfere with
// future blocks, ie, the bad state is cleared.
BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) {
- auto fail_queue =
- std::unique_ptr<Failing_Queue>(new Failing_Queue{QUEUE_BATCH_SIZE});
+ auto fail_queue = std::make_unique<Failing_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg;
for (auto x = 0; x < nScriptCheckThreads; ++x) {
tg.create_thread([&] { fail_queue->Thread(); });
@@ -251,8 +248,7 @@
// just one check being called repeatedly. Test that checks are not called
// more than once as well
BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) {
- auto queue =
- std::unique_ptr<Unique_Queue>(new Unique_Queue{QUEUE_BATCH_SIZE});
+ auto queue = std::make_unique<Unique_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg;
for (auto x = 0; x < nScriptCheckThreads; ++x) {
tg.create_thread([&] { queue->Thread(); });
@@ -288,8 +284,7 @@
// checks might mean leaving a check un-swapped out, and decreasing by 1 each
// time could leave the data hanging across a sequence of blocks.
BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) {
- auto queue =
- std::unique_ptr<Memory_Queue>(new Memory_Queue{QUEUE_BATCH_SIZE});
+ auto queue = std::make_unique<Memory_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg;
for (auto x = 0; x < nScriptCheckThreads; ++x) {
tg.create_thread([&] { queue->Thread(); });
@@ -320,8 +315,7 @@
// Test that a new verification cannot occur until all checks
// have been destructed
BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup) {
- auto queue = std::unique_ptr<FrozenCleanup_Queue>(
- new FrozenCleanup_Queue{QUEUE_BATCH_SIZE});
+ auto queue = std::make_unique<FrozenCleanup_Queue>(QUEUE_BATCH_SIZE);
boost::thread_group tg;
bool fails = false;
for (auto x = 0; x < nScriptCheckThreads; ++x) {
@@ -364,8 +358,7 @@
/** Test that CCheckQueueControl is threadsafe */
BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) {
- auto queue =
- std::unique_ptr<Standard_Queue>(new Standard_Queue{QUEUE_BATCH_SIZE});
+ auto queue = std::make_unique<Standard_Queue>(QUEUE_BATCH_SIZE);
{
boost::thread_group tg;
std::atomic<int> nThreads{0};
diff --git a/src/test/test_bitcoin_fuzzy.cpp b/src/test/test_bitcoin_fuzzy.cpp
--- a/src/test/test_bitcoin_fuzzy.cpp
+++ b/src/test/test_bitcoin_fuzzy.cpp
@@ -281,8 +281,7 @@
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
void initialize() {
- globalVerifyHandle =
- std::unique_ptr<ECCVerifyHandle>(new ECCVerifyHandle());
+ globalVerifyHandle = std::make_unique<ECCVerifyHandle>();
}
// This function is used by libFuzzer
diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp
--- a/src/wallet/test/coinselector_tests.cpp
+++ b/src/wallet/test/coinselector_tests.cpp
@@ -72,8 +72,8 @@
// fake out IsFromMe()
tx.vin.resize(1);
}
- std::unique_ptr<CWalletTx> wtx(
- new CWalletTx(&wallet, MakeTransactionRef(std::move(tx))));
+ auto wtx =
+ std::make_unique<CWalletTx>(&wallet, MakeTransactionRef(std::move(tx)));
if (fIsFromMe) {
wtx->fDebitCached = true;
wtx->nDebitCached = SATOSHI;

File Metadata

Mime Type
text/plain
Expires
Tue, May 20, 22:24 (21 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5866055
Default Alt Text
D4612.id.diff (5 KB)

Event Timeline