Skip to content

Commit 0b68fca

Browse files
author
MarcoFalke
committed
Merge #16092: Don't use global (external) symbols for symbols that are used in only one translation unit
0959d37 Don't use global (external) symbols for symbols that are used in only one translation unit (practicalswift) Pull request description: Don't use global (external) symbols for symbols that are used in only one translation unit. Before: ``` $ for SYMBOL in $(nm src/bitcoind | grep -E ' [BD] ' | c++filt | cut -f3- -d' ' | grep -v @ | grep -v : | sort | grep '[a-z]' | sort -u | grep -vE '(^_|typeinfo|vtable)'); do REFERENCES=$(git grep -lE "([^a-zA-Z]|^)${SYMBOL}([^a-zA-Z]|\$)" -- "*.cpp" "*.h") N_REFERENCES=$(wc -l <<< "${REFERENCES}") if [[ ${N_REFERENCES} > 1 ]]; then continue fi echo "Global symbol ${SYMBOL} is used in only one translation unit: ${REFERENCES}" done Global symbol g_chainstate is used in only one translation unit: src/validation.cpp Global symbol g_ui_signals is used in only one translation unit: src/ui_interface.cpp Global symbol instance_of_cmaincleanup is used in only one translation unit: src/validation.cpp Global symbol instance_of_cnetcleanup is used in only one translation unit: src/net.cpp Global symbol instance_of_cnetprocessingcleanup is used in only one translation unit: src/net_processing.cpp Global symbol pindexBestForkBase is used in only one translation unit: src/validation.cpp Global symbol pindexBestForkTip is used in only one translation unit: src/validation.cpp $ ``` After: ``` $ for SYMBOL in $(nm src/bitcoind | grep -E ' [BD] ' | c++filt | cut -f3- -d' ' | grep -v @ | grep -v : | sort | grep '[a-z]' | sort -u | grep -vE '(^_|typeinfo|vtable)'); do REFERENCES=$(git grep -lE "([^a-zA-Z]|^)${SYMBOL}([^a-zA-Z]|\$)" -- "*.cpp" "*.h") N_REFERENCES=$(wc -l <<< "${REFERENCES}") if [[ ${N_REFERENCES} > 1 ]]; then continue fi echo "Global symbol ${SYMBOL} is used in only one translation unit: ${REFERENCES}" done $ ``` ♻️ Think about future generations: save the global namespace from unnecessary pollution! ♻️ ACKs for commit 0959d3: Empact: ACK bitcoin/bitcoin@0959d37 MarcoFalke: ACK 0959d37 hebasto: ACK 0959d37 promag: ACK 0959d37. Tree-SHA512: 722f66bb50450f19b57e8a8fbe949f30cd651eb8564e5787cbb772a539bf3a288c048dc49e655fd73ece6a46f6dafade515ec4004729bf2b3ab83117b7c5d153
2 parents 0853d8d + 0959d37 commit 0b68fca

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/net.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,8 +2287,8 @@ class CNetCleanup
22872287
WSACleanup();
22882288
#endif
22892289
}
2290-
}
2291-
instance_of_cnetcleanup;
2290+
};
2291+
static CNetCleanup instance_of_cnetcleanup;
22922292

22932293
void CConnman::Interrupt()
22942294
{

src/net_processing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4086,4 +4086,5 @@ class CNetProcessingCleanup
40864086
mapOrphanTransactions.clear();
40874087
mapOrphanTransactionsByPrev.clear();
40884088
}
4089-
} instance_of_cnetprocessingcleanup;
4089+
};
4090+
static CNetProcessingCleanup instance_of_cnetprocessingcleanup;

src/ui_interface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ struct UISignals {
2121
boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip;
2222
boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip;
2323
boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
24-
} g_ui_signals;
24+
};
25+
static UISignals g_ui_signals;
2526

2627
#define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \
2728
boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \

src/validation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bool CBlockIndexWorkComparator::operator()(const CBlockIndex *pa, const CBlockIn
7777
return false;
7878
}
7979

80-
CChainState g_chainstate;
80+
static CChainState g_chainstate;
8181

8282
CChainState& ChainstateActive() { return g_chainstate; }
8383

@@ -1044,7 +1044,7 @@ bool CChainState::IsInitialBlockDownload() const
10441044
return false;
10451045
}
10461046

1047-
CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr;
1047+
static CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr;
10481048

10491049
static void AlertNotify(const std::string& strMessage)
10501050
{
@@ -4757,4 +4757,5 @@ class CMainCleanup
47574757
delete (*it1).second;
47584758
mapBlockIndex.clear();
47594759
}
4760-
} instance_of_cmaincleanup;
4760+
};
4761+
static CMainCleanup instance_of_cmaincleanup;

0 commit comments

Comments
 (0)