From fd1d332d3f662e323cad589aea424c08d174a327 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Fri, 13 Sep 2002 22:35:45 +0000 Subject: [PATCH] Works with arbitrary arity, MSVC6 [SVN r15310] --- include/boost/python/args.hpp | 74 +---------- include/boost/python/bases.hpp | 15 +-- include/boost/python/call.hpp | 4 +- include/boost/python/call_method.hpp | 4 +- include/boost/python/class.hpp | 2 +- include/boost/python/detail/config.hpp | 8 ++ include/boost/python/detail/defaults_def.hpp | 11 +- include/boost/python/detail/defaults_gen.hpp | 41 +++--- include/boost/python/detail/destroy.hpp | 8 +- include/boost/python/detail/make_tuple.hpp | 2 +- include/boost/python/detail/preprocessor.hpp | 7 +- include/boost/python/detail/returning.hpp | 16 +-- include/boost/python/detail/type_list.hpp | 38 ++++-- .../boost/python/detail/type_list_impl.hpp | 55 ++++++++ .../python/detail/type_list_impl_no_pts.hpp | 101 +++++++++++++++ .../boost/python/detail/type_list_utils.hpp | 118 +++--------------- include/boost/python/detail/wrap_python.hpp | 6 +- include/boost/python/enum.hpp | 6 +- include/boost/python/init.hpp | 14 ++- include/boost/python/object/instance.hpp | 3 +- include/boost/python/object/make_holder.hpp | 22 +++- .../boost/python/object/pointer_holder.hpp | 4 +- include/boost/python/object/value_holder.hpp | 4 +- include/boost/python/object_core.hpp | 2 +- include/boost/python/signature.hpp | 58 +++++---- 25 files changed, 343 insertions(+), 280 deletions(-) create mode 100644 include/boost/python/detail/type_list_impl.hpp create mode 100644 include/boost/python/detail/type_list_impl_no_pts.hpp diff --git a/include/boost/python/args.hpp b/include/boost/python/args.hpp index 7ad0265e..941529f0 100644 --- a/include/boost/python/args.hpp +++ b/include/boost/python/args.hpp @@ -1,5 +1,3 @@ -#if !defined(BOOST_PP_IS_ITERATING) - // 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 @@ -8,15 +6,8 @@ #ifndef ARGS_DWA2002323_HPP # define ARGS_DWA2002323_HPP # include - # include - -# include -# include - -# include -# include -# include +# include namespace boost { namespace python { @@ -29,76 +20,15 @@ namespace detail } }} -# if !defined(__EDG_VERSION__) || __EDG_VERSION__ > 245 - namespace boost { namespace python { // A type list for specifying arguments template < BOOST_PYTHON_ENUM_WITH_DEFAULT(BOOST_PYTHON_MAX_ARITY, typename A, mpl::void_) > struct args : detail::args_base > - , mpl::list< BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A) >::type + , detail::type_list< BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A) >::type {}; }} // namespace boost::python -# else // slow template instantiators need this other version with - // explicit specializations of mpl::size<> and - // mpl::at_c<>. Eventually, however, inheritance from mpl::list - // *should* be eliminated and the two versions unified, just in - // order to get true arity independence - -namespace boost { namespace python { - -template < BOOST_PYTHON_ENUM_WITH_DEFAULT(BOOST_PYTHON_MAX_ARITY, typename A, mpl::void_) > -struct args : detail::args_base > -{}; - -}} // namespace boost::python - -namespace boost { namespace mpl { - -template struct size; -template struct at; - -# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, , 1)) -# include BOOST_PP_ITERATE() - -# define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY - 1, , 2)) -# include BOOST_PP_ITERATE() - - -}} // namespace boost::mpl - -# endif // __EDG_VERSION__ # endif // ARGS_DWA2002323_HPP - -/* ---------- size ---------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1 -# line BOOST_PP_LINE(__LINE__, args.hpp(size)) - -# define N BOOST_PP_ITERATION() - -template -struct size > -{ - BOOST_STATIC_CONSTANT(long, value = N); -}; - -# undef N - -/* ---------- at_c ---------- */ -#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2 -# line BOOST_PP_LINE(__LINE__, args.hpp(at)) - -# define N BOOST_PP_ITERATION() - -template -struct at_c > -{ - typedef BOOST_PP_CAT(A, N) type; -}; - -# undef N - -#endif diff --git a/include/boost/python/bases.hpp b/include/boost/python/bases.hpp index 8ce3fd2a..ec03dfba 100644 --- a/include/boost/python/bases.hpp +++ b/include/boost/python/bases.hpp @@ -6,15 +6,16 @@ #ifndef BASES_DWA2002321_HPP # define BASES_DWA2002321_HPP # include -# include +# include # include # include # include namespace boost { namespace python { + // A type list for specifying bases - template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_MPL_LIMIT_LIST_SIZE, typename B, mpl::void_) > - struct bases : mpl::list< BOOST_PP_ENUM_PARAMS(BOOST_MPL_LIMIT_LIST_SIZE, B) >::type + template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PYTHON_MAX_BASES, typename B, mpl::void_) > + struct bases : detail::type_list< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, B) >::type {}; namespace detail @@ -24,14 +25,14 @@ namespace boost { namespace python { { BOOST_STATIC_CONSTANT(bool, value = false); }; - template < BOOST_PP_ENUM_PARAMS(BOOST_MPL_LIMIT_LIST_SIZE, class B) > - struct specifies_bases< bases< BOOST_PP_ENUM_PARAMS(BOOST_MPL_LIMIT_LIST_SIZE, B) > > + template < BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, class B) > + struct specifies_bases< bases< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, B) > > { BOOST_STATIC_CONSTANT(bool, value = true); }; # else - template < BOOST_PP_ENUM_PARAMS(BOOST_MPL_LIMIT_LIST_SIZE, class B) > - static char is_bases_helper(bases< BOOST_PP_ENUM_PARAMS(BOOST_MPL_LIMIT_LIST_SIZE, B) > const&); + template < BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, class B) > + static char is_bases_helper(bases< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, B) > const&); static char (& is_bases_helper(...) )[256]; diff --git a/include/boost/python/call.hpp b/include/boost/python/call.hpp index 6ce027ef..4edceee3 100644 --- a/include/boost/python/call.hpp +++ b/include/boost/python/call.hpp @@ -54,8 +54,8 @@ call(PyObject* callable return converter( PyEval_CallFunction( callable - , const_cast("(" BOOST_PP_REPEAT(N, BOOST_PYTHON_FIXED, "O") ")") - BOOST_PP_REPEAT(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil) + , const_cast("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")") + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil) )); } diff --git a/include/boost/python/call_method.hpp b/include/boost/python/call_method.hpp index 7c8f0e90..e8917c22 100644 --- a/include/boost/python/call_method.hpp +++ b/include/boost/python/call_method.hpp @@ -54,8 +54,8 @@ call_method(PyObject* self, char const* name PyEval_CallMethod( self , const_cast(name) - , const_cast("(" BOOST_PP_REPEAT(N, BOOST_PYTHON_FIXED, "O") ")") - BOOST_PP_REPEAT(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil) + , const_cast("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")") + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil) )); } diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 5bb30268..6480b817 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -280,7 +280,7 @@ class class_ : public objects::class_base // Define the default constructor. self& def_init() { - this->def_init(mpl::list<>::type()); + this->def_init(mpl::list0<>::type()); return *this; } diff --git a/include/boost/python/detail/config.hpp b/include/boost/python/detail/config.hpp index 2a9ec35e..c3750902 100644 --- a/include/boost/python/detail/config.hpp +++ b/include/boost/python/detail/config.hpp @@ -106,4 +106,12 @@ class function; }}} #endif +#if (defined(__DECCXX_VER) && __DECCXX_VER <= 60590014) +// Replace broken Tru64/cxx offsetof macro +# define BOOST_PYTHON_OFFSETOF(s_name, s_member) \ + ((size_t)__INTADDR__(&(((s_name *)0)->s_member))) +#else +# define BOOST_PYTHON_OFFSETOF offsetof +#endif + #endif // CONFIG_DWA052200_H_ diff --git a/include/boost/python/detail/defaults_def.hpp b/include/boost/python/detail/defaults_def.hpp index 4e442acb..9c79d926 100644 --- a/include/boost/python/detail/defaults_def.hpp +++ b/include/boost/python/detail/defaults_def.hpp @@ -14,10 +14,10 @@ #include #include -#include +#include +#include #include #include -#include #include #include #include @@ -201,19 +201,18 @@ struct define_stub_function {}; SigT sig, char const* doc) { - typedef typename boost::python::detail::type_at<0, SigT>::type nth_type; + typedef typename mpl::front::type return_type; typedef typename StubsT::v_type v_type; typedef typename StubsT::nv_type nv_type; typedef typename mpl::if_c< - boost::is_same::value + boost::is_same::value , v_type , nv_type >::type stubs_type; BOOST_STATIC_ASSERT( - (stubs_type::max_args) <= - boost::python::detail::type_list_size::value); + (stubs_type::max_args) <= mpl::size::value); typedef typename stubs_type::template gen gen_type; define_with_defaults_helper::def diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index f505bb54..78808424 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -23,7 +23,8 @@ #include #include #include -#include +#include +#include namespace boost { namespace python { namespace detail { @@ -39,23 +40,23 @@ struct func_stubs_base {}; /////////////////////////////////////////////////////////////////////////////// #define BPL_IMPL_TYPEDEF_GEN(z, INDEX, DATA) \ - typedef typename boost::python::detail::type_at \ + typedef typename ::boost::mpl::at_c \ < \ - BOOST_PP_ADD(INDEX, DATA), \ + BOOST_PP_ADD_D(1, INDEX, DATA), \ SigT \ >::type BOOST_PP_CAT(T, INDEX); \ #define BPL_IMPL_FUNC_WRAPPER_GEN(z, index, DATA) \ static RT BOOST_PP_CAT(func_, index) ( \ BOOST_PYTHON_BINARY_ENUM( \ - BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), T, arg) \ + BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), T, arg) \ ) \ { \ BOOST_PP_TUPLE_ELEM(3, 2, DATA) \ BOOST_PP_TUPLE_ELEM(3, 0, DATA) \ ( \ BOOST_PP_ENUM_PARAMS( \ - BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), \ + BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), \ arg \ ) \ ); \ @@ -70,7 +71,7 @@ struct func_stubs_base {}; template \ struct gen { \ \ - typedef typename boost::python::detail::type_at<0, SigT>::type RT; \ + typedef typename ::boost::mpl::front::type RT; \ \ BOOST_PP_REPEAT_2ND \ ( \ @@ -83,7 +84,7 @@ struct func_stubs_base {}; ( \ BOOST_PP_INC(N_DFLTS), \ BPL_IMPL_FUNC_WRAPPER_GEN, \ - (FNAME, BOOST_PP_SUB(N_ARGS, N_DFLTS), RETURN) \ + (FNAME, BOOST_PP_SUB_D(1, N_ARGS, N_DFLTS), RETURN) \ ) \ }; \ }; \ @@ -92,14 +93,14 @@ struct func_stubs_base {}; #define BPL_IMPL_MEM_FUNC_WRAPPER_GEN(z, index, DATA) \ static RT BOOST_PP_CAT(func_, index) ( \ ClassT& obj BOOST_PP_COMMA_IF( \ - BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index)) \ + BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index)) \ BOOST_PYTHON_BINARY_ENUM( \ - BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), T, arg) \ + BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), T, arg) \ ) \ { \ BOOST_PP_TUPLE_ELEM(3, 2, DATA) obj.BOOST_PP_TUPLE_ELEM(3, 0, DATA)( \ BOOST_PP_ENUM_PARAMS( \ - BOOST_PP_ADD(BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), arg \ + BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), arg \ ) \ ); \ } @@ -113,8 +114,8 @@ struct func_stubs_base {}; template \ struct gen { \ \ - typedef typename boost::python::detail::type_at<0, SigT>::type RT; \ - typedef typename boost::python::detail::type_at<1, SigT>::type ClassT; \ + typedef typename ::boost::mpl::front::type RT; \ + typedef typename ::boost::mpl::at_c<1, SigT>::type ClassT; \ \ BOOST_PP_REPEAT_2ND \ ( \ @@ -127,7 +128,7 @@ struct func_stubs_base {}; ( \ BOOST_PP_INC(N_DFLTS), \ BPL_IMPL_MEM_FUNC_WRAPPER_GEN, \ - (FNAME, BOOST_PP_SUB(N_ARGS, N_DFLTS), RETURN) \ + (FNAME, BOOST_PP_SUB_D(1, N_ARGS, N_DFLTS), RETURN) \ ) \ }; \ }; @@ -224,11 +225,11 @@ struct func_stubs_base {}; // template // struct gen { // -// typedef typename mpl::at_c<0, SigT>::type RT; -// typedef typename mpl::at_c<1, SigT>::type T0; -// typedef typename mpl::at_c<2, SigT>::type T1; -// typedef typename mpl::at_c<3, SigT>::type T2; -// typedef typename mpl::at_c<4, SigT>::type T3; +// typedef typename ::boost::mpl::at_c<0, SigT>::type RT; +// typedef typename ::boost::mpl::at_c<1, SigT>::type T0; +// typedef typename ::boost::mpl::at_c<2, SigT>::type T1; +// typedef typename ::boost::mpl::at_c<3, SigT>::type T2; +// typedef typename ::boost::mpl::at_c<4, SigT>::type T3; // // static RT func_0(T0 arg0) // { return foo(arg0); } @@ -265,7 +266,7 @@ struct func_stubs_base {}; FNAME, \ GENERATOR_NAME, \ MAX_ARGS, \ - BOOST_PP_SUB(MAX_ARGS, MIN_ARGS) \ + BOOST_PP_SUB_D(1, MAX_ARGS, MIN_ARGS) \ ) #define BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(GENERATOR_NAME, FNAME, MIN_ARGS, MAX_ARGS) \ @@ -274,7 +275,7 @@ struct func_stubs_base {}; FNAME, \ GENERATOR_NAME, \ MAX_ARGS, \ - BOOST_PP_SUB(MAX_ARGS, MIN_ARGS) \ + BOOST_PP_SUB_D(1, MAX_ARGS, MIN_ARGS) \ ) // deprecated macro names (to be removed) diff --git a/include/boost/python/detail/destroy.hpp b/include/boost/python/detail/destroy.hpp index 89e82f73..632b75ca 100644 --- a/include/boost/python/detail/destroy.hpp +++ b/include/boost/python/detail/destroy.hpp @@ -68,7 +68,13 @@ inline void destroy_referent_impl(void* p, T& (*)()) // must come *before* T for metrowerks value_destroyer< (boost::is_array::value) - , (boost::has_trivial_destructor::value) + , + // Aleksey, this shouldn't be needed +# if !defined(BOOST_MSVC) || BOOST_MSVC > 1200 + (boost::has_trivial_destructor::value) +# else + false +# endif >::execute((const volatile T*)p); } diff --git a/include/boost/python/detail/make_tuple.hpp b/include/boost/python/detail/make_tuple.hpp index 41fcaa37..07cd9903 100644 --- a/include/boost/python/detail/make_tuple.hpp +++ b/include/boost/python/detail/make_tuple.hpp @@ -22,7 +22,7 @@ make_tuple(BOOST_PYTHON_BINARY_ENUM(N, A, const& a)) { tuple result((detail::new_reference)::PyTuple_New(N)); - BOOST_PP_REPEAT(N, BOOST_PYTHON_MAKE_TUPLE_ARG, _) + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_MAKE_TUPLE_ARG, _) return result; } diff --git a/include/boost/python/detail/preprocessor.hpp b/include/boost/python/detail/preprocessor.hpp index 4d4baa57..45e307d4 100644 --- a/include/boost/python/detail/preprocessor.hpp +++ b/include/boost/python/detail/preprocessor.hpp @@ -27,12 +27,11 @@ # endif # ifndef BOOST_PYTHON_MAX_ARITY -# define BOOST_PYTHON_MAX_ARITY 10 // 15 +# define BOOST_PYTHON_MAX_ARITY 15 # endif -// Temporary! -# ifndef BOOST_MPL_LIMIT_LIST_SIZE -# define BOOST_MPL_LIMIT_LIST_SIZE BOOST_PYTHON_MAX_ARITY +# ifndef BOOST_PYTHON_MAX_BASES +# define BOOST_PYTHON_MAX_BASES 10 # endif # define BOOST_PYTHON_CV_QUALIFIER(i) \ diff --git a/include/boost/python/detail/returning.hpp b/include/boost/python/detail/returning.hpp index 495a8564..9ab87c43 100644 --- a/include/boost/python/detail/returning.hpp +++ b/include/boost/python/detail/returning.hpp @@ -96,7 +96,7 @@ struct returning , PyObject*, P const* policies) { // check that each of the arguments is convertible - BOOST_PP_REPEAT(N, BOOST_PYTHON_CHECK_CONVERSION, nil) + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CHECK_CONVERSION, nil) // find the result converter typedef typename P::result_converter result_converter; @@ -104,7 +104,7 @@ struct returning if (!cr.convertible() || !policies->precall(args_)) return 0; PyObject* result = cr( - (*pf)(BOOST_PP_REPEAT(N, BOOST_PYTHON_CALL_ARGS, nil)) + (*pf)(BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CALL_ARGS, nil)) ); return policies->postcall(args_, result); } @@ -117,11 +117,11 @@ struct returning , PyObject*, P const* policies) { // check that each of the arguments is convertible - BOOST_PP_REPEAT(N, BOOST_PYTHON_CHECK_CONVERSION, nil) + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CHECK_CONVERSION, nil) if (!policies->precall(args_)) return 0; - (*pf)(BOOST_PP_REPEAT(N, BOOST_PYTHON_CALL_ARGS, nil)); + (*pf)(BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CALL_ARGS, nil)); return policies->postcall(args_, detail::none()); } # endif // returning void / non-void @@ -168,7 +168,7 @@ struct returning return 0; // unroll a loop for the rest of them - BOOST_PP_REPEAT(N, BOOST_PYTHON_CHECK_CONVERSION, nil) + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CHECK_CONVERSION, nil) // find the result converter typedef typename P::result_converter result_converter; @@ -177,7 +177,7 @@ struct returning return 0; PyObject* result = cr( ((ct(PyTuple_GET_ITEM(args_, 0))).*pmf)( - BOOST_PP_REPEAT(N, BOOST_PYTHON_CALL_ARGS, nil)) + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CALL_ARGS, nil)) ); return policies->postcall(args_, result); } @@ -196,13 +196,13 @@ struct returning return 0; // unroll a loop for the rest of them - BOOST_PP_REPEAT(N, BOOST_PYTHON_CHECK_CONVERSION, nil) + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CHECK_CONVERSION, nil) if (!policies->precall(args_)) return 0; ((ct(PyTuple_GET_ITEM(args_, 0))).*pmf)( - BOOST_PP_REPEAT(N, BOOST_PYTHON_CALL_ARGS, nil)); + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_CALL_ARGS, nil)); return policies->postcall(args_, detail::none()); } # endif diff --git a/include/boost/python/detail/type_list.hpp b/include/boost/python/detail/type_list.hpp index b61e616a..4a09c0be 100644 --- a/include/boost/python/detail/type_list.hpp +++ b/include/boost/python/detail/type_list.hpp @@ -3,14 +3,38 @@ // 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 TYPE_LIST_DWA200222_HPP -# define TYPE_LIST_DWA200222_HPP -# include +#ifndef TYPE_LIST_DWA2002913_HPP +# define TYPE_LIST_DWA2002913_HPP -namespace boost { namespace python { namespace detail { +# include +# include +# include -struct empty_list : boost::mpl::list<>::type {}; +# if BOOST_PYTHON_MAX_ARITY + 2 > BOOST_PYTHON_MAX_BASES +# define BOOST_PYTHON_LIST_SIZE BOOST_PP_INC(BOOST_PP_INC(BOOST_PYTHON_MAX_ARITY)) +# else +# define BOOST_PYTHON_BASE_LIST_SIZE BOOST_PYTHON_MAX_BASES +# endif -}}} // namespace boost::python::detail +// Compute the MPL list header to use for lists up to BOOST_PYTHON_LIST_SIZE in length +# if BOOST_PYTHON_LIST_SIZE > 48 +# error Arities above 48 not supported by Boost.Python due to MPL internal limit +# elif BOOST_PYTHON_LIST_SIZE > 38 +# include +# elif BOOST_PYTHON_LIST_SIZE > 28 +# include +# elif BOOST_PYTHON_LIST_SIZE > 18 +# include +# elif BOOST_PYTHON_LIST_SIZE > 8 +# include +# else +# include +# endif -#endif // TYPE_LIST_DWA200222_HPP +# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +# include +# else +# include +# endif + +#endif // TYPE_LIST_DWA2002913_HPP diff --git a/include/boost/python/detail/type_list_impl.hpp b/include/boost/python/detail/type_list_impl.hpp new file mode 100644 index 00000000..2a02851f --- /dev/null +++ b/include/boost/python/detail/type_list_impl.hpp @@ -0,0 +1,55 @@ +#ifndef BOOST_PP_IS_ITERATING +// 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 TYPE_LIST_IMPL_DWA2002913_HPP +# define TYPE_LIST_IMPL_DWA2002913_HPP + +# include +# include +# include +# include +# include +# include + +namespace boost { namespace python { namespace detail { + +template +struct type_list + : BOOST_PP_CAT(mpl::list,BOOST_PYTHON_LIST_SIZE) +{ +}; + +# define BOOST_PP_ITERATION_PARAMS_1 \ + (3, (0, BOOST_PP_DEC(BOOST_PYTHON_LIST_SIZE), )) +# include BOOST_PP_ITERATE() + + +}}} // namespace boost::python::detail + +# endif // TYPE_LIST_IMPL_DWA2002913_HPP + +#else // BOOST_PP_IS_ITERATING + +# define N BOOST_PP_ITERATION() +# define BOOST_PYTHON_VOID_ARGS BOOST_PP_SUB_D(1,BOOST_PYTHON_LIST_SIZE,N) + +template < + BOOST_PP_ENUM_PARAMS(N, class T) + > +struct type_list< + BOOST_PP_ENUM_PARAMS(N, T) + BOOST_PP_COMMA_IF(N) + BOOST_PP_ENUM( + BOOST_PYTHON_VOID_ARGS, BOOST_PYTHON_FIXED, mpl::void_) + > + : BOOST_PP_CAT(mpl::list,N) +{ +}; + +# undef BOOST_PYTHON_VOID_ARGS +# undef N + +#endif // BOOST_PP_IS_ITERATING diff --git a/include/boost/python/detail/type_list_impl_no_pts.hpp b/include/boost/python/detail/type_list_impl_no_pts.hpp new file mode 100644 index 00000000..1c4d392c --- /dev/null +++ b/include/boost/python/detail/type_list_impl_no_pts.hpp @@ -0,0 +1,101 @@ +#ifndef BOOST_PP_IS_ITERATING +// 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 TYPE_LIST_IMPL_NO_PTS_DWA2002913_HPP +# define TYPE_LIST_IMPL_NO_PTS_DWA2002913_HPP + +# include +# include +# include +# include +# include +# include +# include + +namespace boost { namespace python { namespace detail { + +template< typename T > +struct is_list_arg +{ + enum { value = true }; +}; + +template<> +struct is_list_arg +{ + enum { value = false }; +}; + +template struct type_list_impl_chooser; + +# define BOOST_PP_ITERATION_PARAMS_1 \ + (3, (0, BOOST_PYTHON_LIST_SIZE, )) +# include BOOST_PP_ITERATE() + +# define BOOST_PYTHON_PLUS() + +# define BOOST_PYTHON_IS_LIST_ARG(z, n, data) \ + BOOST_PP_IF(n, BOOST_PYTHON_PLUS, BOOST_PP_EMPTY)() \ + is_list_arg< BOOST_PP_CAT(T,n) >::value + +template< + BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE, class T) + > +struct type_list_count_args +{ + enum { value = + BOOST_PP_REPEAT_1(BOOST_PYTHON_LIST_SIZE, BOOST_PYTHON_IS_LIST_ARG, _) + }; +}; + +# undef BOOST_PYTHON_IS_LIST_ARG +# undef BOOST_PYTHON_PLUS + +template< + BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE, class T) + > +struct type_list_impl +{ + typedef type_list_count_args< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE,T) > arg_num_; + typedef typename detail::type_list_impl_chooser< arg_num_::value > + ::template result_< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE,T) >::type type; +}; + +template< + BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PYTHON_LIST_SIZE, class T, mpl::void_) + > +struct type_list + : detail::type_list_impl< BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE,T) >::type +{ + typedef typename detail::type_list_impl< + BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE,T) + >::type type; +}; + +}}} // namespace boost::python::detail + +# endif // TYPE_LIST_IMPL_NO_PTS_DWA2002913_HPP + +#else // BOOST_PP_IS_ITERATING + +# define N BOOST_PP_ITERATION() + +template<> +struct type_list_impl_chooser +{ + template< + BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_LIST_SIZE, class T) + > + struct result_ + { + typedef BOOST_PP_CAT(mpl::list,N)< + BOOST_PP_ENUM_PARAMS(N, T) + > type; + }; +}; + +# undef N + +#endif // BOOST_PP_IS_ITERATING diff --git a/include/boost/python/detail/type_list_utils.hpp b/include/boost/python/detail/type_list_utils.hpp index eeeed0fa..ebb5488b 100644 --- a/include/boost/python/detail/type_list_utils.hpp +++ b/include/boost/python/detail/type_list_utils.hpp @@ -1,116 +1,28 @@ -/////////////////////////////////////////////////////////////////////////////// -// +#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. -// -/////////////////////////////////////////////////////////////////////////////// -#if !defined(BOOST_PP_IS_ITERATING) - #ifndef TYPE_LIST_UTILS_JDG20020826_HPP -#define TYPE_LIST_UTILS_JDG20020826_HPP +# define TYPE_LIST_UTILS_JDG20020826_HPP -# include -# include -//# include -//# include - -# include -# include -# include -# include -# include -# include - -# include +# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION namespace boost { namespace python { namespace detail { -# if (!defined(__EDG_VERSION__) || __EDG_VERSION__ > 245) \ - && (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600) +template< typename T > +struct is_list_arg +{ + enum { value = true }; +}; - template - struct type_at : mpl::at_c {}; - - template - struct type_list_size : boost::mpl::size {}; - -// template -// struct pop_front : public boost::mpl::pop_front {}; -// -// template -// struct pop_back : public boost::mpl::pop_back {}; - -# else - - template - struct type_at {}; - - template - struct type_list_size {}; - -// template -// struct pop_front {}; -// -// template -// struct pop_back {}; - -// template -// struct push_back {}; - -# define BOOST_PP_ITERATION_PARAMS_1 \ - (3, (0, BOOST_PYTHON_MAX_ARITY, )) -# include BOOST_PP_ITERATE() - -# endif - -}}} // namespace boost::python::detail +template<> +struct is_list_arg +{ + enum { value = false }; +}; +}}} +# endif #endif // TYPE_LIST_UTILS_JDG20020826_HPP - -#else // defined(BOOST_PP_IS_ITERATING) - -# define N BOOST_PP_ITERATION() - -# if (N < BOOST_PYTHON_MAX_ARITY-1) - - template - struct type_at > - { - typedef BOOST_PP_CAT(A, N) type; - }; - -// template -// struct push_back, T> -// { -// typedef mpl::list sequence; -// }; - -# if (N > 0) - -// template -// struct pop_front > -// { -// typedef mpl::list sequence; -// }; -// -// template -// struct pop_back > -// { -// typedef mpl::list sequence; -// }; - -# endif -# endif - - template - struct type_list_size > - { - BOOST_STATIC_CONSTANT(long, value = N); - }; - -# undef N - -#endif // !defined(BOOST_PP_IS_ITERATING) diff --git a/include/boost/python/detail/wrap_python.hpp b/include/boost/python/detail/wrap_python.hpp index e2392bc5..6cb8dee2 100644 --- a/include/boost/python/detail/wrap_python.hpp +++ b/include/boost/python/detail/wrap_python.hpp @@ -115,7 +115,11 @@ typedef int pid_t; #endif // _WIN32 -#include +#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION < 2 +# include +#else +# include +#endif #ifdef BOOST_PYTHON_ULONG_MAX_UNDEFINED # undef ULONG_MAX diff --git a/include/boost/python/enum.hpp b/include/boost/python/enum.hpp index f7d06075..072a0626 100644 --- a/include/boost/python/enum.hpp +++ b/include/boost/python/enum.hpp @@ -15,6 +15,8 @@ namespace boost { namespace python { template struct enum_ : public objects::enum_base { + typedef objects::enum_base base; + enum_(char const* name); inline enum_& value(char const* name, T); @@ -26,7 +28,7 @@ struct enum_ : public objects::enum_base template inline enum_::enum_(char const* name) - : enum_base( + : base( name , &enum_::to_python , &enum_::convertible @@ -39,7 +41,7 @@ inline enum_::enum_(char const* name) template PyObject* enum_::to_python(void const* x) { - return enum_base::to_python( + return base::to_python( converter::registered::converters.class_object , static_cast(*(T const*)x)); } diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index 87a45829..733973b1 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -10,7 +10,7 @@ #ifndef INIT_JDG20020820_HPP #define INIT_JDG20020820_HPP -#include +#include #include #include #include @@ -31,6 +31,8 @@ #include #include #include +#include +#include /////////////////////////////////////////////////////////////////////////////// #define BOOST_PYTHON_TEMPLATE_TYPES_WITH_DEFAULT \ @@ -125,7 +127,7 @@ namespace detail { template struct init //: detail::check_init_params { - typedef mpl::list signature_; + typedef detail::type_list signature_; typedef typename mpl::end::type finish; // Find the optional<> element, if any @@ -144,7 +146,7 @@ struct init //: detail::check_init_params typedef typename mpl::apply_if< is_same - , mpl::list<> + , mpl::list0<> , opt >::type optional_args; @@ -159,7 +161,7 @@ struct init //: detail::check_init_params // Build a reverse image of all the args, including optionals typedef typename mpl::fold< required_args - , mpl::list<> + , mpl::list0<> , mpl::push_front >::type reversed_required; @@ -182,7 +184,7 @@ struct init //: detail::check_init_params /////////////////////////////////////////////////////////////////////////////// template struct optional - : mpl::list + : detail::type_list { }; @@ -193,7 +195,7 @@ namespace detail { typedef typename mpl::fold< ReversedArgs - , mpl::list<> + , mpl::list0<> , mpl::push_front >::type args; diff --git a/include/boost/python/object/instance.hpp b/include/boost/python/object/instance.hpp index 94e526b2..4cddcc99 100644 --- a/include/boost/python/object/instance.hpp +++ b/include/boost/python/object/instance.hpp @@ -42,7 +42,8 @@ struct additional_instance_size typedef instance instance_data; typedef instance instance_char; BOOST_STATIC_CONSTANT( - std::size_t, value = sizeof(instance_data) - offsetof(instance_char,storage)); + std::size_t, value = sizeof(instance_data) + - BOOST_PYTHON_OFFSETOF(instance_char,storage)); }; }}} // namespace boost::python::object diff --git a/include/boost/python/object/make_holder.hpp b/include/boost/python/object/make_holder.hpp index 6baf44a4..66211abf 100644 --- a/include/boost/python/object/make_holder.hpp +++ b/include/boost/python/object/make_holder.hpp @@ -15,7 +15,9 @@ # include # include -# include +# include +# include +# include # include # include @@ -28,9 +30,18 @@ namespace boost { namespace python { namespace objects { template struct make_holder; +// Temporary workaround for vc6 bug. Hopefully Aleksey will work +// around it in the MPL source somehow... is this an example of ETI? +template struct delay +{ + typedef typename T::type type; +}; + # define BOOST_PYTHON_FORWARD_ARG(z, index, _) \ - typedef typename mpl::at_c::type t##index; \ - typedef typename forward::type f##index; + typedef typename iter##index::type t##index; \ + typedef typename forward::type f##index; \ + typedef typename mpl::next::type \ + BOOST_PP_CAT(iter,BOOST_PP_INC(index)); # define BOOST_PYTHON_DO_FORWARD_ARG(z, index, _) , f##index(a##index) @@ -56,7 +67,8 @@ struct make_holder template struct apply { - BOOST_PP_REPEAT(N, BOOST_PYTHON_FORWARD_ARG, nil) + typedef typename delay >::type iter0; + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FORWARD_ARG, nil) static void execute( PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, t, a)) @@ -66,7 +78,7 @@ struct make_holder void* memory = Holder::allocate(p, offsetof(instance_t, storage), sizeof(Holder)); try { (new (memory) Holder( - p BOOST_PP_REPEAT(N, BOOST_PYTHON_DO_FORWARD_ARG, nil)))->install(p); + p BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_DO_FORWARD_ARG, nil)))->install(p); } catch(...) { Holder::deallocate(p, memory); diff --git a/include/boost/python/object/pointer_holder.hpp b/include/boost/python/object/pointer_holder.hpp index c714a291..0dca4ae3 100644 --- a/include/boost/python/object/pointer_holder.hpp +++ b/include/boost/python/object/pointer_holder.hpp @@ -131,7 +131,7 @@ void* pointer_holder_back_reference::holds(type_info dst_t) # endif pointer_holder(PyObject* BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a)) : m_p(new Value( - BOOST_PP_REPEAT(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) )) {} @@ -149,7 +149,7 @@ void* pointer_holder_back_reference::holds(type_info dst_t) pointer_holder_back_reference( PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a)) : m_p(new held_type( - p BOOST_PP_COMMA_IF(N) BOOST_PP_REPEAT(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) + p BOOST_PP_COMMA_IF(N) BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) )) {} diff --git a/include/boost/python/object/value_holder.hpp b/include/boost/python/object/value_holder.hpp index ea751edc..d40d058d 100644 --- a/include/boost/python/object/value_holder.hpp +++ b/include/boost/python/object/value_holder.hpp @@ -101,7 +101,7 @@ void* value_holder_back_reference::holds( value_holder( PyObject* BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a)) : m_held( - BOOST_PP_REPEAT(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) ) {} @@ -121,7 +121,7 @@ void* value_holder_back_reference::holds( PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a)) : m_held( p BOOST_PP_COMMA_IF(N) - BOOST_PP_REPEAT(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) ) { } diff --git a/include/boost/python/object_core.hpp b/include/boost/python/object_core.hpp index a0119503..ebdfeac1 100755 --- a/include/boost/python/object_core.hpp +++ b/include/boost/python/object_core.hpp @@ -180,7 +180,7 @@ namespace api // there is a confirmed CWPro8 codegen bug here. We prevent the // early destruction of a temporary by binding a named object // instead. -# if __MWERKS__ < 0x3000 || __MWERKS__ > 0x3001 +# if __MWERKS__ < 0x3000 || __MWERKS__ > 0x3002 typedef object const& object_cref2; # else typedef object const object_cref2; diff --git a/include/boost/python/signature.hpp b/include/boost/python/signature.hpp index 5cd8eac8..bd4b26df 100644 --- a/include/boost/python/signature.hpp +++ b/include/boost/python/signature.hpp @@ -19,8 +19,19 @@ # include # include # include -# include +# include + # include +# include +# include +# include + +# define BOOST_PYTHON_FUNCTION_SIGNATURE_LIST(n) \ + BOOST_PP_CAT(mpl::list, BOOST_PP_INC(n)) + +# define BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(n) \ + BOOST_PP_CAT(mpl::list, BOOST_PP_INC(BOOST_PP_INC(n))) + /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace python { namespace detail { @@ -65,6 +76,10 @@ namespace boost { namespace python { namespace detail { }} // namespace boost::python + +# undef BOOST_PYTHON_FUNCTION_SIGNATURE_LIST +# undef BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST + /////////////////////////////////////////////////////////////////////////////// # endif // SIGNATURE_JDG20020813_HPP @@ -73,47 +88,38 @@ namespace boost { namespace python { namespace detail { # define N BOOST_PP_ITERATION() template < - class RT BOOST_PP_COMMA_IF(N) - BOOST_PYTHON_UNARY_ENUM(N, class T)> -inline mpl::list< - RT BOOST_PP_COMMA_IF(N) - BOOST_PP_ENUM_PARAMS(N, T)> + class RT BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)> +inline BOOST_PYTHON_FUNCTION_SIGNATURE_LIST(N)< + RT BOOST_PP_ENUM_TRAILING_PARAMS(N, T)> get_signature(RT(*)(BOOST_PP_ENUM_PARAMS(N, T))) { - return mpl::list< - RT BOOST_PP_COMMA_IF(N) - BOOST_PP_ENUM_PARAMS(N, T)>(); + return BOOST_PYTHON_FUNCTION_SIGNATURE_LIST(N)< + RT BOOST_PP_ENUM_TRAILING_PARAMS(N, T) + >(); } /////////////////////////////////////////////////////////////////////////////// #if N <= (BOOST_PYTHON_MAX_ARITY - 2) template < - class RT, class ClassT BOOST_PP_COMMA_IF(N) - BOOST_PYTHON_UNARY_ENUM(N, class T)> -inline mpl::list< - RT, ClassT BOOST_PP_COMMA_IF(N) - BOOST_PP_ENUM_PARAMS(N, T)> + class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)> +inline BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)< + RT, ClassT BOOST_PP_ENUM_TRAILING_PARAMS(N, T)> get_signature(RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(N, T))) { - return mpl::list< - RT, ClassT BOOST_PP_COMMA_IF(N) - BOOST_PP_ENUM_PARAMS(N, T)>(); + return BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)< + RT, ClassT BOOST_PP_ENUM_TRAILING_PARAMS(N, T)>(); } /////////////////////////////////////// template < - class RT, class ClassT BOOST_PP_COMMA_IF(N) - BOOST_PYTHON_UNARY_ENUM(N, class T)> -inline mpl::list< - RT, ClassT const BOOST_PP_COMMA_IF(N) - BOOST_PP_ENUM_PARAMS(N, T)> + class RT, class ClassT BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)> +inline BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)< + RT, ClassT const BOOST_PP_ENUM_TRAILING_PARAMS(N, T)> get_signature(RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(N, T)) const) { - return mpl::list< - RT, ClassT const - BOOST_PP_COMMA_IF(N) - BOOST_PP_ENUM_PARAMS(N, T)>(); + return BOOST_PYTHON_MEMBER_FUNCTION_SIGNATURE_LIST(N)< + RT, ClassT const BOOST_PP_ENUM_TRAILING_PARAMS(N, T)>(); } #endif // N < (BOOST_PYTHON_MAX_ARITY - 2)