diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 133b752b..08a2c47d 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -52,18 +52,19 @@ namespace detail // type of the first (tag) argument. The 2nd argument is a pointer // to the type of holder that must be created. The 3rd argument is a // reference to the Python type object to be created. - template - static inline void register_copy_constructor(mpl::bool_t const&, Holder*, T* = 0) + template + static inline void register_copy_constructor(mpl::bool_t const&, SelectHolder const& , T* = 0) { - force_instantiate(objects::class_wrapper()); - Holder::register_(); + typedef typename SelectHolder::type holder; + force_instantiate(objects::class_wrapper()); + SelectHolder::register_(); } // Tag dispatched to have no effect. - template - static inline void register_copy_constructor(mpl::bool_t const&, Holder*, T* = 0) + template + static inline void register_copy_constructor(mpl::bool_t const&, SelectHolder const&, T* = 0) { - Holder::register_(); + SelectHolder::register_(); } template int assert_default_constructible(T const&); @@ -340,7 +341,7 @@ inline void class_::register_() const detail::register_copy_constructor( mpl::bool_t() - , objects::select_holder((held_type*)0).get() + , objects::select_holder((held_type*)0) ); } diff --git a/include/boost/python/instance_holder.hpp b/include/boost/python/instance_holder.hpp index f4962479..ea368c1a 100755 --- a/include/boost/python/instance_holder.hpp +++ b/include/boost/python/instance_holder.hpp @@ -25,12 +25,10 @@ struct BOOST_PYTHON_DECL instance_holder : private noncopyable void install(PyObject* inst) throw(); - // Register any converters associated with this Holder - static inline void register_() {} - private: instance_holder* m_next; }; + // This macro is needed for implementation of derived holders # define BOOST_PYTHON_UNFORWARD(N,ignored) (typename unforward::type)(a##N) diff --git a/include/boost/python/object/pointer_holder.hpp b/include/boost/python/object/pointer_holder.hpp index 3d9e9992..d680df66 100644 --- a/include/boost/python/object/pointer_holder.hpp +++ b/include/boost/python/object/pointer_holder.hpp @@ -39,21 +39,12 @@ struct pointer_holder : instance_holder pointer_holder(Pointer); - static void register_(); - // Forward construction to the held object # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, , 1)) # include BOOST_PP_ITERATE() private: // types - struct construct_from_pointer - { - static pointer_holder* execute(PyObject*, Pointer x) - { - return new pointer_holder(x); - } - }; private: // required holder implementation void* holds(type_info); @@ -74,8 +65,6 @@ struct pointer_holder_back_reference : instance_holder // undoubtedly does not carry the correct back reference pointer. pointer_holder_back_reference(Pointer); - static void register_(); - // Forward construction to the held object # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, , 2)) # include BOOST_PP_ITERATE() @@ -95,29 +84,12 @@ inline pointer_holder::pointer_holder(Pointer p) { } -template -inline void pointer_holder::register_() -{ - python::detail::force_instantiate(class_wrapper()); - python::detail::force_instantiate(instance_finder::registration); -} - - template inline pointer_holder_back_reference::pointer_holder_back_reference(Pointer p) : m_p(p) { } -template -inline void pointer_holder_back_reference::register_() -{ - // not implemented at least until we solve the back reference issue mentioned above. - // python::detail::force_instantiate(class_wrapper()); - python::detail::force_instantiate(instance_finder::registration); - python::detail::force_instantiate(instance_finder::registration); -} - template void* pointer_holder::holds(type_info dst_t) { diff --git a/include/boost/python/object/select_holder.hpp b/include/boost/python/object/select_holder.hpp index b4e451c8..a2e50c69 100644 --- a/include/boost/python/object/select_holder.hpp +++ b/include/boost/python/object/select_holder.hpp @@ -11,9 +11,11 @@ # include # include # include +# include # include # include # include +# include namespace boost { namespace python { namespace objects { @@ -28,9 +30,24 @@ namespace detail selector , value_holder_back_reference , value_holder - >::type holder; + >::type type; - static holder* get() { return 0; } + static inline void register_() + { + select_value_holder::register_(mpl::bool_t()); + } + + static type* get() { return 0; } + + private: + static inline void register_(mpl::bool_t) + { + python::detail::force_instantiate(instance_finder::registration); + } + + static inline void register_(mpl::bool_t) + { + } }; template @@ -43,9 +60,47 @@ namespace detail selector , pointer_holder_back_reference , pointer_holder - >::type holder; + >::type type; - static holder* get() { return 0; } + static inline void register_() + { + select_pointer_holder::register_(mpl::bool_t()); + } + + static type* get() { return 0; } + + private: + static inline void register_(mpl::bool_t) + { + // not implemented at least until we solve the back + // reference issue mentioned in pointer_holder.hpp. + // + // python::detail::force_instantiate( + // class_wrapper >()); + + python::detail::force_instantiate(instance_finder::registration); + python::detail::force_instantiate(instance_finder::registration); + } + + struct construct_from_pointer + { + static type* execute(PyObject*, Ptr x) + { + return new type(x); + } + }; + + static inline void register_(mpl::bool_t) + { + python::detail::force_instantiate( + objects::class_wrapper< + Ptr + , type + , construct_from_pointer>()); + + python::detail::force_instantiate( + instance_finder::registration); + } }; } diff --git a/include/boost/python/object/value_holder.hpp b/include/boost/python/object/value_holder.hpp index 3d8d2ac2..05a5c782 100644 --- a/include/boost/python/object/value_holder.hpp +++ b/include/boost/python/object/value_holder.hpp @@ -47,8 +47,6 @@ struct value_holder_back_reference : instance_holder { typedef Held value_type; - static void register_(); - // Forward construction to the held object # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, , 2)) # include BOOST_PP_ITERATE() @@ -85,12 +83,6 @@ void* value_holder_back_reference::holds( return find_static_type(x, src_t, dst_t); } -template -void value_holder_back_reference::register_() -{ - python::detail::force_instantiate(instance_finder::registration); -} - }}} // namespace boost::python::objects # endif // VALUE_HOLDER_DWA20011215_HPP