From 0133bdfbe3733bbedc62a6680e30335670debfce Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sun, 7 Sep 2003 19:44:44 +0000 Subject: [PATCH] Removed unused ConverterGenerators arguments. Updated arg_from_python so that its operator() is nullary -- it already gets everything it needs in its constructor. [SVN r19948] --- include/boost/python/arg_from_python.hpp | 44 ++------- .../python/converter/arg_from_python.hpp | 33 ++++--- .../converter/obj_mgr_arg_from_python.hpp | 10 +- .../converter/pytype_arg_from_python.hpp | 99 ------------------- include/boost/python/data_members.hpp | 6 +- include/boost/python/detail/caller.hpp | 58 +++++------ .../python/detail/make_keyword_range_fn.hpp | 4 +- include/boost/python/detail/signature.hpp | 6 +- include/boost/python/make_function.hpp | 19 ++-- .../boost/python/object/function_handle.hpp | 3 +- include/boost/python/object/iterator.hpp | 4 +- include/boost/python/pure_virtual.hpp | 1 - 12 files changed, 74 insertions(+), 213 deletions(-) delete mode 100644 include/boost/python/converter/pytype_arg_from_python.hpp diff --git a/include/boost/python/arg_from_python.hpp b/include/boost/python/arg_from_python.hpp index 23de5903..b2b40af3 100755 --- a/include/boost/python/arg_from_python.hpp +++ b/include/boost/python/arg_from_python.hpp @@ -26,51 +26,25 @@ struct arg_from_python { typedef PyObject* result_type; - arg_from_python(PyObject*) {} + arg_from_python(PyObject* p) : m_source(p) {} bool convertible() const { return true; } - PyObject* operator()(PyObject* source) const { return source; } + PyObject* operator()() const { return m_source; } + private: + PyObject* m_source; }; template <> struct arg_from_python { typedef PyObject* const& result_type; - arg_from_python(PyObject*) {} + + arg_from_python(PyObject* p) : m_source(p) {} bool convertible() const { return true; } - PyObject*const& operator()(PyObject*const& source) const { return source; } + PyObject*const& operator()() const { return m_source; } + private: + PyObject* m_source; }; -namespace detail -{ - // - // Meta-iterators for use with caller<> - // - - // temporary hack - template struct nullary : T - { - nullary(PyObject* x) : T(x), m_p(x) {} - typename T::result_type operator()() { return this->T::operator()(m_p); } - PyObject* m_p; - }; - - // An MPL metafunction class which returns arg_from_python - struct gen_arg_from_python - { - template struct apply - { - typedef nullary > type; - }; - }; - - // An MPL iterator over an endless sequence of gen_arg_from_python - struct args_from_python - { - typedef gen_arg_from_python type; - typedef args_from_python next; - }; -} - // // implementations // diff --git a/include/boost/python/converter/arg_from_python.hpp b/include/boost/python/converter/arg_from_python.hpp index b17261d0..54ddae0e 100755 --- a/include/boost/python/converter/arg_from_python.hpp +++ b/include/boost/python/converter/arg_from_python.hpp @@ -44,7 +44,7 @@ struct pointer_cref_arg_from_python typedef T result_type; pointer_cref_arg_from_python(PyObject*); - T operator()(PyObject*) const; + T operator()() const; bool convertible() const; private: // storage for a U* @@ -74,7 +74,7 @@ struct pointer_arg_from_python : arg_lvalue_from_python_base typedef T result_type; pointer_arg_from_python(PyObject*); - T operator()(PyObject*) const; + T operator()() const; }; // Used when T == U& and (T != V const& or T == W volatile&) @@ -84,7 +84,7 @@ struct reference_arg_from_python : arg_lvalue_from_python_base typedef T result_type; reference_arg_from_python(PyObject*); - T operator()(PyObject*) const; + T operator()() const; }; // =================== @@ -114,10 +114,11 @@ struct arg_rvalue_from_python # if BOOST_MSVC < 1301 || _MSC_FULL_VER > 13102196 typename arg_rvalue_from_python:: # endif - result_type operator()(PyObject*); + result_type operator()(); private: rvalue_from_python_data m_data; + PyObject* m_source; }; @@ -132,9 +133,10 @@ struct back_reference_arg_from_python typedef T result_type; back_reference_arg_from_python(PyObject*); - T operator()(PyObject*); + T operator()(); private: typedef boost::python::arg_from_python base; + PyObject* m_source; }; @@ -259,9 +261,9 @@ inline bool pointer_cref_arg_from_python::convertible() const return python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0) != 0; } template -inline T pointer_cref_arg_from_python::operator()(PyObject* p) const +inline T pointer_cref_arg_from_python::operator()() const { - return (p == Py_None) // None ==> 0 + return (*(void**)m_result.bytes == Py_None) // None ==> 0 ? detail::null_ptr_reference((T(*)())0) // Otherwise, return a U*const& to the m_result storage. : python::detail::void_ptr_to_reference(m_result.bytes, (T(*)())0); @@ -277,9 +279,9 @@ inline pointer_arg_from_python::pointer_arg_from_python(PyObject* p) } template -inline T pointer_arg_from_python::operator()(PyObject* p) const +inline T pointer_arg_from_python::operator()() const { - return (p == Py_None) ? 0 : T(result()); + return (result() == Py_None) ? 0 : T(result()); } // reference_arg_from_python @@ -291,7 +293,7 @@ inline reference_arg_from_python::reference_arg_from_python(PyObject* p) } template -inline T reference_arg_from_python::operator()(PyObject*) const +inline T reference_arg_from_python::operator()() const { return python::detail::void_ptr_to_reference(result(), (T(*)())0); } @@ -302,6 +304,7 @@ inline T reference_arg_from_python::operator()(PyObject*) const template inline arg_rvalue_from_python::arg_rvalue_from_python(PyObject* obj) : m_data(converter::rvalue_from_python_stage1(obj, registered::converters)) + , m_source(obj) { } @@ -313,10 +316,10 @@ inline bool arg_rvalue_from_python::convertible() const template inline typename arg_rvalue_from_python::result_type -arg_rvalue_from_python::operator()(PyObject* p) +arg_rvalue_from_python::operator()() { if (m_data.stage1.construct != 0) - m_data.stage1.construct(p, &m_data.stage1); + m_data.stage1.construct(m_source, &m_data.stage1); return python::detail::void_ptr_to_reference(m_data.stage1.convertible, (result_type(*)())0); } @@ -325,15 +328,15 @@ arg_rvalue_from_python::operator()(PyObject* p) // template back_reference_arg_from_python::back_reference_arg_from_python(PyObject* x) - : base(x) + : base(x), m_source(x) { } template inline T -back_reference_arg_from_python::operator()(PyObject* x) +back_reference_arg_from_python::operator()() { - return T(x, base::operator()(x)); + return T(m_source, base::operator()()); } }}} // namespace boost::python::converter diff --git a/include/boost/python/converter/obj_mgr_arg_from_python.hpp b/include/boost/python/converter/obj_mgr_arg_from_python.hpp index 1266767d..6f9aef61 100644 --- a/include/boost/python/converter/obj_mgr_arg_from_python.hpp +++ b/include/boost/python/converter/obj_mgr_arg_from_python.hpp @@ -27,7 +27,7 @@ struct object_manager_value_arg_from_python object_manager_value_arg_from_python(PyObject*); bool convertible() const; - T operator()(PyObject*) const; + T operator()() const; private: PyObject* m_source; }; @@ -48,7 +48,7 @@ struct object_manager_ref_arg_from_python object_manager_ref_arg_from_python(PyObject*); bool convertible() const; - Ref operator()(PyObject*) const; + Ref operator()() const; ~object_manager_ref_arg_from_python(); private: typename python::detail::referent_storage::type m_result; @@ -71,9 +71,9 @@ inline bool object_manager_value_arg_from_python::convertible() const } template -inline T object_manager_value_arg_from_python::operator()(PyObject* x) const +inline T object_manager_value_arg_from_python::operator()() const { - return T(python::detail::borrowed_reference(x)); + return T(python::detail::borrowed_reference(m_source)); } template @@ -111,7 +111,7 @@ inline bool object_manager_ref_arg_from_python::convertible() const } template -inline Ref object_manager_ref_arg_from_python::operator()(PyObject*) const +inline Ref object_manager_ref_arg_from_python::operator()() const { return python::detail::void_ptr_to_reference( this->m_result.bytes, (Ref(*)())0); diff --git a/include/boost/python/converter/pytype_arg_from_python.hpp b/include/boost/python/converter/pytype_arg_from_python.hpp deleted file mode 100644 index 7b50b919..00000000 --- a/include/boost/python/converter/pytype_arg_from_python.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// 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 PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP -# define PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP - -# include - -// -// arg_from_python converters for Python type wrappers, to be used as -// base classes for specializations. -// -namespace boost { namespace python { namespace converter { - -template -struct pytype_arg_from_python -{ - pytype_arg_from_python(PyObject*); - bool convertible() const; - private: - PyObject* m_src; -}; - -// rvalue converter base -template -struct pytype_wrapper_value_arg_from_python - : pytype_arg_from_python -{ - typedef Wrapper result_type; - - pytype_wrapper_value_arg_from_python(PyObject*); - Wrapper operator()(PyObject*) const; -}; - -// Special case for Wrapper& - must store an lvalue internally. This -// OK because the entire state of the object is actually in the Python -// object. -template -struct pytype_wrapper_ref_arg_from_python - : pytype_arg_from_python -{ - typedef Wrapper& result_type; - - pytype_wrapper_ref_arg_from_python(PyObject*); - Wrapper& operator()(PyObject*) const; - private: - mutable Wrapper m_result; -}; - -// -// implementations -// - -template -inline pytype_arg_from_python::pytype_arg_from_python(PyObject* x) - : m_src(x) -{ -} - -template -inline bool pytype_arg_from_python::convertible() const -{ - return PyObject_IsInstance(m_src, (PyObject*)python_type); -} - -template -pytype_wrapper_value_arg_from_python::pytype_wrapper_value_arg_from_python( - PyObject* p) - : pytype_arg_from_python(p) -{ -} - -template -Wrapper pytype_wrapper_value_arg_from_python::operator()( - PyObject* x) const -{ - return Wrapper(python::detail::borrowed_reference(x)); -} - -template -pytype_wrapper_ref_arg_from_python::pytype_wrapper_ref_arg_from_python( - PyObject* p) - : pytype_arg_from_python(p) - , m_result(python::detail::borrowed_reference(p)) -{ -} - -template -Wrapper& pytype_wrapper_ref_arg_from_python::operator()( - PyObject* x) const -{ - return m_result; -} - -}}} // namespace boost::python::converter - -#endif // PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP diff --git a/include/boost/python/data_members.hpp b/include/boost/python/data_members.hpp index e9e84a8b..3756bc16 100644 --- a/include/boost/python/data_members.hpp +++ b/include/boost/python/data_members.hpp @@ -69,7 +69,7 @@ namespace detail if (!policies.precall(args_)) return 0; - PyObject* result = cr( (c0(PyTuple_GET_ITEM(args_, 0)))->*pm ); + PyObject* result = cr( (c0())->*pm ); return policies.postcall(args_, result); } @@ -88,7 +88,7 @@ namespace detail if (!policies.precall(args_)) return 0; - (c0(PyTuple_GET_ITEM(args_, 0))).*pm = c1(PyTuple_GET_ITEM(args_, 1)); + (c0()).*pm = c1(); return policies.postcall(args_, detail::none()); } @@ -128,7 +128,7 @@ namespace detail if (!policies.precall(args_)) return 0; - *p = c0(PyTuple_GET_ITEM(args_, 0)); + *p = c0(); return policies.postcall(args_, detail::none()); } diff --git a/include/boost/python/detail/caller.hpp b/include/boost/python/detail/caller.hpp index 14fe9c57..4c18ef5e 100644 --- a/include/boost/python/detail/caller.hpp +++ b/include/boost/python/detail/caller.hpp @@ -17,18 +17,20 @@ # include # include -# include -# include -# include -# include -# include -# include -# include -# include - # include # include # include +# include + +# include + +# include +# include +# include +# include +# include +# include +# include namespace boost { namespace python { namespace detail { @@ -37,14 +39,6 @@ namespace boost { namespace python { namespace detail { // implementation typedef int void_result_to_python; -// A metafunction taking an iterator FunctionIter to a metafunction -// class and an iterator ArgIter to an argument, which applies the -// result of dereferencing FunctionIter to the result of dereferencing -// ArgIter -template -struct apply_iter1 - : mpl::apply1 {}; - // Given a model of CallPolicies and a C++ result type, this // metafunction selects the appropriate converter to use for // converting the result to python. @@ -61,18 +55,17 @@ struct select_result_converter template struct caller_arity; -template +template struct caller; # define BOOST_PYTHON_NEXT(init,name,n) \ typedef BOOST_PP_IF(n,typename BOOST_PP_CAT(name,BOOST_PP_DEC(n)) ::next, init) name##n; -# define BOOST_PYTHON_ARG_CONVERTER(n) \ - BOOST_PYTHON_NEXT(typename first::next, arg_iter,n) \ - BOOST_PYTHON_NEXT(ConverterGenerators, conv_iter,n) \ - typedef typename apply_iter1::type c_t##n; \ - c_t##n c##n(PyTuple_GET_ITEM(args_, n)); \ - if (!c##n.convertible()) \ +# define BOOST_PYTHON_ARG_CONVERTER(n) \ + BOOST_PYTHON_NEXT(typename first::next, arg_iter,n) \ + typedef arg_from_python c_t##n; \ + c_t##n c##n(PyTuple_GET_ITEM(args_, n)); \ + if (!c##n.convertible()) \ return 0; # define BOOST_PP_ITERATION_PARAMS_1 \ @@ -84,11 +77,11 @@ struct caller; // A metafunction returning the base class used for caller. -template +template struct caller_base_select { enum { arity = mpl::size::value - 1 }; - typedef typename caller_arity::template impl type; + typedef typename caller_arity::template impl type; }; // A function object type which wraps C++ objects as Python callable @@ -101,11 +94,6 @@ struct caller_base_select // actually be any data for which an appropriate invoke_tag() can // be generated. invoke(...) takes care of the actual invocation syntax. // -// ConverterGenerators - -// An MPL iterator type over a sequence of metafunction classes -// that can be applied to element 1...N of Sig to produce -// argument from_python converters for the arguments -// // CallPolicies - // The precall, postcall, and what kind of resultconverter to // generate for mpl::front::type @@ -114,12 +102,12 @@ struct caller_base_select // The `intended signature' of the function. An MPL sequence // beginning with a result type and continuing with a list of // argument types. -template +template struct caller - : caller_base_select::type + : caller_base_select::type { typedef typename caller_base_select< - F,ConverterGenerators,CallPolicies,Sig + F,CallPolicies,Sig >::type base; typedef PyObject* result_type; @@ -139,7 +127,7 @@ struct caller template <> struct caller_arity { - template + template struct impl { impl(F f, Policies p) : m_data(f,p) {} diff --git a/include/boost/python/detail/make_keyword_range_fn.hpp b/include/boost/python/detail/make_keyword_range_fn.hpp index 573eea4f..82514b60 100644 --- a/include/boost/python/detail/make_keyword_range_fn.hpp +++ b/include/boost/python/detail/make_keyword_range_fn.hpp @@ -30,7 +30,7 @@ object make_keyword_range_function( , keyword_range const& kw) { return detail::make_function_aux( - f, policies, args_from_python(), detail::get_signature(f), kw, mpl::int_<0>()); + f, policies, detail::get_signature(f), kw, mpl::int_<0>()); } template @@ -41,7 +41,7 @@ object make_keyword_range_function( , Signature const& sig) { return detail::make_function_aux( - f, policies, args_from_python(), sig, kw, mpl::int_<0>()); + f, policies, sig, kw, mpl::int_<0>()); } // } diff --git a/include/boost/python/detail/signature.hpp b/include/boost/python/detail/signature.hpp index de1bd4a2..cc7ba42d 100644 --- a/include/boost/python/detail/signature.hpp +++ b/include/boost/python/detail/signature.hpp @@ -33,8 +33,10 @@ template struct signature_arity; (3, (0, BOOST_PYTHON_MAX_ARITY + 1, )) # include BOOST_PP_ITERATE() -// A metafunction returning the base class used for signature. +// A metafunction returning the base class used for +// +// signature. +// template struct signature_base_select { diff --git a/include/boost/python/make_function.hpp b/include/boost/python/make_function.hpp index ba3dc8b9..b8c26979 100644 --- a/include/boost/python/make_function.hpp +++ b/include/boost/python/make_function.hpp @@ -26,17 +26,16 @@ namespace detail // These helper functions for make_function (below) do the raw work // of constructing a Python object from some invokable entity. See // for more information about how - // the ConverterGenerators and Sig arguments are used. - template + // the Sig arguments is used. + template object make_function_aux( F f // An object that can be invoked by detail::invoke() , CallPolicies const& p // CallPolicies to use in the invocation - , ConverterGenerators const& // An MPL iterator over a sequence of arg_from_python generators , Sig const& // An MPL sequence of argument types expected by F ) { return objects::function_object( - detail::caller(f, p) + detail::caller(f, p) ); } @@ -44,11 +43,10 @@ namespace detail // is used only for a compile-time assertion to make sure the user // doesn't pass more keywords than the function can accept. To // disable all checking, pass mpl::int_<0> for NumKeywords. - template + template object make_function_aux( F f , CallPolicies const& p - , ConverterGenerators const& , Sig const& , detail::keyword_range const& kw // a [begin,end) pair of iterators over keyword names , NumKeywords // An MPL integral type wrapper: the size of kw @@ -61,7 +59,7 @@ namespace detail >::too_many_keywords assertion; return objects::function_object( - detail::caller(f, p) + detail::caller(f, p) , kw); } @@ -75,7 +73,6 @@ namespace detail return detail::make_function_aux( f , policies - , detail::args_from_python() , detail::get_signature(f) , kw.range() , mpl::int_() @@ -88,7 +85,6 @@ namespace detail return detail::make_function_aux( f , policies - , detail::args_from_python() , sig ); } @@ -103,14 +99,14 @@ template object make_function(F f) { return detail::make_function_aux( - f,default_call_policies(),detail::args_from_python(), detail::get_signature(f)); + f,default_call_policies(), detail::get_signature(f)); } template object make_function(F f, CallPolicies const& policies) { return detail::make_function_aux( - f,policies,detail::args_from_python(), detail::get_signature(f)); + f, policies, detail::get_signature(f)); } template @@ -142,7 +138,6 @@ object make_function( return detail::make_function_aux( f , policies - , detail::args_from_python() , sig , kw.range() , mpl::int_() diff --git a/include/boost/python/object/function_handle.hpp b/include/boost/python/object/function_handle.hpp index 67896336..f7b62b50 100644 --- a/include/boost/python/object/function_handle.hpp +++ b/include/boost/python/object/function_handle.hpp @@ -10,7 +10,6 @@ # include # include # include -# include namespace boost { namespace python { namespace objects { @@ -26,7 +25,7 @@ inline handle<> function_handle(F const& f, Signature) return objects::function_handle_impl( python::detail::caller< - F,python::detail::args_from_python,default_call_policies,Signature + F,default_call_policies,Signature >( f, default_call_policies() ) diff --git a/include/boost/python/object/iterator.hpp b/include/boost/python/object/iterator.hpp index af7f68aa..284de261 100644 --- a/include/boost/python/object/iterator.hpp +++ b/include/boost/python/object/iterator.hpp @@ -60,7 +60,7 @@ namespace detail PyObject* py_self = PyTuple_GET_ITEM(args_, 0); arg_from_python c0(py_self); - range_* self = c0(py_self); + range_* self = c0(); // Done iterating? if (self->m_start == self->m_finish) @@ -165,7 +165,7 @@ namespace detail PyObject* arg0 = PyTuple_GET_ITEM(args_, 0); arg_from_python c0(arg0); if (!c0.convertible()) return 0; - typename arg_from_python::result_type x = c0(arg0); + typename arg_from_python::result_type x = c0(); // Build and convert the iterator_range<>. return cr( diff --git a/include/boost/python/pure_virtual.hpp b/include/boost/python/pure_virtual.hpp index 85503787..22be0768 100755 --- a/include/boost/python/pure_virtual.hpp +++ b/include/boost/python/pure_virtual.hpp @@ -8,7 +8,6 @@ # include # include -# include # include # include