diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-30 16:45:42 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-30 16:45:42 +0400 |
commit | f4dea6d8294a8ee31e13324d0c80f6992e467ea2 (patch) | |
tree | aae6acf5cf58fd8217a9b6ef12a807f83634c758 | |
parent | 900fa1bfb91cbb31c5336f63924ec6cb73239dc0 (diff) |
when an invalid subtype is passed to a property, a list of valid subtypes is now included in the exception message.
from bug report [#33018], this avoids common mistakes.
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index 4009104577a..bd033736865 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -310,35 +310,38 @@ static int py_long_as_int(PyObject *py_long, int *r_int) /* terse macros for error checks shared between all funcs cant use function * calls because of static strings passed to pyrna_set_to_enum_bitfield */ #define BPY_PROPDEF_CHECK(_func, _property_flag_items) \ - if (id_len >= MAX_IDPROP_NAME) { \ + if (UNLIKELY(id_len >= MAX_IDPROP_NAME)) { \ PyErr_Format(PyExc_TypeError, \ #_func"(): '%.200s' too long, max length is %d", \ id, MAX_IDPROP_NAME - 1); \ return NULL; \ } \ - if (RNA_def_property_free_identifier(srna, id) == -1) { \ + if (UNLIKELY(RNA_def_property_free_identifier(srna, id) == -1)) { \ PyErr_Format(PyExc_TypeError, \ #_func"(): '%s' is defined as a non-dynamic type", \ id); \ return NULL; \ } \ - if (pyopts && pyrna_set_to_enum_bitfield(_property_flag_items, \ + if (UNLIKELY(pyopts && pyrna_set_to_enum_bitfield(_property_flag_items, \ pyopts, \ &opts, \ - #_func"(options={ ...}):")) \ + #_func"(options={ ...}):"))) \ { \ return NULL; \ } (void)0 #define BPY_PROPDEF_SUBTYPE_CHECK(_func, _property_flag_items, _subtype) \ BPY_PROPDEF_CHECK(_func, _property_flag_items); \ - if (pysubtype && RNA_enum_value_from_id(_subtype, \ + if (UNLIKELY(pysubtype && RNA_enum_value_from_id(_subtype, \ pysubtype, \ - &subtype) == 0) \ + &subtype) == 0)) \ { \ + const char *enum_str = BPy_enum_as_string(_subtype); \ PyErr_Format(PyExc_TypeError, \ - #_func"(subtype='%s'): invalid subtype", \ - pysubtype); \ + #_func"(subtype='%s'): " \ + "subtype not found in (%s)", \ + pysubtype, enum_str); \ + MEM_freeN((void *)enum_str); \ return NULL; \ } (void)0 |