%module SWIG_MODULE_NAME // This tells SWIG to treat char ** as a special case %typemap(in) char ** { // Check if is a list if (PyList_Check($input)) { int size = PyList_Size($input); int i = 0; $1 = (char **) malloc((size+1)*sizeof(char *)); for (i = 0; i < size; i++) { PyObject *o = PyList_GetItem($input,i); if (PyString_Check(o)) $1[i] = PyString_AsString(PyList_GetItem($input,i)); else { PyErr_SetString(PyExc_TypeError,"list must contain strings"); free($1); return NULL; } } $1[i] = 0; } else { PyErr_SetString(PyExc_TypeError,"not a list"); return NULL; } } // This cleans up the char ** array we malloc'd before the function call %typemap(freearg) char ** { free((char *) $1); } // Language independent exception handler %include exception.i // this take care of various exception %exception { CATCH(any_exception_error) { SWIG_exception(SWIG_UnknownError,pyps_last_error); free(pyps_last_error); pyps_last_error=0; } TRY { $action if((void*)$symname != (void*)atinit) { // this is because atinit creates the exception handler, // so it had no exception handler when calling throw if (pyps_last_error) { free(pyps_last_error); pyps_last_error = NULL; } UNCATCH(any_exception_error); } } } %typemap(in) string { $1 = PyString_AsString($input); } %typemap(out) string { $result = PyString_FromString($1); } extern char* activate(const char*); extern int delete_workspace(char*); extern int open_workspace(char*); extern int close_workspace(int); extern void db_invalidate_memory_resource(char*, char*); // SWIG will generate code for pypips.user_log with up to 10 arguments %varargs(10, char *arg = NULL) user_log; extern void user_log(const char* fmt, ...);