Skip to content

Commit 5a6bc44

Browse files
committed
Peter Bienstman's regression tests and associated fixes.
[SVN r13366]
1 parent 17eb4a2 commit 5a6bc44

6 files changed

Lines changed: 103 additions & 77 deletions

File tree

include/boost/python/converter/from_python_data.hpp

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# include <boost/python/detail/char_array.hpp>
1010
# include <boost/mpl/select_type.hpp>
1111
# include <boost/type_traits/same_traits.hpp>
12-
# include <boost/type_traits/alignment_traits.hpp>
1312
# include <boost/type_traits/transform_traits.hpp>
1413
# include <boost/static_assert.hpp>
1514
# include <boost/python/converter/from_python_stage1_data.hpp>
@@ -24,18 +23,10 @@ namespace boost { namespace python { namespace converter {
2423

2524
namespace detail
2625
{
27-
template <class T> struct referent_alignment;
2826
template <class T> struct referent_size;
2927

3028
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
3129

32-
template <class T>
33-
struct referent_alignment<T&>
34-
{
35-
BOOST_STATIC_CONSTANT(
36-
std::size_t, value = alignment_of<T>::value);
37-
};
38-
3930
template <class T>
4031
struct referent_size<T&>
4132
{
@@ -45,26 +36,6 @@ namespace detail
4536

4637
# else
4738

48-
template <class U>
49-
struct alignment_chars
50-
{
51-
BOOST_STATIC_CONSTANT(
52-
std::size_T, n = alignment_of<U>::value);
53-
char elements[n + 1];
54-
};
55-
56-
template <class T> struct referent_alignment
57-
{
58-
template <class U>
59-
static alignment_chars<U> helper(U&);
60-
61-
static T t;
62-
63-
BOOST_STATIC_CONSTANT(
64-
std::size_t, value = sizeof(helper(t).elements) - 1);
65-
};
66-
67-
6839
template <class T> struct referent_size
6940
{
7041
static T f();
@@ -82,24 +53,12 @@ namespace detail
8253
char, short, int, long, float, double, long double \
8354
, void*, function_ptr, member_ptr, member_function_ptr))
8455

85-
# define BOOST_PYTHON_CHOOSE_LOWER_ALIGNMENT(R,P,I,T) \
86-
typename mpl::select_type< \
87-
alignment_of<T>::value <= target, T, char>::type BOOST_PP_CAT(t,I);
88-
8956
# define BOOST_PYTHON_CHOOSE_LOWER_SIZE(R,P,I,T) \
9057
typename mpl::select_type< \
9158
sizeof(T) <= target, T, char>::type BOOST_PP_CAT(t,I);
9259

9360
# define BOOST_PYTHON_CHOOSE_T(R,P,I,T) T BOOST_PP_CAT(t,I);
9461

95-
template <std::size_t target>
96-
union lower_alignment
97-
{
98-
BOOST_PP_LIST_FOR_EACH_I(
99-
BOOST_PYTHON_CHOOSE_LOWER_ALIGNMENT
100-
, ignored, BOOST_PYTHON_ALIGNMENT_TYPES)
101-
};
102-
10362
template <std::size_t target>
10463
union lower_size
10564
{
@@ -108,13 +67,6 @@ namespace detail
10867
, ignored, BOOST_PYTHON_ALIGNMENT_TYPES)
10968
};
11069

111-
union max_align
112-
{
113-
BOOST_PP_LIST_FOR_EACH_I(
114-
BOOST_PYTHON_CHOOSE_T
115-
, ignored, BOOST_PYTHON_ALIGNMENT_TYPES)
116-
};
117-
11870
template <class Align, std::size_t size>
11971
union aligned_storage
12072
{
@@ -125,35 +77,7 @@ namespace detail
12577
template <class Reference>
12678
struct referent_storage
12779
{
128-
BOOST_STATIC_CONSTANT(std::size_t, target = referent_alignment<Reference>::value);
129-
typedef lower_alignment<target> t1;
130-
131-
BOOST_STATIC_CONSTANT(bool, t1_aligned =
132-
(alignment_of<t1>::value >= target)
133-
& (alignment_of<t1>::value % target == 0));
134-
135-
typedef lower_size<referent_size<Reference>::value> t2;
136-
137-
BOOST_STATIC_CONSTANT(bool, t2_aligned =
138-
(alignment_of<t2>::value >= target)
139-
& (alignment_of<t2>::value % target == 0));
140-
141-
142-
typedef typename mpl::select_type<
143-
t1_aligned
144-
, t1
145-
, typename mpl::select_type<
146-
t2_aligned
147-
, t2
148-
, max_align
149-
>::type
150-
>::type align_t;
151-
152-
BOOST_STATIC_CONSTANT(std::size_t, found = alignment_of<align_t>::value);
153-
154-
BOOST_STATIC_ASSERT(found >= target);
155-
BOOST_STATIC_ASSERT(found % target == 0);
156-
80+
typedef lower_size<referent_size<Reference>::value> align_t;
15781
typedef aligned_storage<align_t,referent_size<Reference>::value> type;
15882
};
15983
}

test/Jamfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ rule bpl-test ( name ? : files * )
5151
boost-python-runtest $(name) : $(py) <pyd>$(modules) ;
5252
}
5353

54+
bpl-test bienstman1 ;
55+
bpl-test bienstman2 ;
5456
bpl-test try : newtest.py m1.cpp m2.cpp ;
5557
bpl-test builtin_converters : test_builtin_converters.py test_builtin_converters.cpp ;
5658
bpl-test test_pointer_adoption ;

test/bienstman1.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <boost/python/module.hpp>
2+
#include <boost/python/class.hpp>
3+
#include <boost/python/reference_existing_object.hpp>
4+
#include <boost/python/return_value_policy.hpp>
5+
6+
struct A {};
7+
8+
struct V
9+
{
10+
11+
virtual void f() = 0;
12+
13+
const A* inside() {return &a;}
14+
15+
A a;
16+
};
17+
18+
const A* outside(const V& v) {return &v.a;}
19+
20+
BOOST_PYTHON_MODULE_INIT(bienstman1_ext)
21+
{
22+
using namespace boost::python;
23+
using boost::shared_ptr;
24+
using boost::python::return_value_policy;
25+
using boost::python::reference_existing_object;
26+
27+
module m("bienstman1_ext");
28+
29+
m
30+
.add(class_<A, shared_ptr<A> >("A"))
31+
32+
.add(
33+
class_<V, boost::noncopyable>("V")
34+
.def("inside", &V::inside,
35+
return_value_policy<reference_existing_object>())
36+
.def("outside", outside,
37+
return_value_policy<reference_existing_object>())
38+
)
39+
;
40+
}
41+

test/bienstman1.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
>>> import bienstman1_ext
3+
'''
4+
def run(args = None):
5+
import sys
6+
import doctest
7+
8+
if args is not None:
9+
sys.argv = args
10+
return doctest.testmod(sys.modules.get(__name__))
11+
12+
if __name__ == '__main__':
13+
print "running..."
14+
import sys
15+
sys.exit(run()[0])

test/bienstman2.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <boost/python/module.hpp>
2+
#include <boost/python/class.hpp>
3+
4+
struct C {};
5+
6+
struct D {};
7+
8+
struct E
9+
{
10+
const D fe (const C&) {return D();}
11+
const D fe2(const C&, const C&) {return D();}
12+
};
13+
14+
BOOST_PYTHON_MODULE_INIT(m)
15+
{
16+
using namespace boost::python;
17+
18+
module m("m");
19+
20+
m
21+
.add(class_<C>("C"))
22+
.add(class_<D>("D"))
23+
.add(
24+
class_<E>("E")
25+
.def("fe", &E::fe) // this compiles.
26+
.def("fe2", &E::fe2) // this doesn't.
27+
)
28+
;
29+
}

test/bienstman2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
>>> import bienstman1_ext.py
3+
'''
4+
def run(args = None):
5+
import sys
6+
import doctest
7+
8+
if args is not None:
9+
sys.argv = args
10+
return doctest.testmod(sys.modules.get(__name__))
11+
12+
if __name__ == '__main__':
13+
print "running..."
14+
import sys
15+
sys.exit(run()[0])

0 commit comments

Comments
 (0)