[Bf-blender-cvs] [093532b7390] soc-2020-info-editor: Address comments
Mateusz GrzeliÅski
noreply at git.blender.org
Tue Jun 30 17:24:57 CEST 2020
Commit: 093532b7390ab79cc7bca86da03915e899433184
Author: Mateusz Grzeliński
Date: Mon Jun 29 14:51:04 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rB093532b7390ab79cc7bca86da03915e899433184
Address comments
- rename enum
- duplicate memory in info ed
- encapsulate g_ctx
===================================================================
M intern/clog/CLG_log.h
M intern/clog/clog.c
M source/blender/editors/space_info/info_report.c
M source/blender/editors/space_info/space_info.c
M source/blender/makesdna/DNA_space_types.h
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 749cfb0d42d..771ae1ca24a 100644
--- a/intern/clog/CLG_log.h
+++ b/intern/clog/CLG_log.h
@@ -85,21 +85,16 @@ extern "C" {
# define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param)
#endif
-
/* For printing timestamp. */
#define __STDC_FORMAT_MACROS
#include <DNA_windowmanager_types.h>
#include <inttypes.h>
-#include "BLI_blenlib.h"
-#include "DNA_listBase.h"
-
#define STRINGIFY_ARG(x) "" #x
#define STRINGIFY_APPEND(a, b) "" a #b
#define STRINGIFY(x) STRINGIFY_APPEND("", x)
struct CLogContext;
-extern struct CLogContext *g_ctx;
/* Don't typedef enums. */
enum CLG_LogFlag {
@@ -130,15 +125,6 @@ typedef struct CLG_LogRef {
CLG_LogType *type;
} CLG_LogRef;
-/* -------------------------------------------------------------------- */
-/** \name Internal Types
- * \{ */
-
-typedef struct CLG_IDFilter {
- struct CLG_IDFilter *next;
- /** Over alloc. */
- char match[0];
-} CLG_IDFilter;
typedef struct CLG_LogRecord {
/** Link for ListBase */
@@ -153,42 +139,6 @@ typedef struct CLG_LogRecord {
const char *message;
} CLG_LogRecord;
-typedef struct CLogContext {
- /** Single linked list of types. */
- CLG_LogType *types;
- ListBase log_records;
-
-#ifdef WITH_CLOG_PTHREADS
- pthread_mutex_t types_lock;
-#endif
-
- /* exclude, include filters. */
- CLG_IDFilter *filters[2];
- bool use_color;
- bool use_basename;
- bool use_timestamp;
-
- /** Borrowed, not owned. */
- int output;
- FILE *output_file;
-
- /** For timer (use_timestamp). */
- uint64_t timestamp_tick_start;
-
- /** For new types. */
- struct {
- int level;
- } default_type;
-
- struct {
- void (*fatal_fn)(void *file_handle);
- void (*backtrace_fn)(void *file_handle);
- } callbacks;
-
-} CLogContext;
-
-/** \} */
-
void CLG_log_str(CLG_LogType *lg,
enum CLG_Severity severity,
const char *file_line,
@@ -223,6 +173,7 @@ void CLG_type_filter_include(const char *type_filter, int type_filter_len);
void CLG_type_filter_exclude(const char *type_filter, int type_filter_len);
void CLG_level_set(int level);
+struct ListBase *CLG_log_record_get(void );
void CLG_logref_init(CLG_LogRef *clg_ref);
diff --git a/intern/clog/clog.c b/intern/clog/clog.c
index dca520e4a67..68607a38cc5 100644
--- a/intern/clog/clog.c
+++ b/intern/clog/clog.c
@@ -42,13 +42,16 @@
# include <windows.h>
#endif
+/* For printing timestamp. */
+#define __STDC_FORMAT_MACROS
+#include <DNA_windowmanager_types.h>
+#include <inttypes.h>
+
/* Only other dependency (could use regular malloc too). */
#include "MEM_guardedalloc.h"
/* own include. */
-#include "../../source/blender/blenkernel/BKE_report.h"
#include "../../source/blender/blenlib/BLI_blenlib.h"
-#include "../../source/blender/makesdna/DNA_listBase.h"
#include "CLG_log.h"
/* Local utility defines */
@@ -61,6 +64,52 @@
# define PATHSEP_CHAR '/'
#endif
+/* -------------------------------------------------------------------- */
+/** \name Internal Types
+ * \{ */
+
+typedef struct CLG_IDFilter {
+ struct CLG_IDFilter *next;
+ /** Over alloc. */
+ char match[0];
+} CLG_IDFilter;
+
+typedef struct CLogContext {
+ /** Single linked list of types. */
+ CLG_LogType *types;
+ ListBase log_records;
+
+#ifdef WITH_CLOG_PTHREADS
+ pthread_mutex_t types_lock;
+#endif
+
+ /* exclude, include filters. */
+ CLG_IDFilter *filters[2];
+ bool use_color;
+ bool use_basename;
+ bool use_timestamp;
+
+ /** Borrowed, not owned. */
+ int output;
+ FILE *output_file;
+
+ /** For timer (use_timestamp). */
+ uint64_t timestamp_tick_start;
+
+ /** For new types. */
+ struct {
+ int level;
+ } default_type;
+
+ struct {
+ void (*fatal_fn)(void *file_handle);
+ void (*backtrace_fn)(void *file_handle);
+ } callbacks;
+
+} CLogContext;
+
+/** \} */
+
/* -------------------------------------------------------------------- */
/** \name Mini Buffer Functionality
*
@@ -339,9 +388,7 @@ CLG_LogRecord *clog_log_record_init(CLG_LogType *type,
const char *function,
const char *message)
{
- CLG_LogRecord *log_record = MEM_callocN(sizeof(CLG_LogRecord), "ClogRecord"); // MEM_mallocN
- log_record->next = NULL;
- log_record->prev = NULL;
+ 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;
@@ -600,16 +647,19 @@ static void CLG_ctx_level_set(CLogContext *ctx, int level)
}
}
+static ListBase *CLG_ctx_log_record_get(CLogContext *ctx)
+{
+ return &ctx->log_records;
+}
+
static CLogContext *CLG_ctx_init(void)
{
- CLogContext *ctx = MEM_callocN(sizeof(CLogContext), __func__);
+ CLogContext *ctx = MEM_callocN(sizeof(*ctx), __func__);
#ifdef WITH_CLOG_PTHREADS
pthread_mutex_init(&ctx->types_lock, NULL);
#endif
ctx->use_color = true;
ctx->default_type.level = 1;
- ctx->log_records.first = NULL;
- ctx->log_records.last = NULL;
CLG_ctx_output_set(ctx, stdout);
return ctx;
@@ -623,6 +673,7 @@ static void CLG_ctx_free(CLogContext *ctx)
clog_log_record_free(log);
log = log_next;
}
+ BLI_listbase_clear(&ctx->log_records);
while (ctx->types != NULL) {
CLG_LogType *item = ctx->types;
@@ -706,6 +757,11 @@ void CLG_level_set(int level)
CLG_ctx_level_set(g_ctx, level);
}
+ListBase *CLG_log_record_get()
+{
+ return CLG_ctx_log_record_get(g_ctx);
+}
+
/** \} */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c
index 11f8b0169a8..b251258d84d 100644
--- a/source/blender/editors/space_info/info_report.c
+++ b/source/blender/editors/space_info/info_report.c
@@ -154,9 +154,9 @@ static int select_report_pick_exec(bContext *C, wmOperator *op)
bool extend = RNA_boolean_get(op->ptr, "extend");
SpaceInfo *sinfo = CTX_wm_space_info(C);
- Report *report = BLI_findlink(&sinfo->active_reports->list, report_index);
-
ReportList *reports = sinfo->active_reports;
+ Report *report = BLI_findlink(&reports->list, report_index);
+
const int report_mask = info_report_mask(sinfo);
if (!report) {
return OPERATOR_CANCELLED;
@@ -417,7 +417,7 @@ ReportList *clog_to_report_list()
ReportList *reports = MEM_mallocN(sizeof(ReportList), "ClogConvertedToReportList");
BKE_reports_init(reports, RPT_STORE);
- CLG_LogRecord *log = g_ctx->log_records.first, *log_iter = NULL;
+ 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);
diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c
index b0a47366779..7b2b9f0396c 100644
--- a/source/blender/editors/space_info/space_info.c
+++ b/source/blender/editors/space_info/space_info.c
@@ -94,7 +94,7 @@ static SpaceLink *info_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scen
static void info_free(SpaceLink *sl)
{
SpaceInfo *sinfo = (SpaceInfo *)sl;
- if (sinfo->view == INFO_VIEW_G_CLOG) {
+ if (sinfo->view == INFO_VIEW_CLOG) {
BKE_reports_clear(sinfo->active_reports);
MEM_freeN(sinfo->active_reports);
}
@@ -110,14 +110,14 @@ static void info_init(struct wmWindowManager *wm, ScrArea *area)
static SpaceLink *info_duplicate(SpaceLink *sl)
{
- SpaceInfo *sinfo = MEM_dupallocN(sl);
- if (sinfo->view == INFO_VIEW_G_CLOG) {
- // todo duplicate memory?
+ SpaceInfo *sinfo_old = (SpaceInfo *)sl;
+ SpaceInfo *sinfo_new = MEM_dupallocN(sl);
+ if (sinfo_new->view == INFO_VIEW_CLOG) {
+ sinfo_new = MEM_dupallocN(sinfo_old->active_reports);
+ BLI_duplicatelist(&sinfo_new->active_reports->list, &sinfo_old->active_reports->list);
}
- /* clear or remove stuff from old */
-
- return (SpaceLink *)sinfo;
+ return (SpaceLink *)sinfo_new;
}
/* add handlers, stuff you only do once or on area/region changes */
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index c874cfdc0c4..4042b209bee 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -123,7 +123,7 @@ typedef struct SpaceInfo {
typedef enum eSpaceInfo_View {
INFO_VIEW_REPORTS,
- INFO_VIEW_G_CLOG,
+ INFO_VIEW_CLOG,
} eSpaceInfo_View;
/* SpaceInfo.clog_show */
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 27c7844ac2e..1bbca47eb4f 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -6091,7 +6091,7 @@ static void rna_def_space_info(BlenderRNA *brna)
static const EnumPropertyItem view_type_items[] = {
{INFO_VIEW_REPORTS, "REPORTS", 0, "Reports", ""},
- {INFO_VIEW_G_CLOG, "CLOGS", 0, "Logs", ""},
+ {INFO_VIEW_CLOG, "CLOGS", 0, "Logs", ""},
{0, NULL, 0, NULL, NULL},
};
prop = RNA_def_property(srna, "view", PROP_ENUM, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_space_api.c b/source/blender/makesrna/intern/rna_space_api.c
index 71e22cb5636..141d795bba1 100644
--- a/source/blender/makesrna/intern/rna_space_api.c
+++ b/source/blender/makesrna/intern/rna_space_api.c
@@ -43,7 +43,7 @@ void rna_InfoEditorView_update(struct bContext *C, struct PointerRNA *ptr)
sinfo->active_reports = CTX_wm_reports(C);
break;
}
- case INFO_VIEW_G_CLOG: {
+ case INFO_VIEW_CLOG: {
sinfo->active_reports = clog_to_report_list();
break;
}
More information about the Bf-blender-cvs
mailing list