From 06a8ee0976ac0214d9f3493ce57b6f7151e1803f Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Wed, 28 Jun 2017 11:08:45 +0200 Subject: [PATCH 1/6] logging: fix basetsd on case sensitive sytems --- src/logging.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logging.cc b/src/logging.cc index 397e106..7b33cae 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -183,7 +183,7 @@ GLOG_DEFINE_string(log_backtrace_at, "", #ifndef HAVE_PREAD #if defined(OS_WINDOWS) -#include +#include #define ssize_t SSIZE_T #endif static ssize_t pread(int fd, void* buf, size_t count, off_t offset) { From d354e2e8f9e74eaf359a777d7690a282f93e691f Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Fri, 1 Sep 2017 09:42:44 +0200 Subject: [PATCH 2/6] mingw-w64: fix dbghelp on case sensitive systems - fix dbhelp.h include - fix dbghelp check and link --- CMakeLists.txt | 4 ++-- src/demangle.cc | 4 ++-- src/symbolize.cc | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48bd3e5..6d7e573 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,7 @@ check_cxx_compiler_flag (-Wunnamed-type-template-args check_symbol_exists (snprintf stdio.h HAVE_SNPRINTF) check_library_exists (unwind get_static_proc_name "" HAVE_LIB_UNWIND) -check_library_exists (DbgHelp UnDecorateSymbolName "" HAVE_DBGHELP) +check_library_exists (dbghelp UnDecorateSymbolName "" HAVE_DBGHELP) find_library (UNWIND_LIBRARY NAMES unwind DOC "unwind library") mark_as_advanced (UNWIND_LIBRARY) @@ -456,7 +456,7 @@ if (UNWIND_LIBRARY) endif (UNWIND_LIBRARY) if (HAVE_DBGHELP) - target_link_libraries (glog PUBLIC DbgHelp) + target_link_libraries (glog PUBLIC dbghelp) endif (HAVE_DBGHELP) if (HAVE_PTHREAD) diff --git a/src/demangle.cc b/src/demangle.cc index 4b33580..d7b3af1 100644 --- a/src/demangle.cc +++ b/src/demangle.cc @@ -39,8 +39,8 @@ #include "demangle.h" #if defined(OS_WINDOWS) -#include -#pragma comment(lib, "DbgHelp") +#include +#pragma comment(lib, "dbghelp") #endif _START_GOOGLE_NAMESPACE_ diff --git a/src/symbolize.cc b/src/symbolize.cc index 1f1492d..a950365 100644 --- a/src/symbolize.cc +++ b/src/symbolize.cc @@ -847,10 +847,10 @@ _END_GOOGLE_NAMESPACE_ #elif defined(OS_WINDOWS) || defined(OS_CYGWIN) #include -#include +#include #ifdef _MSC_VER -#pragma comment(lib, "DbgHelp") +#pragma comment(lib, "dbghelp") #endif _START_GOOGLE_NAMESPACE_ From 0797f7382bd44861cc8037444b7685fee08db006 Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Fri, 1 Sep 2017 10:40:46 +0200 Subject: [PATCH 3/6] mingw-w64: fix port.h pthread recreation --- src/windows/port.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/windows/port.h b/src/windows/port.h index 8198461..7928ff4 100755 --- a/src/windows/port.h +++ b/src/windows/port.h @@ -136,19 +136,21 @@ typedef int pid_t; #endif // _MSC_VER // ----------------------------------- THREADS -#ifndef __MINGW32__ +#if defined(HAVE_PTHREAD) +# include +#else // no PTHREAD typedef DWORD pthread_t; typedef DWORD pthread_key_t; typedef LONG pthread_once_t; enum { PTHREAD_ONCE_INIT = 0 }; // important that this be 0! for SpinLock #define pthread_self GetCurrentThreadId #define pthread_equal(pthread_t_1, pthread_t_2) ((pthread_t_1)==(pthread_t_2)) +#endif // HAVE_PTHREAD inline struct tm* localtime_r(const time_t* timep, struct tm* result) { localtime_s(result, timep); return result; } -#endif inline char* strerror_r(int errnum, char* buf, size_t buflen) { strerror_s(buf, buflen, errnum); From 7450a8b34540ac231313559b9370041e30d97163 Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Wed, 23 May 2018 11:17:27 +0200 Subject: [PATCH 4/6] mingw-w64: check if localtime_r exists - check in cmake if localtime_r exists - if localtime_r is missing (MSVC, mingw-w64 on linux) redefine it using localtime_s --- CMakeLists.txt | 12 ++++++++++++ src/config.h.cmake.in | 3 +++ src/windows/port.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d7e573..7cb6cf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -386,6 +386,18 @@ elseif (UNIX OR (APPLE AND HAVE_DLADDR)) set (HAVE_SYMBOLIZE 1) endif (WIN32 OR CYGWIN) +check_cxx_source_compiles (" +#include +#include +int main() +{ + time_t timep; + struct tm result; + localtime_r(&timep, &result); + return EXIT_SUCCESS; +} +" HAVE_LOCALTIME_R) + set (SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) if (WITH_THREADS AND Threads_FOUND) diff --git a/src/config.h.cmake.in b/src/config.h.cmake.in index 14924fa..d5c281c 100644 --- a/src/config.h.cmake.in +++ b/src/config.h.cmake.in @@ -136,6 +136,9 @@ /* define if symbolize support is available */ #cmakedefine HAVE_SYMBOLIZE +/* define if localtime_r is available in time.h */ +#cmakedefine HAVE_LOCALTIME_R + /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #cmakedefine LT_OBJDIR diff --git a/src/windows/port.h b/src/windows/port.h index 7928ff4..c7895dd 100755 --- a/src/windows/port.h +++ b/src/windows/port.h @@ -147,10 +147,12 @@ enum { PTHREAD_ONCE_INIT = 0 }; // important that this be 0! for SpinLock #define pthread_equal(pthread_t_1, pthread_t_2) ((pthread_t_1)==(pthread_t_2)) #endif // HAVE_PTHREAD +#ifndef HAVE_LOCALTIME_R inline struct tm* localtime_r(const time_t* timep, struct tm* result) { localtime_s(result, timep); return result; } +#endif inline char* strerror_r(int errnum, char* buf, size_t buflen) { strerror_s(buf, buflen, errnum); From 800bd423e4e0e423249fcb0545edaf5f8c9b8a92 Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Fri, 1 Jun 2018 10:14:20 +0200 Subject: [PATCH 5/6] port: split localtime_r definition and impl --- src/windows/port.cc | 6 ++++++ src/windows/port.h | 7 ++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/windows/port.cc b/src/windows/port.cc index d994325..aa8dcd8 100755 --- a/src/windows/port.cc +++ b/src/windows/port.cc @@ -55,6 +55,12 @@ int safe_vsnprintf(char *str, size_t size, const char *format, va_list ap) { return _vsnprintf(str, size-1, format, ap); } +#ifndef HAVE_LOCALTIME_R +struct tm* localtime_r(const time_t* timep, struct tm* result) { + localtime_s(result, timep); + return result; +} +#endif // not HAVE_LOCALTIME_R #ifndef HAVE_SNPRINTF int snprintf(char *str, size_t size, const char *format, ...) { va_list ap; diff --git a/src/windows/port.h b/src/windows/port.h index c7895dd..56b172b 100755 --- a/src/windows/port.h +++ b/src/windows/port.h @@ -148,11 +148,8 @@ enum { PTHREAD_ONCE_INIT = 0 }; // important that this be 0! for SpinLock #endif // HAVE_PTHREAD #ifndef HAVE_LOCALTIME_R -inline struct tm* localtime_r(const time_t* timep, struct tm* result) { - localtime_s(result, timep); - return result; -} -#endif +extern struct tm* GOOGLE_GLOG_DLL_DECL localtime_r(const time_t* timep, struct tm* result); +#endif // not HAVE_LOCALTIME_R inline char* strerror_r(int errnum, char* buf, size_t buflen) { strerror_s(buf, buflen, errnum); From 364fad56493ce3e9be50218577a69a3ca4255e26 Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Fri, 1 Jun 2018 10:51:47 +0200 Subject: [PATCH 6/6] port: remove unused includes --- src/windows/port.cc | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/windows/port.cc b/src/windows/port.cc index aa8dcd8..19bda36 100755 --- a/src/windows/port.cc +++ b/src/windows/port.cc @@ -38,15 +38,8 @@ #include "config.h" #include // for va_list, va_start, va_end -#include // for strstr() -#include -#include -#include #include "port.h" -using std::string; -using std::vector; - // These call the windows _vsnprintf, but always NUL-terminate. int safe_vsnprintf(char *str, size_t size, const char *format, va_list ap) { if (size == 0) // not even room for a \0?