summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--av.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/av.c b/av.c
index 777651d2fb..e5f6dc8d7a 100644
--- a/av.c
+++ b/av.c
@@ -554,6 +554,7 @@ Perl_av_unshift(pTHX_ register AV *av, register I32 num)
register I32 i;
register SV **ary;
MAGIC* mg;
+ I32 slide;
if (!av || num <= 0)
return;
@@ -591,6 +592,9 @@ Perl_av_unshift(pTHX_ register AV *av, register I32 num)
}
if (num) {
i = AvFILLp(av);
+ /* Create extra elements */
+ slide = i > 0 ? i : 0;
+ num += slide;
av_extend(av, i + num);
AvFILLp(av) += num;
ary = AvARRAY(av);
@@ -598,6 +602,10 @@ Perl_av_unshift(pTHX_ register AV *av, register I32 num)
do {
ary[--num] = &PL_sv_undef;
} while (num);
+ /* Make extra elements into a buffer */
+ AvMAX(av) -= slide;
+ AvFILLp(av) -= slide;
+ SvPVX(av) = (char*)(AvARRAY(av) + slide);
}
}