[C++-sig] Some thoughts on py3k support

Matthew Scouten (TT) Matthew.Scouten at tradingtechnologies.com
Tue Mar 17 21:23:03 CET 2009


A thought on this bytes vs. strings:

I am not sure if others do the same thing, but:

There are a number of places where the underlying library that we are
wrapping has a char* or a char[] that can be either a null terminated
string or an arbitrary bag of bytes depending on context.  The fact that
python uses strings for arbitrary bags of bytes has been convenient for
us in this regard. 

I can work with whatever you come up with, but it might convenient if a
char* or char[] was treated as a bytes object and a std::string was
treated as a string. Thoughts? 

-----Original Message-----
From:
cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org
[mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py
thon.org] On Behalf Of Haoyu Bai
Sent: Tuesday, March 17, 2009 1:08 PM
To: Development of Python/C++ integration
Subject: [C++-sig] Some thoughts on py3k support


However there are something we need to take care of. One of them is,
in Python 3, string is unicode (and the old string class is called
bytes in Python 3). So if we have a C function

char const* hello(); // returns a "Hello"

According to the current behavior of Boost.Python converters, the
wrapped function in Python 3 will return a b"Hello" (which is a bytes
object but not a string). So code like this will broken:

if "Hello" == hello(): ...

Because string object "Hello" is not equal to bytes object b"Hello"
returned by hello(). We may change the behavior of converter to return
a unicode string in Python 3, that would keep most of existing code
compatible. Anyway there will be code really need a single byte string
returned, a new converter can be explicitly specified for this.

There are more issues similar to this. I'll figure out more and write
a detailed proposal as soon as possible.


Best regards,

Haoyu Bai
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


More information about the Cplusplus-sig mailing list