On Jul 12, 5:42 pm, [EMAIL PROTECTED] (Muppet) wrote:
> sv_2mortal() exists to ensure that things that go onto the stack are
> cleaned up if they are not otherwise stored.
>
> As i understand it:
>
> 1.  Create a new sv with refcount 1.
> 2.  sv_2mortal() makes that refcount 0.
> 3.  Put it on the stack, no refcount change.
> 4.  call_sv(), stuff happens.  there's a die().
> 5.  somewhere, either in the die() or after, perl will free
> everything on the orphaned stack, and your temps will be cleaned up.

More or less. sv_2mortal() does not actually make the refcount 0
immediately. It makes it zero "sometime later". It's a deferred
decrement of the reference count.

So I would describe it:

1. Create a new sv with refcount 1.
2. sv_2mortal() queues up a refcount decrement for the next FREETMPS
at this level of the ENTER,SAVETMPS..FREETMPS,LEAVE stack.
3. Put it on the stack, no refcount change. (A dangerous optimization
that core Perl uses.)
4. call_sv(), stuff happens. There's a die(). call_sv() returns with
$@ (ERRSV) set to whatever you died with. Nothing happens to the
mortal SVs because anything within the call_sv() has its own
ENTER,SAVETMPS scope.
5. In your FREETMPS, the deferred refcount decrement happens and
changes the refcount from 1 to 0. The object is freed.

Reply via email to