Change in default behaviour wrapping C++ bool for Python.

Only a Python True or False will now work for C++ bool parameters.
This fixes overloading bool with other types.
This commit is contained in:
William S Fulton 2014-03-08 12:04:19 +00:00
commit 504c2030bb
11 changed files with 251 additions and 11 deletions

View file

@ -12,6 +12,8 @@ SWIGINTERNINLINE PyObject*
}
}
#ifdef SWIG_PYTHON_LEGACY_BOOL
// Default prior to SWIG 3.0.0
%fragment(SWIG_AsVal_frag(bool),"header",
fragment=SWIG_AsVal_frag(long)) {
SWIGINTERN int
@ -24,6 +26,23 @@ SWIG_AsVal_dec(bool)(PyObject *obj, bool *val)
return SWIG_OK;
}
}
#else
%fragment(SWIG_AsVal_frag(bool),"header",
fragment=SWIG_AsVal_frag(long)) {
SWIGINTERN int
SWIG_AsVal_dec(bool)(PyObject *obj, bool *val)
{
int r;
if (!PyBool_Check(obj))
return SWIG_ERROR;
r = PyObject_IsTrue(obj);
if (r == -1)
return SWIG_ERROR;
if (val) *val = r ? true : false;
return SWIG_OK;
}
}
#endif
/* int */

View file

@ -5,9 +5,11 @@
/* ------------------------------------------------------------
* Fragment section
* ------------------------------------------------------------ */
/* bool is dangerous in Python, change precedence */
#ifdef SWIG_PYTHON_LEGACY_BOOL
// Default prior to SWIG 3.0.0
#undef SWIG_TYPECHECK_BOOL
%define SWIG_TYPECHECK_BOOL 10000 %enddef
#endif
/* Include fundamental fragment definitions */
%include <typemaps/fragments.swg>