]> Savannah Git Hosting - gnulib.git/commitdiff
setlocale-null: Make it easy to rely on the lock in another library.
authorBruno Haible <bruno@clisp.org>
Tue, 24 Dec 2019 16:23:23 +0000 (17:23 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 24 Dec 2019 16:23:23 +0000 (17:23 +0100)
* lib/setlocale-lock.c: Do not define anything if OMIT_SETLOCALE_LOCK is
defined.

ChangeLog
lib/setlocale-lock.c

index 168037ed11291c77187d6d657aede452625467b4..35ce1e7e7677d28948c6a2b4d0d76df439428f11 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-24  Bruno Haible  <bruno@clisp.org>
+
+       setlocale-null: Make it easy to rely on the lock in another library.
+       * lib/setlocale-lock.c: Do not define anything if OMIT_SETLOCALE_LOCK is
+       defined.
+
 2019-12-23  Paul Eggert  <eggert@cs.ucla.edu>
 
        gethrxtime, mktime, nstrftime, strptime: tweak division performance
index 60c1ba32a8acd350589bd858c9fa0fd572216728..a71ba64ce9a212742fc2bf328e6df3da00069bf8 100644 (file)
 
 #include <config.h>
 
+/* When it is known that the gl_get_setlocale_null_lock function is defined
+   by a dependency library, it should not be defined here.  */
+#if OMIT_SETLOCALE_LOCK
+
+/* This declaration is solely to ensure that after preprocessing
+   this file is never empty.  */
+typedef int dummy;
+
+#else
+
 /* This file defines the internal lock used by setlocale_null_r.
    It is a separate compilation unit, so that only one copy of it is
    present when linking statically.  */
 
 /* Prohibit renaming this symbol.  */
-#undef gl_get_setlocale_null_lock
+# 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
+# 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
+#   define DLL_EXPORTED __attribute__((__visibility__("default")))
+#  elif defined _WIN32 || defined __CYGWIN__
+#   define DLL_EXPORTED __declspec(dllexport)
+#  else
+#   define DLL_EXPORTED
+#  endif
 # endif
-#endif
 
-#if defined _WIN32 && !defined __CYGWIN__
+# if defined _WIN32 && !defined __CYGWIN__
 
-# define WIN32_LEAN_AND_MEAN  /* avoid including junk */
-# include <windows.h>
+#  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+#  include <windows.h>
 
-# include "windows-initguard.h"
+#  include "windows-initguard.h"
 
 /* The return type is a 'CRITICAL_SECTION *', not a 'glwthread_mutex_t *',
    because the latter is not guaranteed to be a stable ABI in the future.  */
@@ -79,9 +89,9 @@ gl_get_setlocale_null_lock (void)
   return &lock;
 }
 
-#elif HAVE_PTHREAD_API
+# elif HAVE_PTHREAD_API
 
-# include <pthread.h>
+#  include <pthread.h>
 
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 
@@ -95,10 +105,10 @@ gl_get_setlocale_null_lock (void)
   return &mutex;
 }
 
-#elif HAVE_THREADS_H
+# elif HAVE_THREADS_H
 
-# include <threads.h>
-# include <stdlib.h>
+#  include <threads.h>
+#  include <stdlib.h>
 
 static int volatile init_needed = 1;
 static once_flag init_once = ONCE_FLAG_INIT;
@@ -124,15 +134,17 @@ gl_get_setlocale_null_lock (void)
   return &mutex;
 }
 
-#endif
+# endif
 
-#if defined _WIN32 || defined __CYGWIN__
+# if defined _WIN32 || defined __CYGWIN__
 /* Make sure the '__declspec(dllimport)' in setlocale_null.c does not cause
    a link failure when no DLLs are involved.  */
-# if defined _WIN64 || defined _LP64
-#  define IMP(x) __imp_##x
-# else
-#  define IMP(x) _imp__##x
-# endif
+#  if defined _WIN64 || defined _LP64
+#   define IMP(x) __imp_##x
+#  else
+#   define IMP(x) _imp__##x
+#  endif
 void * IMP(gl_get_setlocale_null_lock) = &gl_get_setlocale_null_lock;
+# endif
+
 #endif