[svn:parrot] r36638 - in trunk: . config/auto config/auto/neg_0 config/gen/config_h lib/Parrot/Configure/Step t/op t/pmc t/steps

rurban at svn.parrot.org rurban at svn.parrot.org
Thu Feb 12 19:30:17 UTC 2009


Author: rurban
Date: Thu Feb 12 19:30:15 2009
New Revision: 36638
URL: https://trac.parrot.org/parrot/changeset/36638

Log:
Fix TT #313, printing -0.0 on older win32 MSVCRT dlls 
and probably on openbsd also.

- add has_negative_zero feature, 
- fix print_n and say_n for the platforms failing the new has_negative_zero
  configure test
- enable the failing tests again

This -0.0 is a long-standing problem and finally fixes [perl #28170], 
[perl #30737], [perl #19183], [perl #60312].

Note that special yet untested platforms, like arm might also fail 
the has_negative_zero test and might fail the signbit workaround we use.
long double -0.0 will also need a workaround code like this.

There's a patch to generate the signbit() fallback at RT #30737.
Many thanks to Andy Dougherty for pointing me to the old tickets 
and for the solution which was there for 5 years.

Added:
   trunk/config/auto/neg_0/
   trunk/config/auto/neg_0.pm
   trunk/config/auto/neg_0/test_c.in
   trunk/t/steps/auto_neg_0-01.t   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/config/gen/config_h/feature_h.in
   trunk/lib/Parrot/Configure/Step/List.pm
   trunk/t/op/arithmetics.t
   trunk/t/pmc/complex.t
   trunk/t/pmc/float.t

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	Thu Feb 12 18:46:52 2009	(r36637)
+++ trunk/MANIFEST	Thu Feb 12 19:30:15 2009	(r36638)
@@ -273,6 +273,8 @@
 config/auto/memalign/test_c.in                              []
 config/auto/msvc.pm                                         []
 config/auto/msvc/test_c.in                                  []
+config/auto/neg_0.pm                                        []
+config/auto/neg_0/test_c.in                                 []
 config/auto/opengl.pm                                       []
 config/auto/opengl/opengl_c.in                              []
 config/auto/ops.pm                                          []
@@ -3248,6 +3250,7 @@
 t/steps/auto_macports-02.t                                  []
 t/steps/auto_memalign-01.t                                  []
 t/steps/auto_msvc-01.t                                      []
+t/steps/auto_neg_0-01.t                                     []
 t/steps/auto_opengl-01.t                                    []
 t/steps/auto_ops-01.t                                       []
 t/steps/auto_pcre-01.t                                      []

Added: trunk/config/auto/neg_0.pm
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/config/auto/neg_0.pm	Thu Feb 12 19:30:15 2009	(r36638)
@@ -0,0 +1,67 @@
+# Copyright (C) 2009, The Perl Foundation.
+# $Id: neg_0.pm 30367 2008-08-20 02:21:59Z rurban $
+
+=head1 NAME
+
+config/auto/neg_0.pm - can print negative zero
+
+=head1 DESCRIPTION
+
+Determines whether print -0.0 can print "-0" or just prints "0"
+
+This needs workarounds on older win32 (msvcrt.dll) and openbsd.
+
+=cut
+
+package auto::neg_0;
+
+use strict;
+use warnings;
+
+
+use base qw(Parrot::Configure::Step);
+
+use Parrot::Configure::Utils ':auto';
+
+sub _init {
+    my $self = shift;
+    my %data;
+    $data{description} = q{Determine whether negative zero can be printed};
+    $data{result}      = q{};
+    return \%data;
+}
+
+sub runstep {
+    my ( $self, $conf ) = @_;
+    my ( $verbose ) = $conf->options->get('verbose');
+    $conf->cc_gen('config/auto/neg_0/test_c.in');
+    eval { $conf->cc_build( q{} ); };
+    my $has_neg_0 = 0;
+    if ( !$@ ) {
+        my $test = $conf->cc_run();
+        $has_neg_0 = $self->_evaluate_cc_run($conf, $test, $has_neg_0, $verbose);
+    }
+    $conf->cc_clean();
+    $conf->data->set( has_negative_zero => $has_neg_0 );
+
+    return 1;
+}
+
+sub _evaluate_cc_run {
+    my $self = shift;
+    my ($conf, $test, $has_neg_0, $verbose) = @_;
+    $has_neg_0 = ($test =~ m/^-0/ ? 1 : 0);
+    $self->set_result( $has_neg_0 ? 'yes' : 'no' );
+    $conf->data->set( has_negative_zero => $has_neg_0 );
+    print $has_neg_0 ? ' (yes) ' : ' (no) ' if $verbose;
+    return $has_neg_0;
+}
+
+1;
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Added: trunk/config/auto/neg_0/test_c.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/config/auto/neg_0/test_c.in	Thu Feb 12 19:30:15 2009	(r36638)
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int
+main(int argc, char* argv[])
+{
+    printf("%.0f", -0.0);
+    return 0;
+}

Modified: trunk/config/gen/config_h/feature_h.in
==============================================================================
--- trunk/config/gen/config_h/feature_h.in	Thu Feb 12 18:46:52 2009	(r36637)
+++ trunk/config/gen/config_h/feature_h.in	Thu Feb 12 19:30:15 2009	(r36638)
@@ -154,6 +154,15 @@
 
 print OUT <<'END_PRINT';
 
+/* from config/auto/neg_0 */
+END_PRINT
+if (@has_negative_zero@) {
+    print OUT <<'END_PRINT';
+#define PARROT_HAS_NEGATIVE_ZERO 1
+END_PRINT
+}
+
+print OUT <<'END_PRINT';
 
 #endif /* PARROT_FEATURE_H_GUARD */
 END_PRINT

Modified: trunk/lib/Parrot/Configure/Step/List.pm
==============================================================================
--- trunk/lib/Parrot/Configure/Step/List.pm	Thu Feb 12 18:46:52 2009	(r36637)
+++ trunk/lib/Parrot/Configure/Step/List.pm	Thu Feb 12 19:30:15 2009	(r36638)
@@ -50,6 +50,7 @@
     auto::memalign
     auto::signal
     auto::socklen_t
+    auto::neg_0
     auto::env
     auto::gmp
     auto::readline

Modified: trunk/t/op/arithmetics.t
==============================================================================
--- trunk/t/op/arithmetics.t	Thu Feb 12 18:46:52 2009	(r36637)
+++ trunk/t/op/arithmetics.t	Thu Feb 12 19:30:15 2009	(r36638)
@@ -152,7 +152,7 @@
 TODO: {
     my @todo;
     @todo = ( todo => '-0.0 not implemented, TT #313' )
-        if $^O =~ m/(?:openbsd|win32)/i;
+        if $^O =~ m/(?:openbsd)/i;
 
 pasm_output_is( <<'CODE', <<OUTPUT, 'negate -0.0', @todo );
         set N0, 0
@@ -843,12 +843,7 @@
 OUTPUT
 }
 
-TODO: {
-    my @todo;
-    @todo = ( todo => 'inf is not platform-independent' )
-        if $^O eq 'MSWin32' and $PConfig{cc} =~ /cl/i;
-
-pir_output_is( <<'CODE', <<OUTPUT, "Inf/NaN - basic arith", @todo );
+pir_output_is( <<'CODE', <<OUTPUT, "Inf/NaN - basic arith" );
 .sub 'test' :main
     $N0 = 'Inf'
     say $N0
@@ -860,8 +855,6 @@
 NaN
 OUTPUT
 
-}
-
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4

Modified: trunk/t/pmc/complex.t
==============================================================================
--- trunk/t/pmc/complex.t	Thu Feb 12 18:46:52 2009	(r36637)
+++ trunk/t/pmc/complex.t	Thu Feb 12 19:30:15 2009	(r36638)
@@ -1065,7 +1065,6 @@
     .complex_op_is("-2-3i", "3.590565-0.530921i", 'sinh' )
 
     eq osname, "openbsd", todo
-    eq osname, "MSWin32", todo
     .complex_op_is("0-2i", "-0.000000-0.909297i", 'sinh' )
     .complex_op_is("0+2i", "-0.000000+0.909297i", 'sinh' )
     .return()

Modified: trunk/t/pmc/float.t
==============================================================================
--- trunk/t/pmc/float.t	Thu Feb 12 18:46:52 2009	(r36637)
+++ trunk/t/pmc/float.t	Thu Feb 12 19:30:15 2009	(r36638)
@@ -506,7 +506,7 @@
 TODO: {
     my @todo;
     @todo = ( todo => '-0.0 not implemented, TT #313' )
-        if $^O =~ m/(?:openbsd|win32)/i;
+        if $^O =~ m/(?:openbsd)/i;
 
 pasm_output_like( <<'CODE', <<'OUTPUT', 'neg 0', @todo );
     new P0, ['Float']

Added: trunk/t/steps/auto_neg_0-01.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/t/steps/auto_neg_0-01.t	Thu Feb 12 19:30:15 2009	(r36638)
@@ -0,0 +1,106 @@
+#! perl
+# Copyright (C) 2009, The Perl Foundation.
+# $Id: auto_neg_0-01.t 30640 2008-08-29 23:09:28Z rurban $
+# auto_neg_0-01.t
+
+use strict;
+use warnings;
+use Test::More tests => 16;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::auto::neg_0');
+use Parrot::Configure;
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Test qw(
+    test_step_thru_runstep
+    rerun_defaults_for_testing
+    test_step_constructor_and_description
+);
+use IO::CaptureOutput qw| capture |;
+
+########### regular ###########
+
+my ($args, $step_list_ref) = process_options(
+    {
+        argv => [ ],
+        mode => q{configure},
+    }
+);
+
+my $conf = Parrot::Configure->new;
+
+my $pkg = q{auto::neg_0};
+
+$conf->add_steps($pkg);
+
+my $serialized = $conf->pcfreeze();
+
+$conf->options->set( %{$args} );
+my $step = test_step_constructor_and_description($conf);
+my $ret = $step->runstep($conf);
+ok( $ret, "runstep() returned true value" );
+ok(defined($step->result()), "A result has been defined");
+
+$conf->replenish($serialized);
+
+##### _evaluate_cc_run() #####
+
+($args, $step_list_ref) = process_options(
+    {
+        argv => [ ],
+        mode => q{configure},
+    }
+);
+$conf->options->set( %{$args} );
+$step = test_step_constructor_and_description($conf);
+
+my $d_neg_0;
+
+$d_neg_0 = q{-0};
+ok($step->_evaluate_cc_run($conf, $d_neg_0),
+    "_evaluate_cc_run() completed satisfactorily");
+is($step->result(), q{yes}, "Got expected result");
+is($conf->data->get('has_negative_zero'), 1,
+    "has_negative_zero set as expected");
+
+$d_neg_0 = q{0};
+ok(!$step->_evaluate_cc_run($conf, $d_neg_0),
+    "_evaluate_cc_run() completed satisfactorily");
+is($step->result(), q{no}, "Got expected result");
+is($conf->data->get('has_negative_zero'), 0,
+    "has_negative_zero set as expected");
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+auto_neg_0-01.t - test auto::neg_0
+
+=head1 SYNOPSIS
+
+    % prove t/steps/auto_neg_0-01.t
+
+=head1 DESCRIPTION
+
+The files in this directory test functionality used by F<Configure.pl>.
+
+The tests in this file test auto::neg_0.
+
+=head1 AUTHOR
+
+Reini Urban
+
+=head1 SEE ALSO
+
+config::auto::neg_0, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:


More information about the parrot-commits mailing list