You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to iterate over python iterable, in c++, iterates past the end with bound c++ types. It seems that comparing the end iterator to the sentinel attempts to advance the end iterator past the end. When iterating a python type calling PyIter_Next past the end simply returns NULL however for a bound STL container this invokes undefined behaviour.
Occurs on:
Windows 10 (VS 2017), Ubuntu 17.04 (gcc 7.0)
pybind11 2.1.1 and master ( 0365d49 )
Example
cpp:
#include<pybind11/pybind11.h>
#include<pybind11/stl_bind.h>namespacepy= pybind11;
PYBIND11_MAKE_OPAQUE(std::vector<int>)
PYBIND11_MODULE(IterableTest, m)
{
py::bind_vector<std::vector<int>>(m, "VectorInt");
m.def("iter_test", [] (py::iterable iterable)
{
auto iter = py::iter(iterable);
while (iter != py::iterator::sentinel())
{
py::print("got value: ", *iter);
++iter;
}
});
}
Fixespybind#896.
From Python docs: Once an iterator’s `__next__()` method raises
`StopIteration`, it must continue to do so on subsequent calls.
Implementations that do not obey this property are deemed broken.
Fixespybind#896.
From Python docs: "Once an iterator’s `__next__()` method raises
`StopIteration`, it must continue to do so on subsequent calls.
Implementations that do not obey this property are deemed broken."
Fixes#896.
From Python docs: "Once an iterator’s `__next__()` method raises
`StopIteration`, it must continue to do so on subsequent calls.
Implementations that do not obey this property are deemed broken."
Issue
Attempting to iterate over python iterable, in c++, iterates past the end with bound c++ types. It seems that comparing the end iterator to the sentinel attempts to advance the end iterator past the end. When iterating a python type calling PyIter_Next past the end simply returns NULL however for a bound STL container this invokes undefined behaviour.
Occurs on:
Windows 10 (VS 2017), Ubuntu 17.04 (gcc 7.0)
pybind11 2.1.1 and master ( 0365d49 )
Example
cpp:
python:
example output:
The text was updated successfully, but these errors were encountered: