Closed p5pRT closed 21 years ago
use overload '""' => sub { my $obj = shift; "\<object at ".sprintf('0x%x>'\,0+$obj).">"; }\, "0+" => sub { $_[0] }\, fallback => 1;
use Test;
BEGIN { plan tests => 1 };
ok(bless{}\, __PACKAGE__);
The overload construction works for everything else\, but fails horrible on Test.
On Thu\, Dec 13\, 2001 at 12:37:50PM -0500\, Simon Cozens wrote:
use overload '""' => sub { my $obj = shift; "\<object at ".sprintf('0x%x>'\,0+$obj).">"; }\, "0+" => sub { $_[0] }\, fallback => 1;
use Test;
BEGIN { plan tests => 1 };
ok(bless{}\, __PACKAGE__);
The overload construction works for everything else\, but fails horrible on Test.
Hmmm\, its choking on line 258 of Test.pm
256 } else { 257 # Issuing two seperate prints() causes problems on VMS. 258==> if (!$ok) { 259: print $TESTOUT "not ok $ntest\n"; 260 } 261 else { 262: print $TESTOUT "ok $ntest\n"; 263 }
$ok being the overloaded object after being copied a few times.
it pauses at that point for a while in the debugger\, if you give it a sigint you're inside the 0+ sub.
I can't get it to fail any other way than by running it through ok(). Bizarre.
--
Michael G. Schwern \schwern@​pobox\.com http://www.pobox.com/~schwern/ Perl Quality Assurance \perl\-qa@​perl\.org Kwalitee Is Job One If you got the wax out of your ears you could hear the twister picking up the trailer park of your future!
-----BEGIN PGP SIGNED MESSAGE-----
Moin\,
not here:
te@null:\~ > cat overload.pl #!/usr/bin/perl -w
use overload '""' => sub { my $obj = shift; "\<object at ".sprintf('0x%x>'\,0+$obj).">"; }\, "0+" => sub { $_[0] }\, fallback => 1;
use Test;
BEGIN { plan tests => 1 };
ok(bless{}\, __PACKAGE__); te@null:\~ > perl overload.pl 1..1 ok 1 te@null:\~ > perl -v
This is perl\, v5.6.1 built for i686-linux
Cheers\,
Tels
- -- perl -MDev::Bollocks -e'print Dev::Bollocks->rand()\,"\n"' advantageously incentivize out-of-the-box market-growth
http://bloodgate.com/perl My current Perl projects PGP key available on http://bloodgate.com/tels.asc or via email
-----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: latin1
iQEVAwUBPBjiG3cLPEOTuEwVAQFPBwf+MO2BAgCeumJcC52WSBW/ssFnjCYEIbhC vb8wdaCWeTL5kju9xWHFBXaxCLoBQD8K4ZpDrZA6/PDfr4YITxwY6vXIKfPO7XDe jT42Bw3RM0Bx+bq5vBkbnESQJWvvGAwlotDu3Zh4dJqWExeOflsds++slRJkossr BAqcEay0uYEY00IzJwxbkWQGNSpZ81vsPYcuBTm1N78Vmd5qdty1lFlWvImNSnm2 8js1On+skX6TNqDNANk+a4Gjw8ZCDKRYYrkM/h6PZPhJG0fvOcyP7ZlqfcizJuFk 58BsaX+n0W1O+9Z12X0hyZpNL7YtjInUOq474rMLCKcD46q7t2qDRw== =P+CU -----END PGP SIGNATURE-----
On Thu\, Dec 13\, 2001 at 07:15:52PM +0100\, Tels wrote:
not here:
Yes\, it appears to be a bleadperl thing.
The trouble is Perl_sv_2bool is going into infinite recursion:
#0 Perl_sv_setsv_flags (dstr=0x104580e0\, sstr=0x104580d4\, flags=2) at sv.c:3525 #1 0x100c621c in Perl_sv_mortalcopy (oldstr=0x104580d4) at sv.c:6118 #2 0x100b024c in Perl_pp_leavesub () at pp_hot.c:2218 #3 0x10088c60 in Perl_runops_debug () at dump.c:1391 #4 0x10028934 in Perl_amagic_call (left=0x104580d4\, right=0x10196e40\, method=2\, flags=9) at gv.c:1665 #5 0x100bd004 in Perl_sv_2bool (sv=0x104580d4) at sv.c:3237 #6 0x100bd168 in Perl_sv_2bool (sv=0x104580c8) at sv.c:3239 #7 0x100bd168 in Perl_sv_2bool (sv=0x104580bc) at sv.c:3239 #8 0x100bd168 in Perl_sv_2bool (sv=0x104580b0) at sv.c:3239 #9 0x100bd168 in Perl_sv_2bool (sv=0x104580a4) at sv.c:3239 #10 0x100bd168 in Perl_sv_2bool (sv=0x10458098) at sv.c:3239 #11 0x100bd168 in Perl_sv_2bool (sv=0x1045808c) at sv.c:3239 #12 0x100bd168 in Perl_sv_2bool (sv=0x10458080) at sv.c:3239 #13 0x100bd168 in Perl_sv_2bool (sv=0x10458074) at sv.c:3239 #14 0x100bd168 in Perl_sv_2bool (sv=0x10458068) at sv.c:3239 #15 0x100bd168 in Perl_sv_2bool (sv=0x1045805c) at sv.c:3239 #16 0x100bd168 in Perl_sv_2bool (sv=0x10458050) at sv.c:3239 #17 0x100bd168 in Perl_sv_2bool (sv=0x10458044) at sv.c:3239 #18 0x100bd168 in Perl_sv_2bool (sv=0x10458038) at sv.c:3239 #19 0x100bd168 in Perl_sv_2bool (sv=0x1045802c) at sv.c:3239 #20 0x100bd168 in Perl_sv_2bool (sv=0x10458020) at sv.c:3239 .... #14854 0x100bd168 in Perl_sv_2bool (sv=0x108e4b20) at sv.c:3239 #14855 0x100bd168 in Perl_sv_2bool (sv=0x108e4b14) at sv.c:3239
at this point I stopped scrolling back through the bt.
Here's the point where it goes off into oblivion:
#0 Perl_sv_2bool (sv=0x101a6acc) at sv.c:3237 #1 0x100bd168 in Perl_sv_2bool (sv=0x101a69dc) at sv.c:3239 #2 0x100bd168 in Perl_sv_2bool (sv=0x101a69c4) at sv.c:3239 #3 0x100bd168 in Perl_sv_2bool (sv=0x101a69d0) at sv.c:3239 #4 0x1002901c in Perl_amagic_call (left=0x10202ddc\, right=0x10196e40\, method=42\, flags=9) at gv.c:1699 #5 0x100ddf38 in Perl_pp_not () at pp.c:2206 #6 0x10088c60 in Perl_runops_debug () at dump.c:1391 #7 0x10018b8c in S_run_body (oldscope=1) at perl.c:1602 #8 0x10018564 in perl_run (my_perl=0x10199408) at perl.c:1523 #9 0x10013e18 in main (argc=3\, argv=0x7ffffb64\, env=0x7ffffb74) at perlmain.c:76 #10 0x0fdd8a30 in __libc_start_main () from /lib/libc.so.6
te@null:\~ > cat overload.pl #!/usr/bin/perl -w
use overload '""' => sub { my $obj = shift; "\<object at ".sprintf('0x%x>'\,0+$obj).">"; }\, "0+" => sub { $_[0] }\, fallback => 1;
use Test;
BEGIN { plan tests => 1 };
ok(bless{}\, __PACKAGE__); te@null:\~ > perl overload.pl 1..1 ok 1 te@null:\~ > perl -v
This is perl\, v5.6.1 built for i686-linux
--
Michael G. Schwern \schwern@​pobox\.com http://www.pobox.com/~schwern/ Perl Quality Assurance \perl\-qa@​perl\.org Kwalitee Is Job One Do you have a map? Because I keep getting lost in your armpits.
-----BEGIN PGP SIGNED MESSAGE-----
Moin\,
On 18-Dec-01 Michael G Schwern tried to scribble about:
On Thu\, Dec 13\, 2001 at 07:15:52PM +0100\, Tels wrote:
not here:
Yes\, it appears to be a bleadperl thing.
The trouble is Perl_sv_2bool is going into infinite recursion:
Might be related to testing whether the returned ref on overload is the same object or not (I think that test was removed\, but IANAPCC).
Cheers\,
Tels
- -- perl -MDev::Bollocks -e'print Dev::Bollocks->rand()\,"\n"' completely exploit essential architectures
http://bloodgate.com/perl My current Perl projects PGP key available on http://bloodgate.com/tels.asc or via email
-----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: latin1
iQEVAwUBPB+UQXcLPEOTuEwVAQHhtQf9E7CuEQtpSgpkNtRm4hg0qzhXcx8NIUiX nO1wh/1jGdrKsRPyvzveyL3qNvYmwcwOFg6KliXSe0yeyT/AmDmuypY4fHqULeD0 FDkl+PnRZZViNa4McxE9lJq1o79nedbIQB30AbJAyyOhw5xUyzqOpo4858/EvHpS FbwGQf5qCXOmf6NTIYdPOHIO1lCZqYOXdX8VEzTJuvVMmTxbS7bEpmG1zOo/Zveq DjxIuK784kKYA+3JnRWZRCFJmmanNmtTY3rt5bWSkJabzoGSEfpScElm8iJ2SvbJ 4gHcWEVmBPFvlLwTXMPq36DJa3rwZ2VxHrW337DoeJqEMncTj0j40Q== =GQfW -----END PGP SIGNATURE-----
On Tue\, Dec 18\, 2001 at 08:11:55PM +0100\, Tels wrote:
The trouble is Perl_sv_2bool is going into infinite recursion:
Might be related to testing whether the returned ref on overload is the same object or not (I think that test was removed\, but IANAPCC).
Well\, here's the point where it decides to leave the solar system
if (SvROK(sv)) { SV* tmpsv; if (SvAMAGIC(sv) && (tmpsv=AMG_CALLun(sv\,bool_)) && (SvTYPE(tmpsv) != SVt_RV || (SvRV(tmpsv) != SvRV(sv)))) return SvTRUE(tmpsv); return SvRV(sv) != 0; }
The "return SvTRUE(tmpsv);" is line 3239.
--
Michael G. Schwern \schwern@​pobox\.com http://www.pobox.com/~schwern/ Perl Quality Assurance \perl\-qa@​perl\.org Kwalitee Is Job One I have this god-awful need to aquire useless crap!!!
Michael G Schwern \schwern@​pobox\.com wrote: :The trouble is Perl_sv_2bool is going into infinite recursion: [...]
Shorter test case: crypt% perl -wle 'use overload "0+" => sub { $_[0] }; $ok = 0; $result = bless {}; $ok = $result; print !$ok' Segmentation fault (core dumped) crypt%
I strongly recommend aiming for a short test case before trying to debug things - as well as making various things easier\, discovering what you _can't_ remove can give vital clues.
In the above test case\, note that $result has to be copied to another variable that must already have been initialised: only then does negating it lead to a coredump.
This turns out to be because of a wrinkle in sv_upgrade: if the target to upgrade has never been initialised (ie has svtype 0)\, we upgrade to exactly the requested type; if we have an IV (svtype 1)\, we always upgrade at least to a PVIV. After the overloaded 'not'\, we then get to the postprocess stage of amagic_call(): case not_amg: ans=!SvTRUE(res); break; ... which calls sv_2bool()\, which has this careful check to avoid loops: if (SvROK(sv)) { SV* tmpsv; if (SvAMAGIC(sv) && (tmpsv=AMG_CALLun(sv\,bool_)) && (SvTYPE(tmpsv) != SVt_RV || (SvRV(tmpsv) != SvRV(sv)))) return SvTRUE(tmpsv); return SvRV(sv) != 0; } ... which\, of course\, fails. Changing the check to SvROK() is preferred by 10 out of 10 of all test cases that expressed a preference.
I'd add a test case (as above)\, but I don't know whether we have a preferred method yet for tests that loop on failure.
Hugo
On Wed\, Dec 19\, 2001 at 01:45:23AM +0000\, Hugo van der Sanden wrote:
Michael G Schwern \schwern@​pobox\.com wrote: :The trouble is Perl_sv_2bool is going into infinite recursion: [...]
Shorter test case: crypt% perl -wle 'use overload "0+" => sub { $_[0] }; $ok = 0; $result = bless {}; $ok = $result; print !$ok' Segmentation fault (core dumped) crypt%
I strongly recommend aiming for a short test case before trying to debug things - as well as making various things easier\, discovering what you _can't_ remove can give vital clues.
In the above test case\, note that $result has to be copied to another variable that must already have been initialised: only then does negating it lead to a coredump.
This turns out to be because of a wrinkle in sv_upgrade: if the target to upgrade has never been initialised (ie has svtype 0)\, we upgrade to exactly the requested type; if we have an IV (svtype 1)\, we always upgrade at least to a PVIV. After the overloaded 'not'\, we then get to the postprocess stage of amagic_call(): case not_amg: ans=!SvTRUE(res); break; ... which calls sv_2bool()\, which has this careful check to avoid loops: if (SvROK(sv)) { SV* tmpsv; if (SvAMAGIC(sv) && (tmpsv=AMG_CALLun(sv\,bool_)) && (SvTYPE(tmpsv) != SVt_RV || (SvRV(tmpsv) != SvRV(sv)))) return SvTRUE(tmpsv); return SvRV(sv) != 0; } ... which\, of course\, fails. Changing the check to SvROK() is preferred by 10 out of 10 of all test cases that expressed a preference.
Thanks\, applied.
I'd add a test case (as above)\, but I don't know whether we have a preferred method yet for tests that loop on failure.
Hugo --- sv.c.old Fri Dec 14 22:29:54 2001 +++ sv.c Wed Dec 19 01:35:05 2001 @@ -3235\,7 +3235\,7 @@ if (SvROK(sv)) { SV* tmpsv; if (SvAMAGIC(sv) && (tmpsv=AMG_CALLun(sv\,bool_)) && - (SvTYPE(tmpsv) != SVt_RV || (SvRV(tmpsv) != SvRV(sv)))) + (!SvROK(tmpsv) || (SvRV(tmpsv) != SvRV(sv)))) return SvTRUE(tmpsv); return SvRV(sv) != 0; }
-- $jhi++; # http://www.iki.fi/jhi/ # There is this special biologist word we use for 'stable'. # It is 'dead'. -- Jack Cohen
On Wed\, Dec 19\, 2001 at 01:45:23AM +0000\, Hugo van der Sanden wrote:
I'd add a test case (as above)\, but I don't know whether we have a preferred method yet for tests that loop on failure.
Toss it onto the end of t/run/kill_perl.t. While it doesn't deal well with infinite loop (and you'll forgive me if I don't want to start adding alarms to code that uses system() and pipes just this moment) this test does eventually spin itself apart.
That reminds me\, I promised I'd get around to dismantling kill_perl.t\, didn't I?
--
Michael G. Schwern \schwern@​pobox\.com http://www.pobox.com/~schwern/ Perl Quality Assurance \perl\-qa@​perl\.org Kwalitee Is Job One How can I stoop so low? Years of practise\, that's how. It's been hard going but now I can stoop lower than a pygmy limbo dancer. -- BOFH
Hugo fixed.
--
Michael G. Schwern \schwern@​pobox\.com http://www.pobox.com/~schwern/ Perl Quality Assurance \perl\-qa@​perl\.org Kwalitee Is Job One IMHO bugs in Perl 5 shouldn't carry over to Perl 6. (Unless\, of course\, we *like* the bugs... ;) -- Ken Fox in \3B8B94B0\.A8A7E41@​vulpes\.com
On Wed\, Dec 19\, 2001 at 06:42:32AM -0500\, Michael G Schwern wrote:
On Wed\, Dec 19\, 2001 at 01:45:23AM +0000\, Hugo van der Sanden wrote:
I'd add a test case (as above)\, but I don't know whether we have a preferred method yet for tests that loop on failure.
Toss it onto the end of t/run/kill_perl.t. While it doesn't deal well with infinite loop (and you'll forgive me if I don't want to start adding alarms to code that uses system() and pipes just this moment) this test does eventually spin itself apart.
That reminds me\, I promised I'd get around to dismantling kill_perl.t\, didn't I?
Yes.
-- $jhi++; # http://www.iki.fi/jhi/ # There is this special biologist word we use for 'stable'. # It is 'dead'. -- Jack Cohen
[followup-to-old-message alert]
On Wed\, 19 Dec 2001 01:45:23 GMT\, Hugo van der Sanden wrote:
Michael G Schwern \schwern@​pobox\.com wrote: :The trouble is Perl_sv_2bool is going into infinite recursion: [...]
Shorter test case: crypt% perl -wle 'use overload "0+" => sub { $_[0] }; $ok = 0; $result = ble ss {}; $ok = $result; print !$ok' Segmentation fault (core dumped) crypt%
I strongly recommend aiming for a short test case before trying to debug things - as well as making various things easier\, discovering what you _can't_ remove can give vital clues.
In the above test case\, note that $result has to be copied to another variable that must already have been initialised: only then does negating it lead to a coredump.
This turns out to be because of a wrinkle in sv_upgrade: if the target to upgrade has never been initialised (ie has svtype 0)\, we upgrade to exactly the requested type; if we have an IV (svtype 1)\, we always upgrade at least to a PVIV. After the overloaded 'not'\, we then get to the postprocess stage of amagic_call(): case not_amg: ans=!SvTRUE(res); break; ... which calls sv_2bool()\, which has this careful check to avoid loops: if (SvROK(sv)) { SV* tmpsv; if (SvAMAGIC(sv) && (tmpsv=AMG_CALLun(sv\,bool_)) && (SvTYPE(tmpsv) != SVt_RV || (SvRV(tmpsv) != SvRV(sv)))) return SvTRUE(tmpsv); return SvRV(sv) != 0; } ... which\, of course\, fails. Changing the check to SvROK() is preferred by 10 out of 10 of all test cases that expressed a preference.
I'd add a test case (as above)\, but I don't know whether we have a preferred method yet for tests that loop on failure.
Hugo --- sv.c.old Fri Dec 14 22:29:54 2001 +++ sv.c Wed Dec 19 01:35:05 2001 @@ -3235\,7 +3235\,7 @@ if (SvROK(sv)) { SV* tmpsv; if (SvAMAGIC(sv) && (tmpsv=AMG_CALLun(sv\,bool_)) && - (SvTYPE(tmpsv) != SVt_RV || (SvRV(tmpsv) != SvRV(sv)))) + (!SvROK(tmpsv) || (SvRV(tmpsv) != SvRV(sv)))) return SvTRUE(tmpsv); return SvRV(sv) != 0; }
This went in as change#13786\, and appears to be fixing only one of the five identical checks that were added in change#9782 to sv.c.
Seems to me the four others in sv.c need fixing as well.
Sarathy gsar@ActiveState.com
Gurusamy Sarathy \gsar@​ActiveState\.com wrote: :On Wed\, 19 Dec 2001 01:45:23 GMT\, Hugo van der Sanden wrote: :>--- sv.c.old Fri Dec 14 22:29:54 2001 :>+++ sv.c Wed Dec 19 01:35:05 2001 :>@@ -3235\,7 +3235\,7 @@ :> if (SvROK(sv)) { :> SV* tmpsv; :> if (SvAMAGIC(sv) && (tmpsv=AMG_CALLun(sv\,bool_)) && :>- (SvTYPE(tmpsv) != SVt_RV | (SvRV(tmpsv) != SvRV(sv)))) :>+ (!SvROK(tmpsv) | (SvRV(tmpsv) != SvRV(sv)))) :> return SvTRUE(tmpsv); :> return SvRV(sv) != 0; :> } |
---|
:This went in as change#13786\, and appears to be fixing only one :of the five identical checks that were added in change#9782 to :sv.c. : :Seems to me the four others in sv.c need fixing as well.
You are quite right; I've applied the parallel change to the other four cases as #18090.
Hugo
@cwest - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#8053 (status was 'resolved')
Searchable as RT8053$