X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=av.c;h=a4d6ea2d06a056a28e30369e52e878d6849cb5d6;hb=6f7a7d3eeb6b7da414c3496d3eb5a7c4f5127201;hp=35748a69244dea44b74eeb6e5e8f074c723b322e;hpb=f1f66076265cc2bac3adabd54c01b0dea28ca3f0;p=p5sagit%2Fp5-mst-13.2.git diff --git a/av.c b/av.c index 35748a6..a4d6ea2 100644 --- a/av.c +++ b/av.c @@ -9,8 +9,10 @@ */ /* - * "...for the Entwives desired order, and plenty, and peace (by which they - * meant that things should remain where they had set them)." --Treebeard + * '...for the Entwives desired order, and plenty, and peace (by which they + * meant that things should remain where they had set them).' --Treebeard + * + * [p.476 of _The Lord of the Rings_, III/iv: "Treebeard"] */ /* @@ -33,8 +35,8 @@ Perl_av_reify(pTHX_ AV *av) if (AvREAL(av)) return; #ifdef DEBUGGING - if (SvTIED_mg((const SV *)av, PERL_MAGIC_tied) && ckWARN_d(WARN_DEBUGGING)) - Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "av_reify called on tied array"); + if (SvTIED_mg((const SV *)av, PERL_MAGIC_tied)) + Perl_ck_warner_d(aTHX_ packWARN(WARN_DEBUGGING), "av_reify called on tied array"); #endif key = AvMAX(av) + 1; while (key > AvFILLp(av) + 1) @@ -402,8 +404,14 @@ Perl_av_make(pTHX_ register I32 size, register SV **strp) AvFILLp(av) = AvMAX(av) = size - 1; for (i = 0; i < size; i++) { assert (*strp); + + /* Don't let sv_setsv swipe, since our source array might + have multiple references to the same temp scalar (e.g. + from a list slice) */ + ary[i] = newSV(0); - sv_setsv(ary[i], *strp); + sv_setsv_flags(ary[i], *strp, + SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL); strp++; } } @@ -429,8 +437,8 @@ Perl_av_clear(pTHX_ register AV *av) assert(SvTYPE(av) == SVt_PVAV); #ifdef DEBUGGING - if (SvREFCNT(av) == 0 && ckWARN_d(WARN_DEBUGGING)) { - Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "Attempt to clear deleted array"); + if (SvREFCNT(av) == 0) { + Perl_ck_warner_d(aTHX_ packWARN(WARN_DEBUGGING), "Attempt to clear deleted array"); } #endif @@ -525,7 +533,8 @@ Perl_av_create_and_push(pTHX_ AV **const avp, SV *const val) =for apidoc av_push Pushes an SV onto the end of the array. The array will grow automatically -to accommodate the addition. +to accommodate the addition. Like C, this takes ownership of one +reference count. =cut */