[11/14] ldbl-128ibm-compat: Add argp_error and argp_failure

Message ID 20180621021023.17036-12-gabriel@inconstante.eti.br
State New, archived
Headers

Commit Message

Gabriel F. T. Gomes June 21, 2018, 2:10 a.m. UTC
  Use the recently added, internal functions, __argp_error_internal and
__argp_failure_internal, to provide argp_error and argp_failure that can
take long double arguments with IEEE binary128 format on platforms where
long double can also take double format or some non-IEEE format
(currently, this means powerpc64le).

Tested for powerpc64le.

	* argp/argpP.h: New file.
	* sysdeps/ieee754/ldbl-128ibm-compat/Makefile
	[subdir == argp] (routines): Add ieee128-argp_error and
	ieee128-argp_failure.
	[subdir == argp] (tests-internal): Add test-argp-error-ieee128,
	test-argp-error-ibm128, test-argp-failure-ieee128, and
	test-argp-failure-ibm128.
	[subdir == argp] (CFLAGS-test-argp-error-ieee128.c): New variable.
	[subdir == argp] (CFLAGS-test-argp-error-ibm128.c): Likewise.
	[subdir == argp] (CFLAGS-test-argp-failure-ieee128.c): Likewise.
	[subdir == argp] (CFLAGS-test-argp-failure-ibm128): Likewise.
	[subdir == argp && run-built-tests == yes] (tests-special): Add
	$(objpfx)test-argp-error-ieee128.out,
	$(objpfx)test-argp-error-ibm128.out,
	$(objpfx)test-argp-failure-ieee128.out,
	$(objpfx)test-argp-failure-ibm128.out.
	[subdir == argp] ($(objpfx)test-argp-error-ieee128.out)
	($(objpfx)test-argp-error-ibm128.out)
	($(objpfx)test-argp-failure-ieee128.out)
	($(objpfx)test-argp-failure-ibm128.out): New build and run rule.
	* sysdeps/ieee754/ldbl-128ibm-compat/Versions (libc): Add
	__argp_errorieee128 and __argp_failureieee128.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_error.c: New file.
	* sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_failure.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ibm128.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ieee128.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.sh:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ibm128.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ieee128.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.sh:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm-compat/test-argp-ldbl-compat.c:
	Likewise.
---
 argp/argpP.h                                       | 29 +++++++++
 sysdeps/ieee754/ldbl-128ibm-compat/Makefile        | 46 +++++++++++++++
 sysdeps/ieee754/ldbl-128ibm-compat/Versions        |  3 +
 .../ldbl-128ibm-compat/ieee128-argp_error.c        | 30 ++++++++++
 .../ldbl-128ibm-compat/ieee128-argp_failure.c      | 32 ++++++++++
 .../ldbl-128ibm-compat/test-argp-error-ibm128.c    |  1 +
 .../ldbl-128ibm-compat/test-argp-error-ieee128.c   |  1 +
 .../test-argp-error-ldbl-compat.c                  |  3 +
 .../test-argp-error-ldbl-compat.sh                 | 46 +++++++++++++++
 .../ldbl-128ibm-compat/test-argp-failure-ibm128.c  |  1 +
 .../ldbl-128ibm-compat/test-argp-failure-ieee128.c |  1 +
 .../test-argp-failure-ldbl-compat.c                |  3 +
 .../test-argp-failure-ldbl-compat.sh               | 45 ++++++++++++++
 .../ldbl-128ibm-compat/test-argp-ldbl-compat.c     | 69 ++++++++++++++++++++++
 14 files changed, 310 insertions(+)
 create mode 100644 argp/argpP.h
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_error.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_failure.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ibm128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ieee128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.sh
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ibm128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ieee128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.sh
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-argp-ldbl-compat.c
  

Patch

diff --git a/argp/argpP.h b/argp/argpP.h
new file mode 100644
index 0000000000..da77c6840c
--- /dev/null
+++ b/argp/argpP.h
@@ -0,0 +1,29 @@ 
+/* Prototypes for internal argp.h functions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library 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.
+
+   The GNU C Library 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdarg.h>
+#include <argp.h>
+
+void
+__argp_error_internal (const struct argp_state *state, const char *fmt,
+		       va_list ap, unsigned int mode_flags);
+
+void
+__argp_failure_internal (const struct argp_state *state, int status,
+			 int errnum, const char *fmt, va_list ap,
+			 unsigned int mode_flags);
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
index 5cb6fd4f73..b37bb05b0f 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
@@ -193,3 +193,49 @@  $(objpfx)test-wscanf-ibm128.out: \
 	$(SHELL) $^ '$(test-program-prefix)' $@; \
 	$(evaluate-test)
 endif
+
+ifeq ($(subdir),argp)
+# Wrappers for argp functions that take long double arguments with
+# IEEE binary128 format
+routines += ieee128-argp_error
+routines += ieee128-argp_failure
+
+tests-internal += test-argp-error-ieee128 test-argp-error-ibm128
+CFLAGS-test-argp-error-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi
+CFLAGS-test-argp-error-ibm128.c += -mabi=ibmlongdouble -Wno-psabi
+
+tests-internal += test-argp-failure-ieee128 test-argp-failure-ibm128
+CFLAGS-test-argp-failure-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi
+CFLAGS-test-argp-failure-ibm128.c += -mabi=ibmlongdouble -Wno-psabi
+
+ifeq ($(run-built-tests),yes)
+tests-special += $(objpfx)test-argp-error-ieee128.out
+tests-special += $(objpfx)test-argp-error-ibm128.out
+tests-special += $(objpfx)test-argp-failure-ieee128.out
+tests-special += $(objpfx)test-argp-failure-ibm128.out
+endif
+
+$(objpfx)test-argp-error-ieee128.out: \
+  ../sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.sh \
+  $(objpfx)test-argp-error-ieee128
+	$(SHELL) $^ '$(test-program-prefix)' $@; \
+	$(evaluate-test)
+
+$(objpfx)test-argp-error-ibm128.out: \
+  ../sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.sh \
+  $(objpfx)test-argp-error-ibm128
+	$(SHELL) $^ '$(test-program-prefix)' $@; \
+	$(evaluate-test)
+
+$(objpfx)test-argp-failure-ieee128.out: \
+  ../sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.sh \
+  $(objpfx)test-argp-failure-ieee128
+	$(SHELL) $^ '$(test-program-prefix)' $@; \
+	$(evaluate-test)
+
+$(objpfx)test-argp-failure-ibm128.out: \
+  ../sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.sh \
+  $(objpfx)test-argp-failure-ibm128
+	$(SHELL) $^ '$(test-program-prefix)' $@; \
+	$(evaluate-test)
+endif
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Versions b/sysdeps/ieee754/ldbl-128ibm-compat/Versions
index e0e7e74160..21a1f28694 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/Versions
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/Versions
@@ -172,5 +172,8 @@  libc {
     __vfwscanfieee128;
     __vswscanfieee128;
     __vwscanfieee128;
+
+    __argp_errorieee128;
+    __argp_failureieee128;
   }
 }
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_error.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_error.c
new file mode 100644
index 0000000000..35c467b471
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_error.c
@@ -0,0 +1,30 @@ 
+/* Wrapper for argp_error.  IEEE128 version.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library 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.
+
+   The GNU C Library 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <argp/argpP.h>
+#include <libio/libioP.h>
+
+void
+___ieee128_argp_error (const struct argp_state *state, const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  __argp_error_internal (state, fmt, ap, PRINTF_LDBL_USES_FLOAT128);
+  va_end (ap);
+}
+strong_alias (___ieee128_argp_error, __argp_errorieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_failure.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_failure.c
new file mode 100644
index 0000000000..0abe88f538
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-argp_failure.c
@@ -0,0 +1,32 @@ 
+/* Wrapper for argp_failure.  IEEE128 version.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library 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.
+
+   The GNU C Library 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <argp/argpP.h>
+#include <libio/libioP.h>
+
+void
+___ieee128_argp_failure (const struct argp_state *state, int status,
+			int errnum, const char *fmt, ...)
+{
+  va_list ap;
+  va_start (ap, fmt);
+  __argp_failure_internal (state, status, errnum, fmt, ap,
+			   PRINTF_LDBL_USES_FLOAT128);
+  va_end (ap);
+}
+strong_alias (___ieee128_argp_failure, __argp_failureieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ibm128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ibm128.c
new file mode 100644
index 0000000000..a201323cd9
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ibm128.c
@@ -0,0 +1 @@ 
+#include <test-argp-error-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ieee128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ieee128.c
new file mode 100644
index 0000000000..a201323cd9
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ieee128.c
@@ -0,0 +1 @@ 
+#include <test-argp-error-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.c
new file mode 100644
index 0000000000..049f8af7a0
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.c
@@ -0,0 +1,3 @@ 
+#define ARGP_FUNCTION		argp_error
+#define ARGP_FUNCTION_PARAMS	(state, arg, (long double) -1)
+#include <test-argp-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.sh b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.sh
new file mode 100644
index 0000000000..5327bf5274
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-error-ldbl-compat.sh
@@ -0,0 +1,46 @@ 
+#!/bin/sh
+# Testing of argp_error.  IEEE binary128 for powerpc64le version.
+# Copyright (C) 2018 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library 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.
+
+# The GNU C Library 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 the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+test_program=$1; shift
+test_program_prefix=$1; shift
+test_program_output=$1; shift
+
+status=0
+
+# Allow argp_error to end with non-zero exit status, run the test
+# program, then restore the exit-on-error behavior
+set +e
+${test_program_prefix} \
+  ${test_program} \
+  2> ${test_program_output}
+set -e
+
+cat <<'EOF' |
+test-argp: -1.000000000000000000000000000000000000000000000000000000000000
+Try `test-argp --help' or `test-argp --usage' for more information.
+EOF
+cmp - ${test_program_output} > /dev/null 2>&1 ||
+{
+  status=1
+  echo "*** output comparison failed"
+}
+
+exit $status
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ibm128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ibm128.c
new file mode 100644
index 0000000000..2983bc3f6c
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ibm128.c
@@ -0,0 +1 @@ 
+#include <test-argp-failure-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ieee128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ieee128.c
new file mode 100644
index 0000000000..2983bc3f6c
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ieee128.c
@@ -0,0 +1 @@ 
+#include <test-argp-failure-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.c
new file mode 100644
index 0000000000..e43d3373bc
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.c
@@ -0,0 +1,3 @@ 
+#define ARGP_FUNCTION		argp_failure
+#define ARGP_FUNCTION_PARAMS	(state, 0, 0, arg, (long double) -1)
+#include <test-argp-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.sh b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.sh
new file mode 100644
index 0000000000..132bc5f96c
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-failure-ldbl-compat.sh
@@ -0,0 +1,45 @@ 
+#!/bin/sh
+# Testing of argp_failure.  IEEE binary128 for powerpc64le version.
+# Copyright (C) 2018 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library 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.
+
+# The GNU C Library 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 the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+set -e
+
+test_program=$1; shift
+test_program_prefix=$1; shift
+test_program_output=$1; shift
+
+status=0
+
+# Allow argp_failure to end with non-zero exit status, run the test
+# program, then restore the exit-on-error behavior
+set +e
+${test_program_prefix} \
+  ${test_program} \
+  2> ${test_program_output}
+set -e
+
+cat <<'EOF' |
+test-argp: -1.000000000000000000000000000000000000000000000000000000000000
+EOF
+cmp - ${test_program_output} > /dev/null 2>&1 ||
+{
+  status=1
+  echo "*** output comparison failed"
+}
+
+exit $status
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-ldbl-compat.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-ldbl-compat.c
new file mode 100644
index 0000000000..ca008b507c
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-argp-ldbl-compat.c
@@ -0,0 +1,69 @@ 
+/* Test for the long double variants of argp* functions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library 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.
+
+   The GNU C Library 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 the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <argp.h>
+#include <string.h>
+
+#include <support/check.h>
+
+static const struct argp_option
+options[] =
+{
+  { "test", 't', "format", 0, "Run argp function with a format string", 0 },
+  { NULL, 0, NULL, 0, NULL }
+};
+
+static error_t
+parser (int key, char *arg, struct argp_state *state)
+{
+  switch (key)
+    {
+      case 't':
+	ARGP_FUNCTION ARGP_FUNCTION_PARAMS;
+	break;
+      default:
+	return ARGP_ERR_UNKNOWN;
+    }
+  return 0;
+}
+
+static struct argp
+argp =
+{
+  options, parser
+};
+
+static int
+do_test (void)
+{
+  int remaining;
+  int argc = 3;
+  char *argv[4] =
+    {
+      (char *) "test-argp",
+      (char *) "--test",
+      (char *) "%.60Lf",
+      NULL
+    };
+
+  argp_parse (&argp, argc, argv, 0, &remaining, NULL);
+
+  return 0;
+}
+
+#include <support/test-driver.c>