From: Bruno Haible Date: Fri, 14 Feb 2025 01:59:02 +0000 (+0100) Subject: freelocale: New module. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=414c6c84f65d54c9ba79716d2c430e539ea0f0f4;p=thirdparty%2Fgnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 1a73e832db..a0e3059066 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2025-02-14 Bruno Haible + + 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 newlocale: Add tests. diff --git a/doc/posix-functions/freelocale.texi b/doc/posix-functions/freelocale.texi index 05ddfa05d6..1167f002fb 100644 --- a/doc/posix-functions/freelocale.texi +++ b/doc/posix-functions/freelocale.texi @@ -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 index 0000000000..9dd7cba02c --- /dev/null +++ b/lib/freelocale.c @@ -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 . */ + +/* Written by Bruno Haible , 2025. */ + +#include + +/* Specification. */ +#include + +#include + +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: + */ + _free_locale (locale->category[i].system_locale); +#endif + free (locale->category[i].name); + } + free (locale); +} diff --git a/lib/locale.in.h b/lib/locale.in.h index 7fa426859f..31d3e9b60b 100644 --- a/lib/locale.in.h +++ b/lib/locale.in.h @@ -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 index 0000000000..61fc0a93bd --- /dev/null +++ b/m4/freelocale.m4 @@ -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 ]]) + if test $ac_cv_func_freelocale = no; then + HAVE_FREELOCALE=0 + fi +]) + +# Prerequisites of lib/freelocale.c. +AC_DEFUN([gl_PREREQ_FREELOCALE], +[ + : +]) diff --git a/m4/locale_h.m4 b/m4/locale_h.m4 index 0635a4c3bb..1e3cc11bf2 100644 --- a/m4/locale_h.m4 +++ b/m4/locale_h.m4 @@ -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 index 0000000000..fe1faaae59 --- /dev/null +++ b/modules/freelocale @@ -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: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/locale-h b/modules/locale-h index a5317cf9c9..52f456ea86 100644 --- a/modules/locale-h +++ b/modules/locale-h @@ -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' \ diff --git a/tests/test-locale-h-c++.cc b/tests/test-locale-h-c++.cc index ad66ae4871..f2bcfaa71d 100644 --- a/tests/test-locale-h-c++.cc +++ b/tests/test-locale-h-c++.cc @@ -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