From 16babcc6bc9469d08dee4bfec8c99e4c9788223a Mon Sep 17 00:00:00 2001 From: WHR Date: Tue, 30 Oct 2018 18:41:59 +0800 Subject: [PATCH 1/2] Fix impossible to build for OS X without clang --- src/common/Platform_mac.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/common/Platform_mac.cpp b/src/common/Platform_mac.cpp index d0c533b0..c974d90d 100644 --- a/src/common/Platform_mac.cpp +++ b/src/common/Platform_mac.cpp @@ -46,9 +46,16 @@ char *Platform::createUserAgent() # ifdef XMRIG_NVIDIA_PROJECT const int cudaVersion = cuda_get_runtime_version(); - snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s CUDA/%d.%d clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), cudaVersion / 1000, cudaVersion % 100, __clang_major__, __clang_minor__, __clang_patchlevel__); + snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s CUDA/%d.%d", APP_NAME, APP_VERSION, uv_version_string(), cudaVersion / 1000, cudaVersion % 100); # else - snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), __clang_major__, __clang_minor__, __clang_patchlevel__); + snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s", APP_NAME, APP_VERSION, uv_version_string()); +# endif +# ifdef __clang__ + size_t i = strlen(buf); + snprintf(buf + i, max - i, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); +# elif defined(__GNUC__) + size_t i = strlen(buf); + snprintf(buf + i, max - i, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); # endif return buf; From c06f77b9e9233c70b0614e7bfbdcb6404d700c82 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 20 Nov 2018 08:18:39 +0700 Subject: [PATCH 2/2] Better compiler name and version handling on Linux and macOS for user-agent string. --- src/common/Platform_mac.cpp | 16 +++++++--------- src/common/Platform_unix.cpp | 8 +++++--- src/common/Platform_win.cpp | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/common/Platform_mac.cpp b/src/common/Platform_mac.cpp index 3855a6e3..4e4aa0ad 100644 --- a/src/common/Platform_mac.cpp +++ b/src/common/Platform_mac.cpp @@ -40,22 +40,20 @@ char *Platform::createUserAgent() { - const size_t max = 160; + constexpr const size_t max = 256; - char *buf = new char[max]; + char *buf = new char[max](); + int length = snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s", APP_NAME, APP_VERSION, uv_version_string()); # ifdef XMRIG_NVIDIA_PROJECT const int cudaVersion = cuda_get_runtime_version(); - snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s CUDA/%d.%d", APP_NAME, APP_VERSION, uv_version_string(), cudaVersion / 1000, cudaVersion % 100); -# else - snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s", APP_NAME, APP_VERSION, uv_version_string()); + length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100); # endif + # ifdef __clang__ - size_t i = strlen(buf); - snprintf(buf + i, max - i, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); + length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); # elif defined(__GNUC__) - size_t i = strlen(buf); - snprintf(buf + i, max - i, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); + length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); # endif return buf; diff --git a/src/common/Platform_unix.cpp b/src/common/Platform_unix.cpp index 1263b846..901df4be 100644 --- a/src/common/Platform_unix.cpp +++ b/src/common/Platform_unix.cpp @@ -54,9 +54,9 @@ typedef cpuset_t cpu_set_t; char *Platform::createUserAgent() { - const size_t max = 160; + constexpr const size_t max = 256; - char *buf = new char[max]; + char *buf = new char[max](); int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION); # if defined(__x86_64__) @@ -70,7 +70,9 @@ char *Platform::createUserAgent() length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100); # endif -# ifdef __GNUC__ +# ifdef __clang__ + length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); +# elif defined(__GNUC__) length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); # endif diff --git a/src/common/Platform_win.cpp b/src/common/Platform_win.cpp index d220f58d..3fa7ea9a 100644 --- a/src/common/Platform_win.cpp +++ b/src/common/Platform_win.cpp @@ -63,9 +63,9 @@ static inline OSVERSIONINFOEX winOsVersion() char *Platform::createUserAgent() { const auto osver = winOsVersion(); - const size_t max = 160; + constexpr const size_t max = 256; - char *buf = new char[max]; + char *buf = new char[max](); int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion); # if defined(__x86_64__) || defined(_M_AMD64)