diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index c990e3bf..76646b41 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -46,7 +46,7 @@ namespace detail struct write_type_id { write_type_id(type_info**p) : p(p) {} - + // Here's the runtime behavior template void operator()(T*) const @@ -85,15 +85,7 @@ namespace detail SelectHolder::register_(); } - template - struct assert_default_constructible - { - static int check2(T const&); - static int check() - { - return sizeof(check2(T())); - } - }; + template int assert_default_constructible(T const&); } // @@ -153,8 +145,8 @@ class class_ : public objects::class_base public: // Automatically derive the class name - only works on some // compilers because type_info::name is sometimes mangled (gcc) - class_(); // With default-constructor init function - class_(no_init_t); // With no init function +// class_(); // With default-constructor init function +// class_(no_init_t); // With no init function // Construct with the class name, with or without docstring, and default init() function class_(char const* name, char const* doc = 0); @@ -165,22 +157,21 @@ class class_ : public objects::class_base // Construct with class name, docstring, and no init() function class_(char const* name, char const* doc, no_init_t); - template - inline class_(char const* name, detail::args_base const&) + template + inline class_(char const* name, init_base const& i) : base(name, id_vector::size, id_vector().ids) { this->register_(); - this->def_init(InitArgs()); + define_init(*this, i.derived()); this->set_instance_size(holder_selector::additional_size()); } - - template - inline class_(char const* name, char const* doc, detail::args_base const&, char const* initdoc = 0) + template + inline class_(char const* name, char const* doc, init_base const& i) : base(name, id_vector::size, id_vector().ids, doc) { this->register_(); - this->def_init(InitArgs(), initdoc); + define_init(*this, i.derived()); this->set_instance_size(holder_selector::additional_size()); } @@ -194,23 +185,10 @@ class class_ : public objects::class_base return *this; } - template - self& def(init const& i) + template + self& def(init_base const& i) { - define_init(*this, i, default_call_policies(), 0); - return *this; - } - - template - self& def( - init const& i, - CallPolicyOrDoc const& policy_or_doc, - char const* doc = 0) - { - typedef detail::def_helper helper; - define_init(*this, i, - helper::get_policy(policy_or_doc), - helper::get_doc(policy_or_doc, doc)); + define_init(*this, i.derived()); return *this; } @@ -218,37 +196,26 @@ class class_ : public objects::class_base self& def(char const* name, Arg1T arg1, Arg2T const& arg2) { // The arguments may be: - // arg1: function or signature - // arg2: policy or docstring or stubs + // def(name, function) + // def(name, function, policy) + // def(name, function, doc_string) + // def(name, signature, stubs) - dispatch_def(&arg2, name, arg1, arg2, (char*)0); + dispatch_def(&arg2, name, arg1, arg2); return *this; } template self& def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3) { - // The arguments may be: - // arg1: function or signature - // arg2: policy or docstring or stubs - // arg3: policy or docstring + // The arguments are definitely: + // def(name, function, policy, doc_string) + // def(name, function, doc_string, policy) dispatch_def(&arg2, name, arg1, arg2, arg3); return *this; } - template - self& def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3, char const* doc) - { - // The arguments are definitely: - // arg1: signature - // arg2: stubs - // arg3: policy - - dispatch_def(&arg2, name, arg1, arg2, arg3, doc); - return *this; - } - template self& def(detail::operator_ const& op) { @@ -288,7 +255,6 @@ class class_ : public objects::class_base // Define the default constructor. self& def_init() { - detail::assert_default_constructible::check(); this->def_init(mpl::list0<>::type()); return *this; } @@ -369,39 +335,46 @@ class class_ : public objects::class_base inline void register_() const; + template + void dispatch_def( + detail::overloads_base const*, + char const* name, + SigT sig, + StubsT const& stubs) + { + // convert sig to a type_list (see detail::get_signature in signature.hpp) + // before calling detail::define_with_defaults. + detail::define_with_defaults( + name, stubs, *this, detail::get_signature(sig)); + } + template void dispatch_def( void const*, char const* name, Fn fn, - CallPolicyOrDoc const& policy_or_doc, - char const* doc) + CallPolicyOrDoc const& policy_or_doc) { typedef detail::def_helper helper; - this->def_impl( name, fn, helper::get_policy(policy_or_doc), - helper::get_doc(policy_or_doc, doc), &fn); + helper::get_doc(policy_or_doc, 0), &fn); } - template + template void dispatch_def( - detail::func_stubs_base const*, + void const*, char const* name, - SigT sig, - StubsT const& stubs, - CallPolicyOrDoc const& policy_or_doc, - char const* doc = 0) + Fn fn, + CallPolicyOrDoc1 const& policy_or_doc1, + CallPolicyOrDoc2 const& policy_or_doc2) { - typedef detail::def_helper helper; + typedef detail::def_helper helper; - // convert sig to a type_list (see detail::get_signature in signature.hpp) - // before calling detail::define_with_defaults. - detail::define_with_defaults( - name, stubs, helper::get_policy(policy_or_doc), - *this, detail::get_signature(sig), - helper::get_doc(policy_or_doc, doc)); + this->def_impl( + name, fn, helper::get_policy(policy_or_doc1, policy_or_doc2), + helper::get_doc(policy_or_doc1, policy_or_doc2), &fn); } }; @@ -421,30 +394,12 @@ inline void class_::register_() const ); } - - -template -inline class_::class_() - : base(typeid(T).name(), id_vector::size, id_vector().ids) -{ - this->register_(); - this->def_init(); - this->set_instance_size(holder_selector::additional_size()); -} - -template -inline class_::class_(no_init_t) - : base(typeid(T).name(), id_vector::size, id_vector().ids) -{ - this->register_(); - this->def_no_init(); -} - template inline class_::class_(char const* name, char const* doc) : base(name, id_vector::size, id_vector().ids, doc) { this->register_(); + detail::force_instantiate(sizeof(detail::assert_default_constructible(T()))); this->def_init(); this->set_instance_size(holder_selector::additional_size()); } diff --git a/include/boost/python/def.hpp b/include/boost/python/def.hpp index c6b8bb54..1ade4fd1 100644 --- a/include/boost/python/def.hpp +++ b/include/boost/python/def.hpp @@ -25,35 +25,44 @@ namespace detail void const*, char const* name, Fn fn, - CallPolicyOrDoc const& policy_or_doc, - char const* doc) + CallPolicyOrDoc const& policy_or_doc) { typedef detail::def_helper helper; detail::scope_setattr_doc( name, boost::python::make_function(fn, helper::get_policy(policy_or_doc)), - helper::get_doc(policy_or_doc, doc)); + helper::get_doc(policy_or_doc, 0)); + } + + template + void dispatch_def( + void const*, + char const* name, + Fn fn, + CallPolicyOrDoc1 const& policy_or_doc1, + CallPolicyOrDoc2 const& policy_or_doc2) + { + typedef detail::def_helper helper; + + detail::scope_setattr_doc( + name, boost::python::make_function( + fn, helper::get_policy(policy_or_doc1, policy_or_doc2)), + helper::get_doc(policy_or_doc1, policy_or_doc2)); } - template + template void dispatch_def( - detail::func_stubs_base const*, + detail::overloads_base const*, char const* name, SigT sig, - StubsT const& stubs, - CallPolicyOrDoc const& policy_or_doc, - char const* doc = 0) + StubsT const& stubs) { - typedef detail::def_helper helper; - // convert sig to a type_list (see detail::get_signature in signature.hpp) // before calling detail::define_with_defaults. scope current; detail::define_with_defaults( - name, stubs, helper::get_policy(policy_or_doc), - current, detail::get_signature(sig), - helper::get_doc(policy_or_doc, doc)); + name, stubs, current, detail::get_signature(sig)); } } @@ -67,33 +76,33 @@ template void def(char const* name, Arg1T arg1, Arg2T const& arg2) { // The arguments may be: - // arg1: function or signature - // arg2: policy or docstring or stubs + // def(name, function) + // def(name, function, policy) + // def(name, function, doc_string) + // def(name, signature, stubs) - detail::dispatch_def(&arg2, name, arg1, arg2, (char*)0); + detail::dispatch_def(&arg2, name, arg1, arg2); } template void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3) { - // The arguments may be: - // arg1: function or signature - // arg2: policy or docstring or stubs - // arg3: policy or docstring + // The arguments are definitely: + // def(name, function, policy, doc_string) // TODO: exchange policy, doc_string position detail::dispatch_def(&arg2, name, arg1, arg2, arg3); } -template -void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3, char const* doc) -{ - // The arguments are definitely: - // arg1: signature - // arg2: stubs - // arg3: policy - - detail::dispatch_def(&arg2, name, arg1, arg2, arg3, doc); -} +//template +//void def(char const* name, Arg1T arg1, Arg2T const& arg2, Arg3T const& arg3, char const* doc) +//{ +// // The arguments are definitely: +// // arg1: signature +// // arg2: stubs +// // arg3: policy +// +// detail::dispatch_def(&arg2, name, arg1, arg2, arg3, doc); +//} }} // namespace boost::python diff --git a/include/boost/python/detail/def_helper.hpp b/include/boost/python/detail/def_helper.hpp index 1222f71b..b9931cfe 100644 --- a/include/boost/python/detail/def_helper.hpp +++ b/include/boost/python/detail/def_helper.hpp @@ -32,17 +32,33 @@ template struct def_helper_impl { template - static P const& get_policy(P const& x) { return x; } + static P const& + get_policy(P const& x) { return x; } + + template + static P1 const& + get_policy(P1 const& x, P2 const&) { return x; } // select left template - static char const* get_doc(P const&, char const* doc) { return doc; } + static char const* + get_doc(P const&, char const* doc) { return doc; } // select right }; template <> struct def_helper_impl { - static python::default_call_policies get_policy(char const*) { return default_call_policies(); } - static char const* get_doc(char const* doc, char const*) { return doc; } + static python::default_call_policies + get_policy(char const*) + { return default_call_policies(); } + + template + static P2 const& + get_policy(P1 const&, P2 const& y) { return y; } // select right + + template + static char const* + get_doc(char const* doc, P const&) // select left + { return doc; } }; template diff --git a/include/boost/python/detail/defaults_def.hpp b/include/boost/python/detail/defaults_def.hpp index 9c79d926..721fc37f 100644 --- a/include/boost/python/detail/defaults_def.hpp +++ b/include/boost/python/detail/defaults_def.hpp @@ -191,24 +191,22 @@ struct define_stub_function {}; // void C::foo(int) mpl::list // /////////////////////////////////////////////////////////////////////////////// - template + template inline void define_with_defaults( char const* name, - StubsT, - CallPolicies const& policies, + StubsT const& stubs, NameSpaceT& name_space, - SigT sig, - char const* doc) + SigT sig) { typedef typename mpl::front::type return_type; - typedef typename StubsT::v_type v_type; - typedef typename StubsT::nv_type nv_type; + typedef typename StubsT::void_return_type void_return_type; + typedef typename StubsT::non_void_return_type non_void_return_type; typedef typename mpl::if_c< boost::is_same::value - , v_type - , nv_type + , void_return_type + , non_void_return_type >::type stubs_type; BOOST_STATIC_ASSERT( @@ -216,7 +214,7 @@ struct define_stub_function {}; typedef typename stubs_type::template gen gen_type; define_with_defaults_helper::def - (name, gen_type(), policies, name_space, doc); + (name, gen_type(), stubs.call_policies(), name_space, stubs.doc_string()); } } // namespace detail @@ -238,8 +236,7 @@ struct define_stub_function { StubsT, CallPolicies const& policies, NameSpaceT& name_space, - char const* doc - ) + char const* doc) { detail::name_space_def(name_space, name, diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index 78808424..f2d48897 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -12,12 +12,12 @@ #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -26,164 +26,224 @@ #include #include -namespace boost { namespace python { namespace detail { +namespace boost { namespace python { + +// overloads_base is used as a base class for all function +// stubs. This class holds the doc_string of the stubs. + +namespace detail +{ + struct overloads_base + { + overloads_base(char const* doc_) + : doc(doc_) {} + + char const* doc_string() const + { return doc; } + + char const* doc; + }; +} + +// overloads_proxy is generated by the overloads_common operator[] (see +// below). This class holds a user defined call policies of the stubs. + +template +struct overloads_proxy + : public detail::overloads_base +{ + typedef typename OverloadsT::non_void_return_type non_void_return_type; + typedef typename OverloadsT::void_return_type void_return_type; + + overloads_proxy(CallPoliciesT const& policies_, char const* doc) + : detail::overloads_base(doc), policies(policies_) {} + + CallPoliciesT + call_policies() const + { return policies; } + + CallPoliciesT policies; +}; + +// overloads_common is our default function stubs base class. This class +// returns the default_call_policies in its call_policies() member function. +// It can generate a overloads_proxy however through its operator[] + +template +struct overloads_common +: public detail::overloads_base { + + overloads_common(char const* doc) + : detail::overloads_base(doc) {} + + default_call_policies + call_policies() const + { return default_call_policies(); } + + template + ::boost::python::overloads_proxy + operator[](CallPoliciesT const& policies) const + { + return overloads_proxy + (policies, doc); + } +}; + +}} // namespace boost::python /////////////////////////////////////////////////////////////////////////////// -// -// func_stubs_base is used as a base class for all function stubs. -// -/////////////////////////////////////////////////////////////////////////////// -struct func_stubs_base {}; +#define BOOST_PYTHON_TYPEDEF_GEN(z, index, data) \ + typedef typename BOOST_PP_CAT(iter, index)::next \ + BOOST_PP_CAT(iter, BOOST_PP_INC(index)); \ + typedef typename BOOST_PP_CAT(iter, index)::type BOOST_PP_CAT(T, index); \ -}}} // namespace boost::python::detail - - -/////////////////////////////////////////////////////////////////////////////// -#define BPL_IMPL_TYPEDEF_GEN(z, INDEX, DATA) \ - typedef typename ::boost::mpl::at_c \ - < \ - BOOST_PP_ADD_D(1, INDEX, DATA), \ - SigT \ - >::type BOOST_PP_CAT(T, INDEX); \ - -#define BPL_IMPL_FUNC_WRAPPER_GEN(z, index, DATA) \ - static RT BOOST_PP_CAT(func_, index) ( \ - BOOST_PYTHON_BINARY_ENUM( \ - BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), T, arg) \ - ) \ - { \ - BOOST_PP_TUPLE_ELEM(3, 2, DATA) \ - BOOST_PP_TUPLE_ELEM(3, 0, DATA) \ - ( \ - BOOST_PP_ENUM_PARAMS( \ - BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), \ - arg \ - ) \ - ); \ +#define BOOST_PYTHON_FUNC_WRAPPER_GEN(z, index, data) \ + static RT BOOST_PP_CAT(func_, \ + BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \ + BOOST_PYTHON_BINARY_ENUM( \ + index, T, arg)) \ + { \ + BOOST_PP_TUPLE_ELEM(3, 2, data) \ + BOOST_PP_TUPLE_ELEM(3, 0, data)( \ + BOOST_PP_ENUM_PARAMS( \ + index, \ + arg)); \ } -#define BPL_IMPL_GEN_FUNCTION(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS, RETURN) \ - struct FSTUBS_NAME { \ +#define BOOST_PYTHON_GEN_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \ + struct fstubs_name { \ \ - BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(N_DFLTS)); \ + BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \ BOOST_STATIC_CONSTANT(int, max_args = n_funcs); \ \ template \ struct gen { \ \ - typedef typename ::boost::mpl::front::type RT; \ + typedef typename ::boost::mpl::begin::type rt_iter; \ + typedef typename rt_iter::type RT; \ + typedef typename rt_iter::next iter0; \ \ - BOOST_PP_REPEAT_2ND \ - ( \ - N_ARGS, \ - BPL_IMPL_TYPEDEF_GEN, \ - 1 \ - ) \ + BOOST_PP_REPEAT_2ND( \ + n_args, \ + BOOST_PYTHON_TYPEDEF_GEN, \ + 0) \ \ - BOOST_PP_REPEAT_2ND \ - ( \ - BOOST_PP_INC(N_DFLTS), \ - BPL_IMPL_FUNC_WRAPPER_GEN, \ - (FNAME, BOOST_PP_SUB_D(1, N_ARGS, N_DFLTS), RETURN) \ - ) \ + BOOST_PP_REPEAT_FROM_TO( \ + BOOST_PP_SUB_D(1, n_args, n_dflts), \ + BOOST_PP_INC(n_args), \ + BOOST_PYTHON_FUNC_WRAPPER_GEN, \ + (fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \ }; \ }; \ /////////////////////////////////////////////////////////////////////////////// -#define BPL_IMPL_MEM_FUNC_WRAPPER_GEN(z, index, DATA) \ - static RT BOOST_PP_CAT(func_, index) ( \ - ClassT& obj BOOST_PP_COMMA_IF( \ - BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index)) \ - BOOST_PYTHON_BINARY_ENUM( \ - BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), T, arg) \ +#define BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN(z, index, data) \ + static RT BOOST_PP_CAT(func_, \ + BOOST_PP_SUB_D(1, index, BOOST_PP_TUPLE_ELEM(3, 1, data))) ( \ + ClassT& obj BOOST_PP_COMMA_IF(index) \ + BOOST_PYTHON_BINARY_ENUM(index, T, arg) \ ) \ { \ - BOOST_PP_TUPLE_ELEM(3, 2, DATA) obj.BOOST_PP_TUPLE_ELEM(3, 0, DATA)( \ - BOOST_PP_ENUM_PARAMS( \ - BOOST_PP_ADD_D(1, BOOST_PP_TUPLE_ELEM(3, 1, DATA), index), arg \ - ) \ + BOOST_PP_TUPLE_ELEM(3, 2, data) obj.BOOST_PP_TUPLE_ELEM(3, 0, data)( \ + BOOST_PP_ENUM_PARAMS(index, arg) \ ); \ } -#define BPL_IMPL_GEN_MEM_FUNCTION(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS, RETURN) \ - struct FSTUBS_NAME { \ - \ - BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(N_DFLTS)); \ - BOOST_STATIC_CONSTANT(int, max_args = n_funcs + 1); \ - \ - template \ - struct gen { \ - \ - typedef typename ::boost::mpl::front::type RT; \ - typedef typename ::boost::mpl::at_c<1, SigT>::type ClassT; \ - \ - BOOST_PP_REPEAT_2ND \ - ( \ - N_ARGS, \ - BPL_IMPL_TYPEDEF_GEN, \ - 2 \ - ) \ - \ - BOOST_PP_REPEAT_2ND \ - ( \ - BOOST_PP_INC(N_DFLTS), \ - BPL_IMPL_MEM_FUNC_WRAPPER_GEN, \ - (FNAME, BOOST_PP_SUB_D(1, N_ARGS, N_DFLTS), RETURN) \ - ) \ - }; \ +#define BOOST_PYTHON_GEN_MEM_FUNCTION(fname, fstubs_name, n_args, n_dflts, ret) \ + struct fstubs_name { \ + \ + BOOST_STATIC_CONSTANT(int, n_funcs = BOOST_PP_INC(n_dflts)); \ + BOOST_STATIC_CONSTANT(int, max_args = n_funcs + 1); \ + \ + template \ + struct gen { \ + \ + typedef typename ::boost::mpl::begin::type rt_iter; \ + typedef typename rt_iter::type RT; \ + \ + typedef typename rt_iter::next class_iter; \ + typedef typename class_iter::type ClassT; \ + typedef typename class_iter::next iter0; \ + \ + BOOST_PP_REPEAT_2ND( \ + n_args, \ + BOOST_PYTHON_TYPEDEF_GEN, \ + 0) \ + \ + BOOST_PP_REPEAT_FROM_TO( \ + BOOST_PP_SUB_D(1, n_args, n_dflts), \ + BOOST_PP_INC(n_args), \ + BOOST_PYTHON_MEM_FUNC_WRAPPER_GEN, \ + (fname, BOOST_PP_SUB_D(1, n_args, n_dflts), ret)) \ + }; \ }; - /////////////////////////////////////////////////////////////////////////////// -#if defined(BOOST_MSVC) +#if defined(BOOST_NO_VOID_RETURNS) -#define BPL_IMPL_GEN_FUNCTION_STUB(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS) \ - BPL_IMPL_GEN_FUNCTION \ - (FNAME, BOOST_PP_CAT(FSTUBS_NAME, _NV), N_ARGS, N_DFLTS, return) \ - BPL_IMPL_GEN_FUNCTION \ - (FNAME, BOOST_PP_CAT(FSTUBS_NAME, _V), N_ARGS, N_DFLTS, ;) \ - struct FSTUBS_NAME \ - : public boost::python::detail::func_stubs_base { \ - \ - typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) nv_type; \ - typedef BOOST_PP_CAT(FSTUBS_NAME, _V) v_type; \ +#define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ + BOOST_PYTHON_GEN_FUNCTION \ + (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ + BOOST_PYTHON_GEN_FUNCTION \ + (fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \ + struct fstubs_name \ + : public boost::python::overloads_common \ + { \ + typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, _V) void_return_type; \ + \ + fstubs_name(char const* doc = 0) \ + : boost::python:: \ + overloads_common(doc) {} \ }; \ /////////////////////////////////////////////////////////////////////////////// -#define BPL_IMPL_GEN_MEM_FUNCTION_STUB(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS) \ - BPL_IMPL_GEN_MEM_FUNCTION \ - (FNAME, BOOST_PP_CAT(FSTUBS_NAME, _NV), N_ARGS, N_DFLTS, return) \ - BPL_IMPL_GEN_MEM_FUNCTION \ - (FNAME, BOOST_PP_CAT(FSTUBS_NAME, _V), N_ARGS, N_DFLTS, ;) \ - struct FSTUBS_NAME \ - : public boost::python::detail::func_stubs_base { \ +#define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ + BOOST_PYTHON_GEN_MEM_FUNCTION \ + (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ + BOOST_PYTHON_GEN_MEM_FUNCTION \ + (fname, BOOST_PP_CAT(fstubs_name, _V), n_args, n_dflts, ;) \ + struct fstubs_name \ + : public boost::python::overloads_common \ + { \ + typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, _V) void_return_type; \ \ - typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) nv_type; \ - typedef BOOST_PP_CAT(FSTUBS_NAME, _V) v_type; \ + fstubs_name(char const* doc = 0) \ + : boost::python:: \ + overloads_common(doc) {} \ }; \ #else /////////////////////////////////////////////////////////////////////////////// -#define BPL_IMPL_GEN_FUNCTION_STUB(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS) \ - BPL_IMPL_GEN_FUNCTION \ - (FNAME, BOOST_PP_CAT(FSTUBS_NAME, _NV), N_ARGS, N_DFLTS, return) \ - struct FSTUBS_NAME \ - : public boost::python::detail::func_stubs_base { \ +#define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ + BOOST_PYTHON_GEN_FUNCTION \ + (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ + struct fstubs_name \ + : public boost::python::overloads_common \ + { \ + typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, _NV) void_return_type; \ \ - typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) nv_type; \ - typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) v_type; \ + fstubs_name(char const* doc = 0) \ + : boost::python:: \ + overloads_common(doc) {} \ }; \ /////////////////////////////////////////////////////////////////////////////// -#define BPL_IMPL_GEN_MEM_FUNCTION_STUB(FNAME, FSTUBS_NAME, N_ARGS, N_DFLTS) \ - BPL_IMPL_GEN_MEM_FUNCTION \ - (FNAME, BOOST_PP_CAT(FSTUBS_NAME, _NV), N_ARGS, N_DFLTS, return) \ - struct FSTUBS_NAME \ - : public boost::python::detail::func_stubs_base { \ +#define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ + BOOST_PYTHON_GEN_MEM_FUNCTION \ + (fname, BOOST_PP_CAT(fstubs_name, _NV), n_args, n_dflts, return) \ + struct fstubs_name \ + : public boost::python::overloads_common \ + { \ + typedef BOOST_PP_CAT(fstubs_name, _NV) non_void_return_type; \ + typedef BOOST_PP_CAT(fstubs_name, _NV) void_return_type; \ \ - typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) nv_type; \ - typedef BOOST_PP_CAT(FSTUBS_NAME, _NV) v_type; \ + fstubs_name(char const* doc = 0) \ + : boost::python:: \ + overloads_common(doc) {} \ }; \ #endif // defined(BOOST_MSVC) @@ -192,11 +252,11 @@ struct func_stubs_base {}; // // MAIN MACROS // -// Given GENERATOR_NAME, FNAME, MIN_ARGS and MAX_ARGS, These macros +// Given generator_name, fname, min_args and max_args, These macros // generate function stubs that forward to a function or member function -// named FNAME. MAX_ARGS is the arity of the function or member function -// FNAME. FNAME can have default arguments. MIN_ARGS is the minimum -// arity that FNAME can accept. +// named fname. max_args is the arity of the function or member function +// fname. fname can have default arguments. min_args is the minimum +// arity that fname can accept. // // There are two versions: // @@ -225,11 +285,17 @@ struct func_stubs_base {}; // template // struct gen { // -// typedef typename ::boost::mpl::at_c<0, SigT>::type RT; -// typedef typename ::boost::mpl::at_c<1, SigT>::type T0; -// typedef typename ::boost::mpl::at_c<2, SigT>::type T1; -// typedef typename ::boost::mpl::at_c<3, SigT>::type T2; -// typedef typename ::boost::mpl::at_c<4, SigT>::type T3; +// typedef typename ::boost::mpl::begin::type rt_iter; +// typedef typename rt_iter::type RT; +// typedef typename rt_iter::next iter0; +// typedef typename iter0::type T0; +// typedef typename iter0::next iter1; +// typedef typename iter1::type T1; +// typedef typename iter1::next iter2; +// typedef typename iter2::type T2; +// typedef typename iter2::next iter3; +// typedef typename iter3::type T3; +// typedef typename iter3::next iter4; // // static RT func_0(T0 arg0) // { return foo(arg0); } @@ -246,37 +312,42 @@ struct func_stubs_base {}; // }; // // struct foo_stubs -// : public boost::python::detail::func_stubs_base { +// : public boost::python::overloads_common // -// typedef foo_stubs_NV nv_type; -// typedef foo_stubs_NV v_type; +// typedef foo_stubs_NV non_void_return_type; +// typedef foo_stubs_NV void_return_type; +// +// fstubs_name(char const* doc = 0) +// : boost::python:: +// overloads_common(doc) {} // }; // -// The typedefs nv_type and v_type are used to handle compilers that -// do not support void returns. The example above typedefs nv_type -// and v_type to foo_stubs_NV. On compilers that do not support -// void returns, there are two versions: foo_stubs_NV and foo_stubs_V. -// The "V" version is almost identical to the "NV" version except -// for the return type (void) and the lack of the return keyword. +// The typedefs non_void_return_type and void_return_type are +// used to handle compilers that do not support void returns. The +// example above typedefs non_void_return_type and +// void_return_type to foo_stubs_NV. On compilers that do not +// support void returns, there are two versions: foo_stubs_NV and +// foo_stubs_V. The "V" version is almost identical to the "NV" +// version except for the return type (void) and the lack of the +// return keyword. +// +// See the overloads_common above for a description of the foo_stubs' +// base class. // /////////////////////////////////////////////////////////////////////////////// -#define BOOST_PYTHON_FUNCTION_OVERLOADS(GENERATOR_NAME, FNAME, MIN_ARGS, MAX_ARGS) \ - BPL_IMPL_GEN_FUNCTION_STUB \ - ( \ - FNAME, \ - GENERATOR_NAME, \ - MAX_ARGS, \ - BOOST_PP_SUB_D(1, MAX_ARGS, MIN_ARGS) \ - ) +#define BOOST_PYTHON_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \ + BOOST_PYTHON_GEN_FUNCTION_STUB( \ + fname, \ + generator_name, \ + max_args, \ + BOOST_PP_SUB_D(1, max_args, min_args)) -#define BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(GENERATOR_NAME, FNAME, MIN_ARGS, MAX_ARGS) \ - BPL_IMPL_GEN_MEM_FUNCTION_STUB \ - ( \ - FNAME, \ - GENERATOR_NAME, \ - MAX_ARGS, \ - BOOST_PP_SUB_D(1, MAX_ARGS, MIN_ARGS) \ - ) +#define BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(generator_name, fname, min_args, max_args) \ + BOOST_PYTHON_GEN_MEM_FUNCTION_STUB( \ + fname, \ + generator_name, \ + max_args, \ + BOOST_PP_SUB_D(1, max_args, min_args)) // deprecated macro names (to be removed) #define BOOST_PYTHON_FUNCTION_GENERATOR BOOST_PYTHON_FUNCTION_OVERLOADS diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index 385fb385..ed913124 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -36,26 +36,20 @@ /////////////////////////////////////////////////////////////////////////////// #define BOOST_PYTHON_TEMPLATE_TYPES_WITH_DEFAULT \ - BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT \ - ( \ + BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( \ BOOST_PYTHON_MAX_ARITY, \ class T, \ - mpl::void_ \ - ) \ + mpl::void_) \ #define BOOST_PYTHON_TEMPLATE_TYPES \ - BOOST_PP_ENUM_PARAMS \ - ( \ + BOOST_PP_ENUM_PARAMS( \ BOOST_PYTHON_MAX_ARITY, \ - class T \ - ) \ + class T) \ #define BOOST_PYTHON_TEMPLATE_ARGS \ - BOOST_PP_ENUM_PARAMS \ - ( \ + BOOST_PP_ENUM_PARAMS( \ BOOST_PYTHON_MAX_ARITY, \ - T \ - ) \ + T) \ /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace python { @@ -94,7 +88,7 @@ namespace detail { bool, value = sizeof(f(t())) == sizeof(::boost::type_traits::yes_type)); typedef mpl::bool_c type; - + BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_optional,(T)) // needed for MSVC & Borland }; @@ -123,10 +117,56 @@ namespace detail { } // namespace detail +template +struct init_base { + + DerivedT const& derived() const + { return *static_cast(this); } +}; + +template +struct init_with_call_policies +: public init_base > +{ + BOOST_STATIC_CONSTANT(int, n_arguments = InitT::n_arguments); + BOOST_STATIC_CONSTANT(int, n_defaults = InitT::n_defaults); + + typedef typename InitT::reversed_args reversed_args; + + init_with_call_policies(CallPoliciesT const& policies_, char const* doc_) + : policies(policies_), doc(doc_) {} + + char const* doc_string() const + { return doc; } + + CallPoliciesT + call_policies() const + { return policies; } + + CallPoliciesT policies; + char const* doc; +}; template -struct init //: detail::check_init_params +struct init : public init_base > { + typedef init self_t; + + init(char const* doc_ = 0) + : doc(doc_) {} + + char const* doc_string() const + { return doc; } + + default_call_policies + call_policies() const + { return default_call_policies(); } + + template + init_with_call_policies + operator[](CallPoliciesT const& policies) const + { return init_with_call_policies(policies, doc); } + typedef detail::type_list signature_; typedef typename mpl::end::type finish; @@ -143,7 +183,7 @@ struct init //: detail::check_init_params , mpl::next >::type expected_finish; BOOST_STATIC_ASSERT((is_same::value)); - + typedef typename mpl::apply_if< is_same , mpl::list0<> @@ -173,6 +213,36 @@ struct init //: detail::check_init_params // Count the maximum number of arguments BOOST_STATIC_CONSTANT(int, n_arguments = mpl::size::value); + + char const* doc; +}; + +template <> // specialization for zero args +struct init<> : public init_base > +{ + typedef init<> self_t; + + init(char const* doc_ = 0) + : doc(doc_) {} + + char const* doc_string() const + { return doc; } + + default_call_policies + call_policies() const + { return default_call_policies(); } + + template + init_with_call_policies + operator[](CallPoliciesT const& policies) const + { return init_with_call_policies(policies, doc); } + + BOOST_STATIC_CONSTANT(int, n_defaults = 0); + BOOST_STATIC_CONSTANT(int, n_arguments = 0); + + typedef detail::type_list<> reversed_args; + + char const* doc; }; /////////////////////////////////////////////////////////////////////////////// @@ -198,10 +268,10 @@ namespace detail , mpl::list0<> , mpl::push_front<> >::type args; - + cl.def_init(args(), policies, doc); } - + /////////////////////////////////////////////////////////////////////////////// // // define_class_init_helper::apply @@ -269,12 +339,13 @@ namespace detail // __init__(int) // /////////////////////////////////////////////////////////////////////////////// -template +template void -define_init(ClassT& cl, InitT const& i, CallPoliciesT const& policies, char const* doc) +define_init(ClassT& cl, InitT const& i) { typedef typename InitT::reversed_args reversed_args; - detail::define_class_init_helper::apply(cl, policies, reversed_args(), doc); + detail::define_class_init_helper::apply( + cl, i.call_policies(), reversed_args(), i.doc_string()); } }} // namespace boost::python diff --git a/include/boost/python/module.hpp b/include/boost/python/module.hpp index a455ca41..2bf923c0 100644 --- a/include/boost/python/module.hpp +++ b/include/boost/python/module.hpp @@ -85,13 +85,12 @@ class module : public detail::module_base SigT sig, StubsT const& stubs, char const* doc, - detail::func_stubs_base const*) + detail::overloads_base const*) { // convert sig to a type_list (see detail::get_signature in signature.hpp) // before calling detail::define_with_defaults. detail::define_with_defaults( - name, stubs, default_call_policies(), - *this, detail::get_signature(sig), doc); + name, stubs, *this, detail::get_signature(sig)); } }; diff --git a/test/back_reference.cpp b/test/back_reference.cpp index 73990640..d5ae5ece 100644 --- a/test/back_reference.cpp +++ b/test/back_reference.cpp @@ -93,12 +93,12 @@ BOOST_PYTHON_MODULE_INIT(back_reference_ext) def("copy_Z", copy_Z, return_value_policy()); def("x_instances", &X::count); - class_("Y", args()) + class_("Y", init()) .def("value", &Y::value) .def("set", &Y::set) ; - class_ >("Z", args()) + class_ >("Z", init()) .def("value", &Z::value) .def("set", &Z::set) ; diff --git a/test/bienstman3.cpp b/test/bienstman3.cpp index f1dc212d..22c7638e 100644 --- a/test/bienstman3.cpp +++ b/test/bienstman3.cpp @@ -17,6 +17,6 @@ BOOST_PYTHON_MODULE_INIT(bienstman3_ext) using namespace boost::python; class_("V", no_init); - class_("B", args()); + class_("B", init()); } diff --git a/test/bienstman4.cpp b/test/bienstman4.cpp index 324af85a..ee510f2d 100644 --- a/test/bienstman4.cpp +++ b/test/bienstman4.cpp @@ -30,7 +30,7 @@ BOOST_PYTHON_MODULE_INIT(bienstman4_ext) class_("T1") ; - class_("Term", args()) + class_("Term", init()) ; Type1 t1; diff --git a/test/bienstman5.cpp b/test/bienstman5.cpp index 007d12a9..75fbd8da 100644 --- a/test/bienstman5.cpp +++ b/test/bienstman5.cpp @@ -17,7 +17,7 @@ BOOST_PYTHON_MODULE_INIT(bienstman5_ext) { using namespace boost::python; - class_("M", args const&>()) + class_("M", init const&>()) ; } diff --git a/test/callbacks.cpp b/test/callbacks.cpp index 700c190a..763dcda8 100644 --- a/test/callbacks.cpp +++ b/test/callbacks.cpp @@ -137,8 +137,8 @@ BOOST_PYTHON_MODULE_INIT(callbacks_ext) def("apply_to_string_literal", apply_to_string_literal); - class_("X", args()) - .def_init(args()) + class_("X", init()) + .def(init()) .def("value", &X::value) .def("set", &X::set) ; diff --git a/test/data_members.cpp b/test/data_members.cpp index 99459dff..7a05d359 100644 --- a/test/data_members.cpp +++ b/test/data_members.cpp @@ -22,14 +22,14 @@ double get_fair_value(X const& x) { return x.value(); } BOOST_PYTHON_MODULE_INIT(data_members_ext) { - class_("X", args()) + class_("X", init()) .def("value", &X::value) .def("set", &X::set) .def_readonly("x", &X::x) .add_property("fair_value", &get_fair_value) ; - class_("Y", args()) + class_("Y", init()) .def("value", &Y::value) .def("set", &Y::set) .def_readwrite("x", &Y::x) diff --git a/test/defaults.cpp b/test/defaults.cpp index 0f552666..41341e72 100644 --- a/test/defaults.cpp +++ b/test/defaults.cpp @@ -158,25 +158,17 @@ BOOST_PYTHON_MODULE_INIT(defaults_ext) .def("barfoo", (object(*)(int, char, std::string, double))0, bar_stubs()) ; - class_("Y", no_init) + class_("Y", init<>("doc of Y init")) // this should work .def("get_state", &Y::get_state) ; class_("X") -# if (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600) - .def(init >()) - .def(init()) -# else - .def_init(args()) - .def_init(args()) - .def_init(args()) - .def_init(args()) - .def_init(args()) -# endif + .def(init >("doc of init")) + .def(init()[default_call_policies()]) // what's a good policy here? .def("get_state", &X::get_state) .def("bar", &X::bar, X_bar_stubs()) - .def("bar2", &X::bar2, X_bar_stubs2(), return_internal_reference<>()) + .def("bar2", &X::bar2, X_bar_stubs2("doc of X::bar2")[return_internal_reference<>()]) .def("foo", (object(X::*)(std::string, bool) const)0, X_foo_2_stubs()) .def("foo", (object(X::*)(int, bool) const)0, X_foo_2_stubs()) .def("foo", (object(X::*)(list, list, bool) const)0, X_foo_3_stubs()) diff --git a/test/defaults.py b/test/defaults.py index aa7602f2..ee7a6588 100644 --- a/test/defaults.py +++ b/test/defaults.py @@ -3,73 +3,115 @@ >>> from defaults_ext import * >>> bar(1) 'int(1); char(D); string(default); double(0.0); ' + >>> bar(2, 'X') 'int(2); char(X); string(default); double(0.0); ' + >>> bar(3, 'Y', "Hello World") 'int(3); char(Y); string(Hello World); double(0.0); ' + >>> bar(4, 'Z', "Hi There", 3.3) 'int(4); char(Z); string(Hi There); double(3.3); ' + >>> foo(1) 'int(1); char(D); string(default); double(0.0); ' + >>> foo(2, 'X') 'int(2); char(X); string(default); double(0.0); ' + >>> foo(3, 'Y', "Hello World") 'int(3); char(Y); string(Hello World); double(0.0); ' + >>> foo(4, 'Z', "Hi There", 3.3) 'int(4); char(Z); string(Hi There); double(3.3); ' + >>> x = X() >>> x.bar(1) 'int(1); char(D); string(default); double(0.0); ' + >>> x.bar(2, 'X') 'int(2); char(X); string(default); double(0.0); ' + >>> x.bar(3, 'Y', "Hello World") 'int(3); char(Y); string(Hello World); double(0.0); ' + >>> x.bar(4, 'Z', "Hi There", 3.3) 'int(4); char(Z); string(Hi There); double(3.3); ' + >>> x.foo(5) 'int(5); bool(0); ' + >>> x.foo(6, 0) 'int(6); bool(0); ' + >>> x.foo(7, 1) 'int(7); bool(1); ' + >>> x.foo("A") 'string(A); bool(0); ' + >>> x.foo("B", False) 'string(B); bool(0); ' + >>> x.foo("C", True) 'string(C); bool(1); ' + >>> x.foo([0,1,2], [2,3,4]) 'list([0, 1, 2]); list([2, 3, 4]); bool(0); ' + >>> x.foo([0,1,2], [2,3,4], False) 'list([0, 1, 2]); list([2, 3, 4]); bool(0); ' + >>> x.foo([0,1,2], [2,3,4], True) 'list([0, 1, 2]); list([2, 3, 4]); bool(1); ' + >>> x = X(1) >>> x.get_state() 'int(1); char(D); string(constructor); double(0.0); ' + >>> x = X(1, 'X') >>> x.get_state() 'int(1); char(X); string(constructor); double(0.0); ' + >>> x = X(1, 'X', "Yabadabadoo") >>> x.get_state() 'int(1); char(X); string(Yabadabadoo); double(0.0); ' + >>> x = X(1, 'X', "Phoenix", 3.65) >>> x.get_state() 'int(1); char(X); string(Phoenix); double(3.65); ' + >>> x.bar2().get_state() 'int(0); char(D); string(default); double(0.0); ' + >>> x.bar2(1).get_state() 'int(1); char(D); string(default); double(0.0); ' + >>> x.bar2(1, 'K').get_state() 'int(1); char(K); string(default); double(0.0); ' + >>> x.bar2(1, 'K', "Kim").get_state() 'int(1); char(K); string(Kim); double(0.0); ' + >>> x.bar2(1, 'K', "Kim", 9.9).get_state() 'int(1); char(K); string(Kim); double(9.9); ' + >>> x = X("Phoenix", 1) >>> x.get_state() 'Got exactly two arguments from constructor: string(Phoenix); bool(1); ' +>>> def printdoc(x): +... print x.__doc__ + +>>> printdoc(X.__init__) +doc of init + +>>> printdoc(Y.__init__) +doc of Y init + +>>> printdoc(X.bar2) +doc of X::bar2 + """ def run(args = None): import sys diff --git a/test/docstring.cpp b/test/docstring.cpp index 01bacfba..417a6635 100644 --- a/test/docstring.cpp +++ b/test/docstring.cpp @@ -36,23 +36,24 @@ BOOST_PYTHON_MODULE_INIT(docstring_ext) "A simple test module for documentation strings\n" "Exercised by docstring.py" ; - + class_("X", "A simple class wrapper around a C++ int\n" "includes some error-checking" - - , args(), - "this is the __init__ function\n" - "its documentation has two lines." + + , init( + "this is the __init__ function\n" + "its documentation has two lines." + ) ) .def("value", &X::value, "gets the value of the object") ; - + def("create", create, return_value_policy(), "creates a new X object"); - + def("fact", fact, "compute the factorial"); } diff --git a/test/extract.cpp b/test/extract.cpp index 17640f2f..749f265a 100644 --- a/test/extract.cpp +++ b/test/extract.cpp @@ -124,7 +124,7 @@ BOOST_PYTHON_MODULE_INIT(extract_ext) ; object x_class( - class_("X", args()) + class_("X", init()) .def( "__repr__", x_rep)); // Instantiate an X object through the Python interface diff --git a/test/implicit.cpp b/test/implicit.cpp index cbf34027..2637f5ca 100644 --- a/test/implicit.cpp +++ b/test/implicit.cpp @@ -27,7 +27,7 @@ BOOST_PYTHON_MODULE_INIT(implicit_ext) def("x_value", x_value); def("make_x", make_x); - class_("X", args()) + class_("X", init()) .def("value", &X::value) .def("set", &X::set) ; diff --git a/test/iterator.cpp b/test/iterator.cpp index 191bf693..02e67546 100644 --- a/test/iterator.cpp +++ b/test/iterator.cpp @@ -94,6 +94,7 @@ BOOST_PYTHON_MODULE_INIT(iterator_ext) , range(&list_range::first, &list_range::second)) ; + // No runtime tests for this one yet class_("list_range2") // We can specify member functions returning a non-const reference diff --git a/test/list.cpp b/test/list.cpp index b3bce4a2..83ea063b 100644 --- a/test/list.cpp +++ b/test/list.cpp @@ -138,7 +138,7 @@ BOOST_PYTHON_MODULE_INIT(list_ext) def("exercise", exercise); - class_("X", args()) + class_("X", init()) .def( "__repr__", x_rep) ; } diff --git a/test/m1.cpp b/test/m1.cpp index f09e4a93..122ad04d 100644 --- a/test/m1.cpp +++ b/test/m1.cpp @@ -171,6 +171,9 @@ struct B : A int x; }; +#if BOOST_MSVC == 1200 +# define C C_ +#endif struct C : A { @@ -259,8 +262,8 @@ BOOST_PYTHON_MODULE_INIT(m1) ; class_("complicated", - args()) - .def_init(args()) + init()) + .def(init()) .def("get_n", &complicated::get_n) ; } diff --git a/test/multi_arg_constructor.cpp b/test/multi_arg_constructor.cpp index 43e8bfb1..24bc4d9a 100644 --- a/test/multi_arg_constructor.cpp +++ b/test/multi_arg_constructor.cpp @@ -17,7 +17,7 @@ BOOST_PYTHON_MODULE_INIT(multi_arg_constructor_ext) class_ >( "A" - , args() + , init() ) ; diff --git a/test/nested.cpp b/test/nested.cpp index 9bc5be32..8cbe3d79 100644 --- a/test/nested.cpp +++ b/test/nested.cpp @@ -34,12 +34,12 @@ BOOST_PYTHON_MODULE_INIT(nested_ext) // Establish X as the current scope. scope x_class( - class_("X", args()) + class_("X", init()) .def(str(self)) ); // Y will now be defined in the current scope - class_("Y", args()) + class_("Y", init()) .def(str(self)) ; } diff --git a/test/operators.cpp b/test/operators.cpp index e21b5509..dc2313df 100755 --- a/test/operators.cpp +++ b/test/operators.cpp @@ -59,7 +59,7 @@ std::ostream& operator<<(std::ostream& s, X const& x) BOOST_PYTHON_MODULE_INIT(operators_ext) { - class_("X", args()) + class_("X", init()) .def("value", &X::value) .def(self - self) .def(self - int()) @@ -77,7 +77,7 @@ BOOST_PYTHON_MODULE_INIT(operators_ext) .def(pow(int(),self)) ; - class_ >("Z", args()) + class_ >("Z", init()) .def(int_(self)) .def(float_(self)) .def(complex_(self)) diff --git a/test/pickle1.cpp b/test/pickle1.cpp index e1397d60..1f9e5139 100644 --- a/test/pickle1.cpp +++ b/test/pickle1.cpp @@ -48,7 +48,7 @@ namespace { BOOST_PYTHON_MODULE_INIT(pickle1_ext) { using namespace boost::python; - class_("world", args()) + class_("world", init()) .def("greet", &world::greet) .def_pickle(world_pickle_suite()) ; diff --git a/test/pickle2.cpp b/test/pickle2.cpp index 984d6380..b8aacbd7 100644 --- a/test/pickle2.cpp +++ b/test/pickle2.cpp @@ -90,7 +90,7 @@ namespace { // Avoid cluttering the global namespace. BOOST_PYTHON_MODULE_INIT(pickle2_ext) { boost::python::class_( - "world", boost::python::args()) + "world", boost::python::init()) .def("greet", &world::greet) .def("get_secret_number", &world::get_secret_number) .def("set_secret_number", &world::set_secret_number) diff --git a/test/pickle3.cpp b/test/pickle3.cpp index 8911b24c..5fae9e6c 100644 --- a/test/pickle3.cpp +++ b/test/pickle3.cpp @@ -98,7 +98,7 @@ namespace { // Avoid cluttering the global namespace. BOOST_PYTHON_MODULE_INIT(pickle3_ext) { boost::python::class_( - "world", boost::python::args()) + "world", boost::python::init()) .def("greet", &world::greet) .def("get_secret_number", &world::get_secret_number) .def("set_secret_number", &world::set_secret_number) diff --git a/test/test_pointer_adoption.cpp b/test/test_pointer_adoption.cpp index b04e3496..90b39ea7 100644 --- a/test/test_pointer_adoption.cpp +++ b/test/test_pointer_adoption.cpp @@ -26,7 +26,7 @@ struct inner { this->s = new_s; } - + std::string s; }; @@ -42,7 +42,7 @@ struct A : Base { ++a_instances; } - + ~A() { --a_instances; @@ -65,7 +65,7 @@ struct B { B() : x(0) {} B(A* x_) : x(x_) {} - + inner const* adopt(A* x) { this->x = x; return &x->get_inner(); } std::string a_content() @@ -96,29 +96,29 @@ BOOST_PYTHON_MODULE_INIT(test_pointer_adoption_ext) def("create", create, return_value_policy()); def("as_A", as_A, return_internal_reference<>()); - + class_("Base") ; - - class_ >(no_init) + + class_ >("A", no_init) .def("content", &A::content) .def("get_inner", &A::get_inner, return_internal_reference<>()) ; - - class_(no_init) + + class_("inner", no_init) .def("change", &inner::change) ; - + class_("B") - .def_init(args(), with_custodian_and_ward_postcall<1,2>()) - + .def(init()[with_custodian_and_ward_postcall<1,2>()]) + .def("adopt", &B::adopt // Adopt returns a pointer referring to a subobject of its 2nd argument (1st being "self") , return_internal_reference<2 // Meanwhile, self holds a reference to the 2nd argument. , with_custodian_and_ward<1,2> >() ) - + .def("a_content", &B::a_content) ; } diff --git a/test/virtual_functions.cpp b/test/virtual_functions.cpp index 73d47dc5..f0bfd787 100644 --- a/test/virtual_functions.cpp +++ b/test/virtual_functions.cpp @@ -89,7 +89,7 @@ int X::counter; BOOST_PYTHON_MODULE_INIT(virtual_functions_ext) { - class_("concrete", args()) + class_("concrete", init()) .def("value", &concrete::value) .def("set", &concrete::set) .def("call_f", &concrete::call_f) @@ -97,14 +97,14 @@ BOOST_PYTHON_MODULE_INIT(virtual_functions_ext) ; class_ - >("abstract", args()) + >("abstract", init()) .def("value", &abstract::value) .def("call_f", &abstract::call_f) .def("set", &abstract::set) ; - class_("Y", args()) + class_("Y", init()) .def("value", &Y::value) .def("set", &Y::set) ;