1616# include < boost/python/object/inheritance.hpp>
1717# include < boost/python/object/find_instance.hpp>
1818# include < boost/python/object/forward.hpp>
19+ # include < boost/python/object/class_wrapper.hpp>
1920# include < boost/python/pointee.hpp>
2021# include < boost/python/detail/force_instantiate.hpp>
2122# include < boost/python/detail/preprocessor.hpp>
@@ -34,13 +35,26 @@ namespace boost { namespace python { namespace objects {
3435template <class Pointer , class Value >
3536struct pointer_holder : instance_holder
3637{
38+ typedef Value value_type;
39+
3740 pointer_holder (Pointer);
3841
42+ static void register_ ();
43+
3944 // Forward construction to the held object
4045
4146# define BOOST_PP_ITERATION_PARAMS_1 (4 , (0 , BOOST_PYTHON_MAX_ARITY, <boost/python/object/pointer_holder.hpp>, 1 ))
4247# include BOOST_PP_ITERATE()
4348
49+ private: // types
50+ struct construct_from_pointer
51+ {
52+ static pointer_holder* execute (PyObject*, Pointer x)
53+ {
54+ return new pointer_holder (x);
55+ }
56+ };
57+
4458 private: // required holder implementation
4559 void * holds (type_info);
4660
@@ -54,9 +68,14 @@ struct pointer_holder_back_reference : instance_holder
5468 private:
5569 typedef typename python::pointee<Pointer>::type held_type;
5670 public:
71+ typedef Value value_type;
5772
73+ // Not sure about this one -- can it work? The source object
74+ // undoubtedly does not carry the correct back reference pointer.
5875 pointer_holder_back_reference (Pointer);
5976
77+ static void register_ ();
78+
6079 // Forward construction to the held object
6180# define BOOST_PP_ITERATION_PARAMS_1 (4 , (0 , BOOST_PYTHON_MAX_ARITY, <boost/python/object/pointer_holder.hpp>, 2 ))
6281# include BOOST_PP_ITERATE()
@@ -76,12 +95,29 @@ inline pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
7695{
7796}
7897
98+ template <class Pointer , class Value >
99+ inline void pointer_holder<Pointer,Value>::register_()
100+ {
101+ python::detail::force_instantiate (class_wrapper<Pointer,pointer_holder,construct_from_pointer>());
102+ python::detail::force_instantiate (instance_finder<Pointer>::registration);
103+ }
104+
105+
79106template <class Pointer , class Value >
80107inline pointer_holder_back_reference<Pointer,Value>::pointer_holder_back_reference(Pointer p)
81108 : m_p(p)
82109{
83110}
84111
112+ template <class Pointer , class Value >
113+ inline void pointer_holder_back_reference<Pointer,Value>::register_()
114+ {
115+ // not implemented at least until we solve the back reference issue mentioned above.
116+ // python::detail::force_instantiate(class_wrapper<Pointer,pointer_holder_back_reference>());
117+ python::detail::force_instantiate (instance_finder<Pointer>::registration);
118+ python::detail::force_instantiate (instance_finder<held_type>::registration);
119+ }
120+
85121template <class Pointer , class Value >
86122void * pointer_holder<Pointer, Value>::holds(type_info dst_t )
87123{
@@ -142,9 +178,7 @@ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
142178 : m_p(new held_type(
143179 p BOOST_PP_COMMA_IF (N) BOOST_PP_REPEAT(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
144180 ))
145- {
146- python::detail::force_instantiate (instance_finder<held_type>::registration);
147- }
181+ {}
148182
149183# undef N
150184
0 commit comments