From 2028f2854fd5b01fe71d3bac1909a031fd5a9d00 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 23 Dec 2019 08:55:35 +0100 Subject: [PATCH] setlocale-null: Export the lock function also on non-Windows platforms. * lib/setlocale-lock.c (DLL_EXPORTED): New macro. (gl_get_setlocale_null_lock): Declare as DLL_EXPORTED. * m4/setlocale_null.m4 (gl_PREREQ_SETLOCALE_LOCK): New macro. * modules/setlocale-null (configure.ac): Invoke it. (Files): Add m4/visibility.m4. --- ChangeLog | 9 +++++++++ lib/setlocale-lock.c | 24 +++++++++++++++++++----- m4/setlocale_null.m4 | 6 ++++++ modules/setlocale-null | 2 ++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47cbfb2cdf..e0ecf87b78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2019-12-23 Bruno Haible + + setlocale-null: Export the lock function also on non-Windows platforms. + * lib/setlocale-lock.c (DLL_EXPORTED): New macro. + (gl_get_setlocale_null_lock): Declare as DLL_EXPORTED. + * m4/setlocale_null.m4 (gl_PREREQ_SETLOCALE_LOCK): New macro. + * modules/setlocale-null (configure.ac): Invoke it. + (Files): Add m4/visibility.m4. + 2019-12-22 Paul Eggert gethrxtime: fix rounding bug with negative args diff --git a/lib/setlocale-lock.c b/lib/setlocale-lock.c index 9c47afc9ec..60c1ba32a8 100644 --- a/lib/setlocale-lock.c +++ b/lib/setlocale-lock.c @@ -25,6 +25,19 @@ /* Prohibit renaming this symbol. */ #undef gl_get_setlocale_null_lock +/* Macro for exporting a symbol (function, not variable) defined in this file, + when compiled into a shared library. */ +#ifndef DLL_EXPORTED +# if HAVE_VISIBILITY + /* Override the effect of the compiler option '-fvisibility=hidden'. */ +# define DLL_EXPORTED __attribute__((__visibility__("default"))) +# elif defined _WIN32 || defined __CYGWIN__ +# define DLL_EXPORTED __declspec(dllexport) +# else +# define DLL_EXPORTED +# endif +#endif + #if defined _WIN32 && !defined __CYGWIN__ # define WIN32_LEAN_AND_MEAN /* avoid including junk */ @@ -36,7 +49,7 @@ because the latter is not guaranteed to be a stable ABI in the future. */ /* Make sure the function gets exported from DLLs. */ -__declspec(dllexport) CRITICAL_SECTION *gl_get_setlocale_null_lock (void); +DLL_EXPORTED CRITICAL_SECTION *gl_get_setlocale_null_lock (void); static glwthread_initguard_t guard = GLWTHREAD_INITGUARD_INIT; static CRITICAL_SECTION lock; @@ -72,10 +85,8 @@ gl_get_setlocale_null_lock (void) static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -# if defined _WIN32 || defined __CYGWIN__ -/* Make sure the function gets exported from DLLs. */ -__declspec(dllexport) pthread_mutex_t *gl_get_setlocale_null_lock (void); -# endif +/* Make sure the function gets exported from shared libraries. */ +DLL_EXPORTED pthread_mutex_t *gl_get_setlocale_null_lock (void); /* Returns the internal lock used by setlocale_null_r. */ pthread_mutex_t * @@ -101,6 +112,9 @@ atomic_init (void) init_needed = 0; } +/* Make sure the function gets exported from shared libraries. */ +DLL_EXPORTED mtx_t *gl_get_setlocale_null_lock (void); + /* Returns the internal lock used by setlocale_null_r. */ mtx_t * gl_get_setlocale_null_lock (void) diff --git a/m4/setlocale_null.m4 b/m4/setlocale_null.m4 index eff6e76ab6..465ef1127c 100644 --- a/m4/setlocale_null.m4 +++ b/m4/setlocale_null.m4 @@ -90,3 +90,9 @@ AC_DEFUN([gl_FUNC_SETLOCALE_NULL], dnl with gcc or xlc, and empty otherwise. AC_SUBST([LIB_SETLOCALE_NULL]) ]) + +# Prerequisites of lib/setlocale-lock.c. +AC_DEFUN([gl_PREREQ_SETLOCALE_LOCK], +[ + gl_VISIBILITY +]) diff --git a/modules/setlocale-null b/modules/setlocale-null index 52403692c5..2774004ff1 100644 --- a/modules/setlocale-null +++ b/modules/setlocale-null @@ -8,6 +8,7 @@ lib/setlocale-lock.c lib/windows-initguard.h m4/setlocale_null.m4 m4/threadlib.m4 +m4/visibility.m4 Depends-on: locale @@ -17,6 +18,7 @@ configure.ac: gl_FUNC_SETLOCALE_NULL if test $SETLOCALE_NULL_ALL_MTSAFE = 0 || test $SETLOCALE_NULL_ONE_MTSAFE = 0; then AC_LIBOBJ([setlocale-lock]) + gl_PREREQ_SETLOCALE_LOCK fi gl_LOCALE_MODULE_INDICATOR([setlocale_null]) -- 2.39.5