X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=av.c;h=a4d6ea2d06a056a28e30369e52e878d6849cb5d6;hb=6f7a7d3eeb6b7da414c3496d3eb5a7c4f5127201;hp=7bd19eea5a72a71cefa0969a1cc86f528df9c753;hpb=ad64d0ecd555e97c5a216efca1ec5a96b7fd0b34;p=p5sagit%2Fp5-mst-13.2.git diff --git a/av.c b/av.c index 7bd19ee..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) @@ -134,7 +136,7 @@ Perl_av_extend(pTHX_ AV *av, I32 key) the current lazy system of only writing to it if our caller has a need for more space. NWC */ newmax = Perl_safesysmalloc_size((void*)AvALLOC(av)) / - sizeof(SV*) - 1; + sizeof(const SV *) - 1; if (key <= newmax) goto resized; @@ -145,20 +147,21 @@ Perl_av_extend(pTHX_ AV *av, I32 key) #if defined(STRANGE_MALLOC) || defined(MYMALLOC) Renew(AvALLOC(av),newmax+1, SV*); #else - bytes = (newmax + 1) * sizeof(SV*); + bytes = (newmax + 1) * sizeof(const SV *); #define MALLOC_OVERHEAD 16 itmp = MALLOC_OVERHEAD; while ((MEM_SIZE)(itmp - MALLOC_OVERHEAD) < bytes) itmp += itmp; itmp -= MALLOC_OVERHEAD; - itmp /= sizeof(SV*); + itmp /= sizeof(const SV *); assert(itmp > newmax); newmax = itmp - 1; assert(newmax >= AvMAX(av)); Newx(ary, newmax+1, SV*); Copy(AvALLOC(av), ary, AvMAX(av)+1, SV*); if (AvMAX(av) > 64) - offer_nice_chunk(AvALLOC(av), (AvMAX(av)+1) * sizeof(SV*)); + offer_nice_chunk(AvALLOC(av), + (AvMAX(av)+1) * sizeof(const SV *)); else Safefree(AvALLOC(av)); AvALLOC(av) = ary; @@ -341,7 +344,7 @@ Perl_av_store(pTHX_ register AV *av, I32 key, SV *val) } if (SvREADONLY(av) && key >= AvFILL(av)) - Perl_croak(aTHX_ PL_no_modify); + Perl_croak(aTHX_ "%s", PL_no_modify); if (!AvREAL(av) && AvREIFY(av)) av_reify(av); @@ -401,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++; } } @@ -428,13 +437,13 @@ 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 if (SvREADONLY(av)) - Perl_croak(aTHX_ PL_no_modify); + Perl_croak(aTHX_ "%s", PL_no_modify); /* Give any tie a chance to cleanup first */ if (SvRMAGICAL(av)) { @@ -524,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 */ @@ -539,7 +549,7 @@ Perl_av_push(pTHX_ register AV *av, SV *val) assert(SvTYPE(av) == SVt_PVAV); if (SvREADONLY(av)) - Perl_croak(aTHX_ PL_no_modify); + Perl_croak(aTHX_ "%s", PL_no_modify); if ((mg = SvTIED_mg((const SV *)av, PERL_MAGIC_tied))) { dSP; @@ -578,7 +588,7 @@ Perl_av_pop(pTHX_ register AV *av) assert(SvTYPE(av) == SVt_PVAV); if (SvREADONLY(av)) - Perl_croak(aTHX_ PL_no_modify); + Perl_croak(aTHX_ "%s", PL_no_modify); if ((mg = SvTIED_mg((const SV *)av, PERL_MAGIC_tied))) { dSP; PUSHSTACKi(PERLSI_MAGIC); @@ -647,7 +657,7 @@ Perl_av_unshift(pTHX_ register AV *av, register I32 num) assert(SvTYPE(av) == SVt_PVAV); if (SvREADONLY(av)) - Perl_croak(aTHX_ PL_no_modify); + Perl_croak(aTHX_ "%s", PL_no_modify); if ((mg = SvTIED_mg((const SV *)av, PERL_MAGIC_tied))) { dSP; @@ -720,7 +730,7 @@ Perl_av_shift(pTHX_ register AV *av) assert(SvTYPE(av) == SVt_PVAV); if (SvREADONLY(av)) - Perl_croak(aTHX_ PL_no_modify); + Perl_croak(aTHX_ "%s", PL_no_modify); if ((mg = SvTIED_mg((const SV *)av, PERL_MAGIC_tied))) { dSP; PUSHSTACKi(PERLSI_MAGIC); @@ -851,7 +861,7 @@ Perl_av_delete(pTHX_ AV *av, I32 key, I32 flags) assert(SvTYPE(av) == SVt_PVAV); if (SvREADONLY(av)) - Perl_croak(aTHX_ PL_no_modify); + Perl_croak(aTHX_ "%s", PL_no_modify); if (SvRMAGICAL(av)) { const MAGIC * const tied_magic