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