Merge #16092: Don't use global (external) symbols for symbols that are used in only one translation unit

0959d37e3e 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 0959d37e3e
  MarcoFalke:
    ACK 0959d37e3e
  hebasto:
    ACK 0959d37e3e
  promag:
    ACK 0959d37.

Tree-SHA512: 722f66bb50450f19b57e8a8fbe949f30cd651eb8564e5787cbb772a539bf3a288c048dc49e655fd73ece6a46f6dafade515ec4004729bf2b3ab83117b7c5d153
This commit is contained in:
MarcoFalke 2019-06-18 15:59:40 -04:00
commit 0b68fca700
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
4 changed files with 10 additions and 7 deletions

View file

@ -2287,8 +2287,8 @@ public:
WSACleanup(); WSACleanup();
#endif #endif
} }
} };
instance_of_cnetcleanup; static CNetCleanup instance_of_cnetcleanup;
void CConnman::Interrupt() void CConnman::Interrupt()
{ {

View file

@ -4086,4 +4086,5 @@ public:
mapOrphanTransactions.clear(); mapOrphanTransactions.clear();
mapOrphanTransactionsByPrev.clear(); mapOrphanTransactionsByPrev.clear();
} }
} instance_of_cnetprocessingcleanup; };
static CNetProcessingCleanup instance_of_cnetprocessingcleanup;

View file

@ -21,7 +21,8 @@ struct UISignals {
boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip; boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip;
boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip; boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip;
boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged; boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
} g_ui_signals; };
static UISignals g_ui_signals;
#define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \ #define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \
boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \ boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \

View file

@ -77,7 +77,7 @@ bool CBlockIndexWorkComparator::operator()(const CBlockIndex *pa, const CBlockIn
return false; return false;
} }
CChainState g_chainstate; static CChainState g_chainstate;
CChainState& ChainstateActive() { return g_chainstate; } CChainState& ChainstateActive() { return g_chainstate; }
@ -1044,7 +1044,7 @@ bool CChainState::IsInitialBlockDownload() const
return false; return false;
} }
CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr; static CBlockIndex *pindexBestForkTip = nullptr, *pindexBestForkBase = nullptr;
static void AlertNotify(const std::string& strMessage) static void AlertNotify(const std::string& strMessage)
{ {
@ -4757,4 +4757,5 @@ public:
delete (*it1).second; delete (*it1).second;
mapBlockIndex.clear(); mapBlockIndex.clear();
} }
} instance_of_cmaincleanup; };
static CMainCleanup instance_of_cmaincleanup;