Skip to content

Commit cfb1aeb

Browse files
committed
+ Added Ralf's test code
+ Fixed defaults_gen MACRO generation + Fixed signature for const member functions [SVN r15047]
1 parent e4f54bd commit cfb1aeb

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

include/boost/python/detail/defaults_gen.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct func_stubs_base {};
8888
\
8989
BOOST_PP_FIX_REPEAT_2ND \
9090
( \
91-
BOOST_PP_INC(N_DFLTS), \
91+
N_ARGS, \
9292
BPL_IMPL_TYPEDEF_GEN, \
9393
1 \
9494
) \
@@ -140,7 +140,7 @@ struct func_stubs_base {};
140140
\
141141
BOOST_PP_FIX_REPEAT_2ND \
142142
( \
143-
BOOST_PP_INC(N_DFLTS), \
143+
N_ARGS, \
144144
BPL_IMPL_TYPEDEF_GEN, \
145145
2 \
146146
) \

include/boost/python/signature.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ template
242242
>
243243
inline boost::mpl::type_list
244244
<
245-
RT, ClassT BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
245+
RT, ClassT const BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
246246
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), T)
247247
>
248248
get_signature

test/defaults.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,47 @@ struct X {
8989
abcd.append(d);
9090
return "int(%s); char(%s); string(%s); double(%s); " % tuple(abcd);
9191
}
92+
93+
object
94+
foo(int a, bool b=false) const
95+
{
96+
list ab;
97+
ab.append(a);
98+
ab.append(b);
99+
return "int(%s); bool(%s); " % tuple(ab);
100+
}
101+
102+
object
103+
foo(std::string a, bool b=false) const
104+
{
105+
list ab;
106+
ab.append(a);
107+
ab.append(b);
108+
return "string(%s); bool(%s); " % tuple(ab);
109+
}
110+
111+
object
112+
foo(list a, list b, bool c=false) const
113+
{
114+
list abc;
115+
abc.append(a);
116+
abc.append(b);
117+
abc.append(c);
118+
return "list(%s); list(%s); bool(%s); " % tuple(abc);
119+
}
92120
};
93121

94122
BOOST_PYTHON_MEM_FUN_GENERATOR(X_bar_stubs, bar, 1, 4)
123+
BOOST_PYTHON_MEM_FUN_GENERATOR(X_foo_2_stubs, foo, 1, 2)
124+
BOOST_PYTHON_MEM_FUN_GENERATOR(X_foo_3_stubs, foo, 2, 3)
95125

96126
///////////////////////////////////////////////////////////////////////////////
97127

98128
BOOST_PYTHON_MODULE_INIT(defaults_ext)
99129
{
100130
module("defaults_ext")
101131
.def("foo", foo, foo_stubs())
102-
132+
103133
#if !(defined(BOOST_MSVC) && (BOOST_MSVC <= 1200))
104134
.def("bar", signature<object(*)(int, char, std::string, double)>(), bar_stubs())
105135
#else // signature does not work on VC6 only (VC7 is ok)
@@ -109,7 +139,17 @@ BOOST_PYTHON_MODULE_INIT(defaults_ext)
109139

110140
class_<X>("X")
111141
.def("bar", &X::bar, X_bar_stubs())
142+
.def("foo", (object(X::*)(std::string, bool) const)0, X_foo_2_stubs())
143+
144+
#if !(defined(BOOST_MSVC) && (BOOST_MSVC <= 1200))
145+
.def("foo", signature<object(X::*)(int, bool) const>(), X_foo_2_stubs())
146+
#else // signature does not work on VC6 only (VC7 is ok)
147+
.def("foo", (object(X::*)(int, bool) const)0, X_foo_2_stubs())
148+
#endif
149+
150+
.def("foo", (object(X::*)(list, list, bool) const)0, X_foo_3_stubs())
112151
;
113152
}
114153

115154
#include "module_tail.cpp"
155+

0 commit comments

Comments
 (0)