From 3ae5bd787fb107d98f4071b489ff83861a393e59 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Fri, 17 Jun 2016 22:29:10 +0100 Subject: [PATCH 1/2] Remove extraneous semicolon (-pedantic warning) --- include/pybind11/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 560be4331..daafa7dd9 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -116,7 +116,7 @@ extern "C" { struct _Py_atomic_address { void *value; }; PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current; -}; +} #endif #define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code From daed1abc9c6fb3c43b6c633391316249fb263dad Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Fri, 17 Jun 2016 22:29:39 +0100 Subject: [PATCH 2/2] Switch to using prefix increment in make_iterator --- include/pybind11/pybind11.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 1438e3494..d472531f3 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1028,7 +1028,10 @@ PYBIND11_NOINLINE inline void keep_alive_impl(int Nurse, int Patient, handle arg (void) wr.release(); } -template struct iterator_state { Iterator it, end; }; +template struct iterator_state { + Iterator it, end; + bool first; +}; NAMESPACE_END(detail) @@ -1044,13 +1047,17 @@ iterator make_iterator(Iterator first, Iterator last, Extra &&... extra) { class_(handle(), "") .def("__iter__", [](state &s) -> state& { return s; }) .def("__next__", [](state &s) -> ValueType { + if (!s.first) + ++s.it; + else + s.first = false; if (s.it == s.end) throw stop_iteration(); - return *s.it++; + return *s.it; }, return_value_policy::reference_internal, std::forward(extra)...); } - return (iterator) cast(state { first, last }); + return (iterator) cast(state { first, last, true }); } template iterator make_iterator(Type &value, Extra&&... extra) {