Opened 10 years ago

Last modified 10 years ago

#7080 new Bugs

make_constructor Does Not Initialize base_wrapper

Reported by: team@… Owned by: Ralf W. Grosse-Kunstleve
Milestone: To Be Determined Component: python USE GITHUB
Version: Boost 1.51.0 Severity: Problem
Keywords: Cc:

Description

When binding a shared_ptr to Python, we're using a custom allocator defined using make_constructor:

class_< Controller, shared_ptr<Controller>, boost::noncopyable >("Controller", no_init)
            .def("__init__", boost::python::make_constructor(&Controller::make));

This works as expected except when classes are derived in Python. In those cases, get_override does not work, since m_self is NULL. If you use init<>() in the class_ constructor, instead of the make_constructor line, it works as expected.

The bug is that make_constructor does not initialize the base_wrapper. I've tried a fix as follows, and it's now functional -- though I can't say if this is a good way to solve it.

+++ make_constructor.hpp
@@ -59,6 +59,7 @@
           void* memory = holder::allocate(this->m_self, offsetof(instance_t, storage), sizeof(holder));
           try {
               (new (memory) holder(x))->install(this->m_self);
+			  python::detail::initialize_wrapper(this->m_self, get_pointer(x));
           }
           catch(...) {
               holder::deallocate(this->m_self, memory);

It's also possible to fix this by partially specializing "template <typename T> struct install_holder;" before boost::python is included.

Change History (4)

comment:1 by dave@…, 10 years ago

Dave, could you comment?

comment:2 by Ralf W. Grosse-Kunstleve, 10 years ago

(Sorry I misunderstood the trac interface; that was rwgk trying to ask Dave to comment.)

comment:3 by Dave Abrahams, 10 years ago

Sorry, I don't have much to add merely on the basis of inspecting the patch. If it passes the usual criteria (comes with a test case that it fixes, doesn't break any other tests), I'd be generally biased towards accepting it.

comment:4 by jonatan@…, 10 years ago

Any progress on this?

Note: See TracTickets for help on using tickets.