1

I get a very similar issue as in: unexpected result iterating over a boost::python vector_indexing_suite

I have the following C++ code:

#include <vector>
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>

using namespace boost::python;

class Composite {

    public:
        std::string name;
        std::vector<Composite*>& getChildren() {
        return children;
    };

    std::vector<Composite*> children;
};

typedef std::vector<Composite*> CompositeArray;

BOOST_PYTHON_MODULE(coin)
{
    class_<CompositeArray>("CompositeArray")
        .def(vector_indexing_suite<CompositeArray, true>());


    class_<Composite>("Composite", "Composite*", init<>())
        .def("getChildren", &Composite::getChildren, return_internal_reference<>())
        .def_readwrite("name", &Composite::name, "str")
    ;
}

And the following Python code:

import coin

gna = coin.Composite()
gna.name = "test"
gna2 = coin.Composite()
gna2.name = "test2"

gna.getChildren().append(gna2)

for slip in gna.getChildren():
      print(slip.name)

produces the error:

Traceback (most recent call last):
  File "gna.py", line 34, in <module>
    for prout in gna.getChildren():
TypeError: No to_python (by-value) converter found for C++ type: class Composite * __ptr64

This was working fine with Boost 1.59, but not anymore with Boost 1.60.

Any idea ?

Edit: I tried by updating (see proposal below) :

    class_<Composite>("Composite", "Composite*", init<>())

to:

    class_<Composite, Composite*>("Composite", "Composite*", init<>())

And I confirm that it is working with boost 1.59 but not boost 1.60.

4
  • Does not work with 1.55 either. Commented Jan 28, 2016 at 8:42
  • When I write "class_<Composite, Composite*>", I don't get any error message neither with boost1.59 nor with boost1.60. I compiled boost with gcc-4.8.4 and python3.4. Maybe, there's something wrong with your installation or with your command of compilation. Can you show us your command ? Commented Jan 29, 2016 at 16:05
  • I am using Visual Studio 2013 and Python 3.3.5. I will try with a newer Python. Are you still interested by the compilation line from VS ? Commented Feb 1, 2016 at 7:50
  • Unfortunately, it is not working either with Python 3.5.1. So it would be a Windows regression only ? Commented Feb 1, 2016 at 9:33

2 Answers 2

1

Changing

class_<Composite>("Composite", "Composite*", init<>())

to

class_<Composite, Composite*>("Composite", "Composite*", init<>())

helped with boost 1.55.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks ! Unfortunately, it is still not working here.
You are probably right, I missed something when building my reproducer. Now I am sure that I have something working with boost 1.59 and not boost 1.60.
0

I could find any "nice" solution for this issue and migrated all my raw pointers to std::shared_ptr to make it work. This issue is discussed here: https://github.com/boostorg/python/issues/29 and here: https://github.com/boostorg/python/issues/56

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.