2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-26 18:52:26 +00:00

Apply more preprocessor optimizations

[SVN r15435]
This commit is contained in:
Dave Abrahams
2002-09-18 04:54:31 +00:00
parent ca5a222aec
commit 065a53b997
14 changed files with 59 additions and 44 deletions

View File

@@ -8,6 +8,7 @@
# include <boost/config.hpp>
# include <boost/python/detail/preprocessor.hpp>
# include <boost/python/detail/type_list.hpp>
# include <boost/preprocessor/enum_params.hpp>
namespace boost { namespace python {
@@ -24,8 +25,8 @@ 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<args<BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A)> >
, detail::type_list< BOOST_PYTHON_UNARY_ENUM(BOOST_PYTHON_MAX_ARITY, A) >::type
struct args : detail::args_base<args<BOOST_PP_ENUM_PARAMS_Z(1, BOOST_PYTHON_MAX_ARITY, A)> >
, detail::type_list< BOOST_PP_ENUM_PARAMS_Z(1, BOOST_PYTHON_MAX_ARITY, A) >::type
{};
}} // namespace boost::python

View File

@@ -77,7 +77,7 @@ struct arg_tuple_size
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template <class R BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
struct arg_tuple_size<R (*)(BOOST_PYTHON_UNARY_ENUM(N, A))>
struct arg_tuple_size<R (*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A))>
{
BOOST_STATIC_CONSTANT(std::size_t, value = N);
};
@@ -86,7 +86,7 @@ struct arg_tuple_size<R (*)(BOOST_PYTHON_UNARY_ENUM(N, A))>
template<class R BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
char_array<N> arg_tuple_size_helper(
R (*)(BOOST_PYTHON_UNARY_ENUM(N, A)));
R (*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)));
# endif // !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)

View File

@@ -61,10 +61,10 @@ struct caller
template <
class P, class R
BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)
BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
>
PyObject* operator()(
R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A))
R (*pf)(BOOST_PP_ENUM_PARAMS_Z(1, N, A))
, PyObject* args
, PyObject* keywords
, P const& policies) const
@@ -92,7 +92,7 @@ template <
BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
>
PyObject* operator()(
R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q
R (T::*pmf)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)) Q
, PyObject* args, PyObject* keywords
, P const& policies
) const

View File

@@ -15,6 +15,7 @@
#include <boost/preprocessor/repeat_from_to.hpp>
#include <boost/preprocessor/enum.hpp>
#include <boost/preprocessor/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/tuple.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
@@ -97,17 +98,17 @@ struct overloads_common
BOOST_PP_CAT(iter, BOOST_PP_INC(index)); \
typedef typename BOOST_PP_CAT(iter, index)::type BOOST_PP_CAT(T, index); \
#define BOOST_PYTHON_FUNC_WRAPPER_GEN(z, index, data) \
static RT BOOST_PP_CAT(func_, \
BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
BOOST_PYTHON_BINARY_ENUM( \
index, T, arg)) \
{ \
BOOST_PP_TUPLE_ELEM(3, 2, data) \
BOOST_PP_TUPLE_ELEM(3, 0, data)( \
BOOST_PP_ENUM_PARAMS( \
index, \
arg)); \
#define BOOST_PYTHON_FUNC_WRAPPER_GEN(z, index, data) \
static RT BOOST_PP_CAT(func_, \
BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
BOOST_PP_ENUM_BINARY_PARAMS_Z( \
1, index, T, arg)) \
{ \
BOOST_PP_TUPLE_ELEM(3, 2, data) \
BOOST_PP_TUPLE_ELEM(3, 0, data)( \
BOOST_PP_ENUM_PARAMS( \
index, \
arg)); \
}
#define BOOST_PYTHON_GEN_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \
@@ -141,7 +142,7 @@ struct overloads_common
static RT BOOST_PP_CAT(func_, \
BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \
ClassT& obj BOOST_PP_COMMA_IF(index) \
BOOST_PYTHON_BINARY_ENUM(index, T, arg) \
BOOST_PP_ENUM_BINARY_PARAMS_Z(1, index, T, arg) \
) \
{ \
BOOST_PP_TUPLE_ELEM(3, 2, data) obj.BOOST_PP_TUPLE_ELEM(3, 0, data)( \

View File

@@ -17,9 +17,9 @@
, python::incref(python::object(a##N).ptr()) \
);
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
tuple
make_tuple(BOOST_PYTHON_BINARY_ENUM(N, A, const& a))
make_tuple(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a))
{
tuple result((detail::new_reference)::PyTuple_New(N));
BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_MAKE_TUPLE_ARG, _)

View File

@@ -17,6 +17,8 @@
# include <boost/preprocessor/comma_if.hpp>
# include <boost/preprocessor/iterate.hpp>
# include <boost/preprocessor/debug/line.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
namespace boost { namespace python { namespace detail {
@@ -97,17 +99,19 @@ struct member_function_cast
# define N BOOST_PP_ITERATION()
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
# define P BOOST_PP_ENUM_PARAMS_Z(1, N, A)
template <
class S, class R
BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
>
static cast_helper<S, R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q>
stage1(R (S::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q)
static cast_helper<S, R (T::*)( P ) Q>
stage1(R (S::*)( P ) Q)
{
return cast_helper<S, R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q>();
return cast_helper<S, R (T::*)( P ) Q>();
}
# undef P
# undef N
# undef Q

View File

@@ -92,8 +92,8 @@ result(X const&, short = 0) { return 0; }
# define N BOOST_PP_ITERATION()
template <class R BOOST_PP_COMMA_IF(N) BOOST_PYTHON_UNARY_ENUM(N, class A)>
boost::type<R>* result(R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A)), int = 0)
template <class R BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
boost::type<R>* result(R (*pf)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)), int = 0)
{
return 0;
}

View File

@@ -92,7 +92,7 @@ struct returning<void>
template<class P BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
static PyObject* call(
R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A))
R (*pf)(BOOST_PP_ENUM_PARAMS_Z(1, N, A))
, PyObject* args_
, PyObject*, P const* policies)
{
@@ -113,7 +113,7 @@ struct returning<void>
template<class P BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
static PyObject* call(
R (*pf)(BOOST_PYTHON_UNARY_ENUM(N, A))
R (*pf)(BOOST_PP_ENUM_PARAMS_Z(1, N, A))
, PyObject* args_
, PyObject*, P const* policies)
{
@@ -158,7 +158,7 @@ struct returning<void>
template<class P, class T BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
static PyObject* call(
R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q
R (T::*pmf)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)) Q
, PyObject* args_
, PyObject*, P const* policies)
{
@@ -186,7 +186,7 @@ struct returning<void>
template<class P, class T BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
static PyObject* call(
R (T::*pmf)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q
R (T::*pmf)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)) Q
, PyObject* args_
, PyObject*, P const* policies)
{

View File

@@ -66,7 +66,7 @@ boost::type<BOOST_PP_IF(N, A0, void)>* target(R (*)(BOOST_PP_ENUM_PARAMS_Z(1, N,
# define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
template <class R, class T BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
boost::type<T Q*>* target(R (T::*)(BOOST_PYTHON_UNARY_ENUM(N, A)) Q)
boost::type<T Q*>* target(R (T::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)) Q)
{
return 0;
}

View File

@@ -23,6 +23,7 @@
# include <boost/preprocessor/iterate.hpp>
# include <boost/preprocessor/repeat.hpp>
# include <boost/preprocessor/debug/line.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
# include <cstddef>
@@ -64,7 +65,7 @@ struct make_holder<N>
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))
BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, t, a))
{
typedef instance<Holder> instance_t;

View File

@@ -20,7 +20,6 @@
# include <boost/python/pointee.hpp>
# include <boost/python/detail/force_instantiate.hpp>
# include <boost/python/detail/preprocessor.hpp>
# include <boost/preprocessor/debug/line.hpp>
# include <boost/mpl/if.hpp>
# include <boost/mpl/apply.hpp>
@@ -28,6 +27,9 @@
# include <boost/preprocessor/comma_if.hpp>
# include <boost/preprocessor/iterate.hpp>
# include <boost/preprocessor/repeat.hpp>
# include <boost/preprocessor/debug/line.hpp>
# include <boost/preprocessor/enum_params.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
namespace boost { namespace python { namespace objects {
@@ -127,9 +129,9 @@ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
# define N BOOST_PP_ITERATION()
# if (N != 0)
template< BOOST_PYTHON_UNARY_ENUM(N, class A) >
template< BOOST_PP_ENUM_PARAMS_Z(1, N, class A) >
# endif
pointer_holder(PyObject* BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a))
pointer_holder(PyObject* BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
: m_p(new Value(
BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
))
@@ -144,10 +146,10 @@ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
# define N BOOST_PP_ITERATION()
# if (N != 0)
template < BOOST_PYTHON_UNARY_ENUM(N, class A) >
template < BOOST_PP_ENUM_PARAMS_Z(1, N, class A) >
# endif
pointer_holder_back_reference(
PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a))
PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
: m_p(new held_type(
p BOOST_PP_COMMA_IF(N) BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
))

View File

@@ -19,10 +19,14 @@
# include <boost/python/detail/preprocessor.hpp>
# include <boost/preprocessor/comma_if.hpp>
# include <boost/preprocessor/enum_params.hpp>
# include <boost/preprocessor/iterate.hpp>
# include <boost/preprocessor/repeat.hpp>
# include <boost/preprocessor/debug/line.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
namespace boost { namespace python { namespace objects {
# define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) (typename unforward<A##n>::type)(a##n)
@@ -96,10 +100,10 @@ void* value_holder_back_reference<Held,BackReferenceType>::holds(
# define N BOOST_PP_ITERATION()
# if (N != 0)
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
# endif
value_holder(
PyObject* BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a))
PyObject* BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
: m_held(
BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
)
@@ -115,10 +119,10 @@ void* value_holder_back_reference<Held,BackReferenceType>::holds(
# define N BOOST_PP_ITERATION()
# if (N != 0)
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
# endif
value_holder_back_reference(
PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PYTHON_BINARY_ENUM(N, A, a))
PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
: m_held(
p BOOST_PP_COMMA_IF(N)
BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)

View File

@@ -10,13 +10,13 @@
#define N BOOST_PP_ITERATION()
template <BOOST_PYTHON_UNARY_ENUM(N, class A)>
template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
typename detail::dependent<object, A0>::type
operator()(BOOST_PYTHON_BINARY_ENUM(N, A, const& a)) const
operator()(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)) const
{
typedef typename detail::dependent<object, A0>::type obj;
U const& self = *static_cast<U const*>(this);
return call<obj>(get_managed_object(self, tag), BOOST_PYTHON_UNARY_ENUM(N, a));
return call<obj>(get_managed_object(self, tag), BOOST_PP_ENUM_PARAMS_Z(1, N, a));
}
#undef N

View File

@@ -3,6 +3,8 @@
#include <boost/python/object.hpp>
#include <boost/python/converter/pytype_object_mgr_traits.hpp>
#include <boost/preprocessor/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
namespace boost { namespace python {