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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-02-17 16:28:09 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-02-17 16:31:59 +0400
commit50b2c78ad8b6f994ceba77f548c39b2e510a98be (patch)
tree1fee99a7496293112729e30117b69c61fa3bc3e9 /source
parentd607a70795d0478eb70bbb05cf297f871a97cd4e (diff)
RNA: assert on NULL return values from itemf callbacks
Diffstat (limited to 'source')
-rw-r--r--source/blender/makesrna/RNA_access.h8
-rw-r--r--source/blender/makesrna/intern/rna_access.c55
2 files changed, 36 insertions, 27 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 07c7d3e58c3..0941f022901 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -786,10 +786,10 @@ bool RNA_enum_description(EnumPropertyItem *item, const int value, const char **
int RNA_enum_from_value(EnumPropertyItem *item, const int value);
int RNA_enum_from_identifier(EnumPropertyItem *item, const char *identifier);
-void RNA_property_enum_items(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item,
- int *r_totitem, bool *r_free);
-void RNA_property_enum_items_gettexted(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item,
- int *r_totitem, bool *r_free);
+void RNA_property_enum_items(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop,
+ EnumPropertyItem **item, int *r_totitem, bool *r_free);
+void RNA_property_enum_items_gettexted(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop,
+ EnumPropertyItem **r_item, int *r_totitem, bool *r_free);
bool RNA_property_enum_value(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value);
bool RNA_property_enum_identifier(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier);
bool RNA_property_enum_name(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **name);
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 2d8f8eb5c45..7ba0cabc6c2 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1214,7 +1214,7 @@ EnumPropertyItem DummyRNA_DEFAULT_items[] = {
{0, NULL, 0, NULL, NULL}
};
-void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item,
+void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **r_item,
int *r_totitem, bool *r_free)
{
EnumPropertyRNA *eprop = (EnumPropertyRNA *)rna_ensure_property(prop);
@@ -1222,38 +1222,42 @@ void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, En
*r_free = false;
if (eprop->itemf && (C != NULL || (prop->flag & PROP_ENUM_NO_CONTEXT))) {
+ EnumPropertyItem *item;
+
if (prop->flag & PROP_ENUM_NO_CONTEXT)
- *item = eprop->itemf(NULL, ptr, prop, r_free);
+ item = eprop->itemf(NULL, ptr, prop, r_free);
else
- *item = eprop->itemf(C, ptr, prop, r_free);
+ item = eprop->itemf(C, ptr, prop, r_free);
- if ((*item) == NULL) {
- int tot = 0;
- RNA_enum_item_end(item, &tot);
- }
+ /* any callbacks returning NULL should be fixed */
+ BLI_assert(item != NULL);
if (r_totitem) {
- int tot = 0;
- for (; (*item)[tot].identifier; tot++) ;
+ int tot;
+ for (tot = 0; item[tot].identifier; tot++) {
+ /* pass */
+ }
*r_totitem = tot;
}
+ *r_item = item;
}
else {
- *item = eprop->item;
+ *r_item = eprop->item;
if (r_totitem)
*r_totitem = eprop->totitem;
}
}
-void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item,
- int *r_totitem, bool *r_free)
+void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop,
+ EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
{
- RNA_property_enum_items(C, ptr, prop, item, r_totitem, r_free);
+ RNA_property_enum_items(C, ptr, prop, r_item, r_totitem, r_free);
#ifdef WITH_INTERNATIONAL
if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
int i;
+
/* Note: Only do those tests once, and then use BLF_pgettext. */
bool do_iface = BLF_translate_iface();
bool do_tooltip = BLF_translate_tooltips();
@@ -1263,19 +1267,24 @@ void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA
return;
if (*r_free) {
- nitem = *item;
+ nitem = *r_item;
}
else {
- int totitem = 0;
+ EnumPropertyItem *item = *r_item;
+ int tot;
- /* count */
- for (i = 0; (*item)[i].identifier; i++)
- totitem++;
-
- nitem = MEM_callocN(sizeof(EnumPropertyItem) * (totitem + 1), "enum_items_gettexted");
+ if (r_totitem) {
+ tot = *r_totitem;
+ }
+ else {
+ /* count */
+ for (tot = 0; item[tot].identifier; tot++) {
+ /* pass */
+ }
+ }
- for (i = 0; (*item)[i].identifier; i++)
- nitem[i] = (*item)[i];
+ nitem = MEM_mallocN(sizeof(EnumPropertyItem) * tot + 1, "enum_items_gettexted");
+ memcpy(nitem, item, sizeof(EnumPropertyItem) * tot + 1);
*r_free = true;
}
@@ -1289,7 +1298,7 @@ void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA
}
}
- *item = nitem;
+ *r_item = nitem;
}
#endif
}