[v2,14/30] ldbl-128ibm-compat: Add obstack printing functions

Message ID 20191025153410.15405-15-gabriel@inconstante.net.br
State Committed
Headers

Commit Message

Gabriel F. T. Gomes Oct. 25, 2019, 3:33 p.m. UTC
  From: "Gabriel F. T. Gomes" <gabrielftg@linux.ibm.com>

No changes since v1.

-- 8< --
Similarly to the functions from the *printf family, this patch adds
implementations for __obstack_*printf* functions that set the
'mode_flags' parameter to PRINTF_LDBL_USES_FLOAT128, before making calls
to __vfprintf_internal (indirectly through __obstack_vprintf_internal).

Tested for powerpc64le.
---
 sysdeps/ieee754/ldbl-128ibm-compat/Makefile   | 13 +++-
 sysdeps/ieee754/ldbl-128ibm-compat/Versions   |  5 ++
 .../ldbl-128ibm-compat/ieee128-obprintf.c     | 42 ++++++++++++
 .../ldbl-128ibm-compat/ieee128-obstack_chk.c  | 39 +++++++++++
 .../ldbl-128ibm-compat/ieee128-vobstack_chk.c | 31 +++++++++
 .../test-obstack-chk-ibm128.c                 |  1 +
 .../test-obstack-chk-ieee128.c                |  1 +
 .../test-obstack-chk-ldbl-compat.c            |  6 ++
 .../ldbl-128ibm-compat/test-obstack-ibm128.c  |  1 +
 .../ldbl-128ibm-compat/test-obstack-ieee128.c |  1 +
 .../test-obstack-ldbl-compat-template.c       | 64 +++++++++++++++++++
 .../test-obstack-ldbl-compat.c                |  6 ++
 12 files changed, 209 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obprintf.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obstack_chk.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vobstack_chk.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ibm128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ieee128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ldbl-compat.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ibm128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ieee128.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat-template.c
 create mode 100644 sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat.c
  

Comments

Paul E Murphy Nov. 8, 2019, 11:42 p.m. UTC | #1
On 10/25/19 10:33 AM, Gabriel F. T. Gomes wrote:
> From: "Gabriel F. T. Gomes" <gabrielftg@linux.ibm.com>
> 
> No changes since v1.
> 
> -- 8< --
> Similarly to the functions from the *printf family, this patch adds
> implementations for __obstack_*printf* functions that set the
> 'mode_flags' parameter to PRINTF_LDBL_USES_FLOAT128, before making calls
> to __vfprintf_internal (indirectly through __obstack_vprintf_internal).

> diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile

OK

> diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Versions b/sysdeps/ieee754/ldbl-128ibm-compat/Versions

OK

> diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obprintf.c

...

The wrappers all look OK.

> diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ibm128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ibm128.c
> diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ieee128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ieee128.c

OK

> diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ldbl-compat.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ldbl-compat. > diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ibm128.c 
b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ibm128.c
> diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ieee128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ieee128.c

OK

> diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat-template.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat-template.c

OK

> diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat.c

OK.  I think it may be time to start the weekend.
  
Gabriel F. T. Gomes Nov. 27, 2019, 7:11 p.m. UTC | #2
On Fri, 08 Nov 2019, Paul E Murphy wrote:

>The wrappers all look OK.

Thanks, now pushed to master.
  

Patch

diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
index 1f944806e7..9e8237d075 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/Makefile
@@ -47,7 +47,10 @@  ldbl-extra-routines += printf_size \
 		       isoc99_sscanf \
 		       isoc99_vfscanf \
 		       isoc99_vscanf \
-		       isoc99_vsscanf
+		       isoc99_vsscanf \
+		       obprintf \
+		       obstack_chk \
+		       vobstack_chk
 
 # Printing long double values with IEEE binary128 format reuses part
 # of the internal float128 implementation (__printf_fp, __printf_fphex,
@@ -70,6 +73,14 @@  tests-internal += test-wprintf-ieee128 test-wprintf-ibm128
 CFLAGS-test-wprintf-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi
 CFLAGS-test-wprintf-ibm128.c += -mabi=ibmlongdouble -Wno-psabi
 
+tests-internal += test-obstack-ieee128 test-obstack-ibm128
+CFLAGS-test-obstack-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi
+CFLAGS-test-obstack-ibm128.c += -mabi=ibmlongdouble -Wno-psabi
+
+tests-internal += test-obstack-chk-ieee128 test-obstack-chk-ibm128
+CFLAGS-test-obstack-chk-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi
+CFLAGS-test-obstack-chk-ibm128.c += -mabi=ibmlongdouble -Wno-psabi
+
 tests-internal += test-scanf-ieee128 test-scanf-ibm128
 CFLAGS-test-scanf-ieee128.c += -mfloat128 -mabi=ieeelongdouble -Wno-psabi
 CFLAGS-test-scanf-ibm128.c += -mabi=ibmlongdouble -Wno-psabi
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/Versions b/sysdeps/ieee754/ldbl-128ibm-compat/Versions
index 23c2fd9793..f59dfb59fe 100644
--- a/sysdeps/ieee754/ldbl-128ibm-compat/Versions
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/Versions
@@ -165,6 +165,11 @@  libc {
     __vswprintf_chkieee128;
     __vwprintf_chkieee128;
 
+    __obstack_printfieee128;
+    __obstack_vprintfieee128;
+    __obstack_printf_chkieee128;
+    __obstack_vprintf_chkieee128;
+
     __fscanfieee128;
     __scanfieee128;
     __sscanfieee128;
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obprintf.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obprintf.c
new file mode 100644
index 0000000000..924838eed5
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obprintf.c
@@ -0,0 +1,42 @@ 
+/* Wrapper for obstack_vprintf and obstack_printf.  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 <stdarg.h>
+#include <libio/libioP.h>
+
+int
+__ieee128_obstack_vprintf (struct obstack *obstack, const char *format,
+			   va_list ap)
+{
+  return __obstack_vprintf_internal (obstack, format, ap,
+				     PRINTF_LDBL_USES_FLOAT128);
+}
+strong_alias (__ieee128_obstack_vprintf, __obstack_vprintfieee128)
+
+int
+__ieee128_obstack_printf (struct obstack *obstack, const char *format, ...)
+{
+  int result;
+  va_list ap;
+  va_start (ap, format);
+  result = __obstack_vprintf_internal (obstack, format, ap,
+				       PRINTF_LDBL_USES_FLOAT128);
+  va_end (ap);
+  return result;
+}
+strong_alias (__ieee128_obstack_printf, __obstack_printfieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obstack_chk.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obstack_chk.c
new file mode 100644
index 0000000000..194589ca26
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-obstack_chk.c
@@ -0,0 +1,39 @@ 
+/* Wrapper for __obstack_printf_chk.  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 <stdarg.h>
+#include <libio/libioP.h>
+
+extern int
+___ieee128_obstack_printf_chk (struct obstack *obstack, int flag,
+			       const char *format, ...)
+{
+  va_list ap;
+  int done;
+
+  unsigned int mode = PRINTF_LDBL_USES_FLOAT128;
+  if (flag > 0)
+    mode |= PRINTF_FORTIFY;
+
+  va_start (ap, format);
+  done = __obstack_vprintf_internal (obstack, format, ap, mode);
+  va_end (ap);
+
+  return done;
+}
+strong_alias (___ieee128_obstack_printf_chk, __obstack_printf_chkieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vobstack_chk.c b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vobstack_chk.c
new file mode 100644
index 0000000000..fa5182aac9
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/ieee128-vobstack_chk.c
@@ -0,0 +1,31 @@ 
+/* Wrapper for __obstack_vprintf_chk.  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 <libio/libioP.h>
+
+extern int
+___ieee128__obstack_vprintf_chk  (struct obstack *obstack, int flag,
+				  const char *format, va_list ap)
+{
+  unsigned int mode = PRINTF_LDBL_USES_FLOAT128;
+  if (flag > 0)
+    mode |= PRINTF_FORTIFY;
+
+  return __obstack_vprintf_internal (obstack, format, ap, mode);
+}
+strong_alias (___ieee128__obstack_vprintf_chk, __obstack_vprintf_chkieee128)
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ibm128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ibm128.c
new file mode 100644
index 0000000000..ca4c9f2d22
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ibm128.c
@@ -0,0 +1 @@ 
+#include <test-obstack-chk-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ieee128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ieee128.c
new file mode 100644
index 0000000000..ca4c9f2d22
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ieee128.c
@@ -0,0 +1 @@ 
+#include <test-obstack-chk-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ldbl-compat.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ldbl-compat.c
new file mode 100644
index 0000000000..feae8f21c6
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-chk-ldbl-compat.c
@@ -0,0 +1,6 @@ 
+#define _FORTIFY_SOURCE 2
+#define OBSTACK_FUNCTION __obstack_printf_chk
+#define OBSTACK_FUNCTION_PARAMS (&ob, 1, "%.30Lf", ld)
+#define VOBSTACK_FUNCTION __obstack_vprintf_chk
+#define VOBSTACK_FUNCTION_PARAMS (&ob, 1, "%.30Lf", ap)
+#include <test-obstack-ldbl-compat-template.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ibm128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ibm128.c
new file mode 100644
index 0000000000..be88675030
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ibm128.c
@@ -0,0 +1 @@ 
+#include <test-obstack-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ieee128.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ieee128.c
new file mode 100644
index 0000000000..be88675030
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ieee128.c
@@ -0,0 +1 @@ 
+#include <test-obstack-ldbl-compat.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat-template.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat-template.c
new file mode 100644
index 0000000000..c82ddc4355
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat-template.c
@@ -0,0 +1,64 @@ 
+/* Test for the long double variants of obstrack*printf 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 <malloc.h>
+#include <obstack.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include <support/check.h>
+
+#define obstack_chunk_alloc malloc
+#define obstack_chunk_free free
+
+static void
+do_test_call (void *last, ...)
+{
+  const char *expected = "-1.000000000000000000000000000000";
+  char *actual = NULL;
+  long double ld = -1;
+  struct obstack ob;
+  va_list ap;
+
+  obstack_init (&ob);
+  OBSTACK_FUNCTION OBSTACK_FUNCTION_PARAMS;
+  actual = (char *) obstack_finish (&ob);
+  TEST_VERIFY (strncmp (expected, actual, 33) == 0);
+  obstack_free (&ob, NULL);
+  actual = NULL;
+
+  obstack_init (&ob);
+  va_start (ap, last);
+  VOBSTACK_FUNCTION VOBSTACK_FUNCTION_PARAMS;
+  va_end (ap);
+  actual = (char *) obstack_finish (&ob);
+  TEST_VERIFY (strncmp (expected, actual, 33) == 0);
+  obstack_free (&ob, NULL);
+  actual = NULL;
+}
+
+static int
+do_test (void)
+{
+  long double ld = -1;
+  do_test_call (NULL, ld);
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat.c b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat.c
new file mode 100644
index 0000000000..3849d25ef1
--- /dev/null
+++ b/sysdeps/ieee754/ldbl-128ibm-compat/test-obstack-ldbl-compat.c
@@ -0,0 +1,6 @@ 
+#define _FORTIFY_SOURCE 0
+#define OBSTACK_FUNCTION obstack_printf
+#define OBSTACK_FUNCTION_PARAMS (&ob, "%.30Lf", ld)
+#define VOBSTACK_FUNCTION obstack_vprintf
+#define VOBSTACK_FUNCTION_PARAMS (&ob, "%.30Lf", ap)
+#include <test-obstack-ldbl-compat-template.c>