From e33ce235a877f376e5589a5c6f2ea2e7162d59cf Mon Sep 17 00:00:00 2001 From: Haoyu Bai Date: Fri, 5 Jun 2009 12:19:00 +0000 Subject: [PATCH] implemented a arg_from_python converter that converts py3k unicode to const char*, not an ideal solution, just experimenting. [SVN r53653] --- include/boost/python/arg_from_python.hpp | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/boost/python/arg_from_python.hpp b/include/boost/python/arg_from_python.hpp index 05611edb..5793aac8 100644 --- a/include/boost/python/arg_from_python.hpp +++ b/include/boost/python/arg_from_python.hpp @@ -62,6 +62,35 @@ struct arg_from_python PyObject* m_source; }; +#if PY_VERSION_HEX >= 0x03000000 +// specialization for const char *, experimenting +template <> +struct arg_from_python +{ + typedef const char* result_type; + + arg_from_python(PyObject* p) : m_source(p), intermediate(0) {} + bool convertible() const + { + return PyUnicode_Check(m_source); + } + const char* operator()() + { + const char* result; + intermediate = PyUnicode_AsUTF8String(m_source); + result = PyBytes_AsString(intermediate); + return result; + } + ~arg_from_python() + { + Py_DECREF(intermediate); + } + private: + PyObject* m_source; + PyObject* intermediate; +}; +#endif + // // implementations //