Boost logo

Boost :

Subject: Re: [boost] Assertion `slot->m_to_python == 0' failed in when trying to expose custom iterator
From: Jim Bosch (talljimbo_at_[hidden])
Date: 2010-06-25 18:29:53


On 06/24/2010 07:32 PM, Yongning Zhu wrote:
> Hi,
>
> I am following a tutorial to expose a custom iterator to python,
> The iterator was used in C++ by
> for(T_ITERATOR it();it.Valid();it.Next()){
> T_VALUE v=it.Value();
> }
>
> And I wrote the following wrapper:
>
> template<class Klass, class KlassIter>
> struct iterator_wrappers
> {
> static Klass
> next(KlassIter& o)
> {
> o.Next();
> Klass result = o.Value();
> if (!o.Valid()) {
> PyErr_SetString(PyExc_StopIteration, "No more data.");
> boost::python::throw_error_already_set();
> }
> return result;
> }
>
> static void
> wrap(const char* python_name)
> {
> //using namespace boost::python;
> class_<KlassIter>(python_name, init<>())//no_init
> .def("next", next)
> .def("__iter__", pass_through)
> ;
> }
> };
>
> and expose it by
> iterator_wrappers<T_VALUE,T_ITERATOR>().wrap("t_iterator");
>
> It compiles but when I am importing the module in python, there is an
> error saying:
>
> python: ../../../../libs/python/src/converter/registry.cpp:212: void
> boost::python::converter::registry::insert(PyObject* (*)(const void*),
> boost::python::type_info, const PyTypeObject* (*)()): Assertion
> `slot->m_to_python == 0' failed.
> Aborted
>

Just a guess...is there any chance you might be exposing the same C++
iterator to Python multiple times? Admittedly, I've usually seen that
produce warnings rather than assertion failures, but both cases seem to
be related to Boost.Python not being particularly happy about having
multiple to-python converters for a single C++ type.

By the way, you might have more luck with Boost.Python questions at the
cplusplus-sig_at_[hidden] list.

HTH

Jim Bosch


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk