diff options
author | Aaron Crane <arc@cpan.org> | 2017-10-13 10:03:59 +0200 |
---|---|---|
committer | Aaron Crane <arc@cpan.org> | 2017-10-21 16:52:44 +0100 |
commit | f1519f70705b2eee563b9ac4056d4eb39d383ea1 (patch) | |
tree | 99be297bc99adf835bdb6832add4fbf24992a766 | |
parent | 03f3961765f87fb8bccb4e3fa5b9e2e533d7dc30 (diff) | |
download | perl-f1519f70705b2eee563b9ac4056d4eb39d383ea1.tar.gz |
Rely on C89 sprintf() return value semantics
-rwxr-xr-x | Configure | 65 | ||||
-rw-r--r-- | Cross/config.sh-arm-linux | 1 | ||||
-rw-r--r-- | Cross/config.sh-arm-linux-n770 | 1 | ||||
-rw-r--r-- | NetWare/config.wc | 1 | ||||
-rw-r--r-- | Porting/Glossary | 6 | ||||
-rw-r--r-- | Porting/config.sh | 1 | ||||
-rw-r--r-- | Porting/config_H | 8 | ||||
-rwxr-xr-x | config_h.SH | 8 | ||||
-rw-r--r-- | configure.com | 1 | ||||
-rw-r--r-- | embed.fnc | 4 | ||||
-rw-r--r-- | makedef.pl | 5 | ||||
-rw-r--r-- | perl.h | 16 | ||||
-rw-r--r-- | plan9/config_sh.sample | 1 | ||||
-rw-r--r-- | proto.h | 5 | ||||
-rw-r--r-- | symbian/config.sh | 1 | ||||
-rw-r--r-- | uconfig.h | 12 | ||||
-rw-r--r-- | uconfig.sh | 1 | ||||
-rw-r--r-- | uconfig64.sh | 1 | ||||
-rw-r--r-- | util.c | 22 | ||||
-rw-r--r-- | win32/config.ce | 1 | ||||
-rw-r--r-- | win32/config.gc | 1 | ||||
-rw-r--r-- | win32/config.vc | 1 | ||||
-rw-r--r-- | win32/config_H.ce | 8 | ||||
-rw-r--r-- | win32/config_H.gc | 8 | ||||
-rw-r--r-- | win32/config_H.vc | 8 |
25 files changed, 9 insertions, 178 deletions
@@ -830,7 +830,6 @@ sockethdr='' socketlib='' d_socklen_t='' d_socks5_init='' -d_sprintf_returns_strlen='' d_sqrtl='' d_srand48_r='' srand48_r_proto='' @@ -18537,69 +18536,6 @@ eval $hasproto set socks5_init d_socks5_init eval $inlibc -: see if sprintf returns the length of the string in the buffer as per ANSI -$echo "Checking whether sprintf returns the length of the string..." >&4 -$cat <<EOP >try.c -#include <stdio.h> -#$i_stdlib I_STDLIB -#ifdef I_STDLIB -#include <stdlib.h> -#endif -#$i_string I_STRING -#ifdef I_STRING -# include <string.h> -#else -# include <strings.h> -#endif -#$i_math I_MATH -#ifdef I_MATH -#include <math.h> -#endif - -char buffer[256]; - -int check (size_t expect, int test) { - size_t got = strlen(buffer); - if (expect == got) - return 0; - - printf("expected %ld, got %ld in test %d '%s'\n", (long) expect, (long) got, - test, buffer); - exit (test); -} - -int main(int argc, char **argv) { - int test = 0; - - check(sprintf(buffer, ""), ++test); - check(sprintf(buffer, "%s %s", "perl", "rules"), ++test); - check(sprintf(buffer, "I like %g", atan2(0,-1)), ++test); - - return 0; -} -EOP -set try - -if eval $compile; then - xxx="`$run ./try`" - case "$?" in - 0) cat >&4 <<EOM -sprintf returns the length of the string (as ANSI says it should) -EOM - d_sprintf_returns_strlen="$define" - ;; - *) cat >&4 <<EOM -sprintf does not return the length of the string (how old is this system?) -EOM - d_sprintf_returns_strlen="$undef" - ;; - esac -else - echo "(I can't seem to compile the test program--assuming it doesn't)" >&4 - d_sprintf_returns_strlen="$undef" -fi -$rm_try - : see if srand48_r exists set srand48_r d_srand48_r eval $inlibc @@ -24462,7 +24398,6 @@ d_socket='$d_socket' d_socklen_t='$d_socklen_t' d_sockpair='$d_sockpair' d_socks5_init='$d_socks5_init' -d_sprintf_returns_strlen='$d_sprintf_returns_strlen' d_sqrtl='$d_sqrtl' d_srand48_r='$d_srand48_r' d_srandom_r='$d_srandom_r' diff --git a/Cross/config.sh-arm-linux b/Cross/config.sh-arm-linux index 0bcaba4219..5ccf847b6d 100644 --- a/Cross/config.sh-arm-linux +++ b/Cross/config.sh-arm-linux @@ -537,7 +537,6 @@ d_socket='define' d_socklen_t='define' d_sockpair='define' d_socks5_init='undef' -d_sprintf_returns_strlen='define' d_sqrtl='define' d_srand48_r='undef' d_srandom_r='undef' diff --git a/Cross/config.sh-arm-linux-n770 b/Cross/config.sh-arm-linux-n770 index a39cd6f648..5e7a6bbabc 100644 --- a/Cross/config.sh-arm-linux-n770 +++ b/Cross/config.sh-arm-linux-n770 @@ -420,7 +420,6 @@ d_socket='define' d_socklen_t='define' d_sockpair='define' d_socks5_init='undef' -d_sprintf_returns_strlen='define' d_sqrtl='define' d_srand48_r='undef' d_srandom_r='undef' diff --git a/NetWare/config.wc b/NetWare/config.wc index 1bbafd4fde..80a3fad824 100644 --- a/NetWare/config.wc +++ b/NetWare/config.wc @@ -527,7 +527,6 @@ d_socket='define' d_socklen_t='undef' d_sockpair='undef' d_socks5_init='undef' -d_sprintf_returns_strlen='undef' d_sqrtl='undef' d_srand48_r='undef' d_srandom_r='undef' diff --git a/Porting/Glossary b/Porting/Glossary index 4821813c00..97a5a8c6a8 100644 --- a/Porting/Glossary +++ b/Porting/Glossary @@ -2466,12 +2466,6 @@ d_socks5_init (d_socks5_init.U): This variable conditionally defines the HAS_SOCKS5_INIT symbol, which indicates to the C program that the socks5_init() routine is available. -d_sprintf_returns_strlen (d_sprintf_len.U): - This variable defines whether sprintf returns the length of the string - (as per the ANSI spec). Some C libraries retain compatibility with - pre-ANSI C and return a pointer to the passed in buffer; for these - this variable will be undef. - d_sqrtl (d_sqrtl.U): This variable conditionally defines the HAS_SQRTL symbol, which indicates to the C program that the sqrtl() routine is available. diff --git a/Porting/config.sh b/Porting/config.sh index dfc62f4ce6..ea0a08da16 100644 --- a/Porting/config.sh +++ b/Porting/config.sh @@ -550,7 +550,6 @@ d_socket='define' d_socklen_t='define' d_sockpair='define' d_socks5_init='undef' -d_sprintf_returns_strlen='define' d_sqrtl='define' d_srand48_r='undef' d_srandom_r='undef' diff --git a/Porting/config_H b/Porting/config_H index 93865a7916..b3d74a9358 100644 --- a/Porting/config_H +++ b/Porting/config_H @@ -3502,14 +3502,6 @@ */ /*#define HAS_SOCKS5_INIT / **/ -/* SPRINTF_RETURNS_STRLEN: - * This variable defines whether sprintf returns the length of the string - * (as per the ANSI spec). Some C libraries retain compatibility with - * pre-ANSI C and return a pointer to the passed in buffer; for these - * this variable will be undef. - */ -#define SPRINTF_RETURNS_STRLEN /**/ - /* HAS_SQRTL: * This symbol, if defined, indicates that the sqrtl routine is * available to do long double square roots. diff --git a/config_h.SH b/config_h.SH index 6c0520135d..bbd4261133 100755 --- a/config_h.SH +++ b/config_h.SH @@ -3370,14 +3370,6 @@ sed <<!GROK!THIS! >$CONFIG_H -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un */ #$d_socks5_init HAS_SOCKS5_INIT /**/ -/* SPRINTF_RETURNS_STRLEN: - * This variable defines whether sprintf returns the length of the string - * (as per the ANSI spec). Some C libraries retain compatibility with - * pre-ANSI C and return a pointer to the passed in buffer; for these - * this variable will be undef. - */ -#$d_sprintf_returns_strlen SPRINTF_RETURNS_STRLEN /**/ - /* HAS_SQRTL: * This symbol, if defined, indicates that the sqrtl routine is * available to do long double square roots. diff --git a/configure.com b/configure.com index 97301173aa..e4780c0676 100644 --- a/configure.com +++ b/configure.com @@ -6375,7 +6375,6 @@ $ WC "d_socket='" + d_socket + "'" $ WC "d_socklen_t='" + d_socklen_t + "'" $ WC "d_sockpair='" + d_sockpair + "'" $ WC "d_socks5_init='undef'" -$ WC "d_sprintf_returns_strlen='define'" $ WC "d_sqrtl='define'" $ WC "d_sresgproto='undef'" $ WC "d_sresgproto='undef'" @@ -3005,10 +3005,6 @@ ApoP |bool |ckwarn_d |U32 w XEopMR |STRLEN *|new_warnings_bitfield|NULLOK STRLEN *buffer \ |NN const char *const bits|STRLEN size -#ifndef SPRINTF_RETURNS_STRLEN -Apnod |int |my_sprintf |NN char *buffer|NN const char *pat|... -#endif - Apnodf |int |my_snprintf |NN char *buffer|const Size_t len|NN const char *format|... Apnod |int |my_vsnprintf |NN char *buffer|const Size_t len|NN const char *format|va_list ap #ifdef USE_QUADMATH diff --git a/makedef.pl b/makedef.pl index 2af197fa43..5f05c85f3b 100644 --- a/makedef.pl +++ b/makedef.pl @@ -108,7 +108,6 @@ my $config_h = 'config.h'; open(CFG, '<', $config_h) || die "Cannot open $config_h: $!\n"; while (<CFG>) { $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY - |SPRINTF_RETURNS_STRLEN |KILL_BY_SIGPRC |(?:PERL|USE|HAS)_\w+)\b/x; } @@ -465,10 +464,6 @@ unless ($define{'PERL_DONT_CREATE_GVSV'}) { ++$skip{Perl_gv_SVadd}; } -if ($define{'SPRINTF_RETURNS_STRLEN'}) { - ++$skip{Perl_my_sprintf}; -} - unless ($define{'PERL_USES_PL_PIDSTATUS'}) { ++$skip{PL_pidstatus}; } @@ -1455,15 +1455,13 @@ EXTERN_C char *crypt(const char *, const char *); #undef UV #endif -/* For the times when you want the return value of sprintf, and you want it - to be the length. Can't have a thread variable passed in, because C89 has - no varargs macros. -*/ -#ifdef SPRINTF_RETURNS_STRLEN -# define my_sprintf sprintf -#else -# define my_sprintf Perl_my_sprintf -#endif +/* This used to be conditionally defined based on whether we had a sprintf() + * that correctly returns the string length (as required by C89), but we no + * longer need that. XS modules can (and do) use this name, so it must remain + * a part of the API that's visible to modules. But we no longer document it + * either (because using sprintf() rather than snprintf() is almost always + * a bad idea). */ +#define my_sprintf sprintf /* * If we have v?snprintf() and the C99 variadic macros, we can just diff --git a/plan9/config_sh.sample b/plan9/config_sh.sample index bfe766628b..114a58932f 100644 --- a/plan9/config_sh.sample +++ b/plan9/config_sh.sample @@ -537,7 +537,6 @@ d_socket='define' d_socklen_t='undef' d_sockpair='define' d_socks5_init='undef' -d_sprintf_returns_strlen='undef' d_sqrtl='undef' d_srand48_r='undef' d_srandom_r='undef' @@ -4059,11 +4059,6 @@ STATIC void S_validate_suid(pTHX_ PerlIO *rsfp); assert(rsfp) # endif #endif -#if !defined(SPRINTF_RETURNS_STRLEN) -PERL_CALLCONV int Perl_my_sprintf(char *buffer, const char *pat, ...); -#define PERL_ARGS_ASSERT_MY_SPRINTF \ - assert(buffer); assert(pat) -#endif #if !defined(USE_QUADMATH) # if defined(PERL_IN_NUMERIC_C) STATIC NV S_mulexp10(NV value, I32 exponent); diff --git a/symbian/config.sh b/symbian/config.sh index 904e973a3b..53aa97238d 100644 --- a/symbian/config.sh +++ b/symbian/config.sh @@ -486,7 +486,6 @@ d_socket='define' d_socklen_t='undef' d_sockpair='undef' d_socks5_init='undef' -d_sprintf_returns_strlen='define' d_sqrtl='undef' d_srand48_r='undef' d_srandom_r='undef' @@ -3335,14 +3335,6 @@ */ /*#define HAS_SOCKS5_INIT / **/ -/* SPRINTF_RETURNS_STRLEN: - * This variable defines whether sprintf returns the length of the string - * (as per the ANSI spec). Some C libraries retain compatibility with - * pre-ANSI C and return a pointer to the passed in buffer; for these - * this variable will be undef. - */ -/*#define SPRINTF_RETURNS_STRLEN / **/ - /* HAS_SQRTL: * This symbol, if defined, indicates that the sqrtl routine is * available to do long double square roots. @@ -5269,6 +5261,6 @@ #endif /* Generated from: - * 946b039c5c96299edae15aed6aeb6ca541042f6e545cb5631660412885369e33 config_h.SH - * ac7c2c95dc09327ba3d5305e3e786bcd8c6d759f88fc469a2f1b9310f03137f9 uconfig.sh + * a54380e85f5a0f9c6f5793c309854712008ac68f6370e6376c6a90edbecb6a7b config_h.SH + * d40282b246b20f1f20a5febcae42b3ac44234c5a1c1a2df89e5ac77a54830cca uconfig.sh * ex: set ro: */ diff --git a/uconfig.sh b/uconfig.sh index 14afc70a99..6fcd66d695 100644 --- a/uconfig.sh +++ b/uconfig.sh @@ -477,7 +477,6 @@ d_socket='undef' d_socklen_t='undef' d_sockpair='undef' d_socks5_init='undef' -d_sprintf_returns_strlen='undef' d_sqrtl='undef' d_srand48_r='undef' d_srandom_r='undef' diff --git a/uconfig64.sh b/uconfig64.sh index 94b0936aa3..6446f02485 100644 --- a/uconfig64.sh +++ b/uconfig64.sh @@ -477,7 +477,6 @@ d_socket='undef' d_socklen_t='undef' d_sockpair='undef' d_socks5_init='undef' -d_sprintf_returns_strlen='undef' d_sqrtl='undef' d_srand48_r='undef' d_srandom_r='undef' @@ -4868,28 +4868,6 @@ Perl_mem_log_del_sv(const SV *sv, #endif /* PERL_MEM_LOG */ /* -=for apidoc my_sprintf - -The C library C<sprintf>, wrapped if necessary, to ensure that it will return -the length of the string written to the buffer. Only rare pre-ANSI systems -need the wrapper function - usually this is a direct call to C<sprintf>. - -=cut -*/ -#ifndef SPRINTF_RETURNS_STRLEN -int -Perl_my_sprintf(char *buffer, const char* pat, ...) -{ - va_list args; - PERL_ARGS_ASSERT_MY_SPRINTF; - va_start(args, pat); - vsprintf(buffer, pat, args); - va_end(args); - return strlen(buffer); -} -#endif - -/* =for apidoc quadmath_format_single C<quadmath_snprintf()> is very strict about its C<format> string and will diff --git a/win32/config.ce b/win32/config.ce index adaea891be..da654aa97c 100644 --- a/win32/config.ce +++ b/win32/config.ce @@ -525,7 +525,6 @@ d_socket='define' d_socklen_t='undef' d_sockpair='undef' d_socks5_init='undef' -d_sprintf_returns_strlen='define' d_sqrtl='undef' d_srand48_r='undef' d_srandom_r='undef' diff --git a/win32/config.gc b/win32/config.gc index 591694625e..e1d276e2f5 100644 --- a/win32/config.gc +++ b/win32/config.gc @@ -526,7 +526,6 @@ d_socket='define' d_socklen_t='undef' d_sockpair='undef' d_socks5_init='undef' -d_sprintf_returns_strlen='define' d_sqrtl='undef' d_srand48_r='undef' d_srandom_r='undef' diff --git a/win32/config.vc b/win32/config.vc index 44baf36453..3ed21144bf 100644 --- a/win32/config.vc +++ b/win32/config.vc @@ -525,7 +525,6 @@ d_socket='define' d_socklen_t='undef' d_sockpair='undef' d_socks5_init='undef' -d_sprintf_returns_strlen='define' d_sqrtl='undef' d_srand48_r='undef' d_srandom_r='undef' diff --git a/win32/config_H.ce b/win32/config_H.ce index b7cd127621..4fde9e6d27 100644 --- a/win32/config_H.ce +++ b/win32/config_H.ce @@ -3862,14 +3862,6 @@ */ /*#define HAS_SOCKATMARK_PROTO /**/ -/* SPRINTF_RETURNS_STRLEN: - * This variable defines whether sprintf returns the length of the string - * (as per the ANSI spec). Some C libraries retain compatibility with - * pre-ANSI C and return a pointer to the passed in buffer; for these - * this variable will be undef. - */ -#define SPRINTF_RETURNS_STRLEN /**/ - /* HAS_SETRESGID_PROTO: * This symbol, if defined, indicates that the system provides * a prototype for the setresgid() function. Otherwise, it is up diff --git a/win32/config_H.gc b/win32/config_H.gc index 76f331d19c..7aaf192254 100644 --- a/win32/config_H.gc +++ b/win32/config_H.gc @@ -3322,14 +3322,6 @@ */ /*#define HAS_SOCKS5_INIT / **/ -/* SPRINTF_RETURNS_STRLEN: - * This variable defines whether sprintf returns the length of the string - * (as per the ANSI spec). Some C libraries retain compatibility with - * pre-ANSI C and return a pointer to the passed in buffer; for these - * this variable will be undef. - */ -#define SPRINTF_RETURNS_STRLEN /**/ - /* HAS_SQRTL: * This symbol, if defined, indicates that the sqrtl routine is * available to do long double square roots. diff --git a/win32/config_H.vc b/win32/config_H.vc index ce796ab504..795a6b1f6a 100644 --- a/win32/config_H.vc +++ b/win32/config_H.vc @@ -3313,14 +3313,6 @@ */ /*#define HAS_SOCKS5_INIT / **/ -/* SPRINTF_RETURNS_STRLEN: - * This variable defines whether sprintf returns the length of the string - * (as per the ANSI spec). Some C libraries retain compatibility with - * pre-ANSI C and return a pointer to the passed in buffer; for these - * this variable will be undef. - */ -#define SPRINTF_RETURNS_STRLEN /**/ - /* HAS_SQRTL: * This symbol, if defined, indicates that the sqrtl routine is * available to do long double square roots. |