[Bf-blender-cvs] [7b11c717294] master: RNA: modify debug mode logic for setting invalid unset values
Campbell Barton
noreply at git.blender.org
Mon Feb 21 02:24:02 CET 2022
Commit: 7b11c717294341f5c288e2dc8432e84bc53663ff
Author: Campbell Barton
Date: Sun Feb 20 21:28:59 2022 +1100
Branches: master
https://developer.blender.org/rB7b11c717294341f5c288e2dc8432e84bc53663ff
RNA: modify debug mode logic for setting invalid unset values
The previous behavior called RNA_enum_item_add a second time,
filled it's contents with invalid values then subtracted totitem,
this caused an unusual reallocation pattern where MEM_recallocN
would run in order to create the dummy item, then again when adding
another itme (reallocating an array of the same size).
Simply memset the array to 0xff instead.
===================================================================
M source/blender/makesrna/intern/rna_define.c
===================================================================
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 850accd0b24..5127b418b7f 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -4391,24 +4391,21 @@ void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropert
if (tot == 0) {
*items = MEM_callocN(sizeof(EnumPropertyItem[8]), __func__);
+ /* Ensure we get crashes on missing calls to 'RNA_enum_item_end', see T74227. */
+#ifdef DEBUG
+ memset(*items, 0xff, sizeof(EnumPropertyItem[8]));
+#endif
}
else if (tot >= 8 && (tot & (tot - 1)) == 0) {
/* power of two > 8 */
*items = MEM_recallocN_id(*items, sizeof(EnumPropertyItem) * tot * 2, __func__);
+#ifdef DEBUG
+ memset((*items) + tot, 0xff, sizeof(EnumPropertyItem) * tot);
+#endif
}
(*items)[tot] = *item;
*totitem = tot + 1;
-
- /* Ensure we get crashes on missing calls to 'RNA_enum_item_end', see T74227. */
-#ifdef DEBUG
- static const EnumPropertyItem item_error = {
- -1, POINTER_FROM_INT(-1), -1, POINTER_FROM_INT(-1), POINTER_FROM_INT(-1)};
- if (item != &item_error) {
- RNA_enum_item_add(items, totitem, &item_error);
- *totitem -= 1;
- }
-#endif
}
void RNA_enum_item_add_separator(EnumPropertyItem **items, int *totitem)
More information about the Bf-blender-cvs
mailing list