ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl5-porters
perl5-porters
Re: (blead patch) New TRIE regex patch
by Dave Mitchell other posts by this author
Mar 2 2005 11:46AM messages near this date
Re: (blead patch) New TRIE regex patch | Re: (blead patch) New TRIE regex patch
On Wed, Mar 02, 2005 at 05:20:36PM +0100, demerphq wrote:
>  What is the difference between the two sets? In my case should I use
>  ENTER/LEAVE or SAVETMPS/FREETMPS or both sets? Anybody who understands
>  these details who felt inclined to update the pod on this would find
>  me very grateful.

There are two stacks in question, the save stack, and the tmps stack.
Creating mortals (eg sv_2mortal() or sv_newmortal()) pushes a reference to
that SV onto the tmpstack. FREETMPS frees all the items on the tmpstack
down to the current floor. SAVETMPS sets a new floor. Typically FREETMPS
is called once every statement (by pp_nextstate).

On the other hand, ENTER sets a new floor on the savestack and LEAVE
processes all the items on the savestack back down to the previous floor.
The savestack is more general than the tmpstack; a whole bunch of things
an be pushed onto the savestack, not just temporary values.  Note that
SAVETMPS actually saves the current tmpstack floor on the savestack.

So.....

If you just want to create a temporary value and are happy for it to be
freed at the next statement, just create a new mortal SV. The danger with
that is if your code gets involved in any sort of looping or recursion
within a single op, where new tmps are created each time, then the
tmpsstack will fill up with rubbish.

If you want to set a new floor on the tmpstack and make sure its freed up
earlier, then you want to do domething like:

    ENTER;		# set new floor on savestack
    SAVETMPS;		# push the current tmps floor onto the savestack;
    ...
    sv_newmortal();	# create new mortal(s)
    ...
    FREETMPS;		# free all the mortals you've created
    LEAVE;		# pop the item(s) off the savestack, causing
			# (possibly amongst other things) the old tmpstack
			# floor to be restored.

If the code should die in the middle and be trapped by eval, then the
LEAVE is called implicity.

Dave.

-- 
You live and learn (although usually you just live).
Thread:

Yitzchak Scott-Thoennes
Demerphq

Demerphq
Yitzchak Scott-Thoennes

Dave Mitchell
Demerphq
Dave Mitchell
Demerphq
Dave Mitchell

Demerphq
Demerphq
Yitzchak Scott-Thoennes
Rafael Garcia-Suarez

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved