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.
This commit is contained in:
Tamito Kajiyama 2013-11-16 22:10:27 +00:00
parent c239baa0ba
commit c592ebf5df
8 changed files with 38 additions and 15 deletions

View File

@ -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());
}

View File

@ -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);

View File

@ -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*());
}

View File

@ -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*());
}

View File

@ -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);

View File

@ -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);

View File

@ -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))
{

View File

@ -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*());
}