Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53653 - sandbox-branches/bhy/py3k/boost/python
From: divinekid_at_[hidden]
Date: 2009-06-05 08:19:01


Author: bhy
Date: 2009-06-05 08:19:00 EDT (Fri, 05 Jun 2009)
New Revision: 53653
URL: http://svn.boost.org/trac/boost/changeset/53653

Log:
implemented a arg_from_python converter that converts py3k unicode to const char*, not an ideal solution, just experimenting.
Text files modified:
   sandbox-branches/bhy/py3k/boost/python/arg_from_python.hpp | 29 +++++++++++++++++++++++++++++
   1 files changed, 29 insertions(+), 0 deletions(-)

Modified: sandbox-branches/bhy/py3k/boost/python/arg_from_python.hpp
==============================================================================
--- sandbox-branches/bhy/py3k/boost/python/arg_from_python.hpp (original)
+++ sandbox-branches/bhy/py3k/boost/python/arg_from_python.hpp 2009-06-05 08:19:00 EDT (Fri, 05 Jun 2009)
@@ -62,6 +62,35 @@
     PyObject* m_source;
 };
 
+#if PY_VERSION_HEX >= 0x03000000
+// specialization for const char *, experimenting
+template <>
+struct arg_from_python<const char*>
+{
+ 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
 //


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