in reply to perl xs pass an array by reference
A SV * is not a double *. do_nothing is looking at garbage data (an SV struct), and you should have compiler warnings about the lack of a cast (and don't add one either). Look at lib/ExtUtils/typemap in perl.git. There is no typemap entry for a double *. Now, is do_nothing's x parameter an input or an output parameter?double * T_SV
MODULE = Myfunction PACKAGE = Myfunction PROTOTYPES: ENABLE double do_nothing(x) NV x CODE: RETVAL = do_nothing(&x); OUTPUT: RETVAL x
I basically tried to pass an array by reference to my C subroutine that takes a pointer to a double.
MODULE = Myfunction PACKAGE = Myfunction PROTOTYPES: ENABLE double do_nothing(x) AV * x PREINIT: SV ** svnv; double x_db; CODE: if(av_len(x) != 2) croak("bad array len"); svnv = av_fetch(x, 0, 0); x_db = SvNV(*svnv); RETVAL = do_nothing(&x_db); sv_setnv_mg(*svnv, (NV)x_db); OUTPUT: RETVAL
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl xs pass an array by reference
by andromedia33 (Novice) on Dec 06, 2012 at 20:48 UTC | |
by bulk88 (Priest) on Dec 06, 2012 at 22:05 UTC | |
by andromedia33 (Novice) on Dec 31, 2012 at 19:18 UTC |