Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-01-11 14:03:21 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-01-11 14:03:21 +0400
commitc2508b6e1b8f330419762dd0badc3059a8d1f448 (patch)
tree2e53dfff3ce0495c69da7165b714349a78c1e11b /source/blender/python/bmesh/bmesh_py_types_customdata.c
parent3072d817d86ede1b0da265484732545e2c2d78ac (diff)
Fix T38150: correct fix this time
also use fixed size lists for list creation.
Diffstat (limited to 'source/blender/python/bmesh/bmesh_py_types_customdata.c')
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_customdata.c74
1 files changed, 34 insertions, 40 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index dec78123601..dd4b4071a4c 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -439,93 +439,87 @@ static PyObject *bpy_bmlayercollection_keys(BPy_BMLayerCollection *self)
PyObject *item;
int index;
CustomData *data;
+ int tot, i;
BPY_BM_CHECK_OBJ(self);
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_layer_index(data, self->type); /* absolute, but no need to make relative */
+ tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;
- ret = PyList_New(0);
+ ret = PyList_New(tot);
- if (index != -1) {
- int tot = CustomData_number_of_layers(data, self->type);
- for ( ; tot-- > 0; index++) {
- item = PyUnicode_FromString(data->layers[index].name);
- PyList_Append(ret, item);
- Py_DECREF(item);
- }
+ for (i = 0; tot-- > 0; index++) {
+ item = PyUnicode_FromString(data->layers[index].name);
+ PyList_SET_ITEM(ret, i++, item);
}
return ret;
}
-PyDoc_STRVAR(bpy_bmlayercollection_values_doc,
-".. method:: values()\n"
+PyDoc_STRVAR(bpy_bmlayercollection_items_doc,
+".. method:: items()\n"
"\n"
-" Return the values of collection\n"
-" (matching pythons dict.values() functionality).\n"
+" Return the identifiers of collection members\n"
+" (matching pythons dict.items() functionality).\n"
"\n"
-" :return: the members of this collection.\n"
-" :rtype: list\n"
+" :return: (key, value) pairs for each member of this collection.\n"
+" :rtype: list of tuples\n"
);
-static PyObject *bpy_bmlayercollection_values(BPy_BMLayerCollection *self)
+static PyObject *bpy_bmlayercollection_items(BPy_BMLayerCollection *self)
{
PyObject *ret;
PyObject *item;
int index;
CustomData *data;
+ int tot, i;
BPY_BM_CHECK_OBJ(self);
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_layer_index(data, self->type);
+ tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;
- ret = PyList_New(0);
+ ret = PyList_New(tot);
- if (index != -1) {
- int tot = CustomData_number_of_layers(data, self->type);
- for ( ; tot-- > 0; index++) {
- item = PyTuple_New(2);
- PyTuple_SET_ITEM(item, 0, PyUnicode_FromString(data->layers[index].name));
- PyTuple_SET_ITEM(item, 1, BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index));
- PyList_Append(ret, item);
- Py_DECREF(item);
- }
+ for (i = 0; tot-- > 0; index++) {
+ item = PyTuple_New(2);
+ PyTuple_SET_ITEM(item, 0, PyUnicode_FromString(data->layers[index].name));
+ PyTuple_SET_ITEM(item, 1, BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index));
+ PyList_SET_ITEM(ret, i++, item);
}
return ret;
}
-PyDoc_STRVAR(bpy_bmlayercollection_items_doc,
-".. method:: items()\n"
+PyDoc_STRVAR(bpy_bmlayercollection_values_doc,
+".. method:: values()\n"
"\n"
-" Return the identifiers of collection members\n"
-" (matching pythons dict.items() functionality).\n"
+" Return the values of collection\n"
+" (matching pythons dict.values() functionality).\n"
"\n"
-" :return: (key, value) pairs for each member of this collection.\n"
-" :rtype: list of tuples\n"
+" :return: the members of this collection.\n"
+" :rtype: list\n"
);
-static PyObject *bpy_bmlayercollection_items(BPy_BMLayerCollection *self)
+static PyObject *bpy_bmlayercollection_values(BPy_BMLayerCollection *self)
{
PyObject *ret;
PyObject *item;
int index;
CustomData *data;
+ int tot, i;
BPY_BM_CHECK_OBJ(self);
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_layer_index(data, self->type);
+ tot = (index != -1) ? CustomData_number_of_layers(data, self->type) : 0;
- ret = PyList_New(0);
+ ret = PyList_New(tot);
- if (index != -1) {
- int tot = CustomData_number_of_layers(data, self->type);
- for ( ; tot-- > 0; index++) {
- item = BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
- PyList_Append(ret, item);
- Py_DECREF(item);
- }
+ for (i = 0; tot-- > 0; index++) {
+ item = BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
+ PyList_SET_ITEM(ret, i++, item);
}
return ret;