develooper Front page | perl.perl5.porters | Postings from December 2011

questions about saving stacks

Thread Next
From:
Kamal Khatri
Date:
December 1, 2011 14:08
Subject:
questions about saving stacks
Message ID:
CAByhwiwCaKQp0nh9vX0ups832xvj+8NLSENJmbs4wdSTa=wtUQ@mail.gmail.com
Hi all,

(Sorry about the previous incomplete post.)

I was looking at techniques to save perl stacks and restore them. I have
looked at perlguts (and other docs)
and code back and forth for a while now. So far as I understand, and
looking at the implementation
of Perl_init_stacks(pTHX), perl seems to use 6 separate stacks
(PL_stack_sp, cxstack,  PL_tmps_stack,
PL_markstack, PL_scopestack, PL_savestack). I also noticed each of these
stacks have max and index
markers (with floor marker for tmp stack).

What would be the right way to save these stacks so that they could be
restored again. Currently
I am using the following techniques. However, I suspect I am not correctly
handling saving
of the Perl data types. This results in unpredictable crashes.

1. PL_stack_sp

     for(i=0; i < (PL_stack_sp - PL_stack_base); i++)
         copy using newSVsv(*(PL_stack_base + i)); however this does not
seems to work for SVt_PVCV

2.  cxstack

     for(i=0; i <= PL_curstackinfo->si_cxix ; i++)
           memcpy &cxstack[i]

3. PL_tmps_stack

     for(i=PL_tmps_floor+1; i <= PL_tmps_ix; i++)
            copy using newSVsv(PL_tmps_stack[i]); this also does not work
for SVt_PVCV

4. PL_markstack

      memcpy(dest_markstack, PL_markstack, (PL_markstack_ptr -
PL_markstack) * sizeof(I32));

5. PL_savestack

          memcpy(dest_savestack, PL_savestack, (PL_savestack_ix +  1) *
sizeof(ANY));

6. PL_scopestack

           memcpy(dest_stk_scope, PL_scopestack, (PL_scopestack_ix + 1) *
sizeof(I32));

Does the above way of saving stack make sense. Any help or pointers is
highly appreciated.

thanks,
Kamal

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About