[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51766] trunk/blender/source/blender/ python/intern/bpy_props.c: when an invalid subtype is passed to a property, a list of valid subtypes is now included in the exception message.

Campbell Barton ideasman42 at gmail.com
Tue Oct 30 13:45:46 CET 2012


Revision: 51766
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51766
Author:   campbellbarton
Date:     2012-10-30 12:45:42 +0000 (Tue, 30 Oct 2012)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_props.c

Modified: trunk/blender/source/blender/python/intern/bpy_props.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_props.c	2012-10-30 12:36:54 UTC (rev 51765)
+++ trunk/blender/source/blender/python/intern/bpy_props.c	2012-10-30 12:45:42 UTC (rev 51766)
@@ -310,35 +310,38 @@
 /* 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
 




More information about the Bf-blender-cvs mailing list