Hi,

I'm new to this list so I hope my question is relevant.  I've tried to suss it out as best I can.

I'm trying wrap a large custom binary package that my research group uses so that I can more easily mesh our data storage to analysis tools.  Python is a very natural language for this (the analysis packages already have well developed python bindings) and swig has a lot of promise for bringing this all together.

There are a few difficulties in that our binary package depends greatly on global c-structures which are loaded from data in files.  In addition, the c-structures can have all kinds of arrays.  I have a bunch of questions which I will ask later, but now swig seems to have a bug wrapping a global triple array.  I have included a simple example which includes a global triple array and two functions to access the data:

/* File : example.c */
#define SIZE 10
int  myArray[SIZE][SIZE][SIZE];

void setArray(int array[SIZE][SIZE][SIZE]){
  int i, j, k;
  for(i=0;i<SIZE;i++){
    for(j=0;j<SIZE;j++){
      for(k=0;k<SIZE;k++){
    array[i][j][k] = i*j*k;
      }
    }
  }
}

int getArrayValue3(int array[SIZE][SIZE][SIZE], int i, int j, int k){
  return array[i][j][k];
}

When I wrap this, there is a problem with the "set" function:


SWIGINTERN int Swig_var_myArray_set(PyObject *_val) {
  {
    int (*inp)[10] = 0;
    int res = SWIG_ConvertPtr(_val, SWIG_as_voidptrptr(&inp), SWIGTYPE_p_a_10__a_10__int,  0 );
    if (!SWIG_IsOK(res)) {
      SWIG_exception_fail(SWIG_ArgError(res), "in variable '""myArray""' of type '""int [10][10][10]""'");
    } else if (inp) {
      size_t ii = 0;
      for (; ii < (size_t)10; ++ii) {
        if (inp[ii]) {
          size_t jj = 0;
          for (; jj < (size_t)10; ++jj) myArray[ii][jj] = inp[ii][jj];
        } else {
          SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""myArray""' of type '""int [10][10][10]""'");
        }
      }
    } else {
      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""myArray""' of type '""int [10][10][10]""'");
    }
  }
  return 0;
fail:
  return 1;
}


The error is in this line:
for (; jj < (size_t)10; ++jj) myArray[ii][jj] = inp[ii][jj];

inp is a double array and myArray is a triple.

I replaced this (by hand) with this function:


SWIGINTERN int Swig_var_myArray_set(PyObject *_val) {
  {
    int (*inp)[10][10] = 0;
    int res = SWIG_ConvertPtr(_val, SWIG_as_voidptrptr(&inp), SWIGTYPE_p_a_10__a_10__int,  0 );
    if (!SWIG_IsOK(res)) {
      SWIG_exception_fail(SWIG_ArgError(res), "in variable '""myArray""' of type '""int [10][10][10]""'");
    } else if (inp) {
      size_t ii = 0;
      for (; ii < (size_t)10; ++ii) {
        if (inp[ii]) {
          size_t jj = 0;
          for (; jj < (size_t)10; ++jj){
        if(inp[ii][jj]){
          size_t kk = 0;
          for(; kk < (size_t) 10; ++kk) myArray[ii][jj][kk] = inp[ii][jj][kk];
        } else {
          SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""myArray""' of type '""double [10][10][10]""'");
        }
      }
        } else {
          SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""myArray""' of type '""int [10][10][10]""'");
        }
      }
    } else {
      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""myArray""' of type '""int [10][10][10]""'");
    }
  }
  return 0;
fail:
  return 1;
}


and everything works fine.  I can load and access the data.  Is this a bug?  Are "triple" arrays simply not supported?  If not, my job will be much harder! 

Thanks again,

If you need anything else from me please let me know.

Elliott