Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ General C++

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

- Use `MakeUnique()` to construct objects owned by `unique_ptr`s

- *Rationale*: `MakeUnique` is concise and ensures exception safety in complex expressions.
`MakeUnique` is a temporary project local implementation of `std::make_unique` (C++14).

C++ data structures
--------------------

Expand Down
4 changes: 3 additions & 1 deletion src/bench/bench_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <bls/bls.h>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

static const int64_t DEFAULT_BENCH_EVALUATIONS = 5;
static const char* DEFAULT_BENCH_FILTER = ".*";
static const char* DEFAULT_BENCH_SCALING = "1.0";
Expand Down Expand Up @@ -95,7 +97,7 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}

std::unique_ptr<benchmark::Printer> printer(new benchmark::ConsolePrinter());
std::unique_ptr<benchmark::Printer> printer = MakeUnique<benchmark::ConsolePrinter>();
std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER);
if ("plot" == printer_arg) {
printer.reset(new benchmark::PlotlyPrinter(
Expand Down
9 changes: 6 additions & 3 deletions src/bench/checkblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ static void DeserializeBlockTest(benchmark::State& state)
while (state.KeepRunning()) {
CBlock block;
stream >> block;
assert(stream.Rewind(sizeof(raw_bench::block813851)));
bool rewound = stream.Rewind(sizeof(raw_bench::block813851));
assert(rewound);
}
}

Expand All @@ -43,10 +44,12 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state)
while (state.KeepRunning()) {
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
stream >> block;
assert(stream.Rewind(sizeof(raw_bench::block813851)));
bool rewound = stream.Rewind(sizeof(raw_bench::block813851));
assert(rewound);

CValidationState validationState;
assert(CheckBlock(block, validationState, chainParams->GetConsensus(), block.GetBlockTime()));
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus(), block.GetBlockTime());
assert(checked);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void add_coin(const CAmount& nValue, int nInput, std::vector<OutputGroup>
CMutableTransaction tx;
tx.vout.resize(nInput + 1);
tx.vout[nInput].nValue = nValue;
std::unique_ptr<CWalletTx> wtx(new CWalletTx(&testWallet, MakeTransactionRef(std::move(tx))));
std::unique_ptr<CWalletTx> wtx = MakeUnique<CWalletTx>(&testWallet, MakeTransactionRef(std::move(tx)));
set.emplace_back(COutput(wtx.get(), nInput, 0, true, true, true).GetInputCoin(), 0, true, 0, 0);
wtxn.emplace_back(std::move(wtx));
}
Expand Down
2 changes: 2 additions & 0 deletions src/dash-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <univalue.h>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

static const char DEFAULT_RPCCONNECT[] = "127.0.0.1";
static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
static const bool DEFAULT_NAMED=false;
Expand Down
2 changes: 2 additions & 0 deletions src/dash-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static bool fCreateBlank;
static std::map<std::string,UniValue> registers;
static const int CONTINUE_EXECUTION=-1;

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

static void SetupBitcoinTxArgs()
{
gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS);
Expand Down
2 changes: 2 additions & 0 deletions src/dashd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <stdio.h>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

/* Introduction text for doxygen: */

/*! \mainpage Developer documentation
Expand Down
5 changes: 3 additions & 2 deletions src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ bool StartHTTPRPC()
// ifdef can be removed once we switch to better endpoint support and API versioning
RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
#endif
assert(EventBase());
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(EventBase());
struct event_base* eventBase = EventBase();
assert(eventBase);
httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(eventBase);
RPCSetTimerInterface(httpRPCTimerInterface.get());
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,12 @@ static void registerSignalHandler(int signal, void(*handler)(int))

static void OnRPCStarted()
{
uiInterface.NotifyBlockTip.connect(&RPCNotifyBlockChange);
uiInterface.NotifyBlockTip_connect(&RPCNotifyBlockChange);
}

static void OnRPCStopped()
{
uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange);
uiInterface.NotifyBlockTip_disconnect(&RPCNotifyBlockChange);
RPCNotifyBlockChange(false, nullptr);
g_best_block_cv.notify_all();
LogPrint(BCLog::RPC, "RPC stopped.\n");
Expand Down Expand Up @@ -1855,7 +1855,7 @@ bool AppInitMain()
*/
if (gArgs.GetBoolArg("-server", false))
{
uiInterface.InitMessage.connect(SetRPCWarmupStatus);
uiInterface.InitMessage_connect(SetRPCWarmupStatus);
if (!AppInitServers())
return InitError(_("Unable to start HTTP server. See debug log for details."));
}
Expand Down Expand Up @@ -2432,13 +2432,13 @@ bool AppInitMain()
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
// No locking, as this happens before any background thread is started.
if (chainActive.Tip() == nullptr) {
uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait);
uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait);
} else {
fHaveGenesis = true;
}

if (gArgs.IsArgSet("-blocknotify"))
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
uiInterface.NotifyBlockTip_connect(BlockNotifyCallback);

std::vector<fs::path> vImportFiles;
for (const std::string& strFile : gArgs.GetArgs("-loadblock")) {
Expand All @@ -2456,7 +2456,7 @@ bool AppInitMain()
while (!fHaveGenesis && !ShutdownRequested()) {
g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500));
}
uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait);
uiInterface.NotifyBlockTip_disconnect(BlockNotifyGenesisWait);
}

// As importing blocks can take several minutes, it's possible the user
Expand Down
26 changes: 13 additions & 13 deletions src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,67 +365,67 @@ class NodeImpl : public Node

std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override
{
return MakeHandler(::uiInterface.InitMessage.connect(fn));
return MakeHandler(::uiInterface.InitMessage_connect(fn));
}
std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override
{
return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn));
return MakeHandler(::uiInterface.ThreadSafeMessageBox_connect(fn));
}
std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override
{
return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn));
return MakeHandler(::uiInterface.ThreadSafeQuestion_connect(fn));
}
std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
{
return MakeHandler(::uiInterface.ShowProgress.connect(fn));
return MakeHandler(::uiInterface.ShowProgress_connect(fn));
}
std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
{
CHECK_WALLET(
return MakeHandler(::uiInterface.LoadWallet.connect([fn](std::shared_ptr<CWallet> wallet) { fn(MakeWallet(wallet)); })));
return MakeHandler(::uiInterface.LoadWallet_connect([fn](std::shared_ptr<CWallet> wallet) { fn(MakeWallet(wallet)); })));
}
std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
{
return MakeHandler(::uiInterface.NotifyNumConnectionsChanged.connect(fn));
return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn));
}
std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override
{
return MakeHandler(::uiInterface.NotifyNetworkActiveChanged.connect(fn));
return MakeHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn));
}
std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override
{
return MakeHandler(::uiInterface.NotifyAlertChanged.connect(fn));
return MakeHandler(::uiInterface.NotifyAlertChanged_connect(fn));
}
std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override
{
return MakeHandler(::uiInterface.BannedListChanged.connect(fn));
return MakeHandler(::uiInterface.BannedListChanged_connect(fn));
}
std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override
{
return MakeHandler(::uiInterface.NotifyBlockTip.connect([fn](bool initial_download, const CBlockIndex* block) {
return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](bool initial_download, const CBlockIndex* block) {
fn(initial_download, block->nHeight, block->GetBlockTime(), block->GetBlockHash().ToString(),
GuessVerificationProgress(Params().TxData(), block));
}));
}
std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override
{
return MakeHandler(
::uiInterface.NotifyHeaderTip.connect([fn](bool initial_download, const CBlockIndex* block) {
::uiInterface.NotifyHeaderTip_connect([fn](bool initial_download, const CBlockIndex* block) {
fn(initial_download, block->nHeight, block->GetBlockTime(), block->GetBlockHash().ToString(),
GuessVerificationProgress(Params().TxData(), block));
}));
}
std::unique_ptr<Handler> handleNotifyMasternodeListChanged(NotifyMasternodeListChangedFn fn) override
{
return MakeHandler(
::uiInterface.NotifyMasternodeListChanged.connect([fn](const CDeterministicMNList& newList) {
::uiInterface.NotifyMasternodeListChanged_connect([fn](const CDeterministicMNList& newList) {
fn(newList);
}));
}
std::unique_ptr<Handler> handleNotifyAdditionalDataSyncProgressChanged(NotifyAdditionalDataSyncProgressChangedFn fn) override
{
return MakeHandler(
::uiInterface.NotifyAdditionalDataSyncProgressChanged.connect([fn](double nSyncProgress) {
::uiInterface.NotifyAdditionalDataSyncProgressChanged_connect([fn](double nSyncProgress) {
fn(nSyncProgress);
}));
}
Expand Down
8 changes: 5 additions & 3 deletions src/noui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <stdint.h>
#include <string>

#include <boost/signals2/connection.hpp>

static bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style)
{
bool fSecure = style & CClientUIInterface::SECURE;
Expand Down Expand Up @@ -53,7 +55,7 @@ static void noui_InitMessage(const std::string& message)
void noui_connect()
{
// Connect dashd signal handlers
uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox);
uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestion);
uiInterface.InitMessage.connect(noui_InitMessage);
uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
uiInterface.InitMessage_connect(noui_InitMessage);
}
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#include <QUrlQuery>
#include <QVBoxLayout>

#include <boost/bind.hpp>

const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
#if defined(Q_OS_MAC)
"macosx"
Expand Down
10 changes: 3 additions & 7 deletions src/qt/dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,10 @@ static void InitMessage(const std::string &message)
LogPrintf("init message: %s\n", message);
}

/*
Translate string to current locale using Qt.
*/
static std::string Translate(const char* psz)
{
/** Translate string to current locale using Qt. */
const std::function<std::string(const char*)> G_TRANSLATION_FUN = [](const char* psz) {
return QCoreApplication::translate("dash-core", psz).toStdString();
}
};

static QString GetLangTerritory()
{
Expand Down Expand Up @@ -628,7 +625,6 @@ int main(int argc, char *argv[])
// Now that QSettings are accessible, initialize translations
QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
translationInterface.Translate.connect(Translate);

if (gArgs.IsArgSet("-printcrashinfo")) {
auto crashInfo = GetCrashInfoStrFromSerializedStr(gArgs.GetArg("-printcrashinfo", ""));
Expand Down
4 changes: 3 additions & 1 deletion src/qt/splashscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>
#include <util/system.h>
#include <ui_interface.h>
#include <util/system.h>
#include <version.h>

#include <QApplication>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QPainter>

#include <boost/bind.hpp>

SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle) :
QWidget(0, f), curAlignment(0), m_node(node)
{
Expand Down
4 changes: 3 additions & 1 deletion src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
#include <core_io.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <validation.h>
#include <sync.h>
#include <uint256.h>
#include <util/system.h>
#include <validation.h>

#include <QColor>
#include <QDateTime>
#include <QDebug>
#include <QIcon>
#include <QList>

#include <boost/bind.hpp>

// Amount column is right-aligned it contains numbers
static int column_alignments[] = {
Qt::AlignLeft|Qt::AlignVCenter, /* status */
Expand Down
3 changes: 2 additions & 1 deletion src/script/sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script)
SignatureData sigs;
if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) {
// VerifyScript check is just defensive, and should never fail.
assert(VerifyScript(sigs.scriptSig, script, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER));
bool verified = VerifyScript(sigs.scriptSig, script, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER);
assert(verified);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/test/allocator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class TestLockedPageAllocator: public LockedPageAllocator
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));
std::unique_ptr<LockedPageAllocator> x = MakeUnique<TestLockedPageAllocator>(3, 1);
LockedPool pool(std::move(x));
BOOST_CHECK(pool.stats().total == 0);
BOOST_CHECK(pool.stats().locked == 0);
Expand Down
Loading