Rafael Garcia-Suarez
2006-05-12 21:00:01 UTC
Change 28183 by ***@marais on 2006/05/12 20:57:07
Subject: Re: [PATCH] my_snprintf
From: Jarkko Hietaniemi <***@gmail.com>
Date: Fri, 12 May 2006 22:28:49 +0300
Message-ID: <***@gmail.com>
Affected files ...
... //depot/perl/embed.fnc#377 edit
... //depot/perl/global.sym#302 edit
... //depot/perl/perl.h#695 edit
... //depot/perl/perlio.c#325 edit
... //depot/perl/pod/perlapi.pod#257 edit
... //depot/perl/pp_ctl.c#565 edit
... //depot/perl/proto.h#720 edit
... //depot/perl/regcomp.c#426 edit
... //depot/perl/sv.c#1271 edit
... //depot/perl/toke.c#682 edit
... //depot/perl/universal.c#142 edit
... //depot/perl/util.c#561 edit
Differences ...
==== //depot/perl/embed.fnc#377 (text) ====
Index: perl/embed.fnc
--- perl/embed.fnc#376~28180~ 2006-05-12 08:48:43.000000000 -0700
+++ perl/embed.fnc 2006-05-12 13:57:07.000000000 -0700
@@ -1687,6 +1687,9 @@
Apnod |int |my_sprintf |NN char *buffer|NN const char *pat|...
#endif
+Apnod |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
+
px |void |my_clearenv
#ifdef PERL_IMPLICIT_CONTEXT
==== //depot/perl/global.sym#302 (text+w) ====
Index: perl/global.sym
--- perl/global.sym#301~28071~ 2006-05-02 18:46:27.000000000 -0700
+++ perl/global.sym 2006-05-12 13:57:07.000000000 -0700
@@ -713,5 +713,7 @@
Perl_ckwarn_d
Perl_new_warnings_bitfield
Perl_my_sprintf
+Perl_my_snprintf
+Perl_my_vsnprintf
Perl_my_cxt_init
# ex: set ro:
==== //depot/perl/perl.h#695 (text) ====
Index: perl/perl.h
--- perl/perl.h#694~28140~ 2006-05-09 08:23:55.000000000 -0700
+++ perl/perl.h 2006-05-12 13:57:07.000000000 -0700
@@ -1449,6 +1449,9 @@
# define my_sprintf Perl_my_sprintf
#endif
+#define my_snprintf Perl_my_snprintf
+#define my_vsnprintf Perl_my_vsnprintf
+
/* Configure gets this right but the UTS compiler gets it wrong.
-- Hal Morris <***@utsglobal.com> */
#ifdef UTS
==== //depot/perl/perlio.c#325 (text) ====
Index: perl/perlio.c
--- perl/perlio.c#324~28140~ 2006-05-09 08:23:55.000000000 -0700
+++ perl/perlio.c 2006-05-12 13:57:07.000000000 -0700
@@ -479,11 +479,7 @@
/* Use fixed buffer as sv_catpvf etc. needs SVs */
char buffer[1024];
const STRLEN len = my_sprintf(buffer, "%.40s:%" IVdf " ", s ? s : "(none)", (IV) CopLINE(PL_curcop));
-# ifdef USE_VSNPRINTF
- const STRLEN len2 = vsnprintf(buffer+len, sizeof(buffer) - len, fmt, ap);
-# else
- const STRLEN len2 = vsprintf(buffer+len, fmt, ap);
-# endif /* USE_VSNPRINTF */
+ const STRLEN len2 = my_vsnprintf(buffer+len, sizeof(buffer) - len, fmt, ap);
PerlLIO_write(PL_perlio_debug_fd, buffer, len + len2);
#else
const char *s = CopFILE(PL_curcop);
@@ -5147,11 +5143,7 @@
PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap)
{
dVAR;
-#ifdef USE_VSNPRINTF
- const int val = vsnprintf(s, n > 0 ? n : 0, fmt, ap);
-#else
- const int val = vsprintf(s, fmt, ap);
-#endif /* #ifdef USE_VSNPRINTF */
+ const int val = my_vsnprintf(s, n > 0 ? n : 0, fmt, ap);
if (n >= 0) {
if (strlen(s) >= (STRLEN) n) {
dTHX;
==== //depot/perl/pod/perlapi.pod#257 (text+w) ====
Index: perl/pod/perlapi.pod
--- perl/pod/perlapi.pod#256~28063~ 2006-05-02 08:55:25.000000000 -0700
+++ perl/pod/perlapi.pod 2006-05-12 13:57:07.000000000 -0700
@@ -2245,6 +2245,19 @@
=for hackers
Found in file util.c
+=item my_snprintf
+X<my_snprintf>
+
+The C library C<snprintf> functionality, if available and
+standards-compliant (uses C<vsnprintf>, actually). If the
+C<vsnprintf> is not available, will unfortunately use the unsafe
+C<vsprintf>. Consider using C<sv_vcatpvf> instead.
+
+ int my_snprintf(char *buffer, const Size_t len, const char *format, ...)
+
+=for hackers
+Found in file util.c
+
=item my_sprintf
X<my_sprintf>
@@ -2257,6 +2270,18 @@
=for hackers
Found in file util.c
+=item my_vsnprintf
+X<my_vsnprintf>
+
+The C library C<vsnprintf> if available and standards-compliant,
+but if the C<vsnprintf> is not available, will unfortunately use
+the unsafe C<vsprintf>. Consider using C<sv_vcatpvf> instead.
+
+ int my_vsnprintf(char *buffer, const Size_t len, const char *format, va_list ap)
+
+=for hackers
+Found in file util.c
+
=item new_version
X<new_version>
==== //depot/perl/pp_ctl.c#565 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#564~28150~ 2006-05-10 07:08:43.000000000 -0700
+++ perl/pp_ctl.c 2006-05-12 13:57:07.000000000 -0700
@@ -831,11 +831,7 @@
/* Formats aren't yet marked for locales, so assume "yes". */
{
STORE_NUMERIC_STANDARD_SET_LOCAL();
-#ifdef USE_SNPRINTF
- snprintf(t, SvLEN(PL_formtarget) - (t - SvPVX(PL_formtarget)), fmt, (int) fieldsize, (int) arg & 255, value);
-#else
- sprintf(t, fmt, (int) fieldsize, (int) arg & 255, value);
-#endif /* ifdef USE_SNPRINTF */
+ my_snprintf(t, SvLEN(PL_formtarget) - (t - SvPVX(PL_formtarget)), fmt, (int) fieldsize, (int) arg & 255, value);
RESTORE_NUMERIC_STANDARD();
}
t += fieldsize;
@@ -2773,13 +2769,8 @@
len = SvCUR(sv);
}
else
-#ifdef USE_SNPRINTF
- len = snprintf(tmpbuf, sizeof(tbuf), "_<(%.10s_eval %lu)", code,
- (unsigned long)++PL_evalseq);
-#else
- len = my_sprintf(tmpbuf, "_<(%.10s_eval %lu)", code,
- (unsigned long)++PL_evalseq);
-#endif /* ifdef USE_SNPRINTF */
+ len = my_snprintf(tmpbuf, sizeof(tbuf), "_<(%.10s_eval %lu)", code,
+ (unsigned long)++PL_evalseq);
SAVECOPFILE_FREE(&PL_compiling);
CopFILE_set(&PL_compiling, tmpbuf+2);
SAVECOPLINE(&PL_compiling);
@@ -3461,11 +3452,7 @@
len = SvCUR(temp_sv);
}
else
-#ifdef USE_SNPRINTF
- len = snprintf(tmpbuf, sizeof(tbuf), "_<(eval %lu)", (unsigned long)++PL_evalseq);
-#else
- len = my_sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
-#endif /* ifdef USE_SNPRINTF */
+ len = my_snprintf(tmpbuf, sizeof(tbuf), "_<(eval %lu)", (unsigned long)++PL_evalseq);
SAVECOPFILE_FREE(&PL_compiling);
CopFILE_set(&PL_compiling, tmpbuf+2);
SAVECOPLINE(&PL_compiling);
==== //depot/perl/proto.h#720 (text+w) ====
Index: perl/proto.h
--- perl/proto.h#719~28180~ 2006-05-12 08:48:43.000000000 -0700
+++ perl/proto.h 2006-05-12 13:57:07.000000000 -0700
@@ -4335,6 +4335,15 @@
#endif
+PERL_CALLCONV int Perl_my_snprintf(char *buffer, const Size_t len, const char *format, ...)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(3);
+
+PERL_CALLCONV int Perl_my_vsnprintf(char *buffer, const Size_t len, const char *format, va_list ap)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(3);
+
+
PERL_CALLCONV void Perl_my_clearenv(pTHX);
#ifdef PERL_IMPLICIT_CONTEXT
==== //depot/perl/regcomp.c#426 (text) ====
Index: perl/regcomp.c
--- perl/regcomp.c#425~28010~ 2006-04-29 06:09:18.000000000 -0700
+++ perl/regcomp.c 2006-05-12 13:57:07.000000000 -0700
@@ -6184,11 +6184,7 @@
U32 i;
for (i = 1; i <= rx->nparens; i++) {
char digits[TYPE_CHARS(long)];
-#ifdef USE_SNPRINTF
- const STRLEN len = snprintf(digits, sizeof(digits), "%lu", (long)i);
-#else
- const STRLEN len = my_sprintf(digits, "%lu", (long)i);
-#endif /* #ifdef USE_SNPRINTF */
+ const STRLEN len = my_snprintf(digits, sizeof(digits), "%lu", (long)i);
GV *const *const gvp
= (GV**)hv_fetch(PL_defstash, digits, len, 0);
==== //depot/perl/sv.c#1271 (text) ====
Index: perl/sv.c
--- perl/sv.c#1270~28178~ 2006-05-12 07:08:45.000000000 -0700
+++ perl/sv.c 2006-05-12 13:57:07.000000000 -0700
@@ -2660,13 +2660,8 @@
if (SvIOKp(sv)) {
len = SvIsUV(sv)
-#ifdef USE_SNPRINTF
- ? snprintf(tbuf, sizeof(tbuf), "%"UVuf, (UV)SvUVX(sv))
- : snprintf(tbuf, sizeof(tbuf), "%"IVdf, (IV)SvIVX(sv));
-#else
- ? my_sprintf(tbuf, "%"UVuf, (UV)SvUVX(sv))
- : my_sprintf(tbuf, "%"IVdf, (IV)SvIVX(sv));
-#endif /* #ifdef USE_SNPRINTF */
+ ? my_snprintf(tbuf, sizeof(tbuf), "%"UVuf, (UV)SvUVX(sv))
+ : my_snprintf(tbuf, sizeof(tbuf), "%"IVdf, (IV)SvIVX(sv));
} else {
Gconvert(SvNVX(sv), NV_DIG, 0, tbuf);
len = strlen(tbuf);
@@ -9270,13 +9265,8 @@
* --jhi */
#if defined(HAS_LONG_DOUBLE)
elen = ((intsize == 'q')
-# ifdef USE_SNPRINTF
- ? snprintf(PL_efloatbuf, PL_efloatsize, ptr, nv)
- : snprintf(PL_efloatbuf, PL_efloatsize, ptr, (double)nv));
-# else
- ? my_sprintf(PL_efloatbuf, ptr, nv)
- : my_sprintf(PL_efloatbuf, ptr, (double)nv));
-# endif /* #ifdef USE_SNPRINTF */
+ ? my_snprintf(PL_efloatbuf, PL_efloatsize, ptr, nv)
+ : my_snprintf(PL_efloatbuf, PL_efloatsize, ptr, (double)nv));
#else
elen = my_sprintf(PL_efloatbuf, ptr, nv);
#endif
==== //depot/perl/toke.c#682 (text) ====
Index: perl/toke.c
--- perl/toke.c#681~28179~ 2006-05-12 07:33:40.000000000 -0700
+++ perl/toke.c 2006-05-12 13:57:07.000000000 -0700
@@ -5976,11 +5976,7 @@
if (!PL_in_my_stash) {
char tmpbuf[1024];
PL_bufptr = s;
-#ifdef USE_SNPRINTF
- snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
-#else
- sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
-#endif /* #ifdef USE_SNPRINTF */
+ my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
yyerror(tmpbuf);
}
#ifdef PERL_MAD
==== //depot/perl/universal.c#142 (text) ====
Index: perl/universal.c
--- perl/universal.c#141~28008~ 2006-04-28 13:40:41.000000000 -0700
+++ perl/universal.c 2006-05-12 13:57:07.000000000 -0700
@@ -622,11 +622,7 @@
if ( SvNOK(ver) ) /* may get too much accuracy */
{
char tbuf[64];
-#ifdef USE_SNPRINTF
- const STRLEN len = snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
-#else
- const STRLEN len = my_sprintf(tbuf, "%.9"NVgf, SvNVX(ver));
-#endif /* #ifdef USE_SNPRINTF */
+ const STRLEN len = my_snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
version = savepvn(tbuf, len);
}
else
==== //depot/perl/util.c#561 (text) ====
Index: perl/util.c
--- perl/util.c#560~28148~ 2006-05-09 18:32:10.000000000 -0700
+++ perl/util.c 2006-05-12 13:57:07.000000000 -0700
@@ -4294,11 +4294,7 @@
if ( SvNOK(ver) ) /* may get too much accuracy */
{
char tbuf[64];
-#ifdef USE_SNPRINTF
- const STRLEN len = snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
-#else
- const STRLEN len = my_sprintf(tbuf, "%.9"NVgf, SvNVX(ver));
-#endif /* #ifdef USE_SNPRINTF */
+ const STRLEN len = my_snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
version = savepvn(tbuf, len);
}
#ifdef SvVOK
@@ -5215,38 +5211,21 @@
gettimeofday(&tv, 0);
{
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "%10d.%06d: alloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(newalloc));
-# else
- my_sprintf(buf,
- "%10d.%06d: alloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(newalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "%10d.%06d: alloc: %s:%d:%s: %"IVdf" %"UVuf
+ " %s = %"IVdf": %"UVxf"\n",
+ (int)tv.tv_sec, (int)tv.tv_usec,
+ filename, linenumber, funcname, n, typesize,
+ typename, n * typesize, PTR2UV(newalloc));
# else
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "alloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf"\n",
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(newalloc));
-# else
- my_sprintf(buf,
- "alloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf"\n",
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(newalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "alloc: %s:%d:%s: %"IVdf" %"UVuf
+ " %s = %"IVdf": %"UVxf"\n",
+ filename, linenumber, funcname, n, typesize,
+ typename, n * typesize, PTR2UV(newalloc));
# endif
# ifdef PERL_MEM_LOG_ENV_FD
s = PerlEnv_getenv("PERL_MEM_LOG_FD");
@@ -5280,42 +5259,23 @@
gettimeofday(&tv, 0);
{
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "%10d.%06d: realloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(oldalloc),
- PTR2UV(newalloc));
-# else
- my_sprintf(buf,
- "%10d.%06d: realloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(oldalloc),
- PTR2UV(newalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "%10d.%06d: realloc: %s:%d:%s: %"IVdf" %"UVuf
+ " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
+ (int)tv.tv_sec, (int)tv.tv_usec,
+ filename, linenumber, funcname, n, typesize,
+ typename, n * typesize, PTR2UV(oldalloc),
+ PTR2UV(newalloc));
# else
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "realloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(oldalloc),
- PTR2UV(newalloc));
-# else
- my_sprintf(buf,
- "realloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(oldalloc),
- PTR2UV(newalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "realloc: %s:%d:%s: %"IVdf" %"UVuf
+ " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
+ filename, linenumber, funcname, n, typesize,
+ typename, n * typesize, PTR2UV(oldalloc),
+ PTR2UV(newalloc));
# endif
# ifdef PERL_MEM_LOG_ENV_FD
s = PerlEnv_getenv("PERL_MEM_LOG_FD");
@@ -5349,20 +5309,12 @@
gettimeofday(&tv, 0);
{
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "%10d.%06d: free: %s:%d:%s: %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname,
- PTR2UV(oldalloc));
-# else
- my_sprintf(buf,
- "%10d.%06d: free: %s:%d:%s: %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname,
- PTR2UV(oldalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "%10d.%06d: free: %s:%d:%s: %"UVxf"\n",
+ (int)tv.tv_sec, (int)tv.tv_usec,
+ filename, linenumber, funcname,
+ PTR2UV(oldalloc));
# else
const STRLEN len =
my_sprintf(buf,
@@ -5405,6 +5357,72 @@
}
#endif
+/*
+=for apidoc my_snprintf
+
+The C library C<snprintf> functionality, if available and
+standards-compliant (uses C<vsnprintf>, actually). If the
+C<vsnprintf> is not available, will unfortunately use the unsafe
+C<vsprintf>. Consider using C<sv_vcatpvf> instead.
+
+=cut
+*/
+int
+Perl_my_snprintf(char *buffer, const Size_t len, const char *format, ...)
+/* Cannot do this using variadic macros because that is too unportable. */
+{
+ dTHX;
+ int retval;
+ va_list ap;
+#ifndef USE_VSNPRINTF
+ PERL_UNUSED_ARG(len);
+#endif
+ va_start(ap, format);
+#ifdef USE_VSNPRINTF
+ retval = vsnprintf(buffer, len, format, ap);
+#else
+ retval = vsprintf(buffer, format, ap);
+#endif
+ va_end(ap);
+ return retval;
+}
+
+/*
+=for apidoc my_vsnprintf
+
+The C library C<vsnprintf> if available and standards-compliant,
+but if the C<vsnprintf> is not available, will unfortunately use
+the unsafe C<vsprintf>. Consider using C<sv_vcatpvf> instead.
+
+=cut
+*/
+int
+Perl_my_vsnprintf(char *buffer, const Size_t len, const char *format, va_list ap)
+/* Cannot do this using variadic macros because that is too unportable. */
+{
+ dTHX;
+ int retval;
+#ifndef USE_VSNPRINTF
+ PERL_UNUSED_ARG(len);
+#endif
+#ifdef NEED_VA_COPY
+ va_list apc;
+ Perl_va_copy(apc);
+# ifdef USE_VSNPRINTF
+ retval = vsnprintf(buffer, len, format, apc);
+# else
+ retval = vsprintf(buffer, format, apc);
+# endif
+#else
+# ifdef USE_VSNPRINTF
+ retval = vsnprintf(buffer, len, format, ap);
+# else
+ retval = vsprintf(buffer, format, ap);
+# endif
+#endif
+ return retval;
+}
+
void
Perl_my_clearenv(pTHX)
{
End of Patch.
Subject: Re: [PATCH] my_snprintf
From: Jarkko Hietaniemi <***@gmail.com>
Date: Fri, 12 May 2006 22:28:49 +0300
Message-ID: <***@gmail.com>
Affected files ...
... //depot/perl/embed.fnc#377 edit
... //depot/perl/global.sym#302 edit
... //depot/perl/perl.h#695 edit
... //depot/perl/perlio.c#325 edit
... //depot/perl/pod/perlapi.pod#257 edit
... //depot/perl/pp_ctl.c#565 edit
... //depot/perl/proto.h#720 edit
... //depot/perl/regcomp.c#426 edit
... //depot/perl/sv.c#1271 edit
... //depot/perl/toke.c#682 edit
... //depot/perl/universal.c#142 edit
... //depot/perl/util.c#561 edit
Differences ...
==== //depot/perl/embed.fnc#377 (text) ====
Index: perl/embed.fnc
--- perl/embed.fnc#376~28180~ 2006-05-12 08:48:43.000000000 -0700
+++ perl/embed.fnc 2006-05-12 13:57:07.000000000 -0700
@@ -1687,6 +1687,9 @@
Apnod |int |my_sprintf |NN char *buffer|NN const char *pat|...
#endif
+Apnod |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
+
px |void |my_clearenv
#ifdef PERL_IMPLICIT_CONTEXT
==== //depot/perl/global.sym#302 (text+w) ====
Index: perl/global.sym
--- perl/global.sym#301~28071~ 2006-05-02 18:46:27.000000000 -0700
+++ perl/global.sym 2006-05-12 13:57:07.000000000 -0700
@@ -713,5 +713,7 @@
Perl_ckwarn_d
Perl_new_warnings_bitfield
Perl_my_sprintf
+Perl_my_snprintf
+Perl_my_vsnprintf
Perl_my_cxt_init
# ex: set ro:
==== //depot/perl/perl.h#695 (text) ====
Index: perl/perl.h
--- perl/perl.h#694~28140~ 2006-05-09 08:23:55.000000000 -0700
+++ perl/perl.h 2006-05-12 13:57:07.000000000 -0700
@@ -1449,6 +1449,9 @@
# define my_sprintf Perl_my_sprintf
#endif
+#define my_snprintf Perl_my_snprintf
+#define my_vsnprintf Perl_my_vsnprintf
+
/* Configure gets this right but the UTS compiler gets it wrong.
-- Hal Morris <***@utsglobal.com> */
#ifdef UTS
==== //depot/perl/perlio.c#325 (text) ====
Index: perl/perlio.c
--- perl/perlio.c#324~28140~ 2006-05-09 08:23:55.000000000 -0700
+++ perl/perlio.c 2006-05-12 13:57:07.000000000 -0700
@@ -479,11 +479,7 @@
/* Use fixed buffer as sv_catpvf etc. needs SVs */
char buffer[1024];
const STRLEN len = my_sprintf(buffer, "%.40s:%" IVdf " ", s ? s : "(none)", (IV) CopLINE(PL_curcop));
-# ifdef USE_VSNPRINTF
- const STRLEN len2 = vsnprintf(buffer+len, sizeof(buffer) - len, fmt, ap);
-# else
- const STRLEN len2 = vsprintf(buffer+len, fmt, ap);
-# endif /* USE_VSNPRINTF */
+ const STRLEN len2 = my_vsnprintf(buffer+len, sizeof(buffer) - len, fmt, ap);
PerlLIO_write(PL_perlio_debug_fd, buffer, len + len2);
#else
const char *s = CopFILE(PL_curcop);
@@ -5147,11 +5143,7 @@
PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap)
{
dVAR;
-#ifdef USE_VSNPRINTF
- const int val = vsnprintf(s, n > 0 ? n : 0, fmt, ap);
-#else
- const int val = vsprintf(s, fmt, ap);
-#endif /* #ifdef USE_VSNPRINTF */
+ const int val = my_vsnprintf(s, n > 0 ? n : 0, fmt, ap);
if (n >= 0) {
if (strlen(s) >= (STRLEN) n) {
dTHX;
==== //depot/perl/pod/perlapi.pod#257 (text+w) ====
Index: perl/pod/perlapi.pod
--- perl/pod/perlapi.pod#256~28063~ 2006-05-02 08:55:25.000000000 -0700
+++ perl/pod/perlapi.pod 2006-05-12 13:57:07.000000000 -0700
@@ -2245,6 +2245,19 @@
=for hackers
Found in file util.c
+=item my_snprintf
+X<my_snprintf>
+
+The C library C<snprintf> functionality, if available and
+standards-compliant (uses C<vsnprintf>, actually). If the
+C<vsnprintf> is not available, will unfortunately use the unsafe
+C<vsprintf>. Consider using C<sv_vcatpvf> instead.
+
+ int my_snprintf(char *buffer, const Size_t len, const char *format, ...)
+
+=for hackers
+Found in file util.c
+
=item my_sprintf
X<my_sprintf>
@@ -2257,6 +2270,18 @@
=for hackers
Found in file util.c
+=item my_vsnprintf
+X<my_vsnprintf>
+
+The C library C<vsnprintf> if available and standards-compliant,
+but if the C<vsnprintf> is not available, will unfortunately use
+the unsafe C<vsprintf>. Consider using C<sv_vcatpvf> instead.
+
+ int my_vsnprintf(char *buffer, const Size_t len, const char *format, va_list ap)
+
+=for hackers
+Found in file util.c
+
=item new_version
X<new_version>
==== //depot/perl/pp_ctl.c#565 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#564~28150~ 2006-05-10 07:08:43.000000000 -0700
+++ perl/pp_ctl.c 2006-05-12 13:57:07.000000000 -0700
@@ -831,11 +831,7 @@
/* Formats aren't yet marked for locales, so assume "yes". */
{
STORE_NUMERIC_STANDARD_SET_LOCAL();
-#ifdef USE_SNPRINTF
- snprintf(t, SvLEN(PL_formtarget) - (t - SvPVX(PL_formtarget)), fmt, (int) fieldsize, (int) arg & 255, value);
-#else
- sprintf(t, fmt, (int) fieldsize, (int) arg & 255, value);
-#endif /* ifdef USE_SNPRINTF */
+ my_snprintf(t, SvLEN(PL_formtarget) - (t - SvPVX(PL_formtarget)), fmt, (int) fieldsize, (int) arg & 255, value);
RESTORE_NUMERIC_STANDARD();
}
t += fieldsize;
@@ -2773,13 +2769,8 @@
len = SvCUR(sv);
}
else
-#ifdef USE_SNPRINTF
- len = snprintf(tmpbuf, sizeof(tbuf), "_<(%.10s_eval %lu)", code,
- (unsigned long)++PL_evalseq);
-#else
- len = my_sprintf(tmpbuf, "_<(%.10s_eval %lu)", code,
- (unsigned long)++PL_evalseq);
-#endif /* ifdef USE_SNPRINTF */
+ len = my_snprintf(tmpbuf, sizeof(tbuf), "_<(%.10s_eval %lu)", code,
+ (unsigned long)++PL_evalseq);
SAVECOPFILE_FREE(&PL_compiling);
CopFILE_set(&PL_compiling, tmpbuf+2);
SAVECOPLINE(&PL_compiling);
@@ -3461,11 +3452,7 @@
len = SvCUR(temp_sv);
}
else
-#ifdef USE_SNPRINTF
- len = snprintf(tmpbuf, sizeof(tbuf), "_<(eval %lu)", (unsigned long)++PL_evalseq);
-#else
- len = my_sprintf(tmpbuf, "_<(eval %lu)", (unsigned long)++PL_evalseq);
-#endif /* ifdef USE_SNPRINTF */
+ len = my_snprintf(tmpbuf, sizeof(tbuf), "_<(eval %lu)", (unsigned long)++PL_evalseq);
SAVECOPFILE_FREE(&PL_compiling);
CopFILE_set(&PL_compiling, tmpbuf+2);
SAVECOPLINE(&PL_compiling);
==== //depot/perl/proto.h#720 (text+w) ====
Index: perl/proto.h
--- perl/proto.h#719~28180~ 2006-05-12 08:48:43.000000000 -0700
+++ perl/proto.h 2006-05-12 13:57:07.000000000 -0700
@@ -4335,6 +4335,15 @@
#endif
+PERL_CALLCONV int Perl_my_snprintf(char *buffer, const Size_t len, const char *format, ...)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(3);
+
+PERL_CALLCONV int Perl_my_vsnprintf(char *buffer, const Size_t len, const char *format, va_list ap)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(3);
+
+
PERL_CALLCONV void Perl_my_clearenv(pTHX);
#ifdef PERL_IMPLICIT_CONTEXT
==== //depot/perl/regcomp.c#426 (text) ====
Index: perl/regcomp.c
--- perl/regcomp.c#425~28010~ 2006-04-29 06:09:18.000000000 -0700
+++ perl/regcomp.c 2006-05-12 13:57:07.000000000 -0700
@@ -6184,11 +6184,7 @@
U32 i;
for (i = 1; i <= rx->nparens; i++) {
char digits[TYPE_CHARS(long)];
-#ifdef USE_SNPRINTF
- const STRLEN len = snprintf(digits, sizeof(digits), "%lu", (long)i);
-#else
- const STRLEN len = my_sprintf(digits, "%lu", (long)i);
-#endif /* #ifdef USE_SNPRINTF */
+ const STRLEN len = my_snprintf(digits, sizeof(digits), "%lu", (long)i);
GV *const *const gvp
= (GV**)hv_fetch(PL_defstash, digits, len, 0);
==== //depot/perl/sv.c#1271 (text) ====
Index: perl/sv.c
--- perl/sv.c#1270~28178~ 2006-05-12 07:08:45.000000000 -0700
+++ perl/sv.c 2006-05-12 13:57:07.000000000 -0700
@@ -2660,13 +2660,8 @@
if (SvIOKp(sv)) {
len = SvIsUV(sv)
-#ifdef USE_SNPRINTF
- ? snprintf(tbuf, sizeof(tbuf), "%"UVuf, (UV)SvUVX(sv))
- : snprintf(tbuf, sizeof(tbuf), "%"IVdf, (IV)SvIVX(sv));
-#else
- ? my_sprintf(tbuf, "%"UVuf, (UV)SvUVX(sv))
- : my_sprintf(tbuf, "%"IVdf, (IV)SvIVX(sv));
-#endif /* #ifdef USE_SNPRINTF */
+ ? my_snprintf(tbuf, sizeof(tbuf), "%"UVuf, (UV)SvUVX(sv))
+ : my_snprintf(tbuf, sizeof(tbuf), "%"IVdf, (IV)SvIVX(sv));
} else {
Gconvert(SvNVX(sv), NV_DIG, 0, tbuf);
len = strlen(tbuf);
@@ -9270,13 +9265,8 @@
* --jhi */
#if defined(HAS_LONG_DOUBLE)
elen = ((intsize == 'q')
-# ifdef USE_SNPRINTF
- ? snprintf(PL_efloatbuf, PL_efloatsize, ptr, nv)
- : snprintf(PL_efloatbuf, PL_efloatsize, ptr, (double)nv));
-# else
- ? my_sprintf(PL_efloatbuf, ptr, nv)
- : my_sprintf(PL_efloatbuf, ptr, (double)nv));
-# endif /* #ifdef USE_SNPRINTF */
+ ? my_snprintf(PL_efloatbuf, PL_efloatsize, ptr, nv)
+ : my_snprintf(PL_efloatbuf, PL_efloatsize, ptr, (double)nv));
#else
elen = my_sprintf(PL_efloatbuf, ptr, nv);
#endif
==== //depot/perl/toke.c#682 (text) ====
Index: perl/toke.c
--- perl/toke.c#681~28179~ 2006-05-12 07:33:40.000000000 -0700
+++ perl/toke.c 2006-05-12 13:57:07.000000000 -0700
@@ -5976,11 +5976,7 @@
if (!PL_in_my_stash) {
char tmpbuf[1024];
PL_bufptr = s;
-#ifdef USE_SNPRINTF
- snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
-#else
- sprintf(tmpbuf, "No such class %.1000s", PL_tokenbuf);
-#endif /* #ifdef USE_SNPRINTF */
+ my_snprintf(tmpbuf, sizeof(tmpbuf), "No such class %.1000s", PL_tokenbuf);
yyerror(tmpbuf);
}
#ifdef PERL_MAD
==== //depot/perl/universal.c#142 (text) ====
Index: perl/universal.c
--- perl/universal.c#141~28008~ 2006-04-28 13:40:41.000000000 -0700
+++ perl/universal.c 2006-05-12 13:57:07.000000000 -0700
@@ -622,11 +622,7 @@
if ( SvNOK(ver) ) /* may get too much accuracy */
{
char tbuf[64];
-#ifdef USE_SNPRINTF
- const STRLEN len = snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
-#else
- const STRLEN len = my_sprintf(tbuf, "%.9"NVgf, SvNVX(ver));
-#endif /* #ifdef USE_SNPRINTF */
+ const STRLEN len = my_snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
version = savepvn(tbuf, len);
}
else
==== //depot/perl/util.c#561 (text) ====
Index: perl/util.c
--- perl/util.c#560~28148~ 2006-05-09 18:32:10.000000000 -0700
+++ perl/util.c 2006-05-12 13:57:07.000000000 -0700
@@ -4294,11 +4294,7 @@
if ( SvNOK(ver) ) /* may get too much accuracy */
{
char tbuf[64];
-#ifdef USE_SNPRINTF
- const STRLEN len = snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
-#else
- const STRLEN len = my_sprintf(tbuf, "%.9"NVgf, SvNVX(ver));
-#endif /* #ifdef USE_SNPRINTF */
+ const STRLEN len = my_snprintf(tbuf, sizeof(tbuf), "%.9"NVgf, SvNVX(ver));
version = savepvn(tbuf, len);
}
#ifdef SvVOK
@@ -5215,38 +5211,21 @@
gettimeofday(&tv, 0);
{
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "%10d.%06d: alloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(newalloc));
-# else
- my_sprintf(buf,
- "%10d.%06d: alloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(newalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "%10d.%06d: alloc: %s:%d:%s: %"IVdf" %"UVuf
+ " %s = %"IVdf": %"UVxf"\n",
+ (int)tv.tv_sec, (int)tv.tv_usec,
+ filename, linenumber, funcname, n, typesize,
+ typename, n * typesize, PTR2UV(newalloc));
# else
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "alloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf"\n",
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(newalloc));
-# else
- my_sprintf(buf,
- "alloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf"\n",
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(newalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "alloc: %s:%d:%s: %"IVdf" %"UVuf
+ " %s = %"IVdf": %"UVxf"\n",
+ filename, linenumber, funcname, n, typesize,
+ typename, n * typesize, PTR2UV(newalloc));
# endif
# ifdef PERL_MEM_LOG_ENV_FD
s = PerlEnv_getenv("PERL_MEM_LOG_FD");
@@ -5280,42 +5259,23 @@
gettimeofday(&tv, 0);
{
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "%10d.%06d: realloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(oldalloc),
- PTR2UV(newalloc));
-# else
- my_sprintf(buf,
- "%10d.%06d: realloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(oldalloc),
- PTR2UV(newalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "%10d.%06d: realloc: %s:%d:%s: %"IVdf" %"UVuf
+ " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
+ (int)tv.tv_sec, (int)tv.tv_usec,
+ filename, linenumber, funcname, n, typesize,
+ typename, n * typesize, PTR2UV(oldalloc),
+ PTR2UV(newalloc));
# else
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "realloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(oldalloc),
- PTR2UV(newalloc));
-# else
- my_sprintf(buf,
- "realloc: %s:%d:%s: %"IVdf" %"UVuf
- " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
- filename, linenumber, funcname, n, typesize,
- typename, n * typesize, PTR2UV(oldalloc),
- PTR2UV(newalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "realloc: %s:%d:%s: %"IVdf" %"UVuf
+ " %s = %"IVdf": %"UVxf" -> %"UVxf"\n",
+ filename, linenumber, funcname, n, typesize,
+ typename, n * typesize, PTR2UV(oldalloc),
+ PTR2UV(newalloc));
# endif
# ifdef PERL_MEM_LOG_ENV_FD
s = PerlEnv_getenv("PERL_MEM_LOG_FD");
@@ -5349,20 +5309,12 @@
gettimeofday(&tv, 0);
{
const STRLEN len =
-# ifdef USE_SNPRINTF
- snprintf(buf,
- PERL_MEM_LOG_SPRINTF_BUF_SIZE,
- "%10d.%06d: free: %s:%d:%s: %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname,
- PTR2UV(oldalloc));
-# else
- my_sprintf(buf,
- "%10d.%06d: free: %s:%d:%s: %"UVxf"\n",
- (int)tv.tv_sec, (int)tv.tv_usec,
- filename, linenumber, funcname,
- PTR2UV(oldalloc));
-# endif
+ my_snprintf(buf,
+ PERL_MEM_LOG_SPRINTF_BUF_SIZE,
+ "%10d.%06d: free: %s:%d:%s: %"UVxf"\n",
+ (int)tv.tv_sec, (int)tv.tv_usec,
+ filename, linenumber, funcname,
+ PTR2UV(oldalloc));
# else
const STRLEN len =
my_sprintf(buf,
@@ -5405,6 +5357,72 @@
}
#endif
+/*
+=for apidoc my_snprintf
+
+The C library C<snprintf> functionality, if available and
+standards-compliant (uses C<vsnprintf>, actually). If the
+C<vsnprintf> is not available, will unfortunately use the unsafe
+C<vsprintf>. Consider using C<sv_vcatpvf> instead.
+
+=cut
+*/
+int
+Perl_my_snprintf(char *buffer, const Size_t len, const char *format, ...)
+/* Cannot do this using variadic macros because that is too unportable. */
+{
+ dTHX;
+ int retval;
+ va_list ap;
+#ifndef USE_VSNPRINTF
+ PERL_UNUSED_ARG(len);
+#endif
+ va_start(ap, format);
+#ifdef USE_VSNPRINTF
+ retval = vsnprintf(buffer, len, format, ap);
+#else
+ retval = vsprintf(buffer, format, ap);
+#endif
+ va_end(ap);
+ return retval;
+}
+
+/*
+=for apidoc my_vsnprintf
+
+The C library C<vsnprintf> if available and standards-compliant,
+but if the C<vsnprintf> is not available, will unfortunately use
+the unsafe C<vsprintf>. Consider using C<sv_vcatpvf> instead.
+
+=cut
+*/
+int
+Perl_my_vsnprintf(char *buffer, const Size_t len, const char *format, va_list ap)
+/* Cannot do this using variadic macros because that is too unportable. */
+{
+ dTHX;
+ int retval;
+#ifndef USE_VSNPRINTF
+ PERL_UNUSED_ARG(len);
+#endif
+#ifdef NEED_VA_COPY
+ va_list apc;
+ Perl_va_copy(apc);
+# ifdef USE_VSNPRINTF
+ retval = vsnprintf(buffer, len, format, apc);
+# else
+ retval = vsprintf(buffer, format, apc);
+# endif
+#else
+# ifdef USE_VSNPRINTF
+ retval = vsnprintf(buffer, len, format, ap);
+# else
+ retval = vsprintf(buffer, format, ap);
+# endif
+#endif
+ return retval;
+}
+
void
Perl_my_clearenv(pTHX)
{
End of Patch.