Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginDebug.cpp

Issue 29332020: Noissue - Add tracing function 'ToHexLiteral()' (Closed)
Patch Set: fix error messages Created Dec. 21, 2015, 12:51 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/plugin/PluginDebug.h ('k') | test/plugin/DebugTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginDebug.cpp
===================================================================
--- a/src/plugin/PluginDebug.cpp
+++ b/src/plugin/PluginDebug.cpp
@@ -20,6 +20,7 @@
#include "PluginClientBase.h"
#include "PluginMutex.h"
#include "PluginSettings.h"
+#include <cstdint>
class CPluginDebugLock : public CPluginMutex
{
@@ -256,3 +257,29 @@
}
#endif // ENABLE_DEBUG_RESULT_IGNORED
+
+namespace
+{
+ /*
+ * To convert a pointer to a hexadecimal number, we need an integral type that has the same size as that of the pointer.
+ */
+#if defined(_WIN64)
+ typedef uint64_t voidIntegral;
+ static_assert(sizeof(void*)==sizeof(voidIntegral),"WIN64: sizeof(uint64_t) is not the same as sizeof(void*)");
+#elif defined(_WIN32)
+ typedef uint32_t voidIntegral;
+ static_assert(sizeof(void*)==sizeof(voidIntegral),"WIN32: sizeof(uint32_t) is not the same as sizeof(void*)");
+#else
+#error Must compile with either _WIN32 or _WIN64
+#endif
+}
+
+std::wstring ToHexLiteral(void const* p)
sergei 2016/01/05 10:55:27 How does it happen that in header it's `const void
Eric 2016/01/05 14:38:26 Not using copy-paste, in all likelihood. I really
+{
+ std::wstringstream ss;
+ ss << L"0x";
+ ss.width(sizeof(p) * 2);
+ ss.fill(L'0');
+ ss << std::hex << reinterpret_cast<voidIntegral>(p);
+ return ss.str();
+}
« no previous file with comments | « src/plugin/PluginDebug.h ('k') | test/plugin/DebugTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld