[Bf-blender-cvs] [4bef5f3df70] master: Cleanup: move some undo related files to C++

Jacques Lucke noreply at git.blender.org
Mon Jan 23 00:54:09 CET 2023


Commit: 4bef5f3df700b43012667c58a74a25a2e252a670
Author: Jacques Lucke
Date:   Mon Jan 23 00:32:39 2023 +0100
Branches: master
https://developer.blender.org/rB4bef5f3df700b43012667c58a74a25a2e252a670

Cleanup: move some undo related files to C++

For continued testing in D14139. Also see T103343.

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

M	source/blender/blenkernel/BKE_undo_system.h
M	source/blender/blenkernel/CMakeLists.txt
R085	source/blender/blenkernel/intern/blender_undo.c	source/blender/blenkernel/intern/blender_undo.cc
R088	source/blender/blenkernel/intern/blendfile.c	source/blender/blenkernel/intern/blendfile.cc
R086	source/blender/blenkernel/intern/undo_system.c	source/blender/blenkernel/intern/undo_system.cc
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/tests/blendfile_loading_base_test.cc
M	source/blender/editors/armature/CMakeLists.txt
R090	source/blender/editors/armature/editarmature_undo.c	source/blender/editors/armature/editarmature_undo.cc
M	source/blender/editors/curve/CMakeLists.txt
M	source/blender/editors/curve/curve_intern.h
R089	source/blender/editors/curve/editcurve_undo.c	source/blender/editors/curve/editcurve_undo.cc
M	source/blender/editors/gpencil/CMakeLists.txt
R085	source/blender/editors/gpencil/gpencil_undo.c	source/blender/editors/gpencil/gpencil_undo.cc
M	source/blender/editors/include/ED_armature.h
M	source/blender/editors/include/ED_curve.h
M	source/blender/editors/include/ED_sculpt.h
M	source/blender/editors/include/ED_text.h
M	source/blender/editors/sculpt_paint/CMakeLists.txt
R091	source/blender/editors/sculpt_paint/sculpt_undo.c	source/blender/editors/sculpt_paint/sculpt_undo.cc
M	source/blender/editors/space_text/CMakeLists.txt
M	source/blender/editors/space_text/text_intern.h
R086	source/blender/editors/space_text/text_undo.c	source/blender/editors/space_text/text_undo.cc
M	source/blender/editors/undo/CMakeLists.txt
R089	source/blender/editors/undo/ed_undo.c	source/blender/editors/undo/ed_undo.cc
R090	source/blender/editors/undo/memfile_undo.c	source/blender/editors/undo/memfile_undo.cc
R091	source/blender/editors/undo/undo_intern.h	source/blender/editors/undo/undo_intern.hh
R098	source/blender/editors/undo/undo_system_types.c	source/blender/editors/undo/undo_system_types.cc
M	source/blender/editors/uvedit/uvedit_clipboard.cc
M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
R087	source/blender/windowmanager/intern/wm_files.c	source/blender/windowmanager/intern/wm_files.cc
R091	source/blender/windowmanager/intern/wm_init_exit.c	source/blender/windowmanager/intern/wm_init_exit.cc
M	source/blender/windowmanager/intern/wm_platform_support.h
M	source/blender/windowmanager/intern/wm_window.c
M	source/blender/windowmanager/wm.h
M	source/blender/windowmanager/wm_files.h

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

diff --git a/source/blender/blenkernel/BKE_undo_system.h b/source/blender/blenkernel/BKE_undo_system.h
index 5d1a27f8ba0..365a3a86b7c 100644
--- a/source/blender/blenkernel/BKE_undo_system.h
+++ b/source/blender/blenkernel/BKE_undo_system.h
@@ -93,6 +93,7 @@ typedef enum eUndoPushReturn {
   UNDO_PUSH_RET_SUCCESS = (1 << 0),
   UNDO_PUSH_RET_OVERRIDE_CHANGED = (1 << 1),
 } eUndoPushReturn;
+ENUM_OPERATORS(eUndoPushReturn, UNDO_PUSH_RET_OVERRIDE_CHANGED)
 
 typedef void (*UndoTypeForEachIDRefFn)(void *user_data, struct UndoRefID *id_ref);
 
@@ -137,7 +138,7 @@ typedef struct UndoType {
 
   /**
    * The size of the undo struct 'inherited' from #UndoStep for that specific type. Used for
-   * generic allocation in BKE's `undo_system.c`. */
+   * generic allocation in BKE's `undo_system.cc`. */
   size_t step_size;
 } UndoType;
 
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 8d6fe6c3cf7..1f4ab73911a 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -78,9 +78,9 @@ set(SRC
   intern/autoexec.c
   intern/blender.c
   intern/blender_copybuffer.c
-  intern/blender_undo.c
+  intern/blender_undo.cc
   intern/blender_user_menu.c
-  intern/blendfile.c
+  intern/blendfile.cc
   intern/blendfile_link_append.c
   intern/boids.c
   intern/bpath.c
@@ -296,7 +296,7 @@ set(SRC
   intern/tracking_stabilize.c
   intern/tracking_util.c
   intern/type_conversions.cc
-  intern/undo_system.c
+  intern/undo_system.cc
   intern/unit.c
   intern/vfont.c
   intern/vfontdata_freetype.c
diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.cc
similarity index 85%
rename from source/blender/blenkernel/intern/blender_undo.c
rename to source/blender/blenkernel/intern/blender_undo.cc
index f22dfc6054a..9f548c539c7 100644
--- a/source/blender/blenkernel/intern/blender_undo.c
+++ b/source/blender/blenkernel/intern/blender_undo.cc
@@ -63,10 +63,10 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
   G.fileflags |= G_FILE_NO_UI;
 
   if (UNDO_DISK) {
-    const struct BlendFileReadParams params = {0};
-    BlendFileReadReport bf_reports = {.reports = NULL};
+    const BlendFileReadParams params{};
+    BlendFileReadReport bf_reports{};
     struct BlendFileData *bfd = BKE_blendfile_read(mfu->filepath, &params, &bf_reports);
-    if (bfd != NULL) {
+    if (bfd != nullptr) {
       BKE_blendfile_read_setup(C, bfd, &params, &bf_reports);
       success = true;
     }
@@ -77,10 +77,11 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
     if (!use_old_bmain_data) {
       params.skip_flags |= BLO_READ_SKIP_UNDO_OLD_MAIN;
     }
+    BlendFileReadReport blend_file_read_report{};
     struct BlendFileData *bfd = BKE_blendfile_read_from_memfile(
-        bmain, &mfu->memfile, &params, NULL);
-    if (bfd != NULL) {
-      BKE_blendfile_read_setup(C, bfd, &params, &(BlendFileReadReport){NULL});
+        bmain, &mfu->memfile, &params, nullptr);
+    if (bfd != nullptr) {
+      BKE_blendfile_read_setup(C, bfd, &params, &blend_file_read_report);
       success = true;
     }
   }
@@ -100,7 +101,7 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
 
 MemFileUndoData *BKE_memfile_undo_encode(Main *bmain, MemFileUndoData *mfu_prev)
 {
-  MemFileUndoData *mfu = MEM_callocN(sizeof(MemFileUndoData), __func__);
+  MemFileUndoData *mfu = MEM_cnew<MemFileUndoData>(__func__);
 
   /* Include recovery information since undo-data is written out as #BLENDER_QUIT_FILE. */
   const int fileflags = G.fileflags | G_FILE_RECOVER_WRITE;
@@ -118,13 +119,14 @@ MemFileUndoData *BKE_memfile_undo_encode(Main *bmain, MemFileUndoData *mfu_prev)
     BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter);
     BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_session(), numstr);
 
+    const BlendFileWriteParams blend_file_write_params{};
     /* success = */ /* UNUSED */ BLO_write_file(
-        bmain, filepath, fileflags, &(const struct BlendFileWriteParams){0}, NULL);
+        bmain, filepath, fileflags, &blend_file_write_params, nullptr);
 
     BLI_strncpy(mfu->filepath, filepath, sizeof(mfu->filepath));
   }
   else {
-    MemFile *prevfile = (mfu_prev) ? &(mfu_prev->memfile) : NULL;
+    MemFile *prevfile = (mfu_prev) ? &(mfu_prev->memfile) : nullptr;
     if (prevfile) {
       BLO_memfile_clear_future(prevfile);
     }
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.cc
similarity index 88%
rename from source/blender/blenkernel/intern/blendfile.c
rename to source/blender/blenkernel/intern/blendfile.cc
index f4421fc0d1c..9ccd3e7541a 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.cc
@@ -83,7 +83,7 @@ static bool blendfile_or_libraries_versions_atleast(Main *bmain,
   return true;
 }
 
-static bool foreach_path_clean_cb(BPathForeachPathData *UNUSED(bpath_data),
+static bool foreach_path_clean_cb(BPathForeachPathData * /*bpath_data*/,
                                   char *path_dst,
                                   const char *path_src)
 {
@@ -95,12 +95,13 @@ static bool foreach_path_clean_cb(BPathForeachPathData *UNUSED(bpath_data),
 /* make sure path names are correct for OS */
 static void clean_paths(Main *bmain)
 {
-  BKE_bpath_foreach_path_main(&(BPathForeachPathData){
-      .bmain = bmain,
-      .callback_function = foreach_path_clean_cb,
-      .flag = BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE,
-      .user_data = NULL,
-  });
+  BPathForeachPathData foreach_path_data{};
+  foreach_path_data.bmain = bmain;
+  foreach_path_data.callback_function = foreach_path_clean_cb;
+  foreach_path_data.flag = BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE;
+  foreach_path_data.user_data = nullptr;
+
+  BKE_bpath_foreach_path_main(&foreach_path_data);
 
   LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
     BLI_path_slash_native(scene->r.pic);
@@ -110,7 +111,7 @@ static void clean_paths(Main *bmain)
 static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene)
 {
   wmWindow *win;
-  for (win = wm->windows.first; win; win = win->next) {
+  for (win = static_cast<wmWindow *>(wm->windows.first); win; win = win->next) {
     if (win->scene == scene) {
       return true;
     }
@@ -123,7 +124,7 @@ static void setup_app_userdef(BlendFileData *bfd)
   if (bfd->user) {
     /* only here free userdef themes... */
     BKE_blender_userdef_data_set_and_free(bfd->user);
-    bfd->user = NULL;
+    bfd->user = nullptr;
 
     /* Security issue: any blend file could include a USER block.
      *
@@ -151,7 +152,7 @@ static void setup_app_data(bContext *C,
                            BlendFileReadReport *reports)
 {
   Main *bmain = G_MAIN;
-  Scene *curscene = NULL;
+  Scene *curscene = nullptr;
   const bool recover = (G.fileflags & G_FILE_RECOVER_READ) != 0;
   const bool is_startup = params->is_startup;
   enum {
@@ -161,12 +162,12 @@ static void setup_app_data(bContext *C,
   } mode;
 
   if (params->undo_direction != STEP_INVALID) {
-    BLI_assert(bfd->curscene != NULL);
+    BLI_assert(bfd->curscene != nullptr);
     mode = LOAD_UNDO;
   }
-  /* may happen with library files - UNDO file should never have NULL curscene (but may have a
-   * NULL curscreen)... */
-  else if (ELEM(NULL, bfd->curscreen, bfd->curscene)) {
+  /* may happen with library files - UNDO file should never have nullptr curscene (but may have a
+   * nullptr curscreen)... */
+  else if (ELEM(nullptr, bfd->curscreen, bfd->curscene)) {
     BKE_report(reports->reports, RPT_WARNING, "Library file, loading empty scene");
     mode = LOAD_UI_OFF;
   }
@@ -205,7 +206,7 @@ static void setup_app_data(bContext *C,
      * see: T43424
      */
     wmWindow *win;
-    bScreen *curscreen = NULL;
+    bScreen *curscreen = nullptr;
     ViewLayer *cur_view_layer;
     bool track_undo_scene;
 
@@ -213,10 +214,10 @@ static void setup_app_data(bContext *C,
     SWAP(ListBase, bmain->wm, bfd->main->wm);
     SWAP(ListBase, bmain->workspaces, bfd->main->workspaces);
     SWAP(ListBase, bmain->screens, bfd->main->screens);
-    if (bmain->name_map != NULL) {
+    if (bmain->name_map != nullptr) {
       BKE_main_namemap_destroy(&bmain->name_map);
     }
-    if (bfd->main->name_map != NULL) {
+    if (bfd->main->name_map != nullptr) {
       BKE_main_namemap_destroy(&bfd->main->name_map);
     }
 
@@ -250,14 +251,14 @@ static void setup_app_data(bContext *C,
 
     track_undo_scene = (mode == LOAD_UNDO && curscreen && curscene && bfd->main->wm.first);
 
-    if (curscene == NULL) {
-      curscene = bfd->main->scenes.first;
+    if (curscene == nullptr) {
+      curscene = static_cast<Scene *>(bfd->main->scenes.first);
     }
     /* empty file, we add a scene to make Blender work */
-    if (curscene == NULL) {
+    if (curscene == nullptr) {
       curscene = BKE_scene_add(bfd->main, "Empty");
     }
-    if (cur_view_layer == NULL) {
+    if (cur_view_layer == nullptr) {
       /* fallback to scene layer */
       cur_view_layer = BKE_view_layer_default_view(curscene);
     }
@@ -267,7 +268,7 @@ static void setup_app_data(bContext *C,
        * replace it with 'curscene' if its needed */
     }
     /* and we enforce curscene to be in current screen */
-    else if (win) { /* The window may be NULL in background-mode. */
+    else if (win) { /* The window may be nullptr in background-mode. */
       win->scene = curscene;
     }
 
@@ -278,7 +279,7 @@ static void setup_app_data(bContext *C,
     }
 
     if (track_undo_scene) {
-      wmWindowManager *wm = bfd->main->wm.first;
+      wmWindowManager *wm = static_cast<wmWindowManager *>(bfd->main->wm.first);
       if (wm_scene_is_visible(wm, bfd->curscene) == false) {
         curscene = bfd->curscene;
         win->scene = curscene;
@@ -296,7 +297,7 @@ static void setup_app_data(bContext *C,
 
   BKE_blender_globals_main_replace(bfd->main);
   bmain = G_MAIN;
-  bfd->main = NULL;
+  bfd->main = nullptr;
 
   CTX_data_main_set(C, bmain);
 
@@ -306,12 +307,12 @@ static void setup_app_data(bContext *C,
     CTX_data_scene_set(C, curscene);
   }
   else {
-    CTX_wm_manager_set(C, bmain->wm.first);
+    CTX_wm_manager_set(C, s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list