Skip to content

Commit

Permalink
Remove _GNU_SOURCE flag from APPLE builds
Browse files Browse the repository at this point in the history
_GNU_SOURCE should not have been defined in the first place for OSX, and
then it should have defaulted to using non-thread-specific locale. This
fixes future such problems.

In this case the Linux and apple interface to thread-specific locale
seems to be the same, why I keep the xlocale header instead of
defaulting to process-specific.
  • Loading branch information
filip-stenstrom committed Apr 27, 2021
1 parent 1ab7ac6 commit fad9c6d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ endif()
if(FMILIB_BUILD_SHARED_LIB)
add_library(fmilib_shared SHARED ${FMILIB_SHARED_SRC})

if (UNIX)
if (UNIX AND NOT APPLE)
target_compile_definitions(fmilib_shared PRIVATE -D_GNU_SOURCE)
endif()

Expand Down
5 changes: 4 additions & 1 deletion Config.cmake/jmutil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ endif(CYGWIN)

target_link_libraries(jmutils c99snprintf)

if(UNIX)
if(UNIX AND NOT APPLE)
target_compile_definitions(jmutils PRIVATE -D_GNU_SOURCE)
endif()

if(UNIX)
target_link_libraries(jmutils dl)
endif(UNIX)
if(WIN32)
Expand Down
12 changes: 9 additions & 3 deletions src/Util/src/JM/jm_portability.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
#include <string.h>

#include <locale.h>

#if defined(_GNU_SOURCE) || defined(__APPLE__)
#define UNIX_THREAD_LOCALE
#endif

#ifdef __APPLE__
/* Include thread-specific locale functions for OSX. */
#include <xlocale.h>
#endif

Expand Down Expand Up @@ -361,7 +367,7 @@ int jm_snprintf(char * str, size_t size, const char * fmt, ...) {
}

struct jm_locale_t {
#ifdef _GNU_SOURCE
#ifdef UNIX_THREAD_LOCALE
locale_t locale_old;
#else
char* locale_old;
Expand All @@ -379,7 +385,7 @@ jm_locale_t* jm_setlocale_numeric(jm_callbacks* cb, const char* value) {
return NULL;
}

#ifdef _GNU_SOURCE
#ifdef UNIX_THREAD_LOCALE
{
locale_t nloc = NULL;

Expand Down Expand Up @@ -450,7 +456,7 @@ int jm_resetlocale_numeric(jm_callbacks* cb, jm_locale_t* jmloc) {
return 1; /* impl. error */
}

#ifdef _GNU_SOURCE
#ifdef UNIX_THREAD_LOCALE
{
/* Get current locale, which is expected to have been set with a previous
* call to 'jm_setlocale_numeric'. */
Expand Down

0 comments on commit fad9c6d

Please sign in to comment.