Boost logo

Boost :

Subject: [boost] Assertion `slot->m_to_python == 0' failed in when trying to expose custom iterator
From: Yongning Zhu (yongningbrg_at_[hidden])
Date: 2010-06-24 22:32:33


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)
      Klass result = o.Value();
      if (!o.Valid()) {
        PyErr_SetString(PyExc_StopIteration, "No more data.");
      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

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.

Could some one please help me?
Thanks a lot!


Boost list run by bdawes at, gregod at, cpdaniel at, john at