2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-23 05:42:30 +00:00

merged from trunk

[SVN r31394]
This commit is contained in:
Dave Abrahams
2005-10-19 18:19:23 +00:00
parent 2e8a265abf
commit 8fa75c8fb5
3 changed files with 39 additions and 12 deletions

View File

@@ -30,6 +30,10 @@
# include <boost/mpl/for_each.hpp>
# include <boost/mpl/placeholders.hpp>
# include <boost/mpl/single_view.hpp>
# include <boost/mpl/assert.hpp>
# include <boost/type_traits/is_same.hpp>
# include <boost/type_traits/is_convertible.hpp>
# include <boost/noncopyable.hpp>
@@ -49,6 +53,8 @@ struct register_base_of
template <class Base>
inline void operator()(Base*) const
{
BOOST_MPL_ASSERT_NOT((is_same<Base,Derived>));
// Register the Base class
register_dynamic_id<Base>();
@@ -58,7 +64,7 @@ struct register_base_of
// Register the down-cast, if appropriate.
this->register_downcast((Base*)0, is_polymorphic<Base>());
}
private:
static inline void register_downcast(void*, mpl::false_) {}
@@ -186,7 +192,7 @@ struct class_metadata
, mpl::if_<
use_value_holder
, value_holder<T>
, pointer_holder<held_type,T>
, pointer_holder<held_type,wrapped>
>
>::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 <class T2>
inline static void maybe_register_callback_class(T2*, mpl::true_)
{

View File

@@ -13,6 +13,14 @@
#include <boost/python/call.hpp>
#include <boost/utility.hpp>
#include <memory>
#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_<ACallback,boost::noncopyable>("A")
class_<ACallback HELD_PTR(A),boost::noncopyable>("A")
.def("f", &A::f, &ACallback::default_f)
;
def("getBCppObj", getBCppObj, return_value_policy<reference_existing_object>());
class_<C,bases<A>,boost::noncopyable>("C")
class_<C HELD_PTR(C),bases<A>,boost::noncopyable>("C")
.def("f", &C::f)
;
class_<DCallback,bases<A>,boost::noncopyable>("D")
class_<DCallback HELD_PTR(D),bases<A>,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, bases<P> >("Q")
class_<Q HELD_PTR(Q), bases<P> >("Q")
.def("g", &P::g) // make sure virtual inheritance doesn't interfere
;
}

View File

@@ -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 *