mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
util: Use compile-time check for FatalErrorf
This commit is contained in:
parent
faa62c0112
commit
fa7087b896
5 changed files with 15 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2017-2022 The Bitcoin Core developers
|
// Copyright (c) 2017-present The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
||||||
#include <node/database_args.h>
|
#include <node/database_args.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
|
#include <util/string.h>
|
||||||
#include <util/thread.h>
|
#include <util/thread.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validation.h> // For g_chainman
|
#include <validation.h> // For g_chainman
|
||||||
|
@ -27,7 +28,7 @@ constexpr auto SYNC_LOG_INTERVAL{30s};
|
||||||
constexpr auto SYNC_LOCATOR_WRITE_INTERVAL{30s};
|
constexpr auto SYNC_LOCATOR_WRITE_INTERVAL{30s};
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void BaseIndex::FatalErrorf(const char* fmt, const Args&... args)
|
void BaseIndex::FatalErrorf(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
|
||||||
{
|
{
|
||||||
auto message = tfm::format(fmt, args...);
|
auto message = tfm::format(fmt, args...);
|
||||||
node::AbortNode(m_chain->context()->shutdown, m_chain->context()->exit_status, Untranslated(message), m_chain->context()->warnings.get());
|
node::AbortNode(m_chain->context()->shutdown, m_chain->context()->exit_status, Untranslated(message), m_chain->context()->warnings.get());
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2017-2022 The Bitcoin Core developers
|
// Copyright (c) 2017-present The Bitcoin Core developers
|
||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <dbwrapper.h>
|
#include <dbwrapper.h>
|
||||||
#include <interfaces/chain.h>
|
#include <interfaces/chain.h>
|
||||||
|
#include <util/string.h>
|
||||||
#include <util/threadinterrupt.h>
|
#include <util/threadinterrupt.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ private:
|
||||||
virtual bool AllowPrune() const = 0;
|
virtual bool AllowPrune() const = 0;
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void FatalErrorf(const char* fmt, const Args&... args);
|
void FatalErrorf(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<interfaces::Chain> m_chain;
|
std::unique_ptr<interfaces::Chain> m_chain;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define BITCOIN_UTIL_STRING_H
|
#define BITCOIN_UTIL_STRING_H
|
||||||
|
|
||||||
#include <span.h>
|
#include <span.h>
|
||||||
|
#include <tinyformat.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
@ -234,4 +235,12 @@ template <typename T1, size_t PREFIX_LEN>
|
||||||
}
|
}
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
|
namespace tinyformat {
|
||||||
|
template <typename... Args>
|
||||||
|
std::string format(util::ConstevalFormatString<sizeof...(Args)> fmt, const Args&... args)
|
||||||
|
{
|
||||||
|
return format(fmt.fmt, args...);
|
||||||
|
}
|
||||||
|
} // namespace tinyformat
|
||||||
|
|
||||||
#endif // BITCOIN_UTIL_STRING_H
|
#endif // BITCOIN_UTIL_STRING_H
|
||||||
|
|
|
@ -16,7 +16,6 @@ import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS = [
|
FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS = [
|
||||||
'FatalErrorf,0',
|
|
||||||
'tfm::format,1', # Assuming tfm::::format(std::ostream&, ...
|
'tfm::format,1', # Assuming tfm::::format(std::ostream&, ...
|
||||||
'LogConnectFailure,1',
|
'LogConnectFailure,1',
|
||||||
'LogError,0',
|
'LogError,0',
|
||||||
|
|
|
@ -13,8 +13,6 @@ import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
FALSE_POSITIVES = [
|
FALSE_POSITIVES = [
|
||||||
("src/index/base.cpp", "FatalErrorf(const char* fmt, const Args&... args)"),
|
|
||||||
("src/index/base.h", "FatalErrorf(const char* fmt, const Args&... args)"),
|
|
||||||
("src/netbase.cpp", "LogConnectFailure(bool manual_connection, const char* fmt, const Args&... args)"),
|
("src/netbase.cpp", "LogConnectFailure(bool manual_connection, const char* fmt, const Args&... args)"),
|
||||||
("src/clientversion.cpp", "strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION)"),
|
("src/clientversion.cpp", "strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION)"),
|
||||||
("src/test/translation_tests.cpp", "strprintf(format, arg)"),
|
("src/test/translation_tests.cpp", "strprintf(format, arg)"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue