mirror of
https://github.com/boostorg/python.git
synced 2026-01-21 17:12:22 +00:00
Move converter registration from body of individual Holder classes to
select_holder implementation, which prevents Holder instantiation in case the class being wrapped is abstract. [SVN r15138]
This commit is contained in:
@@ -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 <class T, class Holder>
|
||||
static inline void register_copy_constructor(mpl::bool_t<true> const&, Holder*, T* = 0)
|
||||
template <class T, class SelectHolder>
|
||||
static inline void register_copy_constructor(mpl::bool_t<true> const&, SelectHolder const& , T* = 0)
|
||||
{
|
||||
force_instantiate(objects::class_wrapper<T,Holder>());
|
||||
Holder::register_();
|
||||
typedef typename SelectHolder::type holder;
|
||||
force_instantiate(objects::class_wrapper<T,holder>());
|
||||
SelectHolder::register_();
|
||||
}
|
||||
|
||||
// Tag dispatched to have no effect.
|
||||
template <class T, class Holder>
|
||||
static inline void register_copy_constructor(mpl::bool_t<false> const&, Holder*, T* = 0)
|
||||
template <class T, class SelectHolder>
|
||||
static inline void register_copy_constructor(mpl::bool_t<false> const&, SelectHolder const&, T* = 0)
|
||||
{
|
||||
Holder::register_();
|
||||
SelectHolder::register_();
|
||||
}
|
||||
|
||||
template <class T> int assert_default_constructible(T const&);
|
||||
@@ -340,7 +341,7 @@ inline void class_<T,X1,X2,X3>::register_() const
|
||||
|
||||
detail::register_copy_constructor<T>(
|
||||
mpl::bool_t<is_copyable>()
|
||||
, objects::select_holder<T,held_type>((held_type*)0).get()
|
||||
, objects::select_holder<T,held_type>((held_type*)0)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<A##N>::type)(a##N)
|
||||
|
||||
|
||||
@@ -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, <boost/python/object/pointer_holder.hpp>, 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, <boost/python/object/pointer_holder.hpp>, 2))
|
||||
# include BOOST_PP_ITERATE()
|
||||
@@ -95,29 +84,12 @@ inline pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
inline void pointer_holder<Pointer,Value>::register_()
|
||||
{
|
||||
python::detail::force_instantiate(class_wrapper<Pointer,pointer_holder,construct_from_pointer>());
|
||||
python::detail::force_instantiate(instance_finder<Pointer>::registration);
|
||||
}
|
||||
|
||||
|
||||
template <class Pointer, class Value>
|
||||
inline pointer_holder_back_reference<Pointer,Value>::pointer_holder_back_reference(Pointer p)
|
||||
: m_p(p)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
inline void pointer_holder_back_reference<Pointer,Value>::register_()
|
||||
{
|
||||
// not implemented at least until we solve the back reference issue mentioned above.
|
||||
// python::detail::force_instantiate(class_wrapper<Pointer,pointer_holder_back_reference>());
|
||||
python::detail::force_instantiate(instance_finder<Pointer>::registration);
|
||||
python::detail::force_instantiate(instance_finder<held_type>::registration);
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
void* pointer_holder<Pointer, Value>::holds(type_info dst_t)
|
||||
{
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
# include <boost/python/pointee.hpp>
|
||||
# include <boost/python/object/value_holder.hpp>
|
||||
# include <boost/python/object/pointer_holder.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/mpl/bool_t.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
@@ -28,9 +30,24 @@ namespace detail
|
||||
selector
|
||||
, value_holder_back_reference<T,Held>
|
||||
, value_holder<T>
|
||||
>::type holder;
|
||||
>::type type;
|
||||
|
||||
static holder* get() { return 0; }
|
||||
static inline void register_()
|
||||
{
|
||||
select_value_holder::register_(mpl::bool_t<selector>());
|
||||
}
|
||||
|
||||
static type* get() { return 0; }
|
||||
|
||||
private:
|
||||
static inline void register_(mpl::bool_t<true>)
|
||||
{
|
||||
python::detail::force_instantiate(instance_finder<Held>::registration);
|
||||
}
|
||||
|
||||
static inline void register_(mpl::bool_t<false>)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <class T,class Ptr>
|
||||
@@ -43,9 +60,47 @@ namespace detail
|
||||
selector
|
||||
, pointer_holder_back_reference<Ptr,T>
|
||||
, pointer_holder<Ptr,T>
|
||||
>::type holder;
|
||||
>::type type;
|
||||
|
||||
static holder* get() { return 0; }
|
||||
static inline void register_()
|
||||
{
|
||||
select_pointer_holder::register_(mpl::bool_t<selector>());
|
||||
}
|
||||
|
||||
static type* get() { return 0; }
|
||||
|
||||
private:
|
||||
static inline void register_(mpl::bool_t<true>)
|
||||
{
|
||||
// not implemented at least until we solve the back
|
||||
// reference issue mentioned in pointer_holder.hpp.
|
||||
//
|
||||
// python::detail::force_instantiate(
|
||||
// class_wrapper<Pointer,pointer_holder_back_reference<Pointer,Value> >());
|
||||
|
||||
python::detail::force_instantiate(instance_finder<Ptr>::registration);
|
||||
python::detail::force_instantiate(instance_finder<pointee>::registration);
|
||||
}
|
||||
|
||||
struct construct_from_pointer
|
||||
{
|
||||
static type* execute(PyObject*, Ptr x)
|
||||
{
|
||||
return new type(x);
|
||||
}
|
||||
};
|
||||
|
||||
static inline void register_(mpl::bool_t<false>)
|
||||
{
|
||||
python::detail::force_instantiate(
|
||||
objects::class_wrapper<
|
||||
Ptr
|
||||
, type
|
||||
, construct_from_pointer>());
|
||||
|
||||
python::detail::force_instantiate(
|
||||
instance_finder<Ptr>::registration);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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, <boost/python/object/value_holder.hpp>, 2))
|
||||
# include BOOST_PP_ITERATE()
|
||||
@@ -85,12 +83,6 @@ void* value_holder_back_reference<Held,BackReferenceType>::holds(
|
||||
return find_static_type(x, src_t, dst_t);
|
||||
}
|
||||
|
||||
template <class Held, class BackReferenceType>
|
||||
void value_holder_back_reference<Held,BackReferenceType>::register_()
|
||||
{
|
||||
python::detail::force_instantiate(instance_finder<BackReferenceType>::registration);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
# endif // VALUE_HOLDER_DWA20011215_HPP
|
||||
|
||||
Reference in New Issue
Block a user