develooper Front page | perl.perl5.porters | Postings from March 2013

[perl #117231] using constant loads utf8 unnecessarily

Thread Previous
From:
Brad Gilbert
Date:
March 20, 2013 15:54
Subject:
[perl #117231] using constant loads utf8 unnecessarily
Message ID:
rt-3.6.HEAD-28177-1363794832-1072.117231-75-0@perl.org
# New Ticket Created by  "Brad Gilbert" 
# Please include the string:  [perl #117231]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=117231 >


Right now just loading constant will force utf8 to also be loaded.

    $ perl-5.16.1 -mconstant -e'print qq[$_\n] for keys %INC'
    warnings.pm
    warnings/register.pm
    utf8_heavy.pl
    utf8.pm
    vars.pm
    strict.pm
    constant.pm
    unicore/lib/Perl/_PerlIDS.pl
    unicore/Heavy.pl

The reason is that `{chr 256} = \3` is in the `BEGIN` block.

This was needed to determine when `constant` needed to
work around perl bug #31991.
( following code was added in bd8cb552 by Father Chrysostomos,
just before the fix )

BEGIN{
    ...
    # Before this makes its way into a dev perl release, we have to do
    # browser-sniffing, as it were....
    *{chr 256} = \3;
    if (exists ${__PACKAGE__."::"}{"\xc4\x80"}) {
	delete ${__PACKAGE__."::"}{"\xc4\x80"};
	*_DOWNGRADE = sub () {1};
    }
    else {
	delete ${__PACKAGE__."::"}{chr 256};
	*_DOWNGRADE = sub () {0};
    }
}

...

		if (_DOWNGRADE) { # for 5.8 to 5.14
		    # Work around perl bug #31991: Sub names (actually glob
		    # names in general) ignore the UTF8 flag. So we have to
		    # turn it off to get the "right" symbol table entry.
		    utf8::is_utf8 $name and utf8::encode $name;
		}

Since #31991 was fixed between two dev releases, it couldn't
just check the version of perl. Based on the associated comment
it should probably have been made version dependent after the
next dev release.

    my $downgrade = $] < 5.015004; # && $] >= 5.008
    *_DOWNGRADE = sub () { $downgrade };

( `&& $] >= 5.008`  is commented out because there is
a `use 5.008;` earlier )

I have tested this change on 5.14.1 and 5.16.1
it delays loading utf8 until it is actually needed.

$ perl-5.16.1 -Mconstant -e'print qq[$_\n] for keys %INC;
    constant->import(chr(256),\3);print qq[\n];
    print qq[$_\n] for keys %INC'
warnings.pm
warnings/register.pm
vars.pm
strict.pm
constant.pm

warnings/register.pm
utf8_heavy.pl
vars.pm
strict.pm
constant.pm
unicore/Heavy.pl
warnings.pm
utf8.pm
unicore/lib/Perl/Word.pl


It still needs a version bump, and to be released to CPAN.

( as far as I can tell core is upstream )

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About