Perl / perl5

đŸȘ The Perl programming language
https://dev.perl.org/perl5/
Other
1.86k stars 529 forks source link

return 0 or die; #9523

Closed p5pRT closed 10 years ago

p5pRT commented 15 years ago

Migrated from rt.perl.org#59802 (status was 'resolved')

Searchable as RT59802$

p5pRT commented 10 years ago

From @xdg

On Wed\, Jul 17\, 2013 at 4​:12 PM\, Father Chrysostomos via RT \perlbug\-followup@​perl\.org wrote​:

Those patches look good. Thank you. Now we just have to wait for Parse​::CPAN​::Meta.

The patch is in the new Perl-Toolchain-Gang repo.

I'll try to ship it tonight.

David

-- David Golden \xdg@​xdg\.me Take back your inbox! → http​://www.bunchmail.com/ Twitter/IRC​: @​xdg

p5pRT commented 10 years ago

From @xdg

  Parse-CPAN-Meta-1.4405.tar.gz

has entered CPAN as

  file​: $CPAN/authors/id/D/DA/ DAGOLDEN/Parse-CPAN-Meta-1.4405.tar.gz   size​: 20876 bytes   md5​: f9025240afbd3fd98e34964609732b8b

On Wed\, Jul 17\, 2013 at 4​:59 PM\, David Golden \xdg@​xdg\.me wrote​:

On Wed\, Jul 17\, 2013 at 4​:12 PM\, Father Chrysostomos via RT \perlbug\-followup@​perl\.org wrote​:

Those patches look good. Thank you. Now we just have to wait for Parse​::CPAN​::Meta.

The patch is in the new Perl-Toolchain-Gang repo.

I'll try to ship it tonight.

David

-- David Golden \xdg@​xdg\.me Take back your inbox! → http​://www.bunchmail.com/ Twitter/IRC​: @​xdg

-- David Golden \xdg@​xdg\.me Take back your inbox! → http​://www.bunchmail.com/ Twitter/IRC​: @​xdg

p5pRT commented 10 years ago

From @cpansprout

On Wed Jul 17 18​:47​:35 2013\, xdg@​xdg.me wrote​:

Parse\-CPAN\-Meta\-1\.4405\.tar\.gz

has entered CPAN as

file​: $CPAN/authors/id/D/DA/ DAGOLDEN/Parse-CPAN-Meta-1.4405.tar.gz size​: 20876 bytes md5​: f9025240afbd3fd98e34964609732b8b

Thank you.

--

Father Chrysostomos

p5pRT commented 10 years ago

From @nthykier

On 2013-07-17 22​:12\, Father Chrysostomos via RT wrote​:

On Wed Jul 17 12​:37​:07 2013\, niels@​thykier.net wrote​:

[...]

Included is a patch to add the op_folded member and my previous patch has been rebased on top of it.

RE​: op_folded-patch - I made OPpCONST_FOLDED redundant internally in the code (i.e. perl does the right thing even without it). However\, I left it in (and kept it maintained) for now until B​::Concise can be updated. I presume that will involve exposing op_folded via B.pm\, which I have left as "future work" for now. I made no attempt to have it replace OPf_SPECIAL on the regexp/tr operators either.

Those patches look good. Thank you. Now we just have to wait for Parse​::CPAN​::Meta.

Revised warning patch attached with more tests. Thanks to Reini Urban for smoke testing CPAN and reminding me that exit is a unary operator (so it is not even safe to use "||" with exit).

~Niels

p5pRT commented 10 years ago

From @nthykier

0002-op.c-Warn-on-return-a-or-b-perl-59802.patch ```diff From cb322ab05e51647edb4db431f1757b9631ef5001 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Mon, 15 Jul 2013 22:25:19 +0200 Subject: [PATCH 2/2] op.c: Warn on "return $a or $b" [perl #59802] Add a warning for the (likely) unintended use of "return $a or $b" (and similar expressions), which perl parses as "(return $a) || $b" (which is effectively just "return $a;"). Note this warning is triggered by some modules (e.g. Test::Builder). These are not fixed by this commit. Signed-off-by: Niels Thykier --- op.c | 38 ++++++++++++++++++ pod/perldiag.pod | 22 ++++++++++ t/lib/warnings/op | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) diff --git a/op.c b/op.c index a9ee2d1..0459968 100644 --- a/op.c +++ b/op.c @@ -5830,6 +5830,44 @@ S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp) first = *firstp; other = *otherp; + /* [perl #59802]: Warn about things like "return $a or $b", which + is parsed as "(return $a) or $b" rather than "return ($a or + $b)". NB: This also applies to xor, which is why we do it + here. + */ + switch (first->op_type) { + case OP_NEXT: + case OP_LAST: + case OP_REDO: + /* XXX: Perhaps we should emit a stronger warning for these. + Even with the high-precedence operator they don't seem to do + anything sensible. + + But until we do, fall through here. + */ + case OP_RETURN: + case OP_EXIT: + case OP_DIE: + case OP_GOTO: + /* XXX: Currently we allow people to "shoot themselves in the + foot" by explicitly writing "(return $a) or $b". + + Warn unless we are looking at the result from folding or if + the programmer explicitly grouped the operators like this. + The former can occur with e.g. + + use constant FEATURE => ( $] >= ... ); + sub { not FEATURE and return or do_stuff(); } + */ + if (!first->op_folded && !(first->op_flags & OPf_PARENS)) + Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), + "Possible precedence issue with control flow operator"); + /* XXX: Should we optimze this to "return $a;" (i.e. remove + the "or $b" part)? + */ + break; + } + if (type == OP_XOR) /* Not short circuit, but here by precedence. */ return newBINOP(type, flags, scalar(first), scalar(other)); diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 5165599..7347969 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -4229,6 +4229,28 @@ higher precedence of C<==>. This is probably not what you want. (If you really meant to write this, disable the warning, or, better, put the parentheses explicitly and write C<$x & ($y == 0)>). +=item Possible precedence issue with control flow operator + +(W syntax) There is a possible problem with the mixing of a control +flow operator (e.g. C) and a low-precedence operator like +C. Consider: + + sub { return $a or $b; } + +This is parsed as: + + sub { (return $a) or $b; } + +Which is effectively just: + + sub { return $a; } + +Either use parentheses or the high-precedence variant of the operator. + +Note this may be also triggered for constructs like: + + sub { 1 if die; } + =item Possible unintended interpolation of $\ in regex (W ambiguous) You said something like C in a regex. diff --git a/t/lib/warnings/op b/t/lib/warnings/op index c38bcde..d858f32 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -1575,3 +1575,118 @@ OPTION regex ?(?s).* Subroutine DynaLoader::dl_error redefined at \(eval 2\) line 2\. ######## +# op.c +use warnings; +sub do_warn_1 { return $a or $b; } +sub do_warn_2 { return $a and $b; } +sub do_warn_3 { return $a xor $b; } +sub do_warn_4 { die $a or $b; } +sub do_warn_5 { die $a and $b; } +sub do_warn_6 { die $a xor $b; } +sub do_warn_7 { exit $a or $b; } +sub do_warn_8 { exit $a and $b; } +sub do_warn_9 { exit $a xor $b; } + +# Since exit is an unary operator, it is even stronger than +# || and &&. +sub do_warn_10 { exit $a || $b; } +sub do_warn_11 { exit $a && $b; } + +sub do_warn_12 { goto $a or $b; } +sub do_warn_13 { goto $a and $b; } +sub do_warn_14 { goto $a xor $b; } +sub do_warn_15 { next $a or $b while(1); } +sub do_warn_16 { next $a and $b while(1); } +sub do_warn_17 { next $a xor $b while(1); } +sub do_warn_18 { last $a or $b while(1); } +sub do_warn_19 { last $a and $b while(1); } +sub do_warn_20 { last $a xor $b while(1); } +sub do_warn_21 { redo $a or $b while(1); } +sub do_warn_22 { redo $a and $b while(1); } +sub do_warn_23 { redo $a xor $b while(1); } +# These get re-written to "(return/die $a) and $b" +sub do_warn_24 { $b if return $a; } +sub do_warn_25 { $b if die $a; } +EXPECT +Possible precedence issue with control flow operator at - line 3. +Possible precedence issue with control flow operator at - line 4. +Possible precedence issue with control flow operator at - line 5. +Possible precedence issue with control flow operator at - line 6. +Possible precedence issue with control flow operator at - line 7. +Possible precedence issue with control flow operator at - line 8. +Possible precedence issue with control flow operator at - line 9. +Possible precedence issue with control flow operator at - line 10. +Possible precedence issue with control flow operator at - line 11. +Possible precedence issue with control flow operator at - line 15. +Possible precedence issue with control flow operator at - line 16. +Possible precedence issue with control flow operator at - line 18. +Possible precedence issue with control flow operator at - line 19. +Possible precedence issue with control flow operator at - line 20. +Possible precedence issue with control flow operator at - line 21. +Possible precedence issue with control flow operator at - line 22. +Possible precedence issue with control flow operator at - line 23. +Possible precedence issue with control flow operator at - line 24. +Possible precedence issue with control flow operator at - line 25. +Possible precedence issue with control flow operator at - line 26. +Possible precedence issue with control flow operator at - line 27. +Possible precedence issue with control flow operator at - line 28. +Possible precedence issue with control flow operator at - line 29. +Possible precedence issue with control flow operator at - line 31. +Possible precedence issue with control flow operator at - line 32. +######## +# op.c +# (same as above, except these should not warn) +use constant FEATURE => 1; +use constant MISSING_FEATURE => 0; + +sub dont_warn_1 { MISSING_FEATURE and return or dont_warn_3(); } +sub dont_warn_2 { FEATURE || return and dont_warn_3(); } +sub dont_warn_3 { not FEATURE and return or dont_warn_3(); } +sub dont_warn_4 { !MISSING_FEATURE || return and dont_warn_3(); } +sub dont_warn_5 { MISSING_FEATURE and die or dont_warn_3(); } +sub dont_warn_6 { FEATURE || die and dont_warn_3(); } +sub dont_warn_7 { not FEATURE and die or dont_warn_3(); } +sub dont_warn_8 { !MISSING_FEATURE || die and dont_warn_3(); } +sub dont_warn_9 { MISSING_FEATURE and goto $a or dont_warn_3(); } +sub dont_warn_10 { FEATURE || goto $a and dont_warn_3(); } +sub dont_warn_11 { not FEATURE and goto $a or dont_warn_3(); } +sub dont_warn_12 { !MISSING_FEATURE || goto $a and dont_warn_3(); } + +sub dont_warn_13 { MISSING_FEATURE and exit $a or dont_warn_3(); } +sub dont_warn_14 { FEATURE || exit $a and dont_warn_3(); } +sub dont_warn_15 { not FEATURE and exit $a or dont_warn_3(); } +sub dont_warn_16 { !MISSING_FEATURE || exit $a and dont_warn_3(); } + +sub dont_warn_17 { MISSING_FEATURE and next or dont_warn_3() while(1); } +sub dont_warn_18 { FEATURE || next and dont_warn_3() while(1); } +sub dont_warn_19 { not FEATURE and next or dont_warn_3() while(1); } +sub dont_warn_20 { !MISSING_FEATURE || next and dont_warn_3() while(1); } +sub dont_warn_21 { MISSING_FEATURE and redo or dont_warn_3() while(1); } +sub dont_warn_22 { FEATURE || redo and dont_warn_3() while(1); } +sub dont_warn_23 { not FEATURE and redo or dont_warn_3() while(1); } +sub dont_warn_24 { !MISSING_FEATURE || redo and dont_warn_3() while(1); } +sub dont_warn_25 { MISSING_FEATURE and last or dont_warn_3() while(1); } +sub dont_warn_26 { FEATURE || last and dont_warn_3() while(1); } +sub dont_warn_27 { not FEATURE and last or dont_warn_3() while(1); } +sub dont_warn_28 { !MISSING_FEATURE || last and dont_warn_3() while(1); } + +# These are weird, but at least not ambiguous. +sub dont_warn_29 { return ($a or $b); } +sub dont_warn_30 { return ($a and $b); } +sub dont_warn_31 { return ($a xor $b); } +sub dont_warn_32 { die ($a or $b); } +sub dont_warn_33 { die ($a and $b); } +sub dont_warn_34 { die ($a xor $b); } +sub dont_warn_35 { goto ($a or $b); } +sub dont_warn_36 { goto ($a and $b); } +sub dont_warn_37 { goto ($a xor $b); } +sub dont_warn_38 { next ($a or $b) while(1); } +sub dont_warn_39 { next ($a and $b) while(1); } +sub dont_warn_40 { next ($a xor $b) while(1); } +sub dont_warn_41 { last ($a or $b) while(1); } +sub dont_warn_42 { last ($a and $b) while(1); } +sub dont_warn_43 { last ($a xor $b) while(1); } +sub dont_warn_44 { redo ($a or $b) while(1); } +sub dont_warn_45 { redo ($a and $b) while(1); } +sub dont_warn_46 { redo ($a xor $b) while(1); } +EXPECT -- 1.7.10.4 ```
p5pRT commented 10 years ago

From @rurban

On Thu\, Jul 18\, 2013 at 6​:05 PM\, Niels Thykier \niels@&#8203;thykier\.net wrote​:

On 2013-07-17 22​:12\, Father Chrysostomos via RT wrote​:

On Wed Jul 17 12​:37​:07 2013\, niels@​thykier.net wrote​:

Included is a patch to add the op_folded member and my previous patch has been rebased on top of it.

RE​: op_folded-patch - I made OPpCONST_FOLDED redundant internally in the code (i.e. perl does the right thing even without it). However\, I left it in (and kept it maintained) for now until B​::Concise can be updated. I presume that will involve exposing op_folded via B.pm\, which I have left as "future work" for now. I made no attempt to have it replace OPf_SPECIAL on the regexp/tr operators either.

Those patches look good. Thank you. Now we just have to wait for Parse​::CPAN​::Meta.

Revised warning patch attached with more tests. Thanks to Reini Urban for smoke testing CPAN and reminding me that exit is a unary operator (so it is not even safe to use "||" with exit).

LGTM.

These are the bugs we found so far​:

Perl-Critic [cpan #87032] wrong return precedence in Perl​::Critic​::Utils​::interpolate YAML-Syck [cpan #87034] precedence error in inc/Test/Builder.pm DBI [cpan #87029] Possible precedence issue with control flow operator at ./t/16destroy.t Git-CPAN-Patch [cpan #86950] wrong return or precedence (fixed) Apache-SWIT [cpan #86949] return expr or precedence error Parse-CPAN-Meta - fixed with 1.4405

JSON-PP (no ticket yet) Test-Simple (no ticket yet)

I needed the following patch to extend B for folded (and the other missing fields)\, and to fix dump.

And the 2nd patch is a hint for the upstream maintainers.

When I fixed all B modules to use the new B\, we can get rid of the OPpCONST_FOLDED and have one more private bit free for CONSTs. B​::C and ByteLoader already done. B-Generate has more problems with blead.

-- Reini Urban http​://cpanel.net/ http​://www.perl-compiler.org/

p5pRT commented 10 years ago

From @rurban

0001-more-op_folded-support-B-dump.patch ```diff From 9c97840a3a4c7538643548513ff282fb21a3ecde Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Thu, 18 Jul 2013 14:50:35 -0500 Subject: [PATCH 1/2] more op_folded support: B, dump also add more B::OP accessors for the missing bitfields --- dump.c | 5 +++-- ext/B/B.xs | 28 ++++++++++++++++++++++++++-- op.h | 2 ++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/dump.c b/dump.c index 6ba4fd2..4720e30 100644 --- a/dump.c +++ b/dump.c @@ -861,13 +861,14 @@ S_op_private_to_names(pTHX_ SV *tmpsv, U32 optype, U32 op_private) { if (o->op_slabbed) sv_catpvs(tmpsv, ",SLABBED"); \ if (o->op_savefree) sv_catpvs(tmpsv, ",SAVEFREE"); \ if (o->op_static) sv_catpvs(tmpsv, ",STATIC"); \ - if (!xml) \ + if (o->op_folded) sv_catpvs(tmpsv, ",FOLDED"); \ + if (!xml) \ Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", \ SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");\ else \ PerlIO_printf(file, " flags=\"%s\"", \ SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); \ - SvREFCNT_dec_NN(tmpsv); \ + SvREFCNT_dec_NN(tmpsv); \ } #if !defined(PERL_MAD) diff --git a/ext/B/B.xs b/ext/B/B.xs index 0b2ecae..a17f876 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -670,7 +670,7 @@ struct OP_methods { STR_WITH_LEN("targ"), PADOFFSETp, offsetof(struct op, op_targ), /* 2*/ STR_WITH_LEN("flags"), U8p, offsetof(struct op, op_flags), /* 3*/ STR_WITH_LEN("private"), U8p, offsetof(struct op, op_private), /* 4*/ - STR_WITH_LEN("first"), OPp, offsetof(struct unop, op_first), /* 5*/ + STR_WITH_LEN("first"), OPp, offsetof(struct unop, op_first), /* 5*/ STR_WITH_LEN("last"), OPp, offsetof(struct binop, op_last), /* 6*/ STR_WITH_LEN("other"), OPp, offsetof(struct logop, op_other), /* 7*/ STR_WITH_LEN("pmreplstart"), 0, -1, /* 8*/ @@ -730,6 +730,14 @@ struct OP_methods { STR_WITH_LEN("warnings"),0, -1, /*44*/ STR_WITH_LEN("io"), 0, -1, /*45*/ STR_WITH_LEN("hints_hash"),0, -1, /*46*/ +#if PERL_VERSION >= 17 + STR_WITH_LEN("slabbed"), 0, -1, /*47*/ + STR_WITH_LEN("savefree"),0, -1, /*48*/ + STR_WITH_LEN("static"), 0, -1, /*49*/ +#if PERL_VERSION >= 19 + STR_WITH_LEN("folded"), 0, -1, /*50*/ +#endif +#endif }; #include "const-c.inc" @@ -1001,6 +1009,10 @@ next(o) B::COP::warnings = 44 B::COP::io = 45 B::COP::hints_hash = 46 + B::OP::slabbed = 47 + B::OP::savefree = 48 + B::OP::static = 49 + B::OP::folded = 50 PREINIT: char *ptr; SV *ret; @@ -1076,10 +1088,22 @@ next(o) case 30: /* type */ case 31: /* opt */ case 32: /* spare */ - /* These 3 are all bitfields, so we can't take their addresses */ +#if PERL_VERSION >= 17 + case 47: /* slabbed */ + case 48: /* savefree */ + case 49: /* static */ +#if PERL_VERSION >= 19 + case 50: /* folded */ +#endif +#endif + /* These are all bitfields, so we can't take their addresses */ ret = sv_2mortal(newSVuv((UV)( ix == 30 ? o->op_type : ix == 31 ? o->op_opt + : ix == 47 ? o->op_slabbed + : ix == 48 ? o->op_savefree + : ix == 49 ? o->op_static + : ix == 50 ? o->op_folded : o->op_spare))); break; case 33: /* children */ diff --git a/op.h b/op.h index dcfd5be..ffb7178 100644 --- a/op.h +++ b/op.h @@ -656,6 +656,8 @@ struct loop { # define OpREFCNT_dec(o) (--(o)->op_targ) #endif +#define OpFOLDED(o) ((o)->type == OP_CONST ? (o)->op_private & OPpCONST_FOLDED : (o)->op_folded) + /* flags used by Perl_load_module() */ #define PERL_LOADMOD_DENY 0x1 /* no Module */ #define PERL_LOADMOD_NOIMPORT 0x2 /* use Module () */ -- 1.8.3.1 ```
p5pRT commented 10 years ago

From @rurban

0002-External-TODOs-for-59802-cpan-JSON-PP-cpan-Test-Simp.patch ```diff From 72758296adbd0c6b838d1a041381b5954bacecd1 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Thu, 18 Jul 2013 11:00:57 -0500 Subject: [PATCH 2/2] External TODOs for #59802 cpan/JSON-PP, cpan/Test-Simple --- cpan/JSON-PP/lib/JSON/PP.pm | 2 +- cpan/Test-Simple/lib/Test/Builder.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpan/JSON-PP/lib/JSON/PP.pm b/cpan/JSON-PP/lib/JSON/PP.pm index e9e65b1..12b7d51 100644 --- a/cpan/JSON-PP/lib/JSON/PP.pm +++ b/cpan/JSON-PP/lib/JSON/PP.pm @@ -1564,7 +1564,7 @@ sub _incr_parse { $self->{incr_text} = substr( $self->{incr_text}, $p ); $self->{incr_p} = 0; - return $obj or ''; + return $obj || ''; } diff --git a/cpan/Test-Simple/lib/Test/Builder.pm b/cpan/Test-Simple/lib/Test/Builder.pm index cb4335f..18e90f5 100644 --- a/cpan/Test-Simple/lib/Test/Builder.pm +++ b/cpan/Test-Simple/lib/Test/Builder.pm @@ -915,7 +915,7 @@ sub _is_dualvar { no warnings 'numeric'; my $numval = $val + 0; - return $numval != 0 and $numval ne $val ? 1 : 0; + return ($numval != 0 and $numval ne $val) ? 1 : 0; } =item B -- 1.8.3.1 ```
p5pRT commented 10 years ago

From @nthykier

On 2013-07-19 06​:22\, Reini Urban wrote​:

On Thu\, Jul 18\, 2013 at 6​:05 PM\, Niels Thykier \niels@&#8203;thykier\.net wrote​:

[...]

Revised warning patch attached with more tests. Thanks to Reini Urban for smoke testing CPAN and reminding me that exit is a unary operator (so it is not even safe to use "||" with exit).

LGTM.

These are the bugs we found so far​:

Perl-Critic [cpan #87032] wrong return precedence in Perl​::Critic​::Utils​::interpolate YAML-Syck [cpan #87034] precedence error in inc/Test/Builder.pm DBI [cpan #87029] Possible precedence issue with control flow operator at ./t/16destroy.t Git-CPAN-Patch [cpan #86950] wrong return or precedence (fixed) Apache-SWIT [cpan #86949] return expr or precedence error Parse-CPAN-Meta - fixed with 1.4405

Great. :)

JSON-PP (no ticket yet) Test-Simple (no ticket yet)

I believe these are filed​:

* https://rt.cpan.org/Public/Bug/Display.html?id=86948 * https://github.com/schwern/test-more/pull/385

I needed the following patch to extend B for folded (and the other missing fields)\, and to fix dump.

And the 2nd patch is a hint for the upstream maintainers.

When I fixed all B modules to use the new B\, we can get rid of the OPpCONST_FOLDED and have one more private bit free for CONSTs. B​::C and ByteLoader already done. B-Generate has more problems with blead.

-- Reini Urban http​://cpanel.net/ http​://www.perl-compiler.org/

Sounds good to me. :)

~Niels

p5pRT commented 10 years ago

From @rurban

CPAN updates on this after the night run​:

+ DBI [cpan #87029] (fixed) * Git-CPAN-Patch [cpan #86950] (fixed) * Parse-CPAN-Meta (fixed)

* Perl-Critic [cpan #87032] * YAML-Syck [cpan #87034] * Apache-SWIT [cpan #86949] + JSON-PP [cpan #86948] + HTML-Mason [cpan #87050] + IO-Async [cpan #87051] + IO-Socket-SSL [cpan #87052] + Test-Simple [cpan #87053] + https://github.com/schwern/test-more/pull/385

all patches also in my distroprefs​: https://github.com/rurban/distroprefs -- Reini Urban http​://cpanel.net/ http​://www.perl-compiler.org/

p5pRT commented 10 years ago

From @cpansprout

On Wed Jul 17 12​:37​:07 2013\, niels@​thykier.net wrote​:

On 2013-07-17 18​:56\, Father Chrysostomos via RT wrote​:

On Wed Jul 17 01​:30​:56 2013\, niels@​thykier.net wrote​:

[...]

You wrote "also set op->op_folded" and later imply the change could simplify the code by using the same bit. Just to confirm here\, did you want the "op_folded" member replace OPpCONST_FOLDED and (for regexp/tr operators) OPf_SPECIAL?

That would be nice. But it is not a prerequisite for getting your patch in. :-)

And if so\, should OPf_SPECIAL still be set in these cases since it is a public flag or should it be cleared so we can repurpose it?

I think (off the top of my head) that B​::Deparse currently uses it. So B​::Deparse may have to change. I don’t remember now.

OPf_SPECIAL is a private flag\, at least in terms of its use\, but stored with the public flags.

Included is a patch to add the op_folded member and my previous patch has been rebased on top of it.

RE​: op_folded-patch - I made OPpCONST_FOLDED redundant internally in the code (i.e. perl does the right thing even without it). However\, I left it in (and kept it maintained) for now until B​::Concise can be updated. I presume that will involve exposing op_folded via B.pm\, which I have left as "future work" for now. I made no attempt to have it replace OPf_SPECIAL on the regexp/tr operators either.

Thank you. I have applied the op_folded patch as 3513c7400.

The warning patch will again have to wait\, as your more thorough version of the patch triggers other warnings\, causing other test failures\, as I am sure you well know.

--

Father Chrysostomos

p5pRT commented 10 years ago

From @cpansprout

On Thu Jul 18 21​:23​:27 2013\, rurban wrote​:

On Thu\, Jul 18\, 2013 at 6​:05 PM\, Niels Thykier \niels@&#8203;thykier\.net wrote​:

On 2013-07-17 22​:12\, Father Chrysostomos via RT wrote​:

On Wed Jul 17 12​:37​:07 2013\, niels@​thykier.net wrote​:

Included is a patch to add the op_folded member and my previous patch has been rebased on top of it.

RE​: op_folded-patch - I made OPpCONST_FOLDED redundant internally in the code (i.e. perl does the right thing even without it). However\, I left it in (and kept it maintained) for now until B​::Concise can be updated. I presume that will involve exposing op_folded via B.pm\, which I have left as "future work" for now. I made no attempt to have it replace OPf_SPECIAL on the regexp/tr operators either.

Those patches look good. Thank you. Now we just have to wait for Parse​::CPAN​::Meta.

Revised warning patch attached with more tests. Thanks to Reini Urban for smoke testing CPAN and reminding me that exit is a unary operator (so it is not even safe to use "||" with exit).

LGTM.

These are the bugs we found so far​:

Perl-Critic [cpan #87032] wrong return precedence in Perl​::Critic​::Utils​::interpolate YAML-Syck [cpan #87034] precedence error in inc/Test/Builder.pm DBI [cpan #87029] Possible precedence issue with control flow operator at ./t/16destroy.t Git-CPAN-Patch [cpan #86950] wrong return or precedence (fixed) Apache-SWIT [cpan #86949] return expr or precedence error Parse-CPAN-Meta - fixed with 1.4405

JSON-PP (no ticket yet) Test-Simple (no ticket yet)

I needed the following patch to extend B for folded (and the other missing fields)\, and to fix dump.

And the 2nd patch is a hint for the upstream maintainers.

When I fixed all B modules to use the new B\, we can get rid of the OPpCONST_FOLDED and have one more private bit free for CONSTs. B​::C and ByteLoader already done. B-Generate has more problems with blead.

Thank you. I have applied the first patch as 3164fde474d1\, but I omitted the OpFOLDED macro\, because I don’t understand its purpose (or need). Niels’ patch changes the core not to use OPpCONST_FOLDED at all\, so having a macro to check that doesn’t help. If it is for B​::C’s sake\, then it won’t be present in older perls anyway\, so you will still have to #define it in B​::C.

--

Father Chrysostomos

p5pRT commented 10 years ago

From @rurban

On Fri\, Jul 19\, 2013 at 12​:30 PM\, Father Chrysostomos via RT \perlbug\-followup@&#8203;perl\.org wrote​:

On Thu Jul 18 21​:23​:27 2013\, rurban wrote​:

On Thu\, Jul 18\, 2013 at 6​:05 PM\, Niels Thykier \niels@&#8203;thykier\.net wrote​:

On 2013-07-17 22​:12\, Father Chrysostomos via RT wrote​:

On Wed Jul 17 12​:37​:07 2013\, niels@​thykier.net wrote​:

Included is a patch to add the op_folded member and my previous patch has been rebased on top of it.

RE​: op_folded-patch - I made OPpCONST_FOLDED redundant internally in the code (i.e. perl does the right thing even without it). However\, I left it in (and kept it maintained) for now until B​::Concise can be updated. I presume that will involve exposing op_folded via B.pm\, which I have left as "future work" for now. I made no attempt to have it replace OPf_SPECIAL on the regexp/tr operators either.

Those patches look good. Thank you. Now we just have to wait for Parse​::CPAN​::Meta.

Revised warning patch attached with more tests. Thanks to Reini Urban for smoke testing CPAN and reminding me that exit is a unary operator (so it is not even safe to use "||" with exit).

LGTM.

These are the bugs we found so far​:

Perl-Critic [cpan #87032] wrong return precedence in Perl​::Critic​::Utils​::interpolate YAML-Syck [cpan #87034] precedence error in inc/Test/Builder.pm DBI [cpan #87029] Possible precedence issue with control flow operator at ./t/16destroy.t Git-CPAN-Patch [cpan #86950] wrong return or precedence (fixed) Apache-SWIT [cpan #86949] return expr or precedence error Parse-CPAN-Meta - fixed with 1.4405

JSON-PP (no ticket yet) Test-Simple (no ticket yet)

I needed the following patch to extend B for folded (and the other missing fields)\, and to fix dump.

And the 2nd patch is a hint for the upstream maintainers.

When I fixed all B modules to use the new B\, we can get rid of the OPpCONST_FOLDED and have one more private bit free for CONSTs. B​::C and ByteLoader already done. B-Generate has more problems with blead.

Thank you. I have applied the first patch as 3164fde474d1\, but I omitted the OpFOLDED macro\, because I don’t understand its purpose (or need). Niels’ patch changes the core not to use OPpCONST_FOLDED at all\, so having a macro to check that doesn’t help. If it is for B​::C’s sake\, then it won’t be present in older perls anyway\, so you will still have to #define it in B​::C.

Thanks and I'm fine with that. It thought it's a cool API for the time when we have both. But I haven't found a usecase for it yet.

So missing are​:

commit 715975678ef3c57515eb6282cdaab53da6afbb46 Author​: Niels Thykier \niels@&#8203;thykier\.net Date​: Mon Jul 15 22​:25​:19 2013 +0200

  op.c​: Warn on "return $a or $b" [perl #59802]

  Add a warning for the (likely) unintended use of "return $a or $b"   (and similar expressions)\, which perl parses as "(return $a) || $b"   (which is effectively just "return $a;").

  Note this warning is triggered by some modules (e.g. Test​::Builder).   These are not fixed by this commit.

  Signed-off-by​: Niels Thykier \niels@&#8203;thykier\.net

commit c1f7aff8b732c59411569240ce4ffc7a83080e33 Author​: Reini Urban \rurban@&#8203;x\-ray\.at Date​: Thu Jul 11 12​:09​:15 2013 -0500

  Return B​::HEK for B​::CV​::GV of lexical subs

  A lexsub has a hek instead of a gv.   Provide a ref to a PV for the name in the new B​::HEK class.   This crashed previously accessing the not existing SvFLAGS of the hek.

-- Reini Urban http​://cpanel.net/ http​://www.perl-compiler.org/

p5pRT commented 10 years ago

From @rjbs

* Niels Thykier \niels@&#8203;thykier\.net [2013-07-16T04​:58​:01]

Here is a revised patch. [
] The warning is now emitted for any of the following ops​: OP_{NEXT\,LAST\,REDO\,RETURN\,DIE\,EXIT\,GOTO}

Thanks\, Niels\, this warning is something I'm very happy to see finally happening!

-- rjbs

p5pRT commented 10 years ago

From @cpansprout

On Mon Jul 22 14​:59​:51 2013\, perl.p5p@​rjbs.manxome.org wrote​:

* Niels Thykier \niels@&#8203;thykier\.net [2013-07-16T04​:58​:01]

Here is a revised patch. [
] The warning is now emitted for any of the following ops​: OP_{NEXT\,LAST\,REDO\,RETURN\,DIE\,EXIT\,GOTO}

Thanks\, Niels\, this warning is something I'm very happy to see finally happening!

This is currently blocked by Test​::Builder. If we are to have this warning\, we probably ought to have it present in bleadperl for as long as possible\, in order to shake out CPAN bugs.

Would it be acceptable to break the usual rule and patch Test​::Builder directly in blead (assigning it a previously unused dev version)?

--

Father Chrysostomos

p5pRT commented 10 years ago

From @rjbs

* Father Chrysostomos via RT \perlbug\-followup@&#8203;perl\.org [2013-08-20T11​:51​:46]

Would it be acceptable to break the usual rule and patch Test​::Builder directly in blead (assigning it a previously unused dev version)?

I've just poked Schwern both via GitHub and another channel. Let's give him a day or two to state his intentions before patching blead... which we should do if needed. (and if you do that\, please add a ticket to #116923 which I will follow up on)

-- rjbs

p5pRT commented 10 years ago

From @rjbs

* Ricardo Signes \perl\.p5p@&#8203;rjbs\.manxome\.org [2013-08-22T22​:17​:24]

I've just poked Schwern both via GitHub and another channel. Let's give him a day or two to state his intentions before patching blead... which we should do if needed. (and if you do that\, please add a ticket to #116923 which I will follow up on)

FWIW\, Schwern is now AFK for a week or so.

-- rjbs

p5pRT commented 10 years ago

From @cpansprout

On Sun Aug 25 21​:28​:46 2013\, perl.p5p@​rjbs.manxome.org wrote​:

* Ricardo Signes \perl\.p5p@&#8203;rjbs\.manxome\.org [2013-08-22T22​:17​:24]

I've just poked Schwern both via GitHub and another channel. Let's give him a day or two to state his intentions before patching blead... which we should do if needed. (and if you do that\, please add a ticket to #116923 which I will follow up on)

FWIW\, Schwern is now AFK for a week or so.

What does AFK stand for? Asking for kippers?

--

Father Chrysostomos

p5pRT commented 10 years ago

From @tux

On Mon\, 26 Aug 2013 00​:09​:12 -0700\, "Father Chrysostomos via RT" \perlbug\-followup@&#8203;perl\.org wrote​:

On Sun Aug 25 21​:28​:46 2013\, perl.p5p@​rjbs.manxome.org wrote​:

* Ricardo Signes \perl\.p5p@&#8203;rjbs\.manxome\.org [2013-08-22T22​:17​:24]

I've just poked Schwern both via GitHub and another channel. Let's give him a day or two to state his intentions before patching blead... which we should do if needed. (and if you do that\, please add a ticket to #116923 which I will follow up on)

FWIW\, Schwern is now AFK for a week or so.

What does AFK stand for? Asking for kippers?

Away From Keyboard

http​://www.acronymfinder.com/Away-From-Keyboard-(AFK).html

-- H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/ using perl5.00307 .. 5.19 porting perl5 on HP-UX\, AIX\, and openSUSE http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/ http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

p5pRT commented 10 years ago

From @rurban

On Tue\, Aug 20\, 2013 at 10​:51 AM\, Father Chrysostomos via RT \perlbug\-followup@&#8203;perl\.org wrote​:

On Mon Jul 22 14​:59​:51 2013\, perl.p5p@​rjbs.manxome.org wrote​:

* Niels Thykier \niels@&#8203;thykier\.net [2013-07-16T04​:58​:01]

Here is a revised patch. [
] The warning is now emitted for any of the following ops​: OP_{NEXT\,LAST\,REDO\,RETURN\,DIE\,EXIT\,GOTO}

Thanks\, Niels\, this warning is something I'm very happy to see finally happening!

This is currently blocked by Test​::Builder. If we are to have this warning\, we probably ought to have it present in bleadperl for as long as possible\, in order to shake out CPAN bugs.

All possible CPAN bugs have already been reported by smoking CPAN with a patched bleadperl with these warning enabled last month. The fastest response was from DBI\, the slowest seems to be Test​::Builder. Now only BlackPAN is the problem. Our own company blackpan was okay.

See http​://blogs.perl.org/users/rurban/2013/07/smoking-cpan.html All necessary distroprefs patches are in my repo https://github.com/rurban/distroprefs

Would it be acceptable to break the usual rule and patch Test​::Builder directly in blead (assigning it a previously unused dev version)?

-- Reini Urban http​://cpanel.net/ http​://www.perl-compiler.org/

p5pRT commented 10 years ago

From @cpansprout

On Thu Aug 22 19​:17​:59 2013\, perl.p5p@​rjbs.manxome.org wrote​:

* Father Chrysostomos via RT \perlbug\-followup@&#8203;perl\.org [2013-08- 20T11​:51​:46]

Would it be acceptable to break the usual rule and patch Test​::Builder directly in blead (assigning it a previously unused dev version)?

I've just poked Schwern both via GitHub and another channel. Let's give him a day or two to state his intentions before patching blead... which we should do if needed. (and if you do that\, please add a ticket to #116923 which I will follow up on)

I have applied Niels’ warning patch now as 9da2d0467dc5 (thank you). His precedence patch has been applied as 13c65ef8cd5.

I have opened ticket #119825 to track this.

--

Father Chrysostomos

p5pRT commented 10 years ago

@cpansprout - Status changed from 'open' to 'resolved'