2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-22 17:32:55 +00:00

This commit was manufactured by cvs2svn to create branch 'mpl_v2'.

[SVN r14323]
This commit is contained in:
nobody
2002-07-07 15:55:19 +00:00
parent 37270cb809
commit 40e6b73721
48 changed files with 6193 additions and 0 deletions

30
test/back_reference.py Normal file
View File

@@ -0,0 +1,30 @@
'''
>>> from back_reference_ext import *
>>> y = Y(3)
>>> z = Z(4)
>>> x_instances()
2
>>> y2 = copy_Y(y)
>>> x_instances()
3
>>> z2 = copy_Z(z)
>>> x_instances()
4
>>> y_identity(y) is y
1
>>> y_equality(y, y)
1
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print "running..."
import sys
sys.exit(run()[0])

34
test/borrowed.cpp Executable file
View File

@@ -0,0 +1,34 @@
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/python/detail/wrap_python.hpp>
#include <boost/python/borrowed.hpp>
#include <boost/static_assert.hpp>
using namespace boost::python;
template <class T>
void assert_borrowed_ptr(T const& x)
{
BOOST_STATIC_ASSERT(boost::python::detail::is_borrowed_ptr<T>::value);
}
template <class T>
void assert_not_borrowed_ptr(T const& x)
{
BOOST_STATIC_ASSERT(!boost::python::detail::is_borrowed_ptr<T>::value);
}
int main()
{
assert_borrowed_ptr(borrowed((PyObject*)0));
assert_borrowed_ptr(borrowed((PyTypeObject*)0));
assert_borrowed_ptr((detail::borrowed<PyObject> const*)0);
assert_borrowed_ptr((detail::borrowed<PyObject> volatile*)0);
assert_borrowed_ptr((detail::borrowed<PyObject> const volatile*)0);
assert_not_borrowed_ptr((PyObject*)0);
assert_not_borrowed_ptr(0);
return 0;
}

133
test/callbacks.py Normal file
View File

@@ -0,0 +1,133 @@
'''
>>> from callbacks_ext import *
>>> def double(x):
... return x + x
...
>>> apply_int_int(double, 42)
84
>>> apply_void_int(double, 42)
>>> def identity(x):
... return x
Once we have array conversion support, this test will fail. Er,
succeed<wink>:
>>> try: apply_to_string_literal(identity)
... except: pass # expected
... else: print 'expected an exception!'
>>> x = apply_X_X(identity, X(42))
>>> x.value()
42
>>> x_count()
1
>>> del x
>>> x_count()
0
>>> def increment(x):
... x.set(x.value() + 1)
...
>>> x = X(42)
>>> apply_void_X_ref(increment, x)
>>> x.value()
43
>>> apply_void_X_cref(increment, x)
>>> x.value() # const-ness is not respected, sorry!
44
>>> last_x = 1
>>> def decrement(x):
... global last_x
... last_x = x
... if x is not None:
... x.set(x.value() - 1)
>>> apply_void_X_ptr(decrement, x)
>>> x.value()
43
>>> last_x.value()
43
>>> increment(last_x)
>>> x.value()
44
>>> last_x.value()
44
>>> apply_void_X_ptr(decrement, None)
>>> assert last_x is None
>>> x.value()
44
>>> last_x = 1
>>> apply_void_X_deep_ptr(decrement, None)
>>> assert last_x is None
>>> x.value()
44
>>> apply_void_X_deep_ptr(decrement, x)
>>> x.value()
44
>>> last_x.value()
43
>>> y = apply_X_ref_handle(identity, x)
>>> assert y.value() == x.value()
>>> increment(x)
>>> assert y.value() == x.value()
>>> y = apply_X_ptr_handle_cref(identity, x)
>>> assert y.value() == x.value()
>>> increment(x)
>>> assert y.value() == x.value()
>>> y = apply_X_ptr_handle_cref(identity, None)
>>> y
>>> def new_x(ignored):
... return X(666)
...
>>> try: apply_X_ref_handle(new_x, 1)
... except ReferenceError: pass
... else: print 'no error'
>>> try: apply_X_ptr_handle_cref(new_x, 1)
... except ReferenceError: pass
... else: print 'no error'
>>> try: apply_cstring_cstring(identity, 'hello')
... except ReferenceError: pass
... else: print 'no error'
>>> apply_char_char(identity, 'x')
'x'
>>> apply_cstring_pyobject(identity, 'hello')
'hello'
>>> apply_cstring_pyobject(identity, None)
>>> apply_char_char(identity, 'x')
'x'
>>> assert apply_to_own_type(identity) is type(identity)
>>> assert apply_object_object(identity, identity) is identity
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print "running..."
import sys
sys.exit(run()[0])

1281
test/comprehensive.py Normal file

File diff suppressed because it is too large Load Diff

1173
test/doctest.py Normal file

File diff suppressed because it is too large Load Diff

45
test/if_else.cpp Normal file
View File

@@ -0,0 +1,45 @@
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/static_assert.hpp>
#include <boost/python/detail/if_else.hpp>
#include <boost/type_traits/same_traits.hpp>
typedef char c1;
typedef char c2[2];
typedef char c3[3];
typedef char c4[4];
template <unsigned size>
struct choose
{
typedef typename boost::python::detail::if_<
(sizeof(c1) == size)
>::template then<
c1
>::template elif<
(sizeof(c2) == size)
>::template then<
c2
>::template elif<
(sizeof(c3) == size)
>::template then<
c3
>::template elif<
(sizeof(c4) == size)
>::template then<
c4
>::template else_<void*>::type type;
};
int main()
{
BOOST_STATIC_ASSERT((boost::is_same<choose<1>::type,c1>::value));
BOOST_STATIC_ASSERT((boost::is_same<choose<2>::type,c2>::value));
BOOST_STATIC_ASSERT((boost::is_same<choose<3>::type,c3>::value));
BOOST_STATIC_ASSERT((boost::is_same<choose<4>::type,c4>::value));
BOOST_STATIC_ASSERT((boost::is_same<choose<5>::type,void*>::value));
return 0;
}

View File

@@ -0,0 +1,80 @@
//#include <stdio.h>
#include <cassert>
#include <boost/python/detail/indirect_traits.hpp>
//#define print(expr) printf("%s ==> %s\n", #expr, expr)
// not all the compilers can handle an incomplete class type here.
struct X {};
int main()
{
using namespace boost::python::detail;
#if 0 // not yet supported
assert(is_reference_to_function<int (&)()>::value);
assert(!is_reference_to_function<int (*)()>::value);
#endif
assert(!is_pointer_to_function<int (&)()>::value);
assert(is_pointer_to_function<int (*)()>::value);
assert(is_reference_to_pointer<int*&>::value);
assert(is_reference_to_pointer<int* const&>::value);
assert(is_reference_to_pointer<int*volatile&>::value);
assert(is_reference_to_pointer<int*const volatile&>::value);
assert(!is_reference_to_pointer<int const volatile>::value);
assert(!is_reference_to_pointer<int>::value);
assert(!is_reference_to_pointer<int*>::value);
assert(!is_reference_to_const<int*&>::value);
assert(is_reference_to_const<int* const&>::value);
assert(!is_reference_to_const<int*volatile&>::value);
assert(is_reference_to_const<int*const volatile&>::value);
assert(!is_reference_to_const<int const volatile>::value);
assert(!is_reference_to_const<int>::value);
assert(!is_reference_to_const<int*>::value);
assert(is_reference_to_non_const<int*&>::value);
assert(!is_reference_to_non_const<int* const&>::value);
assert(is_reference_to_non_const<int*volatile&>::value);
assert(!is_reference_to_non_const<int*const volatile&>::value);
assert(!is_reference_to_non_const<int const volatile>::value);
assert(!is_reference_to_non_const<int>::value);
assert(!is_reference_to_non_const<int*>::value);
assert(!is_reference_to_volatile<int*&>::value);
assert(!is_reference_to_volatile<int* const&>::value);
assert(is_reference_to_volatile<int*volatile&>::value);
assert(is_reference_to_volatile<int*const volatile&>::value);
assert(!is_reference_to_volatile<int const volatile>::value);
assert(!is_reference_to_volatile<int>::value);
assert(!is_reference_to_volatile<int*>::value);
assert(!is_reference_to_class<int>::value);
assert(!is_reference_to_class<int&>::value);
assert(!is_reference_to_class<int*>::value);
assert(!is_reference_to_class<X>::value);
assert(is_reference_to_class<X&>::value);
assert(is_reference_to_class<X const&>::value);
assert(is_reference_to_class<X volatile&>::value);
assert(is_reference_to_class<X const volatile&>::value);
assert(!is_pointer_to_class<int>::value);
assert(!is_pointer_to_class<int*>::value);
assert(!is_pointer_to_class<int&>::value);
assert(!is_pointer_to_class<X>::value);
assert(!is_pointer_to_class<X&>::value);
assert(is_pointer_to_class<X*>::value);
assert(is_pointer_to_class<X const*>::value);
assert(is_pointer_to_class<X volatile*>::value);
assert(is_pointer_to_class<X const volatile*>::value);
return 0;
}

72
test/iterator.py Normal file
View File

@@ -0,0 +1,72 @@
'''
>>> from iterator_ext import *
>>> from input_iterator import *
>>> x = list_int()
>>> x.push_back(1)
>>> x.back()
1
>>> x.push_back(3)
>>> x.push_back(5)
>>> for y in x:
... print y
1
3
5
>>> z = range(x)
>>> for y in z:
... print y
1
3
5
Range2 wraps a transform_iterator which doubles the elements it
traverses. This proves we can wrap input iterators
>>> z2 = range2(x)
>>> for y in z2:
... print y
2
6
10
>>> l2 = two_lists()
>>> for y in l2.primes:
... print y
2
3
5
7
11
13
>>> for y in l2.evens:
... print y
2
4
6
8
10
12
>>> ll = list_list()
>>> ll.push_back(x)
>>> x.push_back(7)
>>> ll.push_back(x)
>>> for a in ll:
... for b in a:
... print b,
... print
...
1 3 5
1 3 5 7
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print "running..."
import sys
sys.exit(run()[0])

2
test/minimal.py Normal file
View File

@@ -0,0 +1,2 @@
import minimal_ext

View File

@@ -0,0 +1,16 @@
'''
>>> from multi_arg_constructor_ext import *
>>> a = A(1.0, 2, 3, 4, 5, 6, 7.0, 8.1, 9.3)
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print "running..."
import sys
sys.exit(run()[0])

126
test/object.py Normal file
View File

@@ -0,0 +1,126 @@
'''
>>> from object_ext import *
>>> def print1(x):
... print x
>>> call_object_3(print1)
3
>>> message()
'hello, world!'
>>> number()
42
>>> test('hi')
1
>>> test(None)
0
>>> test_not('hi')
0
>>> test_not(0)
1
Attributes
>>> class X: pass
...
>>> x = X()
>>> try: obj_getattr(x, 'foo')
... except AttributeError: pass
... else: print 'expected an exception'
>>> obj_setattr(x, 'foo', 1)
>>> x.foo
1
>>> obj_getattr(x, 'foo')
1
>>> obj_const_getattr(x, 'foo')
1
>>> obj_setattr42(x, 'foo')
>>> x.foo
42
>>> obj_moveattr(x, 'foo', 'bar')
>>> x.bar
42
>>> test_attr(x, 'foo')
1
>>> test_not_attr(x, 'foo')
0
>>> x.foo = None
>>> test_attr(x, 'foo')
0
>>> test_not_attr(x, 'foo')
1
Items
>>> d = {}
>>> obj_setitem(d, 'foo', 1)
>>> d['foo']
1
>>> obj_getitem(d, 'foo')
1
>>> obj_const_getitem(d, 'foo')
1
>>> obj_setitem42(d, 'foo')
>>> obj_getitem(d, 'foo')
42
>>> d['foo']
42
>>> obj_moveitem(d, 'foo', 'bar')
>>> d['bar']
42
>>> obj_moveitem2(d, 'bar', d, 'baz')
>>> d['baz']
42
>>> test_item(d, 'foo')
1
>>> test_not_item(d, 'foo')
0
>>> d['foo'] = None
>>> test_item(d, 'foo')
0
>>> test_not_item(d, 'foo')
1
Slices
>>> assert check_string_slice()
Operators
>>> assert check_binary_operators()
>>> class X: pass
...
>>> assert check_inplace(range(3), X())
Now make sure that object is actually managing reference counts
>>> import weakref
>>> class Z: pass
...
>>> z = Z()
>>> def death(r): print 'death'
...
>>> r = weakref.ref(z, death)
>>> z.foo = 1
>>> obj_getattr(z, 'foo')
1
>>> del z
death
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print "running..."
import sys
sys.exit(run()[0])

12
test/object_fail1.cpp Executable file
View File

@@ -0,0 +1,12 @@
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/python/object.hpp>
int f(boost::python::object const& x)
{
x._("hello") = 1;
return 0;
}

86
test/operators.py Normal file
View File

@@ -0,0 +1,86 @@
'''
>>> from operators_ext import *
>>> x = X(42)
>>> x.value()
42
>>> y = x - X(5)
>>> y.value()
37
>>> y = x - 4
>>> y.value()
38
>>> y = 3 - x
>>> y.value()
-39
>>> (-y).value()
39
>>> abs(y).value()
39
>>> x < 10
0
>>> x < 43
1
>>> 10 < x
1
>>> 43 < x
0
>>> x < y
0
>>> y < x
1
------
>>> x > 10
1
>>> x > 43
0
>>> 10 > x
0
>>> 43 > x
1
>>> x > y
1
>>> y > x
0
>>> y = x - 5
>>> x -= y
>>> x.value()
5
>>> str(x)
'5'
>>> z = Z(10)
>>> int(z)
10
>>> float(z)
10.0
>>> complex(z)
(10+0j)
>>> pow(2,x)
32
>>> pow(x,2).value()
25
>>> pow(X(2),x).value()
32
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print "running..."
import sys
sys.exit(run()[0])

35
test/pointee.cpp Normal file
View File

@@ -0,0 +1,35 @@
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/python/pointee.hpp>
#include <boost/type_traits/same_traits.hpp>
#include <memory>
#include <boost/shared_ptr.hpp>
#include <boost/static_assert.hpp>
struct A;
int main()
{
BOOST_STATIC_ASSERT(
(boost::is_same<
boost::python::pointee<std::auto_ptr<char**> >::type
, char**
>::value));
BOOST_STATIC_ASSERT(
(boost::is_same<
boost::python::pointee<boost::shared_ptr<A> >::type
, A>::value));
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
BOOST_STATIC_ASSERT(
(boost::is_same<
boost::python::pointee<char*>::type
, char
>::value));
#endif
return 0;
}

View File

@@ -0,0 +1,39 @@
#include <boost/python/type_id.hpp>
#include <cassert>
#include <boost/python/converter/pointer_type_id.hpp>
int main()
{
using namespace boost::python::converter;
boost::python::type_info x
= boost::python::type_id<int>();
assert(pointer_type_id<int*>() == x);
assert(pointer_type_id<int const*>() == x);
assert(pointer_type_id<int volatile*>() == x);
assert(pointer_type_id<int const volatile*>() == x);
assert(pointer_type_id<int*&>() == x);
assert(pointer_type_id<int const*&>() == x);
assert(pointer_type_id<int volatile*&>() == x);
assert(pointer_type_id<int const volatile*&>() == x);
assert(pointer_type_id<int*const&>() == x);
assert(pointer_type_id<int const*const&>() == x);
assert(pointer_type_id<int volatile*const&>() == x);
assert(pointer_type_id<int const volatile*const&>() == x);
assert(pointer_type_id<int*volatile&>() == x);
assert(pointer_type_id<int const*volatile&>() == x);
assert(pointer_type_id<int volatile*volatile&>() == x);
assert(pointer_type_id<int const volatile*volatile&>() == x);
assert(pointer_type_id<int*const volatile&>() == x);
assert(pointer_type_id<int const*const volatile&>() == x);
assert(pointer_type_id<int volatile*const volatile&>() == x);
assert(pointer_type_id<int const volatile*const volatile&>() == x);
return 0;
}

12
test/raw_pyobject_fail1.cpp Executable file
View File

@@ -0,0 +1,12 @@
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/python/converter/arg_to_python.hpp>
int main()
{
boost::python::converter::arg_to_python<PyTypeObject*> x(0);
return 0;
}

14
test/raw_pyobject_fail2.cpp Executable file
View File

@@ -0,0 +1,14 @@
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/python/converter/arg_to_python.hpp>
struct X : PyObject {};
int main()
{
boost::python::converter::arg_to_python<X*> x(0);
return 0;
}

112
test/result.cpp Executable file
View File

@@ -0,0 +1,112 @@
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/python/detail/result.hpp>
#include <boost/type.hpp>
#include <functional>
using boost::python::detail::result;
using boost::type;
void expect_int(type<int>*) {}
void expect_string(type<char*>*) {}
struct X {};
int main()
{
// Test the usage which works for functions, member functions, and data members
expect_int(
result((int(*)())0)
);
expect_int(
result((int(*)(char))0)
);
expect_int(
result((int(X::*)())0)
);
expect_int(
result((int(X::*)(char))0)
);
expect_int(
result((int(X::*))0)
);
expect_string(
result((char*(*)())0)
);
expect_string(
result((char*(*)(char))0)
);
expect_string(
result((char*(X::*)())0)
);
expect_string(
result((char*(X::*)(char))0)
);
expect_string(
result((char*(X::*))0)
);
// Show that we can use the general version that works for
// AdaptableFunctions
expect_int(
result((int(*)())0,0)
);
expect_int(
result((int(*)(char))0,0)
);
expect_int(
result((int(X::*)())0,0)
);
expect_int(
result((int(X::*)(char))0,0)
);
expect_int(
result((int(X::*))0,0)
);
expect_int(
result(std::plus<int>(),0)
);
expect_string(
result((char*(*)())0,0)
);
expect_string(
result((char*(*)(char))0,0)
);
expect_string(
result((char*(X::*)())0,0)
);
expect_string(
result((char*(X::*)(char))0,0)
);
expect_string(
result((char*(X::*))0,0)
);
expect_string(
result(std::plus<char*>(),0)
);
return 0;
}

View File

@@ -0,0 +1,157 @@
#include <boost/python/converter/arg_from_python.hpp>
#include <boost/python/type_id.hpp>
#include <iostream>
// gcc 2.95.x and MIPSpro 7.3.1.3 linker seem to demand this definition
#if ((defined(__GNUC__) && __GNUC__ < 3)) \
|| (defined(__sgi) && defined(__EDG_VERSION__) && (__EDG_VERSION__ == 238))
namespace boost { namespace python {
BOOST_PYTHON_DECL bool handle_exception_impl(function0<void>)
{
return true;
}
}}
#endif
int result;
#define ASSERT_SAME(T1,T2) \
if (!is_same< T1, T2 >::value) { \
std::cout << "*********************\n"; \
std::cout << python::type_id< T1 >() << " != " << python::type_id< T2 >() << "\n"; \
std::cout << "*********************\n"; \
result = 1; \
}
int main()
{
using namespace boost::python::converter;
using namespace boost;
ASSERT_SAME(
select_arg_from_python<int>::type, arg_rvalue_from_python<int>
);
ASSERT_SAME(
select_arg_from_python<int const>::type, arg_rvalue_from_python<int const>
);
ASSERT_SAME(
select_arg_from_python<int volatile>::type, arg_rvalue_from_python<int volatile>
);
ASSERT_SAME(
select_arg_from_python<int const volatile>::type, arg_rvalue_from_python<int const volatile>
);
ASSERT_SAME(
select_arg_from_python<int*>::type, pointer_arg_from_python<int*>
);
ASSERT_SAME(
select_arg_from_python<int const*>::type, pointer_arg_from_python<int const*>
);
ASSERT_SAME(
select_arg_from_python<int volatile*>::type, pointer_arg_from_python<int volatile*>
);
ASSERT_SAME(
select_arg_from_python<int const volatile*>::type, pointer_arg_from_python<int const volatile*>
);
ASSERT_SAME(
select_arg_from_python<int&>::type, reference_arg_from_python<int&>
);
ASSERT_SAME(
select_arg_from_python<int const&>::type, arg_rvalue_from_python<int const&>
);
ASSERT_SAME(
select_arg_from_python<int volatile&>::type, reference_arg_from_python<int volatile&>
);
ASSERT_SAME(
select_arg_from_python<int const volatile&>::type, reference_arg_from_python<int const volatile&>
);
ASSERT_SAME(
select_arg_from_python<int*&>::type, reference_arg_from_python<int*&>
);
ASSERT_SAME(
select_arg_from_python<int const*&>::type, reference_arg_from_python<int const*&>
);
ASSERT_SAME(
select_arg_from_python<int volatile*&>::type, reference_arg_from_python<int volatile*&>
);
ASSERT_SAME(
select_arg_from_python<int const volatile*&>::type, reference_arg_from_python<int const volatile*&>
);
ASSERT_SAME(
select_arg_from_python<int* const&>::type, pointer_cref_arg_from_python<int*const&>
);
ASSERT_SAME(
select_arg_from_python<int const* const&>::type, pointer_cref_arg_from_python<int const*const&>
);
ASSERT_SAME(
select_arg_from_python<int volatile* const&>::type, pointer_cref_arg_from_python<int volatile*const&>
);
ASSERT_SAME(
select_arg_from_python<int const volatile* const&>::type, pointer_cref_arg_from_python<int const volatile*const&>
);
ASSERT_SAME(
select_arg_from_python<int*volatile&>::type, reference_arg_from_python<int*volatile&>
);
ASSERT_SAME(
select_arg_from_python<int const*volatile&>::type, reference_arg_from_python<int const*volatile&>
);
ASSERT_SAME(
select_arg_from_python<int volatile*volatile&>::type, reference_arg_from_python<int volatile*volatile&>
);
ASSERT_SAME(
select_arg_from_python<int const volatile*volatile&>::type, reference_arg_from_python<int const volatile*volatile&>
);
ASSERT_SAME(
select_arg_from_python<int*const volatile&>::type, reference_arg_from_python<int*const volatile&>
);
ASSERT_SAME(
select_arg_from_python<int const*const volatile&>::type, reference_arg_from_python<int const*const volatile&>
);
ASSERT_SAME(
select_arg_from_python<int volatile*const volatile&>::type, reference_arg_from_python<int volatile*const volatile&>
);
ASSERT_SAME(
select_arg_from_python<int const volatile*const volatile&>::type, reference_arg_from_python<int const volatile*const volatile&>
);
return result;
}

19
test/upcast.cpp Executable file
View File

@@ -0,0 +1,19 @@
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/python/cast.hpp>
struct X { long x; };
struct Y : X, PyObject {};
int main()
{
PyTypeObject o;
Y y;
assert(&boost::python::upcast<PyObject>(&o)->ob_refcnt == &o.ob_refcnt);
assert(&boost::python::upcast<PyObject>(&y)->ob_refcnt == &y.ob_refcnt);
return 0;
}