Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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.

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2023-12-03 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (20 votes). Check out past polls.

    Notices?