]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
freelocale: New module.
authorBruno Haible <bruno@clisp.org>
Fri, 14 Feb 2025 01:59:02 +0000 (02:59 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 14 Feb 2025 02:05:29 +0000 (03:05 +0100)
* 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.

ChangeLog
doc/posix-functions/freelocale.texi
lib/freelocale.c [new file with mode: 0644]
lib/locale.in.h
m4/freelocale.m4 [new file with mode: 0644]
m4/locale_h.m4
modules/freelocale [new file with mode: 0644]
modules/locale-h
tests/test-locale-h-c++.cc

index 1a73e832dba72c4309f9e3a188fcb32006d624b7..a0e305906681f01a23d5a1e74ce994a2b7ca7132 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+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.
index 05ddfa05d6aebd623b2e6c3382d6e7b53b6d922a..1167f002fbdb4c9c2a675e095feb14d5dd2e036e 100644 (file)
@@ -4,21 +4,22 @@
 
 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:
diff --git a/lib/freelocale.c b/lib/freelocale.c
new file mode 100644 (file)
index 0000000..9dd7cba
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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);
+}
index 7fa426859f91f7b9bd4bd0a14ffba994e0e59b3b..31d3e9b60bf302ee9e7a4e365de1e5a3643e9775 100644 (file)
@@ -361,7 +361,7 @@ _GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - "
 # 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
@@ -371,13 +371,14 @@ _GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - "
 _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
diff --git a/m4/freelocale.m4 b/m4/freelocale.m4
new file mode 100644 (file)
index 0000000..61fc0a9
--- /dev/null
@@ -0,0 +1,22 @@
+# 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],
+[
+  :
+])
index 0635a4c3bb5aeaa519ce9eab27d85c55223bfb02..1e3cc11bf22085a838220b1c02f3f0431108210b 100644 (file)
@@ -1,5 +1,5 @@
 # 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,
@@ -178,6 +178,7 @@ AC_DEFUN([gl_LOCALE_H_REQUIRE_DEFAULTS],
     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])
diff --git a/modules/freelocale b/modules/freelocale
new file mode 100644 (file)
index 0000000..fe1faaa
--- /dev/null
@@ -0,0 +1,31 @@
+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
index a5317cf9c9db414b8b0e534b5097ebca99d16234..52f456ea865cfb165a6c1ce6150dedbbe74fb25f 100644 (file)
@@ -40,6 +40,7 @@ locale.h: locale.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
              -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' \
index ad66ae4871ff2bc8db46432cb726071b5ccd5a7b..f2bcfaa71d42195f5d26c49c8be2d0c1cf148cd2 100644 (file)
@@ -40,7 +40,7 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::newlocale, locale_t, (int, const char *, loca
 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