From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 2281B3947428; Wed, 16 Mar 2022 17:57:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2281B3947428 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/azanella/clang] Replace internal usage of strtol and wcstol for internal alias X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/azanella/clang X-Git-Oldrev: d05e6dc8d1032e1732542a48e0fb895432008b6e X-Git-Newrev: 541a2a108e2b0d61cfd70710d7ca4a9a5b5df46e Message-Id: <20220316175752.2281B3947428@sourceware.org> Date: Wed, 16 Mar 2022 17:57:52 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Mar 2022 17:57:52 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=541a2a108e2b0d61cfd70710d7ca4a9a5b5df46e commit 541a2a108e2b0d61cfd70710d7ca4a9a5b5df46e Author: Adhemerval Zanella Date: Thu Mar 3 12:11:11 2022 -0300 Replace internal usage of strtol and wcstol for internal alias To clean up the exported headers to have only one function prototype with the ABI aliais (if any) it requires to use the internal alias for all symbols, since to redirect the internal usage a new it requires to redirect the symbol with an extra prototype (which this patch tries to avoid). The atoi is replace with __strtol due the optimization on stdlib.h. Checked on x86_64-linux-gnu and powerpc64le-linux-gnu. Diff: --- argp/argp-help.c | 2 +- argp/argp-parse.c | 2 +- iconv/gconv_conf.c | 2 +- include/stdlib.h | 25 ++++++++++++++++--------- include/wchar.h | 24 ++++++++++++++++-------- inet/rexec.c | 2 +- intl/plural-exp.c | 2 +- nss/nss_files/files-parse.c | 4 ++++ posix/wordexp.c | 4 ++-- resolv/inet_addr.c | 2 +- resolv/res_init.c | 6 +++--- stdlib/atof.c | 2 +- stdlib/atoi.c | 2 +- stdlib/atol.c | 2 +- stdlib/atoll.c | 2 +- stdlib/fmtmsg.c | 2 +- stdlib/strtod.c | 7 +++++-- stdlib/strtol.c | 2 +- stdlib/strtold.c | 18 +++++++++--------- sysdeps/posix/getaddrinfo.c | 1 + sysdeps/unix/sysv/linux/getlogin_r.c | 2 +- sysdeps/unix/sysv/linux/getsysstats.c | 6 +++--- sysdeps/unix/sysv/linux/readonly-area.c | 4 ++-- sysdeps/unix/sysv/linux/sysconf.c | 2 +- sysdeps/wordsize-64/strtol.c | 3 +-- time/tzset.c | 2 +- 26 files changed, 77 insertions(+), 55 deletions(-) diff --git a/argp/argp-help.c b/argp/argp-help.c index 90a2795cef..f128313e06 100644 --- a/argp/argp-help.c +++ b/argp/argp-help.c @@ -210,7 +210,7 @@ fill_in_uparams (const struct argp_state *state) } else if (isdigit ((unsigned char) *arg)) { - val = atoi (arg); + val = (int) __strtol (arg, NULL, 10); while (isdigit ((unsigned char) *arg)) arg++; SKIPWS (arg); diff --git a/argp/argp-parse.c b/argp/argp-parse.c index 68dc45417b..13cd84dd33 100644 --- a/argp/argp-parse.c +++ b/argp/argp-parse.c @@ -147,7 +147,7 @@ argp_default_parser (int key, char *arg, struct argp_state *state) break; case OPT_HANG: - _argp_hang = atoi (arg ? arg : "3600"); + _argp_hang = (int) __strtol (arg ? arg : "3600", NULL, 10); while (_argp_hang-- > 0) __sleep (1); break; diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c index f069e28323..989ccc479e 100644 --- a/iconv/gconv_conf.c +++ b/iconv/gconv_conf.c @@ -290,7 +290,7 @@ add_module (char *rp, const char *directory, size_t dir_len, int modcounter) char *endp; *wp++ = '\0'; - cost_hi = strtol (rp, &endp, 10); + cost_hi = __strtol (rp, &endp, 10); if (rp == endp || cost_hi < 1) /* No useful information. */ cost_hi = 1; diff --git a/include/stdlib.h b/include/stdlib.h index 1c6f70b082..f1f313b15f 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -221,15 +221,22 @@ libc_hidden_proto (____strtoul_l_internal) libc_hidden_proto (____strtoull_l_internal) #include -libc_hidden_proto (strtof) -libc_hidden_proto (strtod) +extern __typeof (strtof) __strtof; +libc_hidden_proto (__strtof) +extern __typeof (strtod) __strtod; +libc_hidden_proto (__strtod) #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0 -libc_hidden_proto (strtold) +extern __typeof (strtold) __strtold; +libc_hidden_proto (__strtold) #endif -libc_hidden_proto (strtol) -libc_hidden_proto (strtoll) -libc_hidden_proto (strtoul) -libc_hidden_proto (strtoull) +extern __typeof (strtol) __strtol; +libc_hidden_proto (__strtol) +extern __typeof (strtoll) __strtoll; +libc_hidden_proto (__strtoll) +extern __typeof (strtoul) __strtoul; +libc_hidden_proto (__strtoul) +extern __typeof (strtoull) __strtoull; +libc_hidden_proto (__strtoull) libc_hidden_proto (atoi) @@ -251,10 +258,10 @@ libc_hidden_proto (__wcstold_nan) #include #if __HAVE_DISTINCT_FLOAT128 +extern __typeof (strtof128) __strtof128; +libc_hidden_proto (__strtof128) extern __typeof (strtof128_l) __strtof128_l; - libc_hidden_proto (__strtof128_l) -libc_hidden_proto (strtof128) extern _Float128 __strtof128_nan (const char *, char **, char); extern _Float128 __wcstof128_nan (const wchar_t *, wchar_t **, wchar_t); diff --git a/include/wchar.h b/include/wchar.h index 4267985625..781ad7c20e 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -71,13 +71,20 @@ libc_hidden_proto (__wcstol_internal) libc_hidden_proto (__wcstoll_internal) libc_hidden_proto (__wcstoul_internal) libc_hidden_proto (__wcstoull_internal) -libc_hidden_proto (wcstof) -libc_hidden_proto (wcstod) -libc_hidden_ldbl_proto (wcstold) -libc_hidden_proto (wcstol) -libc_hidden_proto (wcstoll) -libc_hidden_proto (wcstoul) -libc_hidden_proto (wcstoull) +extern __typeof (wcstof) __wcstof; +libc_hidden_proto (__wcstof) +extern __typeof (wcstod) __wcstod; +libc_hidden_proto (__wcstod) +extern __typeof (wcstold) __wcstold; +libc_hidden_ldbl_proto (__wcstold) +extern __typeof (wcstol) __wcstol; +libc_hidden_proto (__wcstol) +extern __typeof (wcstoll) __wcstoll; +libc_hidden_proto (__wcstoll) +extern __typeof (wcstoul) __wcstoul; +libc_hidden_proto (__wcstoul) +extern __typeof (wcstoull) __wcstoull; +libc_hidden_proto (__wcstoull) extern float ____wcstof_l_internal (const wchar_t *, wchar_t **, int, locale_t) attribute_hidden; @@ -100,6 +107,8 @@ extern unsigned long long int ____wcstoull_l_internal (const wchar_t *, attribute_hidden; #if __HAVE_DISTINCT_FLOAT128 +extern __typeof (wcstof128) __wcstof128; +libc_hidden_proto (__wcstof128) extern __typeof (wcstof128_l) __wcstof128_l; libc_hidden_proto (__wcstof128_l) extern _Float128 __wcstof128_internal (const wchar_t *__restrict __nptr, @@ -110,7 +119,6 @@ extern _Float128 ____wcstof128_l_internal (const wchar_t *, wchar_t **, int, locale_t) attribute_hidden; libc_hidden_proto (__wcstof128_internal) -libc_hidden_proto (wcstof128) #endif libc_hidden_proto (__wcscasecmp_l) diff --git a/inet/rexec.c b/inet/rexec.c index 064e979d68..330282ac16 100644 --- a/inet/rexec.c +++ b/inet/rexec.c @@ -134,7 +134,7 @@ retry: if (!getnameinfo(&sa2.sa, sa2len, NULL, 0, servbuff, sizeof(servbuff), NI_NUMERICSERV)) - port = atoi(servbuff); + port = (int) __strtol (servbuff, NULL, 10); (void) sprintf(num, "%u", port); (void) __write(s, num, strlen(num)+1); { socklen_t len = sizeof (from); diff --git a/intl/plural-exp.c b/intl/plural-exp.c index d5aec23b55..80b0a5afb1 100644 --- a/intl/plural-exp.c +++ b/intl/plural-exp.c @@ -120,7 +120,7 @@ EXTRACT_PLURAL_EXPRESSION (const char *nullentry, if (!(*nplurals >= '0' && *nplurals <= '9')) goto no_plural; #if defined HAVE_STRTOUL || defined _LIBC - n = strtoul (nplurals, &endp, 10); + n = __strtoul (nplurals, &endp, 10); #else for (endp = nplurals, n = 0; *endp >= '0' && *endp <= '9'; endp++) n = n * 10 + (*endp - '0'); diff --git a/nss/nss_files/files-parse.c b/nss/nss_files/files-parse.c index c90e293802..bd3266702e 100644 --- a/nss/nss_files/files-parse.c +++ b/nss/nss_files/files-parse.c @@ -53,6 +53,10 @@ # define STRUCTURE ENTNAME #endif +#if IS_IN(libc) +# define strtoul __strtoul +#endif + struct parser_data { diff --git a/posix/wordexp.c b/posix/wordexp.c index d4cb9c734b..7bec5a73aa 100644 --- a/posix/wordexp.c +++ b/posix/wordexp.c @@ -564,7 +564,7 @@ eval_expr_val (char **expr, long int *result) /* POSIX requires that decimal, octal, and hexadecimal constants are recognized. Therefore we pass 0 as the third parameter to strtol. */ - *result = strtol (digit, expr, 0); + *result = __strtol (digit, expr, 0); if (digit == *expr) return WRDE_SYNTAX; @@ -1398,7 +1398,7 @@ envsubst: /* Is it a numeric parameter? */ else if (isdigit (env[0])) { - unsigned long n = strtoul (env, NULL, 10); + unsigned long n = __strtoul (env, NULL, 10); if (n >= __libc_argc) /* Substitute NULL. */ diff --git a/resolv/inet_addr.c b/resolv/inet_addr.c index 8059a23ec9..451531899d 100644 --- a/resolv/inet_addr.c +++ b/resolv/inet_addr.c @@ -130,7 +130,7 @@ inet_aton_end (const char *cp, struct in_addr *addr, const char **endp) goto ret_0; { char *endp; - unsigned long ul = strtoul (cp, &endp, 0); + unsigned long ul = __strtoul (cp, &endp, 0); if (ul == ULONG_MAX && errno == ERANGE) goto ret_0; if (ul > 0xfffffffful) diff --git a/resolv/res_init.c b/resolv/res_init.c index cbc16ba021..a6d5364835 100644 --- a/resolv/res_init.c +++ b/resolv/res_init.c @@ -654,7 +654,7 @@ res_setoptions (struct resolv_conf_parser *parser, const char *options) /* Search for and process individual options. */ if (!strncmp (cp, "ndots:", sizeof ("ndots:") - 1)) { - int i = atoi (cp + sizeof ("ndots:") - 1); + int i = (int) __strtol (cp + sizeof ("ndots:") - 1, NULL, 10); if (i <= RES_MAXNDOTS) parser->template.ndots = i; else @@ -662,7 +662,7 @@ res_setoptions (struct resolv_conf_parser *parser, const char *options) } else if (!strncmp (cp, "timeout:", sizeof ("timeout:") - 1)) { - int i = atoi (cp + sizeof ("timeout:") - 1); + int i = (int) __strtol (cp + sizeof ("timeout:") - 1, NULL, 10); if (i <= RES_MAXRETRANS) parser->template.retrans = i; else @@ -670,7 +670,7 @@ res_setoptions (struct resolv_conf_parser *parser, const char *options) } else if (!strncmp (cp, "attempts:", sizeof ("attempts:") - 1)) { - int i = atoi (cp + sizeof ("attempts:") - 1); + int i = (int) __strtol (cp + sizeof ("attempts:") - 1, NULL, 10); if (i <= RES_MAXRETRY) parser->template.retry = i; else diff --git a/stdlib/atof.c b/stdlib/atof.c index 782c6053eb..d208c6d329 100644 --- a/stdlib/atof.c +++ b/stdlib/atof.c @@ -24,5 +24,5 @@ double atof (const char *nptr) { - return strtod (nptr, (char **) NULL); + return __strtod (nptr, (char **) NULL); } diff --git a/stdlib/atoi.c b/stdlib/atoi.c index c977506b38..d7560121b7 100644 --- a/stdlib/atoi.c +++ b/stdlib/atoi.c @@ -24,6 +24,6 @@ int atoi (const char *nptr) { - return (int) strtol (nptr, (char **) NULL, 10); + return (int) __strtol (nptr, (char **) NULL, 10); } libc_hidden_def (atoi) diff --git a/stdlib/atol.c b/stdlib/atol.c index 5706d6e143..77183bd051 100644 --- a/stdlib/atol.c +++ b/stdlib/atol.c @@ -24,5 +24,5 @@ long int atol (const char *nptr) { - return strtol (nptr, (char **) NULL, 10); + return __strtol (nptr, (char **) NULL, 10); } diff --git a/stdlib/atoll.c b/stdlib/atoll.c index 05ad7c141b..5be05716e2 100644 --- a/stdlib/atoll.c +++ b/stdlib/atoll.c @@ -24,5 +24,5 @@ long long int atoll (const char *nptr) { - return strtoll (nptr, (char **) NULL, 10); + return __strtoll (nptr, (char **) NULL, 10); } diff --git a/stdlib/fmtmsg.c b/stdlib/fmtmsg.c index 787a263d63..3e48800331 100644 --- a/stdlib/fmtmsg.c +++ b/stdlib/fmtmsg.c @@ -263,7 +263,7 @@ init (void) /* Second field: severity level, a number. */ char *cp; - level = strtol (sevlevel_var, &cp, 0); + level = __strtol (sevlevel_var, &cp, 0); if (cp != sevlevel_var && cp < end && *cp++ == ',' && level > MM_INFO) { diff --git a/stdlib/strtod.c b/stdlib/strtod.c index 98794f22da..ce54584dd2 100644 --- a/stdlib/strtod.c +++ b/stdlib/strtod.c @@ -61,6 +61,8 @@ #define INTERNAL(x) INTERNAL1(x) #define INTERNAL1(x) __##x##_internal +#define DOUBLEUNDESCORE(x) DOUBLEUNDESCORE1(x) +#define DOUBLEUNDESCORE1(x) __##x FLOAT @@ -77,12 +79,13 @@ FLOAT #ifdef weak_function weak_function #endif -STRTOF (const STRING_TYPE *nptr, STRING_TYPE **endptr) +DOUBLEUNDESCORE (STRTOF) (const STRING_TYPE *nptr, STRING_TYPE **endptr) { return INTERNAL(STRTOF_L) (nptr, endptr, 0, _NL_CURRENT_LOCALE); } #if defined _LIBC -libc_hidden_def (STRTOF) +weak_alias (DOUBLEUNDESCORE (STRTOF), STRTOF) +libc_hidden_def (DOUBLEUNDESCORE (STRTOF)) #endif #ifdef LONG_DOUBLE_COMPAT diff --git a/stdlib/strtol.c b/stdlib/strtol.c index be7719f493..7e9611fb27 100644 --- a/stdlib/strtol.c +++ b/stdlib/strtol.c @@ -106,4 +106,4 @@ __strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base) return INTERNAL (__strtol_l) (nptr, endptr, base, 0, _NL_CURRENT_LOCALE); } weak_alias (__strtol, strtol) -libc_hidden_weak (strtol) +libc_hidden_weak (__strtol) diff --git a/stdlib/strtold.c b/stdlib/strtold.c index a03620e308..34ed8da0ea 100644 --- a/stdlib/strtold.c +++ b/stdlib/strtold.c @@ -34,13 +34,13 @@ #ifdef __LONG_DOUBLE_MATH_OPTIONAL # include # define NEW(x) NEW1(x) -# define NEW1(x) __new_##x -long double ____new_strtold_internal (const char *, char **, int); +# define NEW1(x) new_##x +long double __new_strtold_internal (const char *, char **, int); long double __new_strtold (const char *, char **); -long double ____new_wcstold_internal (const wchar_t *, wchar_t **, int); +long double __new_wcstold_internal (const wchar_t *, wchar_t **, int); long double __new_wcstold (const wchar_t *, wchar_t **); -libc_hidden_proto (____new_strtold_internal) -libc_hidden_proto (____new_wcstold_internal) +libc_hidden_proto (__new_strtold_internal) +libc_hidden_proto (__new_wcstold_internal) libc_hidden_proto (__new_strtold) libc_hidden_proto (__new_wcstold) #else @@ -63,12 +63,12 @@ libc_hidden_proto (__new_wcstold) # include # ifdef USE_WIDE_CHAR long_double_symbol (libc, __new_wcstold, wcstold); -long_double_symbol (libc, ____new_wcstold_internal, __wcstold_internal); -libc_hidden_ver (____new_wcstold_internal, __wcstold_internal) +long_double_symbol (libc, __new_wcstold_internal, __wcstold_internal); +libc_hidden_ver (__new_wcstold_internal, __wcstold_internal) # else long_double_symbol (libc, __new_strtold, strtold); -long_double_symbol (libc, ____new_strtold_internal, __strtold_internal); -libc_hidden_ver (____new_strtold_internal, __strtold_internal) +long_double_symbol (libc, __new_strtold_internal, __strtold_internal); +libc_hidden_ver (__new_strtold_internal, __strtold_internal) # endif #endif diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 18dccd5924..13372e8d47 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -90,6 +90,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if IS_IN (libc) # define feof_unlocked(fp) __feof_unlocked (fp) +# define strtoul __strtoul #endif struct gaih_service diff --git a/sysdeps/unix/sysv/linux/getlogin_r.c b/sysdeps/unix/sysv/linux/getlogin_r.c index 461716601e..290628f5aa 100644 --- a/sysdeps/unix/sysv/linux/getlogin_r.c +++ b/sysdeps/unix/sysv/linux/getlogin_r.c @@ -51,7 +51,7 @@ __getlogin_r_loginuid (char *name, size_t namesize) if (n <= 0 || n == sizeof (uidbuf) || (uidbuf[n] = '\0', - uid = strtoul (uidbuf, &endp, 10), + uid = __strtoul (uidbuf, &endp, 10), endp == uidbuf || *endp != '\0')) return -1; diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c index d1ea074f0d..0c65d0e268 100644 --- a/sysdeps/unix/sysv/linux/getsysstats.c +++ b/sysdeps/unix/sysv/linux/getsysstats.c @@ -156,7 +156,7 @@ get_nprocs_cpu_online (void) do { char *endp; - unsigned long int n = strtoul (l, &endp, 10); + unsigned long int n = __strtoul (l, &endp, 10); if (l == endp) { result = 0; @@ -167,7 +167,7 @@ get_nprocs_cpu_online (void) if (*endp == '-') { l = endp + 1; - m = strtoul (l, &endp, 10); + m = __strtoul (l, &endp, 10); if (l == endp) { result = 0; @@ -204,7 +204,7 @@ get_nprocs_cpu (void) if (d->d_type == DT_DIR && strncmp (d->d_name, "cpu", 3) == 0) { char *endp; - unsigned long int nr = strtoul (d->d_name + 3, &endp, 10); + unsigned long int nr = __strtoul (d->d_name + 3, &endp, 10); if (nr != ULONG_MAX && endp != d->d_name + 3 && *endp == '\0') ++count; } diff --git a/sysdeps/unix/sysv/linux/readonly-area.c b/sysdeps/unix/sysv/linux/readonly-area.c index e8fde06fa9..3a94d7c52f 100644 --- a/sysdeps/unix/sysv/linux/readonly-area.c +++ b/sysdeps/unix/sysv/linux/readonly-area.c @@ -59,13 +59,13 @@ __readonly_area (const char *ptr, size_t size) break; char *p; - uintptr_t from = strtoul (line, &p, 16); + uintptr_t from = __strtoul (line, &p, 16); if (p == line || *p++ != '-') break; char *q; - uintptr_t to = strtoul (p, &q, 16); + uintptr_t to = __strtoul (p, &q, 16); if (q == p || *q++ != ' ') break; diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c index 7706819c32..4afc00c8d0 100644 --- a/sysdeps/unix/sysv/linux/sysconf.c +++ b/sysdeps/unix/sysv/linux/sysconf.c @@ -111,7 +111,7 @@ __sysconf (int name) buf[n] = '\0'; char *endp; - long int res = strtol (buf, &endp, 10); + long int res = __strtol (buf, &endp, 10); if (endp != buf && (*endp == '\0' || *endp == '\n')) return res; } diff --git a/sysdeps/wordsize-64/strtol.c b/sysdeps/wordsize-64/strtol.c index a1b2374153..9ce616c89e 100644 --- a/sysdeps/wordsize-64/strtol.c +++ b/sysdeps/wordsize-64/strtol.c @@ -11,7 +11,6 @@ strong_alias (__strtol_internal, __strtoll_internal) libc_hidden_ver (__strtol_internal, __strtoll_internal) weak_alias (strtol, strtoll) -libc_hidden_ver (strtol, strtoll) +libc_hidden_ver (__strtol, __strtoll) weak_alias (strtol, strtoq) -libc_hidden_ver (strtol, strtoq) weak_alias (strtol, strtoimax) diff --git a/time/tzset.c b/time/tzset.c index a06142bb58..ac20e1a560 100644 --- a/time/tzset.c +++ b/time/tzset.c @@ -242,7 +242,7 @@ parse_rule (const char **tzp, int whichrule) tzr->type = *tz == 'J' ? J1 : J0; if (tzr->type == J1 && !isdigit (*++tz)) return false; - unsigned long int d = strtoul (tz, &end, 10); + unsigned long int d = __strtoul (tz, &end, 10); if (end == tz || d > 365) return false; if (tzr->type == J1 && d == 0)