1 #if !defined(BOOST_PP_IS_ITERATING) 2 3 // Copyright David Abrahams 2002. 4 // Distributed under the Boost Software License, Version 1.0. (See 5 // accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 8 # ifndef CALL_DWA2002411_HPP 9 # define CALL_DWA2002411_HPP 10 11 # include <boost/python/detail/prefix.hpp> 12 13 # include <boost/type.hpp> 14 15 # include <boost/python/converter/arg_to_python.hpp> 16 # include <boost/python/converter/return_from_python.hpp> 17 # include <boost/python/detail/preprocessor.hpp> 18 # include <boost/python/detail/void_return.hpp> 19 20 # include <boost/preprocessor/comma_if.hpp> 21 # include <boost/preprocessor/iterate.hpp> 22 # include <boost/preprocessor/repeat.hpp> 23 # include <boost/preprocessor/debug/line.hpp> 24 # include <boost/preprocessor/repetition/enum_trailing_params.hpp> 25 # include <boost/preprocessor/repetition/enum_binary_params.hpp> 26 27 namespace boost { namespace python { 28 29 # define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \ 30 , converter::arg_to_python<A##n>(a##n).get() 31 32 # define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call.hpp>)) 33 # include BOOST_PP_ITERATE() 34 35 # undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET 36 37 }} // namespace boost::python 38 39 # endif // CALL_DWA2002411_HPP 40 41 #elif BOOST_PP_ITERATION_DEPTH() == 1 42 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \ 43 && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201))) 44 # line BOOST_PP_LINE(__LINE__, call.hpp) 45 # endif 46 47 # define N BOOST_PP_ITERATION() 48 49 template < 50 class R 51 BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A) 52 > 53 typename detail::returnable<R>::type 54 call(PyObject* callable 55 BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a) 56 , boost::type<R>* = 0 57 ) 58 { 59 PyObject* const result = 60 PyEval_CallFunction( 61 callable 62 , const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")") 63 BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil) 64 ); 65 66 // This conversion *must not* be done in the same expression as 67 // the call, because, in the special case where the result is a 68 // reference a Python object which was created by converting a C++ 69 // argument for passing to PyEval_CallFunction, its reference 70 // count will be 2 until the end of the full expression containing 71 // the conversion, and that interferes with dangling 72 // pointer/reference detection. 73 converter::return_from_python<R> converter; 74 return converter(result); 75 } 76 77 # undef N 78 79 #endif 80