[C++-sig] boost::python::str and Python's str and unicode types

Robert Smallshire Robert.Smallshire at roxar.com
Mon Aug 3 10:27:38 CEST 2009


 

________________________________

From: cplusplus-sig-bounces+robert.smallshire=roxar.com at python.org on behalf of Haoyu Bai
Sent: Sun 8/2/2009 07:45
To: Development of Python/C++ integration
Subject: Re: [C++-sig] boost::python::str and Python's str and unicode types



On Tue, Jul 28, 2009 at 10:11 PM, Robert
Smallshire<Robert.Smallshire at roxar.com> wrote:
>
>> On 07/23/2009 10:17 AM, Robert Smallshire wrote:
>> > Hello,
>> >
>> > I'm looking for some confirmation that my understanding of what
>> > boost.python is doing is correct.
>> >
>> > > From what I understand boost::python::str represents the str
>> > (PyStringObject) type in Python.  Unless I'm missing
>> something, here
>> > doesn't seem to be anything like boost::python::unicode
>> representing
>> > the unicode type (PyUnicodeObject).
>> >
>> > Boost.Python does have a built-in conversion from std::wstring to
>> > object, but this creates a str in Python, so presumably
>> there is some
>> > (lossy?) decoding going on here.
>> >
>> > It seems that to directly create a PyUnicodeObject from C++ I will
>> > need to do one or more of the following:
>> >
>> > 1) Directly use the Python C API to create and manipulate
>> > PyUnicodeObject.
>> > 2) Create my own subclass of boost::python::object called
>> for example
>> > 'unicode', which would be similar to the str class provided
>> out of the
>> > box, but would use PyUnicodeObject underneath and deal with wchar_t
>> > rather than char.
>
> I have modified my local build of boost.python to include a
> boost::python::unicode class, together with appropriate conversions from
> wchar, const wchar_t* and std::wstring, together with additional tests
> in the boost.python test suite.  As you would expect, the code is
> closely derived from the existing boost::python::str code but uses the
> Python C API for PyUnicode_Type rather than PyString_Type. There are no
> breaking changes to the existing boost.python API.
>
> I'd like to contribute these changes back to boost.python so they can be
> hopefully integrated into future official Boost releases.  What is the
> procedure for this?  Where do I start?
>
> Cheers,
>
> Robert Smallshire
>
> DISCLAIMER:
> This message contains information that may be privileged or confidential and is the property of the Roxar Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorised to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>

Hi,

Sorry for the delayed reply because I was busy on some other stuff last week.

Currently the unicode support I implemented for Python 3 contains some
converters for PyUnicode and C++ string types, and a
boost::python::str class that conditionally call PyUnicode API in
Python 3 or PyString API in Python 2. So a boost::python::unicode type
would be very useful for Python 2. And for Python 3, we might need to
rename the new "unicode" class to "str", and the old "str" class to
"bytes", in order to reflect the change of Python.

I'd happy to help to integrate and test it if send your code to the boost trac.

Thank you!

--
Haoyu Bai
School of Computing,
National University of Singapore.
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig 

 

Hi Bayou,

I should be able to get around to adding the boost::python::unicode patches to Trac this week.  I have also added converters to/from std::wstring and const wchar_t*.  Its getting some testing in a commercial development project this week, so hopefully most of the bugs will have been squashed by the time I submit the patches.

Cheers!

Rob

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 7240 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090803/a02bfeb7/attachment.bin>


More information about the Cplusplus-sig mailing list