Skip to content

Commit

Permalink
Fix tests on 3.6 <= Python < 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickJadoul committed Jan 22, 2021
1 parent caa5382 commit cffc586
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1049,18 +1049,22 @@ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
if (index_check(src.ptr())) {
index = reinterpret_steal<object>(PyNumber_Index(src.ptr()));
if (!index) {
PyErr_Clear();
return false;
src_or_index = handle();
py_value = (py_type) -1;
}
else {
src_or_index = index;
}
src_or_index = index;
}
#endif
if (std::is_unsigned<py_type>::value) {
py_value = as_unsigned<py_type>(src_or_index.ptr());
} else { // signed integer:
py_value = sizeof(T) <= sizeof(long)
? (py_type) PyLong_AsLong(src_or_index.ptr())
: (py_type) PYBIND11_LONG_AS_LONGLONG(src_or_index.ptr());
if (src_or_index) {
if (std::is_unsigned<py_type>::value) {
py_value = as_unsigned<py_type>(src_or_index.ptr());
} else { // signed integer:
py_value = sizeof(T) <= sizeof(long)
? (py_type) PyLong_AsLong(src_or_index.ptr())
: (py_type) PYBIND11_LONG_AS_LONGLONG(src_or_index.ptr());
}
}
}

Expand Down

0 comments on commit cffc586

Please sign in to comment.