title: How to pass list of structs to C in SWIG/Python
body: <p>I have a C++ class I'm exporting via swig, and a function that takes an array of <code>Foo</code>s:</p>
  
  <pre><code>typedef class Foo {
    int i;
  } Foo;
  
  void func(Foo *all_foos);
  </code></pre>
  
  <p>Now I'd like to be able to pass a python list containing those into all_foos:</p>
  
  <pre><code>afoo = mymod.Foo()
  bfoo = mymod.Foo()
  mymod.func([afoo, bfoo])
  </code></pre>
  
  <p>I have a typemap which doesn't work.  See the FIXME line for where I need help.</p>
  
  <pre><code>%typemap(in) Foo ** {
    /* Check if it's a list */
    if (PyList_Check($input)) {
      int size = PyList_Size($input);
      int i = 0;
      $1 = (Foo **) malloc((size+1)*sizeof(Foo *));
      for (i = 0; i &lt; size; i++) {
        PyObject *o = PyList_GetItem($input,i);
        // here o-&gt;ob_type-&gt;tp_name is "Foo"; could check that
        // FIXME: HOW DO I GO FROM o -&gt; SwigPyObject -&gt; Foo *?  THIS IS WRONG
        $1[i] = (Foo *)(reinterpret_cast&lt;SwigPyObject *&gt;(o))-&gt;ptr;
      }
    } else {
      PyErr_SetString(PyExc_TypeError,"not a list");
      return NULL;
    }
  }
  </code></pre>
  
  <p>Basically, I have a <code>PyObject</code> o; I need to get the <code>SwigPyObject</code> from it (do I just cast it?  Or is it a member?) and then get my <code>Foo</code> pointer from the <code>SwigPyObject</code> somehow.</p>