From b3117c2b02b9793325de5cc231e41327cac74903 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Fri, 1 Feb 2002 04:36:46 +0000 Subject: [PATCH] Use call policies [SVN r12618] --- include/boost/python/converter/smart_ptr.hpp | 70 ++ include/boost/python/converter/to_python.hpp | 2 +- include/boost/python/converter/type_id.hpp | 82 +- include/boost/python/copy_const_reference.hpp | 42 + .../boost/python/copy_non_const_reference.hpp | 42 + .../boost/python/default_call_policies.hpp | 72 ++ include/boost/python/detail/caller.hpp | 220 ++++- .../boost/python/detail/indirect_traits.hpp | 116 +++ include/boost/python/detail/returning.hpp | 842 +++++++++++++----- include/boost/python/from_python.hpp | 42 + include/boost/python/make_function.hpp | 15 +- include/boost/python/module.hpp | 16 +- .../python/return_internal_reference.hpp | 45 + include/boost/python/return_value_policy.hpp | 20 + include/boost/python/to_python.hpp | 37 + include/boost/python/type_from_python.hpp | 23 + src/objects.cpp | 4 +- test/m1.cpp | 13 +- test/m2.cpp | 28 +- 19 files changed, 1380 insertions(+), 351 deletions(-) create mode 100644 include/boost/python/converter/smart_ptr.hpp create mode 100644 include/boost/python/copy_const_reference.hpp create mode 100644 include/boost/python/copy_non_const_reference.hpp create mode 100644 include/boost/python/default_call_policies.hpp create mode 100644 include/boost/python/detail/indirect_traits.hpp create mode 100644 include/boost/python/from_python.hpp create mode 100644 include/boost/python/return_internal_reference.hpp create mode 100644 include/boost/python/return_value_policy.hpp create mode 100644 include/boost/python/to_python.hpp create mode 100644 include/boost/python/type_from_python.hpp diff --git a/include/boost/python/converter/smart_ptr.hpp b/include/boost/python/converter/smart_ptr.hpp new file mode 100644 index 00000000..bae4c2b8 --- /dev/null +++ b/include/boost/python/converter/smart_ptr.hpp @@ -0,0 +1,70 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef SMART_PTR_DWA2002123_HPP +# define SMART_PTR_DWA2002123_HPP + +# include +# include +namespace boost { namespace python { namespace converter { + +template +class smart_ptr_wrapper + : wrapper +{ + smart_ptr_wrapper(ref const& type_) + : m_class_object(type_) + { + assert(type_->ob_type == (PyTypeObject*)class_metatype().get()); + } + + PyObject* convert(Pointer x) const; + + private: + ref m_class_object; + + smart_ptr_converters(); +} + + +// +// implementations +// + +template +PyObject* smart_ptr_wrapper::convert(Pointer x) const +{ + if (x.operator->() == 0) + return detail::none(); + + // Don't call the type to do the construction, since that + // would require the registration of an __init__ copy + // constructor. Instead, just construct the object in place. + PyObject* raw_result = (PyObject*)PyObject_New( + instance, (PyTypeObject*)m_class_object.get()); + + if (raw_result == 0) + return 0; + + // Everything's OK; Bypass NULL checks but guard against + // exceptions. + ref result(raw_result, ref::allow_null()); + + // Build a value_holder to contain the object using the copy + // constructor + objects::pointer_holder* + p = new objects::pointer_holder(x); + + // Install it in the instance + p->install(raw_result); + + // Return the new result + return result.release(); +} + + +}}} // namespace boost::python::converter + +#endif // SMART_PTR_DWA2002123_HPP diff --git a/include/boost/python/converter/to_python.hpp b/include/boost/python/converter/to_python.hpp index 61dc7dad..a1d6c28b 100644 --- a/include/boost/python/converter/to_python.hpp +++ b/include/boost/python/converter/to_python.hpp @@ -101,7 +101,7 @@ template inline bool to_python_lookup::convertible() const { - return m_converter != 0; + return m_convert != 0; } template diff --git a/include/boost/python/converter/type_id.hpp b/include/boost/python/converter/type_id.hpp index fd731f83..e5068604 100644 --- a/include/boost/python/converter/type_id.hpp +++ b/include/boost/python/converter/type_id.hpp @@ -6,10 +6,8 @@ #ifndef TYPE_ID_DWA20011127_HPP # define TYPE_ID_DWA20011127_HPP # include -# include +# include # include -# include -# include # include # include # include @@ -79,80 +77,6 @@ struct type_id_t : totally_ordered base_id_t m_base_type; }; -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -struct is_reference_to_const -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct is_reference_to_const -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct is_reference_to_volatile -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct is_reference_to_volatile -{ - BOOST_STATIC_CONSTANT(bool, value = true); -}; -# else -template -struct is_const_help -{ - typedef typename mpl::select_type< - is_const::value - , type_traits::yes_type - , type_traits::no_type - >::type type; -}; - -template -struct is_volatile_help -{ - typedef typename mpl::select_type< - is_volatile::value - , type_traits::yes_type - , type_traits::no_type - >::type type; -}; - -template -typename is_const_help::type reference_to_const_helper(V&); - -type_traits::no_type -reference_to_const_helper(...); - -template -struct is_reference_to_const -{ - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = sizeof(reference_to_const_helper(t)) == sizeof(type_traits::yes_type)); -}; - -template -typename is_volatile_help::type reference_to_volatile_helper(V&); -type_traits::no_type reference_to_volatile_helper(...); - -template -struct is_reference_to_volatile -{ - static T t; - BOOST_STATIC_CONSTANT( - bool, value - = sizeof(reference_to_volatile_helper(t)) == sizeof(type_traits::yes_type)); -}; -# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template inline undecorated_type_id_t undecorated_type_id(detail::dummy* = 0) { @@ -165,9 +89,9 @@ inline type_id_t type_id(detail::dummy* = 0) return type_id_t( undecorated_type_id() , type_id_t::decoration( - (is_const::value || is_reference_to_const::value + (is_const::value || python::detail::is_reference_to_const::value ? type_id_t::const_ : 0) - | (is_volatile::value || is_reference_to_volatile::value + | (is_volatile::value || python::detail::is_reference_to_volatile::value ? type_id_t::volatile_ : 0) | (is_reference::value ? type_id_t::reference : 0) ) diff --git a/include/boost/python/copy_const_reference.hpp b/include/boost/python/copy_const_reference.hpp new file mode 100644 index 00000000..55e8f87f --- /dev/null +++ b/include/boost/python/copy_const_reference.hpp @@ -0,0 +1,42 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef COPY_CONST_REFERENCE_DWA2002131_HPP +# define COPY_CONST_REFERENCE_DWA2002131_HPP +# include +# include +# include + +namespace boost { namespace python { + +namespace detail +{ + template + struct copy_const_reference_expects_a_const_reference_return_type +# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) + {} +# endif + ; +} + +template struct to_python; + +struct copy_const_reference +{ + template + struct apply + { + typedef typename mpl::select_type< + detail::is_reference_to_const::value + , to_python + , detail::copy_const_reference_expects_a_const_reference_return_type + >::type type; + }; +}; + + +}} // namespace boost::python + +#endif // COPY_CONST_REFERENCE_DWA2002131_HPP diff --git a/include/boost/python/copy_non_const_reference.hpp b/include/boost/python/copy_non_const_reference.hpp new file mode 100644 index 00000000..4afdc369 --- /dev/null +++ b/include/boost/python/copy_non_const_reference.hpp @@ -0,0 +1,42 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef COPY_NON_CONST_REFERENCE_DWA2002131_HPP +# define COPY_NON_CONST_REFERENCE_DWA2002131_HPP +# include +# include +# include + +namespace boost { namespace python { + +namespace detail +{ + template + struct copy_non_const_reference_expects_a_non_const_reference_return_type +# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) + {} +# endif + ; +} + +template struct to_python; + +struct copy_non_const_reference +{ + template + struct apply + { + typedef typename mpl::select_type< + boost::python::detail::is_reference_to_non_const::value + , to_python + , detail::copy_non_const_reference_expects_a_non_const_reference_return_type + >::type type; + }; +}; + + +}} // namespace boost::python + +#endif // COPY_NON_CONST_REFERENCE_DWA2002131_HPP diff --git a/include/boost/python/default_call_policies.hpp b/include/boost/python/default_call_policies.hpp new file mode 100644 index 00000000..3dc3d4d4 --- /dev/null +++ b/include/boost/python/default_call_policies.hpp @@ -0,0 +1,72 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef DEFAULT_CALL_POLICIES_DWA2002131_HPP +# define DEFAULT_CALL_POLICIES_DWA2002131_HPP +# include +# include + +namespace boost { namespace python { + +template struct to_python; + +namespace detail +{ +// for "readable" error messages + template struct specify_a_result_policy_to_wrap_functions_returning +# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) + {} +# endif + ; +} + +struct default_result_converter; + +struct default_call_policies +{ + // Nothing to do + static bool precall(PyObject*) + { + return true; + } + + // Pass the result through + static PyObject* postcall(PyObject*, PyObject* result) + { + return result; + } + + typedef default_result_converter result_converter; +}; + +struct default_result_converter +{ + template + struct apply + { + typedef typename mpl::select_type< + is_reference::value | is_pointer::value + , detail::specify_a_result_policy_to_wrap_functions_returning + , to_python + >::type type; + }; +}; + +// Exceptions for c strings an PyObject*s +template <> +struct default_result_converter::apply +{ + typedef boost::python::to_python type; +}; + +template <> +struct default_result_converter::apply +{ + typedef boost::python::to_python type; +}; + +}} // namespace boost::python + +#endif // DEFAULT_CALL_POLICIES_DWA2002131_HPP diff --git a/include/boost/python/detail/caller.hpp b/include/boost/python/detail/caller.hpp index 95c6dc7a..fe022961 100644 --- a/include/boost/python/detail/caller.hpp +++ b/include/boost/python/detail/caller.hpp @@ -6,19 +6,229 @@ #ifndef CALLER_DWA20011214_HPP # define CALLER_DWA20011214_HPP -# include # include +# include +# include +# include +# include +# include -namespace boost { namespace python { namespace detail { +namespace boost { namespace python +{ + template struct to_python; +}} + +namespace boost { namespace python { namespace detail { + +// for "readable" error messages +template struct must_use_a_result_handler_to_wrap_functions_returning +# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) +{} +# endif +; + +struct to_python_generator +{ + template + struct apply + { + typedef typename mpl::select_type< + is_reference::value | is_pointer::value + , must_use_a_result_handler_to_wrap_functions_returning + , to_python + >::type type; + }; +}; struct caller { typedef PyObject* result_type; - template - PyObject* operator()(F f, PyObject* args, PyObject* keywords) + template + PyObject* operator()(R (*f)(), PyObject* args, PyObject* keywords, P const& policies) const { - return call(f, args, keywords); + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (*f)(A0), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (*f)(A0, A1), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (*f)(A0, A1, A2), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (*f)(A0, A1, A2, A3), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (*f)(A0, A1, A2, A3, A4), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (*f)(A0, A1, A2, A3, A4, A5), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + +// Member functions + template + PyObject* operator()(R (A0::*f)(), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3, A4), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3, A4, A5), PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)() const, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1) const, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2) const, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3) const, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3, A4) const, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)() volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1) volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2) volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3) volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3, A4) volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3, A4, A5) volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)() const volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1) const volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2) const volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3) const volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3, A4) const volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); + } + + template + PyObject* operator()(R (A0::*f)(A1, A2, A3, A4, A5) const volatile, PyObject* args, PyObject* keywords, P const& policies) const + { + return returning::call(f, args, keywords, policies); } }; diff --git a/include/boost/python/detail/indirect_traits.hpp b/include/boost/python/detail/indirect_traits.hpp new file mode 100644 index 00000000..c76ffbc0 --- /dev/null +++ b/include/boost/python/detail/indirect_traits.hpp @@ -0,0 +1,116 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef INDIRECT_TRAITS_DWA2002131_HPP +# define INDIRECT_TRAITS_DWA2002131_HPP +# include +# include +# include + +namespace boost { namespace python { namespace detail { + +# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +template +struct is_reference_to_const +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template +struct is_reference_to_const +{ + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template +struct is_reference_to_non_const +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template +struct is_reference_to_non_const +{ + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template +struct is_reference_to_volatile +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template +struct is_reference_to_volatile +{ + BOOST_STATIC_CONSTANT(bool, value = true); +}; +# else + +typedef char (&inner_yes_type)[3]; +typedef char (&inner_no_type)[2]; +typedef char (&outer_no_type)[1]; + +template +struct is_const_help +{ + typedef typename mpl::select_type< + is_const::value + , inner_yes_type + , inner_no_type + >::type type; +}; + +template +struct is_volatile_help +{ + typedef typename mpl::select_type< + is_volatile::value + , inner_yes_type + , inner_no_type + >::type type; +}; + +template +typename is_const_help::type reference_to_const_helper(V&); + +outer_no_type +reference_to_const_helper(...); + +template +struct is_reference_to_const +{ + static T t; + BOOST_STATIC_CONSTANT( + bool, value + = sizeof(reference_to_const_helper(t)) == sizeof(inner_yes_type)); +}; + +template +struct is_reference_to_non_const +{ + static T t; + BOOST_STATIC_CONSTANT( + bool, value + = sizeof(reference_to_const_helper(t)) == sizeof(inner_no_type)); +}; + +template +typename is_volatile_help::type reference_to_volatile_helper(V&); +outer_no_type reference_to_volatile_helper(...); + +template +struct is_reference_to_volatile +{ + static T t; + BOOST_STATIC_CONSTANT( + bool, value + = sizeof(reference_to_volatile_helper(t)) == sizeof(inner_yes_type)); +}; +# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + +}}} // namespace boost::python::detail + +#endif // INDIRECT_TRAITS_DWA2002131_HPP diff --git a/include/boost/python/detail/returning.hpp b/include/boost/python/detail/returning.hpp index 4aa228b5..c8533f9e 100644 --- a/include/boost/python/detail/returning.hpp +++ b/include/boost/python/detail/returning.hpp @@ -18,25 +18,38 @@ # include # include +namespace boost { namespace python +{ + template struct to_python; +}} // namespace boost::python + namespace boost { namespace python { namespace detail { // Calling C++ from Python template struct returning { - template - static PyObject* call(R (A0::*pmf)(), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)() ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)() ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -45,11 +58,19 @@ struct returning if (!c1.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -60,11 +81,19 @@ struct returning if (!c2.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -77,11 +106,19 @@ struct returning if (!c3.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -96,11 +133,19 @@ struct returning if (!c4.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -117,23 +162,39 @@ struct returning if (!c5.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)() const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)() const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)() ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)() ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -142,11 +203,19 @@ struct returning if (!c1.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -157,11 +226,19 @@ struct returning if (!c2.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -174,11 +251,19 @@ struct returning if (!c3.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -193,11 +278,19 @@ struct returning if (!c4.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -214,23 +307,39 @@ struct returning if (!c5.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)() volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)() volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)() ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)() ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -239,11 +348,19 @@ struct returning if (!c1.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -254,11 +371,19 @@ struct returning if (!c2.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -271,11 +396,19 @@ struct returning if (!c3.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -290,11 +423,19 @@ struct returning if (!c4.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -311,26 +452,42 @@ struct returning if (!c5.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + + if (!result) return 0; + return policies.postcall(args, result); } // missing const volatile type traits # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - static PyObject* call(R (A0::*pmf)() const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)() const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)() ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)() ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -339,11 +496,19 @@ struct returning if (!c1.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -354,11 +519,19 @@ struct returning if (!c2.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -371,11 +544,19 @@ struct returning if (!c3.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -390,11 +571,19 @@ struct returning if (!c4.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -411,31 +600,58 @@ struct returning if (!c5.convertible()) return 0; // find the result converter - to_python r; - return r( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + typedef typename P::result_converter result_converter; + typename eval::type cr; + if (!cr.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = cr( ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + + if (!result) return 0; + return policies.postcall(args, result); } # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - - static PyObject* call(R (*pf)(), PyObject*, PyObject* /* keywords */ ) + + + template + static PyObject* call(R (*pf)(), PyObject* args, PyObject*, P const& policies) { // find the result converter - to_python c0; - return c0( (*pf)() ); + typedef typename P::result_converter result_converter; + typename eval::type c0; + if (!c0.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = c0( (*pf)() ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (*pf)(A0), PyObject* args, PyObject* /* keywords */ ) + + template + static PyObject* call(R (*pf)(A0), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; // find the result converter - to_python c1; - return c1( (*pf)(c0(PyTuple_GET_ITEM(args, 0))) ); + typedef typename P::result_converter result_converter; + typename eval::type c1; + if (!c1.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = c1( (*pf)(c0(PyTuple_GET_ITEM(args, 0))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (*pf)(A0, A1), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -444,11 +660,19 @@ struct returning if (!c1.convertible()) return 0; // find the result converter - to_python c2; - return c2( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1))) ); + typedef typename P::result_converter result_converter; + typename eval::type c2; + if (!c2.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = c2( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (*pf)(A0, A1, A2), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1, A2), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -459,11 +683,19 @@ struct returning if (!c2.convertible()) return 0; // find the result converter - to_python c3; - return c3( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + typedef typename P::result_converter result_converter; + typename eval::type c3; + if (!c3.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = c3( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (*pf)(A0, A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1, A2, A3), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -476,11 +708,19 @@ struct returning if (!c3.convertible()) return 0; // find the result converter - to_python c4; - return c4( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + typedef typename P::result_converter result_converter; + typename eval::type c4; + if (!c4.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = c4( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (*pf)(A0, A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1, A2, A3, A4), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -495,11 +735,19 @@ struct returning if (!c4.convertible()) return 0; // find the result converter - to_python c5; - return c5( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + typedef typename P::result_converter result_converter; + typename eval::type c5; + if (!c5.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = c5( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))) ); + + if (!result) return 0; + return policies.postcall(args, result); } - template - static PyObject* call(R (*pf)(A0, A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1, A2, A3, A4, A5), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -516,8 +764,16 @@ struct returning if (!c5.convertible()) return 0; // find the result converter - to_python c6; - return c6( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + typedef typename P::result_converter result_converter; + typename eval::type c6; + if (!c6.convertible()) return 0; + + if (!policies.precall(args)) return 0; + + PyObject* result = c6( (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))) ); + + if (!result) return 0; + return policies.postcall(args, result); } }; @@ -525,30 +781,36 @@ template <> struct returning { typedef void R; - template - static PyObject* call(R (A0::*pmf)(), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; from_python c1(PyTuple_GET_ITEM(args, 1)); if (!c1.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -557,12 +819,15 @@ struct returning if (!c1.convertible()) return 0; from_python c2(PyTuple_GET_ITEM(args, 2)); if (!c2.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -573,12 +838,15 @@ struct returning if (!c2.convertible()) return 0; from_python c3(PyTuple_GET_ITEM(args, 3)); if (!c3.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -591,12 +859,15 @@ struct returning if (!c3.convertible()) return 0; from_python c4(PyTuple_GET_ITEM(args, 4)); if (!c4.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -611,35 +882,44 @@ struct returning if (!c4.convertible()) return 0; from_python c5(PyTuple_GET_ITEM(args, 5)); if (!c5.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)() const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)() const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; from_python c1(PyTuple_GET_ITEM(args, 1)); if (!c1.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -648,12 +928,15 @@ struct returning if (!c1.convertible()) return 0; from_python c2(PyTuple_GET_ITEM(args, 2)); if (!c2.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -664,12 +947,15 @@ struct returning if (!c2.convertible()) return 0; from_python c3(PyTuple_GET_ITEM(args, 3)); if (!c3.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -682,12 +968,15 @@ struct returning if (!c3.convertible()) return 0; from_python c4(PyTuple_GET_ITEM(args, 4)); if (!c4.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -702,35 +991,44 @@ struct returning if (!c4.convertible()) return 0; from_python c5(PyTuple_GET_ITEM(args, 5)); if (!c5.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)() volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)() volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; from_python c1(PyTuple_GET_ITEM(args, 1)); if (!c1.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -739,12 +1037,15 @@ struct returning if (!c1.convertible()) return 0; from_python c2(PyTuple_GET_ITEM(args, 2)); if (!c2.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -755,12 +1056,15 @@ struct returning if (!c2.convertible()) return 0; from_python c3(PyTuple_GET_ITEM(args, 3)); if (!c3.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -773,12 +1077,15 @@ struct returning if (!c3.convertible()) return 0; from_python c4(PyTuple_GET_ITEM(args, 4)); if (!c4.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -793,38 +1100,47 @@ struct returning if (!c4.convertible()) return 0; from_python c5(PyTuple_GET_ITEM(args, 5)); if (!c5.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))); - return detail::none(); + + return policies.postcall(args, detail::none()); } // missing const volatile type traits # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - static PyObject* call(R (A0::*pmf)() const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)() const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; from_python c1(PyTuple_GET_ITEM(args, 1)); if (!c1.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -833,12 +1149,15 @@ struct returning if (!c1.convertible()) return 0; from_python c2(PyTuple_GET_ITEM(args, 2)); if (!c2.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -849,12 +1168,15 @@ struct returning if (!c2.convertible()) return 0; from_python c3(PyTuple_GET_ITEM(args, 3)); if (!c3.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -867,12 +1189,15 @@ struct returning if (!c3.convertible()) return 0; from_python c4(PyTuple_GET_ITEM(args, 4)); if (!c4.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const volatile, PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (A0::*pmf)(A1, A2, A3, A4, A5) const volatile, PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -887,42 +1212,53 @@ struct returning if (!c4.convertible()) return 0; from_python c5(PyTuple_GET_ITEM(args, 5)); if (!c5.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + ((c0(PyTuple_GET_ITEM(args, 0))).*pmf)(c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))); - return detail::none(); + + return policies.postcall(args, detail::none()); } # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - - static PyObject* call(R (*pf)(), PyObject*, PyObject* /* keywords */ ) + + template + static PyObject* call(R (*pf)(), PyObject*, PyObject*, P const& policies) { (*pf)(); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (*pf)(A0), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + (*pf)(c0(PyTuple_GET_ITEM(args, 0))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (*pf)(A0, A1), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); if (!c0.convertible()) return 0; from_python c1(PyTuple_GET_ITEM(args, 1)); if (!c1.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (*pf)(A0, A1, A2), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1, A2), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -931,12 +1267,15 @@ struct returning if (!c1.convertible()) return 0; from_python c2(PyTuple_GET_ITEM(args, 2)); if (!c2.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (*pf)(A0, A1, A2, A3), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1, A2, A3), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -947,12 +1286,15 @@ struct returning if (!c2.convertible()) return 0; from_python c3(PyTuple_GET_ITEM(args, 3)); if (!c3.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (*pf)(A0, A1, A2, A3, A4), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1, A2, A3, A4), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -965,12 +1307,15 @@ struct returning if (!c3.convertible()) return 0; from_python c4(PyTuple_GET_ITEM(args, 4)); if (!c4.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4))); - return detail::none(); + + return policies.postcall(args, detail::none()); } - template - static PyObject* call(R (*pf)(A0, A1, A2, A3, A4, A5), PyObject* args, PyObject* /* keywords */ ) + template + static PyObject* call(R (*pf)(A0, A1, A2, A3, A4, A5), PyObject* args, PyObject*, P const& policies) { // check that each of the arguments is convertible from_python c0(PyTuple_GET_ITEM(args, 0)); @@ -985,9 +1330,12 @@ struct returning if (!c4.convertible()) return 0; from_python c5(PyTuple_GET_ITEM(args, 5)); if (!c5.convertible()) return 0; - + + if (!policies.precall(args)) return 0; + (*pf)(c0(PyTuple_GET_ITEM(args, 0)), c1(PyTuple_GET_ITEM(args, 1)), c2(PyTuple_GET_ITEM(args, 2)), c3(PyTuple_GET_ITEM(args, 3)), c4(PyTuple_GET_ITEM(args, 4)), c5(PyTuple_GET_ITEM(args, 5))); - return detail::none(); + + return policies.postcall(args, detail::none()); } }; diff --git a/include/boost/python/from_python.hpp b/include/boost/python/from_python.hpp new file mode 100644 index 00000000..995f7877 --- /dev/null +++ b/include/boost/python/from_python.hpp @@ -0,0 +1,42 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef FROM_PYTHON_DWA2002128_HPP +# define FROM_PYTHON_DWA2002128_HPP + +# include +# include + +namespace boost { namespace python { + +template +struct from_python + : converter::from_python_lookup::type> +{ + typedef converter::from_python_lookup::type> base; + from_python(PyObject*); +}; + +// specialization for PyObject* +template <> +struct from_python +{ + from_python(PyObject*) {} + bool convertible() const { return true; } + PyObject* operator()(PyObject* source) const { return source; } +}; + +// +// implementations +// +template +from_python::from_python(PyObject* source) + : base(source) +{ +} + +}} // namespace boost::python + +#endif // FROM_PYTHON_DWA2002128_HPP diff --git a/include/boost/python/make_function.hpp b/include/boost/python/make_function.hpp index dfd11865..6f989256 100644 --- a/include/boost/python/make_function.hpp +++ b/include/boost/python/make_function.hpp @@ -15,6 +15,7 @@ # include # include # include +# include namespace boost { namespace python { @@ -24,7 +25,17 @@ objects::function* make_function(F f) converter::acquire_registrations(detail::signature(f)); return new objects::function( objects::py_function( - ::boost::bind(detail::caller(), f, _1, _2)) + ::boost::bind(detail::caller(), f, _1, _2, default_call_policies())) + , detail::arg_tuple_size::value); +} + +template +objects::function* make_function(F f, Policies const& policies) +{ + converter::acquire_registrations(detail::signature(f)); + return new objects::function( + objects::py_function( + ::boost::bind(detail::caller(), f, _1, _2, policies)) , detail::arg_tuple_size::value); } @@ -41,7 +52,7 @@ objects::function* make_constructor(T* = 0, ArgList* = 0, Generator* = 0) ::boost::bind(detail::caller(), objects::make_holder ::template apply::execute - , _1, _2)) + , _1, _2, default_call_policies())) , nargs + 1); } diff --git a/include/boost/python/module.hpp b/include/boost/python/module.hpp index 5661e106..3a243b06 100644 --- a/include/boost/python/module.hpp +++ b/include/boost/python/module.hpp @@ -58,20 +58,20 @@ class module : public module_base return *this; } -# if 0 - template - void def_raw(char const* name, Fn fn) - { - add(detail::new_raw_arguments_function(fn), name); - } -# endif - template module& def(char const* name, Fn fn) { this->setattr(name, boost::python::make_function(fn)); return *this; } + + + template + module& def(char const* name, Fn fn, ResultHandler handler) + { + this->setattr(name, boost::python::make_function(fn, handler)); + return *this; + } }; // diff --git a/include/boost/python/return_internal_reference.hpp b/include/boost/python/return_internal_reference.hpp new file mode 100644 index 00000000..ac7f3fbf --- /dev/null +++ b/include/boost/python/return_internal_reference.hpp @@ -0,0 +1,45 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef RETURN_INTERNAL_REFERENCE_DWA2002131_HPP +# define RETURN_INTERNAL_REFERENCE_DWA2002131_HPP + +# include +# include + +namespace boost { namespace python { + +namespace detail +{ + template + struct return_internal_reference_requires_a_pointer_or_reference_return_type +# if defined(__GNUC__) && __GNUC__ >= 3 || defined(__EDG__) + {} +# endif + ; +}; + +struct internal_reference_to_python_generator +{ + template + struct apply + { + typedef typename mpl::select_type< + !is_object::value + , internal_reference_to_python + , detail::return_internal_reference_requires_a_pointer_or_reference_return_type + >::type type; + }; +}; + +template +struct return_internal_reference : Base +{ + typedef wrap_internal_reference result_converter; +}; + +}} // namespace boost::python + +#endif // RETURN_INTERNAL_REFERENCE_DWA2002131_HPP diff --git a/include/boost/python/return_value_policy.hpp b/include/boost/python/return_value_policy.hpp new file mode 100644 index 00000000..0beec47b --- /dev/null +++ b/include/boost/python/return_value_policy.hpp @@ -0,0 +1,20 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef RETURN_VALUE_POLICY_DWA2002131_HPP +# define RETURN_VALUE_POLICY_DWA2002131_HPP +# include + +namespace boost { namespace python { + +template +struct return_value_policy : Base +{ + typedef Handler result_converter; +}; + +}} // namespace boost::python + +#endif // RETURN_VALUE_POLICY_DWA2002131_HPP diff --git a/include/boost/python/to_python.hpp b/include/boost/python/to_python.hpp new file mode 100644 index 00000000..e00346bb --- /dev/null +++ b/include/boost/python/to_python.hpp @@ -0,0 +1,37 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef TO_PYTHON_DWA2002128_HPP +# define TO_PYTHON_DWA2002128_HPP + +# include +# include + +namespace boost { namespace python { + +template +struct to_python + : converter::to_python_lookup::type> +{ +}; + +// specialization for PyObject* +template <> +struct to_python +{ + bool convertible() const { return true; } + PyObject* operator()(PyObject* source) const { return source; } +}; + +template <> +struct to_python +{ + bool convertible() const { return true; } + PyObject* operator()(PyObject* source) const { return source; } +}; + +}} // namespace boost::python + +#endif // TO_PYTHON_DWA2002128_HPP diff --git a/include/boost/python/type_from_python.hpp b/include/boost/python/type_from_python.hpp new file mode 100644 index 00000000..46d59d13 --- /dev/null +++ b/include/boost/python/type_from_python.hpp @@ -0,0 +1,23 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef TYPE_FROM_PYTHON_DWA2002130_HPP +# define TYPE_FROM_PYTHON_DWA2002130_HPP + +namespace boost { namespace python { + +template +struct type_from_python +{ + static void* convertible(PyObject* op) + { + return PyObject_TypeCheck( + op, const_cast(python_type)) ? op : 0; + } +}; + +}} // namespace boost::python + +#endif // TYPE_FROM_PYTHON_DWA2002130_HPP diff --git a/src/objects.cpp b/src/objects.cpp index 90417dac..b447b262 100644 --- a/src/objects.cpp +++ b/src/objects.cpp @@ -8,7 +8,9 @@ // TODO: Move inline implementations from objects.cpp here -#define BOOST_PYTHON_SOURCE +#ifndef BOOST_PYTHON_SOURCE +r# define BOOST_PYTHON_SOURCE +#endif #include #include diff --git a/test/m1.cpp b/test/m1.cpp index d422b426..b807dc43 100644 --- a/test/m1.cpp +++ b/test/m1.cpp @@ -12,7 +12,8 @@ #include #include #include -//#include +#include +#include #include #include #include @@ -198,6 +199,9 @@ BOOST_PYTHON_MODULE_INIT(m1) using boost::python::value_from_python; using boost::python::type_from_python; using boost::python::get_member; + using boost::python::copy_const_reference; + using boost::python::return_value_policy; + using boost::mpl::type_list; // Create the converters; they are self-registering/unregistering. static to_python_converter c1(simple_to_python); @@ -239,7 +243,8 @@ BOOST_PYTHON_MODULE_INIT(m1) .def("f", f) // Expose g() - .def("g", g) + .def("g", g , return_value_policy() + ) .def("take_a", take_a) .def("take_b", take_b) @@ -279,8 +284,8 @@ BOOST_PYTHON_MODULE_INIT(m1) .add( class_("complicated") - .def_init(args()) - .def_init(args()) + .def_init(type_list()) + .def_init(type_list()) .def("get_n", &complicated::get_n) ) ; diff --git a/test/m2.cpp b/test/m2.cpp index 0a5df161..afffb27d 100644 --- a/test/m2.cpp +++ b/test/m2.cpp @@ -8,6 +8,9 @@ // by exposing raw Python extension functions that use wrap<> and // unwrap<> objects. #include +#include +#include +#include #include "simple_type.hpp" // Get a simple (by value) from the argument, and return the @@ -59,6 +62,10 @@ struct rewrap BOOST_PYTHON_MODULE_INIT(m2) { + using boost::python::return_value_policy; + using boost::python::copy_const_reference; + using boost::python::copy_non_const_reference; + boost::python::module("m2") .def("unwrap_int", unwrap_int) .def("unwrap_int_ref", unwrap_int_ref) @@ -68,11 +75,24 @@ BOOST_PYTHON_MODULE_INIT(m2) .def("unwrap_simple_const_ref", unwrap_simple_const_ref) .def("wrap_int", &rewrap::f) - .def("wrap_int_ref", &rewrap::f) - .def("wrap_int_const_ref", &rewrap::f) + + .def("wrap_int_ref", &rewrap::f + , return_value_policy() + ) + + .def("wrap_int_const_ref", &rewrap::f + , return_value_policy() + ) + .def("wrap_simple", &rewrap::f) - .def("wrap_simple_ref", &rewrap::f) - .def("wrap_simple_const_ref", &rewrap::f) + + .def("wrap_simple_ref", &rewrap::f + , return_value_policy() + ) + + .def("wrap_simple_const_ref", &rewrap::f + , return_value_policy() + ) ; }