[Bf-blender-cvs] [78468225803] soc-2020-info-editor: WIP: Refactor reports: change use of RPT_PRINT and remove storelevel

Mateusz Grzeliński noreply at git.blender.org
Fri Jul 3 17:08:56 CEST 2020


Commit: 78468225803f5eff6397a0f470a28982c78939fc
Author: Mateusz Grzeliński
Date:   Fri Jul 3 17:08:42 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rB78468225803f5eff6397a0f470a28982c78939fc

WIP: Refactor reports: change use of RPT_PRINT and remove storelevel

- storelevel is not used feature - it was meant to print report to console (and not store) but with growing usage of logger it is redundant and complicates logic. Its place will take logger bke.report
- remove G.background from logic. If you want to see reports, enable logger (can be done by default)
- RPT_PRINT will no longer controll what gets printed to console, but it will only
- remove debug report: is your message user or developer oriented? If user, use info report, if developer, use log. Also duplicates functionality with log

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

M	intern/clog/CLG_log.h
M	intern/clog/clog.c
M	source/blender/blenkernel/BKE_report.h
M	source/blender/blenkernel/intern/curveprofile.c
M	source/blender/blenkernel/intern/report.c
M	source/blender/editors/render/render_opengl.c
M	source/blender/editors/space_info/info_draw.c
M	source/blender/editors/space_info/info_report.c
M	source/blender/editors/transform/transform_convert_armature.c
M	source/blender/editors/undo/ed_undo.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/modifiers/intern/MOD_datatransfer.c
M	source/blender/python/intern/bpy_capi_utils.c
M	source/blender/python/intern/bpy_library_write.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/creator/creator_args.c

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

diff --git a/intern/clog/CLG_log.h b/intern/clog/CLG_log.h
index 7b3e8b77cf6..f9ef05fd99e 100644
--- a/intern/clog/CLG_log.h
+++ b/intern/clog/CLG_log.h
@@ -188,7 +188,10 @@ void CLG_logref_init(CLG_LogRef *clg_ref);
 #define CLOG_ENSURE(clg_ref) \
   ((clg_ref)->type ? (clg_ref)->type : (CLG_logref_init(clg_ref), (clg_ref)->type))
 
-#define CLOG_CHECK(clg_ref, verbose_level, ...) \
+#define CLOG_CHECK_IN_USE(clg_ref, ...) \
+  ((void)CLOG_ENSURE(clg_ref), ((clg_ref)->type->flag & CLG_FLAG_USE))
+
+#define CLOG_CHECK_LEVEL(clg_ref, verbose_level, ...) \
   ((void)CLOG_ENSURE(clg_ref), \
    ((clg_ref)->type->flag & CLG_FLAG_USE) && ((clg_ref)->type->level >= verbose_level))
 
diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index c8b729a296b..dad1206cd52 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -542,7 +542,7 @@ void CLG_logf(CLG_LogType *lg,
 
   write_file_line_fn(&cstr, file_line, fn, lg->ctx->use_basename);
 
-  int csr_size_before_va = cstr.len;
+  int cstr_size_before_va = cstr.len;
   {
     va_list ap;
     va_start(ap, fmt);
@@ -550,8 +550,11 @@ void CLG_logf(CLG_LogType *lg,
     va_end(ap);
   }
 
-  char *message = MEM_callocN(cstr.len - csr_size_before_va + 1, "LogMessage");
-  memcpy(message, cstr.data + csr_size_before_va, cstr.len - csr_size_before_va);
+  size_t mem_size = cstr.len - cstr_size_before_va + 1; // +1 to null terminate?
+  char *message = MEM_callocN(mem_size, "LogMessage");
+  // todo memcpy crashes when message is too big? (ex. duplicating objects)
+  memcpy(message, cstr.data + cstr_size_before_va, mem_size-1);
+
   CLG_LogRecord *log_record = clog_log_record_init(lg, severity, file_line, fn, message);
   CLG_report_append(&(lg->ctx->log_records), log_record);
 
diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h
index 9e350dbf47f..c54abe0e892 100644
--- a/source/blender/blenkernel/BKE_report.h
+++ b/source/blender/blenkernel/BKE_report.h
@@ -52,11 +52,7 @@ void BKE_reports_prependf(ReportList *reports, const char *prepend, ...) ATTR_PR
 ReportType BKE_report_print_level(ReportList *reports);
 void BKE_report_print_level_set(ReportList *reports, ReportType level);
 
-ReportType BKE_report_store_level(ReportList *reports);
-void BKE_report_store_level_set(ReportList *reports, ReportType level);
-
-char *BKE_reports_string(ReportList *reports, ReportType level);
-void BKE_reports_print(ReportList *reports, ReportType level);
+char *BKE_reports_sprintfN(ReportList *reports, ReportType level);
 
 Report *BKE_reports_last_displayable(ReportList *reports);
 
diff --git a/source/blender/blenkernel/intern/curveprofile.c b/source/blender/blenkernel/intern/curveprofile.c
index 10765ed5d26..1f0512080de 100644
--- a/source/blender/blenkernel/intern/curveprofile.c
+++ b/source/blender/blenkernel/intern/curveprofile.c
@@ -863,7 +863,7 @@ void BKE_curveprofile_create_samples(CurveProfile *profile,
     BLI_assert(i_sample <= n_segments);
   }
 
-  if (CLOG_CHECK(&BKE_LOG_CURVEPROFILE_TABLE, 2)) {
+  if (CLOG_CHECK_LEVEL(&BKE_LOG_CURVEPROFILE_TABLE, 2)) {
     DynStr *message = BLI_dynstr_new();
     BLI_dynstr_appendf(message,
                        "CURVEPROFILE CREATE SAMPLES\n"
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
index 5ac34e43b49..e6d178e094a 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -43,8 +43,6 @@ static CLG_LogRef LOG = {"bke.report"};
 const char *BKE_report_type_str(ReportType type)
 {
   switch (type) {
-    case RPT_DEBUG:
-      return TIP_("Debug");
     case RPT_INFO:
       return TIP_("Info");
     case RPT_OPERATOR:
@@ -66,6 +64,30 @@ const char *BKE_report_type_str(ReportType type)
   }
 }
 
+static int report_type_to_verbosity(ReportType type)
+{
+  switch (type) {
+    case RPT_INFO:
+      return 5;
+    case RPT_OPERATOR:
+      return 4;
+    case RPT_PROPERTY:
+      return 3;
+    case RPT_WARNING:
+      return 2;
+    case RPT_ERROR:
+      return 1;
+    case RPT_ERROR_INVALID_INPUT:
+      return 1;
+    case RPT_ERROR_INVALID_CONTEXT:
+      return 1;
+    case RPT_ERROR_OUT_OF_MEMORY:
+      return 1;
+    default:
+      return 0;
+  }
+}
+
 void BKE_reports_init(ReportList *reports, int flag)
 {
   if (!reports) {
@@ -74,7 +96,6 @@ void BKE_reports_init(ReportList *reports, int flag)
 
   memset(reports, 0, sizeof(ReportList));
 
-  reports->storelevel = RPT_INFO;
   reports->printlevel = RPT_ERROR;
   reports->flag = flag;
 }
@@ -131,22 +152,9 @@ void BKE_report(ReportList *reports, ReportType type, const char *_message)
   int len;
   const char *message = TIP_(_message);
 
-  /* in background mode always log otherwise there are cases the errors wont be displayed,
-   * but still add to the report list since this is used for python exception handling */
-  if (G.background || !reports || ((reports->flag & RPT_PRINT) && (type >= reports->printlevel))) {
-    // todo enable bke.report logger by default ?
-    if (type & RPT_ERROR_ALL) {
-      CLOG_ERROR(&LOG, "%s: %s", BKE_report_type_str(type), message);
-    }
-    else if (type & RPT_WARNING_ALL) {
-      CLOG_WARN(&LOG, "%s: %s", BKE_report_type_str(type), message);
-    }
-    else {
-      CLOG_INFO(&LOG, 0, "%s: %s", BKE_report_type_str(type), message);
-    }
-  }
+  CLOG_INFO(&LOG, report_type_to_verbosity(type), "%s: %s", BKE_report_type_str(type), message);
 
-  if (reports && (reports->flag & RPT_STORE) && (type >= reports->storelevel)) {
+  if (reports && (reports->flag & RPT_STORE)) {
     char *message_alloc;
     report = MEM_callocN(sizeof(Report), "Report");
     report->type = type;
@@ -163,47 +171,37 @@ void BKE_report(ReportList *reports, ReportType type, const char *_message)
 
 void BKE_reportf(ReportList *reports, ReportType type, const char *_format, ...)
 {
-  DynStr *ds;
   Report *report;
   va_list args;
   const char *format = TIP_(_format);
+  DynStr *message = BLI_dynstr_new();
 
-  if (G.background || !reports || ((reports->flag & RPT_PRINT) && (type >= reports->printlevel))) {
-    DynStr *message = BLI_dynstr_new();
-    va_start(args, _format);
-    BLI_dynstr_vappendf(message, format, args);
-    va_end(args);
+  va_start(args, _format);
+  BLI_dynstr_vappendf(message, format, args);
+  va_end(args);
+
+  // check logger to avoid allocating memory if logger is off
+  if (CLOG_CHECK_IN_USE(&LOG)) {
     char *message_cstring = BLI_dynstr_get_cstring(message);
-    if (type & RPT_ERROR_ALL) {
-      CLOG_ERROR(&LOG, "%s: %s", BKE_report_type_str(type), message_cstring);
-    }
-    else if (type & RPT_WARNING_ALL) {
-      CLOG_WARN(&LOG, "%s: %s", BKE_report_type_str(type), message_cstring);
-    }
-    else {
-      CLOG_INFO(&LOG, 0, "%s: %s", BKE_report_type_str(type), message_cstring);
-    }
+    CLOG_INFO(&LOG,
+              report_type_to_verbosity(type),
+              "%s: %s",
+              BKE_report_type_str(type),
+              message_cstring);
     MEM_freeN(message_cstring);
-    BLI_dynstr_free(message);
   }
 
-  if (reports && (reports->flag & RPT_STORE) && (type >= reports->storelevel)) {
+  if (reports && (reports->flag & RPT_STORE)) {
     report = MEM_callocN(sizeof(Report), "Report");
 
-    ds = BLI_dynstr_new();
-    va_start(args, _format);
-    BLI_dynstr_vappendf(ds, format, args);
-    va_end(args);
-
-    report->message = BLI_dynstr_get_cstring(ds);
-    report->len = BLI_dynstr_get_len(ds);
-    BLI_dynstr_free(ds);
-
+    report->message = BLI_dynstr_get_cstring(message);
+    report->len = BLI_dynstr_get_len(message);
     report->type = type;
     report->typestr = BKE_report_type_str(type);
 
     BLI_addtail(&reports->list, report);
   }
+  BLI_dynstr_free(message);
 }
 
 void BKE_reports_prepend(ReportList *reports, const char *_prepend)
@@ -275,25 +273,8 @@ void BKE_report_print_level_set(ReportList *reports, ReportType level)
   reports->printlevel = level;
 }
 
-ReportType BKE_report_store_level(ReportList *reports)
-{
-  if (!reports) {
-    return RPT_ERROR;
-  }
-
-  return reports->storelevel;
-}
-
-void BKE_report_store_level_set(ReportList *reports, ReportType level)
-{
-  if (!reports) {
-    return;
-  }
-
-  reports->storelevel = level;
-}
-
-char *BKE_reports_string(ReportList *reports, ReportType level)
+/** return pretty printed reports with minimum level (level=0 - print all) or NULL */
+char *BKE_reports_sprintfN(ReportList *reports, ReportType level)
 {
   Report *report;
   DynStr *ds;
@@ -321,19 +302,6 @@ char *BKE_reports_string(ReportList *reports, ReportType level)
   return cstring;
 }
 
-void BKE_reports_print(ReportList *reports, ReportType level)
-{
-  char *cstring = BKE_reports_string(reports, level);
-
-  if (cstring == NULL) {
-    return;
-  }
-
-  puts(cstring);
-  fflush(stdout);
-  MEM_freeN(cstring);
-}
-
 Report *BKE_reports_last_displayable(ReportList *reports)
 {
   Report *report;
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 2861e851282..56781dc57f8 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -1044,7 +1044,7 @@ static void write_result_func(TaskPool *__restrict pool, void *task_data_v)
    * safely pass to the underlying functions.
    */
   ReportList reports;
-  BKE_reports_init(&reports, oglrender->reports->flag & ~RPT_PRINT);
+  BKE_reports_init(&reports, oglrender->reports->flag);
   /* Do actual save logic here, depending on the file format.
    *
    * NOTE: We have to construct temporary scene with proper scene->r.cfra.
diff --git a/source/blender/editors/space_info/info_draw.c b/source/blender/editors/space_info/info_draw.c
index cc720f1cf8e..2c98c89135a 100644
--- a/source/blender/editors/space_info/info_draw.c
+++ b/source/blender/editors/space_info/info_draw.c
@@ -94,11 +94,6 @@ static enum eTextViewContext_LineFlag report_line_data(TextViewContext *tvc,
     icon_bg_id = TH_INFO_INFO;
     *r_icon = ICON_INFO;
   }
-  else if (report->type & RPT_DEBUG_ALL) {
-    icon_fg_id = TH_INFO_DEBUG_TEXT;
-    icon_bg_id = TH_INFO_DEBUG;
-    *r_icon = ICON_SYSTEM;
-  }
   else if (report->type & RPT_P

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list