[Bf-blender-cvs] [120292a1909] blender-v2.83-release: Fix slicing with negative indices
Campbell Barton
noreply at git.blender.org
Mon Aug 16 10:02:39 CEST 2021
Commit: 120292a1909f0a6962da9cc4c22cfeedb980c7cc
Author: Campbell Barton
Date: Thu Aug 5 16:44:03 2021 +1000
Branches: blender-v2.83-release
https://developer.blender.org/rB120292a1909f0a6962da9cc4c22cfeedb980c7cc
Fix slicing with negative indices
Negative indices that remained negative after adding the sequence length
caused incorrect slicing.
With the default scene for example:
bpy.context.scene.objects[-4:2]
Gave a different result to:
tuple(bpy.context.scene.objects)[-4:2]
Clamp indices above zero so loops that step forward works as intended.
===================================================================
M source/blender/python/bmesh/bmesh_py_types.c
M source/blender/python/bmesh/bmesh_py_types_customdata.c
M source/blender/python/bmesh/bmesh_py_types_select.c
M source/blender/python/intern/bpy_rna.c
===================================================================
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index fccdfe7fbdc..cb3941c621c 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -3290,9 +3290,11 @@ static PyObject *bpy_bmelemseq_subscript(BPy_BMElemSeq *self, PyObject *key)
Py_ssize_t len = bpy_bmelemseq_length(self);
if (start < 0) {
start += len;
+ CLAMP_MIN(start, 0);
}
if (stop < 0) {
stop += len;
+ CLAMP_MIN(stop, 0);
}
}
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index ffddfb4a7e1..a8504f4b4c0 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -786,9 +786,11 @@ static PyObject *bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, Py
Py_ssize_t len = bpy_bmlayercollection_length(self);
if (start < 0) {
start += len;
+ CLAMP_MIN(start, 0);
}
if (stop < 0) {
stop += len;
+ CLAMP_MIN(stop, 0);
}
}
diff --git a/source/blender/python/bmesh/bmesh_py_types_select.c b/source/blender/python/bmesh/bmesh_py_types_select.c
index 5e064453a04..c41459f1f1e 100644
--- a/source/blender/python/bmesh/bmesh_py_types_select.c
+++ b/source/blender/python/bmesh/bmesh_py_types_select.c
@@ -284,9 +284,11 @@ static PyObject *bpy_bmeditselseq_subscript(BPy_BMEditSelSeq *self, PyObject *ke
Py_ssize_t len = bpy_bmeditselseq_length(self);
if (start < 0) {
start += len;
+ CLAMP_MIN(start, 0);
}
if (stop < 0) {
stop += len;
+ CLAMP_MIN(stop, 0);
}
}
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index c570e3f8d7a..0c0d4e91ca5 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -2745,9 +2745,11 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject
Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop);
if (start < 0) {
start += len;
+ CLAMP_MIN(start, 0);
}
if (stop < 0) {
stop += len;
+ CLAMP_MIN(stop, 0);
}
}
@@ -2880,9 +2882,11 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self,
Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop);
if (start < 0) {
start += len;
+ CLAMP_MIN(start, 0);
}
if (stop < 0) {
stop += len;
+ CLAMP_MIN(stop, 0);
}
}
More information about the Bf-blender-cvs
mailing list