diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-01-02 08:30:13 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-01-02 08:39:45 +0300 |
commit | 09f46ef6faf5e95db966825e39941ce0378ce4a9 (patch) | |
tree | e726e0848dd4b61c67b76e878f509c76565385c3 /source/blender | |
parent | aae5f2b04611fee5de003083c6545fc89db33aa4 (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 24 |
1 files changed, 6 insertions, 18 deletions
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); |