[Bf-blender-cvs] [9d1ae07d4fe] master: Cleanup: Avoid ifdefs in multiple places

Sergey Sharybin noreply at git.blender.org
Tue Jan 16 17:15:26 CET 2018


Commit: 9d1ae07d4fe347c8ddd37c9c1b2e35d31c0690e1
Author: Sergey Sharybin
Date:   Tue Jan 16 17:14:57 2018 +0100
Branches: master
https://developer.blender.org/rB9d1ae07d4fe347c8ddd37c9c1b2e35d31c0690e1

Cleanup: Avoid ifdefs in multiple places

Define a helper macro. Makes code read easier.

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

M	source/blender/blenloader/intern/readfile.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index bc51f0fe96b..40b53d4c684 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -220,6 +220,15 @@
 /* Use GHash for restoring pointers by name */
 #define USE_GHASH_RESTORE_POINTER
 
+/* Define this to have verbose debug prints. */
+#define USE_DEBUG_PRINT
+
+#ifdef USE_DEBUG_PRINT
+#  define DEBUG_PRINTF(...) printf(__VA_ARGS__)
+#else
+#  define DEBUG_PRINTF(...)
+#endif
+
 /***/
 
 typedef struct OldNew {
@@ -8124,22 +8133,16 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
 	if (fd->memfile && ELEM(bhead->code, ID_LI, ID_ID)) {
 		const char *idname = bhead_id_name(fd, bhead);
 
-#ifdef PRINT_DEBUG
-		printf("Checking %s...\n", idname);
-#endif
+		DEBUG_PRINTF("Checking %s...\n", idname);
 
 		if (bhead->code == ID_LI) {
 			Main *libmain = fd->old_mainlist->first;
 			/* Skip oldmain itself... */
 			for (libmain = libmain->next; libmain; libmain = libmain->next) {
-#ifdef PRINT_DEBUG
-				printf("... against %s: ", libmain->curlib ? libmain->curlib->id.name : "<NULL>");
-#endif
+				DEBUG_PRINTF("... against %s: ", libmain->curlib ? libmain->curlib->id.name : "<NULL>");
 				if (libmain->curlib && STREQ(idname, libmain->curlib->id.name)) {
 					Main *oldmain = fd->old_mainlist->first;
-#ifdef PRINT_DEBUG
-					printf("FOUND!\n");
-#endif
+					DEBUG_PRINTF("FOUND!\n");
 					/* In case of a library, we need to re-add its main to fd->mainlist, because if we have later
 					 * a missing ID_ID, we need to get the correct lib it is linked to!
 					 * Order is crucial, we cannot bulk-add it in BLO_read_from_memfile() like it used to be... */
@@ -8153,19 +8156,13 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
 					}
 					return blo_nextbhead(fd, bhead);
 				}
-#ifdef PRINT_DEBUG
-				printf("nothing...\n");
-#endif
+				DEBUG_PRINTF("nothing...\n");
 			}
 		}
 		else {
-#ifdef PRINT_DEBUG
-			printf("... in %s (%s): ", main->curlib ? main->curlib->id.name : "<NULL>", main->curlib ? main->curlib->name : "<NULL>");
-#endif
+			DEBUG_PRINTF("... in %s (%s): ", main->curlib ? main->curlib->id.name : "<NULL>", main->curlib ? main->curlib->name : "<NULL>");
 			if ((id = BKE_libblock_find_name_ex(main, GS(idname), idname + 2))) {
-#ifdef PRINT_DEBUG
-				printf("FOUND!\n");
-#endif
+				DEBUG_PRINTF("FOUND!\n");
 				/* Even though we found our linked ID, there is no guarantee its address is still the same... */
 				if (id != bhead->old) {
 					oldnewmap_insert(fd->libmap, bhead->old, id, GS(id->name));
@@ -8177,9 +8174,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
 				}
 				return blo_nextbhead(fd, bhead);
 			}
-#ifdef PRINT_DEBUG
-			printf("nothing...\n");
-#endif
+			DEBUG_PRINTF("nothing...\n");
 		}
 	}



More information about the Bf-blender-cvs mailing list