If I have  void foo(double **x) which I want to call both with a list object and with the PyObject returned from the use of cpointer.i :

>>>from example import *
>>> l=[1.0, 2.0, 3.0, 4.0]
>>> x=myalloc(2,2)  #use cpointer.i
>>> foo(4, l)             #now I use the typemap
>>> foo(4, x)            #now I use the PyObject returned by cpointer.i

python complains when interpreting foo(4,x)
>>> foo(4,x)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: not a list

How can I pass double **x to foo?
Here below is example.i

%module example

%include cpointer.i

%typemap(python,in) (double **) {
  if (PyList_Check($input)) {
    int i;
    int size = PyList_Size($input);
    $1 = (double **) malloc(sizeof(double*));
    $1[0]=(double *) malloc(size*sizeof(double));
    for(i=0; i<size; i++){
      PyObject *o = PyList_GetItem($input,i);
      if (PyFloat_Check(o))
    $1[0][i] = PyFloat_AsDouble(o);
      else {
    PyErr_SetString(PyExc_TypeError,"list must contain doubles");
    return NULL;
      }
    }
  }
  else {
    PyErr_SetString(PyExc_TypeError,"not a list");
    return NULL;
  }

}/*closes typemap*/


%inline{

  double **myalloc(int n, int m){
    int i,nm=n*m;
    double **r;
    r= (double**) malloc(n*sizeof(double*));
    r[0]= (double*) malloc(nm*sizeof(double));
    for(i=1;i<n;i++) r[i]=r[i-1]+m;
    return r;
  }

  void foo(int nm, double **x){
   int i;
   for(i=0;i<nm;i++) printf("%lf ",x[0][i]);
   printf("\n");
  }

} /*closes inline*/