Hello,

I am trying to pass a array of references on array to a c subroutine:
my @set_2d = ([0.0, 1.0], [1.1, 2.2], [3.1, 4.4]) ;
test::test([EMAIL PROTECTED]) ;

in xs I put:

typedef double floatArray ;

void * floatArrayPtr (int num) {
   SV * mortal ;
   mortal = sv_2mortal (NEWSV (0, num * sizeof (floatArray))) ;
   return SvPVX (mortal) ;
   }

double
spectrum_2d (avref)
     AV * avref
     PREINIT:
        int len, ncols;
        int i, j ;
        SV ** elem ;
        floatMatrix *matrix ;
        AV** row ;
     CODE:
        len = av_len (avref) + 1 ;
        printf ("spectrum_2d: %d\n", len) ;
        ncols = 2 ;
        matrix = floatMatrixPtr (len) ;
        for (i = 0 ; i < len ; i++) {
          matrix [i] = floatArrayPtr (ncols) ;
          }
        for (i = 0 ; i < len ; i++) {
          row = av_fetch (avref, i , 0) ;
          if (row =! NULL) {
            for (j = 0 ; j < ncols ; j++) {
              elem = av_fetch (*row, j , 0) ;
              if (elem == NULL) {
                matrix [i] [j] = 0 ;
                }
              else {
                matrix [i] [j] = SvNV (*elem) ;
                }
              }
            }
          }
        RETVAL = 0 ;
     OUTPUT:
        RETVAL

But it does not work,
If somebody could tell me what is wrong !

There are a few things wrong with this. There is no typedef for floatMatrix for
instance,
Sorry:
typedef double *floatMatrix ;

 and =! isn't a valid C operator.
Right, the compiler did not see it !!!
 But what is it supposed to do? It

For now, nothing, I need to fill my c array from the perl array (kind of 2d array), when I will be able to do it, then I will finish.

seems to be copying a Perl array of arrays to the floatmatrix 'matrix', but then
just ignores that copy and returns 0.0.

Rob


--
---
==========================================================================
 Patrick DUPRÉ                      |   |
 Department of Chemistry            |   |    Phone: (44)-(0)-1904-434384
 The University of York             |   |    Fax:   (44)-(0)-1904-432516
 Heslington                         |   |
 York YO10 5DD  United Kingdom      |   |    email: [EMAIL PROTECTED]
==========================================================================
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/

Reply via email to