From: Olly B. <ol...@su...> - 2008-01-10 18:18:25
|
On 2008-01-10, Jelmer Vernooij <je...@sa...> wrote: > I'd rather avoid that if possible, defines indeed make the code less > readable and we do have to read the code when debugging the > SWIG-generated code. While readable generated code is certainly useful, I think there are higher priorities. As the boilerplate comment at the top already says: "This file is not intended to be easily readable" > Ideally I would like to just push all of the complexity for this into > SWIG and make the -modern flag take care of not emitting these casts. > Why specifically is this not technically possible at the moment ? I > would be happy to provide patches, if possible. Because -modern currently requires Python 2.2 or newer, and only Python 2.5 doesn't need these casts (older versions generate warnings with recent versions of GCC). I don't think it makes sense to add a "-moremodern" option just for this - SWIG already has bafflingly many options (particularly for Python), and more options means more combinations which won't be regularly tested and so will bitrot. Also, "--moremodern" would go against the general SWIG aim of producing code which works with as many versions of the targetted tool as feasible. I think right now a macro is your best option. Either as William describes, or one which wraps PyObject_GetAttrString() and inserts the cast when required - e.g.: #if PY_VERSION_HEX >= 0x02050000 # define SWIG_PyObject_GetAttrString(A, B) PyObject_GetAttrString((A), (B)) #else # define SWIG_PyObject_GetAttrString(A, B) PyObject_GetAttrString((A), (char*)(B)) #endif I don't know how many other Python functions will need this though. If it's required for any function which takes a string, it could be rather a big job. Cheers, Olly |