[C++-sig] Difference between old and new Boost.Python interface.

Roman Yakovenko roman.yakovenko at gmail.com
Tue Sep 26 22:14:59 CEST 2006


Good evening. I think I found a bug.
I expose a class that defines operator+. If I use old Boost.Python interface
for wrapper construction all works as expected. If I use new interface, then
I can not invoke it.

Please consider next code:

namespace bp = boost::python;

struct vector_new{
    vector_new(){}
    vector_new operator+( const vector_new& x ) const;
    static const vector_new v_new;
};

struct vector_old{
    vector_old(){}
    vector_old operator+( const vector_old& x ) const;
    static const vector_old v_old;
};

struct vector_new_wrapper : vector_new, bp::wrapper< vector_new > {
    vector_new_wrapper()
    : vector_new(), bp::wrapper< vector_new >()
    {}

    vector_new_wrapper(vector_new const & arg )
    : vector_new(), bp::wrapper< vector_new >()
    {}
};

struct vector_old_wrapper : vector_old, bp::wrapper< vector_old > {
    vector_old_wrapper(PyObject* )
    : vector_old(), bp::wrapper< vector_old >()
    {}

    vector_old_wrapper(PyObject*, vector_old const & arg )
    : vector_old(), bp::wrapper< vector_old >()
    {}
};

BOOST_PYTHON_MODULE( operators_ext ){
    bp::class_< vector_new_wrapper >( "vector_new" )
        .def( bp::self + bp::self )
        .def_readonly( "v_new", vector_new::v_new);

    bp::class_< vector_old, vector_old_wrapper >( "vector_old" )
        .def( bp::self + bp::self )
        .def_readonly( "v_old", vector_old::v_old );
}


I can invoke operator+ for vector_old class, but I can not invoke operator+ for
vector_new class:

import operators_ext
old = operators_ext.vector_old()
tmp = old + operators_ext.vector_old.v_old #this will work

new = operators_ext.vector_new()
tmp = new + operators_ext.vector_new.v_new
#Previous line will raise  TypeError:
#TypeError: unsupported operand type(s) for +: 'vector_new' and 'vector_new'

I attached minimal test case that reproduce the problem to the mail.

Thank you.

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: operators_ext.cpp
Type: text/x-c++src
Size: 1403 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060926/23e0a9fe/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 386 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060926/23e0a9fe/attachment.py>


More information about the Cplusplus-sig mailing list