Skip to content

Commit 834d815

Browse files
committed
mapping suite update
[SVN r19598]
1 parent 57e58c4 commit 834d815

2 files changed

Lines changed: 31 additions & 25 deletions

File tree

include/boost/python/suite/indexing/detail/indexing_suite_detail.hpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace boost { namespace python { namespace detail {
9898
{
9999
BOOST_PYTHON_INDEXING_CHECK_INVARIANT;
100100
// Erase the proxy with index i
101-
replace(i, i, 0);
101+
replace(i, i+1, 0);
102102
BOOST_PYTHON_INDEXING_CHECK_INVARIANT;
103103
}
104104

@@ -109,9 +109,14 @@ namespace boost { namespace python { namespace detail {
109109
// Erase the proxy with index i
110110

111111
iterator iter = first_proxy(i);
112-
if (iter != proxies.end()
113-
&& extract<Proxy&>(*iter)().get_index() == i)
112+
extract<Proxy&> p(*iter);
113+
114+
if (iter != proxies.end() && p().get_index() == i)
115+
{
116+
extract<Proxy&> p(*iter);
117+
p().detach();
114118
proxies.erase(iter);
119+
}
115120
BOOST_PYTHON_INDEXING_CHECK_INVARIANT;
116121
}
117122

@@ -215,6 +220,17 @@ namespace boost { namespace python { namespace detail {
215220
"Invariant: Proxy vector in an inconsistent state");
216221
throw_error_already_set();
217222
}
223+
224+
if (i+1 != proxies.end())
225+
{
226+
if (extract<Proxy&>(*(i+1))().get_index() ==
227+
extract<Proxy&>(*(i))().get_index())
228+
{
229+
PyErr_SetString(PyExc_RuntimeError,
230+
"Invariant: Proxy vector in an inconsistent state (duplicate proxy)");
231+
throw_error_already_set();
232+
}
233+
}
218234
}
219235
}
220236
#endif

include/boost/python/suite/indexing/map_indexing_suite.hpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,32 @@ namespace boost { namespace python {
6464
typedef typename Container::size_type size_type;
6565
typedef typename Container::difference_type difference_type;
6666

67-
// template <class Class>
68-
// static void
69-
// extension_def(Class& cl)
70-
// {
67+
template <class Class>
68+
static void
69+
extension_def(Class& cl)
70+
{
7171
// cl
7272
// .def("append", &base_append)
7373
// .def("extend", &base_extend)
7474
// ;
75-
// }
75+
}
7676

7777
static data_type&
7878
get_item(Container& container, index_type i_)
7979
{
8080
typename Container::iterator i = container.find(i_);
81-
key_check(container, i);
81+
if (i == container.end())
82+
{
83+
PyErr_SetString(PyExc_KeyError, "Invalid key");
84+
throw_error_already_set();
85+
}
8286
return i->second;
8387
}
8488

8589
static void
86-
set_item(Container& container, index_type i_, data_type const& v)
90+
set_item(Container& container, index_type i, data_type const& v)
8791
{
88-
typename Container::iterator i = container.find(i_);
89-
key_check(container, i);
90-
i->second = v;
92+
container[i] = v;
9193
}
9294

9395
static void
@@ -133,18 +135,6 @@ namespace boost { namespace python {
133135
throw_error_already_set();
134136
return index_type();
135137
}
136-
137-
private:
138-
139-
static void
140-
key_check(Container& container, typename Container::iterator i)
141-
{
142-
if (i == container.end())
143-
{
144-
PyErr_SetString(PyExc_KeyError, "Invalid key");
145-
throw_error_already_set();
146-
}
147-
}
148138
};
149139

150140
}} // namespace boost::python

0 commit comments

Comments
 (0)