[Insight-users] Getting PyObject* through to wrapped C++ code

Charl P. Botha c . p . botha at ewi . tudelft . nl
Tue, 22 Jul 2003 20:15:46 +0200


Hi Bill,

Sorry for all the mails, but I've just discovered something very
interesting.  This also leads to a more elegant solution to all current
difficulties (I hope).

Please bear with me.

On Tue, Jul 22, 2003 at 01:41:22PM -0400, Bill Hoffman wrote:
>  Node *top = Swig_cparse(cpps);
>  CableSwig cswig; 
>  cswig.ParseFile(input_file, top, typemap_lang);

Also in this code, we see the following:
Printf(fs,"%%include \"swig.swg\"\n");
if (lang_config) {
    Printf(fs,"\n%%include \"%s\"\n", lang_config);
}

lang_config is set by python.cxx (part of swig) to python.swg and by
tcl8.cxx to tcl8.swg.  This means that swig IS seeing the following typemap:

%typemap(in)   PyObject * "$1 = $input;";
%typemap(out)  PyObject * "$result = $1;";

Which means it SHOULDN'T be touching PyObject* parameter or return types!
However, Cable doesn't see these as "PyObject *"s, but as "p._object", due
to the fact that PyObject is actually a typedef'ed _object in the system
global python.h.  So, the typemap is being set, but Cable is presenting
PyObjects with another name, so Swig isn't recognising them and consequently
PyObject*s are being mangled.

Should python.swg be patched?  Or should we create a global python-cable.swg
and tcl8-cable.swg with corrections for CableSwig specific behaviour?

My idea would be to create a global itk.swg that always gets parsed (after
the language specific .swg) with corrections/global additions.  It should be
possible to move the exception handling there as well as the corrected type
mappings.

What say you?  Would you like me to implement a proof-of-concept?

Thanks,
Charl
                          
-- 
charl p. botha http://cpbotha . net/ http://visualisation . tudelft . nl/