Cleaner.
[p5sagit/p5-mst-13.2.git] / op.c
diff --git a/op.c b/op.c
index 8446499..b0d4006 100644 (file)
--- a/op.c
+++ b/op.c
@@ -1027,7 +1027,7 @@ Perl_scalar(pTHX_ OP *o)
     case OP_SPLIT:
        if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
            if (!kPMOP->op_pmreplroot)
-               deprecate("implicit split to @_");
+               deprecate_old("implicit split to @_");
        }
        /* FALL THROUGH */
     case OP_MATCH:
@@ -1274,7 +1274,7 @@ Perl_scalarvoid(pTHX_ OP *o)
     case OP_SPLIT:
        if ((kid = cLISTOPo->op_first) && kid->op_type == OP_PUSHRE) {
            if (!kPMOP->op_pmreplroot)
-               deprecate("implicit split to @_");
+               deprecate_old("implicit split to @_");
        }
        break;
     }
@@ -2498,30 +2498,6 @@ Perl_fold_constants(pTHX_ register OP *o)
     }
 
   nope:
-    if (!(PL_opargs[type] & OA_OTHERINT))
-       return o;
-
-    if (!(PL_hints & HINT_INTEGER)) {
-       if (type == OP_MODULO
-           || type == OP_DIVIDE
-           || !(o->op_flags & OPf_KIDS))
-       {
-           return o;
-       }
-
-       for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) {
-           if (curop->op_type == OP_CONST) {
-               if (SvIOK(((SVOP*)curop)->op_sv))
-                   continue;
-               return o;
-           }
-           if (PL_opargs[curop->op_type] & OA_RETINTEGER)
-               continue;
-           return o;
-       }
-       o->op_ppaddr = PL_ppaddr[++(o->op_type)];
-    }
-
     return o;
 }
 
@@ -2546,6 +2522,7 @@ Perl_gen_constant_list(pTHX_ register OP *o)
 
     o->op_type = OP_RV2AV;
     o->op_ppaddr = PL_ppaddr[OP_RV2AV];
+    o->op_seq = 0;             /* needs to be revisited in peep() */
     curop = ((UNOP*)o)->op_first;
     ((UNOP*)o)->op_first = newSVOP(OP_CONST, 0, SvREFCNT_inc(*PL_stack_sp--));
     op_free(curop);
@@ -3378,7 +3355,7 @@ Perl_package(pTHX_ OP *o)
        op_free(o);
     }
     else {
-       deprecate("\"package\" with no arguments");
+       deprecate_old("\"package\" with no arguments");
        sv_setpv(PL_curstname,"<none>");
        PL_curstash = Nullhv;
     }
@@ -3474,11 +3451,22 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *id, OP *arg)
            newSTATEOP(0, Nullch, imop) ));
 
     if (packname) {
-        if (ckWARN(WARN_MISC) && !gv_stashpvn(packname, packlen, FALSE)) {
-            Perl_warner(aTHX_ WARN_MISC,
-                        "Package `%s' not found "
-                        "(did you use the incorrect case?)", packname);
-        }
+        /* The "did you use incorrect case?" warning used to be here.
+         * The problem is that on case-insensitive filesystems one
+         * might get false positives for "use" (and "require"):
+         * "use Strict" or "require CARP" will work.  This causes
+         * portability problems for the script: in case-strict
+         * filesystems the script will stop working.
+         *
+         * The "incorrect case" warning checked whether "use Foo"
+         * imported "Foo" to your namespace, but that is wrong, too:
+         * there is no requirement nor promise in the language that
+         * a Foo.pm should or would contain anything in package "Foo".
+         *
+         * There is very little Configure-wise that can be done, either:
+         * the case-sensitivity of the build filesystem of Perl does not
+         * help in guessing the case-sensitivity of the runtime environment.
+         */
         safefree(packname);
     }
 
@@ -4365,10 +4353,6 @@ Perl_newLOOPEX(pTHX_ I32 type, OP *label)
 void
 Perl_cv_undef(pTHX_ CV *cv)
 {
-    CV *outsidecv;
-    CV *freecv = Nullcv;
-    bool is_eval = CvEVAL(cv) && !CvGV(cv);    /* is this eval"" ? */
-
 #ifdef USE_5005THREADS
     if (CvMUTEXP(cv)) {
        MUTEX_DESTROY(CvMUTEXP(cv));
@@ -4404,14 +4388,13 @@ Perl_cv_undef(pTHX_ CV *cv)
     }
     SvPOK_off((SV*)cv);                /* forget prototype */
     CvGV(cv) = Nullgv;
-    outsidecv = CvOUTSIDE(cv);
     /* Since closure prototypes have the same lifetime as the containing
      * CV, they don't hold a refcount on the outside CV.  This avoids
      * the refcount loop between the outer CV (which keeps a refcount to
      * the closure prototype in the pad entry for pp_anoncode()) and the
      * closure prototype, and the ensuing memory leak.  --GSAR */
     if (!CvANON(cv) || CvCLONED(cv))
-       freecv = outsidecv;
+       SvREFCNT_dec(CvOUTSIDE(cv));
     CvOUTSIDE(cv) = Nullcv;
     if (CvCONST(cv)) {
        SvREFCNT_dec((SV*)CvXSUBANY(cv).any_ptr);
@@ -4420,39 +4403,10 @@ Perl_cv_undef(pTHX_ CV *cv)
     if (CvPADLIST(cv)) {
        /* may be during global destruction */
        if (SvREFCNT(CvPADLIST(cv))) {
-           AV *padlist = CvPADLIST(cv);
-           I32 ix;
-           if (is_eval) {
-               /* inner references to eval's cv must be fixed up */
-               AV *comppad_name = (AV*)AvARRAY(padlist)[0];
-               AV *comppad = (AV*)AvARRAY(padlist)[1];
-               SV **namepad = AvARRAY(comppad_name);
-               SV **curpad = AvARRAY(comppad);
-               for (ix = AvFILLp(comppad_name); ix > 0; ix--) {
-                   SV *namesv = namepad[ix];
-                   if (namesv && namesv != &PL_sv_undef
-                       && *SvPVX(namesv) == '&'
-                       && ix <= AvFILLp(comppad))
-                   {
-                       CV *innercv = (CV*)curpad[ix];
-                       if (innercv && SvTYPE(innercv) == SVt_PVCV
-                           && CvOUTSIDE(innercv) == cv)
-                       {
-                           CvOUTSIDE(innercv) = outsidecv;
-                           if (!CvANON(innercv) || CvCLONED(innercv)) {
-                               (void)SvREFCNT_inc(outsidecv);
-                               if (SvREFCNT(cv))
-                                   SvREFCNT_dec(cv);
-                           }
-                       }
-                   }
-               }
-           }
-           if (freecv)
-               SvREFCNT_dec(freecv);
-           ix = AvFILLp(padlist);
-           while (ix >= 0) {
-               SV* sv = AvARRAY(padlist)[ix--];
+           I32 i = AvFILLp(CvPADLIST(cv));
+           while (i >= 0) {
+               SV** svp = av_fetch(CvPADLIST(cv), i--, FALSE);
+               SV* sv = svp ? *svp : Nullsv;
                if (!sv)
                    continue;
                if (sv == (SV*)PL_comppad_name)
@@ -4467,8 +4421,6 @@ Perl_cv_undef(pTHX_ CV *cv)
        }
        CvPADLIST(cv) = Nullav;
     }
-    else if (freecv)
-       SvREFCNT_dec(freecv);
     if (CvXSUB(cv)) {
         CvXSUB(cv) = 0;
     }
@@ -4814,13 +4766,15 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
     name = o ? SvPVx(cSVOPo->op_sv, n_a) : Nullch;
     if (!name && PERLDB_NAMEANON && CopLINE(PL_curcop)) {
        SV *sv = sv_newmortal();
-       Perl_sv_setpvf(aTHX_ sv, "__ANON__[%s:%"IVdf"]",
+       Perl_sv_setpvf(aTHX_ sv, "%s[%s:%"IVdf"]",
+                      PL_curstash ? "__ANON__" : "__ANON__::__ANON__",
                       CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
        aname = SvPVX(sv);
     }
     else
        aname = Nullch;
-    gv = gv_fetchpv(name ? name : (aname ? aname : "__ANON__"),
+    gv = gv_fetchpv(name ? name : (aname ? aname : 
+                   (PL_curstash ? "__ANON__" : "__ANON__::__ANON__")),
                    GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
                    SVt_PVCV);
 
@@ -5238,7 +5192,9 @@ Used by C<xsubpp> to hook up XSUBs as Perl subs.
 CV *
 Perl_newXS(pTHX_ char *name, XSUBADDR_t subaddr, char *filename)
 {
-    GV *gv = gv_fetchpv(name ? name : "__ANON__", GV_ADDMULTI, SVt_PVCV);
+    GV *gv = gv_fetchpv(name ? name :
+                       (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"),
+                       GV_ADDMULTI, SVt_PVCV);
     register CV *cv;
 
     if ((cv = (name ? GvCV(gv) : Nullcv))) {
@@ -5471,8 +5427,8 @@ Perl_newAVREF(pTHX_ OP *o)
        return o;
     }
     else if ((o->op_type == OP_RV2AV || o->op_type == OP_PADAV)
-               && ckWARN(WARN_DEPRECATED)) {
-       Perl_warner(aTHX_ WARN_DEPRECATED,
+               && ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) {
+       Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
                "Using an array as a reference is deprecated");
     }
     return newUNOP(OP_RV2AV, 0, scalar(o));
@@ -5495,8 +5451,8 @@ Perl_newHVREF(pTHX_ OP *o)
        return o;
     }
     else if ((o->op_type == OP_RV2HV || o->op_type == OP_PADHV)
-               && ckWARN(WARN_DEPRECATED)) {
-       Perl_warner(aTHX_ WARN_DEPRECATED,
+               && ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) {
+       Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
                "Using a hash as a reference is deprecated");
     }
     return newUNOP(OP_RV2HV, 0, scalar(o));
@@ -5957,8 +5913,8 @@ Perl_ck_fun(pTHX_ OP *o)
                    char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
                    OP *newop = newAVREF(newGVOP(OP_GV, 0,
                        gv_fetchpv(name, TRUE, SVt_PVAV) ));
-                   if (ckWARN(WARN_DEPRECATED))
-                       Perl_warner(aTHX_ WARN_DEPRECATED,
+                   if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
+                       Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
                            "Array @%s missing the @ in argument %"IVdf" of %s()",
                            name, (IV)numargs, PL_op_desc[type]);
                    op_free(kid);
@@ -5977,8 +5933,8 @@ Perl_ck_fun(pTHX_ OP *o)
                    char *name = SvPVx(((SVOP*)kid)->op_sv, n_a);
                    OP *newop = newHVREF(newGVOP(OP_GV, 0,
                        gv_fetchpv(name, TRUE, SVt_PVHV) ));
-                   if (ckWARN(WARN_DEPRECATED))
-                       Perl_warner(aTHX_ WARN_DEPRECATED,
+                   if (ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
+                       Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
                            "Hash %%%s missing the %% in argument %"IVdf" of %s()",
                            name, (IV)numargs, PL_op_desc[type]);
                    op_free(kid);
@@ -6235,7 +6191,7 @@ Perl_ck_lfun(pTHX_ OP *o)
 OP *
 Perl_ck_defined(pTHX_ OP *o)           /* 19990527 MJD */
 {
-    if ((o->op_flags & OPf_KIDS) && ckWARN(WARN_DEPRECATED)) {
+    if ((o->op_flags & OPf_KIDS) && ckWARN2(WARN_DEPRECATED, WARN_SYNTAX)) {
        switch (cUNOPo->op_first->op_type) {
        case OP_RV2AV:
            /* This is needed for
@@ -6245,9 +6201,9 @@ Perl_ck_defined(pTHX_ OP *o)              /* 19990527 MJD */
            break;                      /* Globals via GV can be undef */
        case OP_PADAV:
        case OP_AASSIGN:                /* Is this a good idea? */
-           Perl_warner(aTHX_ WARN_DEPRECATED,
+           Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
                        "defined(@array) is deprecated");
-           Perl_warner(aTHX_ WARN_DEPRECATED,
+           Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
                        "\t(Maybe you should just omit the defined()?)\n");
        break;
        case OP_RV2HV:
@@ -6257,9 +6213,9 @@ Perl_ck_defined(pTHX_ OP *o)              /* 19990527 MJD */
               */
            break;                      /* Globals via GV can be undef */
        case OP_PADHV:
-           Perl_warner(aTHX_ WARN_DEPRECATED,
+           Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
                        "defined(%%hash) is deprecated");
-           Perl_warner(aTHX_ WARN_DEPRECATED,
+           Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
                        "\t(Maybe you should just omit the defined()?)\n");
            break;
        default: