develooper Front page | perl.perl5.porters | Postings from July 2016

Re: Confused by eval behavior

Thread Previous | Thread Next
From:
Aristotle Pagaltzis
Date:
July 1, 2016 15:07
Subject:
Re: Confused by eval behavior
Message ID:
20160701150659.GA25735@plasmasturm.org
* Dave Mitchell <davem@iabyn.com> [2016-06-30 13:48]:
>     The problem with this in try/eval (exiting normally or via an
>     exception) is that it can delay some SVs getting freed until
>     *after* $@ has been set. If that freeing calls a destructor which
>     happens to set $@, then that overwrites the "real" value of $@.

So if I understand this correctly, it means the full idiom for safe eval
on current and older perls must be as follows:

    eval { { local $@; ... } () }                 #   void context, pre-5.26
    eval { my $ret = do { local $@; ... } $ret }  # scalar context, pre-5.14

(With list context essentially like scalar context.)

Correct?

Rewriting your tests accordingly does makes them pass, at least.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Thread Previous | 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