From c592ebf5df4a2be3b70bd3e2f2bba0e3d5908704 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Sat, 16 Nov 2013 22:10:27 +0000 Subject: Freestyle: a follow-up fix of trunk revision 61233. When an iterator has reached the end, any reference of the object pointed by it will now lead to a RuntimeError instead of returning None, with the aim of forcing Python API users to check the end of iteration rather than implicitly indicating the error condition. Acknowledgement to flokkievids for API discussions in the BlenderArtists.org Freestyle for Blender thread. --- .../freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp | 10 ++++++++-- .../freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp | 6 ++++-- .../intern/python/Iterator/BPy_CurvePointIterator.cpp | 6 ++++-- .../intern/python/Iterator/BPy_Interface0DIterator.cpp | 6 ++++-- .../freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp | 4 ++++ .../intern/python/Iterator/BPy_StrokeVertexIterator.cpp | 6 ++++-- .../freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp | 9 ++++++--- .../intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp | 6 ++++-- 8 files changed, 38 insertions(+), 15 deletions(-) (limited to 'source/blender/freestyle/intern/python/Iterator') diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index 0daaa1a0476..292729782ec 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -115,8 +115,10 @@ PyDoc_STRVAR(AdjacencyIterator_object_doc, static PyObject *AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) { - if (self->a_it->isEnd()) - Py_RETURN_NONE; + if (self->a_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } ViewEdge *ve = self->a_it->operator*(); if (ve) return BPy_ViewEdge_from_ViewEdge(*ve); @@ -131,6 +133,10 @@ PyDoc_STRVAR(AdjacencyIterator_is_incoming_doc, static PyObject *AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) { + if (self->a_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } return PyBool_from_bool(self->a_it->isIncoming()); } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp index 91e8de118a9..9a4eb2b7f61 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -175,8 +175,10 @@ PyDoc_STRVAR(ChainingIterator_object_doc, static PyObject *ChainingIterator_object_get(BPy_ChainingIterator *self, void *UNUSED(closure)) { - if (self->c_it->isEnd()) - Py_RETURN_NONE; + if (self->c_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } ViewEdge *ve = self->c_it->operator*(); if (ve) return BPy_ViewEdge_from_ViewEdge(*ve); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp index 1655b766a6b..0329aa99acc 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp @@ -97,8 +97,10 @@ PyDoc_STRVAR(CurvePointIterator_object_doc, static PyObject *CurvePointIterator_object_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) { - if (self->cp_it->isEnd()) - Py_RETURN_NONE; + if (self->cp_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } return BPy_CurvePoint_from_CurvePoint(self->cp_it->operator*()); } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index 2f6c8ff7348..3a246263efa 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -123,8 +123,10 @@ PyDoc_STRVAR(Interface0DIterator_object_doc, static PyObject *Interface0DIterator_object_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) { - if (self->if0D_it->isEnd()) - Py_RETURN_NONE; + if (self->if0D_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } return Any_BPy_Interface0D_from_Interface0D(self->if0D_it->operator*()); } diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp index d493b6c158b..ccf52c64757 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp @@ -115,6 +115,10 @@ PyDoc_STRVAR(SVertexIterator_object_doc, static PyObject *SVertexIterator_object_get(BPy_SVertexIterator *self, void *UNUSED(closure)) { + if (self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } SVertex *sv = self->sv_it->operator->(); if (sv) return BPy_SVertex_from_SVertex(*sv); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index 3174980b7d9..8287e280186 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -109,8 +109,10 @@ PyDoc_STRVAR(StrokeVertexIterator_object_doc, static PyObject *StrokeVertexIterator_object_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) { - if (!self->reversed && self->sv_it->isEnd()) - Py_RETURN_NONE; + if (!self->reversed && self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } StrokeVertex *sv = self->sv_it->operator->(); if (sv) return BPy_StrokeVertex_from_StrokeVertex(*sv); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp index c191a94f08d..87e05a790b4 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp @@ -122,8 +122,10 @@ PyDoc_STRVAR(ViewEdgeIterator_object_doc, static PyObject *ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) { - if (!self->ve_it->isEnd()) - Py_RETURN_NONE; + if (!self->ve_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } ViewEdge *ve = self->ve_it->operator*(); if (ve) return BPy_ViewEdge_from_ViewEdge(*ve); @@ -140,7 +142,8 @@ static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, v ViewEdge *ve = self->ve_it->getCurrentEdge(); if (ve) return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE;} + Py_RETURN_NONE; +} static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) { diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp index cbefcd3292e..12ca3d6cc4a 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp @@ -103,8 +103,10 @@ PyDoc_STRVAR(orientedViewEdgeIterator_object_doc, static PyObject *orientedViewEdgeIterator_object_get(BPy_orientedViewEdgeIterator *self, void *UNUSED(closure)) { - if (self->ove_it->isEnd()) - Py_RETURN_NONE; + if (self->ove_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } return BPy_directedViewEdge_from_directedViewEdge(self->ove_it->operator*()); } -- cgit v1.2.3