turbidity in av.[ch]
[p5sagit/p5-mst-13.2.git] / pp.c
diff --git a/pp.c b/pp.c
index 5b6af5a..711ba29 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -98,7 +98,13 @@ PP(pp_rv2gv)
     if (SvROK(sv)) {
       wasref:
        sv = SvRV(sv);
-       if (SvTYPE(sv) != SVt_PVGV)
+       if (SvTYPE(sv) == SVt_PVIO) {
+           GV *gv = (GV*) sv_newmortal();
+           gv_init(gv, 0, "", 0, 0);
+           GvIOp(gv) = (IO *)sv;
+           SvREFCNT_inc(sv);
+           sv = (SV*) gv;
+       } else if (SvTYPE(sv) != SVt_PVGV)
            DIE("Not a GLOB reference");
     }
     else {
@@ -570,7 +576,7 @@ PP(pp_predec)
 {
     dSP;
     if (SvIOK(TOPs)) {
-       if (SvIVX(TOPs) == PERL_LONG_MIN) {
+       if (SvIVX(TOPs) == IV_MIN) {
            sv_setnv(TOPs, (double)SvIVX(TOPs) - 1.0);
        }
        else {
@@ -589,7 +595,7 @@ PP(pp_postinc)
     dSP; dTARGET;
     sv_setsv(TARG, TOPs);
     if (SvIOK(TOPs)) {
-       if (SvIVX(TOPs) == PERL_LONG_MAX) {
+       if (SvIVX(TOPs) == IV_MAX) {
            sv_setnv(TOPs, (double)SvIVX(TOPs) + 1.0);
        }
        else {
@@ -611,7 +617,7 @@ PP(pp_postdec)
     dSP; dTARGET;
     sv_setsv(TARG, TOPs);
     if (SvIOK(TOPs)) {
-       if (SvIVX(TOPs) == PERL_LONG_MIN) {
+       if (SvIVX(TOPs) == IV_MIN) {
            sv_setnv(TOPs, (double)SvIVX(TOPs) - 1.0);
        }
        else {
@@ -1440,8 +1446,17 @@ PP(pp_substr)
            rem = len;
        sv_setpvn(TARG, tmps, rem);
        if (lvalue) {                   /* it's an lvalue! */
-           if (!SvGMAGICAL(sv))
-               (void)SvPOK_only(sv);
+           if (!SvGMAGICAL(sv)) {
+               if (SvROK(sv)) {
+                   SvPV_force(sv,na);
+                   if (dowarn)
+                       warn("Attempt to use reference as lvalue in substr");
+               }
+               if (SvOK(sv))           /* is it defined ? */
+                   (void)SvPOK_only(sv);
+               else
+                   sv_setpvn(sv,"",0); /* avoid lexical reincarnation */
+           }
            if (SvTYPE(TARG) < SVt_PVLV) {
                sv_upgrade(TARG, SVt_PVLV);
                sv_magic(TARG, Nullsv, 'x', Nullch, 0);
@@ -3515,7 +3530,7 @@ PP(pp_split)
        iters++;
     }
     else if (!origlimit) {
-       while (iters > 0 && SvCUR(TOPs) == 0)
+       while (iters > 0 && (!TOPs || !SvANY(TOPs) || SvCUR(TOPs) == 0))
            iters--, SP--;
     }
     if (realarray) {