I'm very new to SWIG, so if this answer is obvious, please forgive me. 

I'm trying to use SWIG to wrap a class that is similar to the following (I'm under NDA, and can't show the actual listing, so this is here to protect the guilty).

namespace A
{
    class B: public C
    {
        public:
            // constructors, destructors, etc.

            // My current headache
            int foo(char**& inout1, int**& inout2);
    };
}

There are a number of methods in this class that are similar to this, some of which are quite a bit more involved.  Each pointer is to a variable length array whose last element is NULL to indicate that there are no more pointers left.  The char array is just an array of NULL terminated C-strings.  Each array in the int array is length-prefixed; that is, the first element of the array is the number of elements in the rest of the array.  The problem is that this is both an input and an output; data is calloc()ed and passed in, then the method pulls out the pieces of interest, and operates on it.  It then decides if it is going to realloc() the array of pointers to make it larger, or calloc() a new array and copy over the pointers of interest from the old array.  It may also decide to mess with the C-strings/integer arrays, free()ing them, modifying them, etc.  Once the method returns, the caller owns all of the allocated memory; normal usage is to do what you want with it, and then either reuse what you need, or go through a deallocation loop that free()s everything.

My problem is that I have to find a way of wrapping this so that Python can use it sanely, and I'm not allowed to modify the header.  I looked at http://www.swig.org/Doc2.0/SWIGDocumentation.html#Library_nn11 for %newobject, but since that works on the return value, I wasn't sure if it is appropriate for this.  I also looked at the example at http://www.swig.org/Doc2.0/Python.html#Python_nn59 but I'm not sure if or how that applies here.

Any help would be appreciated!  I'm at my wits end, and like everyone, I'm on a tight deadline.

Thanks,
Cem Karan