From da5979931c4836f9cd0b88bd749d1e3289e97e2e Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 16 Aug 2003 13:48:34 +0000 Subject: [PATCH] class.hpp, object/select_holder.hpp, object/pointer_holder.hpp - fix a problem which was causing value_holder to be instantiated on abstract classes. Now we compute the held_type at an outer level thereby avoiding the inner instantiation. object_core.hpp - workarounds for GCC 2.x bugs suite/indexing/detail/indexing_suite_detail.hpp - workaround for a CWPro8 bug [SVN r19635] --- include/boost/python/class.hpp | 15 ++------ .../boost/python/object/pointer_holder.hpp | 2 +- include/boost/python/object/select_holder.hpp | 4 +++ include/boost/python/object_core.hpp | 35 ++++++++++++++++--- .../indexing/detail/indexing_suite_detail.hpp | 6 ++-- 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 47e0a53f..16bef205 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -585,19 +585,14 @@ inline void class_::register_() const objects::register_class_from_python(); typedef BOOST_DEDUCED_TYPENAME holder_selector::type select_holder; - typedef BOOST_DEDUCED_TYPENAME select_holder::type holder; - typedef BOOST_DEDUCED_TYPENAME holder::held_type held_t; + typedef BOOST_DEDUCED_TYPENAME select_holder::held_type held_t; detail::register_wrapper_class(); detail::register_class_to_python( mpl::bool_() -# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - , holder_selector::execute((held_type*)0) -# else - , BOOST_DEDUCED_TYPENAME holder_selector::type() -# endif - ); + , BOOST_DEDUCED_TYPENAME holder_selector::type() + ); } template @@ -606,11 +601,7 @@ inline class_::class_(char const* name, char const* doc) { this->register_(); this->set_instance_size(holder_selector::additional_size()); -# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - holder_selector::execute((held_type*)0).assert_default_constructible(); -# else holder_selector::type::assert_default_constructible(); -# endif this->def(init<>()); } diff --git a/include/boost/python/object/pointer_holder.hpp b/include/boost/python/object/pointer_holder.hpp index 7b0796ad..60a2df7e 100644 --- a/include/boost/python/object/pointer_holder.hpp +++ b/include/boost/python/object/pointer_holder.hpp @@ -52,7 +52,6 @@ bool is_null(T* p, int) template struct pointer_holder : instance_holder { - typedef Value held_type; typedef Value value_type; pointer_holder(Pointer); @@ -75,6 +74,7 @@ template struct pointer_holder_back_reference : instance_holder { typedef typename python::pointee::type held_type; + private: typedef Value value_type; // Not sure about this one -- can it work? The source object diff --git a/include/boost/python/object/select_holder.hpp b/include/boost/python/object/select_holder.hpp index 00636a95..3b461edd 100644 --- a/include/boost/python/object/select_holder.hpp +++ b/include/boost/python/object/select_holder.hpp @@ -109,6 +109,8 @@ namespace detail , value_holder >::type type; + typedef Held held_type; + static inline void register_() {} static type* get() { return 0; } @@ -136,6 +138,8 @@ namespace detail , pointer_holder >::type type; + typedef typename pointee::type held_type; + static inline void register_() { select_pointer_holder::register_(use_back_ref()); diff --git a/include/boost/python/object_core.hpp b/include/boost/python/object_core.hpp index 14f767a8..d41b18ad 100755 --- a/include/boost/python/object_core.hpp +++ b/include/boost/python/object_core.hpp @@ -34,6 +34,7 @@ # include # include +# include # if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) # include @@ -217,6 +218,7 @@ namespace api PyObject* m_ptr; }; +# if BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template struct is_derived_impl { @@ -235,26 +237,51 @@ namespace api struct is_derived : mpl::bool_::value> {}; +# else + template + struct is_derived + : is_convertible< + typename remove_reference::type* + , U const* + > + {}; +# endif template typename objects::unforward_cref::type do_unforward_cref(T const& x) { +# if BOOST_WORKAROUND(__GNUC__, == 2) + typedef typename objects::unforward_cref::type ret; + return ret(x); +# else return x; +# endif } +# if BOOST_WORKAROUND(__GNUC__, == 2) + // GCC 2.x has non-const string literals; this hacks around that problem. + template + char const (& do_unforward_cref(char const(&x)[N]) )[N] + { + return x; + } +# endif + class object; template PyObject* object_base_initializer(T const& x) { + typedef typename is_derived< + BOOST_DEDUCED_TYPENAME objects::unforward_cref::type + , object + >::type is_obj; + return object_initializer< BOOST_DEDUCED_TYPENAME unwrap_reference::type >::get( api::do_unforward_cref(x) - , is_derived< - BOOST_DEDUCED_TYPENAME objects::unforward_cref::type - , object - >() + , is_obj() ); } diff --git a/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp b/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp index 46a73e05..10aa0954 100644 --- a/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp +++ b/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp @@ -168,12 +168,12 @@ namespace boost { namespace python { namespace detail { while (right != proxies.end()) { + typedef typename Proxy::container_type::difference_type difference_type; extract p(*right); p().set_index( extract(*right)().get_index() - - (typename Proxy::container_type::difference_type(to) - - from - len) - ); + - (difference_type(to) - from - len) + ); ++right; }