1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/call.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,79 @@
1.4 +#if !defined(BOOST_PP_IS_ITERATING)
1.5 +
1.6 +// Copyright David Abrahams 2002.
1.7 +// Distributed under the Boost Software License, Version 1.0. (See
1.8 +// accompanying file LICENSE_1_0.txt or copy at
1.9 +// http://www.boost.org/LICENSE_1_0.txt)
1.10 +
1.11 +# ifndef CALL_DWA2002411_HPP
1.12 +# define CALL_DWA2002411_HPP
1.13 +
1.14 +# include <boost/python/detail/prefix.hpp>
1.15 +
1.16 +# include <boost/type.hpp>
1.17 +
1.18 +# include <boost/python/converter/arg_to_python.hpp>
1.19 +# include <boost/python/converter/return_from_python.hpp>
1.20 +# include <boost/python/detail/preprocessor.hpp>
1.21 +# include <boost/python/detail/void_return.hpp>
1.22 +
1.23 +# include <boost/preprocessor/comma_if.hpp>
1.24 +# include <boost/preprocessor/iterate.hpp>
1.25 +# include <boost/preprocessor/repeat.hpp>
1.26 +# include <boost/preprocessor/debug/line.hpp>
1.27 +# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
1.28 +# include <boost/preprocessor/repetition/enum_binary_params.hpp>
1.29 +
1.30 +namespace boost { namespace python {
1.31 +
1.32 +# define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \
1.33 + , converter::arg_to_python<A##n>(a##n).get()
1.34 +
1.35 +# define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call.hpp>))
1.36 +# include BOOST_PP_ITERATE()
1.37 +
1.38 +# undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
1.39 +
1.40 +}} // namespace boost::python
1.41 +
1.42 +# endif // CALL_DWA2002411_HPP
1.43 +
1.44 +#elif BOOST_PP_ITERATION_DEPTH() == 1
1.45 +# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
1.46 + && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
1.47 +# line BOOST_PP_LINE(__LINE__, call.hpp)
1.48 +# endif
1.49 +
1.50 +# define N BOOST_PP_ITERATION()
1.51 +
1.52 +template <
1.53 + class R
1.54 + BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
1.55 + >
1.56 +typename detail::returnable<R>::type
1.57 +call(PyObject* callable
1.58 + BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)
1.59 + , boost::type<R>* = 0
1.60 + )
1.61 +{
1.62 + PyObject* const result =
1.63 + PyEval_CallFunction(
1.64 + callable
1.65 + , const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")")
1.66 + BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
1.67 + );
1.68 +
1.69 + // This conversion *must not* be done in the same expression as
1.70 + // the call, because, in the special case where the result is a
1.71 + // reference a Python object which was created by converting a C++
1.72 + // argument for passing to PyEval_CallFunction, its reference
1.73 + // count will be 2 until the end of the full expression containing
1.74 + // the conversion, and that interferes with dangling
1.75 + // pointer/reference detection.
1.76 + converter::return_from_python<R> converter;
1.77 + return converter(result);
1.78 +}
1.79 +
1.80 +# undef N
1.81 +
1.82 +#endif