|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53315 - in sandbox-branches/bhy/py3k: boost/python/converter libs/python/src/converter
From: divinekid_at_[hidden]
Date: 2009-05-27 14:16:13
Author: bhy
Date: 2009-05-27 14:16:13 EDT (Wed, 27 May 2009)
New Revision: 53315
URL: http://svn.boost.org/trac/boost/changeset/53315
Log:
more minor fixes to get test cases passed
Text files modified:
sandbox-branches/bhy/py3k/boost/python/converter/builtin_converters.hpp | 2 +-
sandbox-branches/bhy/py3k/libs/python/src/converter/builtin_converters.cpp | 27 ++++++++++++++++++++++++++-
2 files changed, 27 insertions(+), 2 deletions(-)
Modified: sandbox-branches/bhy/py3k/boost/python/converter/builtin_converters.hpp
==============================================================================
--- sandbox-branches/bhy/py3k/boost/python/converter/builtin_converters.hpp (original)
+++ sandbox-branches/bhy/py3k/boost/python/converter/builtin_converters.hpp 2009-05-27 14:16:13 EDT (Wed, 27 May 2009)
@@ -136,7 +136,7 @@
#if PY_VERSION_HEX >= 0x03000000
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x), &PyUnicode_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x), &PyUnicode_Type)
-BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, ::PyBytes_FromStringAndSize(x.data(),implicit_cast<ssize_t>(x.size())), &PyUnicode_Type)
+BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, ::PyUnicode_FromStringAndSize(x.data(),implicit_cast<ssize_t>(x.size())), &PyUnicode_Type)
#else
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x), &PyString_Type)
BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x), &PyString_Type)
Modified: sandbox-branches/bhy/py3k/libs/python/src/converter/builtin_converters.cpp
==============================================================================
--- sandbox-branches/bhy/py3k/libs/python/src/converter/builtin_converters.cpp (original)
+++ sandbox-branches/bhy/py3k/libs/python/src/converter/builtin_converters.cpp 2009-05-27 14:16:13 EDT (Wed, 27 May 2009)
@@ -40,7 +40,8 @@
// An lvalue conversion function which extracts a char const* from a
// Python String.
- // Cannot have this lvalue conversion in Python 3.
+ // Cannot have this lvalue conversion in Python 3, instead, we have
+ // char_rvalue_from_python.
#if PY_VERSION_HEX < 0x03000000
void* convert_to_cstring(PyObject* obj)
{
@@ -366,6 +367,24 @@
#endif
};
+#if PY_VERSION_HEX >= 0x03000000
+ // A SlotPolicy for extracting C char* string from Python 3 unicode string.
+ struct char_rvalue_from_python
+ {
+ static unaryfunc* get_slot(PyObject *obj)
+ {
+ printf("*********CALLED*************\n");
+ return PyUnicode_Check(obj) ? &py_unicode_as_string_unaryfunc : 0;
+ }
+
+ static const char* extract(PyObject* intermediate)
+ {
+ return PyBytes_AsString(intermediate);
+ }
+ static PyTypeObject const* get_pytype() { return &PyUnicode_Type;}
+ };
+#endif
+
#if defined(Py_USING_UNICODE) && !defined(BOOST_NO_STD_WSTRING)
// encode_string_unaryfunc/py_encode_string -- manufacture a unaryfunc
// "slot" which encodes a Python string using the default encoding
@@ -517,6 +536,11 @@
// Add an lvalue converter for char which gets us char const*
#if PY_VERSION_HEX < 0x03000000
registry::insert(convert_to_cstring,type_id<char>(),&converter::wrap_pytype<&PyString_Type>::get_pytype);
+#else
+ //TODO(bhy) This doesn't work because for const char* a lvalue converter is
+ // always expected. (See select_extract in extract.hpp for detail)
+ // So we should figure out a workaround.
+ slot_rvalue_from_python<const char*, char_rvalue_from_python>();
#endif
// Register by-value converters to std::string, std::wstring
@@ -524,6 +548,7 @@
slot_rvalue_from_python<std::wstring, wstring_rvalue_from_python>();
# endif
slot_rvalue_from_python<std::string, string_rvalue_from_python>();
+
}
}}} // namespace boost::python::converter
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk