assert() that SvPV_set() isn't used on arrays.
Nicholas Clark [Mon, 6 Nov 2006 22:21:05 +0000 (22:21 +0000)]
p4raw-id: //depot/perl@29221

av.c
cop.h
mathoms.c
pp.c
pp_ctl.c
pp_hot.c
pp_sort.c
sv.c
sv.h

diff --git a/av.c b/av.c
index e4ab13a..22eb671 100644 (file)
--- a/av.c
+++ b/av.c
@@ -95,7 +95,7 @@ Perl_av_extend(pTHX_ AV *av, I32 key)
            tmp = AvARRAY(av) - AvALLOC(av);
            Move(AvARRAY(av), AvALLOC(av), AvFILLp(av)+1, SV*);
            AvMAX(av) += tmp;
-           SvPV_set(av, (char*)AvALLOC(av));
+           AvARRAY(av) = AvALLOC(av);
            if (AvREAL(av)) {
                while (tmp)
                    ary[--tmp] = &PL_sv_undef;
@@ -171,7 +171,7 @@ Perl_av_extend(pTHX_ AV *av, I32 key)
                    ary[--tmp] = &PL_sv_undef;
            }
            
-           SvPV_set(av, (char*)AvALLOC(av));
+           AvARRAY(av) = AvALLOC(av);
            AvMAX(av) = newmax;
        }
     }
@@ -367,7 +367,7 @@ Perl_newAV(pTHX)
     sv_upgrade((SV *)av, SVt_PVAV);
     /* sv_upgrade does AvREAL_only()  */
     AvALLOC(av) = 0;
-    SvPV_set(av, NULL);
+    AvARRAY(av) = NULL;
     AvMAX(av) = AvFILLp(av) = -1;
     return av;
 }
@@ -394,7 +394,7 @@ Perl_av_make(pTHX_ register I32 size, register SV **strp)
         register I32 i;
        Newx(ary,size,SV*);
        AvALLOC(av) = ary;
-       SvPV_set(av, (char*)ary);
+       AvARRAY(av) = ary;
        AvFILLp(av) = AvMAX(av) = size - 1;
        for (i = 0; i < size; i++) {
            assert (*strp);
@@ -452,7 +452,7 @@ Perl_av_clear(pTHX_ register AV *av)
     extra = AvARRAY(av) - AvALLOC(av);
     if (extra) {
        AvMAX(av) += extra;
-       SvPV_set(av, (char*)AvALLOC(av));
+       AvARRAY(av) = AvALLOC(av);
     }
     AvFILLp(av) = -1;
 
@@ -482,7 +482,7 @@ Perl_av_undef(pTHX_ register AV *av)
     }
     Safefree(AvALLOC(av));
     AvALLOC(av) = NULL;
-    SvPV_set(av, NULL);
+    AvARRAY(av) = NULL;
     AvMAX(av) = AvFILLp(av) = -1;
 }
 
@@ -618,7 +618,7 @@ Perl_av_unshift(pTHX_ register AV *av, register I32 num)
     
        AvMAX(av) += i;
        AvFILLp(av) += i;
-       SvPV_set(av, (char*)(AvARRAY(av) - i));
+       AvARRAY(av) = AvARRAY(av) - i;
     }
     if (num) {
        register SV **ary;
@@ -637,7 +637,7 @@ Perl_av_unshift(pTHX_ register AV *av, register I32 num)
        /* Make extra elements into a buffer */
        AvMAX(av) -= slide;
        AvFILLp(av) -= slide;
-       SvPV_set(av, (char*)(AvARRAY(av) + slide));
+       AvARRAY(av) = AvARRAY(av) + slide;
     }
 }
 
@@ -681,7 +681,7 @@ Perl_av_shift(pTHX_ register AV *av)
     retval = *AvARRAY(av);
     if (AvREAL(av))
        *AvARRAY(av) = &PL_sv_undef;
-    SvPV_set(av, (char*)(AvARRAY(av) + 1));
+    AvARRAY(av) = AvARRAY(av) + 1;
     AvMAX(av)--;
     AvFILLp(av)--;
     if (SvSMAGICAL(av))
diff --git a/cop.h b/cop.h
index e9d786f..d75d2f1 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -320,7 +320,7 @@ struct block_sub {
 #define CLEAR_ARGARRAY(ary) \
     STMT_START {                                                       \
        AvMAX(ary) += AvARRAY(ary) - AvALLOC(ary);                      \
-       SvPV_set(ary, (char*)AvALLOC(ary));                             \
+       AvARRAY(ary) = AvALLOC(ary);                                    \
        AvFILLp(ary) = -1;                                              \
     } STMT_END
 
index d15aec9..79a3c31 100644 (file)
--- a/mathoms.c
+++ b/mathoms.c
@@ -554,7 +554,7 @@ Perl_av_fake(pTHX_ register I32 size, register SV **strp)
     AvALLOC(av) = ary;
     Copy(strp,ary,size,SV*);
     AvREIFY_only(av);
-    SvPV_set(av, (char*)ary);
+    AvARRAY(av) = ary;
     AvFILLp(av) = size - 1;
     AvMAX(av) = size - 1;
     while (size--) {
diff --git a/pp.c b/pp.c
index 229f703..43e400b 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -4276,7 +4276,7 @@ PP(pp_splice)
                    *dst-- = *src--;
            }
            dst = AvARRAY(ary);
-           SvPV_set(ary, (char*)(AvARRAY(ary) - diff)); /* diff is negative */
+           AvARRAY(ary) = AvARRAY(ary) - diff; /* diff is negative */
            AvMAX(ary) += diff;
        }
        else {
@@ -4312,7 +4312,7 @@ PP(pp_splice)
                    dst = src - diff;
                    Move(src, dst, offset, SV*);
                }
-               SvPV_set(ary, (char*)(AvARRAY(ary) - diff));/* diff is positive */
+               AvARRAY(ary) = AvARRAY(ary) - diff;/* diff is positive */
                AvMAX(ary) += diff;
                AvFILLp(ary) += diff;
            }
index 7a8da0d..6bc8e78 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2450,13 +2450,13 @@ PP(pp_goto)
                        SV **ary = AvALLOC(av);
                        if (AvARRAY(av) != ary) {
                            AvMAX(av) += AvARRAY(av) - AvALLOC(av);
-                           SvPV_set(av, (char*)ary);
+                           AvARRAY(av) = ary;
                        }
                        if (items >= AvMAX(av) + 1) {
                            AvMAX(av) = items - 1;
                            Renew(ary,items+1,SV*);
                            AvALLOC(av) = ary;
-                           SvPV_set(av, (char*)ary);
+                           AvARRAY(av) = ary;
                        }
                    }
                    ++mark;
index d1873b2..d2e8e87 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2856,13 +2856,13 @@ try_autoload:
                SV **ary = AvALLOC(av);
                if (AvARRAY(av) != ary) {
                    AvMAX(av) += AvARRAY(av) - AvALLOC(av);
-                   SvPV_set(av, (char*)ary);
+                   AvARRAY(av) = ary;
                }
                if (items > AvMAX(av) + 1) {
                    AvMAX(av) = items - 1;
                    Renew(ary,items,SV*);
                    AvALLOC(av) = ary;
-                   SvPV_set(av, (char*)ary);
+                   AvARRAY(av) = ary;
                }
            }
            Copy(MARK,AvARRAY(av),items,SV*);
index dfcdac4..6899ff4 100644 (file)
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1770,12 +1770,12 @@ S_sortcv_stacked(pTHX_ SV *a, SV *b)
        SV** ary = AvALLOC(av);
        if (AvARRAY(av) != ary) {
            AvMAX(av) += AvARRAY(av) - AvALLOC(av);
-           SvPV_set(av, (char*)ary);
+           AvARRAY(av) = ary;
        }
        if (AvMAX(av) < 1) {
            AvMAX(av) = 1;
            Renew(ary,2,SV*);
-           SvPV_set(av, (char*)ary);
+           AvARRAY(av) = ary;
        }
     }
     AvFILLp(av) = 1;
diff --git a/sv.c b/sv.c
index 8aaa792..66d29e4 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -10060,7 +10060,7 @@ Perl_sv_dup(pTHX_ const SV *sstr, CLONE_PARAMS* param)
                    src_ary = AvARRAY((AV*)sstr);
                    Newxz(dst_ary, AvMAX((AV*)sstr)+1, SV*);
                    ptr_table_store(PL_ptr_table, src_ary, dst_ary);
-                   SvPV_set(dstr, (char*)dst_ary);
+                   AvARRAY((AV*)dstr) = dst_ary;
                    AvALLOC((AV*)dstr) = dst_ary;
                    if (AvREAL((AV*)sstr)) {
                        while (items-- > 0)
@@ -10076,7 +10076,7 @@ Perl_sv_dup(pTHX_ const SV *sstr, CLONE_PARAMS* param)
                    }
                }
                else {
-                   SvPV_set(dstr, NULL);
+                   AvARRAY((AV*)dstr)  = NULL;
                    AvALLOC((AV*)dstr)  = (SV**)NULL;
                }
                break;
diff --git a/sv.h b/sv.h
index 0937fbd..eabc2bf 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -1239,6 +1239,7 @@ the scalar's value cannot change unless written to.
                (((XPVNV*)SvANY(sv))->xnv_u.xnv_nv = (val)); } STMT_END
 #define SvPV_set(sv, val) \
        STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
+               assert(SvTYPE(sv) != SVt_PVAV);         \
                assert(SvTYPE(sv) != SVt_PVHV);         \
                assert(!isGV_with_GP(sv));              \
                ((sv)->sv_u.svu_pv = (val)); } STMT_END