}
else {
if (AvALLOC(av)) {
+#ifndef STRANGE_MALLOC
U32 bytes;
+#endif
newmax = key + AvMAX(av) / 5;
resize:
newmax = tmp - 1;
New(2,ary, newmax+1, SV*);
Copy(AvALLOC(av), ary, AvMAX(av)+1, SV*);
- if (AvMAX(av) > 64 && !AvREUSED(av))
- sv_add_arena((char*)AvALLOC(av), AvMAX(av) * sizeof(SV*),0);
+ if (AvMAX(av) > 64 && !nice_chunk) {
+ nice_chunk = (char*)AvALLOC(av);
+ nice_chunk_size = (AvMAX(av) + 1) * sizeof(SV*);
+ }
else
Safefree(AvALLOC(av));
AvALLOC(av) = ary;
#endif
ary = AvALLOC(av) + AvMAX(av) + 1;
tmp = newmax - AvMAX(av);
- if (av == stack) { /* Oops, grew stack (via av_store()?) */
+ if (av == curstack) { /* Oops, grew stack (via av_store()?) */
stack_sp = AvALLOC(av) + (stack_sp - stack_base);
stack_base = AvALLOC(av);
stack_max = stack_base + newmax;
return av_store(av,key,sv);
}
if (AvARRAY(av)[key] == &sv_undef) {
+ emptyness:
if (lval) {
sv = NEWSV(6,0);
return av_store(av,key,sv);
}
return 0;
}
+ else if (AvREIFY(av)
+ && (!AvARRAY(av)[key] /* eg. @_ could have freed elts */
+ || SvTYPE(AvARRAY(av)[key]) == SVTYPEMASK)) {
+ AvARRAY(av)[key] = &sv_undef; /* 1/2 reify */
+ goto emptyness;
+ }
return &AvARRAY(av)[key];
}
if (!av)
return 0;
+ if (!val)
+ val = &sv_undef;
if (SvRMAGICAL(av)) {
if (mg_find((SV*)av,'P')) {
- mg_copy((SV*)av, val, 0, key);
+ if (val != &sv_undef)
+ mg_copy((SV*)av, val, 0, key);
return 0;
}
}
if (key < 0)
return 0;
}
- if (!val)
- val = &sv_undef;
-
+ if (SvREADONLY(av) && key >= AvFILL(av))
+ croak(no_modify);
if (key > AvMAX(av))
av_extend(av,key);
- if (AvREIFY(av))
+ if (!AvREAL(av) && AvREIFY(av))
av_reify(av);
-
ary = AvARRAY(av);
if (AvFILL(av) < key) {
if (!AvREAL(av)) {
- if (av == stack && key > stack_sp - stack_base)
+ if (av == curstack && key > stack_sp - stack_base)
stack_sp = stack_base + key; /* XPUSH in disguise */
do
ary[++AvFILL(av)] = &sv_undef;
register I32 key;
SV** ary;
+#ifdef DEBUGGING
+ if (SvREFCNT(av) <= 0) {
+ warn("Attempt to clear deleted array");
+ }
+#endif
if (!av || AvMAX(av) < 0)
return;
/*SUPPRESS 560*/
while (key)
SvREFCNT_dec(AvARRAY(av)[--key]);
}
- if (key = AvARRAY(av) - AvALLOC(av)) {
- AvMAX(av) += key;
- SvPVX(av) = (char*)AvALLOC(av);
- }
Safefree(AvALLOC(av));
AvALLOC(av) = 0;
SvPVX(av) = 0;
AvMAX(av) = AvFILL(av) = -1;
- AvREUSED_on(av); /* Avoid leak of making SVs out of old memory again. */
if (AvARYLEN(av)) {
SvREFCNT_dec(AvARYLEN(av));
AvARYLEN(av) = 0;
if (!av || AvFILL(av) < 0)
return &sv_undef;
+ if (SvREADONLY(av))
+ croak(no_modify);
retval = AvARRAY(av)[AvFILL(av)];
AvARRAY(av)[AvFILL(av)--] = &sv_undef;
if (SvSMAGICAL(av))
if (!av || num <= 0)
return;
- if (!AvREAL(av)) {
- if (AvREIFY(av))
- av_reify(av);
- else
- croak("Can't unshift");
- }
+ if (SvREADONLY(av))
+ croak(no_modify);
+ if (!AvREAL(av) && AvREIFY(av))
+ av_reify(av);
i = AvARRAY(av) - AvALLOC(av);
if (i) {
if (i > num)
if (!av || AvFILL(av) < 0)
return &sv_undef;
+ if (SvREADONLY(av))
+ croak(no_modify);
retval = *AvARRAY(av);
if (AvREAL(av))
*AvARRAY(av) = &sv_undef;