Skip to content

Commit 43e5ccd

Browse files
committed
object_core.hpp - allow wrapping of objects which take object managers in their constructors.
forward.hpp pointer_holder.hpp value_holder.hpp test/long.[py/cpp] pointee.hpp, - begin making borland work. cv_category.hpp, referent_storage.hpp instance.hpp self.hpp - removed flotsam signature.hpp - use vector instead of list destroy.hpp - removed needless complication make_keyword_range_fn.hpp - support for simpler init using vectors class_converters.hpp - workaround for pro7 inheritance.hpp - simplified; took out pro7 workarounds; factored out inheritance_query.hpp to reduce recompilation dependencies make_ptr_instance.hpp - add missing typename registry.cpp - add a little invariant checking for metrowerks class.cpp - stopped relying on class_id typedef test/data_members.cpp - added a few more tests to make sure things compile at least. test/destroy_test.cpp - removed cheating has_trivial_destructor tests test/enum.cpp - added some pro7 workarounds test/virtual_functions.[py/cpp] - added _some_ tests for callbacks which return by reference. [SVN r18489]
1 parent 66d6272 commit 43e5ccd

25 files changed

+301
-170
lines changed

include/boost/python/detail/cv_category.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ typedef cv_tag<true,true> const_volatile_;
2424
template <class T>
2525
struct cv_category
2626
{
27-
BOOST_STATIC_CONSTANT(bool, c = is_const<T>::value);
28-
BOOST_STATIC_CONSTANT(bool, v = is_volatile<T>::value);
29-
typedef cv_tag<c,v> type;
27+
// BOOST_STATIC_CONSTANT(bool, c = is_const<T>::value);
28+
// BOOST_STATIC_CONSTANT(bool, v = is_volatile<T>::value);
29+
typedef cv_tag<
30+
::boost::is_const<T>::value
31+
, ::boost::is_volatile<T>::value
32+
> type;
3033
};
3134

3235
}}} // namespace boost::python::detail

include/boost/python/detail/destroy.hpp

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
#ifndef DESTROY_DWA2002221_HPP
77
# define DESTROY_DWA2002221_HPP
88

9-
# include <boost/type_traits/composite_traits.hpp>
10-
# include <boost/type_traits/object_traits.hpp>
9+
# include <boost/type_traits/is_array.hpp>
1110

1211
namespace boost { namespace python { namespace detail {
1312

14-
template <bool array, bool trivial_destructor> struct value_destroyer;
15-
13+
template <bool array> struct value_destroyer;
14+
1615
template <>
17-
struct value_destroyer<false,false>
16+
struct value_destroyer<false>
1817
{
1918
template <class T>
2019
static void execute(T const volatile* p)
@@ -24,16 +23,17 @@ struct value_destroyer<false,false>
2423
};
2524

2625
template <>
27-
struct value_destroyer<true,false>
26+
struct value_destroyer<true>
2827
{
2928
template <class A, class T>
3029
static void execute(A*, T const volatile* const first)
3130
{
3231
for (T const volatile* p = first; p != first + sizeof(A)/sizeof(T); ++p)
32+
{
3333
value_destroyer<
3434
boost::is_array<T>::value
35-
,boost::has_trivial_destructor<T>::value
36-
>::execute(p);
35+
>::execute(p);
36+
}
3737
}
3838

3939
template <class T>
@@ -43,33 +43,14 @@ struct value_destroyer<true,false>
4343
}
4444
};
4545

46-
template <>
47-
struct value_destroyer<true,true>
48-
{
49-
template <class T>
50-
static void execute(T const volatile*)
51-
{
52-
}
53-
};
54-
55-
template <>
56-
struct value_destroyer<false,true>
57-
{
58-
template <class T>
59-
static void execute(T const volatile*)
60-
{
61-
}
62-
};
63-
6446
template <class T>
6547
inline void destroy_referent_impl(void* p, T& (*)())
6648
{
6749
// note: cv-qualification needed for MSVC6
6850
// must come *before* T for metrowerks
6951
value_destroyer<
7052
(boost::is_array<T>::value)
71-
,(boost::has_trivial_destructor<T>::value)
72-
>::execute((const volatile T*)p);
53+
>::execute((const volatile T*)p);
7354
}
7455

7556
template <class T>

include/boost/python/detail/make_keyword_range_fn.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ object make_keyword_range_function(F f, Policies const& policies, keyword_range
3434
// constructor.
3535
//
3636
// Holder and ArgList are intended to be explicitly specified.
37-
template <class ArgList, class Holder, class CallPolicies>
37+
template <class ArgList, class Arity, class Holder, class CallPolicies>
3838
object make_keyword_range_constructor(
3939
CallPolicies const& policies // The CallPolicies with which to invoke the Holder's constructor
4040
, detail::keyword_range const& kw // The (possibly empty) set of associated argument keywords
4141
, Holder* = 0
42-
, ArgList* = 0)
42+
, ArgList* = 0, Arity* = 0)
4343
{
44-
BOOST_STATIC_CONSTANT(unsigned, arity = mpl::size<ArgList>::value);
45-
4644
return detail::make_keyword_range_function(
47-
objects::make_holder<arity>
45+
objects::make_holder<Arity::value>
4846
::template apply<Holder,ArgList>::execute
4947
, policies
5048
, kw);

include/boost/python/detail/referent_storage.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ union aligned_storage
6767
template <class T>
6868
struct referent_storage
6969
{
70-
typedef aligned_storage<referent_size<T>::value> type;
70+
typedef aligned_storage<
71+
::boost::python::detail::referent_size<T>::value
72+
> type;
7173
};
7274

7375
}}} // namespace boost::python::detail

include/boost/python/object/class_converters.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# include <boost/python/detail/force_instantiate.hpp>
1515

1616
# include <boost/type_traits/add_pointer.hpp>
17+
# include <boost/type_traits/is_polymorphic.hpp>
1718

1819
# include <boost/mpl/for_each.hpp>
1920

@@ -58,11 +59,15 @@ struct register_base_of
5859
register_conversion<Derived,Base>(false);
5960

6061
// Register the down-cast, if appropriate.
61-
mpl::if_c<
62-
is_polymorphic<Base>::value
63-
, register_downcast<Base,Derived>
64-
, do_nothing
65-
>::type::execute();
62+
mpl::if_<
63+
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
64+
mpl::true_
65+
# else
66+
is_polymorphic<Base>
67+
# endif
68+
, register_downcast<Base,Derived>
69+
, do_nothing
70+
>::type::execute();
6671
}
6772
};
6873

include/boost/python/object/forward.hpp

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
# define FORWARD_DWA20011215_HPP
88

99
# include <boost/mpl/if.hpp>
10-
# include <boost/type_traits/object_traits.hpp>
11-
# include <boost/type_traits/composite_traits.hpp>
12-
# include <boost/type_traits/transform_traits.hpp>
10+
# include <boost/type_traits/is_scalar.hpp>
1311
# include <boost/type_traits/add_const.hpp>
12+
# include <boost/type_traits/add_reference.hpp>
1413
# include <boost/ref.hpp>
1514

1615
namespace boost { namespace python { namespace objects {
@@ -24,7 +23,7 @@ struct reference_to_value
2423
typedef typename add_reference<typename add_const<T>::type>::type reference;
2524

2625
reference_to_value(reference x) : m_value(x) {}
27-
operator reference() const { return m_value; }
26+
reference get() const { return m_value; }
2827
private:
2928
reference m_value;
3029
};
@@ -34,27 +33,43 @@ struct reference_to_value
3433
// is T.
3534
template <class T>
3635
struct forward
37-
: mpl::if_c<
38-
is_scalar<T>::value
36+
: mpl::if_<
37+
is_scalar<T>
3938
, T
40-
, reference_to_value<T> >
39+
, reference_to_value<T>
40+
>
4141
{
4242
};
4343

4444
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
4545
template<typename T>
46-
class unforward
46+
struct unforward
4747
{
48-
public:
4948
typedef typename unwrap_reference<T>::type& type;
5049
};
5150

5251
template<typename T>
53-
class unforward<reference_to_value<T> >
52+
struct unforward<reference_to_value<T> >
5453
{
55-
public:
5654
typedef T type;
5755
};
56+
57+
template <typename T>
58+
struct unforward_cref
59+
: add_reference<
60+
typename add_const<
61+
typename unwrap_reference<T>::type
62+
>::type
63+
>
64+
{
65+
};
66+
67+
template<typename T>
68+
struct unforward_cref<reference_to_value<T> >
69+
: add_reference<typename add_const<T>::type>
70+
{
71+
};
72+
5873
# else // no partial specialization
5974

6075
namespace detail
@@ -87,26 +102,81 @@ namespace detail
87102
};
88103
};
89104

105+
template<bool wrapped = false>
106+
struct cref_unforwarder
107+
{
108+
template <class T>
109+
struct apply
110+
: add_reference<
111+
typename add_const<
112+
typename unwrap_reference<T>::type
113+
>::type
114+
>
115+
{
116+
};
117+
};
118+
119+
template<>
120+
struct cref_unforwarder<true>
121+
{
122+
template <class T>
123+
struct apply
124+
: add_reference<
125+
typename add_const<
126+
typename T::reference
127+
>::type
128+
>
129+
{
130+
};
131+
};
132+
90133
template<typename T>
91-
class is_reference_to_value
134+
struct is_reference_to_value
92135
{
93-
public:
94136
BOOST_STATIC_CONSTANT(
95137
bool, value = (
96138
sizeof(is_reference_to_value_test(boost::type<T>()))
97139
== sizeof(yes_reference_to_value_t)));
140+
typedef mpl::bool_<value> type;
98141
};
99142
}
100143

101144
template <typename T>
102-
class unforward
145+
struct unforward
103146
: public detail::unforwarder<
104147
detail::is_reference_to_value<T>::value
105148
>::template apply<T>
106149
{};
107150

151+
template <typename T>
152+
struct unforward_cref
153+
: public detail::cref_unforwarder<
154+
detail::is_reference_to_value<T>::value
155+
>::template apply<T>
156+
{};
157+
108158
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
109159

160+
template <class T>
161+
typename reference_to_value<T>::reference
162+
do_unforward(reference_to_value<T> const& x, int)
163+
{
164+
return x.get();
165+
}
166+
167+
template <class T>
168+
typename reference_wrapper<T>::type&
169+
do_unforward(reference_wrapper<T> const& x, int)
170+
{
171+
return x.get();
172+
}
173+
174+
template <class T>
175+
T const& do_unforward(T const& x, ...)
176+
{
177+
return x;
178+
}
179+
110180
}}} // namespace boost::python::objects
111181

112182
#endif // FORWARD_DWA20011215_HPP

0 commit comments

Comments
 (0)