Will Coleda (via RT) wrote:
# New Ticket Created by Will Coleda
# Please include the string: [perl #57468]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=57468 >
There's an ifdef in misc.c to allow us to conditionally use vnsnprintf.
If we're going to keep the conditional, we need to provide a config
probe for it (and rename to something like PARROT_HAS_VNSNPRINTF)
Otherwise, we should delete the conditional.
$ ack -a BLAHBLAHBLAH
src/misc.c
249:#ifdef BLAHBLAHBLAH_WAS_A_CHECK_FOR_VNSNPRINTF
$ svn blame src/misc.c | ack BLAHBLAHBLAH
25545 petdance #ifdef BLAHBLAHBLAH_WAS_A_CHECK_FOR_VNSNPRINTF
vnsnprintf here appears be a typo of vsnprintf. There are a couple references
to it that Google finds, but they appear to be typos too.
The attached patch adds a configure step for vsnprintf based heavily on the
one for snprintf. make test passes, but the only function that uses vsnprintf
(Parrot_secret_snprintf) doesn't appear to have any test coverage.
The patch should be simple enough to be obviously correct, but I'd like a +1
from someone just to be on the safe side.
Christoph
Index: lib/Parrot/Configure/Step/List.pm
===================================================================
--- lib/Parrot/Configure/Step/List.pm (revision 29993)
+++ lib/Parrot/Configure/Step/List.pm (working copy)
@@ -61,6 +61,7 @@
auto::crypto
auto::gettext
auto::snprintf
+ auto::vsnprintf
auto::perldoc
auto::ctags
auto::revision
Index: config/auto/vsnprintf.pm
===================================================================
--- config/auto/vsnprintf.pm (revision 0)
+++ config/auto/vsnprintf.pm (revision 0)
@@ -0,0 +1,70 @@
+# Copyright (C) 2001-2003, The Perl Foundation.
+# $Id: vsnprintf.pm 24769 2008-01-12 01:22:59Z jkeenan $
+
+=head1 NAME
+
+config/auto/vsnprintf.pm - Test for vsnprintf
+
+=head1 DESCRIPTION
+
+Tests if vsnprintf is present and if it's C99 compliant.
+
+=cut
+
+package auto::vsnprintf;
+
+use strict;
+use warnings;
+
+use base qw(Parrot::Configure::Step);
+
+sub _init {
+ my $self = shift;
+ my %data;
+ $data{description} = q{Testing vsnprintf};
+ $data{result} = q{};
+ return \%data;
+}
+
+sub runstep {
+ my ( $self, $conf ) = @_;
+
+ my $res = _probe_for_vsnprintf($conf);
+
+ $self->_evaluate_vsnprintf($conf, $res);
+
+ return 1;
+}
+
+sub _probe_for_vsnprintf {
+ my $conf = shift;
+ $conf->cc_gen('config/auto/vsnprintf/test.in');
+ $conf->cc_build();
+ my $res = $conf->cc_run() or die "Can't run the vsnprintf testing program: $!";
+ $conf->cc_clean();
+ return $res;
+}
+
+sub _evaluate_vsnprintf {
+ my ($self, $conf, $res) = @_;
+ if ( $res =~ /vsnprintf/ ) {
+ $conf->data->set( HAS_VSNPRINTF => 1 );
+ }
+ if ( $res =~ /^C99 vsnprintf/ ) {
+ $conf->data->set( HAS_C99_VSNPRINTF => 1 );
+ }
+ elsif ( $res =~ /^old vsnprintf/ ) {
+ $conf->data->set( HAS_OLD_VSNPRINTF => 1 );
+ }
+ print " ($res) " if $conf->options->get('verbose');
+ return 1;
+}
+
+1;
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
Index: config/auto/vsnprintf/test.in
===================================================================
--- config/auto/vsnprintf/test.in (revision 0)
+++ config/auto/vsnprintf/test.in (revision 0)
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdarg.h>
+#ifdef _WIN32
+# define vsnprintf _vsnprintf
+#endif
+
+int vsnprintf_wrapper(char *buf, size_t size, const char *fmt, ...);
+
+int
+main(int argc, char* argv[])
+{
+ char buf[10];
+ int n;
+
+ n = vsnprintf_wrapper(buf, 2, "%s", "01234");
+ if (n == -1)
+ puts("old vsnprintf");
+ else if (n == 5)
+ puts("C99 vsnprintf");
+ else
+ printf("borken vsnprintf: n = %d\n", n);
+ return 0;
+}
+
+int
+vsnprintf_wrapper(char *buf, size_t size, const char *fmt, ...)
+{
+ int retval;
+ va_list ap;
+ va_start(ap, fmt);
+ retval = vsnprintf(buf, size, fmt, ap);
+ va_end(ap);
+ return retval;
+}
Index: src/misc.c
===================================================================
--- src/misc.c (revision 29993)
+++ src/misc.c (working copy)
@@ -246,7 +246,7 @@
int retval;
va_list ap;
va_start(ap, format);
-#ifdef BLAHBLAHBLAH_WAS_A_CHECK_FOR_VNSNPRINTF
+#ifdef PARROT_HAS_VSNPRINTF
retval = vsnprintf(buffer, len, format, ap);
#else
retval = vsprintf(buffer, format, ap);