From: Guillaume B. <gui...@ub...> - 2010-03-05 10:29:05
|
Digger into that issue, I found something quite strange to me: SWIG converts to bool on a PyObject_IsTrue basis, not on a proper PyBool_Check. This behavior is not what I want, so I patched it; I don't know what variant is the most "pythonic" though... :) Index: Lib/python/pyprimtypes.swg =================================================================== --- Lib/python/pyprimtypes.swg (revision 11893) +++ Lib/python/pyprimtypes.swg (working copy) @@ -17,11 +17,12 @@ SWIGINTERN int SWIG_AsVal_dec(bool)(PyObject *obj, bool *val) { - int r = PyObject_IsTrue(obj); - if (r == -1) - return SWIG_ERROR; - if (val) *val = r ? true : false; - return SWIG_OK; + if( PyBool_Check(obj) ) + { + if(val) *val = (obj==Py_True) ? true : false; + return SWIG_OK; + } + return SWIG_TypeError; } } Index: Lib/python/pytypemaps.swg =================================================================== --- Lib/python/pytypemaps.swg (revision 11893) +++ Lib/python/pytypemaps.swg (working copy) @@ -6,8 +6,9 @@ * Fragment section * ------------------------------------------------------------ */ /* bool is dangerous in Python, change precedence */ -#undef SWIG_TYPECHECK_BOOL -%define SWIG_TYPECHECK_BOOL 10000 %enddef +// commented because I've changed the conversion to bool behaviour in this patch. +// #undef SWIG_TYPECHECK_BOOL +// %define SWIG_TYPECHECK_BOOL 10000 %enddef /* Include fundamental fragemt definitions */ %include <typemaps/fragments.swg> |