mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-09-25 23:26:40 +02:00
Merge bitcoin/bitcoin#30889: log: Use ConstevalFormatString
facbcd4cef
log: Use ConstevalFormatString (MarcoFalke)fae9b60c4f
test: Use LogPrintStr to test m_log_sourcelocations (MarcoFalke)fa39b1ca63
doc: move-only logging warning (MarcoFalke) Pull request description: This changes all logging (including the wallet logging) to produce a `ConstevalFormatString` at compile time, so that the format string can be validated at compile-time. I tested with `clang` and found that the compiler will use less than 1% more of time and memory. When an error is found, the compile-time error depends on the compiler, but it may look similar to: ``` src/util/string.h: In function ‘int main(int, char**)’: src/bitcoind.cpp:265:5: in ‘constexpr’ expansion of ‘util::ConstevalFormatString<1>(((const char*)"Hi %s %s"))’ src/util/string.h:38:98: in ‘constexpr’ expansion of ‘util::ConstevalFormatString<1>::Detail_CheckNumFormatSpecifiers(std::basic_string_view<char>(((const char*)((util::ConstevalFormatString<1>*)this)->util::ConstevalFormatString<1>::fmt)))’ src/util/string.h:78:34: error: expression ‘<throw-expression>’ is not a constant expression 78 | if (num_params != count) throw "Format specifier count must match the argument count!"; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` This refactor does not change behavior of the compiled executables. ACKs for top commit: hodlinator: re-ACKfacbcd4cef
l0rinc: ACKfacbcd4cef
ryanofsky: Code review ACKfacbcd4cef
pablomartin4btc: re-ACKfacbcd4cef
stickies-v: Approach ACK and code LGTMfacbcd4cef
modulo a `tinyformat::format_error` concern. Tree-SHA512: 852f74d360897020f0d0f6e5064edc5e7f7dacc2bec1d5feff22c634a2fcd2eb535aa75be0b7191d9053728be6108484c737154b02d68ad3186a2e5544ba0db8
This commit is contained in:
@@ -17,15 +17,7 @@ import sys
|
||||
|
||||
FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS = [
|
||||
'tfm::format,1', # Assuming tfm::::format(std::ostream&, ...
|
||||
'LogError,0',
|
||||
'LogWarning,0',
|
||||
'LogInfo,0',
|
||||
'LogDebug,1',
|
||||
'LogTrace,1',
|
||||
'LogPrintf,0',
|
||||
'LogPrintLevel,2',
|
||||
'strprintf,0',
|
||||
'WalletLogPrintf,0',
|
||||
]
|
||||
RUN_LINT_FILE = 'test/lint/run-lint-format-strings.py'
|
||||
|
||||
|
@@ -15,11 +15,6 @@ import sys
|
||||
FALSE_POSITIVES = [
|
||||
("src/clientversion.cpp", "strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION)"),
|
||||
("src/test/translation_tests.cpp", "strprintf(format, arg)"),
|
||||
("src/validationinterface.cpp", "LogDebug(BCLog::VALIDATION, fmt \"\\n\", __VA_ARGS__)"),
|
||||
("src/wallet/wallet.h", "WalletLogPrintf(const char* fmt, Params... parameters)"),
|
||||
("src/wallet/wallet.h", "LogPrintf((\"%s \" + std::string{fmt}).c_str(), GetDisplayName(), parameters...)"),
|
||||
("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(const char* fmt, Params... parameters)"),
|
||||
("src/wallet/scriptpubkeyman.h", "LogPrintf((\"%s \" + std::string{fmt}).c_str(), m_storage.GetDisplayName(), parameters...)"),
|
||||
]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user