[Bf-blender-cvs] [4bcb8de] master: DNA: print errors to stderr

Campbell Barton noreply at git.blender.org
Sun Jan 10 23:31:03 CET 2016


Commit: 4bcb8defb8ff954813e84eb2f53bfc0ff35d1fb3
Author: Campbell Barton
Date:   Mon Jan 11 08:51:27 2016 +1100
Branches: master
https://developer.blender.org/rB4bcb8defb8ff954813e84eb2f53bfc0ff35d1fb3

DNA: print errors to stderr

Wasn't showing error output in some cases.

Also reduce variable scope in calculate_structlen

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

M	source/blender/makesdna/intern/makesdna.c

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

diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index a7ff424..685cde6 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -573,7 +573,7 @@ static int convert_include(char *filename)
 	
 	md = maindata = read_file_data(filename, &filelen);
 	if (filelen == -1) {
-		printf("Can't read file %s\n", filename);
+		fprintf(stderr, "Can't read file %s\n", filename);
 		return 1;
 	}
 
@@ -606,7 +606,7 @@ static int convert_include(char *filename)
 
 					strct = add_type(md1, 0);
 					if (strct == -1) {
-						printf("File '%s' contains struct we cant parse \"%s\"\n", filename, md1);
+						fprintf(stderr, "File '%s' contains struct we cant parse \"%s\"\n", filename, md1);
 						return 1;
 					}
 
@@ -638,7 +638,7 @@ static int convert_include(char *filename)
 							/* we've got a type! */
 							type = add_type(md1, 0);
 							if (type == -1) {
-								printf("File '%s' contains struct we can't parse \"%s\"\n", filename, md1);
+								fprintf(stderr, "File '%s' contains struct we can't parse \"%s\"\n", filename, md1);
 								return 1;
 							}
 
@@ -728,63 +728,65 @@ static int arraysize(const char *str)
 
 static int calculate_structlens(int firststruct)
 {
-	int a, b, len_native, len_32, len_64, unknown = nr_structs, lastunknown, structtype, type, mul, namelen;
-	const short *sp, *structpoin;
-	const char *cp;
-	int has_pointer, dna_error = 0;
-		
+	int unknown = nr_structs, lastunknown;
+	bool dna_error = false;
+
 	while (unknown) {
 		lastunknown = unknown;
 		unknown = 0;
 		
 		/* check all structs... */
-		for (a = 0; a < nr_structs; a++) {
-			structpoin = structs[a];
-			structtype = structpoin[0];
+		for (int a = 0; a < nr_structs; a++) {
+			const short *structpoin = structs[a];
+			const int    structtype = structpoin[0];
 
 			/* when length is not known... */
 			if (typelens_native[structtype] == 0) {
 				
-				sp = structpoin + 2;
-				len_native = 0;
-				len_32 = 0;
-				len_64 = 0;
-				has_pointer = 0;
+				const short *sp = structpoin + 2;
+				int len_native = 0;
+				int len_32 = 0;
+				int len_64 = 0;
+				bool has_pointer = false;
 				
 				/* check all elements in struct */
-				for (b = 0; b < structpoin[1]; b++, sp += 2) {
-					type = sp[0];
-					cp = names[sp[1]];
+				for (int b = 0; b < structpoin[1]; b++, sp += 2) {
+					int type = sp[0];
+					const char *cp = names[sp[1]];
 
-					namelen = (int) strlen(cp);
+					int namelen = (int)strlen(cp);
 					/* is it a pointer or function pointer? */
 					if (cp[0] == '*' || cp[1] == '*') {
 						has_pointer = 1;
 						/* has the name an extra length? (array) */
-						mul = 1;
+						int mul = 1;
 						if (cp[namelen - 1] == ']') mul = arraysize(cp);
 
 						if (mul == 0) {
-							printf("Zero array size found or could not parse %s: '%.*s'\n", types[structtype], namelen + 1, cp);
+							fprintf(stderr, "Zero array size found or could not parse %s: '%.*s'\n",
+							        types[structtype], namelen + 1, cp);
 							dna_error = 1;
 						}
 
 						/* 4-8 aligned/ */
 						if (sizeof(void *) == 4) {
 							if (len_native % 4) {
-								printf("Align pointer error in struct (len_native 4): %s %s\n", types[structtype], cp);
+								fprintf(stderr, "Align pointer error in struct (len_native 4): %s %s\n",
+								        types[structtype], cp);
 								dna_error = 1;
 							}
 						}
 						else {
 							if (len_native % 8) {
-								printf("Align pointer error in struct (len_native 8): %s %s\n", types[structtype], cp);
+								fprintf(stderr, "Align pointer error in struct (len_native 8): %s %s\n",
+								        types[structtype], cp);
 								dna_error = 1;
 							}
 						}
 
 						if (len_64 % 8) {
-							printf("Align pointer error in struct (len_64 8): %s %s\n", types[structtype], cp);
+							fprintf(stderr, "Align pointer error in struct (len_64 8): %s %s\n",
+							        types[structtype], cp);
 							dna_error = 1;
 						}
 
@@ -795,38 +797,44 @@ static int calculate_structlens(int firststruct)
 					}
 					else if (cp[0] == '[') {
 						/* parsing can cause names "var" and "[3]" to be found for "float var [3]" ... */
-						printf("Parse error in struct, invalid member name: %s %s\n", types[structtype], cp);
+						fprintf(stderr, "Parse error in struct, invalid member name: %s %s\n",
+						        types[structtype], cp);
 						dna_error = 1;
 					}
 					else if (typelens_native[type]) {
 						/* has the name an extra length? (array) */
-						mul = 1;
+						int mul = 1;
 						if (cp[namelen - 1] == ']') mul = arraysize(cp);
 
 						if (mul == 0) {
-							printf("Zero array size found or could not parse %s: '%.*s'\n", types[structtype], namelen + 1, cp);
+							fprintf(stderr, "Zero array size found or could not parse %s: '%.*s'\n",
+							        types[structtype], namelen + 1, cp);
 							dna_error = 1;
 						}
 
 						/* struct alignment */
 						if (type >= firststruct) {
 							if (sizeof(void *) == 8 && (len_native % 8) ) {
-								printf("Align struct error: %s %s\n", types[structtype], cp);
+								fprintf(stderr, "Align struct error: %s %s\n",
+								        types[structtype], cp);
 								dna_error = 1;
 							}
 						}
 						
 						/* 2-4-8 aligned/ */
 						if (type < firststruct && typelens_native[type] > 4 && (len_native % 8)) {
-							printf("Align 8 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 8);
+							fprintf(stderr, "Align 8 error in struct: %s %s (add %d padding bytes)\n",
+							        types[structtype], cp, len_native % 8);
 							dna_error = 1;
 						}
 						if (typelens_native[type] > 3 && (len_native % 4) ) {
-							printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 4);
+							fprintf(stderr, "Align 4 error in struct: %s %s (add %d padding bytes)\n",
+							        types[structtype], cp, len_native % 4);
 							dna_error = 1;
 						}
 						else if (typelens_native[type] == 2 && (len_native % 2) ) {
-							printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 2);
+							fprintf(stderr, "Align 2 error in struct: %s %s (add %d padding bytes)\n",
+							        types[structtype], cp, len_native % 2);
 							dna_error = 1;
 						}
 
@@ -854,13 +862,15 @@ static int calculate_structlens(int firststruct)
 					 * has_pointer is set or len_native  doesn't match any of 32/64bit lengths*/
 					if (has_pointer || len_64 != len_native || len_32 != len_native) {
 						if (len_64 % 8) {
-							printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], len_64 % 8);
+							fprintf(stderr, "Sizeerror 8 in struct: %s (add %d bytes)\n",
+							        types[structtype], len_64 % 8);
 							dna_error = 1;
 						}
 					}
 					
 					if (len_native % 4) {
-						printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len_native % 4);
+						fprintf(stderr, "Sizeerror 4 in struct: %s (add %d bytes)\n",
+						       types[structtype], len_native % 4);
 						dna_error = 1;
 					}
 					
@@ -872,32 +882,32 @@ static int calculate_structlens(int firststruct)
 	}
 	
 	if (unknown) {
-		printf("ERROR: still %d structs unknown\n", unknown);
+		fprintf(stderr, "ERROR: still %d structs unknown\n", unknown);
 
 		if (debugSDNA) {
-			printf("*** Known structs :\n");
+			fprintf(stderr, "*** Known structs :\n");
 			
-			for (a = 0; a < nr_structs; a++) {
-				structpoin = structs[a];
-				structtype = structpoin[0];
+			for (int a = 0; a < nr_structs; a++) {
+				const short *structpoin = structs[a];
+				const int    structtype = structpoin[0];
 				
 				/* length unknown */
 				if (typelens_native[structtype] != 0) {
-					printf("  %s\n", types[structtype]);
+					fprintf(stderr, "  %s\n", types[structtype]);
 				}
 			}
 		}
 
 			
-		printf("*** Unknown structs :\n");
+		fprintf(stderr, "*** Unknown structs :\n");
 			
-		for (a = 0; a < nr_structs; a++) {
-			structpoin = structs[a];
-			structtype = structpoin[0];
+		for (int a = 0; a < nr_structs; a++) {
+			const short *structpoin = structs[a];
+			const int    structtype = structpoin[0];
 
 			/* length unknown yet */
 			if (typelens_native[structtype] == 0) {
-				printf("  %s\n", types[structtype]);
+				fprintf(stderr, "  %s\n", types[structtype]);
 			}
 		}




More information about the Bf-blender-cvs mailing list