mirror of
https://github.com/boostorg/python.git
synced 2026-01-23 17:52:17 +00:00
Fix static object initialization under Visual Studio 2017 (#208)
Fix static object initialization under VS 15.7.2
This commit is contained in:
committed by
Stefan Seefeld
parent
4f6d547c0a
commit
65bfec2d97
@@ -109,6 +109,23 @@ struct converter_target_type <void_result_to_python >
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Generation of ret moved from caller_arity<N>::impl::signature to here due to "feature" in MSVC 15.7.2 with /O2
|
||||
// which left the ret uninitialized and caused segfaults in Python interpreter.
|
||||
template<class Policies, class Sig> const signature_element* get_ret()
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Policies::template extract_return_type<Sig>::type rtype;
|
||||
typedef typename select_result_converter<Policies, rtype>::type result_converter;
|
||||
|
||||
static const signature_element ret = {
|
||||
(is_void<rtype>::value ? "void" : type_id<rtype>().name())
|
||||
, &detail::converter_target_type<result_converter>::get_pytype
|
||||
, boost::detail::indirect_traits::is_reference_to_non_const<rtype>::value
|
||||
};
|
||||
|
||||
return &ret;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -229,16 +246,12 @@ struct caller_arity<N>
|
||||
{
|
||||
const signature_element * sig = detail::signature<Sig>::elements();
|
||||
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
|
||||
// MSVC 15.7.2, when compiling to /O2 left the static const signature_element ret,
|
||||
// originally defined here, uninitialized. This in turn led to SegFault in Python interpreter.
|
||||
// Issue is resolved by moving the generation of ret to separate function in detail namespace (see above).
|
||||
const signature_element * ret = detail::get_ret<Policies, Sig>();
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Policies::template extract_return_type<Sig>::type rtype;
|
||||
typedef typename select_result_converter<Policies, rtype>::type result_converter;
|
||||
|
||||
static const signature_element ret = {
|
||||
(is_void<rtype>::value ? "void" : type_id<rtype>().name())
|
||||
, &detail::converter_target_type<result_converter>::get_pytype
|
||||
, boost::detail::indirect_traits::is_reference_to_non_const<rtype>::value
|
||||
};
|
||||
py_func_sig_info res = {sig, &ret };
|
||||
py_func_sig_info res = {sig, ret };
|
||||
#else
|
||||
py_func_sig_info res = {sig, sig };
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user