Skip to content

Commit 525979a

Browse files
committed
testing for char conversions
[SVN r13735]
1 parent 93a10f3 commit 525979a

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

test/comprehensive.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,10 @@ def assert_integer_expected(err):
12731273
def run(args = None):
12741274
if args is not None:
12751275
sys.argv = args
1276+
1277+
if hasattr(sys,'setdlopenflags'):
1278+
sys.setdlopenflags( 6 ) # dl.RTLD_NOW | dl.RTLD_GLOBAL)
1279+
12761280
import doctest, comprehensive
12771281
return doctest.testmod(comprehensive)
12781282

test/m1.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#include <boost/python/module.hpp>
1111
#include <boost/python/class.hpp>
1212
#include <boost/python/type_from_python.hpp>
13-
#include <boost/python/object/value_holder.hpp>
14-
#include <boost/python/object/pointer_holder.hpp>
15-
#include <boost/python/object/class.hpp>
1613
#include <boost/python/copy_const_reference.hpp>
1714
#include <boost/python/return_value_policy.hpp>
1815
#include <boost/python/to_python_converter.hpp>
@@ -98,9 +95,7 @@ PyObject* new_simple()
9895

9996
//
10097
// Declare some wrappers/unwrappers to test the low-level conversion
101-
// mechanism. See boost/python/converter/source.hpp,target.hpp for a
102-
// description of how the type parameters to wrapper<> and unwrapper<>
103-
// are selected.
98+
// mechanism.
10499
//
105100
using boost::python::to_python_converter;
106101

test/test_builtin_converters.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ struct by_const_reference
2525
}
2626
};
2727

28+
char const* rewrap_value_mutable_cstring(char* x) { return x; }
29+
2830
BOOST_PYTHON_MODULE_INIT(builtin_converters)
2931
{
3032
boost::python::module("builtin_converters")
3133

3234
.def("rewrap_value_bool", by_value<bool>::rewrap)
35+
.def("rewrap_value_char", by_value<char>::rewrap)
3336
.def("rewrap_value_signed_char", by_value<signed char>::rewrap)
3437
.def("rewrap_value_unsigned_char", by_value<unsigned char>::rewrap)
3538
.def("rewrap_value_int", by_value<int>::rewrap)
@@ -47,8 +50,12 @@ BOOST_PYTHON_MODULE_INIT(builtin_converters)
4750
.def("rewrap_value_string", by_value<std::string>::rewrap)
4851
.def("rewrap_value_cstring", by_value<char const*>::rewrap)
4952

53+
// Expose this to illustrate our failings ;-). See test_builtin_converters.py
54+
.def("rewrap_value_mutable_cstring", rewrap_value_mutable_cstring)
55+
5056

5157
.def("rewrap_const_reference_bool", by_const_reference<bool>::rewrap)
58+
.def("rewrap_const_reference_char", by_const_reference<char>::rewrap)
5259
.def("rewrap_const_reference_signed_char", by_const_reference<signed char>::rewrap)
5360
.def("rewrap_const_reference_unsigned_char", by_const_reference<unsigned char>::rewrap)
5461
.def("rewrap_const_reference_int", by_const_reference<int>::rewrap)

test/test_builtin_converters.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
0
77
>>> rewrap_value_bool(33)
88
1
9+
>>> rewrap_value_char('x')
10+
'x'
11+
12+
Note that there's currently silent truncation of strings passed to
13+
char arguments.
14+
15+
>>> rewrap_value_char('xy')
16+
'x'
917
>>> rewrap_value_signed_char(42)
1018
42
1119
>>> rewrap_value_unsigned_char(42)
@@ -42,12 +50,26 @@
4250
>>> rewrap_value_string('yo, wassup?')
4351
'yo, wassup?'
4452
53+
Note that we can currently get a mutable pointer into an immutable
54+
Python string:
55+
56+
>>> rewrap_value_mutable_cstring('hello, world')
57+
'hello, world'
58+
4559
>>> rewrap_const_reference_bool(None)
4660
0
4761
>>> rewrap_const_reference_bool(0)
4862
0
4963
>>> rewrap_const_reference_bool('yes')
5064
1
65+
>>> rewrap_const_reference_char('x')
66+
'x'
67+
68+
Note that there's currently silent truncation of strings passed to
69+
char arguments.
70+
71+
>>> rewrap_const_reference_char('xy')
72+
'x'
5173
>>> rewrap_const_reference_signed_char(42)
5274
42
5375
>>> rewrap_const_reference_unsigned_char(42)

0 commit comments

Comments
 (0)