Commit: c2508b6e1b8f330419762dd0badc3059a8d1f448
Author: Campbell Barton
Date:   Sat Jan 11 21:03:21 2014 +1100
https://developer.blender.org/rBc2508b6e1b8f330419762dd0badc3059a8d1f448

Fix T38150: correct fix this time

also use fixed size lists for list creation.

===================================================================

M       source/blender/python/bmesh/bmesh_py_types_customdata.c

===================================================================

diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c 
b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index dec7812..dd4b407 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;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to