util.c UTF8 cleanup
authorBrian Fraser <fraserbn@gmail.com>
Thu, 7 Jul 2011 09:09:12 +0000 (06:09 -0300)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 6 Oct 2011 20:01:16 +0000 (13:01 -0700)
t/lib/warnings/util
util.c

index e632d09..618cf75 100644 (file)
@@ -156,3 +156,123 @@ if ($x) {
 EXPECT
 Name "main::y" used only once: possible typo at - line 8.
 Use of uninitialized value $y in print at - line 8.
+########
+# util.c
+use utf8;
+use open qw( :utf8 :std );
+use warnings;
+$ㄒ = 1;
+if ($ㄒ) {
+    print $ʎ;
+}
+EXPECT
+Name "main::ʎ" used only once: possible typo at - line 7.
+Use of uninitialized value $ʎ in print at - line 7.
+########
+# util.c
+use utf8;
+use open qw( :utf8 :std );
+use warnings;
+$ㄒ = 1;
+if ($ㄒ) {
+    $ㄒ++;
+    print $ʎ;
+}
+EXPECT
+Name "main::ʎ" used only once: possible typo at - line 8.
+Use of uninitialized value $ʎ in print at - line 8.
+########
+# util.c
+use utf8;
+use open qw( :utf8 :std );
+use warnings;
+$ㄒ = 0;
+if ($ㄒ) {
+    print "1\n";
+} elsif (!$ㄒ) {
+    print $ʎ;
+} else {
+    print "0\n";
+}
+EXPECT
+Name "main::ʎ" used only once: possible typo at - line 9.
+Use of uninitialized value $ʎ in print at - line 9.
+########
+# util.c
+use utf8;
+use open qw( :utf8 :std );
+use warnings;
+$ㄒ = 0;
+if ($ㄒ) {
+    print "1\n";
+} elsif (!$ㄒ) {
+    $ㄒ++;
+    print $ʎ;
+} else {
+    print "0\n";
+}
+EXPECT
+Name "main::ʎ" used only once: possible typo at - line 10.
+Use of uninitialized value $ʎ in print at - line 10.
+########
+# util.c
+use utf8;
+use open qw( :utf8 :std );
+use warnings;
+package 팣칵ぇ;
+$ㄒ = 1;
+if ($ㄒ) {
+    print $ʎ;
+}
+EXPECT
+Name "팣칵ぇ::ʎ" used only once: possible typo at - line 8.
+Use of uninitialized value $팣칵ぇ::ʎ in print at - line 8.
+########
+# util.c
+use utf8;
+use open qw( :utf8 :std );
+use warnings;
+package 팣칵ぇ;
+$ㄒ = 1;
+if ($ㄒ) {
+    $ㄒ++;
+    print $ʎ;
+}
+EXPECT
+Name "팣칵ぇ::ʎ" used only once: possible typo at - line 9.
+Use of uninitialized value $팣칵ぇ::ʎ in print at - line 9.
+########
+# util.c
+use utf8;
+use open qw( :utf8 :std );
+use warnings;
+package 팣칵ぇ;
+$ㄒ = 0;
+if ($ㄒ) {
+    print "1\n";
+} elsif (!$ㄒ) {
+    print $ʎ;
+} else {
+    print "0\n";
+}
+EXPECT
+Name "팣칵ぇ::ʎ" used only once: possible typo at - line 10.
+Use of uninitialized value $팣칵ぇ::ʎ in print at - line 10.
+########
+# util.c
+use utf8;
+use open qw( :utf8 :std );
+use warnings;
+package 팣칵ぇ;
+$ㄒ = 0;
+if ($ㄒ) {
+    print "1\n";
+} elsif (!$ㄒ) {
+    $ㄒ++;
+    print $ʎ;
+} else {
+    print "0\n";
+}
+EXPECT
+Name "팣칵ぇ::ʎ" used only once: possible typo at - line 11.
+Use of uninitialized value $팣칵ぇ::ʎ in print at - line 11.
diff --git a/util.c b/util.c
index 113cd17..7583d23 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1457,8 +1457,10 @@ Perl_mess_sv(pTHX_ SV *basemsg, bool consume)
        {
            const bool line_mode = (RsSIMPLE(PL_rs) &&
                              SvCUR(PL_rs) == 1 && *SvPVX_const(PL_rs) == '\n');
-           Perl_sv_catpvf(aTHX_ sv, ", <%s> %s %"IVdf,
-                          PL_last_in_gv == PL_argvgv ? "" : GvNAME(PL_last_in_gv),
+           Perl_sv_catpvf(aTHX_ sv, ", <%"SVf"> %s %"IVdf,
+                          SVfARG(PL_last_in_gv == PL_argvgv
+                                 ? &PL_sv_no
+                                 : sv_2mortal(newSVhek(GvNAME_HEK(PL_last_in_gv)))),
                           line_mode ? "line" : "chunk",
                           (IV)IoLINES(GvIOp(PL_last_in_gv)));
        }
@@ -3857,13 +3859,15 @@ void
 Perl_report_wrongway_fh(pTHX_ const GV *gv, const char have)
 {
     if (ckWARN(WARN_IO)) {
-       const char * const name
-           = gv && (isGV(gv) || isGV_with_GP(gv)) ? GvENAME(gv) : NULL;
+        SV * const name
+           = gv && (isGV(gv) || isGV_with_GP(gv))
+                ? sv_2mortal(newSVhek(GvENAME_HEK((gv))))
+                : NULL;
        const char * const direction = have == '>' ? "out" : "in";
 
-       if (name && *name)
+       if (name && SvPOK(name) && *SvPV_nolen(name))
            Perl_warner(aTHX_ packWARN(WARN_IO),
-                       "Filehandle %s opened only for %sput",
+                       "Filehandle %"SVf" opened only for %sput",
                        name, direction);
        else
            Perl_warner(aTHX_ packWARN(WARN_IO),
@@ -3889,8 +3893,9 @@ Perl_report_evil_fh(pTHX_ const GV *gv)
     }
 
     if (ckWARN(warn_type)) {
-       const char * const name
-           = gv && (isGV(gv) || isGV_with_GP(gv)) ? GvENAME(gv) : NULL;
+        SV * const name
+            = gv && (isGV(gv) || isGV_with_GP(gv)) && GvENAMELEN(gv) ?
+                                     sv_2mortal(newSVhek(GvENAME_HEK(gv))) : NULL;
        const char * const pars =
            (const char *)(OP_IS_FILETEST(op) ? "" : "()");
        const char * const func =
@@ -3902,14 +3907,14 @@ Perl_report_evil_fh(pTHX_ const GV *gv)
            (const char *)
            (OP_IS_SOCKET(op) || (io && IoTYPE(io) == IoTYPE_SOCKET)
             ? "socket" : "filehandle");
-       if (name && *name) {
+       if (name && SvPOK(name) && *SvPV_nolen(name)) {
            Perl_warner(aTHX_ packWARN(warn_type),
-                       "%s%s on %s %s %s", func, pars, vile, type, name);
+                       "%s%s on %s %s %"SVf, func, pars, vile, type, SVfARG(name));
            if (io && IoDIRP(io) && !(IoFLAGS(io) & IOf_FAKE_DIRP))
                Perl_warner(
                            aTHX_ packWARN(warn_type),
-                           "\t(Are you trying to call %s%s on dirhandle %s?)\n",
-                           func, pars, name
+                           "\t(Are you trying to call %s%s on dirhandle %"SVf"?)\n",
+                           func, pars, SVfARG(name)
                            );
        }
        else {