diff options
Diffstat (limited to 'source')
6 files changed, 33 insertions, 40 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_SShape.cpp b/source/blender/freestyle/intern/python/BPy_SShape.cpp index e5a38171ecd..11ed07df5de 100644 --- a/source/blender/freestyle/intern/python/BPy_SShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_SShape.cpp @@ -227,13 +227,14 @@ PyDoc_STRVAR(SShape_vertices_doc, static PyObject *SShape_vertices_get(BPy_SShape *self, void *UNUSED(closure)) { - PyObject *py_vertices = PyList_New(0); vector< SVertex * > vertices = self->ss->getVertexList(); vector< SVertex * >::iterator it; + PyObject *py_vertices = PyList_New(vertices.size()); + unsigned int i = 0; for (it = vertices.begin(); it != vertices.end(); it++) { - PyList_Append(py_vertices, BPy_SVertex_from_SVertex(*(*it))); + PyList_SET_ITEM(py_vertices, i++, BPy_SVertex_from_SVertex(*(*it))); } return py_vertices; @@ -246,13 +247,14 @@ PyDoc_STRVAR(SShape_edges_doc, static PyObject *SShape_edges_get(BPy_SShape *self, void *UNUSED(closure)) { - PyObject *py_edges = PyList_New(0); vector< FEdge * > edges = self->ss->getEdgeList(); vector< FEdge * >::iterator it; + PyObject *py_edges = PyList_New(edges.size()); + unsigned int i = 0; for (it = edges.begin(); it != edges.end(); it++) { - PyList_Append(py_edges, Any_BPy_FEdge_from_FEdge(*(*it))); + PyList_SET_ITEM(py_edges, i++, Any_BPy_FEdge_from_FEdge(*(*it))); } return py_edges; diff --git a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp index 2c767eacaec..10073204842 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp @@ -207,12 +207,13 @@ PyDoc_STRVAR(ViewShape_vertices_doc, static PyObject *ViewShape_vertices_get(BPy_ViewShape *self, void *UNUSED(closure)) { - PyObject *py_vertices = PyList_New(0); - vector<ViewVertex *> vertices = self->vs->vertices(); vector<ViewVertex *>::iterator it; + PyObject *py_vertices = PyList_New(vertices.size()); + unsigned int i = 0; + for (it = vertices.begin(); it != vertices.end(); it++) { - PyList_Append( py_vertices, Any_BPy_ViewVertex_from_ViewVertex(*(*it))); + PyList_SET_ITEM(py_vertices, i++, Any_BPy_ViewVertex_from_ViewVertex(*(*it))); } return py_vertices; } @@ -248,13 +249,13 @@ PyDoc_STRVAR(ViewShape_edges_doc, static PyObject *ViewShape_edges_get(BPy_ViewShape *self, void *UNUSED(closure)) { - PyObject *py_edges = PyList_New(0); - vector<ViewEdge *> edges = self->vs->edges(); vector<ViewEdge *>::iterator it; + PyObject *py_edges = PyList_New(edges.size()); + unsigned int i = 0; for (it = edges.begin(); it != edges.end(); it++) { - PyList_Append(py_edges, BPy_ViewEdge_from_ViewEdge(*(*it))); + PyList_SET_ITEM(py_edges, i++, BPy_ViewEdge_from_ViewEdge(*(*it))); } return py_edges; } diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp index 6f47ce93ca8..6845bc3ed12 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -342,13 +342,14 @@ PyDoc_STRVAR(SVertex_normals_doc, static PyObject *SVertex_normals_get(BPy_SVertex *self, void *UNUSED(closure)) { PyObject *py_normals; - set< Vec3r > normals; - - py_normals = PyList_New(0); - normals = self->sv->normals(); - for (set< Vec3r >::iterator set_iterator = normals.begin(); set_iterator != normals.end(); set_iterator++) { - Vec3r v(*set_iterator); - PyList_Append(py_normals, Vector_from_Vec3r(v)); + set< Vec3r > normals = self->sv->normals(); + set< Vec3r >::iterator it; + py_normals = PyList_New(normals.size()); + unsigned int i = 0; + + for (it = normals.begin(); it != normals.end(); it++) { + Vec3r v(*it); + PyList_SET_ITEM(py_normals, i++, Vector_from_Vec3r(v)); } return py_normals; } diff --git a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp index c72ab2aba71..2a61dfb075a 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction0D/BPy_UnaryFunction0DVectorViewShape.cpp @@ -112,20 +112,14 @@ static PyObject *UnaryFunction0DVectorViewShape___call__(BPy_UnaryFunction0DVect } return NULL; } - PyObject *list = PyList_New(0); - PyObject *item; - for (unsigned int i = 0; i < self->uf0D_vectorviewshape->result.size(); i++) { + + const unsigned int list_len = self->uf0D_vectorviewshape->result.size(); + PyObject *list = PyList_New(list_len); + for (unsigned int i = 0; i < list_len; i++) { ViewShape *v = self->uf0D_vectorviewshape->result[i]; - if (v) { - item = BPy_ViewShape_from_ViewShape(*v); - } - else { - item = Py_None; - Py_INCREF(item); - } - PyList_Append(list, item); + PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None)); } - + return list; } diff --git a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp index a028952fa69..c15d974e771 100644 --- a/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp +++ b/source/blender/freestyle/intern/python/UnaryFunction1D/BPy_UnaryFunction1DVectorViewShape.cpp @@ -142,18 +142,12 @@ static PyObject *UnaryFunction1DVectorViewShape___call__(BPy_UnaryFunction1DVect } return NULL; } - PyObject *list = PyList_New(0); - PyObject *item; - for (unsigned int i = 0; i < self->uf1D_vectorviewshape->result.size(); i++) { + + const unsigned int list_len = self->uf1D_vectorviewshape->result.size(); + PyObject *list = PyList_New(list_len); + for (unsigned int i = 0; i < list_len; i++) { ViewShape *v = self->uf1D_vectorviewshape->result[i]; - if (v) { - item = BPy_ViewShape_from_ViewShape(*v); - } - else { - item = Py_None; - Py_INCREF(item); - } - PyList_Append(list, item); + PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None)); } return list; diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index cc203880f94..e5d717e0140 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -511,6 +511,7 @@ PyObject *SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBU PyList_SET_ITEM(keypair,0,PyLong_FromLong(i)); PyList_SET_ITEM(keypair,1,PyLong_FromLong(inevent.m_status)); PyList_Append(resultlist,keypair); + Py_DECREF(keypair); } } return resultlist; |