-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Refactor: Replace fprintf with tfm::format #16205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Nice. Concept ACK. |
|
This might do it: diff --git a/test/lint/lint-locale-dependence.sh b/test/lint/lint-locale-dependence.sh
index 2b6c78c2c841b7cab90ce11b831ea1051118029e..b0c5ce39b1aba1c52b9b23c7451ac46d33cc6c67 100755
--- a/test/lint/lint-locale-dependence.sh
+++ b/test/lint/lint-locale-dependence.sh
@@ -8,7 +8,6 @@ KNOWN_VIOLATIONS=(
"src/dbwrapper.cpp:.*vsnprintf"
"src/httprpc.cpp.*trim"
"src/init.cpp:.*atoi"
- "src/init.cpp:.*fprintf"
"src/qt/rpcconsole.cpp:.*atoi"
"src/rest.cpp:.*strtol"
"src/test/dbwrapper_tests.cpp:.*snprintf"
@@ -189,8 +188,7 @@ GIT_GREP_OUTPUT=$(git grep -E "[^a-zA-Z0-9_\`'\"<>](${REGEXP_LOCALE_DEPENDENT_FU
EXIT_CODE=0
for LOCALE_DEPENDENT_FUNCTION in "${LOCALE_DEPENDENT_FUNCTIONS[@]}"; do
MATCHES=$(grep -E "[^a-zA-Z0-9_\`'\"<>]${LOCALE_DEPENDENT_FUNCTION}(_r|_s)?[^a-zA-Z0-9_\`'\"<>]" <<< "${GIT_GREP_OUTPUT}" | \
- grep -vE "\.(c|cpp|h):\s*(//|\*|/\*|\").*${LOCALE_DEPENDENT_FUNCTION}" | \
- grep -vE 'fprintf\(.*(stdout|stderr)')
+ grep -vE "\.(c|cpp|h):\s*(//|\*|/\*|\").*${LOCALE_DEPENDENT_FUNCTION}")
if [[ ${REGEXP_IGNORE_EXTERNAL_DEPENDENCIES} != "" ]]; then
MATCHES=$(grep -vE "${REGEXP_IGNORE_EXTERNAL_DEPENDENCIES}" <<< "${MATCHES}")
fi |
fa517dc to
fa6bca6
Compare
-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/fprintf\(std(err|out), /tfm::format(std::c\1, /g' $(git grep -l 'fprintf(' -- ':(exclude)src/crypto' ':(exclude)src/leveldb' ':(exclude)src/univalue' ':(exclude)src/secp256k1')
-END VERIFY SCRIPT-
fixup! scripted-diff: Replace fprintf with tfm::format
|
Concept ACK |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Concept ACK, will test in a bit. |
|
ACK fa8f195. Ideally this should be rebased before merge. |
|
utACK fa8f195 |
|
When reviewing please note that |
|
|
||
| if (argc < 2) { | ||
| fprintf(stderr, "Error: too few parameters\n"); | ||
| tfm::format(std::cerr, "Error: too few parameters\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a few of these could drop formatting altogether, via <<
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe tfm uses << under the hood, so it shouldn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the output should be the same, just would remove a layer of indirection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's just a matter of style; it seems most of the developers of this code base prefer %X formatting to the various << incantations (hence the use of tinyformat in the first place), so consistently using tfm::format seems good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Just a nit.
|
ACK fa8f195 |
Another thing to be careful of is to not use |
laanwj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code review and lightly tested ACK fa8f195
jonatack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK fa8f195 from light code review, building, and running linter/unit tests/extended functional tests.
| std::string ToString() const | ||
| { | ||
| return tfm::format( | ||
| return strprintf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this change is only required due to the test/lint/lint-format-strings.sh linter change in fa8f195 of this PR.
E.g. if the above line is not changed then ./test/lint/lint-format-strings.sh will raise
src/sync.cpp: Expected 0 argument(s) after format string but found 4 argument(s): tfm::format( "%s %s:%s%s (in thread %s)", mutexName, sourceFile, itostr(sourceLine), (fTry ? " (TRY)" : ""), m_thread_name)whereas on master it does not raise.
Perhaps an quick note in the commit and PR description explaining why this changed could be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, but I didn't rewrite the commits to preserve the acks.
fa8f195 Replace remaining fprintf with tfm::format manually (MarcoFalke) fac03ec scripted-diff: Replace fprintf with tfm::format (MarcoFalke) fa72a64 tinyformat: Add doc to Bitcoin Core specific strprintf (MarcoFalke) Pull request description: This should be a refactor except in the cases where we use the wrong format specifier [1], in which case this patch is a bug fix. [1] : e.g. depends: Add libevent compatibility patch for windows bitcoin#8730 ACKs for commit fa8f19: promag: ACK fa8f195. Ideally this should be rebased before merge. practicalswift: utACK fa8f195 Empact: ACK bitcoin@fa8f195 laanwj: code review and lightly tested ACK fa8f195 jonatack: ACK fa8f195 from light code review, building, and running linter/unit tests/extended functional tests. Tree-SHA512: 65f648b0bc383e3266a5bdb4ad8c8a1908a719635d49e1cd321b91254be24dbc7e22290370178e29b98ddcb3fec0889de9cbae273c7140abc9793d849534a743
|
Post-merge utACK |
|
Looks like this accidentally fixed multiple test failures with the cross-compiled windows binaries:
|
|
I am going to backport this, since it turned out to be a bugfix |
Github-Pull: bitcoin#16205 Rebased-From: fa72a64
-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/fprintf\(std(err|out), /tfm::format(std::c\1, /g' $(git grep -l 'fprintf(' -- ':(exclude)src/crypto' ':(exclude)src/leveldb' ':(exclude)src/univalue' ':(exclude)src/secp256k1')
-END VERIFY SCRIPT-
fixup! scripted-diff: Replace fprintf with tfm::format
Github-Pull: bitcoin#16205
Rebased-From: fac03ec
Github-Pull: bitcoin#16205 Rebased-From: fa8f195
Github-Pull: bitcoin#16205 Rebased-From: fa72a64
-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/fprintf\(std(err|out), /tfm::format(std::c\1, /g' $(git grep -l 'fprintf(' -- ':(exclude)src/crypto' ':(exclude)src/leveldb' ':(exclude)src/univalue' ':(exclude)src/secp256k1')
-END VERIFY SCRIPT-
fixup! scripted-diff: Replace fprintf with tfm::format
Github-Pull: bitcoin#16205
Rebased-From: fac03ec
Github-Pull: bitcoin#16205 Rebased-From: fa8f195
Github-Pull: bitcoin#16205 Rebased-From: fa72a64
Github-Pull: bitcoin#16205 Rebased-From: fac03ec
Summary:
* tinyformat: Add doc to Bitcoin Core specific strprintf
* scripted-diff: Replace fprintf with tfm::format
-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/fprintf\(std(err|out), /tfm::format(std::c\1, /g' $(git grep -l 'fprintf(' -- ':(exclude)src/crypto' ':(exclude)src/leveldb' ':(exclude)src/univalue' ':(exclude)src/secp256k1')
-END VERIFY SCRIPT-
fixup! scripted-diff: Replace fprintf with tfm::format
* Replace remaining fprintf with tfm::format manually
This is a backport of Core [[bitcoin/bitcoin#16205 | PR16205]]
Test Plan:
grep -r ../src/ -e fprintf | grep -v leveldb | grep -v secp256k1 | grep -v univalue
Check that there are no mre unexpected callsites.
ninja all check-all
arc lint --everything
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Subscribers: Fabien
Differential Revision: https://reviews.bitcoinabc.org/D5782
* tinyformat: Add doc to Bitcoin Core specific strprintf
* scripted-diff: Replace fprintf with tfm::format
-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/fprintf\(std(err|out), /tfm::format(std::c\1, /g' $(git grep -l 'fprintf(' -- ':(exclude)src/crypto' ':(exclude)src/leveldb' ':(exclude)src/univalue' ':(exclude)src/secp256k1')
-END VERIFY SCRIPT-
* Replace remaining fprintf with tfm::format manually
* fixes
Co-authored-by: MarcoFalke <[email protected]>
…pay#4531) * tinyformat: Add doc to Bitcoin Core specific strprintf * scripted-diff: Replace fprintf with tfm::format -BEGIN VERIFY SCRIPT- sed -i --regexp-extended -e 's/fprintf\(std(err|out), /tfm::format(std::c\1, /g' $(git grep -l 'fprintf(' -- ':(exclude)src/crypto' ':(exclude)src/leveldb' ':(exclude)src/univalue' ':(exclude)src/secp256k1') -END VERIFY SCRIPT- * Replace remaining fprintf with tfm::format manually * fixes Co-authored-by: MarcoFalke <[email protected]>
This should be a refactor except in the cases where we use the wrong format specifier [1], in which case this patch is a bug fix.
[1] : e.g. depends: Add libevent compatibility patch for windows #8730