[C++-sig] eposing classes with protected destructors
David Abrahams
dave at boost-consulting.com
Mon Dec 23 17:55:23 CET 2002
David Abrahams <dave at boost-consulting.com> writes:
>>
>> Hope all that's useful...
>
> Nope. Unfortunately it's all irrelevant.
>
>>> Hmm. rvalue_from_python_data<WrappedClass> is used when you wrap a
>>> function taking a WrappedClass or WrappedClass const& argument (and a
>>> few other places, like extract<WrappedClass>). The assumption is that
>>> the converter might need to create a new WrappedClass object, e.g. via
>>> some implicit conversion. I assume that's what's happening here and I
>>> would be very, very surprised if you were able to compile the same
>>> code with Boost 1.29.0.
>>
>> You would be right, there are functions that take a WrappedClass&.
>
> I didn't say WrappedClass&; that case doesn't cause
> rvalue_from_python_data<WrappedClass> to be used.
>
> It's only relevant for WrappedClass const& and WrappedClass arguments.
>
>> In this case, the assumption that a new WrappedClass object may be
>> created is false... at least for my current use case.
>
> Yes, I understand that.
>
>> Get ready to be surprised - this all worked great with a CVS version
>> from a month or two back. I think I last updated in the second half of
>> November. I can't vouch for 1.29.0 though.
>
> Show me a small example, please. I still can't believe it.
FWIW, this small example demonstrates what I think is going on in your
case.
# include <memory>
struct A {
protected:
~A() {}
friend class std::auto_ptr<A>;
};
void f1(A&) {};
void f2(A const&) {};
#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(test_ext)
{
class_<A, std::auto_ptr<A>, boost::noncopyable>("A")
;
def("f1", f1);
def("f2", f2); // comment out this line to silence the error
}
--
David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution
More information about the Cplusplus-sig
mailing list