summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Crane <arc@cpan.org>2017-10-13 10:03:59 +0200
committerAaron Crane <arc@cpan.org>2017-10-21 16:52:44 +0100
commitf1519f70705b2eee563b9ac4056d4eb39d383ea1 (patch)
tree99be297bc99adf835bdb6832add4fbf24992a766
parent03f3961765f87fb8bccb4e3fa5b9e2e533d7dc30 (diff)
downloadperl-f1519f70705b2eee563b9ac4056d4eb39d383ea1.tar.gz
Rely on C89 sprintf() return value semantics
-rwxr-xr-xConfigure65
-rw-r--r--Cross/config.sh-arm-linux1
-rw-r--r--Cross/config.sh-arm-linux-n7701
-rw-r--r--NetWare/config.wc1
-rw-r--r--Porting/Glossary6
-rw-r--r--Porting/config.sh1
-rw-r--r--Porting/config_H8
-rwxr-xr-xconfig_h.SH8
-rw-r--r--configure.com1
-rw-r--r--embed.fnc4
-rw-r--r--makedef.pl5
-rw-r--r--perl.h16
-rw-r--r--plan9/config_sh.sample1
-rw-r--r--proto.h5
-rw-r--r--symbian/config.sh1
-rw-r--r--uconfig.h12
-rw-r--r--uconfig.sh1
-rw-r--r--uconfig64.sh1
-rw-r--r--util.c22
-rw-r--r--win32/config.ce1
-rw-r--r--win32/config.gc1
-rw-r--r--win32/config.vc1
-rw-r--r--win32/config_H.ce8
-rw-r--r--win32/config_H.gc8
-rw-r--r--win32/config_H.vc8
25 files changed, 9 insertions, 178 deletions
diff --git a/Configure b/Configure
index 7df8e675bf..6da12686a5 100755
--- a/Configure
+++ b/Configure
@@ -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'"
diff --git a/embed.fnc b/embed.fnc
index 05c5d883a9..71b308733d 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -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};
}
diff --git a/perl.h b/perl.h
index e7f25b125b..b1e63e2e2b 100644
--- a/perl.h
+++ b/perl.h
@@ -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'
diff --git a/proto.h b/proto.h
index b0a54da7b9..70c1a63fec 100644
--- a/proto.h
+++ b/proto.h
@@ -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'
diff --git a/uconfig.h b/uconfig.h
index 8f1b8ad14c..1dd837fc7d 100644
--- a/uconfig.h
+++ b/uconfig.h
@@ -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'
diff --git a/util.c b/util.c
index a4a6fb6bd7..7525a7e034 100644
--- a/util.c
+++ b/util.c
@@ -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.