From f8ca7d84a6b42c79bc790853ab0737ae57af332f Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 8 May 2009 22:13:50 -0700 Subject: [PATCH] Make conversion of "void *ntuple_data" less wrong. Fixed bugs in NTuple.t fixture data Added test for gsl_ntuple->new --- swig/NTuple.i | 29 ++++++++++++++++++++++++----- t/NTuple.t | 17 +++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/swig/NTuple.i b/swig/NTuple.i index 828cc83..e97e556 100644 --- a/swig/NTuple.i +++ b/swig/NTuple.i @@ -2,22 +2,41 @@ %include "typemaps.i" %include "gsl_typemaps.i" +// XXX: This needs to properly take the type of array into account, +// this assumes ints %typemap(in) void *ntuple_data { - fprintf(stderr,"symname=$symname \n"); + AV *tempav; + I32 len; + int i; + SV **tv; + + //fprintf(stderr,"symname=$symname \n"); if (!SvROK($input)) - croak("Math::GSL : $$1_name is not a reference!"); + croak("Math::GSL::NTuple : $1_name is not a reference!"); if (SvTYPE(SvRV($input)) != SVt_PVAV) - croak("Math::GSL : $$1_name is not an array ref!"); - - $1 = (double *) $input; + croak("Math::GSL::NTuple : $1_name is not an array ref!"); + + tempav = (AV*)SvRV($input); + len = av_len(tempav); + if( len > 0 ){ + $1 = (int **) malloc((len+1)*sizeof(int *)); + for (i = 0; i <= len; i++) { + tv = av_fetch(tempav, i, 0); + memset((int*)($1+i), SvIV(*tv) , sizeof(int *)); + } + } }; %typemap(argout) void *ntuple_data { //Perl_sv_dump($1); } +%typemap(freearg) void *ntuple_data { +// if ($1) free($1); +} + %{ #include "gsl/gsl_ntuple.h" #include "gsl/gsl_errno.h" diff --git a/t/NTuple.t b/t/NTuple.t index 5887f1f..8a79ff3 100644 --- a/t/NTuple.t +++ b/t/NTuple.t @@ -1,6 +1,6 @@ package Math::GSL::NTuple::Test; use base q{Test::Class}; -use Test::More; +use Test::More tests => 9; use Test::Exception; use Math::GSL::NTuple qw/:all/; use Math::GSL::Const qw/:all/; @@ -16,7 +16,7 @@ END { warn "This is the end" } sub make_fixture : Test(setup) { my $self = shift; - my $size = int rand(100); + my $size = 2 + int rand(100); $self->{size} = $size; my $stuff = [1..$size]; @@ -30,13 +30,13 @@ sub teardown : Test(teardown) { unlink 'ntuple2' if -f 'ntuple2'; } -sub GSL_NTUPLE_CREATE : Tests { +sub GSL_NTUPLE_CREATE : Tests(2) { my $self = shift; isa_ok ($self->{ntuple}, 'Math::GSL::NTuple::gsl_ntuple'); ok( -e 'ntuple', 'ntuple file created'); } -sub GSL_NTUPLE_OPEN_CLOSE : Tests { +sub GSL_NTUPLE_OPEN_CLOSE : Tests(2) { my $self = shift; my $stuff = []; my $ntuple = gsl_ntuple_open('ntuple',$stuff, $self->{size} ); @@ -44,7 +44,7 @@ sub GSL_NTUPLE_OPEN_CLOSE : Tests { ok_status(gsl_ntuple_close($ntuple)); } -sub GSL_NTUPLE_WRITE: Tests { +sub GSL_NTUPLE_WRITE: Tests(2) { my $self = shift; my $data = [1..100]; my $base = gsl_ntuple_create('ntuple', $data, 100); @@ -52,7 +52,7 @@ sub GSL_NTUPLE_WRITE: Tests { ok_status(gsl_ntuple_close($base)); } -sub GSL_NTUPLE_READ: Tests { +sub GSL_NTUPLE_READ: Tests(2) { my $self = shift; my $data = [1..100]; my $ntuple = gsl_ntuple_open('ntuple', $data, 100 ); @@ -61,5 +61,10 @@ sub GSL_NTUPLE_READ: Tests { ok_status(gsl_ntuple_read($ntuple),$GSL_EOF); ok_status(gsl_ntuple_close($ntuple)); } +sub GSL_NTUPLE_OBJECT: Tests(1) { + my $ntuple = Math::GSL::NTuple::gsl_ntuple->new; + isa_ok($ntuple,'Math::GSL::NTuple::gsl_ntuple'); +} + 1; Test::Class->runtests; -- 2.11.4.GIT