From ad383b274db2696cf2d4bdea9d477c463992f2fc Mon Sep 17 00:00:00 2001 From: Conor Burgess Date: Thu, 7 Dec 2017 10:53:13 +0000 Subject: [PATCH 1/3] Fix value pointed to by `_NSGetArgc()` on macOS --- googletest/src/gtest.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 749e8299..41ed48bb 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -146,6 +146,12 @@ # define vsnprintf _vsnprintf #endif // GTEST_OS_WINDOWS +#if GTEST_OS_MAC +# ifndef GTEST_OS_IOS +# include +# endif +#endif + namespace testing { using internal::CountIf; @@ -5341,6 +5347,16 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { } } +// Fix the value of *_NSGetArgc() on macOS, but iff +// *_NSGetArgv() == argv +#if GTEST_OS_MAC +# ifndef GTEST_OS_IOS + if (*_NSGetArgv() == argv) { + *_NSGetArgc() = *argc; + } +# endif +#endif + if (g_help_flag) { // We print the help here instead of in RUN_ALL_TESTS(), as the // latter may not be called at all if the user is using Google From 4d50715c2bf9c727573a397cfb02bd551d4aa3b0 Mon Sep 17 00:00:00 2001 From: Conor Burgess Date: Thu, 7 Dec 2017 11:49:33 +0000 Subject: [PATCH 2/3] Fix location of `_NSGetArgv` correction. --- googletest/src/gtest.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 41ed48bb..3c94381c 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5347,16 +5347,6 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { } } -// Fix the value of *_NSGetArgc() on macOS, but iff -// *_NSGetArgv() == argv -#if GTEST_OS_MAC -# ifndef GTEST_OS_IOS - if (*_NSGetArgv() == argv) { - *_NSGetArgc() = *argc; - } -# endif -#endif - if (g_help_flag) { // We print the help here instead of in RUN_ALL_TESTS(), as the // latter may not be called at all if the user is using Google @@ -5369,6 +5359,17 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { // other parts of Google Test. void ParseGoogleTestFlagsOnly(int* argc, char** argv) { ParseGoogleTestFlagsOnlyImpl(argc, argv); + + // Fix the value of *_NSGetArgc() on macOS, but iff + // *_NSGetArgv() == argv + // Only applicable to char** version of argv +#if GTEST_OS_MAC +# ifndef GTEST_OS_IOS + if (*_NSGetArgv() == argv) { + *_NSGetArgc() = *argc; + } +# endif +#endif } void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv) { ParseGoogleTestFlagsOnlyImpl(argc, argv); From 88cd66513c6414cdc6f1d4f7733bd520337864a9 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 17 Aug 2018 13:25:52 -0400 Subject: [PATCH 3/3] Minor formatting/style changes --- googletest/src/gtest.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 7832aa31..a229549f 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -138,11 +138,10 @@ # define vsnprintf _vsnprintf #endif // GTEST_OS_WINDOWS - #if GTEST_OS_MAC -# ifndef GTEST_OS_IOS -# include -# endif +#ifndef GTEST_OS_IOS +#include +#endif #endif #if GTEST_HAS_ABSL @@ -5832,16 +5831,16 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { // other parts of Google Test. void ParseGoogleTestFlagsOnly(int* argc, char** argv) { ParseGoogleTestFlagsOnlyImpl(argc, argv); - - // Fix the value of *_NSGetArgc() on macOS, but iff + + // Fix the value of *_NSGetArgc() on macOS, but iff // *_NSGetArgv() == argv // Only applicable to char** version of argv #if GTEST_OS_MAC -# ifndef GTEST_OS_IOS +#ifndef GTEST_OS_IOS if (*_NSGetArgv() == argv) { *_NSGetArgc() = *argc; } -# endif +#endif #endif } void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv) {