From db1b228d7481ccc58077c420887285cff2d08b91 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 5 Feb 2009 19:36:18 -0800 Subject: [PATCH] perl-module: Make PSPP::Reader::get_next_case() return a list. PSPP::Reader::get_next_case() was documented to return a list, but actually it returned a reference to a list. This commit changes the behavior to match the documentation. This also fixes the behavior on reading past the end of the file. Previously this was documented to return undef but caused a segfault in practice. Now it returns an empty list. Also increase PSPP version number from 0.7.1 to 0.7.2 at John Darrington's request, to alert users of the previous version of the Perl interface. --- configure.ac | 2 +- perl-module/PSPP.xs | 18 +++++------------- perl-module/lib/PSPP.pm | 3 ++- perl-module/t/Pspp.t | 32 ++++++++++++++++---------------- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/configure.ac b/configure.ac index aa1cb6f5..fc4b9828 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. dnl Initialize. AC_PREREQ(2.60) -AC_INIT([pspp],[0.7.1],[bug-gnu-pspp@gnu.org]) +AC_INIT([pspp],[0.7.2],[bug-gnu-pspp@gnu.org]) AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE diff --git a/perl-module/PSPP.xs b/perl-module/PSPP.xs index 2d2c8d9d..237ae95f 100644 --- a/perl-module/PSPP.xs +++ b/perl-module/PSPP.xs @@ -671,32 +671,24 @@ CODE: RETVAL -SV * +void get_next_case (sfr) struct sysreader_info *sfr; -CODE: +PPCODE: struct ccase *c; - if (! (c = casereader_read (sfr->reader))) - { - RETVAL = 0; - } - else + if (c = casereader_read (sfr->reader)) { int v; - AV *av_case = (AV *) sv_2mortal ((SV *) newAV()); + EXTEND (SP, dict_get_var_cnt (sfr->dict)); for (v = 0; v < dict_get_var_cnt (sfr->dict); ++v ) { const struct variable *var = dict_get_var (sfr->dict, v); const union value *val = case_data (c, var); - av_push (av_case, value_to_scalar (val, var)); + PUSHs (sv_2mortal (value_to_scalar (val, var))); } case_unref (c); - RETVAL = newRV ((SV *) av_case); } -OUTPUT: - RETVAL - diff --git a/perl-module/lib/PSPP.pm b/perl-module/lib/PSPP.pm index 93d70ef2..e9e3215d 100644 --- a/perl-module/lib/PSPP.pm +++ b/perl-module/lib/PSPP.pm @@ -493,7 +493,8 @@ This method returns an array of scalars, each of which are the values of the data in the system file. The first call to C after C has been called retrieves the first case in the system file. Each subsequent call retrieves the next -case. If there are no more cases to be read, the function returns undef. +case. If there are no more cases to be read, the function returns an empty +list. If the case contains system missing values, these values are set to the empty string. diff --git a/perl-module/t/Pspp.t b/perl-module/t/Pspp.t index fe141514..030a342a 100644 --- a/perl-module/t/Pspp.t +++ b/perl-module/t/Pspp.t @@ -387,11 +387,11 @@ RESULT print MYFILE "$_ => $vl->{$_}\n" for keys %$vl; } - while (my $c = $sf->get_next_case () ) + while (my @c = $sf->get_next_case () ) { for ($v = 0; $v < $dict->get_var_cnt(); $v++) { - print MYFILE "val$v: \"@$c[$v]\"\n"; + print MYFILE "val$v: \"$c[$v]\"\n"; } print MYFILE "\n"; } @@ -469,9 +469,9 @@ EOF my $output = PSPP::Sysfile->new ("$tempdir/out.sav", $dict); - while (my $c = $input->get_next_case () ) + while (my (@c) = $input->get_next_case () ) { - $output->append_case ($c); + $output->append_case (\@c); } $output->close (); @@ -519,10 +519,10 @@ SYNTAX my $dict = $sf->get_dict (); - my $c = $sf->get_next_case (); + my (@c) = $sf->get_next_case (); my $var = $dict->get_var (0); - my $val = @$c[0]; + my $val = $c[0]; my $formatted = PSPP::format_value ($val, $var); my $str = gmtime ($val - PSPP::PERL_EPOCH); print "Formatted string is \"$formatted\"\n"; @@ -557,30 +557,30 @@ SYNTAX my $dict = $sf->get_dict (); - my $c = $sf->get_next_case (); + my (@c) = $sf->get_next_case (); my $stringvar = $dict->get_var (0); my $numericvar = $dict->get_var (2); - my $val = @$c[0]; + my $val = $c[0]; ok ( !PSPP::value_is_missing ($val, $stringvar), "Missing Value Negative String"); - $val = @$c[2]; + $val = $c[2]; ok ( !PSPP::value_is_missing ($val, $numericvar), "Missing Value Negative Num"); - $c = $sf->get_next_case (); - $c = $sf->get_next_case (); + @c = $sf->get_next_case (); + @c = $sf->get_next_case (); - $val = @$c[0]; + $val = $c[0]; ok ( PSPP::value_is_missing ($val, $stringvar), "Missing Value Positive"); - $c = $sf->get_next_case (); - $val = @$c[2]; + @c = $sf->get_next_case (); + $val = $c[2]; ok ( PSPP::value_is_missing ($val, $numericvar), "Missing Value Positive SYS"); - $c = $sf->get_next_case (); - $val = @$c[2]; + @c = $sf->get_next_case (); + $val = $c[2]; ok ( PSPP::value_is_missing ($val, $numericvar), "Missing Value Positive Num"); } -- 2.30.2