diff --git a/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp b/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp index 538edda9..46a73e05 100644 --- a/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp +++ b/include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp @@ -98,7 +98,7 @@ namespace boost { namespace python { namespace detail { { BOOST_PYTHON_INDEXING_CHECK_INVARIANT; // Erase the proxy with index i - replace(i, i, 0); + replace(i, i+1, 0); BOOST_PYTHON_INDEXING_CHECK_INVARIANT; } @@ -109,9 +109,14 @@ namespace boost { namespace python { namespace detail { // Erase the proxy with index i iterator iter = first_proxy(i); - if (iter != proxies.end() - && extract(*iter)().get_index() == i) + extract p(*iter); + + if (iter != proxies.end() && p().get_index() == i) + { + extract p(*iter); + p().detach(); proxies.erase(iter); + } BOOST_PYTHON_INDEXING_CHECK_INVARIANT; } @@ -215,6 +220,17 @@ namespace boost { namespace python { namespace detail { "Invariant: Proxy vector in an inconsistent state"); throw_error_already_set(); } + + if (i+1 != proxies.end()) + { + if (extract(*(i+1))().get_index() == + extract(*(i))().get_index()) + { + PyErr_SetString(PyExc_RuntimeError, + "Invariant: Proxy vector in an inconsistent state (duplicate proxy)"); + throw_error_already_set(); + } + } } } #endif diff --git a/include/boost/python/suite/indexing/map_indexing_suite.hpp b/include/boost/python/suite/indexing/map_indexing_suite.hpp index d8cb85ec..60347b39 100644 --- a/include/boost/python/suite/indexing/map_indexing_suite.hpp +++ b/include/boost/python/suite/indexing/map_indexing_suite.hpp @@ -64,30 +64,32 @@ namespace boost { namespace python { typedef typename Container::size_type size_type; typedef typename Container::difference_type difference_type; -// template -// static void -// extension_def(Class& cl) -// { + template + static void + extension_def(Class& cl) + { // cl // .def("append", &base_append) // .def("extend", &base_extend) // ; -// } + } static data_type& get_item(Container& container, index_type i_) { typename Container::iterator i = container.find(i_); - key_check(container, i); + if (i == container.end()) + { + PyErr_SetString(PyExc_KeyError, "Invalid key"); + throw_error_already_set(); + } return i->second; } static void - set_item(Container& container, index_type i_, data_type const& v) + set_item(Container& container, index_type i, data_type const& v) { - typename Container::iterator i = container.find(i_); - key_check(container, i); - i->second = v; + container[i] = v; } static void @@ -133,18 +135,6 @@ namespace boost { namespace python { throw_error_already_set(); return index_type(); } - - private: - - static void - key_check(Container& container, typename Container::iterator i) - { - if (i == container.end()) - { - PyErr_SetString(PyExc_KeyError, "Invalid key"); - throw_error_already_set(); - } - } }; }} // namespace boost::python