>>> On Wed, Jun 30, 2010 at 02:49, Tim Bunce <tim.bu...@pobox.com> wrote:
>>> > I suggest the code shift items off the main array, like perl does,
>>> > but also push those items onto a new temp array.

Find attached a patch that does the above (perhaps naively), passes a
make test and fixes the reported problems for me.
diff --git a/src/modules/perl/modperl_util.c b/src/modules/perl/modperl_util.c
index ce95466..7a74be0 100644
--- a/src/modules/perl/modperl_util.c
+++ b/src/modules/perl/modperl_util.c
@@ -467,19 +467,22 @@ void modperl_perl_do_sprintf(pTHX_ SV *sv, I32 len, SV **sarg)
 
 void modperl_perl_call_list(pTHX_ AV *subs, const char *name)
 {
-    I32 i, oldscope = PL_scopestack_ix;
-    SV **ary = AvARRAY(subs);
+    I32 oldscope = PL_scopestack_ix;
+    AV *tmpav = newAV();
+
+    av_extend(tmpav, AvFILLp(subs));
 
     MP_TRACE_g(MP_FUNC, "pid %lu" MP_TRACEf_TID MP_TRACEf_PERLID
                " running %d %s subs",
                (unsigned long)getpid(), MP_TRACEv_TID_ MP_TRACEv_PERLID_
                AvFILLp(subs)+1, name);
 
-    for (i=0; i<=AvFILLp(subs); i++) {
-        CV *cv = (CV*)ary[i];
+    while (av_len(subs) >= 0) {
+        CV *cv = (CV*)av_shift(subs);
         SV *atsv = ERRSV;
 
         PUSHMARK(PL_stack_sp);
+        av_push(tmpav, (SV*)cv);
         call_sv((SV*)cv, G_EVAL|G_DISCARD);
 
         if (SvCUR(atsv)) {
@@ -491,6 +494,11 @@ void modperl_perl_call_list(pTHX_ AV *subs, const char *name)
             Perl_croak(aTHX_ "%s", SvPVX(atsv));
         }
     }
+
+    while (av_len(tmpav) >= 0) {
+        av_push(subs, av_shift(tmpav));
+    }
+    sv_free((SV*)tmpav);
 }
 
 void modperl_perl_exit(pTHX_ int status)

Reply via email to