develooper Front page | perl.perl5.porters | Postings from June 2019

Re: [perl #134177] Argument croak_on_error for eval_pv() is broken

Thread Previous | Thread Next
From:
pali
Date:
June 24, 2019 19:53
Subject:
Re: [perl #134177] Argument croak_on_error for eval_pv() is broken
Message ID:
20190624195318.dg2matvrkuyvo46a@pali
On Sunday 23 June 2019 18:42:34 Tony Cook via RT wrote:
> On Thu, 20 Jun 2019 02:51:32 -0700, pali@cpan.org wrote:
> > On Thursday 20 June 2019 02:49:00 Tony Cook via RT wrote:
> > > On Thu, Jun 20, 2019 at 10:18:40AM +0200, pali@cpan.org wrote:
> > > > > > > doesn't solve this?
> > > > > >
> > > > > > So is clobbering of $@ in eval_sv() possible or not?
> > > > >
> > > > > Evals called within whatever code eval_sv() calls can still
> > > > > clobber $@.
> > > >
> > > > I tried to play with it, but I was not able to write any code which
> > > > would clobber $@. And provide incorrect result with SvROK + SvTRUE
> > > > checks. So it is really possible?
> > >
> > > It has no effect on that, I meant that:
> > >
> > > ./perl -Ilib -MXS::APItest -le '$@ = "foo"; eval_sv("eval q/1/",
> > > G_KEEPERR); print $@'
> > >
> > > $@ isn't preserved.
> > 
> > I mean $@ clobbering in eval_pv(). E.g. when eval_pv() is called with
> > croak_on_error=1.
> 
> eval_pv() never uses (and never will for compatibility) the G_KEEPERR flag when calling eval_sv(), so it will always clobber $@.

I tried to create any other examples where eval_pv() with
croak_on_error=1 would not work correctly. But I was not able to come up
with any other.

All following examples works correctly, no error/fail.

eval { eval_pv '$@ = "croak"'; 1 } and do { print "OK: eval_pv not died, \$@=$@\n"; 1 } or do { print "ERROR: eval_pv died with \$@=$@" };
eval { eval_pv 'eval { die "croak"; }'; 1 } and do { print "OK: eval_pv not died, \$@=$@\n"; 1 } or do { print "ERROR: eval_pv died with \$@=$@" };
eval { eval_pv 'sub obj::DESTROY { eval { die "croak" } } my $obj = bless {}, "obj";'; 1 } and do { print "OK: eval_pv not died, \$@=$@\n"; 1 } or do { print "ERROR: eval_pv died with \$@=$@" };
eval { eval_pv 'local $@; die "message"'; 1 } and do { print "ERROR: eval_pv not died, \$@=$@\n"; 1 } or do { print "OK: eval_pv died with \$@=$@" };

So how can *unpatched* eval_pv() clobbers $@ and make croak_on_error=1
to behave incorrectly? The only example which I created was that one
with overloading 'bool' object method to false.

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