From patchwork Mon Oct 29 12:16:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel F. T. Gomes" X-Patchwork-Id: 29942 Received: (qmail 22761 invoked by alias); 29 Oct 2018 12:17:30 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 20581 invoked by uid 89); 29 Oct 2018 12:17:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=39046 X-HELO: mo19.mail-out.ovh.net From: "Gabriel F. T. Gomes" To: Subject: [PATCH v2 4/8] Use SCANF_LDBL_IS_DBL instead of __ldbl_is_dbl. Date: Mon, 29 Oct 2018 09:16:46 -0300 Message-ID: <20181029121650.24544-5-gabriel@inconstante.eti.br> In-Reply-To: <20181029121650.24544-1-gabriel@inconstante.eti.br> References: <20181029121650.24544-1-gabriel@inconstante.eti.br> MIME-Version: 1.0 X-Ovh-Tracer-Id: 18036916510541795011 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrheekgdefjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecu From: Zack Weinberg Changed since v1: - In __nldbl___isoc99_vwscanf, called __vfwscanf_internal directly (missing (accidentally?) from the previous version). - Broke long lines. - Changed name of variable (from rv to ret), since the rationale for making these changes to variables names is consistency. - Added signed-off-by statements. -- 8< -- Change the callers of __vfscanf_internal and __vfwscanf_internal that want to treat 'long double' as another name for 'double' (all of which happen to be in sysdeps/ieee754/ldbl-opt/nldbl-compat.c) to communicate this via the new flags argument, instead of the per-thread variable __no_long_double and its __ldbl_is_dbl wrapper macro. Tested for powerpc and powerpc64le. 2018-10-16 Zack Weinberg Gabriel F. T. Gomes * stdio-common/vfscanf-internal.c: Don't look at __ldbl_is_dbl. * sysdeps/ieee754/ldbl-opt/ndlbl-compat.c: Include libio/strfile.h instead of libioP.h. (__nldbl_IO_vfscanf, __ndlbl___vfscanf, __nldbl_sscanf) (__nldbl___vsscanf, __nldbl_vscanf, __nldbl_fscanf) (__nldbl_scanf, __nldbl_vfwscanf, __nldbl_swscanf) (__nldbl_vswscanf, __nldbl_vwscanf, __nldbl_fwscanf) (__nldbl_wscanf): Call __vfscanf_internal / __vfwscanf_internal directly, passing SCANF_LDBL_IS_DBL. Set up a strfile if necessary. Do not set __no_long_double. Normalize variable names. (__nldbl___isoc99_vfscanf, __nldbl___isoc99_sscanf) (__nldbl___isoc99_vsscanf, __nldbl___isoc99_vscanf) (__nldbl___isoc99_fscanf, __nldbl___isoc99_scanf) (__nldbl___isoc99_vfwscanf, __nldbl___isoc99_swscanf) (__nldbl___isoc99_vswscanf, __nldbl___isoc99_vwscanf) (__nldbl___isoc99_fwscanf, __nldbl___isoc99_wscanf): Call __vfscanf_internal / __vfwscanf_internal directly, passing SCANF_LDBL_IS_DBL | SCANF_ISOC99_A. Set up a strfile if necessary. Do not set __no_long_double. Normalize variable names. Signed-off-by: Zack Weinberg Signed-off-by: Gabriel F. T. Gomes --- stdio-common/vfscanf-internal.c | 3 - sysdeps/ieee754/ldbl-opt/nldbl-compat.c | 251 +++++++++++++++----------------- 2 files changed, 121 insertions(+), 133 deletions(-) diff --git a/stdio-common/vfscanf-internal.c b/stdio-common/vfscanf-internal.c index dc341b0b1f..f989f8dc07 100644 --- a/stdio-common/vfscanf-internal.c +++ b/stdio-common/vfscanf-internal.c @@ -334,9 +334,6 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, #define LDBL_DISTINCT (__glibc_likely ((mode_flags & SCANF_LDBL_IS_DBL) == 0)) #define USE_ISOC99_A (__glibc_likely (mode_flags & SCANF_ISOC99_A)) - /* Temporarily honor the environmental mode bits. */ - if (__ldbl_is_dbl) - mode_flags |= SCANF_LDBL_IS_DBL; #ifdef __va_copy __va_copy (arg, argptr); diff --git a/sysdeps/ieee754/ldbl-opt/nldbl-compat.c b/sysdeps/ieee754/ldbl-opt/nldbl-compat.c index 91ea27a423..468e23dec4 100644 --- a/sysdeps/ieee754/ldbl-opt/nldbl-compat.c +++ b/sysdeps/ieee754/ldbl-opt/nldbl-compat.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -335,13 +335,10 @@ int attribute_compat_text_section __nldbl__IO_vfscanf (FILE *s, const char *fmt, va_list ap, int *errp) { - int res; - set_no_long_double (); - res = __vfscanf_internal (s, fmt, ap, 0); - clear_no_long_double (); + int ret = __vfscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL); if (__glibc_unlikely (errp != 0)) - *errp = (res == -1); - return res; + *errp = (ret == -1); + return ret; } #endif @@ -349,11 +346,7 @@ int attribute_compat_text_section __nldbl___vfscanf (FILE *s, const char *fmt, va_list ap) { - int res; - set_no_long_double (); - res = __vfscanf_internal (s, fmt, ap, 0); - clear_no_long_double (); - return res; + return __vfscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL); } weak_alias (__nldbl___vfscanf, __nldbl_vfscanf) libc_hidden_def (__nldbl_vfscanf) @@ -362,26 +355,26 @@ int attribute_compat_text_section __nldbl_sscanf (const char *s, const char *fmt, ...) { - va_list arg; - int done; + _IO_strfile sf; + FILE *f = _IO_strfile_read (&sf, s); + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl_vsscanf (s, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL); + va_end (ap); - return done; + return ret; } strong_alias (__nldbl_sscanf, __nldbl__IO_sscanf) int attribute_compat_text_section -__nldbl___vsscanf (const char *string, const char *fmt, va_list ap) +__nldbl___vsscanf (const char *s, const char *fmt, va_list ap) { - int res; - __no_long_double = 1; - res = _IO_vsscanf (string, fmt, ap); - __no_long_double = 0; - return res; + _IO_strfile sf; + FILE *f = _IO_strfile_read (&sf, s); + return __vfscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL); } weak_alias (__nldbl___vsscanf, __nldbl_vsscanf) libc_hidden_def (__nldbl_vsscanf) @@ -390,46 +383,42 @@ int attribute_compat_text_section weak_function __nldbl_vscanf (const char *fmt, va_list ap) { - return __nldbl_vfscanf (stdin, fmt, ap); + return __vfscanf_internal (stdin, fmt, ap, SCANF_LDBL_IS_DBL); } int attribute_compat_text_section __nldbl_fscanf (FILE *stream, const char *fmt, ...) { - va_list arg; - int done; + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl_vfscanf (stream, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfscanf_internal (stream, fmt, ap, SCANF_LDBL_IS_DBL); + va_end (ap); - return done; + return ret; } int attribute_compat_text_section __nldbl_scanf (const char *fmt, ...) { - va_list arg; - int done; + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl_vfscanf (stdin, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfscanf_internal (stdin, fmt, ap, SCANF_LDBL_IS_DBL); + va_end (ap); - return done; + return ret; } int attribute_compat_text_section __nldbl_vfwscanf (FILE *s, const wchar_t *fmt, va_list ap) { - int res; - set_no_long_double (); - res = __vfwscanf_internal (s, fmt, ap, 0); - clear_no_long_double (); - return res; + return __vfwscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL); } libc_hidden_def (__nldbl_vfwscanf) @@ -437,25 +426,28 @@ int attribute_compat_text_section __nldbl_swscanf (const wchar_t *s, const wchar_t *fmt, ...) { - va_list arg; - int done; + _IO_strfile sf; + struct _IO_wide_data wd; + FILE *f = _IO_strfile_readw (&sf, &wd, s); + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl_vswscanf (s, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfwscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL); + va_end (ap); - return done; + return ret; } int attribute_compat_text_section -__nldbl_vswscanf (const wchar_t *string, const wchar_t *fmt, va_list ap) +__nldbl_vswscanf (const wchar_t *s, const wchar_t *fmt, va_list ap) { - int res; - __no_long_double = 1; - res = vswscanf (string, fmt, ap); - __no_long_double = 0; - return res; + _IO_strfile sf; + struct _IO_wide_data wd; + FILE *f = _IO_strfile_readw (&sf, &wd, s); + + return __vfwscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL); } libc_hidden_def (__nldbl_vswscanf) @@ -463,35 +455,35 @@ int attribute_compat_text_section weak_function __nldbl_vwscanf (const wchar_t *fmt, va_list ap) { - return __nldbl_vfwscanf (stdin, fmt, ap); + return __vfwscanf_internal (stdin, fmt, ap, SCANF_LDBL_IS_DBL); } int attribute_compat_text_section __nldbl_fwscanf (FILE *stream, const wchar_t *fmt, ...) { - va_list arg; - int done; + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl_vfwscanf (stream, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfwscanf_internal (stream, fmt, ap, SCANF_LDBL_IS_DBL); + va_end (ap); - return done; + return ret; } int attribute_compat_text_section __nldbl_wscanf (const wchar_t *fmt, ...) { - va_list arg; - int done; + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl_vfwscanf (stdin, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfwscanf_internal (stdin, fmt, ap, SCANF_LDBL_IS_DBL); + va_end (ap); - return done; + return ret; } int @@ -866,11 +858,7 @@ int attribute_compat_text_section __nldbl___isoc99_vfscanf (FILE *s, const char *fmt, va_list ap) { - int res; - set_no_long_double (); - res = __isoc99_vfscanf (s, fmt, ap); - clear_no_long_double (); - return res; + return __vfscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); } libc_hidden_def (__nldbl___isoc99_vfscanf) @@ -878,25 +866,26 @@ int attribute_compat_text_section __nldbl___isoc99_sscanf (const char *s, const char *fmt, ...) { - va_list arg; - int done; + _IO_strfile sf; + FILE *f = _IO_strfile_read (&sf, s); + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl___isoc99_vsscanf (s, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); + va_end (ap); - return done; + return ret; } int attribute_compat_text_section -__nldbl___isoc99_vsscanf (const char *string, const char *fmt, va_list ap) +__nldbl___isoc99_vsscanf (const char *s, const char *fmt, va_list ap) { - int res; - __no_long_double = 1; - res = __isoc99_vsscanf (string, fmt, ap); - __no_long_double = 0; - return res; + _IO_strfile sf; + FILE *f = _IO_strfile_read (&sf, s); + + return __vfscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); } libc_hidden_def (__nldbl___isoc99_vsscanf) @@ -904,46 +893,44 @@ int attribute_compat_text_section __nldbl___isoc99_vscanf (const char *fmt, va_list ap) { - return __nldbl___isoc99_vfscanf (stdin, fmt, ap); + return __vfscanf_internal (stdin, fmt, ap, + SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); } int attribute_compat_text_section -__nldbl___isoc99_fscanf (FILE *stream, const char *fmt, ...) +__nldbl___isoc99_fscanf (FILE *s, const char *fmt, ...) { - va_list arg; - int done; + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl___isoc99_vfscanf (stream, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); + va_end (ap); - return done; + return ret; } int attribute_compat_text_section __nldbl___isoc99_scanf (const char *fmt, ...) { - va_list arg; - int done; + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl___isoc99_vfscanf (stdin, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfscanf_internal (stdin, fmt, ap, + SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); + va_end (ap); - return done; + return ret; } int attribute_compat_text_section __nldbl___isoc99_vfwscanf (FILE *s, const wchar_t *fmt, va_list ap) { - int res; - set_no_long_double (); - res = __isoc99_vfwscanf (s, fmt, ap); - clear_no_long_double (); - return res; + return __vfwscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); } libc_hidden_def (__nldbl___isoc99_vfwscanf) @@ -951,26 +938,28 @@ int attribute_compat_text_section __nldbl___isoc99_swscanf (const wchar_t *s, const wchar_t *fmt, ...) { - va_list arg; - int done; + _IO_strfile sf; + struct _IO_wide_data wd; + FILE *f = _IO_strfile_readw (&sf, &wd, s); + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl___isoc99_vswscanf (s, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfwscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); + va_end (ap); - return done; + return ret; } int attribute_compat_text_section -__nldbl___isoc99_vswscanf (const wchar_t *string, const wchar_t *fmt, - va_list ap) +__nldbl___isoc99_vswscanf (const wchar_t *s, const wchar_t *fmt, va_list ap) { - int res; - __no_long_double = 1; - res = __isoc99_vswscanf (string, fmt, ap); - __no_long_double = 0; - return res; + _IO_strfile sf; + struct _IO_wide_data wd; + FILE *f = _IO_strfile_readw (&sf, &wd, s); + + return __vfwscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); } libc_hidden_def (__nldbl___isoc99_vswscanf) @@ -978,35 +967,37 @@ int attribute_compat_text_section __nldbl___isoc99_vwscanf (const wchar_t *fmt, va_list ap) { - return __nldbl___isoc99_vfwscanf (stdin, fmt, ap); + return __vfwscanf_internal (stdin, fmt, ap, + SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); } int attribute_compat_text_section -__nldbl___isoc99_fwscanf (FILE *stream, const wchar_t *fmt, ...) +__nldbl___isoc99_fwscanf (FILE *s, const wchar_t *fmt, ...) { - va_list arg; - int done; + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl___isoc99_vfwscanf (stream, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfwscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); + va_end (ap); - return done; + return ret; } int attribute_compat_text_section __nldbl___isoc99_wscanf (const wchar_t *fmt, ...) { - va_list arg; - int done; + va_list ap; + int ret; - va_start (arg, fmt); - done = __nldbl___isoc99_vfwscanf (stdin, fmt, arg); - va_end (arg); + va_start (ap, fmt); + ret = __vfwscanf_internal (stdin, fmt, ap, + SCANF_LDBL_IS_DBL | SCANF_ISOC99_A); + va_end (ap); - return done; + return ret; } #if LONG_DOUBLE_COMPAT(libc, GLIBC_2_0)