From c75f99155342338ae9de19b164fd3e255bf96da4 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 15 Feb 2024 09:47:08 +0100 Subject: [PATCH] setlocale-null: Refactor. * lib/setlocale_null.c (setlocale_null_r_with_lock): Renamed from setlocale_null_with_lock. (setlocale_null_r_unlocked): Renamed from setlocale_null_unlocked. (setlocale_null_unlocked): Renamed from setlocale_null_androidfix. --- ChangeLog | 8 ++++++++ lib/setlocale_null.c | 42 +++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05732c7e9d..4ba5cbfc28 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-02-15 Bruno Haible + + setlocale-null: Refactor. + * lib/setlocale_null.c + (setlocale_null_r_with_lock): Renamed from setlocale_null_with_lock. + (setlocale_null_r_unlocked): Renamed from setlocale_null_unlocked. + (setlocale_null_unlocked): Renamed from setlocale_null_androidfix. + 2024-02-15 Bruno Haible localename-unsafe: New module. diff --git a/lib/setlocale_null.c b/lib/setlocale_null.c index 697502fbfe..152452e04f 100644 --- a/lib/setlocale_null.c +++ b/lib/setlocale_null.c @@ -63,7 +63,7 @@ #undef setlocale static const char * -setlocale_null_androidfix (int category) +setlocale_null_unlocked (int category) { const char *result = setlocale (category, NULL); @@ -94,7 +94,7 @@ setlocale_null_androidfix (int category) } static int -setlocale_null_unlocked (int category, char *buf, size_t bufsize) +setlocale_null_r_unlocked (int category, char *buf, size_t bufsize) { #if defined _WIN32 && !defined __CYGWIN__ && defined _MSC_VER /* On native Windows, nowadays, the setlocale() implementation is based @@ -143,7 +143,7 @@ setlocale_null_unlocked (int category, char *buf, size_t bufsize) } } #else - const char *result = setlocale_null_androidfix (category); + const char *result = setlocale_null_unlocked (category); if (result == NULL) { @@ -181,7 +181,7 @@ setlocale_null_unlocked (int category, char *buf, size_t bufsize) #if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE) /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin < 3.4.6 */ -/* Use a lock, so that no two threads can invoke setlocale_null_unlocked +/* Use a lock, so that no two threads can invoke setlocale_null_r_unlocked at the same time. */ /* Prohibit renaming this symbol. */ @@ -190,20 +190,20 @@ setlocale_null_unlocked (int category, char *buf, size_t bufsize) # if AVOID_ANY_THREADS /* The option '--disable-threads' explicitly requests no locking. */ -# define setlocale_null_with_lock setlocale_null_unlocked +# define setlocale_null_r_with_lock setlocale_null_r_unlocked # elif defined _WIN32 && !defined __CYGWIN__ extern __declspec(dllimport) CRITICAL_SECTION *gl_get_setlocale_null_lock (void); static int -setlocale_null_with_lock (int category, char *buf, size_t bufsize) +setlocale_null_r_with_lock (int category, char *buf, size_t bufsize) { CRITICAL_SECTION *lock = gl_get_setlocale_null_lock (); int ret; EnterCriticalSection (lock); - ret = setlocale_null_unlocked (category, buf, bufsize); + ret = setlocale_null_r_unlocked (category, buf, bufsize); LeaveCriticalSection (lock); return ret; @@ -234,7 +234,7 @@ extern # endif static int -setlocale_null_with_lock (int category, char *buf, size_t bufsize) +setlocale_null_r_with_lock (int category, char *buf, size_t bufsize) { if (pthread_in_use()) { @@ -243,14 +243,14 @@ setlocale_null_with_lock (int category, char *buf, size_t bufsize) if (pthread_mutex_lock (lock)) abort (); - ret = setlocale_null_unlocked (category, buf, bufsize); + ret = setlocale_null_r_unlocked (category, buf, bufsize); if (pthread_mutex_unlock (lock)) abort (); return ret; } else - return setlocale_null_unlocked (category, buf, bufsize); + return setlocale_null_r_unlocked (category, buf, bufsize); } # elif HAVE_THREADS_H @@ -258,14 +258,14 @@ setlocale_null_with_lock (int category, char *buf, size_t bufsize) extern mtx_t *gl_get_setlocale_null_lock (void); static int -setlocale_null_with_lock (int category, char *buf, size_t bufsize) +setlocale_null_r_with_lock (int category, char *buf, size_t bufsize) { mtx_t *lock = gl_get_setlocale_null_lock (); int ret; if (mtx_lock (lock) != thrd_success) abort (); - ret = setlocale_null_unlocked (category, buf, bufsize); + ret = setlocale_null_r_unlocked (category, buf, bufsize); if (mtx_unlock (lock) != thrd_success) abort (); @@ -282,27 +282,27 @@ setlocale_null_r (int category, char *buf, size_t bufsize) #if SETLOCALE_NULL_ALL_MTSAFE # if SETLOCALE_NULL_ONE_MTSAFE - return setlocale_null_unlocked (category, buf, bufsize); + return setlocale_null_r_unlocked (category, buf, bufsize); # else if (category == LC_ALL) - return setlocale_null_unlocked (category, buf, bufsize); + return setlocale_null_r_unlocked (category, buf, bufsize); else - return setlocale_null_with_lock (category, buf, bufsize); + return setlocale_null_r_with_lock (category, buf, bufsize); # endif #else # if SETLOCALE_NULL_ONE_MTSAFE if (category == LC_ALL) - return setlocale_null_with_lock (category, buf, bufsize); + return setlocale_null_r_with_lock (category, buf, bufsize); else - return setlocale_null_unlocked (category, buf, bufsize); + return setlocale_null_r_unlocked (category, buf, bufsize); # else - return setlocale_null_with_lock (category, buf, bufsize); + return setlocale_null_r_with_lock (category, buf, bufsize); # endif #endif @@ -312,7 +312,7 @@ const char * setlocale_null (int category) { #if SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE - return setlocale_null_androidfix (category); + return setlocale_null_unlocked (category); #else /* This call must be multithread-safe. To achieve this without using @@ -328,7 +328,7 @@ setlocale_null (int category) if (category == LC_ALL) { # if SETLOCALE_NULL_ALL_MTSAFE - return setlocale_null_androidfix (LC_ALL); + return setlocale_null_unlocked (LC_ALL); # else char buf[SETLOCALE_NULL_ALL_MAX]; static char resultbuf[SETLOCALE_NULL_ALL_MAX]; @@ -342,7 +342,7 @@ setlocale_null (int category) else { # if SETLOCALE_NULL_ONE_MTSAFE - return setlocale_null_androidfix (category); + return setlocale_null_unlocked (category); # else enum { -- 2.39.5