[C++-sig] boost::python for Python 3.0

Alcides Viamontes Esquivel a.viamontes.esquivel at gmail.com
Mon Jun 1 14:52:17 CEST 2009


Good to know that you are on it!

I see your point with const char*, not to mention char* (there is a
'rewrap' in test_builtin_converters.py for that too). For PyUnicode
objects, lvalue conversions are not an option. Short of that, the only
remaining solution is to do an rvalue conversion by encoding and
putting the result in a buffer which the user is responsible of
releasing, as in this:

     scoped_array< char > my_chars = extract< const char* >(a_python_object);
     .... do something with it....

The shortcomings of this are:

    * The encoding to use is restricted to one without zeroes (e.g. utf-8)

    * It is easy to leak memory, because legacy code using
boost::python might have
      been instructed in considering my_chars a pointer to an internal
reference. And it
      should    remain that way for Python 2.x. This point breaks the
approach completely.

However, as you pointed out, a solution can be worked using call
policies. I will think on it a little more.

Regards!

On Mon, Jun 1, 2009 at 8:06 AM, Haoyu Bai <divinekid at gmail.com> wrote:
> On Mon, Jun 1, 2009 at 7:41 PM, Alcides Viamontes Esquivel
> <a.viamontes.esquivel at gmail.com> wrote:
>> Dear all:
>>
>> I would like to know if there is any progress on the development of a
>> version of boost::python for Python 3.0, the last activity that I can
>> track on this is back to the first days of April; that includes
>> mailing lists and the boost repository.
>>
>> I played a little with it and last night I succeeded in compiling
>> boost::python for Python 3.0 and in running the first test
>> (test_builtin_converters.py), but of course a lot have still to be
>> done (the const char* and char* issue, among many ones...). I would
>> like to know if there is somebody else working on this.
>>
>> Any suggestions appreciated.
>>
>> Alcides.
>>
>
> Hi Alcides,
>
> Yes I'm working on py3k support as my GSoC project. And as you see,
> the current situation is it can be compiled under Python 3, and have
> some tests  passed.
>
> But now I get stuck on the Python unicode string and const char*
> conversion issue. In Python 2.x, the Python string -> const char*
> conversion can be simply done by a lvalue conversion. But in Python 3,
> the conversion path would be unicode -> (encoding to) bytes -> const
> char*. This requires an rvalue conversion. Bit after reading the code
> in extract.hpp, I found that since char* is a pointer, the conversion
> must be done as a lvalue conversion. This is a short description of
> the problem, please forgive me if it is not clear. :)
>
> So I'm still reading the code about call policies and type converting,
> hopefully I can state the problem clearer and even find out a solution
> when I get more understanding about BPL internal.
>
> Thanks for your interesting! :)
>
> -- Haoyu Bai
>


More information about the Cplusplus-sig mailing list