A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Perl/perl5/issues/21415 below:

eval_sv() doesn't preserve caller hints/features · Issue #21415 · Perl/perl5 · GitHub

The Perl API function eval_sv() is conceptually the XS version of the Perl eval() function. But it doesn't really match very well, because it doesn't preserve the hints bits or enabled features of its caller; whereas the Perl function does.

eval_sv() isn't normally accessible from Perl but we can abuse XS::APItest in a built source checkout to find a callable copy of it. See the following examples.

The hints bits include the strict flags; these are not preserved:

$ ./perl -Ilib -e 'use strict; eval("\$x + \$y") or die $@'
Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at (eval 1) line 1.
Global symbol "$y" requires explicit package name (did you forget to declare "my $y"?) at (eval 1) line 1.

$ ./perl -Ilib -MXS::APItest -e 'use strict; eval_pv("print \$x + \$y, \"DONE\"", 0)'
0DONE

The features bits include the enabled keywords; these are not preserved either:

$ ./perl -Ilib -e 'use feature "say"; eval("say q(HELLO)") or die $@'
HELLO

$ ./perl -Ilib -MXS::APItest -e 'use strict; eval_pv("say q(HELLO)", 0) or die $@'
syntax error at (eval 6) line 1, near "say q(HELLO)"
Execution of (eval 6) aborted due to compilation errors.

By comparison, the warnings bits are preserved, suggesting that at least this general testing method is valid:

$ ./perl -Ilib -MXS::APItest -e 'use warnings; eval_pv("print 123 + undef", 0) or die $@'
Use of uninitialized value in addition (+) at (eval 6) line 1.
123

$ ./perl -Ilib -MXS::APItest -e 'eval_pv("print 123 + undef", 0) or die $@'
123

Ultimately, I don't think this behaviour could be changed by default without breaking a huge amount of existing code. However, I think it would be useful to provide a new flag of some name I don't have a good suggestion for, to ask it to do this.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4