You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Argument croak_on_error for eval_pv() is broken #17036
Here is test example which proves that when croak_on_error is set to 1
for eval_pv() function, it does not croak.
Just compile it, run and see that die from eval_pv with croak_on_error=1
does not throw any error.
$ xsubpp -prototypes -output test.c test.xs
$ gcc test.c -I`perl -MConfig -e 'print $Config::Config{archlib}'`/CORE -fPIC -shared -o auto/test/test.so
$ perl -I. -Mtest -e ''
ERROR: eval_pv not died
OK: eval_pv died with $@=string error at test.pm line 10.
Source test code is below:
$ cat test.pm
package test;
use XSLoader;
BEGIN { XSLoader::load(__PACKAGE__) }
use strict;
use warnings;
eval { eval_pv 'die bool_obj->new(0)'; 1 } and do { print "ERROR: eval_pv not died\n"; 1; } or do { print "OK: eval_pv died with \$@=$@" };
eval { eval_pv 'die bool_obj->new(1)'; 1 } and do { print "ERROR: eval_pv not died\n"; 1; } or do { print "OK: eval_pv died with \$@=$@" };
package bool_obj;
use overload 'bool' => sub { ${$_[0]} };
use overload '""' => sub { "string error" };
sub new { bless \do{my $tmp = $_[1]}, $_[0] }
On Fri, 14 Jun 2019 00:44:07 -0700, pali@cpan.org wrote:
What about checking for SvROK? Or installing __DIE__ handler and
checking if __DIE__ handler was called?
When I suggested using ROK in #p5p you brought up clobbering $@ as a problem, but I don't think it is one - eval in all its forms clobbers $@ and I don't think it's unreasonable to expect that from eval_pv()/eval_sv() (and eval_sv() can G_KEEPERR).
Using a __DIE__ handler would be unnecessarily complex - you'd be better off modifying eval_sv()[1] to accept a G_RETHROW flag, which wouldn't be too hard.
Is there some way changing:
if(SvTRUE_NN(errsv))
to
if(SvTRUE_NN(errsv) || SvROK(errsv))
doesn't solve this?
Tony
[1] G_EVALBYTE and G_EVALUNICODE to match OPpEVAL_BYTES and OPpEVAL_UNICODE might also be useful.
On Sunday 16 June 2019 21:40:43 Tony Cook via RT wrote:
On Fri, 14 Jun 2019 00:44:07 -0700, pali@cpan.org wrote:
What about checking for SvROK? Or installing __DIE__ handler and
checking if __DIE__ handler was called?
When I suggested using ROK in #p5p you brought up clobbering $@ as a problem, but I don't think it is one - eval in all its forms clobbers $@ and I don't think it's unreasonable to expect that from eval_pv()/eval_sv() (and eval_sv() can G_KEEPERR).
Using a __DIE__ handler would be unnecessarily complex - you'd be better off modifying eval_sv()[1] to accept a G_RETHROW flag, which wouldn't be too hard.
Seems like introduction of G_RETHROW in eval_sv() is the best way.
Is there some way changing:
if(SvTRUE_NN(errsv))
to
if(SvTRUE_NN(errsv) || SvROK(errsv))
Rather check SvROK before SvTRUE
if(SvROK(errsv) || SvTRUE_NN(errsv))
as SvTRUE would call object overloaded method. And it is useless.
doesn't solve this?
So is clobbering of $@ in eval_sv() possible or not?
Tony
[1] G_EVALBYTE and G_EVALUNICODE to match OPpEVAL_BYTES and OPpEVAL_UNICODE might also be useful.
On Mon, 17 Jun 2019 01:06:58 -0700, pali@cpan.org wrote:
On Sunday 16 June 2019 21:40:43 Tony Cook via RT wrote:
On Fri, 14 Jun 2019 00:44:07 -0700, pali@cpan.org wrote:
What about checking for SvROK? Or installing __DIE__ handler and
checking if __DIE__ handler was called?
When I suggested using ROK in #p5p you brought up clobbering $@ as a
problem, but I don't think it is one - eval in all its forms clobbers
$@ and I don't think it's unreasonable to expect that from
eval_pv()/eval_sv() (and eval_sv() can G_KEEPERR).
Using a __DIE__ handler would be unnecessarily complex - you'd be
better off modifying eval_sv()[1] to accept a G_RETHROW flag, which
wouldn't be too hard.
Seems like introduction of G_RETHROW in eval_sv() is the best way.
See the attached.
Is there some way changing:
if(SvTRUE_NN(errsv))
to
if(SvTRUE_NN(errsv) || SvROK(errsv))
Rather check SvROK before SvTRUE
if(SvROK(errsv) || SvTRUE_NN(errsv))
as SvTRUE would call object overloaded method. And it is useless.
Not that it matters if the attached is applied, but the checks SvTRUE() does seem more likely to matter than the SvROK() check in most common cases.
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 $@.
On Wednesday 19 June 2019 22:31:43 Tony Cook via RT wrote:
On Mon, 17 Jun 2019 01:06:58 -0700, pali@cpan.org wrote:
On Sunday 16 June 2019 21:40:43 Tony Cook via RT wrote:
On Fri, 14 Jun 2019 00:44:07 -0700, pali@cpan.org wrote:
What about checking for SvROK? Or installing __DIE__ handler and
checking if __DIE__ handler was called?
When I suggested using ROK in #p5p you brought up clobbering $@ as a
problem, but I don't think it is one - eval in all its forms clobbers
$@ and I don't think it's unreasonable to expect that from
eval_pv()/eval_sv() (and eval_sv() can G_KEEPERR).
Using a __DIE__ handler would be unnecessarily complex - you'd be
better off modifying eval_sv()[1] to accept a G_RETHROW flag, which
wouldn't be too hard.
Seems like introduction of G_RETHROW in eval_sv() is the best way.
See the attached.
Looks good, thanks!
Is there some way changing:
if(SvTRUE_NN(errsv))
to
if(SvTRUE_NN(errsv) || SvROK(errsv))
Rather check SvROK before SvTRUE
if(SvROK(errsv) || SvTRUE_NN(errsv))
as SvTRUE would call object overloaded method. And it is useless.
Not that it matters if the attached is applied, but the checks SvTRUE() does seem more likely to matter than the SvROK() check in most common cases.
Yes, it does not matter for patch which is attached, but SvROK() just
checks sv flags which is fast, but SvTRUE() is slow and has side
effects.
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?
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?
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?
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?
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?
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.
On Wednesday 19 June 2019 22:31:43 Tony Cook via RT wrote:
On Mon, 17 Jun 2019 01:06:58 -0700, pali@cpan.org wrote:
On Sunday 16 June 2019 21:40:43 Tony Cook via RT wrote:
On Fri, 14 Jun 2019 00:44:07 -0700, pali@cpan.org wrote:
What about checking for SvROK? Or installing __DIE__ handler and
checking if __DIE__ handler was called?
When I suggested using ROK in #p5p you brought up clobbering $@ as a
problem, but I don't think it is one - eval in all its forms clobbers
$@ and I don't think it's unreasonable to expect that from
eval_pv()/eval_sv() (and eval_sv() can G_KEEPERR).
Using a __DIE__ handler would be unnecessarily complex - you'd be
better off modifying eval_sv()[1] to accept a G_RETHROW flag, which
wouldn't be too hard.
Seems like introduction of G_RETHROW in eval_sv() is the best way.
On Thu, 04 Jul 2019 03:11:45 -0700, pali@cpan.org wrote:
On Wednesday 19 June 2019 22:31:43 Tony Cook via RT wrote:
On Mon, 17 Jun 2019 01:06:58 -0700, pali@cpan.org wrote:
On Sunday 16 June 2019 21:40:43 Tony Cook via RT wrote:
On Fri, 14 Jun 2019 00:44:07 -0700, pali@cpan.org wrote:
What about checking for SvROK? Or installing __DIE__ handler and
checking if __DIE__ handler was called?
When I suggested using ROK in #p5p you brought up clobbering $@ as a
problem, but I don't think it is one - eval in all its forms clobbers
$@ and I don't think it's unreasonable to expect that from
eval_pv()/eval_sv() (and eval_sv() can G_KEEPERR).
Using a __DIE__ handler would be unnecessarily complex - you'd be
better off modifying eval_sv()[1] to accept a G_RETHROW flag, which
wouldn't be too hard.
Seems like introduction of G_RETHROW in eval_sv() is the best way.
On Sunday 07 July 2019 18:57:12 Tony Cook via RT wrote:
On Thu, 04 Jul 2019 03:11:45 -0700, pali@cpan.org wrote:
On Wednesday 19 June 2019 22:31:43 Tony Cook via RT wrote:
On Mon, 17 Jun 2019 01:06:58 -0700, pali@cpan.org wrote:
On Sunday 16 June 2019 21:40:43 Tony Cook via RT wrote:
On Fri, 14 Jun 2019 00:44:07 -0700, pali@cpan.org wrote:
What about checking for SvROK? Or installing __DIE__ handler and
checking if __DIE__ handler was called?
When I suggested using ROK in #p5p you brought up clobbering $@ as a
problem, but I don't think it is one - eval in all its forms clobbers
$@ and I don't think it's unreasonable to expect that from
eval_pv()/eval_sv() (and eval_sv() can G_KEEPERR).
Using a __DIE__ handler would be unnecessarily complex - you'd be
better off modifying eval_sv()[1] to accept a G_RETHROW flag, which
wouldn't be too hard.
Seems like introduction of G_RETHROW in eval_sv() is the best way.
Activity
p5pRT commentedon Jun 5, 2019
From @pali
Here is test example which proves that when croak_on_error is set to 1
for eval_pv() function, it does not croak.
Just compile it, run and see that die from eval_pv with croak_on_error=1
does not throw any error.
$ xsubpp -prototypes -output test.c test.xs
$ gcc test.c -I`perl -MConfig -e 'print $Config::Config{archlib}'`/CORE -fPIC -shared -o auto/test/test.so
$ perl -I. -Mtest -e ''
ERROR: eval_pv not died
OK: eval_pv died with $@=string error at test.pm line 10.
Source test code is below:
$ cat test.pm
package test;
use XSLoader;
BEGIN { XSLoader::load(__PACKAGE__) }
use strict;
use warnings;
eval { eval_pv 'die bool_obj->new(0)'; 1 } and do { print "ERROR: eval_pv not died\n"; 1; } or do { print "OK: eval_pv died with \$@=$@" };
eval { eval_pv 'die bool_obj->new(1)'; 1 } and do { print "ERROR: eval_pv not died\n"; 1; } or do { print "OK: eval_pv died with \$@=$@" };
package bool_obj;
use overload 'bool' => sub { ${$_[0]} };
use overload '""' => sub { "string error" };
sub new { bless \do{my $tmp = $_[1]}, $_[0] }
1;
$ cat test.xs
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
MODULE = test PACKAGE = test
void
eval_pv(string, croak_on_error = 1)
const char *string
I32 croak_on_error
PPCODE:
EXTEND(SP, 1);
PUSHs(eval_pv(string, croak_on_error));
p5pRT commentedon Jun 14, 2019
From @pali
What about checking for SvROK? Or installing __DIE__ handler and
checking if __DIE__ handler was called?
p5pRT commentedon Jun 17, 2019
From @tonycoz
On Fri, 14 Jun 2019 00:44:07 -0700, pali@cpan.org wrote:
When I suggested using ROK in #p5p you brought up clobbering$@ as a problem, but I don't think it is one - eval in all its forms clobbers $ @ and I don't think it's unreasonable to expect that from eval_pv()/eval_sv() (and eval_sv() can G_KEEPERR).
Using a __DIE__ handler would be unnecessarily complex - you'd be better off modifying eval_sv()[1] to accept a G_RETHROW flag, which wouldn't be too hard.
Is there some way changing:
if(SvTRUE_NN(errsv))
to
if(SvTRUE_NN(errsv) || SvROK(errsv))
doesn't solve this?
Tony
[1] G_EVALBYTE and G_EVALUNICODE to match OPpEVAL_BYTES and OPpEVAL_UNICODE might also be useful.
p5pRT commentedon Jun 17, 2019
The RT System itself - Status changed from 'new' to 'open'
p5pRT commentedon Jun 17, 2019
From @pali
On Sunday 16 June 2019 21:40:43 Tony Cook via RT wrote:
Seems like introduction of G_RETHROW in eval_sv() is the best way.
Rather check SvROK before SvTRUE
if(SvROK(errsv) || SvTRUE_NN(errsv))
as SvTRUE would call object overloaded method. And it is useless.
So is clobbering of $@ in eval_sv() possible or not?
p5pRT commentedon Jun 20, 2019
From @tonycoz
On Mon, 17 Jun 2019 01:06:58 -0700, pali@cpan.org wrote:
See the attached.
Not that it matters if the attached is applied, but the checks SvTRUE() does seem more likely to matter than the SvROK() check in most common cases.
Evals called within whatever code eval_sv() calls can still clobber $@.
Tony
p5pRT commentedon Jun 20, 2019
From @tonycoz
0001-perl-134177-add-G_RETHROW-flag-to-eval_sv.patch
p5pRT commentedon Jun 20, 2019
From @pali
On Wednesday 19 June 2019 22:31:43 Tony Cook via RT wrote:
Looks good, thanks!
Yes, it does not matter for patch which is attached, but SvROK() just
checks sv flags which is fast, but SvTRUE() is slow and has side
effects.
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?
p5pRT commentedon Jun 20, 2019
From @tonycoz
On Thu, Jun 20, 2019 at 10:18:40AM +0200, pali@cpan.org wrote:
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.
Tony
p5pRT commentedon Jun 20, 2019
From @pali
On Thursday 20 June 2019 02:49:00 Tony Cook via RT wrote:
I mean $@ clobbering in eval_pv(). E.g. when eval_pv() is called with
croak_on_error=1.
p5pRT commentedon Jun 24, 2019
From @tonycoz
On Thu, 20 Jun 2019 02:51:32 -0700, pali@cpan.org wrote:
eval_pv() never uses (and never will for compatibility) the G_KEEPERR flag when calling eval_sv(), so it will always clobber $@.
Tony
p5pRT commentedon Jun 24, 2019
From @pali
On Sunday 23 June 2019 18:42:34 Tony Cook via RT wrote:
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 \$@=$@" };$obj = bless {}, "obj";'; 1 } and do { print "OK: eval_pv not died, \$@=$ @\n"; 1 } or do { print "ERROR: eval_pv died with \$@=$@" };$@; die "message"'; 1 } and do { print "ERROR: eval_pv not died, \$@=$ @\n"; 1 } or do { print "OK: 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
eval { eval_pv 'local
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.
p5pRT commentedon Jul 4, 2019
From @pali
On Wednesday 19 June 2019 22:31:43 Tony Cook via RT wrote:
Hi! Have you applied this G_RETHROW patch?
p5pRT commentedon Jul 8, 2019
From @tonycoz
On Thu, 04 Jul 2019 03:11:45 -0700, pali@cpan.org wrote:
Done in fb81daf, 66ff4fb.
Thanks for your feedback.
Tony
p5pRT commentedon Jul 8, 2019
@tonycoz - Status changed from 'open' to 'pending release'
p5pRT commentedon Jul 8, 2019
From @pali
On Sunday 07 July 2019 18:57:12 Tony Cook via RT wrote:
Thanks!
Now reminds only my question about clobbering:
https://rt.perl.org/Public/Bug/Display.html?id=134177#txn-1642800
Can version without G_RETHROW really breaks croak_on_error=1?