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