[C++-sig] problem with iterator and non-destructible container
James Pelletier
jamesp at trdlnk.com
Thu Aug 10 17:14:12 CEST 2006
I'm having trouble wrapping a container object that has a private
destructor. As far as I can tell, the object has all of the necessary
data to be used with the boost::python::iterator object, but when I try
to compile I get an error message saying that the container's destructor
is private. Why would the iterator want to destroy my container? Am I
missing something?
I'm using gcc-3.4 on solaris 10 on intel and boost-1.32. I couldn't
find any differences in header files between boost 1.32 and 1.33 in this
area.
I've whittled it down to a small example below that gives me the same
error message.
The code compiles cleanly if I take out the .def("__iter__"...) line.
-------
#include <vector>
#include <boost/python.hpp>
using namespace boost::python;
class Y
{
Y() {}
~Y() {}
Y( Y const & );
Y & operator=( Y const & );
std::vector<int> v_;
public:
typedef std::vector<int>::const_iterator const_iterator;
const_iterator begin() const { return v_.begin(); }
const_iterator end() const { return v_.end(); }
};
BOOST_PYTHON_MODULE(boostpy)
{
class_<Y, boost::noncopyable>("Y", no_init)
.def( "__iter__", iterator<Y const>() )
;
}
------
test.C: In static member function `static void
boost::python::detail::value_destroyer< false>::execute(const volatile
T*) [with T = Y]':
/opt/app/g++lib6/boost-1.32/include/boost-1_32/boost/python/detail/destroy.hpp:90:
instantiated from `void
boost::python::detail::destroy_referent_impl(void*, T&(*)()) [with T =
const Y]'
/opt/app/g++lib6/boost-1.32/include/boost-1_32/boost/python/detail/destroy.hpp:101:
instantiated from `void
boost::python::detail::destroy_referent(void*, T (*)()) [with T = const Y&]'
/opt/app/g++lib6/boost-1.32/include/boost-1_32/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 Y&]'
/opt/app/g++lib6/boost-1.32/include/boost-1_32/boost/preprocessor/iteration/detail/local.hpp:34:
instantiated from `PyObject*
boost::python::detail::caller_arity<1u>::impl<F, Policies,
Sig>::operator()(PyObject*, PyObject*) [with F =
boost::python::objects::detail::py_iter_<const Y,
__gnu_cxx::__normal_iterator<const int*, std::vector<int,
std::allocator<int> > >,
boost::_bi::protected_bind_t<boost::_bi::bind_t<__gnu_cxx::__normal_iterator<const
int*, std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<const int*, std::vector<int,
std::allocator<int> > > (*)(const Y&), boost::_bi::list1<boost::arg<1> >
> >,
boost::_bi::protected_bind_t<boost::_bi::bind_t<__gnu_cxx::__normal_iterator<const
int*, std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<const int*, std::vector<int,
std::allocator<int> > > (*)(const Y&), boost::_bi::list1<boost::arg<1> >
> >, boost::python::return_value_policy<boost::python::return_by_value,
boost::python::default_call_policies> >, Policies =
boost::python::default_call_policies, Sig =
boost::mpl::vector2<boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value,
boost::python::default_call_policies>,
__gnu_cxx::__normal_iterator<const int*, std::vector<int,
std::allocator<int> > > >, boost::python::back_reference<const Y&> >]'
/opt/app/g++lib6/boost-1.32/include/boost-1_32/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<boost::python::objects::detail::py_iter_<const
Y, __gnu_cxx::__normal_iterator<const int*, std::vector<int,
std::allocator<int> > >,
boost::_bi::protected_bind_t<boost::_bi::bind_t<__gnu_cxx::__normal_iterator<const
int*, std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<const int*, std::vector<int,
std::allocator<int> > > (*)(const Y&), boost::_bi::list1<boost::arg<1> >
> >,
boost::_bi::protected_bind_t<boost::_bi::bind_t<__gnu_cxx::__normal_iterator<const
int*, std::vector<int, std::allocator<int> > >,
__gnu_cxx::__normal_iterator<const int*, std::vector<int,
std::allocator<int> > > (*)(const Y&), boost::_bi::list1<boost::arg<1> >
> >, boost::python::return_value_policy<boost::python::return_by_value,
boost::python::default_call_policies> >,
boost::python::default_call_policies,
boost::mpl::vector2<boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value,
boost::python::default_call_policies>,
__gnu_cxx::__normal_iterator<const int*, std::vector<int,
std::allocator<int> > > >, boost::python::back_reference<const Y&> > >]'
test.C:37: instantiated from here
test.C:10: error: `Y::~Y()' is private
/opt/app/g++lib6/boost-1.32/include/boost-1_32/boost/python/detail/destroy.hpp:33:
error: within this context
More information about the Cplusplus-sig
mailing list