[Bf-blender-cvs] [09f46ef6faf] master: PyRNA: enum no longer returns first item when the value isn't found
Campbell Barton
noreply at git.blender.org
Wed Jan 2 06:43:09 CET 2019
Commit: 09f46ef6faf5e95db966825e39941ce0378ce4a9
Author: Campbell Barton
Date: Wed Jan 2 16:30:13 2019 +1100
Branches: master
https://developer.blender.org/rB09f46ef6faf5e95db966825e39941ce0378ce4a9
PyRNA: enum no longer returns first item when the value isn't found
This hides errors & makes it confusing to debug mistakes
when the enum items aren't correct.
Return an empty string instead.
===================================================================
M source/blender/python/intern/bpy_rna.c
===================================================================
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 77728829066..cc4ad6c93eb 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -1401,20 +1401,12 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
ret = PyUnicode_FromString(identifier);
}
else {
- const EnumPropertyItem *enum_item;
- bool free;
-
- /* don't throw error here, can't trust blender 100% to give the
- * right values, python code should not generate error for that */
- RNA_property_enum_items(BPy_GetContext(), ptr, prop, &enum_item, NULL, &free);
- if (enum_item && enum_item->identifier) {
- ret = PyUnicode_FromString(enum_item->identifier);
- }
- else {
- if (free) {
- MEM_freeN((void *)enum_item);
- }
- RNA_property_enum_items(NULL, ptr, prop, &enum_item, NULL, &free);
+ {
+ /* Static, no need to free. */
+ const EnumPropertyItem *enum_item;
+ bool free_dummy;
+ RNA_property_enum_items_ex(NULL, ptr, prop, true, &enum_item, NULL, &free_dummy);
+ BLI_assert(!free_dummy);
/* Do not print warning in case of DummyRNA_NULL_items, this one will never match any value... */
if (enum_item != DummyRNA_NULL_items) {
@@ -1444,10 +1436,6 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
ret = PyUnicode_FromString("");
}
-
- if (free) {
- MEM_freeN((void *)enum_item);
- }
#if 0
PyErr_Format(PyExc_AttributeError,
"RNA Error: Current value \"%d\" matches no enum", val);
More information about the Bf-blender-cvs
mailing list