[C++-sig] Py3k unicode to const char* conversion solved (Re: boost::python for Python 3.0)

Stefan Seefeld seefeld at sympatico.ca
Sat Jun 6 17:54:53 CEST 2009


Haoyu Bai wrote:
> Hi,
>
> After attempted all the hacks come from my mind, I solved the unicode
> string to const char* conversion problem by simply calling a Python
> C-API: _PyUnicode_AsString. Since it is start with an underscore, it
> is not a public API and not documented. But I wonder why it is not
> documented, as it's really a useful API. PyUnicode manages a PyBytes
> object as the cached encoded string, and _PyUnicode_AsString will
> return the lvalue inside the encoded string. So we don't need anything
> for lifetime management in our code, this API will keep the same
> semantic as PyString_AsString.
>   

That sounds good. I would suggest to get in touch with python-dev people 
to ask about it (or simply submit an issue at bugs.python.org. They are 
pretty responsive).

> Now most of the test cases are passed. Just some corner things
> remaining, and it seems there is a 2to3 bug caused some doctests
> syntax not fixed. I'm going to take care of these.
>   

Excellent. It seems you are making great progress !

       Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list