This queue is for tickets about the Text-CSV_XS CPAN distribution.

Report information
The Basics
Id:
43927
Status:
resolved
Priority:
Low/Low
Queue:

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

BugTracker
Severity:
(no value)
Broken in:
0.40
Fixed in:
0.61



Subject: Is bind_columns broken or am I using it wrong?
Hello, I've been trying to "optimize" our CSV parser to see if I can speed it up and noticed the bind_columns method. I thought it would be the best method to use, and stumbled on this error/warning. The file parses OK if I use the "normal" way without bind_columns, but never works if I try it. I thought the utf8 text might be causing issues, but using the file sanitized of all utf8 characters doesn't work either. Folks on IRC tried to help me debug this, and we agreed that it probably is a bug OR we are obviously using it wrong. I hope you can look at this and let me know if it's a bug or I'm simply using bind_columns wrong. If I'm using it wrong, I would be happy to help you redocument the POD to get it "right", ha! Attached is the perl code + test CSV file. This didn't work on 5.8.8 or 5.10.0 on linux. Thanks again! -- ~Apocalypse
Subject: logparser.pl
#!/usr/bin/perl use strict; use warnings; use Text::CSV_XS; #use utf8; # no difference my $csv = Text::CSV_XS->new({ binary => 1 }); #open my $fh, "<:utf8", "log.txt" or die "unable to open: $!"; # no difference open my $fh, "<", "log.txt" or die "unable to open: $!"; my( $c0, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10 ); my @columns = \( $c0, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10 ); $csv->bind_columns( \$c0, \$c1, \$c2, \$c3, \$c4, \$c5, \$c6, \$c7, \$c8, \$c9, \$c10 ); #$csv->bind_columns( \( $c0, $c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10 ) ); # no difference #$csv->bind_columns( @columns ); # no difference while ( my $row = $csv->getline( $fh ) ) { # got the line print "got row: $c0 - $c1 - $c2\n"; } close $fh or die "unable to close: $!";
Subject: log.txt
SPELL_AURA_APPLIED,0x00000000019BED4E,"Snêêfly",0x514,0x0000000001751ED6,"Fibe",0x511,32223,"Aura des Kreuzfahrers",0x2,BUFF SPELL_AURA_APPLIED,0xF14052A693000017,"Chotuk",0x1114,0x0000000001DECBE8,"Cooly",0x514,47982,"Blutpakt",0x20,BUFF SPELL_AURA_APPLIED,0xF14052A693000017,"Chotuk",0x1114,0x0000000001DECBE8,"Cooly",0x514,35696,"Dämonisches Wissen",0x1,BUFF SPELL_AURA_APPLIED,0xF14052A693000017,"Chotuk",0x1114,0x0000000001DECBE8,"Cooly",0x514,23829,"Meister der Dämonologie",0x20,BUFF SPELL_AURA_REMOVED,0xF14052A693000017,"Chotuk",0x1114,0x0000000001DECBE8,"Cooly",0x514,35696,"Dämonisches Wissen",0x1,BUFF SPELL_AURA_APPLIED,0xF14052A693000017,"Chotuk",0x1114,0x0000000001DECBE8,"Cooly",0x514,35696,"Dämonisches Wissen",0x1,BUFF SPELL_AURA_REMOVED,0xF14052A693000017,"Chotuk",0x1114,0x0000000001DECBE8,"Cooly",0x514,23829,"Meister der Dämonologie",0x20,BUFF SPELL_AURA_APPLIED,0xF14052A693000017,"Chotuk",0x1114,0x0000000001DECBE8,"Cooly",0x514,23829,"Meister der Dämonologie",0x20,BUFF SWING_DAMAGE,0xF1300042660041E1,"Mr. Bigglesworth",0xa28,0xF130003E9E00442C,"Made",0xa28,6,0,1,0,0,0,nil,nil,nil SPELL_AURA_APPLIED,0x00000000019BED4E,"Snêêfly",0x514,0x0000000001DECBE8,"Cooly",0x514,32223,"Aura des Kreuzfahrers",0x2,BUFF
D0h, here is the output, ha! Notice that it doesn't print any rows fetched from getline()... on perl-5.8.8 apoc@apoc-x300:~/Desktop$ perl logparser.pl Use of uninitialized value in unpack at /usr/local/lib/perl/5.8.8/Text/CSV_XS.pm line 144. Use of uninitialized value in pack at /usr/local/lib/perl/5.8.8/Text/CSV_XS.pm line 147. ... repeats several more times ... apoc@apoc-x300:~/Desktop$ on perl-5.10.0 apoc@apoc-x300:~/Desktop$ perl logparser.pl Use of uninitialized value in unpack at /usr/local/lib/perl/5.10.0/Text/CSV_XS.pm line 144. Use of uninitialized value within @cache in pack at /usr/local/lib/perl/5.10.0/Text/CSV_XS.pm line 147. ... repeats several more times ... apoc@apoc-x300:~/Desktop$ On Sat Mar 07 09:06:44 2009, APOCAL wrote:
Show quoted text
> Hello, > > I've been trying to "optimize" our CSV parser to see if I can speed it > up and noticed the bind_columns method. I thought it would be the best > method to use, and stumbled on this error/warning. The file parses OK if > I use the "normal" way without bind_columns, but never works if I try it. > > I thought the utf8 text might be causing issues, but using the file > sanitized of all utf8 characters doesn't work either. Folks on IRC tried > to help me debug this, and we agreed that it probably is a bug OR we are > obviously using it wrong. > > I hope you can look at this and let me know if it's a bug or I'm simply > using bind_columns wrong. If I'm using it wrong, I would be happy to > help you redocument the POD to get it "right", ha! > > Attached is the perl code + test CSV file. This didn't work on 5.8.8 or > 5.10.0 on linux. > > Thanks again!
-- ~Apocalypse
The is_bound member of the csv struct wasn't initialized. The attached patch should fix it. It also solves numerous errors reported by valgrind (see e.g. t/15_flags.t). Vincent.
--- CSV_XS.pm 2009-01-23 10:03:58.000000000 +0100 +++ CSV_XS.pm 2009-03-07 15:30:00.000000000 +0100 @@ -141,6 +141,7 @@ { my ($self, $name, $val) = @_; $self->{$name} = $val; + $self->{_CACHE} or return; my @cache = unpack "C*", $self->{_CACHE}; my $i = $_cache_id{$name}; $cache[$i++] = $_ for unpack "C*", pack "N", $val; --- CSV_XS.xs 2009-01-27 17:28:45.000000000 +0100 +++ CSV_XS.xs 2009-03-07 15:34:54.000000000 +0100 @@ -308,6 +308,11 @@ csv->types_len = len; } + csv->is_bound = 0; + if ((svp = hv_fetchs (self, "_is_bound", FALSE)) && *svp && SvOK(*svp)) { + csv->is_bound = SvIV(*svp); + } + csv->binary = bool_opt ("binary"); csv->keep_meta_info = bool_opt ("keep_meta_info"); csv->always_quote = bool_opt ("always_quote");
On Sat Mar 07 09:40:26 2009, VPIT wrote:
Show quoted text
> The is_bound member of the csv struct wasn't initialized. The attached > patch should fix it. It also solves numerous errors reported by valgrind > (see e.g. t/15_flags.t). > > Vincent.
Thanks for this patch! I confirm it works perfectly on perl-5.8.8 and perl-5.10.0. -- ~Apocalypse


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.