Skip to content

Commit f8490a8

Browse files
committed
Fixed init<...> bug where there are no default arguments. Added a test case for this.
[SVN r15224]
1 parent ee1cc99 commit f8490a8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

include/boost/python/init.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ namespace detail {
262262
struct count_optionals2 {
263263

264264
BOOST_STATIC_CONSTANT(
265-
int, value = boost::mpl::size<typename T::sequence>::value);
265+
int, value = boost::mpl::size<typename T::sequence>::value + 1);
266266
};
267267

268268
template <class T>
@@ -407,9 +407,8 @@ template <class ClassT, class CallPoliciesT, class InitT>
407407
void
408408
define_init(ClassT& cl, InitT const& i, CallPoliciesT const& policies, char const* doc)
409409
{
410-
enum { n_defaults_plus_1 = InitT::n_defaults + 1 };
411410
typedef typename InitT::sequence args_t;
412-
detail::define_class_init_helper<n_defaults_plus_1>::apply(cl, policies, args_t(), doc);
411+
detail::define_class_init_helper<InitT::n_defaults>::apply(cl, policies, args_t(), doc);
413412
}
414413

415414
}} // namespace boost::python

test/defaults.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ struct X {
9191
: state(format % make_tuple(a, b, c, d))
9292
{}
9393

94+
X(std::string s, bool b)
95+
: state("Got exactly two arguments from constructor: string(%s); bool(%s); " % make_tuple(s, b))
96+
{}
97+
9498
object
9599
bar(int a, char b = 'D', std::string c = "default", double d = 0.0) const
96100
{
@@ -162,11 +166,13 @@ BOOST_PYTHON_MODULE_INIT(defaults_ext)
162166

163167
# if (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
164168
.def(init<int, optional<char, std::string, double> >())
169+
.def(init<std::string, bool>())
165170
# else
166171
.def_init(args<int>())
167172
.def_init(args<int, char>())
168173
.def_init(args<int, char, std::string>())
169174
.def_init(args<int, char, std::string, double>())
175+
.def_init(args<std::string, bool>())
170176
# endif
171177
.def("get_state", &X::get_state)
172178
.def("bar", &X::bar, X_bar_stubs())

test/defaults.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
'int(1); char(K); string(Kim); double(0.0); '
6767
>>> x.bar2(1, 'K', "Kim", 9.9).get_state()
6868
'int(1); char(K); string(Kim); double(9.9); '
69+
>>> x = X("Phoenix", 1)
70+
>>> x.get_state()
71+
'Got exactly two arguments from constructor: string(Phoenix); bool(1); '
6972
7073
"""
7174
def run(args = None):

0 commit comments

Comments
 (0)