pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: perl module documentation patches, segfault


From: John Darrington
Subject: Re: perl module documentation patches, segfault
Date: Mon, 2 Feb 2009 08:27:21 +0900
User-agent: Mutt/1.5.13 (2006-08-11)

On Sun, Feb 01, 2009 at 02:50:01PM -0800, Ben Pfaff wrote:
     I noticed that the Perl module documentation doesn't say how to
     tell how you've arrived at the end of the dictionary.  It seems
     that get_var() returns undef in this case, thus:
     
     diff --git a/perl-module/lib/PSPP.pm b/perl-module/lib/PSPP.pm
     --- a/perl-module/lib/PSPP.pm
     +++ b/perl-module/lib/PSPP.pm
     @@ -90,6 +90,8 @@ sub new
      =head3 get_var ($idx)
      
      Returns the C<idx>th variable from the dictionary.
     +Returns undef if C<idx> is greater than or equal to the number
     +of variables in the dictionary.
      
      =cut
      

You're right.  Feel free to commit that.     
     
     
     Second, it seems that get_next_case() does not return a plain
     array but a reference to one.  I would think that a plain array
     would be more "natural" Perl, but here is a documentation fix-up
     in case the choice was intentional:
     
     diff --git a/perl-module/lib/PSPP.pm b/perl-module/lib/PSPP.pm
     --- a/perl-module/lib/PSPP.pm
     +++ b/perl-module/lib/PSPP.pm
     @@ -487,7 +489,8 @@ Returns the dictionary associated with the reader.
      =head3 get_next_case ()
      
      Retrieves the next case from the reader.
     -This method returns an array of scalars, each of which are the values of 
     +This method returns a reference to an array of scalars, each of which
     +are the values of
      the data in the system file.
      The first call to C<get_next_case> after C<open> has been called retrieves
      the first case in the system file.  Each subsequent call retrieves the 
next
     

From what I remember I decided to make that a reference, because it
appeared to be the only way that it would be possible to use a sentinel
value to indicate the end of the file.  Perhaps this was an erroneous
assumption, due to my limited knowledge of perl.
     
     Finally, I was working on a script to dump out a system file as
     text.  Here's what I have so far.  It works, in that it dumps the
     cases, but it segfaults after it reads the last one:
     
         #! /usr/bin/perl
     
         use PSPP;
     
         use strict;
         use warnings;
     
         my $reader = PSPP::Reader->open ($ARGV[0]);
         while (my @case = @{$reader->get_next_case ()}) {
             print join (',', @case), "\n";
         }
     
     Is there a good way to debug this?  Running gdb on perl doesn't
     seem very helpful, since the backtrace is just this:
     
         0x080b8fe9 in Perl_pp_rv2av ()
         (gdb) bt
         #0  0x080b8fe9 in Perl_pp_rv2av ()
         #1  0x080b17a9 in Perl_runops_standard ()
         #2  0x080ac5d0 in perl_run ()
         #3  0x08063ddd in main ()
         (gdb) 
     

Hmm.  The problem seems to be derefencing something whose referand no
longer exists.  You should be able to set a breakpoint on the
get_next_case function in PSPP.xs or running perl under valgrind might
give some clues. 



-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.



 LocalWords:  Undef

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]