Hi Matthias. I spent some time investigating your problem.
// testlib.h
struct Vector
{
double x;
static const Vector one;
Vector(double ax) : x(ax) {}
Vector operator+(const Vector& other) { return Vector(x+other.x); }
virtual void trigger_wrapper() {}
};
// testlib.cpp
#include "testlib.h"
const Vector Vector::one = Vector(1);
As I suspected there is a bug in Boost.Python library.
I asked Py++ to generate wrapper using old Boost.Python interface:
struct vector_wrapper : operators_bug::vector, bp::wrapper<
operators_bug::vector > {
vector_wrapper(PyObject*, operators_bug::vector const & arg )
: operators_bug::vector( arg )
, bp::wrapper< operators_bug::vector >(){
// copy constructor
}
vector_wrapper(PyObject*, double ax )
: operators_bug::vector( ax )
, bp::wrapper< operators_bug::vector >()
{ // Normal constructor
}
virtual void trigger_wrapper( ) {
if( bp::override func_trigger_wrapper = this->get_override(
"trigger_wrapper" ) )
func_trigger_wrapper( );
else
operators_bug::vector::trigger_wrapper( );
}
void default_trigger_wrapper( ) {
operators_bug::vector::trigger_wrapper( );
}
};
And vector registration:
bp::class_< operators_bug::vector, vector_wrapper >( "vector",
"documentation", bp::init< double >(( bp::arg("ax") ), "documentation") )
.def( bp::self + bp::self )
.def(
"trigger_wrapper"
, &::operators_bug::vector::trigger_wrapper
, &vector_wrapper::default_trigger_wrapper )
.def_readonly( "one", operators_bug::vector::one, "documentation"
)
.def_readwrite( "x", &operators_bug::vector::x, "documentation" );
The test code you posted v = Vector(3)+Vector.one now works as expected.
It could be nice if you can post the description of the bug to
boost.pythonmailing
list. I suppose it will be not too difficult to solve it.
In file operators_bug_tester.py you will find work around to your problem.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|