diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-13 19:00:14 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-13 19:00:14 +0300 |
commit | 665648a40b873c637ba0092bb4147de2b0ff1c00 (patch) | |
tree | 718dacb1a92b1801329c0012c0b30ffaeef06159 /source/blender/python | |
parent | e2054b291c35cfd9b4e020b584ec465007ecd189 (diff) |
bugfix [#25578] assigning to multi-dimensional arrays fails
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_rna_array.c | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/source/blender/python/intern/bpy_rna_array.c b/source/blender/python/intern/bpy_rna_array.c index ab13f9928c2..f3b3615793b 100644 --- a/source/blender/python/intern/bpy_rna_array.c +++ b/source/blender/python/intern/bpy_rna_array.c @@ -206,6 +206,23 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop, return validate_array_length(rvalue, ptr, prop, lvalue_dim, totitem, error_prefix); } +static char *copy_value_single(PyObject *item, PointerRNA *ptr, PropertyRNA *prop, char *data, unsigned int item_size, int *index, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index) +{ + if (!data) { + char value[sizeof(int)]; + + convert_item(item, value); + rna_set_index(ptr, prop, *index, value); + *index = *index + 1; + } + else { + convert_item(item, data); + data += item_size; + } + + return data; +} + static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int dim, char *data, unsigned int item_size, int *index, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index) { unsigned int i; @@ -218,19 +235,9 @@ static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int data= copy_values(item, ptr, prop, dim + 1, data, item_size, index, convert_item, rna_set_index); } else { - if (!data) { - char value[sizeof(int)]; - - convert_item(item, value); - rna_set_index(ptr, prop, *index, value); - *index = *index + 1; - } - else { - convert_item(item, data); - data += item_size; - } + data= copy_value_single(item, ptr, prop, data, item_size, index, convert_item, rna_set_index); } - + Py_DECREF(item); } @@ -302,12 +309,18 @@ static int py_to_array_index(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, i index += arrayoffset; - if (!validate_array(py, ptr, prop, lvalue_dim, check_item_type, item_type_str, &totitem, error_prefix)) - return 0; - - if (totitem) - copy_values(py, ptr, prop, lvalue_dim, NULL, 0, &index, convert_item, rna_set_index); + if(lvalue_dim == totdim) { /* single item, assign directly */ + copy_value_single(py, ptr, prop, NULL, 0, &index, convert_item, rna_set_index); + } + else { + if (!validate_array(py, ptr, prop, lvalue_dim, check_item_type, item_type_str, &totitem, error_prefix)) { + return 0; + } + if (totitem) { + copy_values(py, ptr, prop, lvalue_dim, NULL, 0, &index, convert_item, rna_set_index); + } + } return 1; } |