Skip to content

Commit a50219b

Browse files
authored
Update util.h
1 parent a79ed4d commit a50219b

File tree

1 file changed

+60
-14
lines changed

1 file changed

+60
-14
lines changed

src/util.h

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,33 @@ static const int64_t CENT = 1000000;
5656
#define UINTBEGIN(a) ((uint32_t*)&(a))
5757
#define CUINTBEGIN(a) ((const uint32_t*)&(a))
5858

59+
#ifndef PRId64
60+
#if defined(_MSC_VER) || defined(__MSVCRT__)
61+
#define PRIu64 "I64u"
62+
#define PRId64 "I64d"
63+
#define PRIx64 "I64x"
64+
#else
65+
#define PRId64 "lld"
66+
#define PRIu64 "llu"
67+
#define PRIx64 "llx"
68+
#endif
69+
#endif
70+
71+
#ifndef THROW_WITH_STACKTRACE
72+
#define THROW_WITH_STACKTRACE(exception) \
73+
{ \
74+
LogStackTrace(); \
75+
throw (exception); \
76+
}
77+
void LogStackTrace();
78+
#endif
79+
5980
/* Format characters for (s)size_t and ptrdiff_t */
6081
#if defined(_MSC_VER) || defined(__MSVCRT__)
6182
/* (s)size_t and ptrdiff_t have the same size specifier in MSVC:
6283
http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.100%29.aspx
6384
*/
85+
6486
#define PRIszx "Ix"
6587
#define PRIszu "Iu"
6688
#define PRIszd "Id"
@@ -74,13 +96,6 @@ static const int64_t CENT = 1000000;
7496
#define PRIpdx "tx"
7597
#define PRIpdu "tu"
7698
#define PRIpdd "td"
77-
#undef PRIu64
78-
#undef PRId64
79-
#undef PRIx64
80-
81-
#define PRIu64 "I64u"
82-
#define PRId64 "I64d"
83-
#define PRIx64 "I64x"
8499
#endif
85100

86101
// This is needed because the foreach macro can't get over the comma in pair<t1, t2>
@@ -110,6 +125,8 @@ T* alignup(T* p)
110125
#endif
111126
#else
112127
#define MAX_PATH 1024
128+
#endif
129+
113130
inline void Sleep(int64_t n)
114131
{
115132
/*Boost has a year 2038 problem— if the request sleep time is past epoch+2^31 seconds the sleep returns instantly.
@@ -131,21 +148,56 @@ inline void Sleep(int64_t n)
131148

132149

133150

151+
152+
153+
154+
134155
extern std::map<std::string, std::string> mapArgs;
135156
extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
136157
extern bool fDebug;
158+
extern bool fDebugNet;
137159
extern bool fPrintToConsole;
138160
extern bool fPrintToDebugLog;
161+
extern bool fRequestShutdown;
162+
extern bool fShutdown;
139163
extern bool fDaemon;
140164
extern bool fServer;
141165
extern bool fCommandLine;
142166
extern std::string strMiscWarning;
167+
extern bool fTestNet;
143168
extern bool fNoListen;
144169
extern bool fLogTimestamps;
145170
extern volatile bool fReopenDebugLog;
146171

147172
void RandAddSeed();
148173
void RandAddSeedPerfmon();
174+
int ATTR_WARN_PRINTF(1,2) OutputDebugStringF(const char* pszFormat, ...);
175+
176+
/*
177+
Rationale for the real_strprintf / strprintf construction:
178+
It is not allowed to use va_start with a pass-by-reference argument.
179+
(C++ standard, 18.7, paragraph 3). Use a dummy argument to work around this, and use a
180+
macro to keep similar semantics.
181+
*/
182+
183+
/** Overload strprintf for char*, so that GCC format type warnings can be given */
184+
std::string ATTR_WARN_PRINTF(1,3) real_strprintf(const char *format, int dummy, ...);
185+
/** Overload strprintf for std::string, to be able to use it with _ (translation).
186+
* This will not support GCC format type warnings (-Wformat) so be careful.
187+
*/
188+
std::string real_strprintf(const std::string &format, int dummy, ...);
189+
#define strprintf(format, ...) real_strprintf(format, 0, __VA_ARGS__)
190+
std::string vstrprintf(const char *format, va_list ap);
191+
192+
bool ATTR_WARN_PRINTF(1,2) error(const char *format, ...);
193+
194+
/* Redefine printf so that it directs output to debug.log
195+
*
196+
* Do this *after* defining the other printf-like functions, because otherwise the
197+
* __attribute__((format(printf,X,Y))) gets expanded to __attribute__((format(OutputDebugStringF,X,Y)))
198+
* which confuses gcc.
199+
*/
200+
#define printf OutputDebugStringF
149201

150202
/* Return true if log accepts specified category */
151203
bool LogAcceptCategory(const char* category);
@@ -189,7 +241,6 @@ static inline bool error(const char* format)
189241
return false;
190242
}
191243

192-
193244
void PrintException(std::exception* pex, const char* pszThread);
194245
void PrintExceptionContinue(std::exception* pex, const char* pszThread);
195246
void ParseString(const std::string& str, char c, std::vector<std::string>& v);
@@ -231,14 +282,9 @@ uint256 GetRandHash();
231282
int64_t GetTime();
232283
int64_t GetTimeMillis();
233284
int64_t GetTimeMicros();
234-
void SetMockTime(int64_t nMockTimeIn);
235-
std::string FormatFullVersion();
236-
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
237-
void runCommand(std::string strCommand);
238-
239285
int64_t GetAdjustedTime();
240286
int64_t GetTimeOffset();
241-
int64_t GetNodesOffset();
287+
void SetMockTime(int64_t nMockTimeIn);
242288
std::string FormatFullVersion();
243289
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
244290
void AddTimeData(const CNetAddr& ip, int64_t nTime);

0 commit comments

Comments
 (0)