From affc13fc37d571176c2495208a3a38d42f0052f7 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Thu, 29 Sep 2011 18:23:27 -0700 Subject: [PATCH] toke.c: Take utf8 into account when creating DATA handle This is based on work from Brian Fraser, but differs from his original in that it does not require an intermediate SV. --- toke.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/toke.c b/toke.c index 53c6759..c995556 100644 --- 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(); -- 2.7.4