Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53692 - sandbox-branches/bhy/py3k/libs/python/src/converter
From: divinekid_at_[hidden]
Date: 2009-06-06 10:43:49


Author: bhy
Date: 2009-06-06 10:43:48 EDT (Sat, 06 Jun 2009)
New Revision: 53692
URL: http://svn.boost.org/trac/boost/changeset/53692

Log:
implemented unicode -> const char* lvalue converter for py3k, by using _PyUnicode_AsString() C-API
Text files modified:
   sandbox-branches/bhy/py3k/libs/python/src/converter/builtin_converters.cpp | 10 +++++++---
   1 files changed, 7 insertions(+), 3 deletions(-)

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-06-06 10:43:48 EDT (Sat, 06 Jun 2009)
@@ -40,13 +40,16 @@
 
   // An lvalue conversion function which extracts a char const* from a
   // Python String.
- // 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)
   {
       return PyString_Check(obj) ? PyString_AsString(obj) : 0;
   }
+#else
+ void* convert_to_cstring(PyObject* obj)
+ {
+ return PyUnicode_Check(obj) ? _PyUnicode_AsString(obj) : 0;
+ }
 #endif
 
   // Given a target type and a SlotPolicy describing how to perform a
@@ -537,10 +540,11 @@
 #if PY_VERSION_HEX < 0x03000000
     registry::insert(convert_to_cstring,type_id<char>(),&converter::wrap_pytype<&PyString_Type>::get_pytype);
 #else
+ registry::insert(convert_to_cstring,type_id<char>(),&converter::wrap_pytype<&PyUnicode_Type>::get_pytype);
     //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>();
+ //slot_rvalue_from_python<const char*, char_rvalue_from_python>();
 #endif
 
     // Register by-value converters to std::string, std::wstring


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