From 3825652ddfd2e6e7a10980ece6f9a732388cbecf Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sun, 25 Dec 2011 00:16:21 -0800 Subject: [PATCH] PerlIO::get_layers: Treat numbers as strings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit PerlIO::get_layers should not be ignoring an argument like 12, but treating "12" (the string) as a filehandle, as those are both the same value. It’s an instance of the string/num bug, which is a bit like the Unicode Bug. This commit takes the conservative approach of expanding it to flat scalars in general, but not references (in case we decide to do something interesting later on, even though I think that would be a bad idea). --- t/io/layers.t | 6 +++++- universal.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/t/io/layers.t b/t/io/layers.t index 45afd7b..86d171c 100644 --- a/t/io/layers.t +++ b/t/io/layers.t @@ -35,7 +35,7 @@ if (${^UNICODE} & 1) { } else { $UTF8_STDIN = 0; } -my $NTEST = 59 - (($DOSISH || !$FASTSTDIO) ? 7 : 0) - ($DOSISH ? 7 : 0) +my $NTEST = 60 - (($DOSISH || !$FASTSTDIO) ? 7 : 0) - ($DOSISH ? 7 : 0) + $UTF8_STDIN; sub PerlIO::F_UTF8 () { 0x00008000 } # from perliol.h @@ -246,4 +246,8 @@ EOT $t = ''; $f = 0; PerlIO::get_layers $t; is $f, 1, '1 fetch on tied string'; + + # No distinction between nums and strings + open "12", "<:crlf", "test.pl" or die "$0 cannot open test.pl: $!"; + ok PerlIO::get_layers(12), 'str/num arguments are treated identically'; } diff --git a/universal.c b/universal.c index 36800b8..9d743ab 100644 --- a/universal.c +++ b/universal.c @@ -1006,7 +1006,7 @@ XS(XS_PerlIO_get_layers) sv = POPs; gv = MAYBE_DEREF_GV(sv); - if (!gv && SvPOKp(sv)) + if (!gv && !SvROK(sv)) gv = gv_fetchsv_nomg(sv, 0, SVt_PVIO); if (gv && (io = GvIO(gv))) { -- 2.7.4