[Bf-blender-cvs] [87aa13d0257] master: PyAPI: prevent leading comma when printing some enums

Campbell Barton noreply at git.blender.org
Tue Sep 1 08:39:39 CEST 2020


Commit: 87aa13d025797f2f73f6b6216422843d042c4453
Author: Campbell Barton
Date:   Tue Sep 1 16:32:11 2020 +1000
Branches: master
https://developer.blender.org/rB87aa13d025797f2f73f6b6216422843d042c4453

PyAPI: prevent leading comma when printing some enums

BPy_enum_as_string (used for creating error messages)
showed a leading comma for enums that used category headings.

While harmless, it looks odd.

===================================================================

M	source/blender/python/intern/bpy_capi_utils.c

===================================================================

diff --git a/source/blender/python/intern/bpy_capi_utils.c b/source/blender/python/intern/bpy_capi_utils.c
index 27eea80f1f6..8eb44e918d7 100644
--- a/source/blender/python/intern/bpy_capi_utils.c
+++ b/source/blender/python/intern/bpy_capi_utils.c
@@ -51,16 +51,17 @@ void BPy_SetContext(bContext *C)
 char *BPy_enum_as_string(const EnumPropertyItem *item)
 {
   DynStr *dynstr = BLI_dynstr_new();
-  const EnumPropertyItem *e;
-  char *cstring;
 
-  for (e = item; item->identifier; item++) {
+  /* We can't compare with the first element in the array
+   * since it may be a category (without an identifier). */
+  for (bool is_first = true; item->identifier; item++) {
     if (item->identifier[0]) {
-      BLI_dynstr_appendf(dynstr, (e == item) ? "'%s'" : ", '%s'", item->identifier);
+      BLI_dynstr_appendf(dynstr, is_first ? "'%s'" : ", '%s'", item->identifier);
+      is_first = false;
     }
   }
 
-  cstring = BLI_dynstr_get_cstring(dynstr);
+  char *cstring = BLI_dynstr_get_cstring(dynstr);
   BLI_dynstr_free(dynstr);
   return cstring;
 }



More information about the Bf-blender-cvs mailing list