This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c: Take utf8 into account when creating DATA handle
authorFather Chrysostomos <sprout@cpan.org>
Fri, 30 Sep 2011 01:23:27 +0000 (18:23 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 6 Oct 2011 20:01:14 +0000 (13:01 -0700)
This is based on work from Brian Fraser, but differs from his original
in that it does not require an intermediate SV.

toke.c

diff --git a/toke.c b/toke.c
index 53c6759..c995556 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -6952,10 +6952,20 @@ Perl_yylex(pTHX)
            GV *gv;
            if (PL_rsfp && (!PL_in_eval || PL_tokenbuf[2] == 'D')) {
                const char *pname = "main";
+               STRLEN plen = 4;
+               U32 putf8 = 0;
                if (PL_tokenbuf[2] == 'D')
-                   pname = HvNAME_get(PL_curstash ? PL_curstash : PL_defstash);
-               gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), GV_ADD,
-                               SVt_PVIO);
+               {
+                   HV * const stash =
+                       PL_curstash ? PL_curstash : PL_defstash;
+                   pname = HvNAME_get(stash);
+                   plen  = HvNAMELEN (stash);
+                   if(HvNAMEUTF8(stash)) putf8 = SVf_UTF8;
+               }
+               gv = gv_fetchpvn_flags(
+                       Perl_form(aTHX_ "%*s::DATA", (int)plen, pname),
+                       plen+6, GV_ADD|putf8, SVt_PVIO
+               );
                GvMULTI_on(gv);
                if (!GvIO(gv))
                    GvIOp(gv) = newIO();