This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
shrink pp_hot fractionally
authorNicholas Clark <nick@ccl4.org>
Tue, 5 Dec 2000 12:44:31 +0000 (12:44 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Tue, 5 Dec 2000 14:38:53 +0000 (14:38 +0000)
Message-ID: <20001205124431.E74518@plum.flirble.org>

Use report_evil_fh().

p4raw-id: //depot/perl@7990

opcode.pl
opnames.h
pp_hot.c
util.c

index 43d98ae..22ef972 100755 (executable)
--- a/opcode.pl
+++ b/opcode.pl
@@ -56,7 +56,9 @@ for (@ops) {
 }
 print ON "\t", &tab(3,"OP_max"), "\n";
 print ON "} opcode;\n";
-print ON "\n#define MAXO ", scalar @ops, "\n\n"; 
+print ON "\n#define MAXO ", scalar @ops, "\n";
+print ON "#define OP_phoney_INPUT_ONLY -1\n";
+print ON "#define OP_phoney_OUTPUT_ONLY -2\n\n";
 
 # Emit op names and descriptions.
 
index ba28f68..16b2f02 100644 (file)
--- a/opnames.h
+++ b/opnames.h
@@ -359,6 +359,8 @@ typedef enum opcode {
 } opcode;
 
 #define MAXO 351
+#define OP_phoney_INPUT_ONLY -1
+#define OP_phoney_OUTPUT_ONLY -2
 
 
 #define OP_IS_SOCKET(op)       \
index c12e986..830d56e 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -415,21 +415,8 @@ PP(pp_print)
     }
     else if (!(fp = IoOFP(io))) {
        if (ckWARN2(WARN_CLOSED, WARN_IO))  {
-           if (IoIFP(io)) {
-               /* integrate with report_evil_fh()? */
-               char *name = NULL;
-               if (isGV(gv)) {
-                   SV* sv = sv_newmortal();
-                   gv_efullname4(sv, gv, Nullch, FALSE);
-                   name = SvPV_nolen(sv);
-               }
-               if (name && *name)
-                 Perl_warner(aTHX_ WARN_IO,
-                             "Filehandle %s opened only for input", name);
-               else
-                   Perl_warner(aTHX_ WARN_IO,
-                               "Filehandle opened only for input");
-           }
+           if (IoIFP(io))
+               report_evil_fh(gv, io, OP_phoney_INPUT_ONLY);
            else if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
                report_evil_fh(gv, io, PL_op->op_type);
        }
@@ -1394,21 +1381,7 @@ Perl_do_readline(pTHX)
        else if (ckWARN(WARN_IO)        /* stdout/stderr or other write fh */
                 && (IoTYPE(io) == IoTYPE_WRONLY || fp == PerlIO_stdout()
                     || fp == PerlIO_stderr()))
-       {
-           /* integrate with report_evil_fh()? */
-           char *name = NULL;
-           if (isGV(PL_last_in_gv)) { /* can this ever fail? */
-               SV* sv = sv_newmortal();
-               gv_efullname4(sv, PL_last_in_gv, Nullch, FALSE);
-               name = SvPV_nolen(sv);
-           }
-           if (name && *name)
-               Perl_warner(aTHX_ WARN_IO,
-                           "Filehandle %s opened only for output", name);
-           else
-               Perl_warner(aTHX_ WARN_IO,
-                           "Filehandle opened only for output");
-       }
+           report_evil_fh(PL_last_in_gv, io, OP_phoney_OUTPUT_ONLY);
     }
     if (!fp) {
        if (ckWARN2(WARN_GLOB, WARN_CLOSED)
diff --git a/util.c b/util.c
index 128e24e..d0ea96c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -3958,7 +3958,15 @@ Perl_report_evil_fh(pTHX_ GV *gv, IO *io, I32 op)
        name = SvPVX(sv);
     }
 
-    if (name && *name) {
+    if (op == OP_phoney_OUTPUT_ONLY || op == OP_phoney_INPUT_ONLY) {
+       if (name && *name)
+           Perl_warner(aTHX_ WARN_IO, "Filehandle %s opened only for %sput",
+                       name, 
+                       (op == OP_phoney_INPUT_ONLY ? "in" : "out"));
+       else
+           Perl_warner(aTHX_ WARN_IO, "Filehandle opened only for %sput",
+                       (op == OP_phoney_INPUT_ONLY ? "in" : "out"));
+    } else if (name && *name) {
        Perl_warner(aTHX_ warn_type,
                    "%s%s on %s %s %s", func, pars, vile, type, name);
        if (io && IoDIRP(io) && !(IoFLAGS(io) & IOf_FAKE_DIRP))