Skip to content

Commit 43bcbf7

Browse files
committed
added more-rigorous tests
[SVN r12866]
1 parent 7f42036 commit 43bcbf7

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

test/m1.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <boost/python/copy_const_reference.hpp>
1616
#include <boost/python/return_value_policy.hpp>
1717
#include <boost/python/converter/class.hpp>
18-
#include <boost/python/reference_from_python.hpp>
18+
#include <boost/python/lvalue_from_python.hpp>
1919
#include <boost/python/to_python_converter.hpp>
2020
#include <boost/python/value_from_python.hpp>
2121
#include <boost/python/errors.hpp>
@@ -141,6 +141,26 @@ int f(simple const& s)
141141
return strlen(s.s);
142142
}
143143

144+
int f_mutable_ref(simple& s)
145+
{
146+
return strlen(s.s);
147+
}
148+
149+
int f_mutable_ptr(simple* s)
150+
{
151+
return strlen(s->s);
152+
}
153+
154+
int f_const_ptr(simple const* s)
155+
{
156+
return strlen(s->s);
157+
}
158+
159+
int f2(SimpleObject const& s)
160+
{
161+
return strlen(s.x.s);
162+
}
163+
144164
// A trivial passthru function for simple objects
145165
simple const& g(simple const& x)
146166
{
@@ -188,7 +208,7 @@ BOOST_PYTHON_MODULE_INIT(m1)
188208
using boost::python::module;
189209
using boost::python::class_;
190210
using boost::python::converter::from_python_converter;
191-
using boost::python::reference_from_python;
211+
using boost::python::lvalue_from_python;
192212
using boost::python::value_from_python;
193213
using boost::python::type_from_python;
194214
using boost::python::get_member;
@@ -205,14 +225,21 @@ BOOST_PYTHON_MODULE_INIT(m1)
205225
static from_python_converter<int&> c3(
206226
&(boost::python::type_from_python<&NoddyType>::convertible), noddy_to_int_ref);
207227

208-
static boost::python::reference_from_python<
228+
static boost::python::lvalue_from_python<
209229
&SimpleType
210230
, simple
211231
, SimpleObject
232+
#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
233+
, boost::python::get_member<SimpleObject, simple, &SimpleObject::x>
234+
#else
212235
, extract_simple_object
236+
#endif
213237
>
214238
unwrap_simple;
215239

240+
static boost::python::lvalue_from_python<&SimpleType, SimpleObject>
241+
unwrap_simple2;
242+
216243
module m1("m1");
217244

218245
typedef boost::python::objects::pointer_holder_generator<
@@ -229,9 +256,14 @@ BOOST_PYTHON_MODULE_INIT(m1)
229256
.def("new_noddy", new_noddy)
230257
.def("new_simple", new_simple)
231258

232-
// Expose f()
259+
// Expose f() in all its variations
233260
.def("f", f)
261+
.def("f_mutable_ref", f_mutable_ref)
262+
.def("f_mutable_ptr", f_mutable_ptr)
263+
.def("f_const_ptr", f_const_ptr)
234264

265+
.def("f2", f2)
266+
235267
// Expose g()
236268
.def("g", g , return_value_policy<copy_const_reference>()
237269
)

test/newtest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@
5757
>>> f(g(s))
5858
12
5959
60+
>>> f_mutable_ref(g(s))
61+
12
62+
63+
>>> f_const_ptr(g(s))
64+
12
65+
66+
>>> f_mutable_ptr(g(s))
67+
12
68+
69+
>>> f2(g(s))
70+
12
71+
6072
Create an extension class which wraps "complicated" (init1 and get_n)
6173
are a complicated constructor and member function, respectively.
6274

0 commit comments

Comments
 (0)