diff --git a/include/boost/python/object/class_metadata.hpp b/include/boost/python/object/class_metadata.hpp index c29787fb..212abfe4 100755 --- a/include/boost/python/object/class_metadata.hpp +++ b/include/boost/python/object/class_metadata.hpp @@ -30,6 +30,10 @@ # include # include # include + +# include +# include + # include # include @@ -49,6 +53,8 @@ struct register_base_of template inline void operator()(Base*) const { + BOOST_MPL_ASSERT_NOT((is_same)); + // Register the Base class register_dynamic_id(); @@ -58,7 +64,7 @@ struct register_base_of // Register the down-cast, if appropriate. this->register_downcast((Base*)0, is_polymorphic()); } - + private: static inline void register_downcast(void*, mpl::false_) {} @@ -186,7 +192,7 @@ struct class_metadata , mpl::if_< use_value_holder , value_holder - , pointer_holder + , pointer_holder > >::type holder; @@ -253,6 +259,8 @@ struct class_metadata // inline static void maybe_register_callback_class(void*, mpl::false_) {} + inline static void maybe_register_callback_class(wrapped*, mpl::true_) {} + template inline static void maybe_register_callback_class(T2*, mpl::true_) { diff --git a/test/polymorphism2.cpp b/test/polymorphism2.cpp index b5c773e0..8aefbc3a 100755 --- a/test/polymorphism2.cpp +++ b/test/polymorphism2.cpp @@ -13,6 +13,14 @@ #include #include +#include + +#ifdef HELD_BY_AUTO_PTR +# define HELD_PTR(X) , std::auto_ptr< X > +#else +# define HELD_PTR(X) +#endif + using namespace boost::python; struct P @@ -123,19 +131,23 @@ C& getCCppObj () A* pass_a(A* x) { return x; } +#ifdef HELD_BY_AUTO_PTR +BOOST_PYTHON_MODULE_INIT(polymorphism2_auto_ptr_ext) +#else BOOST_PYTHON_MODULE_INIT(polymorphism2_ext) +#endif { - class_("A") + class_("A") .def("f", &A::f, &ACallback::default_f) ; def("getBCppObj", getBCppObj, return_value_policy()); - class_,boost::noncopyable>("C") + class_,boost::noncopyable>("C") .def("f", &C::f) ; - class_,boost::noncopyable>("D") + class_,boost::noncopyable>("D") .def("f", &D::f) .def("g", &D::g) ; @@ -152,7 +164,7 @@ BOOST_PYTHON_MODULE_INIT(polymorphism2_ext) .def("f", pure_virtual(&P::f)) ; - class_ >("Q") + class_ >("Q") .def("g", &P::g) // make sure virtual inheritance doesn't interfere ; } diff --git a/test/polymorphism2.py b/test/polymorphism2.py index 01f6f2f2..2690bac9 100644 --- a/test/polymorphism2.py +++ b/test/polymorphism2.py @@ -2,7 +2,7 @@ # Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) import unittest -from polymorphism2_ext import * +import sys class PolymorphTest(unittest.TestCase): @@ -77,11 +77,18 @@ class PolymorphTest(unittest.TestCase): r = R() self.failUnlessEqual ('R.f', r.f()) - -if __name__ == "__main__": - - # remove the option which upsets unittest + +def test(): + # remove the option that upsets unittest import sys sys.argv = [ x for x in sys.argv if x != '--broken-auto-ptr' ] - unittest.main() + +# This nasty hack basically says that if we're loaded by another module, we'll +# be testing polymorphism2_auto_ptr_ext instead of polymorphism2_ext. +if __name__ == "__main__": + from polymorphism2_ext import * + test() +else: + from polymorphism2_auto_ptr_ext import * +