diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-09-23 06:12:33 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-09-23 06:12:33 +0400 |
commit | 2b9a73ff9831aed988bde26ca1fce474ace01cf6 (patch) | |
tree | 84d5655dd61c632e61df874f95229f9945ceab4d /source/blender/python/intern | |
parent | db47803de42a5b1ae4e6cd381fa5908b33f96721 (diff) |
- py/rna's path_resolve function was ignoring the index eg: obj.path_resolve("location[1]")
- corrected comment from previous commit
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r-- | source/blender/python/intern/bpy_array.c | 6 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 20 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.h | 1 |
3 files changed, 20 insertions, 7 deletions
diff --git a/source/blender/python/intern/bpy_array.c b/source/blender/python/intern/bpy_array.c index 1afd54b3607..6d971d8708e 100644 --- a/source/blender/python/intern/bpy_array.c +++ b/source/blender/python/intern/bpy_array.c @@ -400,7 +400,7 @@ int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, in return ret; } -static PyObject *pyrna_array_item(PointerRNA *ptr, PropertyRNA *prop, int index) +PyObject *pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index) { PyObject *item; @@ -441,7 +441,7 @@ static PyObject *pyrna_py_from_array_internal(PointerRNA *ptr, PropertyRNA *prop if (dim + 1 < totdim) item= pyrna_py_from_array_internal(ptr, prop, dim + 1, index); else { - item= pyrna_array_item(ptr, prop, *index); + item= pyrna_array_index(ptr, prop, *index); *index= *index + 1; } @@ -496,7 +496,7 @@ PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, } else { index = arrayoffset + index; - ret= (BPy_PropertyArrayRNA *)pyrna_array_item(ptr, prop, index); + ret= (BPy_PropertyArrayRNA *)pyrna_array_index(ptr, prop, index); } return (PyObject*)ret; diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index d2234963927..418bece5e7b 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -2262,17 +2262,29 @@ static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args) PyObject *coerce= Py_True; PointerRNA r_ptr; PropertyRNA *r_prop; + int index= -1; if (!PyArg_ParseTuple(args, "s|O!:path_resolve", &path, &PyBool_Type, &coerce)) return NULL; - if (RNA_path_resolve(&self->ptr, path, &r_ptr, &r_prop)) { + if (RNA_path_resolve_full(&self->ptr, path, &r_ptr, &r_prop, &index)) { if(r_prop) { - if(coerce == Py_False) { - return pyrna_prop_CreatePyObject(&r_ptr, r_prop); + if(index != -1) { + if(index >= RNA_property_array_length(&r_ptr, r_prop) || index < 0) { + PyErr_Format(PyExc_TypeError, "%.200s.path_resolve(\"%.200s\") index out of range", RNA_struct_identifier(self->ptr.type), path); + return NULL; + } + else { + return pyrna_array_index(&r_ptr, r_prop, index); + } } else { - return pyrna_prop_to_py(&r_ptr, r_prop); + if(coerce == Py_False) { + return pyrna_prop_CreatePyObject(&r_ptr, r_prop); + } + else { + return pyrna_prop_to_py(&r_ptr, r_prop); + } } } else { diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index 4b8beb42930..7f750f94242 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -101,6 +101,7 @@ void pyrna_free_types(void); /* primitive type conversion */ int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, char *param_data, PyObject *py, const char *error_prefix); int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, int arrayoffset, int index, PyObject *py, const char *error_prefix); +PyObject *pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index); PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop); PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index); |