[Bf-blender-cvs] [85e78fa17cd] master: Cleanup: Declare variables where initialized in context.c

Hans Goudey noreply at git.blender.org
Sat Oct 17 23:36:43 CEST 2020


Commit: 85e78fa17cd54676b5aa9a15a0b885b4a7187086
Author: Hans Goudey
Date:   Sat Oct 17 16:30:56 2020 -0500
Branches: master
https://developer.blender.org/rB85e78fa17cd54676b5aa9a15a0b885b4a7187086

Cleanup: Declare variables where initialized in context.c

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

M	source/blender/blenkernel/intern/context.c

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

diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 2002a49293f..a1edfd1c56d 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -104,9 +104,7 @@ struct bContext {
 
 bContext *CTX_create(void)
 {
-  bContext *C;
-
-  C = MEM_callocN(sizeof(bContext), "bContext");
+  bContext *C = MEM_callocN(sizeof(bContext), "bContext");
 
   return C;
 }
@@ -127,16 +125,13 @@ void CTX_free(bContext *C)
 
 bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *ptr)
 {
-  bContextStoreEntry *entry;
-  bContextStore *ctx, *lastctx;
-
   /* ensure we have a context to put the entry in, if it was already used
    * we have to copy the context to ensure */
-  ctx = contexts->last;
+  bContextStore *ctx = contexts->last;
 
   if (!ctx || ctx->used) {
     if (ctx) {
-      lastctx = ctx;
+      bContextStore *lastctx = ctx;
       ctx = MEM_dupallocN(lastctx);
       BLI_duplicatelist(&ctx->entries, &lastctx->entries);
     }
@@ -147,7 +142,7 @@ bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *p
     BLI_addtail(contexts, ctx);
   }
 
-  entry = MEM_callocN(sizeof(bContextStoreEntry), "bContextStoreEntry");
+  bContextStoreEntry *entry = MEM_callocN(sizeof(bContextStoreEntry), "bContextStoreEntry");
   BLI_strncpy(entry->name, name, sizeof(entry->name));
   entry->ptr = *ptr;
 
@@ -158,16 +153,13 @@ bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *p
 
 bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context)
 {
-  bContextStoreEntry *entry, *tentry;
-  bContextStore *ctx, *lastctx;
-
   /* ensure we have a context to put the entries in, if it was already used
    * we have to copy the context to ensure */
-  ctx = contexts->last;
+  bContextStore *ctx = contexts->last;
 
   if (!ctx || ctx->used) {
     if (ctx) {
-      lastctx = ctx;
+      bContextStore *lastctx = ctx;
       ctx = MEM_dupallocN(lastctx);
       BLI_duplicatelist(&ctx->entries, &lastctx->entries);
     }
@@ -178,8 +170,8 @@ bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context)
     BLI_addtail(contexts, ctx);
   }
 
-  for (tentry = context->entries.first; tentry; tentry = tentry->next) {
-    entry = MEM_dupallocN(tentry);
+  LISTBASE_FOREACH (bContextStoreEntry *, tentry, &context->entries) {
+    bContextStoreEntry *entry = MEM_dupallocN(tentry);
     BLI_addtail(&ctx->entries, entry);
   }
 
@@ -193,9 +185,7 @@ void CTX_store_set(bContext *C, bContextStore *store)
 
 bContextStore *CTX_store_copy(bContextStore *store)
 {
-  bContextStore *ctx;
-
-  ctx = MEM_dupallocN(store);
+  bContextStore *ctx = MEM_dupallocN(store);
   BLI_duplicatelist(&ctx->entries, &store->entries);
 
   return ctx;
@@ -210,7 +200,6 @@ void CTX_store_free(bContextStore *store)
 void CTX_store_free_list(ListBase *contexts)
 {
   bContextStore *ctx;
-
   while ((ctx = BLI_pophead(contexts))) {
     CTX_store_free(ctx);
   }
@@ -326,11 +315,11 @@ static eContextResult ctx_data_get(bContext *C, const char *member, bContextData
    * (0, -1, 1) - Where 1 is highest priority
    * */
   if (done != 1 && recursion < 1 && C->wm.store) {
-    bContextStoreEntry *entry;
-
     C->data.recursion = 1;
 
-    entry = BLI_rfindstring(&C->wm.store->entries, member, offsetof(bContextStoreEntry, name));
+    bContextStoreEntry *entry = BLI_rfindstring(
+        &C->wm.store->entries, member, offsetof(bContextStoreEntry, name));
+
     if (entry) {
       result->ptr = entry->ptr;
       done = 1;
@@ -354,6 +343,7 @@ static eContextResult ctx_data_get(bContext *C, const char *member, bContextData
       }
     }
   }
+
   if (done != 1 && recursion < 4 && (screen = CTX_wm_screen(C))) {
     bContextDataCallback cb = screen->context;
     C->data.recursion = 4;
@@ -373,7 +363,6 @@ static eContextResult ctx_data_get(bContext *C, const char *member, bContextData
 static void *ctx_data_pointer_get(const bContext *C, const char *member)
 {
   bContextDataResult result;
-
   if (C && ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
     BLI_assert(result.type == CTX_DATA_TYPE_POINTER);
     return result.ptr.data;
@@ -384,13 +373,13 @@ static void *ctx_data_pointer_get(const bContext *C, const char *member)
 
 static int ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer)
 {
-  bContextDataResult result;
-
   /* if context is NULL, pointer must be NULL too and that is a valid return */
   if (C == NULL) {
     *pointer = NULL;
     return 1;
   }
+
+  bContextDataResult result;
   if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
     BLI_assert(result.type == CTX_DATA_TYPE_POINTER);
     *pointer = result.ptr.data;
@@ -404,7 +393,6 @@ static int ctx_data_pointer_verify(const bContext *C, const char *member, void *
 static int ctx_data_collection_get(const bContext *C, const char *member, ListBase *list)
 {
   bContextDataResult result;
-
   if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
     BLI_assert(result.type == CTX_DATA_TYPE_COLLECTION);
     *list = result.list;
@@ -419,8 +407,6 @@ static int ctx_data_collection_get(const bContext *C, const char *member, ListBa
 static int ctx_data_base_collection_get(const bContext *C, const char *member, ListBase *list)
 {
   ListBase ctx_object_list;
-  bool ok = false;
-
   if ((ctx_data_collection_get(C, member, &ctx_object_list) == false) ||
       BLI_listbase_is_empty(&ctx_object_list)) {
     BLI_listbase_clear(list);
@@ -433,6 +419,8 @@ static int ctx_data_base_collection_get(const bContext *C, const char *member, L
   Scene *scene = CTX_data_scene(C);
   ViewLayer *view_layer = CTX_data_view_layer(C);
 
+  bool ok = false;
+
   CollectionPointerLink *ctx_object;
   for (ctx_object = ctx_object_list.first; ctx_object; ctx_object = ctx_object->next) {
     Object *ob = ctx_object->ptr.data;
@@ -452,7 +440,6 @@ static int ctx_data_base_collection_get(const bContext *C, const char *member, L
 PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
 {
   bContextDataResult result;
-
   if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
     BLI_assert(result.type == CTX_DATA_TYPE_POINTER);
     return result.ptr;
@@ -494,7 +481,6 @@ PointerRNA CTX_data_pointer_get_type_silent(const bContext *C, const char *membe
 ListBase CTX_data_collection_get(const bContext *C, const char *member)
 {
   bContextDataResult result;
-
   if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
     BLI_assert(result.type == CTX_DATA_TYPE_COLLECTION);
     return result.list;
@@ -651,9 +637,7 @@ void CTX_data_pointer_set(bContextDataResult *result, ID *id, StructRNA *type, v
 
 void CTX_data_id_list_add(bContextDataResult *result, ID *id)
 {
-  CollectionPointerLink *link;
-
-  link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_id_list_add");
+  CollectionPointerLink *link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_id_list_add");
   RNA_id_pointer_create(id, &link->ptr);
 
   BLI_addtail(&result->list, link);
@@ -661,9 +645,7 @@ void CTX_data_id_list_add(bContextDataResult *result, ID *id)
 
 void CTX_data_list_add(bContextDataResult *result, ID *id, StructRNA *type, void *data)
 {
-  CollectionPointerLink *link;
-
-  link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_list_add");
+  CollectionPointerLink *link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_list_add");
   RNA_pointer_create(id, type, data, &link->ptr);
 
   BLI_addtail(&result->list, link);
@@ -1022,7 +1004,6 @@ const char *CTX_wm_operator_poll_msg_get(bContext *C)
 Main *CTX_data_main(const bContext *C)
 {
   Main *bmain;
-
   if (ctx_data_pointer_verify(C, "blend_data", (void *)&bmain)) {
     return bmain;
   }
@@ -1039,7 +1020,6 @@ void CTX_data_main_set(bContext *C, Main *bmain)
 Scene *CTX_data_scene(const bContext *C)
 {
   Scene *scene;
-
   if (ctx_data_pointer_verify(C, "scene", (void *)&scene)) {
     return scene;
   }



More information about the Bf-blender-cvs mailing list