In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/637917bb2be52531e0e1877cc368f6f9f48e6bc0?hp=56e1cca174a06a1be569b25dd29cf4b8d6a5bf9d>
- Log ----------------------------------------------------------------- commit 637917bb2be52531e0e1877cc368f6f9f48e6bc0 Author: Karl Williamson <[email protected]> Date: Fri Jul 19 09:50:27 2013 -0600 locale.c: Add missing STATIC to fcn decl M locale.c commit 02aba72f9af3ac175d1dfacad3955de025cd7130 Author: Karl Williamson <[email protected]> Date: Tue Jul 16 22:02:46 2013 -0600 Move some tests from cpan/version to t/run Commit fb7942811c8097ed2e61fd35a90345226546176a recently moved version.pm to cpan. Earlier, in commit b127e37e51c21b0a36755dcd19811be931a03d83, I had added tests to version's .t that arguably belonged elsewhere. I did this because I thought that this .t was the only one around that had the infrastructure already written to allow such tests to easily be added, and it was in /lib so p5p controlled it. (That infrastructure being finding locales with the decimal point not a dot.) Since then, I found that t/run/locale.t has similar infrastructure. Given that version now may end up being cpan upstream, I thought it best to move those tests to t/run/locale.t I notice that changes to this .t prior to these no longer were careful to avoid 'use locale' in case the platform doesn't support it, and there have been no field problems; so I just went ahead and did a 'use locale' too. M cpan/version/t/07locale.t M t/run/locale.t commit 3fca3d61b552b8da4cb82e43e9eac517631ef737 Author: Karl Williamson <[email protected]> Date: Tue Jul 16 22:05:57 2013 -0600 cpan/version/t/07locale.t: Actually test what is claimed Commit b127e37e51c21b0a36755dcd19811be931a03d83 wrongly changed two tests, and failed to change a third. One of the two ended up doing: ok ("$ver eq '1,23'", ...); That's always going to succeed as ok() doesn't do an eval; it just looks at the result of the expression, which in this case was a non-empty string. The second test was changed from an 'eq' to '=='. It had this diff: - is ($v, "1.23", "Locale doesn't apply to version objects"); + ok ($v == "1.23", "Locale doesn't apply to version objects"); (The code for is() does an 'eq'.) The is() call is made from within the scope of a "use locale" in which the decimal point character is a comma, but version objects are supposed to always use a dot, regardless of the locale. The == will numify the operands, potentially throwing away the locale's decimal point character. Therefore the test should use an 'eq'. Before these changes, the two tests also didn't do what they purported (and hence the motivation for the changes). The tests previously used 'is()', which is defined in a different file which is outside the locale scope, so that the scalars ($v and $ver) there should have a dot even if they have a comma within locale scope, and hence doing an is() would not catch the bug being tested against. Hence the third test (overlooked in the earlier commit) remained wrong until now. M cpan/version/t/07locale.t commit 1078c6a2c81c4b65a2bdfe9f9778a03e3fb57bec Author: Karl Williamson <[email protected]> Date: Tue Jul 16 22:01:08 2013 -0600 sv.h: Comments added/typo fixed. M sv.h ----------------------------------------------------------------------- Summary of changes: cpan/version/t/07locale.t | 25 ++++++++++--------------- locale.c | 2 +- sv.h | 9 ++++++++- t/run/locale.t | 39 +++++++++++++++++++++++++++++++++++---- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/cpan/version/t/07locale.t b/cpan/version/t/07locale.t index 784bc11..d6dc8c9 100644 --- a/cpan/version/t/07locale.t +++ b/cpan/version/t/07locale.t @@ -7,7 +7,7 @@ use File::Basename; use File::Temp qw/tempfile/; use POSIX qw/locale_h/; -use Test::More tests => 9; +use Test::More tests => 7; use Config; BEGIN { @@ -15,8 +15,8 @@ BEGIN { } SKIP: { - skip 'No locale testing for Perl < 5.6.0', 8 if $] < 5.006; - skip 'No locale testing without d_setlocale', 8 if(!$Config{d_setlocale}); + skip 'No locale testing for Perl < 5.6.0', 6 if $] < 5.006; + skip 'No locale testing without d_setlocale', 6 if(!$Config{d_setlocale}); # test locale handling my $warning; @@ -27,33 +27,28 @@ SKIP: { my $ver = 1.23; # has to be floating point number my $loc; my $orig_loc = setlocale(LC_NUMERIC); - is ($ver, '1.23', 'Not using locale yet'); + ok ($ver eq "1.23", 'Not using locale yet'); # Don't use is(), + # because have to + # evaluate in current + # scope while (<DATA>) { chomp; $loc = setlocale( LC_ALL, $_); last if localeconv()->{decimal_point} eq ','; } - skip 'Cannot test locale handling without a comma locale', 7 + skip 'Cannot test locale handling without a comma locale', 5 unless $loc and localeconv()->{decimal_point} eq ','; diag ("Testing locale handling with $loc") unless $ENV{PERL_CORE}; setlocale(LC_NUMERIC, $loc); - ok ("$ver eq '1,23'", "Using locale: $loc"); + ok ($ver eq "1,23", "Using locale: $loc"); $v = version->new($ver); unlike($warning, qr/Version string '1,23' contains invalid data/, "Process locale-dependent floating point"); - ok ($v == "1.23", "Locale doesn't apply to version objects"); + ok ($v eq "1.23", "Locale doesn't apply to version objects"); ok ($v == $ver, "Comparison to locale floating point"); - { - no locale; - ok ("$ver eq '1.23'", "Outside of scope of use locale"); - } - - ok("\"$ver\"+1 gt 2.22" && \"$ver\"+1 lt 2.24", - "Can do math when radix is not a dot"); # [perl 115800] - setlocale( LC_ALL, $orig_loc); # reset this before possible skip skip 'Cannot test RT#46921 with Perl < 5.008', 1 if ($] < 5.008); diff --git a/locale.c b/locale.c index b9be9f9..65c03a6 100644 --- a/locale.c +++ b/locale.c @@ -605,7 +605,7 @@ Perl_mem_collxfrm(pTHX_ const char *s, STRLEN len, STRLEN *xlen) #endif /* USE_LOCALE_COLLATE */ -bool +STATIC bool S_is_cur_LC_category_utf8(pTHX_ int category) { /* Returns TRUE if the current locale for 'category' is UTF-8; FALSE diff --git a/sv.h b/sv.h index 7110b4c..32fe744 100644 --- a/sv.h +++ b/sv.h @@ -120,8 +120,14 @@ Type flag for formats. See L</svtype>. Type flag for I/O objects. See L</svtype>. =cut + + These are ordered so that the simpler types have a lower value; SvUPGRADE + doesn't allow you to upgrade from a higher numbered type to a lower numbered + one; also there is code that assumes that anything that has as a PV component + has a type numbered >= SVt_PV. */ + typedef enum { SVt_NULL, /* 0 */ /* BIND was here, before INVLIST replaced it. */ @@ -154,7 +160,7 @@ typedef enum { #ifndef PERL_CORE /* Although Fast Boyer Moore tables are now being stored in PVGVs, for most - purposes eternal code wanting to consider PVBM probably needs to think of + purposes external code wanting to consider PVBM probably needs to think of PVMG instead. */ # define SVt_PVBM SVt_PVMG /* Anything wanting to create a reference from clean should ensure that it has @@ -943,6 +949,7 @@ in gv.h: */ #define HvAMAGIC_off(hv) (SvFLAGS(hv) &=~ SVf_AMAGIC) +/* "nog" means "doesn't have get magic" */ #define SvPOK_nog(sv) ((SvFLAGS(sv) & (SVf_POK|SVs_GMG)) == SVf_POK) #define SvIOK_nog(sv) ((SvFLAGS(sv) & (SVf_IOK|SVs_GMG)) == SVf_IOK) #define SvUOK_nog(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV|SVs_GMG)) == (SVf_IOK|SVf_IVisUV)) diff --git a/t/run/locale.t b/t/run/locale.t index d01e3bc..4422317 100644 --- a/t/run/locale.t +++ b/t/run/locale.t @@ -62,7 +62,7 @@ EOF # try to find out a locale where LC_NUMERIC makes a difference my $original_locale = setlocale(LC_NUMERIC); -my ($base, $different, $difference); +my ($base, $different, $comma, $difference); for ("C", @locales) { # prefer C for the base if available BEGIN { if($Config{d_setlocale}) { @@ -76,9 +76,10 @@ for ("C", @locales) { # prefer C for the base if available } else { $different ||= $_; $difference ||= $s; + $comma ||= $_ if localeconv()->{decimal_point} eq ','; } - last if $base && $different; + last if $base && $different && $comma; } setlocale(LC_NUMERIC, $original_locale); @@ -167,7 +168,6 @@ EOF "", {}, "version does not clobber version (via eval)"); } - for ($different) { local $ENV{LC_NUMERIC} = $_; local $ENV{LC_ALL}; # so it never overrides LC_NUMERIC @@ -180,6 +180,37 @@ EOF EOF "sprintf() and printf() look at LC_NUMERIC regardless of constant folding"); } + + unless ($comma) { + skip("no locale available where LC_NUMERIC is a comma", 2); + } + else { + + fresh_perl_is(<<"EOF", + my \$i = 1.5; + { + use locale; + use POSIX; + POSIX::setlocale(POSIX::LC_NUMERIC(),"$comma"); + print \$i, "\n"; + } + print \$i, "\n"; +EOF + "1,5\n1.5", {}, "Radix print properly in locale scope, and without"); + + fresh_perl_is(<<"EOF", + my \$i = 1.5; # Should be exactly representable as a base 2 + # fraction, so can use 'eq' below + use locale; + use POSIX; + POSIX::setlocale(POSIX::LC_NUMERIC(),"$comma"); + print \$i, "\n"; + \$i += 1; + print \$i, "\n"; +EOF + "1,5\n2,5", {}, "Can do math when radix is a comma"); # [perl 115800] + } + } # SKIP -sub last { 9 } +sub last { 11 } -- Perl5 Master Repository
