[Bf-blender-cvs] [c377cb2db5b] master: RNA: use clog for logging error messages

Campbell Barton noreply at git.blender.org
Mon Feb 18 00:41:59 CET 2019


Commit: c377cb2db5bf155cdf2e814dab352046001c3044
Author: Campbell Barton
Date:   Mon Feb 18 09:32:15 2019 +1100
Branches: master
https://developer.blender.org/rBc377cb2db5bf155cdf2e814dab352046001c3044

RNA: use clog for logging error messages

Some RNA errors are quite similar, use clog for consistent logging that
always includes the file, function and line number - making errors
quicker to troubleshoot.

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

M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_define.c

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

diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt
index 84aeb29e45d..5188ac425bf 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -159,6 +159,7 @@ set(SRC
 	rna_define.c
 	${DEFSRC}
 	${APISRC}
+	../../../../intern/clog/clog.c
 	../../../../intern/guardedalloc/intern/mallocn.c
 	../../../../intern/guardedalloc/intern/mallocn_guarded_impl.c
 	../../../../intern/guardedalloc/intern/mallocn_lockfree_impl.c
@@ -166,7 +167,7 @@ set(SRC
 )
 
 set(INC
-
+    ../../../../intern/clog
 )
 
 set(INC_SYS
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 72cffaaf8a3..46445a85f6d 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -40,6 +40,10 @@
 #  endif
 #endif
 
+#include "CLG_log.h"
+
+static CLG_LogRef LOG = {"makesrna"};
+
 /**
  * Variable to control debug output of makesrna.
  * debugSRNA:
@@ -105,15 +109,15 @@ static int replace_if_different(const char *tmpfile, const char *dep_files[])
 			if (fp_org) fclose(fp_org);                                       \
 			if (fp_new) fclose(fp_new);                                       \
 			if (remove(orgfile) != 0) {                                       \
-				fprintf(stderr, "%s:%d, Remove Error (%s): \"%s\"\n",         \
-				        __FILE__, __LINE__, strerror(errno), orgfile);        \
+				CLOG_ERROR(&LOG, "remove error (%s): \"%s\"",                 \
+				           strerror(errno), orgfile);                         \
 				return -1;                                                    \
 			}                                                                 \
 		}                                                                     \
 	}                                                                         \
 	if (rename(tmpfile, orgfile) != 0) {                                      \
-		fprintf(stderr, "%s:%d, Rename Error (%s): \"%s\" -> \"%s\"\n",       \
-		        __FILE__, __LINE__, strerror(errno), tmpfile, orgfile);       \
+		CLOG_ERROR(&LOG, "rename error (%s): \"%s\" -> \"%s\"",               \
+		           strerror(errno), tmpfile, orgfile);                        \
 		return -1;                                                            \
 	}                                                                         \
 	remove(tmpfile);                                                          \
@@ -178,7 +182,7 @@ static int replace_if_different(const char *tmpfile, const char *dep_files[])
 
 	if (fp_new == NULL) {
 		/* shouldn't happen, just to be safe */
-		fprintf(stderr, "%s:%d, open error: \"%s\"\n", __FILE__, __LINE__, tmpfile);
+		CLOG_ERROR(&LOG, "open error: \"%s\"", tmpfile);
 		fclose(fp_org);
 		return -1;
 	}
@@ -197,10 +201,12 @@ static int replace_if_different(const char *tmpfile, const char *dep_files[])
 	arr_new = MEM_mallocN(sizeof(char) * len_new, "rna_cmp_file_new");
 	arr_org = MEM_mallocN(sizeof(char) * len_org, "rna_cmp_file_org");
 
-	if (fread(arr_new, sizeof(char), len_new, fp_new) != len_new)
-		fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, tmpfile);
-	if (fread(arr_org, sizeof(char), len_org, fp_org) != len_org)
-		fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, orgfile);
+	if (fread(arr_new, sizeof(char), len_new, fp_new) != len_new) {
+		CLOG_ERROR(&LOG, "unable to read file %s for comparison.", tmpfile);
+	}
+	if (fread(arr_org, sizeof(char), len_org, fp_org) != len_org) {
+		CLOG_ERROR(&LOG, "unable to read file %s for comparison.", orgfile);
+	}
 
 	fclose(fp_new); fp_new = NULL;
 	fclose(fp_org); fp_org = NULL;
@@ -533,8 +539,8 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
 
 	if (!manualfunc) {
 		if (!dp->dnastructname || !dp->dnaname) {
-			fprintf(stderr, "%s (0): %s.%s has no valid dna info.\n",
-			        __func__, srna->identifier, prop->identifier);
+			CLOG_ERROR(&LOG, "%s.%s has no valid dna info.",
+			           srna->identifier, prop->identifier);
 			DefRNA.error = 1;
 			return NULL;
 		}
@@ -545,9 +551,9 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
 			if (prop->type == PROP_FLOAT) {
 				if (IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) {
 					if (prop->subtype != PROP_COLOR_GAMMA) { /* colors are an exception. these get translated */
-						fprintf(stderr, "%s (1): %s.%s is a '%s' but wrapped as type '%s'.\n",
-						        __func__, srna->identifier, prop->identifier, dp->dnatype,
-						        RNA_property_typename(prop->type));
+						CLOG_ERROR(&LOG, "%s.%s is a '%s' but wrapped as type '%s'.",
+						           srna->identifier, prop->identifier, dp->dnatype,
+						           RNA_property_typename(prop->type));
 						DefRNA.error = 1;
 						return NULL;
 					}
@@ -555,9 +561,9 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
 			}
 			else if (prop->type == PROP_INT || prop->type == PROP_BOOLEAN || prop->type == PROP_ENUM) {
 				if (IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
-					fprintf(stderr, "%s (2): %s.%s is a '%s' but wrapped as type '%s'.\n",
-					        __func__, srna->identifier, prop->identifier, dp->dnatype,
-					        RNA_property_typename(prop->type));
+					CLOG_ERROR(&LOG, "%s.%s is a '%s' but wrapped as type '%s'.",
+					           srna->identifier, prop->identifier, dp->dnatype,
+					           RNA_property_typename(prop->type));
 					DefRNA.error = 1;
 					return NULL;
 				}
@@ -833,8 +839,8 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
 	if (!manualfunc) {
 		if (!dp->dnastructname || !dp->dnaname) {
 			if (prop->flag & PROP_EDITABLE) {
-				fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
-				        __func__, srna->identifier, prop->identifier);
+				CLOG_ERROR(&LOG, "%s.%s has no valid dna info.",
+				           srna->identifier, prop->identifier);
 				DefRNA.error = 1;
 			}
 			return NULL;
@@ -1047,8 +1053,8 @@ static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA
 	if (prop->type == PROP_STRING) {
 		if (!manualfunc) {
 			if (!dp->dnastructname || !dp->dnaname) {
-				fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
-				        __func__, srna->identifier, prop->identifier);
+				CLOG_ERROR(&LOG, "%s.%s has no valid dna info.",
+				           srna->identifier, prop->identifier);
 				DefRNA.error = 1;
 				return NULL;
 			}
@@ -1073,8 +1079,8 @@ static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA
 	else if (prop->type == PROP_COLLECTION) {
 		if (!manualfunc) {
 			if (prop->type == PROP_COLLECTION && (!(dp->dnalengthname || dp->dnalengthfixed) || !dp->dnaname)) {
-				fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
-				        __func__, srna->identifier, prop->identifier);
+				CLOG_ERROR(&LOG, "%s.%s has no valid dna info.",
+				           srna->identifier, prop->identifier);
 				DefRNA.error = 1;
 				return NULL;
 			}
@@ -1117,8 +1123,8 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *
 
 	if (!manualfunc) {
 		if (!dp->dnastructname || !dp->dnaname) {
-			fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
-			        __func__, srna->identifier, prop->identifier);
+			CLOG_ERROR(&LOG, "%s.%s has no valid dna info.",
+			           srna->identifier, prop->identifier);
 			DefRNA.error = 1;
 			return NULL;
 		}
@@ -1529,8 +1535,8 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
 			pprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)pprop->get);
 			pprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)pprop->set);
 			if (!pprop->type) {
-				fprintf(stderr, "%s: %s.%s, pointer must have a struct type.\n",
-				        __func__, srna->identifier, prop->identifier);
+				CLOG_ERROR(&LOG, "%s.%s, pointer must have a struct type.",
+				           srna->identifier, prop->identifier);
 				DefRNA.error = 1;
 			}
 			break;
@@ -1572,24 +1578,24 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
 
 			if (!(prop->flag & PROP_IDPROPERTY)) {
 				if (!cprop->begin) {
-					fprintf(stderr, "%s: %s.%s, collection must have a begin function.\n",
-					        __func__, srna->identifier, prop->identifier);
+					CLOG_ERROR(&LOG, "%s.%s, collection must have a begin function.",
+					           srna->identifier, prop->identifier);
 					DefRNA.error = 1;
 				}
 				if (!cprop->next) {
-					fprintf(stderr, "%s: %s.%s, collection must have a next function.\n",
-					        __func__, srna->identifier, prop->identifier);
+					CLOG_ERROR(&LOG, "%s.%s, collection must have a next function.",
+					           srna->identifier, prop->identifier);
 					DefRNA.error = 1;
 				}
 				if (!cprop->get) {
-					fprintf(stderr, "%s: %s.%s, collection must have a get function.\n",
-					        __func__, srna->identifier, prop->identifier);
+					CLOG_ERROR(&LOG, "%s.%s, collection must have a get function.",
+					           srna->identifier, prop->identifier);
 					DefRNA.error = 1;
 				}
 			}
 			if (!cprop->item_type) {
-				fprintf(stderr, "%s: %s.%s, collection must have a struct type.\n",
-				        __func__, srna->identifier, prop->identifier);
+				CLOG_ERROR(&LOG, "%s.%s, collection must have a struct type.",
+				           srna->identifier, prop->identifier);
 				DefRNA.error = 1;
 			}
 			break;
@@ -2944,23 +2950,23 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
 
 				if (prop->flag & PROP_ENUM_FLAG) {
 					if (eprop->defaultvalue & ~totflag) {
-						fprintf(stderr, "%s: %s%s.%s, enum default includes unused bits (%d).\n",
-						        __func__, srna->identifier, errnest, prop->identifier,
+						CLOG_ERROR(&LOG, "%s%s.%s, enum default includes unused bits (%d).",
+						           srna->identifier, errnest, prop->identifier,
 						        eprop->defaultvalue & ~totflag);
 						DefRNA.error = 1;
 					}
 				}
 				else {
 					if (!defaultfound) {
-						fp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list