annotate DEPENDENCIES/generic/include/boost/python/call.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
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
Chris@16 8 # ifndef CALL_DWA2002411_HPP
Chris@16 9 # define CALL_DWA2002411_HPP
Chris@16 10
Chris@16 11 # include <boost/python/detail/prefix.hpp>
Chris@16 12
Chris@16 13 # include <boost/type.hpp>
Chris@16 14
Chris@16 15 # include <boost/python/converter/arg_to_python.hpp>
Chris@16 16 # include <boost/python/converter/return_from_python.hpp>
Chris@16 17 # include <boost/python/detail/preprocessor.hpp>
Chris@16 18 # include <boost/python/detail/void_return.hpp>
Chris@16 19
Chris@16 20 # include <boost/preprocessor/comma_if.hpp>
Chris@16 21 # include <boost/preprocessor/iterate.hpp>
Chris@16 22 # include <boost/preprocessor/repeat.hpp>
Chris@16 23 # include <boost/preprocessor/debug/line.hpp>
Chris@16 24 # include <boost/preprocessor/repetition/enum_trailing_params.hpp>
Chris@16 25 # include <boost/preprocessor/repetition/enum_binary_params.hpp>
Chris@16 26
Chris@16 27 namespace boost { namespace python {
Chris@16 28
Chris@16 29 # define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \
Chris@16 30 , converter::arg_to_python<A##n>(a##n).get()
Chris@16 31
Chris@16 32 # define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call.hpp>))
Chris@16 33 # include BOOST_PP_ITERATE()
Chris@16 34
Chris@16 35 # undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
Chris@16 36
Chris@16 37 }} // namespace boost::python
Chris@16 38
Chris@16 39 # endif // CALL_DWA2002411_HPP
Chris@16 40
Chris@16 41 // For gcc 4.4 compatability, we must include the
Chris@16 42 // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
Chris@16 43 #else // BOOST_PP_IS_ITERATING
Chris@16 44 #if BOOST_PP_ITERATION_DEPTH() == 1
Chris@16 45 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
Chris@16 46 && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
Chris@16 47 # line BOOST_PP_LINE(__LINE__, call.hpp)
Chris@16 48 # endif
Chris@16 49
Chris@16 50 # define N BOOST_PP_ITERATION()
Chris@16 51
Chris@16 52 template <
Chris@16 53 class R
Chris@16 54 BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
Chris@16 55 >
Chris@16 56 typename detail::returnable<R>::type
Chris@16 57 call(PyObject* callable
Chris@16 58 BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)
Chris@16 59 , boost::type<R>* = 0
Chris@16 60 )
Chris@16 61 {
Chris@16 62 PyObject* const result =
Chris@16 63 PyEval_CallFunction(
Chris@16 64 callable
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