[Bf-blender-cvs] [1ae826af172] soc-2020-info-editor: WIP: Further development

Mateusz Grzeliński noreply at git.blender.org
Tue Jun 30 17:24:57 CEST 2020


Commit: 1ae826af1722d2ab12e97faf4d0f76db92a75fe9
Author: Mateusz Grzeliński
Date:   Mon Jun 29 23:07:31 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rB1ae826af1722d2ab12e97faf4d0f76db92a75fe9

WIP: Further development

- join file and line in CLG_LogRecord
- convert clog to dynamically allocated message
- add function for deep copy record list
- remove custom enum update callback in favor of update on tag
- ui tweak

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

M	intern/clog/CLG_log.h
M	intern/clog/clog.c
M	release/scripts/startup/bl_ui/space_info.py
M	source/blender/blenkernel/BKE_report.h
M	source/blender/blenkernel/intern/report.c
M	source/blender/editors/space_info/info_report.c
M	source/blender/editors/space_info/space_info.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_space_api.c

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

diff --git a/intern/clog/CLG_log.h b/intern/clog/CLG_log.h
index 771ae1ca24a..dc9f107d103 100644
--- a/intern/clog/CLG_log.h
+++ b/intern/clog/CLG_log.h
@@ -133,10 +133,9 @@ typedef struct CLG_LogRecord {
   CLG_LogType *type;
   enum CLG_Severity severity;
   uint64_t timestamp;
-  const char *file;
-  const char *line;
+  const char *file_line;
   const char *function;
-  const char *message;
+  char *message;
 } CLG_LogRecord;
 
 void CLG_log_str(CLG_LogType *lg,
@@ -151,12 +150,12 @@ void CLG_logf(CLG_LogType *lg,
               const char *format,
               ...) _CLOG_ATTR_NONNULL(1, 3, 4, 5) _CLOG_ATTR_PRINTF_FORMAT(5, 6);
 
+const char *clg_severity_as_text(enum CLG_Severity severity);
 CLG_LogRecord *clog_log_record_init(CLG_LogType *type,
                                     enum CLG_Severity severity,
-                                    const char *file,
-                                    const char *line,
+                                    const char *file_line,
                                     const char *function,
-                                    const char *message);
+                                    char *message);
 void clog_log_record_free(CLG_LogRecord *log_record);
 
 /* Main initializer and distructor (per session, not logger). */
diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index 68607a38cc5..d46f2140f5c 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -251,7 +251,7 @@ static const char *clg_severity_str[CLG_SEVERITY_LEN] = {
     [CLG_SEVERITY_FATAL] = "FATAL",
 };
 
-static const char *clg_severity_as_text(enum CLG_Severity severity)
+const char *clg_severity_as_text(enum CLG_Severity severity)
 {
   bool ok = (unsigned int)severity < CLG_SEVERITY_LEN;
   assert(ok);
@@ -383,17 +383,15 @@ static uint64_t clg_timestamp_ticks_get(void)
 
 CLG_LogRecord *clog_log_record_init(CLG_LogType *type,
                                     enum CLG_Severity severity,
-                                    const char *file,
-                                    const char *line,
+                                    const char *file_line,
                                     const char *function,
-                                    const char *message)
+                                    char *message)
 {
   CLG_LogRecord *log_record = MEM_callocN(sizeof(*log_record), "ClogRecord");
   log_record->type = type;
   log_record->severity = severity;
   log_record->timestamp = clg_timestamp_ticks_get() - type->ctx->timestamp_tick_start;
-  log_record->file = file;
-  log_record->line = line;
+  log_record->file_line = file_line;
   log_record->function = function;
   log_record->message = message;
   return log_record;
@@ -401,20 +399,10 @@ CLG_LogRecord *clog_log_record_init(CLG_LogType *type,
 
 void clog_log_record_free(CLG_LogRecord *log_record)
 {
+  MEM_freeN(log_record->message);
   MEM_freeN(log_record);
 }
 
-void clog_timestamp_to_char()
-{
-  const uint64_t timestamp = 0;  // clg_timestamp_ticks_get() - type->ctx->timestamp_tick_start;
-  char timestamp_str[64];
-  const uint timestamp_len = snprintf(timestamp_str,
-                                      sizeof(timestamp_str),
-                                      "%" PRIu64 ".%03u ",
-                                      timestamp / 1000,
-                                      (uint)(timestamp % 1000));
-}
-
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -523,19 +511,6 @@ void CLG_logf(CLG_LogType *lg,
               const char *fmt,
               ...)
 {
-  CLG_LogRecord *log_record = clog_log_record_init(lg, severity, file_line, file_line, fn, fmt);
-
-  BLI_addtail(&(lg->ctx->log_records), log_record);
-
-  //  CLG_LogRecord *log = NULL, *log_iter = NULL;
-  //  printf("Dump all log records:\n");
-  //  log = lg->ctx->log_records.first;
-  //  while (log) {
-  //    log_iter = log->next;
-  //    printf("  id: %s, %s\n", log->type->identifier, log->message);
-  //    log = log_iter;
-  //  }
-
   CLogStringBuf cstr;
   char cstr_stack_buf[CLOG_BUF_LEN_INIT];
   clg_str_init(&cstr, cstr_stack_buf, sizeof(cstr_stack_buf));
@@ -547,14 +522,21 @@ void CLG_logf(CLG_LogType *lg,
   write_severity(&cstr, severity, lg->ctx->use_color);
   write_type(&cstr, lg);
 
-  {
-    write_file_line_fn(&cstr, file_line, fn, lg->ctx->use_basename);
+  write_file_line_fn(&cstr, file_line, fn, lg->ctx->use_basename);
 
+  int csr_size_before_va = cstr.len;
+  {
     va_list ap;
     va_start(ap, fmt);
     clg_str_vappendf(&cstr, fmt, ap);
     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);
+  CLG_LogRecord *log_record = clog_log_record_init(lg, severity, file_line, fn, message);
+  BLI_addtail(&(lg->ctx->log_records), log_record);
+
   clg_str_append(&cstr, "\n");
 
   /* could be optional */
@@ -667,7 +649,7 @@ static CLogContext *CLG_ctx_init(void)
 
 static void CLG_ctx_free(CLogContext *ctx)
 {
-  CLG_LogRecord *log = ctx->log_records.first, *log_next=NULL;
+  CLG_LogRecord *log = ctx->log_records.first, *log_next = NULL;
   while (log) {
     log_next = log->next;
     clog_log_record_free(log);
@@ -703,7 +685,7 @@ static void CLG_ctx_free(CLogContext *ctx)
  * \{ */
 
 /* We could support multiple at once, for now this seems not needed. */
-struct CLogContext *g_ctx = NULL;
+static struct CLogContext *g_ctx = NULL;
 
 void CLG_init(void)
 {
diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index 7e369b370f1..f4d63bc72d4 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -40,9 +40,8 @@ class INFO_MT_editor_menus(Menu):
         layout.menu("INFO_MT_info")
 
         sinfo = context.space_data
-        row = layout.row(align=True)
+        row = layout.row()
         row.prop(sinfo, "view", expand=True)
-        # row.prop(sinfo, "view")
 
 
 class INFO_MT_view(Menu):
diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h
index 063c0831a0d..9e350dbf47f 100644
--- a/source/blender/blenkernel/BKE_report.h
+++ b/source/blender/blenkernel/BKE_report.h
@@ -40,6 +40,7 @@ extern "C" {
 
 void BKE_reports_init(ReportList *reports, int flag);
 void BKE_reports_clear(ReportList *reports);
+ReportList *BKE_reports_duplicate(ReportList *reports);
 
 void BKE_report(ReportList *reports, ReportType type, const char *message);
 void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...)
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
index 43ab1a71647..6b8c3a226e4 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -101,6 +101,27 @@ void BKE_reports_clear(ReportList *reports)
   BLI_listbase_clear(&reports->list);
 }
 
+/** deep copy of reports */
+ReportList *BKE_reports_duplicate(ReportList *reports)
+{
+  Report *report = reports->list.first, *report_next, *report_dup;
+  ReportList *reports_new = MEM_dupallocN(reports);
+  BLI_listbase_clear(&reports_new->list);
+
+  while (report) {
+    report_next = report->next;
+    report_dup = MEM_dupallocN(report);
+    report_dup->message = MEM_dupallocN(report->message);
+    BLI_addtail(&reports_new->list, report_dup);
+    report = report_next;
+  }
+
+  // todo learn how to duplicate timer
+  // reports_new->reporttimer
+
+  return reports_new;
+}
+
 void BKE_report(ReportList *reports, ReportType type, const char *_message)
 {
   Report *report;
diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c
index b251258d84d..d956d5ba1b5 100644
--- a/source/blender/editors/space_info/info_report.c
+++ b/source/blender/editors/space_info/info_report.c
@@ -412,17 +412,58 @@ void INFO_OT_report_copy(wmOperatorType *ot)
   /* properties */
 }
 
+/** Return newly allocated ReportList created from log records */
 ReportList *clog_to_report_list()
 {
-  ReportList *reports = MEM_mallocN(sizeof(ReportList), "ClogConvertedToReportList");
+  ReportList *reports = MEM_mallocN(sizeof(*reports), "ClogConvertedToReportList");
   BKE_reports_init(reports, RPT_STORE);
 
+  // todo there might be no logs in log records
   CLG_LogRecord *log = CLG_log_record_get()->first, *log_iter = NULL;
+
   while (log) {
-    BKE_report(reports, RPT_INFO, log->message);
-//    printf("  id: %s, %s\n", log->type->identifier, log->message);
+    DynStr *dynStr = BLI_dynstr_new();
+    // todo implement formatting filters
+    BLI_dynstr_append(dynStr, clg_severity_as_text(log->severity));
+    BLI_dynstr_append(dynStr, " (");
+    BLI_dynstr_append(dynStr, log->type->identifier);
+    BLI_dynstr_append(dynStr, "): ");
+    BLI_dynstr_append(dynStr, log->file_line);
+    BLI_dynstr_append(dynStr, " ");
+    BLI_dynstr_append(dynStr, log->function);
+    BLI_dynstr_append(dynStr, ":\n");
+    BLI_dynstr_append(dynStr, log->message);
+    char *cstr = BLI_dynstr_get_cstring(dynStr);
+    switch (log->severity) {
+      case CLG_SEVERITY_INFO:
+        BKE_report(reports, RPT_INFO, cstr);
+        break;
+      case CLG_SEVERITY_WARN:
+        BKE_report(reports, RPT_WARNING, cstr);
+        break;
+      case CLG_SEVERITY_ERROR:
+      case CLG_SEVERITY_FATAL:
+        BKE_report(reports, RPT_ERROR, cstr);
+        break;
+      default:
+        BKE_report(reports, RPT_INFO, cstr);
+        break;
+    }
+    MEM_freeN(cstr);
+    BLI_dynstr_free(dynStr);
     log_iter = log->next;
     log = log_iter;
   }
   return reports;
 }
+
+static void clog_timestamp_to_char()
+{
+  const uint64_t timestamp = 0;  // clg_timestamp_ticks_get() - type->ctx->timestamp_tick_start;
+  char timestamp_str[64];
+  const uint timestamp_len = snprintf(timestamp_str,
+                                      sizeof(timestamp_str),
+                                      "%" PRIu64 ".%03u ",
+                                      timestamp / 1000,
+                                      (uint)(timestamp % 1000));
+}
\ No newline at end of file
diff --git a/source/blender/editors/spac

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list