[C++-sig] Protected destructor compile error

Allen Bierbaum abierbaum at gmail.com
Wed Jun 21 23:53:36 CEST 2006


I have run into a compiler error with boost.python and I would like to
understand what is causing it so I can try to fix the problem.  This
is coming up in several places in the binding I am working on, so I am
hopeful if I can understand what is happening with one case I can fix
it everywhere.

Background:

I am wrapping a class, Camera, the method that is causing problems is:

bool Camera::calcViewRay (Line &line, Int32 x, Int32 y, const Viewport &port);

I am wrapping it (using pyplusplus) with this def:

Camera_exposer.def("calcViewRay"
    , &::osg::Camera::calcViewRay
    , ( bp::arg("line"), bp::arg("x"), bp::arg("y"), bp::arg("port") )
    , bp::default_call_policies() );

I get this error when building with boost 1.33.1 on fedora core 4 (gcc 4.0.2):

/home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/detail/destroy.hpp:
In static member function 'static void
boost::python::detail::value_destroyer<false>::execute(const volatile
T*) [with T = osg::Viewport]':
/home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/detail/destroy.hpp:90:
  instantiated from 'void
boost::python::detail::destroy_referent_impl(void*, T& (*)()) [with T
= const osg::Viewport]'
/home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/detail/destroy.hpp:101:
  instantiated from 'void
boost::python::detail::destroy_referent(void*, T (*)()) [with T =
const osg::Viewport&]'
/home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/converter/rvalue_from_python_data.hpp:135:
  instantiated from
'boost::python::converter::rvalue_from_python_data<T>::~rvalue_from_python_data()
[with T = const osg::Viewport&]'
/home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/converter/arg_from_python.hpp:108:
  instantiated from 'PyObject*
boost::python::detail::caller_arity<5u>::impl<F, Policies,
Sig>::operator()(PyObject*, PyObject*) [with F = bool
(osg::Camera::*)(osg::Line&, osg::Int32, osg::Int32, const
osg::Viewport&), Policies = boost::python::default_call_policies, Sig
= boost::mpl::vector6<bool, osg::Camera&, osg::Line&, int, int, const
osg::Viewport&>]'
/home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/object/py_function.hpp:38:
  instantiated from 'PyObject*
boost::python::objects::caller_py_function_impl<Caller>::operator()(PyObject*,
PyObject*) [with Caller = boost::python::detail::caller<bool
(osg::Camera::*)(osg::Line&, osg::Int32, osg::Int32, const
osg::Viewport&), boost::python::default_call_policies,
boost::mpl::vector6<bool, osg::Camera&, osg::Line&, int, int, const
osg::Viewport&> >]'
src/osg_module2/Camera.pypp.cpp:459:   instantiated from here
/home/allenb/Source/OpenSG/Builds/i686-pc-linux-gnu-g++/include/OpenSG/OSGViewport.h:126:
error: 'virtual osg::Viewport::~Viewport()' is protected
/home/allenb/Source/boost/installed/include/boost-1_33_1/boost/python/detail/destroy.hpp:33:
error: within this context

It looks like there is a problem with the "const Viewport& port"
argument being passed.  For some reason the generated code seems to
want to be able to destroy instances of the Viewport class.  This
class has protected constructor and destructor as it is reference
counted and the user can only create them using a helper function
(Camera::create()).

Can anyone describe what is happening here and what prerequisites
exist for this call to work?  Is there some call policy that I should
be using to make this work?

Thanks,
Allen



More information about the Cplusplus-sig mailing list