Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/python/call_method.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #if !defined(BOOST_PP_IS_ITERATING)
0002 
0003 // Copyright David Abrahams 2002.
0004 // Distributed under the Boost Software License, Version 1.0. (See
0005 // accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 # ifndef CALL_METHOD_DWA2002411_HPP
0008 #  define CALL_METHOD_DWA2002411_HPP
0009 
0010 # include <boost/python/detail/prefix.hpp>
0011 
0012 #  include <boost/type.hpp>
0013 
0014 #  include <boost/python/converter/arg_to_python.hpp>
0015 #  include <boost/python/converter/return_from_python.hpp>
0016 #  include <boost/python/detail/preprocessor.hpp>
0017 #  include <boost/python/detail/void_return.hpp>
0018 
0019 #  include <boost/preprocessor/comma_if.hpp>
0020 #  include <boost/preprocessor/iterate.hpp>
0021 #  include <boost/preprocessor/repeat.hpp>
0022 #  include <boost/preprocessor/debug/line.hpp>
0023 #  include <boost/preprocessor/repetition/enum_trailing_params.hpp>
0024 #  include <boost/preprocessor/repetition/enum_binary_params.hpp>
0025 
0026 namespace boost { namespace python {
0027 
0028 # define BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET(z, n, _) \
0029     , converter::arg_to_python<A##n>(a##n).get()
0030 
0031 # define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/call_method.hpp>))
0032 # include BOOST_PP_ITERATE()
0033 
0034 # undef BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET
0035 
0036 }} // namespace boost::python
0037 
0038 # endif // CALL_METHOD_DWA2002411_HPP
0039 
0040 // For gcc 4.4 compatability, we must include the
0041 // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
0042 #else // BOOST_PP_IS_ITERATING
0043 #if BOOST_PP_ITERATION_DEPTH() == 1
0044 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100)                      \
0045         && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
0046 #  line BOOST_PP_LINE(__LINE__, call_method.hpp)
0047 # endif 
0048 
0049 # define N BOOST_PP_ITERATION()
0050 
0051 template <
0052     class R
0053     BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
0054     >
0055 typename detail::returnable<R>::type
0056 call_method(PyObject* self, char const* name
0057     BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)
0058     , boost::type<R>* = 0
0059     )
0060 {
0061     PyObject* const result = 
0062         PyObject_CallMethod(
0063             self
0064             , const_cast<char*>(name)
0065             , const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FIXED, "O") ")")
0066             BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
0067             );
0068     
0069     // This conversion *must not* be done in the same expression as
0070     // the call, because, in the special case where the result is a
0071     // reference a Python object which was created by converting a C++
0072     // argument for passing to PyObject_CallFunction, its reference
0073     // count will be 2 until the end of the full expression containing
0074     // the conversion, and that interferes with dangling
0075     // pointer/reference detection.
0076     converter::return_from_python<R> converter;
0077     return converter(result);
0078 }
0079 
0080 # undef N
0081 
0082 #endif // BOOST_PP_ITERATION_DEPTH()
0083 #endif // BOOST_PP_IS_ITERATING