[Bf-blender-cvs] [02ef46314de] soc-2020-info-editor: Refactor readfile.c to use CLOG instead of printf
Mateusz GrzeliÅski
noreply at git.blender.org
Wed Jul 1 15:37:04 CEST 2020
Commit: 02ef46314de199beac8b0096f42d6fb7aec9be08
Author: Mateusz Grzeliński
Date: Wed Jul 1 15:36:14 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rB02ef46314de199beac8b0096f42d6fb7aec9be08
Refactor readfile.c to use CLOG instead of printf
===================================================================
M source/blender/blenloader/CMakeLists.txt
M source/blender/blenloader/intern/readfile.c
===================================================================
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index 09e2f4bf417..6ff9cbcd80d 100644
--- a/source/blender/blenloader/CMakeLists.txt
+++ b/source/blender/blenloader/CMakeLists.txt
@@ -33,6 +33,7 @@ set(INC
../render/extern/include
../windowmanager
../../../intern/guardedalloc
+ ../../../intern/clog
# for writefile.c: dna_type_offsets.h
${CMAKE_BINARY_DIR}/source/blender/makesdna/intern
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f8ceac3cd66..bb62601487f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -172,6 +172,7 @@
#include "readfile.h"
+#include <CLG_log.h>
#include <errno.h>
/* Make preferences read-only. */
@@ -242,14 +243,8 @@
/* 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
+static CLG_LogRef BLENLOADER_LOG_READFILE = {"blenloader.readfile"};
+static CLG_LogRef BLENLOADER_LOG_UNDO = {"blenloader.undo"};
/* local prototypes */
static void read_libraries(FileData *basefd, ListBase *mainlist);
@@ -304,7 +299,7 @@ void blo_reportf_wrap(ReportList *reports, ReportType type, const char *format,
BKE_report(reports, type, fixed_buf);
if (G.background == 0) {
- printf("%s: %s\n", BKE_report_type_str(type), fixed_buf);
+ CLOG_INFO(&BLENLOADER_LOG_READFILE, 1, "%s: %s", BKE_report_type_str(type), fixed_buf);
}
}
@@ -550,7 +545,7 @@ static void split_libdata(ListBase *lb_src, Main **lib_main_array, const uint li
BLI_addtail(lb_dst, id);
}
else {
- printf("%s: invalid library for '%s'\n", __func__, id->name);
+ CLOG_FATAL(&BLENLOADER_LOG_READFILE, "invalid library for '%s'", id->name);
BLI_assert(0);
}
}
@@ -669,17 +664,18 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
BLI_strncpy(name1, filepath, sizeof(name1));
BLI_path_normalize(relabase, name1);
- // printf("blo_find_main: relabase %s\n", relabase);
- // printf("blo_find_main: original in %s\n", filepath);
- // printf("blo_find_main: converted to %s\n", name1);
+ CLOG_INFO(&BLENLOADER_LOG_READFILE,
+ 0,
+ "relabase: %s, original in: %s, converted to %s",
+ relabase,
+ filepath,
+ name1);
for (m = mainlist->first; m; m = m->next) {
const char *libname = (m->curlib) ? m->curlib->filepath_abs : m->name;
if (BLI_path_cmp(name1, libname) == 0) {
- if (G.debug & G_DEBUG) {
- printf("blo_find_main: found library %s\n", libname);
- }
+ CLOG_INFO(&BLENLOADER_LOG_READFILE, 0, "found library %s", libname);
return m;
}
}
@@ -704,9 +700,7 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
read_file_version(fd, m);
- if (G.debug & G_DEBUG) {
- printf("blo_find_main: added new lib %s\n", filepath);
- }
+ CLOG_INFO(&BLENLOADER_LOG_READFILE, 0, "added new lib %s", filepath);
return m;
}
@@ -1276,7 +1270,7 @@ static int fd_read_from_memfile(FileData *filedata,
/* debug, should never happen */
if (chunk == NULL) {
- printf("illegal read, chunk zero\n");
+ CLOG_ERROR(&BLENLOADER_LOG_READFILE, "illegal read, chunk zero");
return 0;
}
@@ -1486,7 +1480,7 @@ static int fd_read_gzip_from_memory(FileData *filedata,
return 0;
}
else if (err != Z_OK) {
- printf("fd_read_gzip_from_memory: zlib error\n");
+ CLOG_ERROR(&BLENLOADER_LOG_READFILE, "zlib error: %d", err);
return 0;
}
@@ -1576,7 +1570,7 @@ void blo_filedata_free(FileData *fd)
if (fd->strm.next_in) {
if (inflateEnd(&fd->strm) != Z_OK) {
- printf("close gzip stream error\n");
+ CLOG_ERROR(&BLENLOADER_LOG_READFILE, "close gzip stream error");
}
}
@@ -2558,8 +2552,9 @@ static void IDP_DirectLinkProperty(IDProperty *prop, BlendDataReader *reader)
default:
/* Unknown IDP type, nuke it (we cannot handle unknown types everywhere in code,
* IDP are way too polymorphic to do it safely. */
- printf(
- "%s: found unknown IDProperty type %d, reset to Integer one !\n", __func__, prop->type);
+ CLOG_WARN(&BLENLOADER_LOG_READFILE,
+ "found unknown IDProperty type %d, reset to Integer one!",
+ prop->type);
/* Note: we do not attempt to free unknown prop, we have no way to know how to do that! */
prop->type = IDP_INT;
prop->subtype = 0;
@@ -2580,7 +2575,10 @@ static void _IDP_DirectLinkGroup_OrFree(IDProperty **prop,
}
else {
/* corrupt file! */
- printf("%s: found non group data, freeing type %d!\n", caller_func_id, (*prop)->type);
+ CLOG_WARN(&BLENLOADER_LOG_READFILE,
+ "%s: found non group data, freeing type %d!",
+ caller_func_id,
+ (*prop)->type);
/* don't risk id, data's likely corrupt. */
// IDP_FreePropertyContent(*prop);
*prop = NULL;
@@ -2599,7 +2597,9 @@ static void IDP_LibLinkProperty(IDProperty *prop, BlendLibReader *reader)
{
void *newaddr = BLO_read_get_new_id_address(reader, NULL, IDP_Id(prop));
if (IDP_Id(prop) && !newaddr && G.debug) {
- printf("Error while loading \"%s\". Data not found in file!\n", prop->name);
+ CLOG_ERROR(&BLENLOADER_LOG_READFILE,
+ "Error while loading \"%s\". Data not found in file!",
+ prop->name);
}
prop->data.pointer = newaddr;
break;
@@ -3023,7 +3023,7 @@ static PackedFile *direct_link_packedfile(BlendDataReader *reader, PackedFile *o
if (pf->data == NULL) {
/* We cannot allow a PackedFile with a NULL data field,
* the whole code assumes this is not possible. See T70315. */
- printf("%s: NULL packedfile data, cleaning up...\n", __func__);
+ CLOG_INFO(&BLENLOADER_LOG_READFILE, 0, "NULL packedfile data, cleaning up...");
MEM_SAFE_FREE(pf);
}
}
@@ -4252,7 +4252,10 @@ static void direct_link_text(BlendDataReader *reader, Text *text)
ln->format = NULL;
if (ln->len != (int)strlen(ln->line)) {
- printf("Error loading text, line lengths differ\n");
+ CLOG_WARN(&BLENLOADER_LOG_READFILE,
+ "Error loading text, line lengths differ: %d != %d",
+ ln->len,
+ (int)strlen(ln->line));
ln->len = strlen(ln->line);
}
}
@@ -5198,10 +5201,15 @@ static void lib_link_object(BlendLibReader *reader, Object *ob)
ob->proxy = NULL;
if (ob->id.lib) {
- printf("Proxy lost from object %s lib %s\n", ob->id.name + 2, ob->id.lib->filepath);
+ CLOG_INFO(&BLENLOADER_LOG_READFILE,
+ 0,
+ "Proxy lost from object %s lib %s",
+ ob->id.name + 2,
+ ob->id.lib->filepath);
}
else {
- printf("Proxy lost from object %s lib <NONE>\n", ob->id.name + 2);
+ CLOG_INFO(
+ &BLENLOADER_LOG_READFILE, 0, "Proxy lost from object %s lib <NONE>", ob->id.name + 2);
}
}
else {
@@ -5216,10 +5224,14 @@ static void lib_link_object(BlendLibReader *reader, Object *ob)
if (ob->data == NULL && poin != NULL) {
if (ob->id.lib) {
- printf("Can't find obdata of %s lib %s\n", ob->id.name + 2, ob->id.lib->filepath);
+ CLOG_INFO(&BLENLOADER_LOG_READFILE,
+ 0,
+ "Can't find obdata of %s lib %s",
+ ob->id.name + 2,
+ ob->id.lib->filepath);
}
else {
- printf("Object %s lost data.\n", ob->id.name + 2);
+ CLOG_INFO(&BLENLOADER_LOG_READFILE, 0, "Object %s lost data", ob->id.name + 2);
}
ob->type = OB_EMPTY;
@@ -5250,7 +5262,8 @@ static void lib_link_object(BlendLibReader *reader, Object *ob)
const short *totcol_data = BKE_object_material_len_p(ob);
/* Only expand so as not to loose any object materials that might be set. */
if (totcol_data && (*totcol_data > ob->totcol)) {
- /* printf("'%s' %d -> %d\n", ob->id.name, ob->totcol, *totcol_data); */
+ CLOG_INFO(
+ &BLENLOADER_LOG_READFILE, 2, "'%s' %d -> %d", ob->id.name, ob->totcol, *totcol_data);
BKE_object_material_resize(reader->main, ob, *totcol_data, false);
}
}
@@ -5629,9 +5642,11 @@ static void direct_link_modifiers(BlendDataReader *reader, ListBase *lb, Object
/* Manta-sim/smoke was already saved in "new format" and this cache is a fake one. */
}
else {
- printf(
+ CLOG_INFO(
+ &BLENLOADER_LOG_READFILE,
+ 0,
"High resolution manta cache not available due to pointcache update. Please "
- "reset the simulation.\n");
+ "reset the simulation");
}
BKE_ptcache_free(cache);
}
@@ -6508,7 +6523,10 @@ static void lib_link_scenes_check_set(Main *bmain)
if (sce->flag & SCE_READFILE_LIBLINK_NEED_SETSCENE_CHECK) {
sce->flag &= ~SCE_READFILE_LIBLINK_NEED_SETSCENE_CHECK;
if (!scene_validate_setscene__liblink(sce, totscene)) {
- printf("Found cyclic background scene when linking %s\n", sce->id.name + 2);
+ CLOG_INFO(&BLENLOADER_LOG_READFILE,
+ 0,
+ "Found cyclic background scene when linking %s",
+ sce->id.name + 2);
}
}
}
@@ -8193,7 +8211,8 @@ static bool direct_link_screen(BlendDataReader *reader, bScreen *screen)
screen->preview = direct_link_preview_image(reader, screen->preview);
if (!direct_link_area_map(reader, AREAMAP_FROM_SCREEN(screen))) {
- printf("Error reading Screen %s... removing it.\n", screen->id.name + 2);
+ CLOG_ERROR(
+ &BLENLOADER_LOG_READFILE, "Error reading Screen %s... removing it", screen->id.name + 2);
success
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list