Skip to content

Commit 39eab72

Browse files
committed
bugfixes
add_property now uses member_function_cast [SVN r16335]
1 parent 71ea2be commit 39eab72

5 files changed

Lines changed: 42 additions & 36 deletions

File tree

include/boost/python/class.hpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,33 @@ class class_ : public objects::class_base
273273

274274
// Property creation
275275
template <class Get>
276-
self& add_property(char const* name, Get const& fget)
276+
self& add_property(char const* name, Get fget)
277277
{
278-
base::add_property(name, object(fget));
278+
base::add_property(
279+
name
280+
, object(
281+
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
282+
)
283+
);
284+
279285
return *this;
280286
}
281287

282288
template <class Get, class Set>
283-
self& add_property(char const* name, Get const& fget, Set const& fset)
289+
self& add_property(char const* name, Get fget, Set fset)
284290
{
285-
base::add_property(name, object(fget), object(fset));
291+
base::add_property(
292+
name
293+
, object(
294+
detail::member_function_cast<T,Get>::stage1(fget).stage2((T*)0).stage3(fget)
295+
)
296+
, object(
297+
detail::member_function_cast<T,Set>::stage1(fset).stage2((T*)0).stage3(fset)
298+
)
299+
);
286300
return *this;
287301
}
288-
302+
289303
template <class U>
290304
self& setattr(char const* name, U const& x)
291305
{

include/boost/python/detail/def_helper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace detail
6565
struct tuple_extract_base_select
6666
{
6767
typedef typename Tuple::head_type head_type;
68-
typedef typename mpl::apply1<Predicate, add_reference<head_type>::type>::type match_t;
68+
typedef typename mpl::apply1<Predicate, typename add_reference<head_type>::type>::type match_t;
6969
BOOST_STATIC_CONSTANT(bool, match = match_t::value);
7070
typedef typename tuple_extract_impl<match>::template apply<Tuple,Predicate> type;
7171
};

include/boost/python/detail/indirect_traits.hpp

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,47 +47,26 @@ struct is_reference_to_const<T const volatile&>
4747
# endif
4848

4949
template <class T>
50-
struct is_reference_to_function
51-
{
52-
BOOST_STATIC_CONSTANT(bool, value = false);
53-
};
54-
55-
template <class T>
56-
struct is_reference_to_function<T&>
57-
{
58-
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
59-
};
60-
61-
# if 0
62-
template <class T>
63-
struct is_reference_to_function<T const&>
50+
struct is_reference_to_function : mpl::bool_c<false>
6451
{
65-
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
6652
};
6753

6854
template <class T>
69-
struct is_reference_to_function<T volatile&>
55+
struct is_reference_to_function<T&> : is_function<T>
7056
{
71-
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
7257
};
7358

7459
template <class T>
75-
struct is_reference_to_function<T const volatile&>
76-
{
77-
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
78-
};
79-
# endif
80-
template <class T>
81-
struct is_pointer_to_function
60+
struct is_pointer_to_function : mpl::bool_c<false>
8261
{
8362
BOOST_STATIC_CONSTANT(bool, value = false);
8463
};
8564

65+
// There's no such thing as a pointer-to-cv-function, so we don't need
66+
// specializations for those
8667
template <class T>
87-
struct is_pointer_to_function<T*>
68+
struct is_pointer_to_function<T*> : is_function<T>
8869
{
89-
// There's no such thing as a pointer-to-cv-function, so we don't need specializations for those
90-
BOOST_STATIC_CONSTANT(bool, value = is_function<T>::value);
9170
};
9271

9372
template <class T>

test/data_members.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ typedef test_class<1> Y;
2222

2323
double get_fair_value(X const& x) { return x.value(); }
2424

25-
struct Var
25+
26+
struct VarBase
2627
{
27-
Var(std::string name_) : name(name_), value(), name2(name.c_str()), y(6) {}
28+
VarBase(std::string name_) : name(name_) {}
29+
2830
std::string const name;
2931
std::string get_name1() const { return name; }
32+
};
33+
34+
struct Var : VarBase
35+
{
36+
Var(std::string name_) : VarBase(name_), value(), name2(name.c_str()), y(6) {}
3037
std::string const& get_name2() const { return name; }
3138
float value;
3239
char const* name2;
@@ -39,7 +46,7 @@ BOOST_PYTHON_MODULE(data_members_ext)
3946
.def("value", &X::value)
4047
.def("set", &X::set)
4148
.def_readonly("x", &X::x)
42-
.add_property("fair_value", &get_fair_value)
49+
.add_property("fair_value", get_fair_value)
4350
;
4451

4552
class_<Y>("Y", init<int>())
@@ -60,6 +67,8 @@ BOOST_PYTHON_MODULE(data_members_ext)
6067
// sense to add the test here.
6168
.def("get_name1", &Var::get_name1, return_value_policy<return_by_value>())
6269
.def("get_name2", &Var::get_name2, return_value_policy<return_by_value>())
70+
71+
.add_property("name3", &Var::get_name1)
6372
;
6473
}
6574

test/data_members.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
>>> v.y.x = -7
3636
>>> v.y.x
3737
-7
38+
39+
>>> v.name3
40+
'pi'
41+
3842
'''
3943

4044
def run(args = None):

0 commit comments

Comments
 (0)