Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: tie() weirdness

by robin (Chaplain)
on Nov 21, 2005 at 15:27 UTC ( #510457=note: print w/ replies, xml ) Need Help??

in reply to tie() weirdness

Yes, this is certainly a bug. Here is what's happening:

Update: This diagnosis is mistaken see below.

  • The way $foo++ is implemented is that the value of $foo is copied to a temporary SV (the op's targ), the original value is then incremented; and finally the top element of the stack is pointed at the targ.
  • In this example, the second time FETCH is called, the targ gets overwritten with the new value. But there's already a pointer to it on the stack.
I guess one solution would be to use a temporary mortal instead of the targ.

Comment on Re: tie() weirdness
Replies are listed 'Best First'.
Re^2: tie() weirdness
by robin (Chaplain) on Nov 21, 2005 at 15:51 UTC
    I guess one solution would be to use a temporary mortal instead of the targ

    i just tried that. It doesn't work, because the mortals get freed on the return from the FETCH routine. I should have realised that would happen.

    Ouch! I wonder how it can be fixed then?

    Update: for completeness I should point out that, although it is indeed true that mortals get freed on return from the FETCH routine, that isn't the (only) reason this doesn't fix the problem. A correct (I hope!) diagnosis and patch can be found in the node below.

Re^2: tie() weirdness
by blazar (Canon) on Nov 22, 2005 at 13:49 UTC
    Update: This diagnosis is mistaken see below.
    I read all of your posts in this thread (replying just to this one out of convenience). Since you submitted a fix yourself, you may be interested to read the replies I got after having submitted a bug report.
      Thanks for the pointer.

      Update: In case it isn't clear, Rafael was talking about my fix when he said that it's fixed in bleadperl.

      There is truth in what dave_the_m says, but the fact is that this behaviour is highly surprising, and can be fixed. It's better to make things behave sensibly than to spin elaborate explanations of why they don't. :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://510457]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2015-11-29 01:55 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls