diff options
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types_customdata.c | 28 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 24 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_geometry.c | 2 |
3 files changed, 35 insertions, 19 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c index 91104fb23f5..6a02d8e4a25 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c @@ -63,7 +63,15 @@ static CustomData *bpy_bm_customdata_get(BMesh *bm, char htype) static CustomDataLayer *bpy_bmlayeritem_get(BPy_BMLayerItem *self) { CustomData *data = bpy_bm_customdata_get(self->bm, self->htype); - return &data->layers[CustomData_get_layer_index_n(data, self->type, self->index)]; + const int index_absolute = CustomData_get_layer_index_n(data, self->type, self->index); + if (index_absolute != -1) { + return &data->layers[index_absolute]; + } + else { + PyErr_SetString(PyExc_RuntimeError, + "layer has become invalid"); + return NULL; + } } /* py-type definitions @@ -126,9 +134,10 @@ static PyObject *bpy_bmlayercollection_active_get(BPy_BMLayerItem *self, void *U BPY_BM_CHECK_OBJ(self); data = bpy_bm_customdata_get(self->bm, self->htype); - index = CustomData_get_active_layer_index(data, self->type); + index = CustomData_get_active_layer_index(data, self->type); /* absolute */ if (index != -1) { + index -= CustomData_get_layer_index(data, self->type); /* make relative */ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index); } else { @@ -146,7 +155,12 @@ static PyObject *bpy_bmlayeritem_name_get(BPy_BMLayerItem *self, void *UNUSED(fl BPY_BM_CHECK_OBJ(self); layer = bpy_bmlayeritem_get(self); - return PyUnicode_FromString(layer->name); + if (layer) { + return PyUnicode_FromString(layer->name); + } + else { + return NULL; + } } static PyGetSetDef bpy_bmlayeraccess_vert_getseters[] = { @@ -311,7 +325,7 @@ static PyObject *bpy_bmlayercollection_keys(BPy_BMLayerCollection *self) BPY_BM_CHECK_OBJ(self); data = bpy_bm_customdata_get(self->bm, self->htype); - index = CustomData_get_layer_index(data, self->type); + index = CustomData_get_layer_index(data, self->type); /* absolute, but no need to make relative */ ret = PyList_New(0); @@ -426,9 +440,10 @@ static PyObject *bpy_bmlayercollection_get(BPy_BMLayerCollection *self, PyObject int index; data = bpy_bm_customdata_get(self->bm, self->htype); - index = CustomData_get_named_layer_index(data, self->type, key); + index = CustomData_get_named_layer_index(data, self->type, key); /* absolute index */ if (index != -1) { + index -= CustomData_get_layer_index(data, self->type); /* make relative */ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index); } } @@ -471,9 +486,10 @@ static PyObject *bpy_bmlayercollection_subscript_str(BPy_BMLayerCollection *self BPY_BM_CHECK_OBJ(self); data = bpy_bm_customdata_get(self->bm, self->htype); - index = CustomData_get_named_layer_index(data, self->type, keyname); + index = CustomData_get_named_layer_index(data, self->type, keyname); /* absolute */ if (index != -1) { + index -= CustomData_get_layer_index(data, self->type); /* make relative */ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index); } else { diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 7259ea8e2f5..7c8f28d0979 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1424,7 +1424,7 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha totkw = kw ? PyDict_Size(kw) : 0; - RNA_STRUCT_BEGIN(ptr, prop) { + RNA_STRUCT_BEGIN (ptr, prop) { arg_name = RNA_property_identifier(prop); if (strcmp(arg_name, "rna_type") == 0) continue; @@ -2203,7 +2203,7 @@ int pyrna_prop_collection_subscript_str_lib_pair_ptr(BPy_PropertyRNA *self, PyOb /* lib is either a valid poniter or NULL, * either way can do direct comparison with id.lib */ - RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { ID *id = itemptr.data; /* always an ID */ if (id->lib == lib && (strncmp(keyname, id->name + 2, sizeof(id->name) - 2) == 0)) { found = TRUE; @@ -3346,7 +3346,7 @@ static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr) RNA_pointer_create(NULL, &RNA_Struct, ptr->type, &tptr); iterprop = RNA_struct_find_property(&tptr, "functions"); - RNA_PROP_BEGIN(&tptr, itemptr, iterprop) { + RNA_PROP_BEGIN (&tptr, itemptr, iterprop) { idname = RNA_function_identifier(itemptr.data); pystring = PyUnicode_FromString(idname); @@ -3365,7 +3365,7 @@ static void pyrna_dir_members_rna(PyObject *list, PointerRNA *ptr) iterprop = RNA_struct_iterator_property(ptr->type); - RNA_PROP_BEGIN(ptr, itemptr, iterprop) { + RNA_PROP_BEGIN (ptr, itemptr, iterprop) { nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { @@ -3980,7 +3980,7 @@ static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self) char name[256], *nameptr; int namelen; - RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { @@ -4017,7 +4017,7 @@ static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self) int namelen; int i = 0; - RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { if (itemptr.data) { /* add to python list */ item = PyTuple_New(2); @@ -4189,7 +4189,7 @@ static PyObject *pyrna_prop_collection_find(BPy_PropertyRNA *self, PyObject *key PYRNA_PROP_CHECK_OBJ(self); - RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen); if (nameptr) { @@ -4220,7 +4220,7 @@ static void foreach_attr_type(BPy_PropertyRNA *self, const char *attr, *attr_signed = FALSE; /* note: this is fail with zero length lists, so don't let this get caled in that case */ - RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { prop = RNA_struct_find_property(&itemptr, attr); *raw_type = RNA_property_raw_type(prop); *attr_tot = RNA_property_array_length(&itemptr, prop); @@ -6401,7 +6401,7 @@ static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self) PyObject *ret = PyList_New(0); PyObject *item; - RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) { + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { StructRNA *srna = itemptr.data; StructRNA *srna_base = RNA_struct_base(itemptr.data); /* skip own operators, these double up [#29666] */ @@ -7189,7 +7189,7 @@ void pyrna_alloc_types(void) RNA_blender_rna_pointer_create(&ptr); prop = RNA_struct_find_property(&ptr, "structs"); - RNA_PROP_BEGIN(&ptr, itemptr, prop) { + RNA_PROP_BEGIN (&ptr, itemptr, prop) { PyObject *item = pyrna_struct_Subtype(&itemptr); if (item == NULL) { if (PyErr_Occurred()) { @@ -7217,7 +7217,7 @@ void pyrna_free_types(void) prop = RNA_struct_find_property(&ptr, "structs"); - RNA_PROP_BEGIN(&ptr, itemptr, prop) { + RNA_PROP_BEGIN (&ptr, itemptr, prop) { StructRNA *srna = srna_from_ptr(&itemptr); void *py_ptr = RNA_struct_py_type_get(srna); @@ -7477,7 +7477,7 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla /* loop over all structs */ - RNA_PROP_BEGIN(&ptr_rna, itemptr, prop_rna) { + RNA_PROP_BEGIN (&ptr_rna, itemptr, prop_rna) { srna_iter = itemptr.data; if (pyrna_srna_contains_pointer_prop_srna(srna_iter, srna, &prop_identifier)) { break; diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index b94c2e21139..543574e5136 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -1011,7 +1011,7 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject coord_array = MEM_callocN(dims * (resolu) * sizeof(float), "interpolate_bezier"); for (i = 0; i < dims; i++) { - forward_diff_bezier(k1[i], h1[i], h2[i], k2[i], coord_array + i, resolu - 1, sizeof(float) * dims); + BKE_curve_forward_diff_bezier(k1[i], h1[i], h2[i], k2[i], coord_array + i, resolu - 1, sizeof(float) * dims); } list = PyList_New(resolu); |