+2025-02-14 Bruno Haible <bruno@clisp.org>
+
+ freelocale: New module.
+ * lib/locale.in.h (freelocale): Consider GNULIB_FREELOCALE. Declare if
+ not declared.
+ * lib/freelocale.c: New file.
+ * m4/freelocale.m4: New file.
+ * m4/locale_h.m4 (gl_LOCALE_H_REQUIRE_DEFAULTS): Initialize
+ GNULIB_FREELOCALE.
+ * modules/locale-h (Makefile.am): Substitute GNULIB_FREELOCALE.
+ * modules/freelocale: New file.
+ * tests/test-locale-h-c++.cc: Check declaration of freelocale.
+ * doc/posix-functions/freelocale.texi: Mention the new module.
+
2025-02-14 Bruno Haible <bruno@clisp.org>
newlocale: Add tests.
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/freelocale.html}
-Gnulib module: ---
+Gnulib module: freelocale
+@mindex freelocale
Portability problems fixed by Gnulib:
@itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
@item
This function is missing on many platforms:
-FreeBSD 9.0, NetBSD 5.0, OpenBSD 6.1, Minix 3.1.8, AIX 6.1, HP-UX 11, Solaris 11.3, Cygwin 2.5.x, mingw, MSVC 14, Android 4.4.
+FreeBSD 9.0, NetBSD 6.1, OpenBSD 6.1, Minix 3.1.8, AIX 6.1, HP-UX 11, Solaris 11.3, Cygwin 2.5.x, mingw, MSVC 14, Android 4.4.
@item
This function is useless because the @code{locale_t} type is not defined
on some platforms:
z/OS.
+@end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
@item
This function may cause crashes in subsequent @code{newlocale} invocations
on some platforms:
--- /dev/null
+/* Free a locale object.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ This file is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2025. */
+
+#include <config.h>
+
+/* Specification. */
+#include <locale.h>
+
+#include <stdlib.h>
+
+void
+freelocale (locale_t locale)
+{
+ int i;
+ for (i = 6; --i >= 0; )
+ {
+#if HAVE_WINDOWS_LOCALE_T
+ if (!(i == gl_log2_lcmask_to_index (gl_log2_lc_mask (LC_MESSAGES))
+ || locale->category[i].is_c_locale))
+ /* Documentation:
+ <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/free-locale> */
+ _free_locale (locale->category[i].system_locale);
+#endif
+ free (locale->category[i].name);
+ }
+ free (locale);
+}
# endif
#endif
-#if /*@GNULIB_FREELOCALE@ ||*/ (@GNULIB_LOCALENAME_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_FREELOCALE@)
+#if @GNULIB_FREELOCALE@ || (@GNULIB_LOCALENAME_UNSAFE@ && @LOCALENAME_ENHANCE_LOCALE_FUNCS@ && @HAVE_FREELOCALE@)
# if @REPLACE_FREELOCALE@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef freelocale
_GL_FUNCDECL_RPL (freelocale, void, (locale_t locale), _GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (freelocale, void, (locale_t locale));
# else
-# if @HAVE_FREELOCALE@
+# if !@HAVE_FREELOCALE@
+_GL_FUNCDECL_SYS (duplocale, locale_t, (locale_t locale), _GL_ARG_NONNULL ((1)));
+# endif
/* Need to cast, because on FreeBSD and Mac OS X 10.13, the return type is
int. */
_GL_CXXALIAS_SYS_CAST (freelocale, void, (locale_t locale));
-# endif
# endif
-# if __GLIBC__ >= 2 && @HAVE_FREELOCALE@
+# if __GLIBC__ >= 2
_GL_CXXALIASWARN (freelocale);
# endif
#elif defined GNULIB_POSIXCHECK
--- /dev/null
+# freelocale.m4
+# serial 1
+dnl Copyright (C) 2025 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+dnl This file is offered as-is, without any warranty.
+
+AC_DEFUN([gl_FUNC_FREELOCALE],
+[
+ AC_REQUIRE([gl_LOCALE_H_DEFAULTS])
+ gl_CHECK_FUNCS_ANDROID([freelocale], [[#include <locale.h>]])
+ if test $ac_cv_func_freelocale = no; then
+ HAVE_FREELOCALE=0
+ fi
+])
+
+# Prerequisites of lib/freelocale.c.
+AC_DEFUN([gl_PREREQ_FREELOCALE],
+[
+ :
+])
# locale_h.m4
-# serial 33
+# serial 34
dnl Copyright (C) 2007, 2009-2025 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETLOCALE_NULL])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_NEWLOCALE])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DUPLOCALE])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREELOCALE])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOCALENAME_UNSAFE])
])
m4_require(GL_MODULE_INDICATOR_PREFIX[_LOCALE_H_MODULE_INDICATOR_DEFAULTS])
--- /dev/null
+Description:
+freelocale() function: free a locale object.
+
+Files:
+lib/freelocale.c
+m4/freelocale.m4
+
+Depends-on:
+locale-h
+
+configure.ac:
+gl_FUNC_FREELOCALE
+gl_CONDITIONAL([GL_COND_OBJ_FREELOCALE], [test $HAVE_LOCALE_T = 0])
+AM_COND_IF([GL_COND_OBJ_FREELOCALE], [
+ gl_PREREQ_FREELOCALE
+])
+gl_LOCALE_MODULE_INDICATOR([freelocale])
+
+Makefile.am:
+if GL_COND_OBJ_FREELOCALE
+lib_SOURCES += freelocale.c
+endif
+
+Include:
+<locale.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
-e 's/@''GNULIB_SETLOCALE_NULL''@/$(GNULIB_SETLOCALE_NULL)/g' \
-e 's/@''GNULIB_NEWLOCALE''@/$(GNULIB_NEWLOCALE)/g' \
-e 's/@''GNULIB_DUPLOCALE''@/$(GNULIB_DUPLOCALE)/g' \
+ -e 's/@''GNULIB_FREELOCALE''@/$(GNULIB_FREELOCALE)/g' \
-e 's/@''GNULIB_LOCALENAME_UNSAFE''@/$(GNULIB_LOCALENAME_UNSAFE)/g' \
-e 's|@''HAVE_NEWLOCALE''@|$(HAVE_NEWLOCALE)|g' \
-e 's|@''HAVE_DUPLOCALE''@|$(HAVE_DUPLOCALE)|g' \
SIGNATURE_CHECK (GNULIB_NAMESPACE::duplocale, locale_t, (locale_t));
#endif
-#if 0
+#if GNULIB_TEST_FREELOCALE
SIGNATURE_CHECK (GNULIB_NAMESPACE::freelocale, void, (locale_t));
#endif