d_getservbyname_r undef up to at least OpenBSD 3.5
[p5sagit/p5-mst-13.2.git] / av.c
diff --git a/av.c b/av.c
index 8fb22d3..9cae023 100644 (file)
--- a/av.c
+++ b/av.c
@@ -114,6 +114,7 @@ Perl_av_extend(pTHX_ AV *av, I32 key)
 #endif 
                newmax = key + AvMAX(av) / 5;
              resize:
+               MEM_WRAP_CHECK_1(newmax+1, SV*, "panic: array extend");
 #if defined(STRANGE_MALLOC) || defined(MYMALLOC)
                Renew(AvALLOC(av),newmax+1, SV*);
 #else
@@ -148,6 +149,7 @@ Perl_av_extend(pTHX_ AV *av, I32 key)
            }
            else {
                newmax = key < 3 ? 3 : key;
+               MEM_WRAP_CHECK_1(newmax+1, SV*, "panic: array extend");
                New(2,AvALLOC(av), newmax+1, SV*);
                ary = AvALLOC(av) + 1;
                tmp = newmax;
@@ -209,9 +211,11 @@ Perl_av_fetch(pTHX_ register AV *av, I32 key, I32 lval)
             }
 
             sv = sv_newmortal();
-            mg_copy((SV*)av, sv, 0, key);
-            PL_av_fetch_sv = sv;
-            return &PL_av_fetch_sv;
+           sv_upgrade(sv, SVt_PVLV);
+           mg_copy((SV*)av, sv, 0, key);
+           LvTYPE(sv) = 't';
+           LvTARG(sv) = sv; /* fake (SV**) */
+           return &(LvTARG(sv));
         }
     }
 
@@ -778,7 +782,8 @@ Perl_av_fill(pTHX_ register AV *av, I32 fill)
 =for apidoc av_delete
 
 Deletes the element indexed by C<key> from the array.  Returns the
-deleted element. C<flags> is currently ignored.
+deleted element. If C<flags> equals C<G_DISCARD>, the element is freed
+and null is returned.
 
 =cut
 */
@@ -836,6 +841,8 @@ Perl_av_delete(pTHX_ AV *av, I32 key, I32 flags)
     if (key > AvFILLp(av))
        return Nullsv;
     else {
+       if (!AvREAL(av) && AvREIFY(av))
+           av_reify(av);
        sv = AvARRAY(av)[key];
        if (key == AvFILLp(av)) {
            AvARRAY(av)[key] = &PL_sv_undef;