make implicit conversions non-reentrant (fixes #1035) (#1037)

This commit is contained in:
Wenzel Jakob
2017-08-28 16:34:06 +02:00
committed by GitHub
parent 15f36d2b2d
commit 8ed5b8ab55
4 changed files with 34 additions and 0 deletions

View File

@@ -1536,7 +1536,16 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
}
template <typename InputType, typename OutputType> void implicitly_convertible() {
struct set_flag {
bool &flag;
set_flag(bool &flag) : flag(flag) { flag = true; }
~set_flag() { flag = false; }
};
auto implicit_caster = [](PyObject *obj, PyTypeObject *type) -> PyObject * {
static bool currently_used = false;
if (currently_used) // implicit conversions are non-reentrant
return nullptr;
set_flag flag_helper(currently_used);
if (!detail::make_caster<InputType>().load(obj, false))
return nullptr;
tuple args(1);