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
Data::Dumper: Useqq interacts badly with overloading #7519
Comments
From zefram@fysh.orgCreated by zefram@fysh.orgI'm using Data::Dumper to display Perl objects for debugging purposes. $ perl -MData::Dumper -e 'package foo; use overload "cmp" => sub { 0 }; package main; $Data::Dumper::Useqq = 1; print Dumper(bless({}, "foo"))' If either the "use overload" statement or the setting of Useqq is removed $ perl -MData::Dumper -e 'package foo; package main; $Data::Dumper::Useqq = 1; print Dumper(bless({}, "foo"))' Setting the Useperl option, which I tried in hope of working around this Perl Info
|
From @demerphq
You may want to try Data::Dump::Streamer instead. Especially if the primary
The XS does it right then, and the Pure Perl code doesn't. Now we know where
This is to be expected as Useqq implies Useperl currently. Only the Pure HTH, |
The RT System itself - Status changed from 'new' to 'open' |
From rick@bort.caOn Fri, Oct 01, 2004 at 03:21:20PM -0000, Zefram wrote:
The problem is not the overloading of 'cmp', but that "foo" objects are -- |
From zefram@fysh.orgRick Delaney via RT wrote:
The object has no reasonable stringification, but does have meaningful
Interesting. I've not come across this concept of "incompletely -zefram |
From rick@bort.caOn Fri, Oct 01, 2004 at 06:49:30PM +0100, Zefram wrote:
Don't know.
That's what I usually do and I wish it was the default. It would also be
That's a good question. I guess the exception is being raised when it's -- |
From rick@bort.caOn Fri, Oct 01, 2004 at 03:21:20PM -0000, Zefram wrote:
That patch below fixes this. You can see that it used to try to call -- Inline Patch--- lib/overload.pm.orig Sat Oct 2 00:28:13 2004
+++ lib/overload.pm Sat Oct 2 00:28:18 2004
@@ -94,7 +94,7 @@
}
sub StrVal {
- (ref $_[0] && OverloadedStringify($_[0]) or ref($_[0]) eq 'Regexp') ?
+ (ref $_[0] && Overloaded($_[0]) or ref($_[0]) eq 'Regexp') ?
(AddrRef(shift)) :
"$_[0]";
}
--- lib/overload.t.orig Sat Oct 2 00:32:50 2004
+++ lib/overload.t Sat Oct 2 00:46:10 2004
@@ -1097,8 +1097,6 @@
test (!defined eval { $a->{b} });
test ($@ =~ /zap/);
-test (overload::StrVal(qr/a/) =~ /^Regexp=SCALAR\(0x[0-9a-f]+\)$/);
-
{
package t229;
use overload '=' => sub { 42 },
@@ -1139,6 +1137,23 @@
sub numify { ${$_[0]} }
}
+{
+ package perl31793;
+ use overload cmp => sub { 0 };
+ package main;
+ my $o = bless [], 'perl31793';
+ my $no = bless [], 'no_overload';
+ test (overload::StrVal(\"scalar") =~ /^SCALAR\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal([]) =~ /^ARRAY\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal({}) =~ /^HASH\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal(sub{1}) =~ /^CODE\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal(\*GLOB) =~ /^GLOB\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal(\$o) =~ /^REF\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal(qr/a/) =~ /^Regexp=SCALAR\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal($o) =~ /^perl31793=ARRAY\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal($no) =~ /^no_overload=ARRAY\(0x[0-9a-f]+\)$/);
+}
+
# These are all check that overloaded values rather than reference addressess
# are what is getting tested.
my ($two, $one, $un, $deux) = map {new Numify $_} 2, 1, 1, 2;
@@ -1160,4 +1175,4 @@
}
}
# Last test is:
-sub last {484}
+sub last {492} |
From perl_dummy@bloodgate.com-----BEGIN PGP SIGNED MESSAGE----- moin, Re: [perl #31793] Data::Dumper: Useqq interacts badly with overloading Rick wrote:
See below for some ideas.
I don't know if that is possible. It is always possible to make "incomplete"
Instead of tracing to Dumper, I simple tried to add a '""' overload and die ############################### package foo; use overload "cmp" => sub { 0 }, package main; use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper(bless({}, "foo")); However, that simple prints: $VAR1 = bless( {}, 'foo' ); on my system. Maybe this is a problem in overload.pm. overload.pm line 97 Data::Dumper /usr/lib/perl5/5.8.3/i586-linux-thread-multi/Data/Dumper.pm 239 And *this* is: ($realpack, $realtype, $id) = Somebody else might have an insight why overload.pm stringifies the object Best wishes, Tels "Naturally the parameter and boundary of their respective position and -----BEGIN PGP SIGNATURE----- iQEVAwUBQV586ncLPEOTuEwVAQHPdAf+PJD1/pYR0LLSBNcGxFI+I5j701S7NJNS |
From @rgsRick Delaney wrote:
Thanks, applied to bleadperl as #23347. |
From @nwc10On Sat, Oct 02, 2004 at 01:04:49AM -0400, Rick Delaney wrote:
This seems to be doing something really horrible to URI, which fails use overload ('""' => sub { ${$_[0]} }, I can't work out why it's failing either - there's something really strange 1..4 which fails on the last line of this script snippet: #!/usr/bin/perl -w print "1..4\n"; use strict; my $uri = URI->new("http://www.example.com/foo/bar/"); print "not " unless $uri->rel("http://www.example.com/foo/bar/") eq "./"; print "not " unless $uri->rel("HTTP://WWW.EXAMPLE.COM/foo/bar/") eq "./"; The error report is generated in Perl_amagic_call in gv.c. I don't understand print "not " unless $uri->rel("http://www.examplE.com/foo/bar/") eq "./"; The change is also breaking Fotango work code, so I've backed it out of maint Nicholas Clark |
From rick@bort.caOn Sat, Oct 23, 2004 at 08:22:28PM +0100, Nicholas Clark wrote:
It passes in blead for me too but I think that's just a fluke. I think the This is what I think is happening (somewhat simplified): URI::http inherits from URI which is overloaded and has set Perl initializes fallback in Gv_AMupdate by checking the glob returned Using the returned glob, the actual fallback state can be checked: *URI::fallback{SCALAR}; which is set to 1. So far, so good. But gv_fetchmeth caches methods it finds. Now when Gv_AMupdate is I'm not entirely sure what triggers Gv_AMupdate to be called and I'm not really sure how this should be fixed. I see a few options: 1. Don't cache fallback method. Whatever we do, we should define fallback inheritance properly. The Note. "fallback" inheritance via @ISA is not carved in plus a couple of other warnings. Hope this helps.
-- |
From rick@bort.caOn Mon, Oct 25, 2004 at 12:27:07AM -0400, Rick Delaney wrote:
Looking further, it appears that Gv_AMupdate tries to avoid this caching $package->can('()'); and C<can> calls gv_fetchmethod_autoload which in turn calls Still, this patchlet does make the problem disappear in 5.8.5. Inline Patch--- gv.c.orig Mon Oct 25 11:02:26 2004
+++ gv.c Mon Oct 25 12:32:39 2004
@@ -441,7 +441,8 @@
ostash = stash;
}
- gv = gv_fetchmeth(stash, name, nend - name, 0);
+ gv = gv_fetchmeth(stash, name, nend - name,
+ strEQ(name,"()") ? -1 : 0);
if (!gv) {
if (strEQ(name,"import") || strEQ(name,"unimport"))
gv = (GV*)&PL_sv_yes;
It's called by C<bless>. What is upsetting the values of -- Inline Patch--- perl-current/lib/overload.pm Mon Oct 4 12:08:29 2004
+++ perl-dev/lib/overload.pm Mon Oct 25 15:06:27 2004
@@ -51,7 +51,11 @@
sub Overloaded {
my $package = shift;
$package = ref $package if ref $package;
- $package->can('()');
+ return 1 if defined &{ "$package\::()" };
+ for my $pkg (@{"$package\::ISA"}) {
+ return 1 if Overloaded($pkg);
+ }
+ return 0;
}
sub ov_method { |
From @nwc10On Mon, Oct 25, 2004 at 03:21:15PM -0400, Rick Delaney wrote:
I have this feeling that we still don't fully understand the cause of the Nicholas Clark |
From rick@bort.caOn Sat, Oct 30, 2004 at 04:59:05PM +0100, Nicholas Clark wrote:
I agree, and might even write the tests if someone could describe how -- |
From @rgsRick Delaney wrote:
Maybe what we need is a version of can() that doesn't try to autoload ? |
From rick@bort.caOn Mon, Nov 01, 2004 at 10:09:11PM +0100, Rafael Garcia-Suarez wrote:
Can we get by with just adding an extra arg to can()? Better make it a Why do we have two separate method fetchers (gv_fetchmeth and -- |
From @rgsRick Delaney wrote:
It appears that overload already provides a mycan function that does The more I think about it, the more I come to the conclusion that Index: lib/overload.pm--- lib/overload.pm (revision 4009) sub StrVal {
|
From @rgsRafael Garcia-Suarez wrote:
I've applied this patch as #23469. The problem coming from Data::Dumper, |
From @rgsZefram wrote:
Resuming the situation, the following program fails with the current use Data::Dumper;package foo;use overload cmp=>sub{0};package main; (as you see it's not the fault of Useqq -- Useqq only selects the This happens because Data::Dumper uses the stringified form of the Drawbacks: it uses Scalar::Util :) (which is in the core now) (and it So, Ilya, if you could integrate something like this in the next Index: ext/Data/Dumper/Dumper.pm--- ext/Data/Dumper/Dumper.pm (revision 4009) +sub init_refaddr_format { $s = $s->new(@_) unless ref $s; @@ -236,8 +249,10 @@ - ($realpack, $realtype, $id) = # if it has a name, we need to either look it up, or keep a tab |
From rick@bort.caOn Wed, Nov 03, 2004 at 12:20:12PM +0100, Rafael Garcia-Suarez wrote:
Oh, I didn't notice that. I think we should just use that then.
Yes, see below.
I still think that this is wrong because it mean that overload::StrVal($overloaded_object); will croak if there is no stringify or fallback. I think it should work
You just deleted some tests! It's good to have tests for use overload cmp => sub { 0 }, fallback => 1; but we still need tests for use overload cmp => sub { 0 }; . -- |
From @rgsRick Delaney wrote:
Hmm, in this case I don't see why StrVal needs to check that its Index: lib/overload.pm--- lib/overload.pm (revision 4014) -sub StrVal { sub mycan { # Real can would leave stubs.
|
From rick@bort.caOn Wed, Nov 03, 2004 at 05:25:31PM +0100, Rafael Garcia-Suarez wrote:
You're right, that's a better fix. But I think the addition of the test Replacement patch follows .sig. -- Inline Patchdiff -pruN perl-current/lib/overload.pm perl-current-dev/lib/overload.pm
--- perl-current/lib/overload.pm Wed Nov 3 08:20:38 2004
+++ perl-current-dev/lib/overload.pm Wed Nov 3 19:12:13 2004
@@ -93,11 +93,7 @@ sub AddrRef {
return sprintf("$class_prefix$type(0x%x)", $addr);
}
-sub StrVal {
- (ref $_[0] && OverloadedStringify($_[0]) or ref($_[0]) eq 'Regexp') ?
- (AddrRef(shift)) :
- "$_[0]";
-}
+*StrVal = *AddrRef;
sub mycan { # Real can would leave stubs.
my ($package, $meth) = @_;
diff -pruN perl-current/lib/overload.t perl-current-dev/lib/overload.t
--- perl-current/lib/overload.t Wed Nov 3 08:20:38 2004
+++ perl-current-dev/lib/overload.t Wed Nov 3 19:15:26 2004
@@ -1139,9 +1139,12 @@ test ($@ =~ /zap/);
{
package perl31793;
+ use overload cmp => sub { 0 };
+ package perl31793_fb;
use overload cmp => sub { 0 }, fallback => 1;
package main;
my $o = bless [], 'perl31793';
+ my $of = bless [], 'perl31793_fb';
my $no = bless [], 'no_overload';
test (overload::StrVal(\"scalar") =~ /^SCALAR\(0x[0-9a-f]+\)$/);
test (overload::StrVal([]) =~ /^ARRAY\(0x[0-9a-f]+\)$/);
@@ -1151,6 +1154,7 @@ test ($@ =~ /zap/);
test (overload::StrVal(\$o) =~ /^REF\(0x[0-9a-f]+\)$/);
test (overload::StrVal(qr/a/) =~ /^Regexp=SCALAR\(0x[0-9a-f]+\)$/);
test (overload::StrVal($o) =~ /^perl31793=ARRAY\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal($of) =~ /^perl31793_fb=ARRAY\(0x[0-9a-f]+\)$/);
test (overload::StrVal($no) =~ /^no_overload=ARRAY\(0x[0-9a-f]+\)$/);
}
@@ -1199,4 +1203,4 @@ foreach my $op (qw(<=> == != < <= > >=))
# Last test is:
-sub last {496}
+sub last {497} |
From @rgsRick Delaney wrote:
Thanks, applied as #23470 to bleadperl. |
@smpeters - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#31793 (status was 'resolved')
Searchable as RT31793$
The text was updated successfully, but these errors were encountered: