/* A pointer to the dictionary. Owned externally */
const struct dictionary *dict;
+
+ /* The scalar containing the dictionary */
+ SV *dict_sv;
};
struct sysfile_info *
-pxs_create_sysfile (name, dict, opts_hr)
+pxs_create_sysfile (name, dict_ref, opts_hr)
char *name
- struct dictionary *dict
+ SV *dict_ref
SV *opts_hr
INIT:
+ SV *dict_sv = SvRV (dict_ref);
+ struct dictionary *dict = (void *) SvIV (dict_sv);
struct sfm_write_options opts;
if (!SvROK (opts_hr))
{
sfi->writer = sfm_open_writer (fh, dict, opts);
sfi->dict = dict;
sfi->opened = true;
+ sfi->dict_sv = dict_sv;
+ SvREFCNT_inc (sfi->dict_sv);
RETVAL = sfi;
OUTPUT:
struct sysfile_info *sfi
CODE:
sysfile_close (sfi);
+ SvREFCNT_dec (sfi->dict_sv);
free (sfi);
int
# change 'tests => 1' to 'tests => last_test_to_print';
-use Test::More tests => 30;
+use Test::More tests => 31;
use Text::Diff;
use File::Temp qw/ tempfile tempdir /;
BEGIN { use_ok('PSPP') };
}
+# Test to make sure that the dictionary survives the sysfile.
+# Thanks to Rob Messer for reporting this problem
+{
+ my $tempdir = tempdir( CLEANUP => 1 );
+ my $tempfile = "$tempdir/testfile.sav";
+ my $sysfile ;
+
+ {
+ my $d = PSPP::Dict->new();
+
+ PSPP::Var->new ($d, "id",
+ (
+ fmt=>PSPP::Fmt::F,
+ width=>2,
+ decimals=>0
+ )
+ );
+
+ $sysfile = PSPP::Sysfile->new ("$tempfile", $d);
+ }
+
+ my $res = $sysfile->append_case ([3]);
+
+ ok ($res, "Dictionary survives sysfile");
+}
+
+
# Basic reader test
{
my $tempdir = tempdir( CLEANUP => 1 );