Skip Menu |

This queue is for tickets about the YAML-Syck CPAN distribution.

Report information
The Basics
Id: 54167
Status: resolved
Priority: 0/
Queue: YAML-Syck

People
Owner: Nobody in particular
Requestors: RCAPUTO [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.07
Fixed in: (no value)



Subject: Dump() affects success of subsequent each()
Thank you for the module. I use it often. It seems that YAML::Syck::Dump($hashref) doesn't reset the iterator for %$hashref when it's done. A subsequent each(%$hashref) fails to iterate at all. Placing keys(%$hashref) before the each() call resets the hash's iterator and allows each() to iterate normally. I've attached a Test::More test case illustrating the problem. I've flagged the Severity as "Important". No offense will be taken if you flag it as less severe.
Subject: yaml-syck-each.pl
#!/usr/bin/env perl use warnings; use strict; use Test::More tests => 2; use YAML::Syck; my $some_hashref = { a => 1, b => 2 }; my $expected_iterations = scalar keys %$some_hashref; is( count_each_iterations($some_hashref), $expected_iterations, "each() iterates properly before YAML::Syck::Dump", ); # Perform the Dump. my $some_yaml_dump = YAML::Syck::Dump($some_hashref); is( count_each_iterations($some_hashref), $expected_iterations, "each() iterates properly after YAML::Syck::Dump", ); exit; sub count_each_iterations { my $hashref = shift; my $iterations = 0; while (my ($k, $v) = each %$hashref) { $iterations++; } return $iterations; }
On Sun Jan 31 14:32:24 2010, RCAPUTO wrote: Show quoted text
> It seems that YAML::Syck::Dump($hashref) doesn't reset the iterator for > %$hashref when it's done. A subsequent each(%$hashref) fails to iterate > at all. Placing keys(%$hashref) before the each() call resets the > hash's iterator and allows each() to iterate normally.
attached patch fixed problem for me
Subject: yaml-syck-each.patch
Only in YAML-Syck-1.07: 0001-Added-hash-each-pointer-reset.patch Only in YAML-Syck-1.07: .git diff -ru YAML-Syck-1.07/perl_syck.h YAML-Syck-1.07-patch/perl_syck.h --- YAML-Syck-1.07/perl_syck.h 2010-04-06 00:40:50.000000000 +0400 +++ YAML-Syck-1.07-patch/perl_syck.h 2010-04-06 00:23:30.000000000 +0400 @@ -973,6 +973,8 @@ syck_emit_item( e, (st_data_t)val ); } } + // reset hash each poiter + hv_iterinit(hv); syck_emit_end(e); return; } Only in YAML-Syck-1.07-patch/t: yaml-syck-each.t
(This is a form-reply that isn't specific to your particular report) YAML::Syck has just acquired one new maintainer (me), it still doesn't have anyone that *cares* about it. But I'm willing to help solve your report & release a new version with the fix if it's easy for me. It now has a Git repository at: http://github.com/avar/YAML-Syck If your report is a patch that fixes a problem, great. Please remake the patch against Git by forking that repo and sending me a pull request on GitHub (or an update to this bug if you prefer git-format-patch(1) or some other repo provider..). Make sure to include a test for what you fixed. If your report is some code that fails (and you have a testcase for it) a patch against the test suite to demonstrate that failure would be very useful. It's OK if the test crashes and burns, see Test::More's docs for how to make TODO tests that fail now, but shouldn't. Even if it segfaults perl C<system $^X => qw/ -Mblib -MYAML::Syck .../> or something like that and checking the return value will do.
On Thu May 20 07:05:39 2010, AVAR wrote: Now fixed in Git. Will be in 1.09.