From: William S F. <ws...@fu...> - 2014-06-05 19:25:39
|
On 05/06/14 12:53, Bob Hood wrote: > On 6/5/2014 3:07 AM, Leonardo Bernardini wrote: >> Hi all, >> >> I’m trying to update my bindings to Swig 3.X , but it seems that , casting to a bool value from an integer is no longer automatic neither accepted. >> Example: >> >> While previously I was able to invoke my module function (setStatus(bool)) in that way: >> >> MyModule.setStatus(1) >> >> now this is no longer possible and produces an exception. I need to explicitly call: >> >> MyModule.setStatus(True) >> >> Is it possible to revert back to the previous configuration, using a typemap or whatever else ? > > Well, I'm just taking a shot, but wouldn't a typemap like this (example in > Python) do what you need? > > %typemap(in) bool{ > $1 = false; // any type other than numeric is automatically false > if(PyInt_Check($input)) > $1 = !(PyInt_AsLong($input) == (long)0); > else if(PyFloat_Check($input)) > $1 = !(PyFloat_AsDouble($input) == 0.0); > } > > See the README file, also online at http://swig.org/release.html. Look for the entry beginning: 2014-03-06: wsfulton [Python] Change in default behaviour wrapping C++ bool. Note you can also use -DSWIG_PYTHON_LEGACY_BOOL to resurrect the old behaviour if you don't fancy using the above sort of typemap. William |