Skip to content
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

[PATCH] Fix RTCPAN#107225 : Carp::longmess() returns "1" when passed a reference and called in scalar context #15217

Closed
p5pRT opened this issue Mar 6, 2016 · 9 comments
Labels

Comments

@p5pRT
Copy link

p5pRT commented Mar 6, 2016

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

Searchable as RT127664$

@p5pRT
Copy link
Author

p5pRT commented Mar 6, 2016

From @shlomif

Hi all,

these two patches [against bleadperl] fix
https://rt.cpan.org/Public/Bug/Display.html?id=107225 with a test. Thanks to
rjbs for some guidance.

As usual, I hereby disclaim any explicit or implict ownership of my changes and
put them under the PD/CC0/MIT-X11/Same-terms-as-Perl/your-licence-of-choice.

They can also be found here​:

https://github.com/shlomif/perl5/tree/shlomif--Carp.pm-improvements

Regards,

  Shlomi Fish

@p5pRT
Copy link
Author

p5pRT commented Mar 6, 2016

From @shlomif

0001-Fix-RTCPAN-107225-longmess-returns-1-on-ref.patch
From bed5a3a3196a6af7e372496c96b105fbf572ccd5 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 6 Mar 2016 20:37:25 +0200
Subject: [PATCH 1/2] Fix RTCPAN#107225 : longmess returns 1 on ref.

See: https://rt.cpan.org/Public/Bug/Display.html?id=107225 . Also
discovered as a bug in perl -d by me (= Shlomi Fish) and reported
after the original report. longmess() returns "1" when called in scalar
context if passed a reference.
---
 dist/Carp/lib/Carp.pm       |  6 ++++--
 dist/Carp/lib/Carp/Heavy.pm |  2 +-
 dist/Carp/t/Carp.t          | 20 +++++++++++++++++++-
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/dist/Carp/lib/Carp.pm b/dist/Carp/lib/Carp.pm
index 9421c74..9a29872 100644
--- a/dist/Carp/lib/Carp.pm
+++ b/dist/Carp/lib/Carp.pm
@@ -87,7 +87,7 @@ BEGIN {
     }
 }
 
-our $VERSION = '1.38';
+our $VERSION = '1.38_01';
 $VERSION =~ tr/_//d;
 
 our $MaxEvalLen = 0;
@@ -445,7 +445,9 @@ sub long_error_loc {
 }
 
 sub longmess_heavy {
-    return @_ if ref( $_[0] );    # don't break references as exceptions
+    if ( ref( $_[0] ) ) {   # don't break references as exceptions
+        return wantarray ? @_ : $_[0];
+    }
     my $i = long_error_loc();
     return ret_backtrace( $i, @_ );
 }
diff --git a/dist/Carp/lib/Carp/Heavy.pm b/dist/Carp/lib/Carp/Heavy.pm
index 91a42d1..1a2ff3a 100644
--- a/dist/Carp/lib/Carp/Heavy.pm
+++ b/dist/Carp/lib/Carp/Heavy.pm
@@ -2,7 +2,7 @@ package Carp::Heavy;
 
 use Carp ();
 
-our $VERSION = '1.38';
+our $VERSION = '1.38_01';
 $VERSION =~ tr/_//d;
 
 # Carp::Heavy was merged into Carp in version 1.12.  Any mismatched versions
diff --git a/dist/Carp/t/Carp.t b/dist/Carp/t/Carp.t
index a18e3b4..9ecdf88 100644
--- a/dist/Carp/t/Carp.t
+++ b/dist/Carp/t/Carp.t
@@ -3,7 +3,7 @@ no warnings "once";
 use Config;
 
 use IPC::Open3 1.0103 qw(open3);
-use Test::More tests => 65;
+use Test::More tests => 66;
 
 sub runperl {
     my(%args) = @_;
@@ -39,6 +39,24 @@ BEGIN {
   );
 }
 
+package MyClass;
+
+sub new { return bless +{ field => ['value1', 'SecondVal'] }; }
+
+package main;
+
+{
+    my $err = Carp::longmess(MyClass->new);
+
+    # See:
+    # https://rt.cpan.org/Public/Bug/Display.html?id=107225
+    is_deeply(
+        $err->{field},
+        ['value1', 'SecondVal',],
+        "longmess returns sth meaningful in scalar context when passed a ref.",
+    );
+}
+
 {
     local $SIG{__WARN__} = sub {
         like $_[0], qr/ok (\d+)\n at.+\b(?i:carp\.t) line \d+\.$/, 'ok 2\n';
-- 
2.7.2

@p5pRT
Copy link
Author

p5pRT commented Mar 6, 2016

From @shlomif

0002-Document-the-previous-commit-in-Carp-s-Changes.patch
From a6e6148720e7165a2ef5997944f88581c984e9b1 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 6 Mar 2016 20:52:03 +0200
Subject: [PATCH 2/2] Document the previous commit in Carp's Changes.

---
 dist/Carp/Changes | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/dist/Carp/Changes b/dist/Carp/Changes
index b55b49f..24c0447 100644
--- a/dist/Carp/Changes
+++ b/dist/Carp/Changes
@@ -1,4 +1,8 @@
 
+version 1.38_01; 2016-03-06
+  * bugfix: longmess() should return the error in scalar context
+  (CPANRT#107225)
+
 version 1.38; 2015-11-06
   * stable release of changes since v1.36
 
-- 
2.7.2

@p5pRT
Copy link
Author

p5pRT commented Mar 7, 2016

From @tonycoz

On Sun Mar 06 11​:12​:08 2016, shlomif@​shlomifish.org wrote​:

Hi all,

these two patches [against bleadperl] fix
https://rt.cpan.org/Public/Bug/Display.html?id=107225 with a test.
Thanks to
rjbs for some guidance.

Applied as 6ca94a7 and 999ef43.

I changed the version number to 1.39.

Tony

@p5pRT
Copy link
Author

p5pRT commented Mar 7, 2016

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 7, 2016

@tonycoz - Status changed from 'open' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented Mar 7, 2016

From @shlomif

On Sun, 6 Mar 2016 20​:47​:00 -0800
"Tony Cook via RT" <perlbug-followup@​perl.org> wrote​:

On Sun Mar 06 11​:12​:08 2016, shlomif@​shlomifish.org wrote​:

Hi all,

these two patches [against bleadperl] fix
https://rt.cpan.org/Public/Bug/Display.html?id=107225 with a test.
Thanks to
rjbs for some guidance.

Applied as 6ca94a7 and
999ef43.

I changed the version number to 1.39.

Thanks, Tony!

Regards,

  Shlomi Fish

Tony

--


Shlomi Fish http​://www.shlomifish.org/
Beginners Site for the Vim text editor - http​://vim.begin-site.org/

Well, one thing I can tell you about parenthood is that such things
can progress from figurative to literal, extremely quickly.
  — http​://www.shlomifish.org/humour/Summerschool-at-the-NSA/

Please reply to list if it's a mailing list post - http​://shlom.in/reply .

@p5pRT
Copy link
Author

p5pRT commented May 13, 2016

From @khwilliamson

Thank you for submitting this report. You have helped make Perl better.
 
With the release of Perl 5.24.0 on May 9, 2016, this and 149 other issues have been resolved.

Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0

@p5pRT p5pRT closed this as completed May 13, 2016
@p5pRT
Copy link
Author

p5pRT commented May 13, 2016

@khwilliamson - Status changed from 'pending release' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant