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>2010-08-31 15:31:21 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-08-31 15:31:21 +0400
commitdfb8c5974e6f937c3404d0dd59f0e6424de455db (patch)
tree736b1fce3378f7fdea6559a3dcda90f7fe368bfc /source/blender/python
parent9a290b39c73d915d800860fa0d52ec7f036ec89e (diff)
rna support for passing dynamic sized arrays to rna functions
using this for object.vertex_groups.assign([index list ...], group, weight, mode)
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_array.c33
-rw-r--r--source/blender/python/intern/bpy_rna.c10
-rw-r--r--source/blender/python/intern/bpy_rna.h1
3 files changed, 24 insertions, 20 deletions
diff --git a/source/blender/python/intern/bpy_array.c b/source/blender/python/intern/bpy_array.c
index 9ceba4ae004..ec5cc2e8809 100644
--- a/source/blender/python/intern/bpy_array.c
+++ b/source/blender/python/intern/bpy_array.c
@@ -24,6 +24,7 @@
#include "bpy_rna.h"
#include "BKE_global.h"
+#include "MEM_guardedalloc.h"
#define MAX_ARRAY_DIMENSION 10
@@ -144,8 +145,9 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA
return 0;
}
#else
- PyErr_Format(PyExc_ValueError, "%s %s.%s: array length cannot be changed to %d", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot);
- return 0;
+ *totitem= tot;
+ return 1;
+
#endif
}
@@ -248,22 +250,25 @@ static int py_to_array(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, Paramet
}
if (totitem) {
- if (!param_data || RNA_property_flag(prop) & PROP_DYNAMIC)
- data= PyMem_MALLOC(item_size * totitem);
- else
+ /* note: this code is confusing */
+ if(param_data && RNA_property_flag(prop) & PROP_DYNAMIC) {
+ /* not freeing allocated mem, RNA_parameter_list_free() will do this */
+ ParameterDynAlloc *param_alloc= (ParameterDynAlloc *)param_data;
+ param_alloc->array_tot= (int)totitem;
+ param_alloc->array= MEM_callocN(item_size * totitem, "py_to_array dyn"); /* freeing param list will free */
+
+ data= param_alloc->array;
+ }
+ else if (param_data) {
data= param_data;
+ }
+ else {
+ data= PyMem_MALLOC(item_size * totitem);
+ }
copy_values(py, ptr, prop, 0, data, item_size, NULL, convert_item, NULL);
- if (param_data) {
- if (RNA_property_flag(prop) & PROP_DYNAMIC) {
- /* not freeing allocated mem, RNA_parameter_list_free will do this */
- *(char**)param_data= data;
-
- RNA_parameter_length_set_data(parms, prop, param_data, totitem);
- }
- }
- else {
+ if (param_data==NULL) {
/* NULL can only pass through in case RNA property arraylength is 0 (impossible?) */
rna_set_array(ptr, prop, data);
PyMem_FREE(data);
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 5cb6dfca0b2..6133a1da616 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -55,7 +55,7 @@
#include "../generic/mathutils.h" /* so we can have mathutils callbacks */
#include "../generic/IDProp.h" /* for IDprop lookups */
-
+static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, void *data, PyObject *value, const char *error_prefix);
static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyRNA *self, PointerRNA *ptr, PropertyRNA *prop, int start, int stop, int length);
static Py_ssize_t pyrna_prop_array_length(BPy_PropertyRNA *self);
static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self);
@@ -972,7 +972,7 @@ static PyObject *pyrna_func_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func)
-int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, void *data, PyObject *value, const char *error_prefix)
+static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, void *data, PyObject *value, const char *error_prefix)
{
/* XXX hard limits should be checked here */
int type = RNA_property_type(prop);
@@ -3412,9 +3412,9 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, ParameterList *parms, PropertyRNA *
int len;
if (flag & PROP_DYNAMIC) {
- len= RNA_parameter_length_get_data(parms, prop, data);
-
- data= *((void **)data);
+ ParameterDynAlloc *data_alloc= data;
+ len= data_alloc->array_tot;
+ data= data_alloc->array;
}
else
len= RNA_property_array_length(ptr, prop);
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index 63f6997d82c..514784d5a4c 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -77,7 +77,6 @@ PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr );
PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop );
/* operators also need this to set args */
-int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, void *data, PyObject *value, const char *error_prefix);
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix);
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);