>From b2fc4a431927a6fbdd523bef93357134d9c489a9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 23 Sep 2017 09:26:48 +0200 Subject: [PATCH 2/3] monetary: New module. * modules/monetary: New file. * lib/monetary.in.h: New file. * m4/monetary_h.m4: New file. * doc/posix-headers/monetary.texi: Mention the new module. * modules/monetary-tests: New file. * tests/test-monetary.c: New file. * modules/monetary-c++-tests: New file. * tests/test-monetary-c++.cc: New file. * modules/duplocale-tests (configure.ac): Use AC_CHECK_HEADERS_ONCE. --- ChangeLog | 13 +++++ doc/posix-headers/monetary.texi | 2 +- lib/monetary.in.h | 105 ++++++++++++++++++++++++++++++++++++++++ m4/monetary_h.m4 | 65 +++++++++++++++++++++++++ modules/duplocale-tests | 2 +- modules/monetary | 57 ++++++++++++++++++++++ modules/monetary-c++-tests | 18 +++++++ modules/monetary-tests | 10 ++++ tests/test-monetary-c++.cc | 39 +++++++++++++++ tests/test-monetary.c | 29 +++++++++++ 10 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 lib/monetary.in.h create mode 100644 m4/monetary_h.m4 create mode 100644 modules/monetary create mode 100644 modules/monetary-c++-tests create mode 100644 modules/monetary-tests create mode 100644 tests/test-monetary-c++.cc create mode 100644 tests/test-monetary.c diff --git a/ChangeLog b/ChangeLog index be1f9f8..2b88ede 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2017-09-23 Bruno Haible + monetary: New module. + * modules/monetary: New file. + * lib/monetary.in.h: New file. + * m4/monetary_h.m4: New file. + * doc/posix-headers/monetary.texi: Mention the new module. + * modules/monetary-tests: New file. + * tests/test-monetary.c: New file. + * modules/monetary-c++-tests: New file. + * tests/test-monetary-c++.cc: New file. + * modules/duplocale-tests (configure.ac): Use AC_CHECK_HEADERS_ONCE. + +2017-09-23 Bruno Haible + duplocale tests: Fix test crash on Linux/x86. * tests/test-duplocale.c (test_with_uselocale): Disconnect the mixed2 locale from the current thread before freeing it. diff --git a/doc/posix-headers/monetary.texi b/doc/posix-headers/monetary.texi index 834bf52..27ad38e 100644 --- a/doc/posix-headers/monetary.texi +++ b/doc/posix-headers/monetary.texi @@ -3,7 +3,7 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/basedefs/monetary.h.html} -Gnulib module: --- +Gnulib module: monetary Portability problems fixed by Gnulib: @itemize diff --git a/lib/monetary.in.h b/lib/monetary.in.h new file mode 100644 index 0000000..52966c4 --- /dev/null +++ b/lib/monetary.in.h @@ -0,0 +1,105 @@ +/* Wrapper around . + Copyright (C) 2017 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +#ifndef address@hidden@_MONETARY_H + +#if __GNUC__ >= 3 address@hidden@ +#endif address@hidden@ + +/* The include_next requires a split double-inclusion guard. */ +#if @HAVE_MONETARY_H@ +# @INCLUDE_NEXT@ @NEXT_MONETARY_H@ +#endif + +#ifndef address@hidden@_MONETARY_H +#define address@hidden@_MONETARY_H + +#if @GNULIB_STRFMON_L@ && @HAVE_XLOCALE_H@ +/* Get locale_t on Mac OS X 10.12. */ +# include +#endif + +/* Like in . */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) +#else +# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ +#endif + +/* _GL_ATTRIBUTE_FORMAT_STRFMON + indicates to GCC that the function takes a format string and arguments, + where the format string directives are the ones standardized by ISO C99 + and POSIX. */ +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) +# define _GL_ATTRIBUTE_FORMAT_STRFMON(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__gnu_strfmon__, formatstring_parameter, first_argument)) +#elif __GNUC__ >= 3 +# define _GL_ATTRIBUTE_FORMAT_STRFMON(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((__strfmon__, formatstring_parameter, first_argument)) +#else +# define _GL_ATTRIBUTE_FORMAT_STRFMON(formatstring_parameter, first_argument) /* empty */ +#endif + + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + +#ifdef __cplusplus +extern "C" { +#endif + + +#if @GNULIB_STRFMON_L@ +/* Converts a monetary value to a string. + See the POSIX:2008 specification + wrapper only if the system already + dnl has a . + if test $ac_cv_header_monetary_h = yes; then + MONETARY_H='monetary.h' + + gl_CHECK_NEXT_HEADERS([monetary.h]) + if test $ac_cv_header_monetary_h = yes; then + HAVE_MONETARY_H=1 + else + HAVE_MONETARY_H=0 + fi + AC_SUBST([HAVE_MONETARY_H]) + + AC_CHECK_HEADERS_ONCE([xlocale.h]) + if test $ac_cv_header_xlocale_h = yes; then + HAVE_XLOCALE_H=1 + else + HAVE_XLOCALE_H=0 + fi + AC_SUBST([HAVE_XLOCALE_H]) + + dnl Check for declarations of anything we want to poison if the + dnl corresponding gnulib module is not in use. + gl_WARN_ON_USE_PREPARE([[ + #include + ]], [strfmon_l]) + else + MONETARY_H='' + fi + AC_SUBST([MONETARY_H]) + AM_CONDITIONAL([GL_GENERATE_MONETARY_H], [test -n "$MONETARY_H"]) +]) + +AC_DEFUN([gl_MONETARY_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_MONETARY_H_DEFAULTS]) + gl_MODULE_INDICATOR_SET_VARIABLE([$1]) +]) + +AC_DEFUN([gl_MONETARY_H_DEFAULTS], +[ + GNULIB_STRFMON_L=0; AC_SUBST([GNULIB_STRFMON_L]) + dnl Assume proper GNU behavior unless another module says otherwise. + HAVE_STRFMON_L=1; AC_SUBST([HAVE_STRFMON_L]) + REPLACE_STRFMON_L=0; AC_SUBST([REPLACE_STRFMON_L]) +]) diff --git a/modules/duplocale-tests b/modules/duplocale-tests index 3420abf..baa9a63 100644 --- a/modules/duplocale-tests +++ b/modules/duplocale-tests @@ -8,7 +8,7 @@ langinfo configure.ac: AC_CHECK_FUNCS_ONCE([duplocale uselocale strfmon_l snprintf_l nl_langinfo_l]) -AC_CHECK_HEADERS([monetary.h]) +AC_CHECK_HEADERS_ONCE([monetary.h]) Makefile.am: TESTS += test-duplocale diff --git a/modules/monetary b/modules/monetary new file mode 100644 index 0000000..c8be360 --- /dev/null +++ b/modules/monetary @@ -0,0 +1,57 @@ +Description: +A substitute . + +Files: +lib/monetary.in.h +m4/monetary_h.m4 + +Depends-on: +include_next +snippet/arg-nonnull +snippet/c++defs +snippet/warn-on-use + +configure.ac: +gl_MONETARY_H + +Makefile.am: +BUILT_SOURCES += $(MONETARY_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +if GL_GENERATE_MONETARY_H +monetary.h: monetary.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) + $(AM_V_GEN)rm -f address@hidden $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \ + -e 's|@''HAVE_MONETARY_H''@|$(HAVE_MONETARY_H)|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_MONETARY_H''@|$(NEXT_MONETARY_H)|g' \ + -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \ + -e 's|@''GNULIB_STRFMON_L''@|$(GNULIB_STRFMON_L)|g' \ + -e 's|@''HAVE_STRFMON_L''@|$(HAVE_STRFMON_L)|g' \ + -e 's|@''REPLACE_STRFMON_L''@|$(REPLACE_STRFMON_L)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/monetary.in.h; \ + } > address@hidden && \ + mv address@hidden $@ +else +monetary.h: $(top_builddir)/config.status + rm -f $@ +endif +MOSTLYCLEANFILES += monetary.h monetary.h-t + +Include: +#if HAVE_MONETARY_H + +#endif + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/monetary-c++-tests b/modules/monetary-c++-tests new file mode 100644 index 0000000..bd4d52e --- /dev/null +++ b/modules/monetary-c++-tests @@ -0,0 +1,18 @@ +Files: +tests/test-monetary-c++.cc +tests/signature.h + +Status: +c++-test + +Depends-on: +ansi-c++-opt + +configure.ac: + +Makefile.am: +if ANSICXX +TESTS += test-monetary-c++ +check_PROGRAMS += test-monetary-c++ +test_monetary_c___SOURCES = test-monetary-c++.cc +endif diff --git a/modules/monetary-tests b/modules/monetary-tests new file mode 100644 index 0000000..eedd0a1 --- /dev/null +++ b/modules/monetary-tests @@ -0,0 +1,10 @@ +Files: +tests/test-monetary.c + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-monetary +check_PROGRAMS += test-monetary diff --git a/tests/test-monetary-c++.cc b/tests/test-monetary-c++.cc new file mode 100644 index 0000000..6b3079a --- /dev/null +++ b/tests/test-monetary-c++.cc @@ -0,0 +1,39 @@ +/* Test of substitute in C++ mode. + Copyright (C) 2017 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2017. */ + +#define GNULIB_NAMESPACE gnulib +#include + +#if HAVE_MONETARY_H +# include +#endif + +#include "signature.h" + + +#if GNULIB_TEST_STRFMON_L +SIGNATURE_CHECK (GNULIB_NAMESPACE::strfmon_l, ssize_t, + (char *s, size_t maxsize, locale_t locale, + const char *format, ...)); +#endif + + +int +main () +{ +} diff --git a/tests/test-monetary.c b/tests/test-monetary.c new file mode 100644 index 0000000..c1f01fc --- /dev/null +++ b/tests/test-monetary.c @@ -0,0 +1,29 @@ +/* Test of substitute. + Copyright (C) 2017 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2017. */ + +#include + +#if HAVE_MONETARY_H +# include +#endif + +int +main () +{ + return 0; +} -- 2.7.4