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

testing for char conversions

[SVN r13735]
This commit is contained in:
Dave Abrahams
2002-05-07 23:23:32 +00:00
parent 93a10f33d5
commit 525979afaa
4 changed files with 34 additions and 6 deletions

View File

@@ -1273,6 +1273,10 @@ import sys
def run(args = None):
if args is not None:
sys.argv = args
if hasattr(sys,'setdlopenflags'):
sys.setdlopenflags( 6 ) # dl.RTLD_NOW | dl.RTLD_GLOBAL)
import doctest, comprehensive
return doctest.testmod(comprehensive)

View File

@@ -10,9 +10,6 @@
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/python/type_from_python.hpp>
#include <boost/python/object/value_holder.hpp>
#include <boost/python/object/pointer_holder.hpp>
#include <boost/python/object/class.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <boost/python/return_value_policy.hpp>
#include <boost/python/to_python_converter.hpp>
@@ -98,9 +95,7 @@ PyObject* new_simple()
//
// Declare some wrappers/unwrappers to test the low-level conversion
// mechanism. See boost/python/converter/source.hpp,target.hpp for a
// description of how the type parameters to wrapper<> and unwrapper<>
// are selected.
// mechanism.
//
using boost::python::to_python_converter;

View File

@@ -25,11 +25,14 @@ struct by_const_reference
}
};
char const* rewrap_value_mutable_cstring(char* x) { return x; }
BOOST_PYTHON_MODULE_INIT(builtin_converters)
{
boost::python::module("builtin_converters")
.def("rewrap_value_bool", by_value<bool>::rewrap)
.def("rewrap_value_char", by_value<char>::rewrap)
.def("rewrap_value_signed_char", by_value<signed char>::rewrap)
.def("rewrap_value_unsigned_char", by_value<unsigned char>::rewrap)
.def("rewrap_value_int", by_value<int>::rewrap)
@@ -47,8 +50,12 @@ BOOST_PYTHON_MODULE_INIT(builtin_converters)
.def("rewrap_value_string", by_value<std::string>::rewrap)
.def("rewrap_value_cstring", by_value<char const*>::rewrap)
// Expose this to illustrate our failings ;-). See test_builtin_converters.py
.def("rewrap_value_mutable_cstring", rewrap_value_mutable_cstring)
.def("rewrap_const_reference_bool", by_const_reference<bool>::rewrap)
.def("rewrap_const_reference_char", by_const_reference<char>::rewrap)
.def("rewrap_const_reference_signed_char", by_const_reference<signed char>::rewrap)
.def("rewrap_const_reference_unsigned_char", by_const_reference<unsigned char>::rewrap)
.def("rewrap_const_reference_int", by_const_reference<int>::rewrap)

View File

@@ -6,6 +6,14 @@
0
>>> rewrap_value_bool(33)
1
>>> rewrap_value_char('x')
'x'
Note that there's currently silent truncation of strings passed to
char arguments.
>>> rewrap_value_char('xy')
'x'
>>> rewrap_value_signed_char(42)
42
>>> rewrap_value_unsigned_char(42)
@@ -42,12 +50,26 @@
>>> rewrap_value_string('yo, wassup?')
'yo, wassup?'
Note that we can currently get a mutable pointer into an immutable
Python string:
>>> rewrap_value_mutable_cstring('hello, world')
'hello, world'
>>> rewrap_const_reference_bool(None)
0
>>> rewrap_const_reference_bool(0)
0
>>> rewrap_const_reference_bool('yes')
1
>>> rewrap_const_reference_char('x')
'x'
Note that there's currently silent truncation of strings passed to
char arguments.
>>> rewrap_const_reference_char('xy')
'x'
>>> rewrap_const_reference_signed_char(42)
42
>>> rewrap_const_reference_unsigned_char(42)