From: Jelmer V. <je...@sa...> - 2008-01-10 17:32:26
|
Am Montag, den 07.01.2008, 09:37 +0000 schrieb William S Fulton: > Jelmer Vernooij <jelmer <at> samba.org> writes:=20 > > swig currently generates a lot of casts from (const char *) to (char *)= . > > This is only necessary for older versions of Python; newer versions use > > the "const" keyword appropriately. For example, the (char *) in the > > following line is no longer necessary for Python >=3D 2.5: > >=20 > > data->newraw =3D PyObject_GetAttrString(data->klass, (char *)"__new__")= ; > >=20 > > Would it be possible to have some way to disable these casts? They > > generate a lot of spurious warnings for those of us that use some more > > pedantic compiler warnings (such as -Wcast-qual for gcc) and make the > > code harder to read.=20 > >=20 >=20 > I guess they could be replaced by a macro that would do nothing if python= >=3D 2.5 > or provide the cast otherwise. The code would then look something like: >=20 > data->newraw =3D PyObject_GetAttrString(data->klass, SWIG_CHAR_CAST"__new= __"); >=20 > where SWIG_CHAR_CAST would be one of the following depending on which pyt= hon.h > is being compiled with: >=20 > #define SWIG_CHAR_CAST (char *) > #define SWIG_CHAR_CAST >=20 > It isn't much more readable, in fact it is less readable, but it will get= rid of > your warnings. The code that SWIG generates is largely independent of the > version of Python being targeted. There are some SWIG Python module speci= fic > flags, like -modern, which would ideally be used. However this is not > technically possible as a lot of the code that goes into the wrappers is = not > processed by SWIG, it is simply dumped into the wrappers. Ultimately this= means > that you wouldn't be able to use SWIG to process this code to strip out t= he > macro. A simple post processing sed script could do it though. 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.=20 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. Cheers, Jelmer --=20 Jelmer Vernooij <je...@sa...> - http://samba.org/~jelmer/ Jabber: je...@ja... |