New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
do and eval sometimes don't clear $@ #2658
Comments
From pimlott@idiomtech.comCreated by pimlott@idiomtech.comThe documentation for eval says If there was no error, C<$@> is guaranteed to be a null string. and the documentation for do (the do EXPR form) says do 'stat.pl'; is just like scalar eval `cat stat.pl`; However, there are circumstances where eval and do leave $@ set to its Example 1: eval { die "shouldn't see this\n" }; Example 2: eval { die "shouldn't see this\n" }; Both examples will warn "shouldn't see this". While the first example is Andrew Perl Info
|
From @simoncozensOn Wed, Sep 20, 2000 at 07:32:56PM -0400, Andrew Pimlott wrote:
Easy-peasy. Just clear the error SV when entering an eval or do: ==== //depot/bleadperl/pp_ctl.c#3 - /home/simon/patchbay/bleadperl/pp_ctl.c ==== + sv_setsv(ERRSV, &PL_sv_no); # don't make this lexical sub do_require { +# do 'nothing' clears $@ # ***interaction with pod (don't put any thing after here)*** -print "1..40\n"; eval 'print "ok 1\n";'; @@ -206,3 +206,20 @@ % ./perl harness op/eval.t comp/require.t |
From @gsarOn Thu, 28 Sep 2000 12:24:49 BST, Simon Cozens wrote:
I think you're forgetting that there is only one $@. (IOW, what about IIRC, the archives have some history on this issue. Sarathy |
From @simoncozensOn Thu, Sep 28, 2000 at 08:41:53AM -0700, Gurusamy Sarathy wrote:
Well, hm, yeah. The point is, anything that enters some kind of eval should
I'll take a look. |
From @schwernThe first case, an empty eval BLOCK not clearing $@, has been fixed in 5.8.0. The second case, do EXPR failing to load a file not clearing $@, has not been fixed. It |
From @jkeenanOn Tue Jul 15 23:51:58 2003, schwern wrote:
Here's the second case as a one-liner: ##### perl -e 'eval { die "should not see this\n" };do "no such file";warn ##### Is there anyone who could take this older ticket on? Thank you very much. |
From @davidnicolOn Sat, Apr 21, 2012 at 4:18 PM, James E Keenan via RT
did it ever work as expected? here's a clarification to make "perldoc -f do" Inline Patchdiff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index c9307f3..130c31a 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -1556,7 +1556,7 @@ file as a Perl script.
is just like
- eval `cat stat.pl`;
+ -r 'stat.pl' and eval `cat stat.pl`;
except that it's more efficient and concise, keeps track of the current
filename for error messages, searches the C<@INC> directories, and updates
-- In this document, the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", |
From @davidnicol |
From @davidnicolI didn't actually test this morning before dawn, the choice of adding a "-r" If "do" cannot read the file, it returns undef and sets $! to which does not say anything about manipulating $@ at all when "do" One-lliner testing just now indicates that a readability test is in A more accurate "just like" that does not rely on unix tools, and has eval join ('', <DO>) if open DO, "<", 'stat.pl'; or even { my $f; open $f, "<", 'stat.pl' and eval join '', <$f> } if we want to obsessively reinforce symbol privacy.
-- |
From @maukeCreated by @mauke'perldoc -f do' says: ... # read in config files: system first, then user Turns out that advice doesn't work: % perl -wle 'eval { die "where is your god now?\n" }; do "no such file"; warn "got: $@"' That is, if 'do' can't open/read the file, it doesn't clear $@, so you might An obvious workaround is to set $@ = undef; before using 'do'. I'm not sure Perl Info
|
From @ikegamiOn Mon, Jun 18, 2012 at 1:31 PM, l.mai@web.de <perlbug-followup@perl.org>wrote:
Your subject is misleading since there's "do" isn't documented to clear $@ % perl -wle 'eval { die "where is your god now?\n" }; do "no such file";
got: where is your god now? But that is clearly a deviation from the documentation. And I believe the
|
The RT System itself - Status changed from 'new' to 'open' |
From @ikegamiPatch attached. |
From @ikegami0001-RT-113730-should-be-cleared-on-do-IO-error.patchFrom 41f30f84ca03741c2936abe141a99fa26bd85b35 Mon Sep 17 00:00:00 2001
From: Eric Brine <ikegami@adaelis.com>
Date: Mon, 18 Jun 2012 14:56:32 -0400
Subject: [PATCH] RT#113730 - $@ should be cleared on "do" IO error.
---
pp_ctl.c | 1 +
t/op/do.t | 12 ++++++++++++
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/pp_ctl.c b/pp_ctl.c
index b414e81..437bc8f 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3928,6 +3928,7 @@ PP(pp_require)
DIE(aTHX_ "Can't locate %s", name);
}
+ CLEAR_ERRSV();
RETPUSHUNDEF;
}
else
diff --git a/t/op/do.t b/t/op/do.t
index 93d3f73..14b9011 100644
--- a/t/op/do.t
+++ b/t/op/do.t
@@ -286,4 +286,16 @@ SKIP: {
is($w, undef, 'do STRING does not propagate warning hints');
}
+# RT#113730 - $@ should be cleared on IO error.
+{
+ $@ = "should not see";
+ $! = 0;
+ my $rv = do("non exitant");
+ my $saved_error = $@;
+ my $saved_errno = $!;
+ ok(!$rv, "do returns false on io errror");
+ ok(!$saved_error, "\$\@ not set on io error");
+ ok($saved_errno, "\$! set on io error");
+}
+
done_testing();
--
1.7.2.5
|
From @tamiasOn Mon, Jun 18, 2012 at 02:59:28PM -0400, Eric Brine wrote:
I suppose it doesn't matter, but you misspelled 'non-existent' in the Ronald |
From @ikegamiOn Mon, Jun 18, 2012 at 3:16 PM, Ronald J Kimball <rjk@tamias.net> wrote:
I know it's "existent" in English, yet I always get it wrong. It must be |
From @ikegamiOn Mon, Jun 18, 2012 at 3:45 PM, Eric Brine <ikegami@adaelis.com> wrote:
I mean "I did that on purpose to increase the chances of the file not |
From @cpansproutOn Mon Jun 18 12:16:43 2012, rjk@tamias.net wrote:
So did you. :-) It has no hyphen. BTW, this bug is a duplicate of #4350. -- Father Chrysostomos |
From @cpansproutOn Mon Jun 18 11:59:59 2012, ikegami@adaelis.com wrote:
Jesse Luehrs has applied this as a3ff80c. -- Father Chrysostomos |
@cpansprout - Status changed from 'open' to 'resolved' |
From @cpansproutOn Sat Apr 21 14:18:39 2012, jkeenan wrote:
This has been fixed by the patch Eric Brine submitted to ticket #113730 -- Father Chrysostomos |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#4350 (status was 'resolved')
Searchable as RT4350$
The text was updated successfully, but these errors were encountered: