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