X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Futil.cpp;h=a6065ef16cb20510e563a9298890efefe51c95be;hb=bd043f19c83654331e5418ea1e7af2bd213899a7;hp=24c7ed4487fd40e835fa93db730610d394c9a070;hpb=865ed8a1e5c587468a40756d46bcbc1c5a12bb06;p=novacoin.git diff --git a/src/util.cpp b/src/util.cpp index 24c7ed4..a6065ef 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,9 +1,20 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2011 The Bitcoin developers +// Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. #include "headers.h" #include "strlcpy.h" + +// Work around clang compilation problem in Boost 1.46: +// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup +// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options +// http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION +namespace boost { + namespace program_options { + std::string to_internal(const std::string&); + } +} + #include #include #include @@ -389,7 +400,7 @@ bool ParseMoney(const char* pszIn, int64& nRet) for (; *p; p++) if (!isspace(*p)) return false; - if (strWhole.size() > 14) + if (strWhole.size() > 10) // guard against 63 bit overflow return false; if (nUnits < 0 || nUnits > COIN) return false; @@ -410,7 +421,7 @@ vector ParseHex(const char* psz) 0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1, -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1 + -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, @@ -472,6 +483,23 @@ void ParseParameters(int argc, char* argv[]) } } +bool SoftSetArg(const std::string& strArg, const std::string& strValue) +{ + if (mapArgs.count(strArg)) + return false; + mapArgs[strArg] = strValue; + return true; +} + +bool SoftSetArg(const std::string& strArg, bool fValue) +{ + if (fValue) + return SoftSetArg(strArg, std::string("1")); + else + return SoftSetArg(strArg, std::string("0")); +} + + const char* wxGetTranslation(const char* pszEnglish) { @@ -626,26 +654,35 @@ string MyGetSpecialFolderPath(int nFolder, bool fCreate) { PSHGETSPECIALFOLDERPATHA pSHGetSpecialFolderPath = (PSHGETSPECIALFOLDERPATHA)GetProcAddress(hShell32, "SHGetSpecialFolderPathA"); + bool fSuccess = false; if (pSHGetSpecialFolderPath) + fSuccess = (*pSHGetSpecialFolderPath)(NULL, pszPath, nFolder, fCreate); FreeModule(hShell32); + if (fSuccess) + return pszPath; } // Backup option - if (pszPath[0] == '\0') + std::string strPath; { + const char *pszEnv; if (nFolder == CSIDL_STARTUP) { - strcpy(pszPath, getenv("USERPROFILE")); - strcat(pszPath, "\\Start Menu\\Programs\\Startup"); + pszEnv = getenv("USERPROFILE"); + if (pszEnv) + strPath = pszEnv; + strPath += "\\Start Menu\\Programs\\Startup"; } else if (nFolder == CSIDL_APPDATA) { - strcpy(pszPath, getenv("APPDATA")); + pszEnv = getenv("APPDATA"); + if (pszEnv) + strPath = pszEnv; } } - return pszPath; + return strPath; } #endif @@ -923,16 +960,22 @@ string FormatFullVersion() struct CLockLocation { - std::string mutexName; - std::string sourceFile; - int sourceLine; - CLockLocation(const char* pszName, const char* pszFile, int nLine) { mutexName = pszName; sourceFile = pszFile; sourceLine = nLine; } + + std::string ToString() const + { + return mutexName+" "+sourceFile+":"+itostr(sourceLine); + } + +private: + std::string mutexName; + std::string sourceFile; + int sourceLine; }; typedef std::vector< std::pair > LockStack; @@ -942,18 +985,22 @@ static std::map, LockStack> lock static boost::thread_specific_ptr lockstack; -static void potential_deadlock_detected(const LockStack& s1, const LockStack& s2) +static void potential_deadlock_detected(const std::pair& mismatch, const LockStack& s1, const LockStack& s2) { printf("POTENTIAL DEADLOCK DETECTED\n"); printf("Previous lock order was:\n"); BOOST_FOREACH(const PAIRTYPE(CCriticalSection*, CLockLocation)& i, s2) { - printf(" %s %s:%d\n", i.second.mutexName.c_str(), i.second.sourceFile.c_str(), i.second.sourceLine); + if (i.first == mismatch.first) printf(" (1)"); + if (i.first == mismatch.second) printf(" (2)"); + printf(" %s\n", i.second.ToString().c_str()); } printf("Current lock order is:\n"); BOOST_FOREACH(const PAIRTYPE(CCriticalSection*, CLockLocation)& i, s1) { - printf(" %s %s:%d\n", i.second.mutexName.c_str(), i.second.sourceFile.c_str(), i.second.sourceLine); + if (i.first == mismatch.first) printf(" (1)"); + if (i.first == mismatch.second) printf(" (2)"); + printf(" %s\n", i.second.ToString().c_str()); } } @@ -963,6 +1010,7 @@ static void push_lock(CCriticalSection* c, const CLockLocation& locklocation) if (lockstack.get() == NULL) lockstack.reset(new LockStack); + if (fDebug) printf("Locking: %s\n", locklocation.ToString().c_str()); dd_mutex.lock(); (*lockstack).push_back(std::make_pair(c, locklocation)); @@ -979,7 +1027,7 @@ static void push_lock(CCriticalSection* c, const CLockLocation& locklocation) std::pair p2 = std::make_pair(c, i.first); if (lockorders.count(p2)) { - potential_deadlock_detected(lockorders[p2], lockorders[p1]); + potential_deadlock_detected(p1, lockorders[p2], lockorders[p1]); break; } } @@ -988,7 +1036,14 @@ static void push_lock(CCriticalSection* c, const CLockLocation& locklocation) static void pop_lock() { + if (fDebug) + { + const CLockLocation& locklocation = (*lockstack).rbegin()->second; + printf("Unlocked: %s\n", locklocation.ToString().c_str()); + } + dd_mutex.lock(); (*lockstack).pop_back(); + dd_mutex.unlock(); } void CCriticalSection::Enter(const char* pszName, const char* pszFile, int nLine)