Avoid redefinition warning for MinGW
[p5sagit/p5-mst-13.2.git] / op.c
diff --git a/op.c b/op.c
index a134164..b062678 100644 (file)
--- a/op.c
+++ b/op.c
@@ -158,13 +158,12 @@ Perl_Slab_Free(pTHX_ void *op)
 
 #define RETURN_UNLIMITED_NUMBER (PERL_INT_MAX / 2)
 
-STATIC char*
+STATIC const char*
 S_gv_ename(pTHX_ GV *gv)
 {
-    STRLEN n_a;
     SV* tmpsv = sv_newmortal();
     gv_efullname3(tmpsv, gv, Nullch);
-    return SvPV(tmpsv,n_a);
+    return SvPV_nolen_const(tmpsv);
 }
 
 STATIC OP *
@@ -1596,14 +1595,7 @@ S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp)
                                    dup_attrlist(attrs)));
 
     /* Fake up a method call to import */
-    meth = newSVpvn("import", 6);
-    SvUPGRADE(meth, SVt_PVIV);
-    (void)SvIOK_on(meth);
-    {
-       U32 hash;
-       PERL_HASH(hash, SvPVX_const(meth), SvCUR(meth));
-       SvUV_set(meth, hash);
-    }
+    meth = newSVpvn_share("import", 6, 0);
     imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL|OPf_WANT_VOID,
                   append_elem(OP_LIST,
                               prepend_elem(OP_LIST, pack, list(arg)),
@@ -2492,7 +2484,7 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
            t = uvuni_to_utf8_flags(tmpbuf, 0x7fffffff,
                                    UNICODE_ALLOW_SUPER);
            sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf);
-           t = (U8*)SvPVX(transv);
+           t = (const U8*)SvPVX_const(transv);
            tlen = SvCUR(transv);
            tend = t + tlen;
            Safefree(cp);
@@ -3051,14 +3043,7 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
            pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)idop)->op_sv));
 
            /* Fake up a method call to VERSION */
-           meth = newSVpvn("VERSION",7);
-           sv_upgrade(meth, SVt_PVIV);
-           (void)SvIOK_on(meth);
-           {
-               U32 hash;
-               PERL_HASH(hash, SvPVX_const(meth), SvCUR(meth));
-               SvUV_set(meth, hash);
-           }
+           meth = newSVpvn_share("VERSION", 7, 0);
            veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
                            append_elem(OP_LIST,
                                        prepend_elem(OP_LIST, pack, list(version)),
@@ -3079,14 +3064,8 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
        pack = newSVOP(OP_CONST, 0, newSVsv(((SVOP*)idop)->op_sv));
 
        /* Fake up a method call to import/unimport */
-       meth = aver ? newSVpvn("import",6) : newSVpvn("unimport", 8);
-       SvUPGRADE(meth, SVt_PVIV);
-       (void)SvIOK_on(meth);
-       {
-           U32 hash;
-           PERL_HASH(hash, SvPVX_const(meth), SvCUR(meth));
-           SvUV_set(meth, hash);
-       }
+       meth = aver
+           ? newSVpvn_share("import",6, 0) : newSVpvn_share("unimport", 8, 0);
        imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
                       append_elem(OP_LIST,
                                   prepend_elem(OP_LIST, pack, list(arg)),
@@ -3095,7 +3074,7 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
 
     /* Fake up the BEGIN {}, which does its thing immediately. */
     newATTRSUB(floor,
-       newSVOP(OP_CONST, 0, newSVpvn("BEGIN", 5)),
+       newSVOP(OP_CONST, 0, newSVpvn_share("BEGIN", 5, 0)),
        Nullop,
        Nullop,
        append_elem(OP_LINESEQ,
@@ -3295,14 +3274,15 @@ Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
        OP *curop;
 
        PL_modcount = 0;
-       PL_eval_start = right;  /* Grandfathering $[ assignment here.  Bletch.*/
+       /* Grandfathering $[ assignment here.  Bletch.*/
+       /* Only simple assignments like C<< ($[) = 1 >> are allowed */
+       PL_eval_start = (left->op_type == OP_CONST) ? right : 0;
        left = mod(left, OP_AASSIGN);
        if (PL_eval_start)
            PL_eval_start = 0;
-       else {
-           op_free(left);
-           op_free(right);
-           return Nullop;
+       else if (left->op_type == OP_CONST) {
+           /* Result of assignment is always 1 (or we'd be dead already) */
+           return newSVOP(OP_CONST, 0, newSViv(1));
        }
        /* optimise C<my @x = ()> to C<my @x>, and likewise for hashes */
        if ((left->op_type == OP_PADAV || left->op_type == OP_PADHV)
@@ -3439,8 +3419,7 @@ Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
        if (PL_eval_start)
            PL_eval_start = 0;
        else {
-           op_free(o);
-           return Nullop;
+           o = newSVOP(OP_CONST, 0, newSViv(PL_compiling.cop_arybase));
        }
     }
     return o;
@@ -4017,7 +3996,6 @@ OP*
 Perl_newLOOPEX(pTHX_ I32 type, OP *label)
 {
     OP *o;
-    STRLEN n_a;
 
     if (type != OP_GOTO || label->op_type == OP_CONST) {
        /* "last()" means "last" */
@@ -4025,7 +4003,7 @@ Perl_newLOOPEX(pTHX_ I32 type, OP *label)
            o = newOP(type, OPf_SPECIAL);
        else {
            o = newPVOP(type, 0, savepv(label->op_type == OP_CONST
-                                       ? SvPVx_const(((SVOP*)label)->op_sv, n_a)
+                                       ? SvPVx_nolen_const(((SVOP*)label)->op_sv)
                                        : ""));
        }
        op_free(label);
@@ -4248,15 +4226,15 @@ CV *
 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
 {
     dVAR;
-    STRLEN n_a;
     const char *aname;
     GV *gv;
     const char *ps;
     STRLEN ps_len;
     register CV *cv=0;
     SV *const_sv;
+    I32 gv_fetch_flags;
 
-    const char * const name = o ? SvPVx_const(cSVOPo->op_sv, n_a) : Nullch;
+    const char * const name = o ? SvPVx_nolen_const(cSVOPo->op_sv) : Nullch;
 
     if (proto) {
        assert(proto->op_type == OP_CONST);
@@ -4274,13 +4252,13 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
     }
     else
        aname = Nullch;
-    gv = name ? gv_fetchsv(cSVOPo->op_sv,
-                          GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
-                          SVt_PVCV)
+
+    gv_fetch_flags = (block || attrs || (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS))
+       ? GV_ADDMULTI : GV_ADDMULTI | GV_NOINIT;
+    gv = name ? gv_fetchsv(cSVOPo->op_sv, gv_fetch_flags, SVt_PVCV)
        : gv_fetchpv(aname ? aname
                     : (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"),
-                    GV_ADDMULTI | ((block || attrs) ? 0 : GV_NOINIT),
-                    SVt_PVCV);
+                    gv_fetch_flags, SVt_PVCV);
 
     if (o)
        SAVEFREEOP(o);
@@ -4317,7 +4295,7 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
     }
 #endif
 
-    if (!block || !ps || *ps || attrs)
+    if (!block || !ps || *ps || attrs || (CvFLAGS(PL_compcv) & CVf_BUILTIN_ATTRS))
        const_sv = Nullsv;
     else
        const_sv = op_const_sv(block, Nullcv);
@@ -5510,7 +5488,7 @@ Perl_ck_fun(pTHX_ OP *o)
                                           
                                      }
                                      if (tmpstr) {
-                                          name = SvPV(tmpstr, len);
+                                          name = SvPV_const(tmpstr, len);
                                           sv_2mortal(tmpstr);
                                      }
                                 }
@@ -6263,7 +6241,6 @@ Perl_ck_subr(pTHX_ OP *o)
     I32 arg = 0;
     I32 contextclass = 0;
     char *e = 0;
-    STRLEN n_a;
     bool delete_op = 0;
 
     o->op_private |= OPpENTERSUB_HASTARG;
@@ -6281,7 +6258,7 @@ Perl_ck_subr(pTHX_ OP *o)
            else {
                if (SvPOK(cv)) {
                    namegv = CvANON(cv) ? gv : CvGV(cv);
-                   proto = SvPV((SV*)cv, n_a);
+                   proto = SvPV_nolen((SV*)cv);
                }
                if (CvASSERTION(cv)) {
                    if (PL_hints & HINT_ASSERTING) {
@@ -6785,7 +6762,7 @@ Perl_peep(pTHX_ register OP *o)
             SV *lexname;
            GV **fields;
            SV **svp, *sv;
-           char *key = NULL;
+           const char *key = NULL;
            STRLEN keylen;
 
            o->op_opt = 1;
@@ -6796,7 +6773,7 @@ Perl_peep(pTHX_ register OP *o)
            /* Make the CONST have a shared SV */
            svp = cSVOPx_svp(((BINOP*)o)->op_last);
            if ((!SvFAKE(sv = *svp) || !SvREADONLY(sv)) && !IS_PADCONST(sv)) {
-               key = SvPV(sv, keylen);
+               key = SvPV_const(sv, keylen);
                lexname = newSVpvn_share(key,
                                         SvUTF8(sv) ? -(I32)keylen : keylen,
                                         0);
@@ -6816,13 +6793,13 @@ Perl_peep(pTHX_ register OP *o)
            fields = (GV**)hv_fetch(SvSTASH(lexname), "FIELDS", 6, FALSE);
            if (!fields || !GvHV(*fields))
                break;
-           key = SvPV(*svp, keylen);
+           key = SvPV_const(*svp, keylen);
            if (!hv_fetch(GvHV(*fields), key,
                        SvUTF8(*svp) ? -(I32)keylen : keylen, FALSE))
            {
                Perl_croak(aTHX_ "No such class field \"%s\" " 
                           "in variable %s of type %s", 
-                     key, SvPV_nolen(lexname), HvNAME_get(SvSTASH(lexname)));
+                     key, SvPV_nolen_const(lexname), HvNAME_get(SvSTASH(lexname)));
            }
 
             break;
@@ -6833,7 +6810,7 @@ Perl_peep(pTHX_ register OP *o)
            SV *lexname;
            GV **fields;
            SV **svp;
-           char *key;
+           const char *key;
            STRLEN keylen;
            SVOP *first_key_op, *key_op;
 
@@ -6873,7 +6850,7 @@ Perl_peep(pTHX_ register OP *o)
                if (key_op->op_type != OP_CONST)
                    continue;
                svp = cSVOPx_svp(key_op);
-               key = SvPV(*svp, keylen);
+               key = SvPV_const(*svp, keylen);
                if (!hv_fetch(GvHV(*fields), key, 
                            SvUTF8(*svp) ? -(I32)keylen : keylen, FALSE))
                {