diff --git a/include/boost/python/args.hpp b/include/boost/python/args.hpp index 9a5902ae..eaf5818f 100644 --- a/include/boost/python/args.hpp +++ b/include/boost/python/args.hpp @@ -20,7 +20,7 @@ # include # include -# include +# include # include # include @@ -66,7 +66,7 @@ namespace detail BOOST_STATIC_CONSTANT(bool, value = (is_ref & is_key)); typedef mpl::bool_c type; - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T)) }; # else typedef char (&yes_keywords_t)[1]; @@ -90,7 +90,7 @@ namespace detail == sizeof(detail::yes_keywords_t))); typedef mpl::bool_c type; - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T)) }; # endif } diff --git a/include/boost/python/detail/indirect_traits.hpp b/include/boost/python/detail/indirect_traits.hpp index d53e396c..92748982 100644 --- a/include/boost/python/detail/indirect_traits.hpp +++ b/include/boost/python/detail/indirect_traits.hpp @@ -18,7 +18,7 @@ # include # include # include -# include +# include # ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION # include @@ -86,7 +86,7 @@ template struct is_reference_to_member_function_pointer : is_reference_to_member_function_pointer_impl { - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T)) }; template @@ -192,7 +192,7 @@ struct is_reference_to_class >::value) ); typedef mpl::bool_c type; - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_class,(T)) }; template @@ -285,7 +285,7 @@ template struct is_pointer_to_function : mpl::if_, is_pointer_to_function_aux, mpl::bool_c >::type { - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_pointer_to_function,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_pointer_to_function,(T)) }; struct false_helper1 @@ -422,7 +422,7 @@ struct is_reference_to_function_pointer , mpl::bool_c >::type { - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_function_pointer,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_function_pointer,(T)) }; @@ -453,7 +453,7 @@ struct is_reference_to_member_function_pointer , mpl::bool_c >::type { - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T)) }; template @@ -470,7 +470,7 @@ struct is_reference_to_class & (sizeof(reference_to_class_helper(t)) == sizeof(inner_yes_type))) ); typedef mpl::bool_c type; - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_class,(T)) }; template diff --git a/include/boost/python/detail/mpl_lambda.hpp b/include/boost/python/detail/mpl_lambda.hpp index 33918c9b..edbea72a 100644 --- a/include/boost/python/detail/mpl_lambda.hpp +++ b/include/boost/python/detail/mpl_lambda.hpp @@ -8,12 +8,39 @@ # include -# if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 +# if 0 // defined(BOOST_MSVC) && BOOST_MSVC <= 1300 + // This approach fails, unfortunately + +# include +# include + +# define BOOST_PYTHON_LAMBDA_SUPPORT_FORMAL_ARG(R,class_,i,param) \ + BOOST_PP_COMMA_IF(i) class_ param \ + /**/ + +# define BOOST_PYTHON_LAMBDA_SUPPORT_ACTUAL_ARG(R,_,i,param) \ + BOOST_PP_COMMA_IF(i) param \ + /**/ + # define BOOST_PYTHON_MPL_LAMBDA_SUPPORT(i,name,params) \ struct rebind; \ }; \ - template \ - struct name < BOOST_PP_ENUM_PARAMS_Z(1, i, X) >::rebind \ + template < \ + BOOST_PP_LIST_FOR_EACH_I_R( \ + 1 \ + , BOOST_PYTHON_LAMBDA_SUPPORT_FORMAL_ARG \ + , class \ + , BOOST_PP_TUPLE_TO_LIST(i,params) \ + ) \ + > \ + struct name < \ + BOOST_PP_LIST_FOR_EACH_I_R( \ + 1 \ + , BOOST_PYTHON_LAMBDA_SUPPORT_ACTUAL_ARG \ + , class \ + , BOOST_PP_TUPLE_TO_LIST(i,params) \ + ) \ + >::rebind \ { \ BOOST_STATIC_CONSTANT(int, arity = i); \ BOOST_PP_LIST_FOR_EACH_I_R( \ diff --git a/include/boost/python/detail/msvc_typeinfo.hpp b/include/boost/python/detail/msvc_typeinfo.hpp index 92f0f56d..11a8bed4 100644 --- a/include/boost/python/detail/msvc_typeinfo.hpp +++ b/include/boost/python/detail/msvc_typeinfo.hpp @@ -6,12 +6,10 @@ #ifndef MSVC_TYPEINFO_DWA200222_HPP # define MSVC_TYPEINFO_DWA200222_HPP -#include #include -#include -#include -#include -#include +#include +#include + // // Fix for MSVC's broken typeid() implementation which doesn't strip // decoration. This fix doesn't handle cv-qualified array types. It @@ -24,78 +22,62 @@ namespace boost { namespace python { namespace detail { typedef std::type_info const& typeinfo; -templatestruct value_id_accessor; - -template<> -struct value_id_accessor<0> -{ - template - static typeinfo get(T*) { return typeid(T); } -}; - -template<> -struct value_id_accessor<1> -{ - template - static typeinfo get(T const*) { return typeid(T); } -}; - -template<> -struct value_id_accessor<2> -{ - template - static typeinfo get(T volatile*) { return typeid(T); } -}; - -template<> -struct value_id_accessor<3> -{ - template - static typeinfo get(T const volatile*) { return typeid(T); } -}; - -template struct bool_t{}; +template +static typeinfo typeid_nonref(T*, ...) { return typeid(T); } template -inline typeinfo typeid_nonref(boost::type* = 0) -{ - bool const c = is_const::value; - bool const v = is_volatile::value; - return value_id_accessor<(2 * v + c)>::get((T*)0); -} +static typeinfo typeid_nonref(T const*, int) { return typeid(T); } template -inline typeinfo typeid_ref(T&(*)()) -{ - return typeid_nonref(); -} +static typeinfo typeid_nonref(T volatile*, int) { return typeid(T); } template -inline typeinfo array_ref_typeid(bool_t, bool_t, boost::type* = 0) -{ - return typeid_ref((T&(*)())0); -} +static typeinfo typeid_nonref(T const volatile*, long) { return typeid(T); } + +# ifdef BOOST_INTEL_CXX_VERSION +// The const volatile overload above confuses Intel when dealing with arrays +template +static typeinfo typeid_nonref(T(*)[N], long) { return typeid(T[N]); } +# endif template -inline typeinfo array_ref_typeid(bool_t, bool_t, boost::type* = 0) +inline typeinfo typeid_ref_1(T&(*)()) { - return typeid_ref((T(*)())0); + return detail::typeid_nonref((T*)0,0L); } +// A non-reference template -inline typeinfo array_ref_typeid(bool_t, bool_t, boost::type* = 0) +inline typeinfo typeid_ref(type*, T&(*)(type)) { - return typeid_ref((T&(*)())0); + return detail::typeid_nonref((T*)0,0L); } +// A reference +template +inline typeinfo typeid_ref(type*, ...) +{ + return detail::typeid_ref_1((T(*)())0); +} + +template< typename T > T&(* is_ref_tester1(type) )(type) { return 0; } +inline char BOOST_TT_DECL is_ref_tester1(...) { return 0; } + template inline typeinfo msvc_typeid(boost::type* = 0) { - typedef bool_t::value> array_tag; - typedef bool_t::value> ref_tag; - return array_ref_typeid(array_tag(), ref_tag(), (boost::type*)0); + return detail::typeid_ref( + (boost::type*)0, detail::is_ref_tester1(type()) + ); } +# ifndef NDEBUG +inline typeinfo assert_array_typeid_compiles() +{ + return msvc_typeid(), msvc_typeid(); +} +# endif + }}} // namespace boost::python::detail # endif // BOOST_MSVC diff --git a/include/boost/python/detail/this_arg_from_python.hpp b/include/boost/python/detail/this_arg_from_python.hpp deleted file mode 100644 index 36ad7ae7..00000000 --- a/include/boost/python/detail/this_arg_from_python.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#error obsolete -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. -#ifndef THIS_ARG_FROM_PYTHON_DWA20021122_HPP -# define THIS_ARG_FROM_PYTHON_DWA20021122_HPP - -# include -# include - -# include - -# include - -namespace boost { namespace python { namespace detail { - -template -struct this_ptr_arg_from_python : converter::arg_lvalue_from_python_base -{ - this_ptr_arg_from_python(PyObject* x) - : converter::arg_lvalue_from_python_base( - converter::get_lvalue_from_python(x, converter::registered::converters)) - {} - - typedef T* result_type; - T* operator()() const - { - return static_cast(this->result()); - } - - bool use_default() const - { - return dynamic_cast((*this)()); - } -}; - -template -struct this_ref_arg_from_python : this_ptr_arg_from_python -{ - typedef this_ptr_arg_from_python base; - this_ref_arg_from_python(PyObject* x) : base(x) {} - typedef T& result_type; - - result_type operator()() const - { - return *this->base::operator()(); - } -}; - -// An MPL metafunction class which returns a `this' converter -// appropriate for ArgType, where the target of the member function is -// a class of type T. -template -struct gen_this_from_python -{ - // Note: there will almost always be an compile-time error if the - // argument type is neither a reference nor a pointer, since T* - // will be extracted in that case and passed on to the wrapped - // function. - template struct apply - { - BOOST_STATIC_CONSTANT( - bool, use_ptr - = is_pointer::value - || boost::python::detail::is_reference_to_pointer::value - && boost::python::detail::is_reference_to_const::value - && !boost::python::detail::is_reference_to_volatile::value); - - typedef typename mpl::if_c< - is_back_reference::value - , nullary > - , typename mpl::if_c< - use_ptr - , this_ptr_arg_from_python - , this_ref_arg_from_python - >::type - >::type type; - }; -}; - -// An MPL iterator which iterates over a sequence whose first element -// is gen_this_from_python and the remainder of which is an endless -// sequence of gen_arg_from_python -template -struct method_args_from_python -{ - typedef gen_this_from_python type; - typedef args_from_python next; -}; - -template -struct defaulted_virtual_fn -{ - defaulted_virtual_fn(VirtualFunction dispatch, Default const& default_impl) - : dispatch(dispatch), default_impl(default_impl) {}; - - VirtualFunction dispatch; - Default default_impl; -}; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -struct is_defaulted_virtual_fn -{ BOOST_STATIC_CONSTANT(bool, value = false); }; - -template -struct is_defaulted_virtual_fn > -{ BOOST_STATIC_CONSTANT(bool, value = true); }; -# else -template -struct is_defaulted_virtual_fn -{ - template - static char helper(defaulted_virtual_fn* x); - static char (& helper(...)) [2]; - - BOOST_STATIC_CONSTANT(bool, value = sizeof(helper((T*)0)) == 1); - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_defaulted_virtual_fn,(T)) -}; -# endif - -}}} // namespace boost::python::detail - -#endif // THIS_ARG_FROM_PYTHON_DWA20021122_HPP diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index 882ce756..47e6da3c 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -22,7 +22,9 @@ #include #include #include -#include + +# include + #include #include #include @@ -104,7 +106,7 @@ namespace detail sizeof(f(t())) == sizeof(::boost::type_traits::yes_type)); typedef mpl::bool_c type; - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_optional,(T)) }; /////////////////////////////////////// @@ -126,7 +128,7 @@ namespace detail struct is_optional : is_optional_impl { typedef mpl::bool_c::value> type; - BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T)) + BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_optional,(T)) }; #endif // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) diff --git a/test/Jamfile b/test/Jamfile index f1cc1302..38e23b2e 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -74,8 +74,7 @@ bpl-test exception_translator ; bpl-test pearu1 : test_cltree.py cltree.cpp ; bpl-test try : newtest.py m1.cpp m2.cpp ; -# Had to break this up into two files for MSVC6 -extension builtin_converters : test_builtin_converters.cpp test_builtin_converters2.cpp ../build/boost_python ; +extension builtin_converters : test_builtin_converters.cpp ../build/boost_python ; boost-python-runtest builtin_converters : test_builtin_converters.py builtin_converters ; bpl-test test_pointer_adoption ; diff --git a/test/test_builtin_converters.cpp b/test/test_builtin_converters.cpp index a078d41f..4f08c534 100644 --- a/test/test_builtin_converters.cpp +++ b/test/test_builtin_converters.cpp @@ -44,10 +44,6 @@ using boost::python::handle; using boost::python::object; using boost::python::borrowed; -// MSVC6 can't process this whole file at once, so we break it up into -// two parts. See test_builtin_converters2.cpp -#ifndef BOOST_PYTHON_WRAP_MORE_BUILTIN_CONVERTERS - // Used to test that arbitrary handle<>s can be returned handle get_type(handle<> x) { @@ -61,10 +57,8 @@ handle<> return_null_handle() char const* rewrap_value_mutable_cstring(char* x) { return x; } -void wrap_more(); - BOOST_PYTHON_MODULE(builtin_converters) -{ +{ def("get_type", get_type); def("return_null_handle", return_null_handle); @@ -80,7 +74,7 @@ BOOST_PYTHON_MODULE(builtin_converters) def("rewrap_value_unsigned_long", by_value::rewrap); // using Python's macro instead of Boost's - we don't seem to get the // config right all the time. -# ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG def("rewrap_value_long_long", by_value::rewrap); def("rewrap_value_unsigned_long_long", by_value::rewrap); # endif @@ -98,14 +92,6 @@ BOOST_PYTHON_MODULE(builtin_converters) // Expose this to illustrate our failings ;-). See test_builtin_converters.py def("rewrap_value_mutable_cstring", rewrap_value_mutable_cstring); - wrap_more(); -} - -#else // BOOST_PYTHON_WRAP_MORE_BUILTIN_CONVERTERS -- this part - // compiled into test_builtin_converters2.cpp - -void wrap_more() -{ def("rewrap_const_reference_bool", by_const_reference::rewrap); def("rewrap_const_reference_char", by_const_reference::rewrap); @@ -133,10 +119,6 @@ void wrap_more() def("rewrap_const_reference_cstring", by_const_reference::rewrap); def("rewrap_const_reference_handle", by_const_reference >::rewrap); def("rewrap_const_reference_object", by_const_reference::rewrap); - - def("rewrap_reference_object", by_reference::rewrap); } -#endif // BOOST_PYTHON_WRAP_MORE_BUILTIN_CONVERTERS - diff --git a/test/test_builtin_converters2.cpp b/test/test_builtin_converters2.cpp deleted file mode 100644 index 37807637..00000000 --- a/test/test_builtin_converters2.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright David Abrahams 2002. Permission to copy, use, -// modify, sell and distribute this software is granted provided this -// copyright notice appears in all copies. This software is provided -// "as is" without express or implied warranty, and with no claim as -// to its suitability for any purpose. - -// This file just defines the rest of the tests that MSVC6 can't -// compile unless we break the file up. It's a hack, I'll admit... -#define BOOST_PYTHON_WRAP_MORE_BUILTIN_CONVERTERS -#include "test_builtin_converters.cpp"