Remove global symbols: Avoid using the global namespace if possible#15622
Remove global symbols: Avoid using the global namespace if possible#15622maflcko merged 1 commit intobitcoin:masterfrom
Conversation
596626c to
b112097
Compare
|
Concept ACK, change looks good. |
|
utACK b112097f8e5f96e96db47e2eef9870d6f0431677. Also checked that the binary is 9kB smaller. |
|
utACK b112097 |
|
utACK 9638da7. |
|
I think we can add some language on this policy in doc/developer-notes.md. It will help new developers. I agree on a zero-globals policy, enforced with singletons, or with a "state" class that is a container of all the globals, or with a dedicated namespace. This way, every time a new global has to be added (rarely), we can see a clear change in a single place. In my mind this policy should not be enforced from now, but should be accepted, then written in doc/developer-notes.md or elsewhere, and enforced after a couple of years, when all the open PRs are already compliant. I've just described this method of long grace periods in my comment on #15465. |
|
@lucayepa I would like to restrict the scope of this PR to these specific code changes which have already been (ut)ACK:ed. |
|
utACK 9638da7 |
|
It's a bit confusing to call this"Remove globals"; a global inside a namespace is still a global. |
|
@sipa I've now clarified that this refers to global (external) symbols :-) |
|
utACK:s from @Empact and @promag, one stale utACK from @MarcoFalke and zero NACK:s @MarcoFalke, are we ready to move forward with this one to get a slightly less polluted global namespace? :-) |
|
I would have thought it would be better to write these as Either way, I don't see the point of dropping |
|
@ajtowns I've now reverted to the original version of the PR which is in accordance with your suggestions. Please re-review :-) @promag @MarcoFalke @Empact Would you mind re-reviewing? :-) |
|
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. |
|
Please squash the second commit, no need to have a separate commit for a single line stylistic fixup |
Rename CCriticalSection to RecursiveMutex (both are AnnotatedMixin<std::recursive_mutex>) ``` $ git grep -E '(typedef|using).*(CCriticalSection|RecursiveMutex)' src/sync.h:using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>; src/sync.h:typedef AnnotatedMixin<std::recursive_mutex> CCriticalSection; ```
|
@MarcoFalke Done! Please re-review :-) |
… if possible fb43415 Remove global symbols: Avoid using the global namespace if possible (practicalswift) Pull request description: Remove global symbols: Avoid using the global namespace if possible. Partially resolves #15612 ("Reduce the number of global symbols used"). Change in global symbols as reported by `nm bitcoind` before vs after: ``` $ diff -u <(nm src/bitcoind-before | c++filt | grep -E '^[0-9a-f]+ [A-Z] ' | cut -f3- -d' ' | sort -u) \ <(nm src/bitcoind-after | c++filt | grep -E '^[0-9a-f]+ [A-Z] ' | cut -f3- -d' ' | sort -u) \ | grep -E '^[+-][^+-]' -boundSockets -cs_warnings -eventHTTP -fFeeEstimatesInitialized -fLargeWorkForkFound -fLargeWorkInvalidChainFound -pathHandlers -strMiscWarning[abi:cxx11] -threadHTTP ``` ACKs for commit fb4341: Tree-SHA512: d2f78f6188a992b0e0de8d107e2c494cfa0faa2de4fda634a1d3606d6515633bec86289cf2a2e78ffe467b17b795e2243cc459fb44e0dfe2fc69899506ff61c9
… if possible
Summary:
fb434159d1 Remove global symbols: Avoid using the global namespace if possible (practicalswift)
Pull request description:
Remove global symbols: Avoid using the global namespace if possible.
Partially resolves #15612 ("Reduce the number of global symbols used").
Change in global symbols as reported by `nm bitcoind` before vs after:
```
$ diff -u <(nm src/bitcoind-before | c++filt | grep -E '^[0-9a-f]+ [A-Z] ' | cut -f3- -d' ' | sort -u) \
<(nm src/bitcoind-after | c++filt | grep -E '^[0-9a-f]+ [A-Z] ' | cut -f3- -d' ' | sort -u) \
| grep -E '^[+-][^+-]'
-boundSockets
-cs_warnings
-eventHTTP
-fFeeEstimatesInitialized
-fLargeWorkForkFound
-fLargeWorkInvalidChainFound
-pathHandlers
-strMiscWarning[abi:cxx11]
-threadHTTP
```
ACKs for commit fb4341:
Tree-SHA512: d2f78f6188a992b0e0de8d107e2c494cfa0faa2de4fda634a1d3606d6515633bec86289cf2a2e78ffe467b17b795e2243cc459fb44e0dfe2fc69899506ff61c9
Backport of Core [[bitcoin/bitcoin#15622 | PR15622]]
Test Plan:
While the instructions in the summary do not appear to work, manually inspecting like:
```
diff -u <(nm src/bitcoind-before) <(nm src/bitcoind-after) | less
```
And searching for the above instances indicates they were removed as expected.
`ninja check check-functional`
Reviewers: #bitcoin_abc, deadalnix
Reviewed By: #bitcoin_abc, deadalnix
Differential Revision: https://reviews.bitcoinabc.org/D6516
…mespace if possible fb43415 Remove global symbols: Avoid using the global namespace if possible (practicalswift) Pull request description: Remove global symbols: Avoid using the global namespace if possible. Partially resolves bitcoin#15612 ("Reduce the number of global symbols used"). Change in global symbols as reported by `nm bitcoind` before vs after: ``` $ diff -u <(nm src/bitcoind-before | c++filt | grep -E '^[0-9a-f]+ [A-Z] ' | cut -f3- -d' ' | sort -u) \ <(nm src/bitcoind-after | c++filt | grep -E '^[0-9a-f]+ [A-Z] ' | cut -f3- -d' ' | sort -u) \ | grep -E '^[+-][^+-]' -boundSockets -cs_warnings -eventHTTP -fFeeEstimatesInitialized -fLargeWorkForkFound -fLargeWorkInvalidChainFound -pathHandlers -strMiscWarning[abi:cxx11] -threadHTTP ``` ACKs for commit fb4341: Tree-SHA512: d2f78f6188a992b0e0de8d107e2c494cfa0faa2de4fda634a1d3606d6515633bec86289cf2a2e78ffe467b17b795e2243cc459fb44e0dfe2fc69899506ff61c9
…mespace if possible fb43415 Remove global symbols: Avoid using the global namespace if possible (practicalswift) Pull request description: Remove global symbols: Avoid using the global namespace if possible. Partially resolves bitcoin#15612 ("Reduce the number of global symbols used"). Change in global symbols as reported by `nm bitcoind` before vs after: ``` $ diff -u <(nm src/bitcoind-before | c++filt | grep -E '^[0-9a-f]+ [A-Z] ' | cut -f3- -d' ' | sort -u) \ <(nm src/bitcoind-after | c++filt | grep -E '^[0-9a-f]+ [A-Z] ' | cut -f3- -d' ' | sort -u) \ | grep -E '^[+-][^+-]' -boundSockets -cs_warnings -eventHTTP -fFeeEstimatesInitialized -fLargeWorkForkFound -fLargeWorkInvalidChainFound -pathHandlers -strMiscWarning[abi:cxx11] -threadHTTP ``` ACKs for commit fb4341: Tree-SHA512: d2f78f6188a992b0e0de8d107e2c494cfa0faa2de4fda634a1d3606d6515633bec86289cf2a2e78ffe467b17b795e2243cc459fb44e0dfe2fc69899506ff61c9
Remove global symbols: Avoid using the global namespace if possible.
Partially resolves #15612 ("Reduce the number of global symbols used").
Change in global symbols as reported by
nm bitcoindbefore vs after: