[Bf-blender-cvs] [ec6fcac6285] master: Cleanup/Refactor: Move ID deletion into its own .c file.

Bastien Montagne noreply at git.blender.org
Mon Feb 10 15:56:28 CET 2020


Commit: ec6fcac62856d7008ddc0af6575ec5fbad4fc363
Author: Bastien Montagne
Date:   Mon Feb 10 15:55:43 2020 +0100
Branches: master
https://developer.blender.org/rBec6fcac62856d7008ddc0af6575ec5fbad4fc363

Cleanup/Refactor: Move ID deletion into its own .c file.

Having functions defined in `BKE_lib_id.h` implemented into
`lib_remap.c` was confusing at best.

Besides trivial code splitting and header includes cleanup, had to add a
new `lib_intern.h` header for callbacks used by both remapping and
deletion code.

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

M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/lib_id_delete.c
A	source/blender/blenkernel/intern/lib_intern.h
M	source/blender/blenkernel/intern/lib_remap.c

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 4c3137fcbe5..e2be61269f9 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -136,6 +136,7 @@ set(SRC
   intern/layer.c
   intern/layer_utils.c
   intern/lib_id.c
+  intern/lib_id_delete.c
   intern/lib_override.c
   intern/lib_query.c
   intern/lib_remap.c
@@ -370,6 +371,7 @@ set(SRC
   intern/CCGSubSurf_inline.h
   intern/CCGSubSurf_intern.h
   intern/data_transfer_intern.h
+  intern/lib_intern.h
   intern/multires_inline.h
   intern/pbvh_intern.h
   intern/subdiv_converter.h
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
new file mode 100644
index 00000000000..8f4ae18c29e
--- /dev/null
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -0,0 +1,541 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bke
+ *
+ * Contains management of ID's for freeing & deletion.
+ */
+
+#include "CLG_log.h"
+
+#include "MEM_guardedalloc.h"
+
+/* all types are needed here, in order to do memory operations */
+#include "DNA_anim_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_brush_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_cachefile_types.h"
+#include "DNA_collection_types.h"
+#include "DNA_gpencil_types.h"
+#include "DNA_ipo_types.h"
+#include "DNA_key_types.h"
+#include "DNA_light_types.h"
+#include "DNA_lattice_types.h"
+#include "DNA_linestyle_types.h"
+#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meta_types.h"
+#include "DNA_movieclip_types.h"
+#include "DNA_mask_types.h"
+#include "DNA_node_types.h"
+#include "DNA_object_types.h"
+#include "DNA_lightprobe_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_speaker_types.h"
+#include "DNA_sound_types.h"
+#include "DNA_text_types.h"
+#include "DNA_vfont_types.h"
+#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
+#include "DNA_world_types.h"
+
+#include "BLI_utildefines.h"
+
+#include "BLI_listbase.h"
+
+#include "BKE_action.h"
+#include "BKE_armature.h"
+#include "BKE_brush.h"
+#include "BKE_camera.h"
+#include "BKE_cachefile.h"
+#include "BKE_collection.h"
+#include "BKE_curve.h"
+#include "BKE_fcurve.h"
+#include "BKE_font.h"
+#include "BKE_gpencil.h"
+#include "BKE_idprop.h"
+#include "BKE_image.h"
+#include "BKE_ipo.h"
+#include "BKE_key.h"
+#include "BKE_light.h"
+#include "BKE_lattice.h"
+#include "BKE_lib_id.h"
+#include "BKE_lib_override.h"
+#include "BKE_lib_remap.h"
+#include "BKE_linestyle.h"
+#include "BKE_mesh.h"
+#include "BKE_material.h"
+#include "BKE_main.h"
+#include "BKE_mask.h"
+#include "BKE_mball.h"
+#include "BKE_movieclip.h"
+#include "BKE_node.h"
+#include "BKE_object.h"
+#include "BKE_paint.h"
+#include "BKE_particle.h"
+#include "BKE_lightprobe.h"
+#include "BKE_speaker.h"
+#include "BKE_sound.h"
+#include "BKE_screen.h"
+#include "BKE_scene.h"
+#include "BKE_text.h"
+#include "BKE_texture.h"
+#include "BKE_workspace.h"
+#include "BKE_world.h"
+
+#include "lib_intern.h"
+
+#include "DEG_depsgraph.h"
+
+#ifdef WITH_PYTHON
+#  include "BPY_extern.h"
+#endif
+
+/* Not used currently. */
+// static CLG_LogRef LOG = {.identifier = "bke.lib.id.delete"};
+
+void BKE_libblock_free_data(ID *id, const bool do_id_user)
+{
+  if (id->properties) {
+    IDP_FreePropertyContent_ex(id->properties, do_id_user);
+    MEM_freeN(id->properties);
+  }
+
+  if (id->override_library) {
+    BKE_override_library_free(&id->override_library, do_id_user);
+  }
+
+  /* XXX TODO remove animdata handling from each type's freeing func,
+   * and do it here, like for copy! */
+}
+
+void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
+{
+  const short type = GS(id->name);
+  switch (type) {
+    case ID_SCE:
+      BKE_scene_free_ex((Scene *)id, false);
+      break;
+    case ID_LI:
+      BKE_library_free((Library *)id);
+      break;
+    case ID_OB:
+      BKE_object_free((Object *)id);
+      break;
+    case ID_ME:
+      BKE_mesh_free((Mesh *)id);
+      break;
+    case ID_CU:
+      BKE_curve_free((Curve *)id);
+      break;
+    case ID_MB:
+      BKE_mball_free((MetaBall *)id);
+      break;
+    case ID_MA:
+      BKE_material_free((Material *)id);
+      break;
+    case ID_TE:
+      BKE_texture_free((Tex *)id);
+      break;
+    case ID_IM:
+      BKE_image_free((Image *)id);
+      break;
+    case ID_LT:
+      BKE_lattice_free((Lattice *)id);
+      break;
+    case ID_LA:
+      BKE_light_free((Light *)id);
+      break;
+    case ID_CA:
+      BKE_camera_free((Camera *)id);
+      break;
+    case ID_IP: /* Deprecated. */
+      BKE_ipo_free((Ipo *)id);
+      break;
+    case ID_KE:
+      BKE_key_free((Key *)id);
+      break;
+    case ID_WO:
+      BKE_world_free((World *)id);
+      break;
+    case ID_SCR:
+      BKE_screen_free((bScreen *)id);
+      break;
+    case ID_VF:
+      BKE_vfont_free((VFont *)id);
+      break;
+    case ID_TXT:
+      BKE_text_free((Text *)id);
+      break;
+    case ID_SPK:
+      BKE_speaker_free((Speaker *)id);
+      break;
+    case ID_LP:
+      BKE_lightprobe_free((LightProbe *)id);
+      break;
+    case ID_SO:
+      BKE_sound_free((bSound *)id);
+      break;
+    case ID_GR:
+      BKE_collection_free((Collection *)id);
+      break;
+    case ID_AR:
+      BKE_armature_free((bArmature *)id);
+      break;
+    case ID_AC:
+      BKE_action_free((bAction *)id);
+      break;
+    case ID_NT:
+      ntreeFreeTree((bNodeTree *)id);
+      break;
+    case ID_BR:
+      BKE_brush_free((Brush *)id);
+      break;
+    case ID_PA:
+      BKE_particlesettings_free((ParticleSettings *)id);
+      break;
+    case ID_WM:
+      if (free_windowmanager_cb) {
+        free_windowmanager_cb(NULL, (wmWindowManager *)id);
+      }
+      break;
+    case ID_GD:
+      BKE_gpencil_free((bGPdata *)id, true);
+      break;
+    case ID_MC:
+      BKE_movieclip_free((MovieClip *)id);
+      break;
+    case ID_MSK:
+      BKE_mask_free((Mask *)id);
+      break;
+    case ID_LS:
+      BKE_linestyle_free((FreestyleLineStyle *)id);
+      break;
+    case ID_PAL:
+      BKE_palette_free((Palette *)id);
+      break;
+    case ID_PC:
+      BKE_paint_curve_free((PaintCurve *)id);
+      break;
+    case ID_CF:
+      BKE_cachefile_free((CacheFile *)id);
+      break;
+    case ID_WS:
+      BKE_workspace_free((WorkSpace *)id);
+      break;
+  }
+}
+
+/**
+ * Complete ID freeing, extended version for corner cases.
+ * Can override default (and safe!) freeing process, to gain some speed up.
+ *
+ * At that point, given id is assumed to not be used by any other data-block already
+ * (might not be actually true, in case e.g. several inter-related IDs get freed together...).
+ * However, they might still be using (referencing) other IDs, this code takes care of it if
+ * #LIB_TAG_NO_USER_REFCOUNT is not defined.
+ *
+ * \param bmain: #Main database containing the freed #ID,
+ * can be NULL in case it's a temp ID outside of any #Main.
+ * \param idv: Pointer to ID to be freed.
+ * \param flag: Set of \a LIB_ID_FREE_... flags controlling/overriding usual freeing process,
+ * 0 to get default safe behavior.
+ * \param use_flag_from_idtag: Still use freeing info flags from given #ID datablock,
+ * even if some overriding ones are passed in \a flag parameter.
+ */
+void BKE_id_free_ex(Main *bmain, void *idv, int flag, const bool use_flag_from_idtag)
+{
+  ID *id = idv;
+
+  if (use_flag_from_idtag) {
+    if ((id->tag & LIB_TAG_NO_MAIN) != 0) {
+      flag |= LIB_ID_FREE_NO_MAIN | LIB_ID_FREE_NO_UI_USER | LIB_ID_FREE_NO_DEG_TAG;
+    }
+    else {
+      flag &= ~LIB_ID_FREE_NO_MAIN;
+    }
+
+    if ((id->tag & LIB_TAG_NO_USER_REFCOUNT) != 0) {
+      flag |= LIB_ID_FREE_NO_USER_REFCOUNT;
+    }
+    else {
+      flag &= ~LIB_ID_FREE_NO_USER_REFCOUNT;
+    }
+
+    if ((id->tag & LIB_TAG_NOT_ALLOCATED) != 0) {
+      flag |= LIB_ID_FREE_NOT_ALLOCATED;
+    }
+    else {
+      flag &= ~LIB_ID_FREE_NOT_ALLOCATED;
+    }
+  }
+
+  BLI_assert((flag & LIB_ID_FREE_NO_MAIN) != 0 || bmain != NULL);
+  BLI_assert((flag & LIB_ID_FREE_NO_MAIN) != 0 || (flag & LIB_ID_FREE_NOT_ALLOCATED) == 0);
+  BLI_assert((flag & LIB_ID_FREE_NO_MAIN) != 0 || (flag & LIB_ID_FREE_NO_USER_REFCOUNT) == 0);
+
+  const short type = GS(id->name);
+
+  if (bmain && (flag & LIB_ID_FREE_NO_DEG_TAG) == 0) {
+    DEG_id_type_tag(bmain, type);
+  }
+
+#ifdef WITH_PYTHON
+#  ifdef WITH_PYTHON_SAFETY
+  BPY_id_release(id);
+#  endif
+  if (id->py_instance) {
+    BPY_DECREF_RNA_INVALIDATE(id->py_instance);
+  }
+#endif
+
+  if ((flag & LIB_ID_FREE_NO_USER_REFCOUNT) == 0) {
+    BKE_libblock_relink_ex(bmain, id, NULL, NULL, 0);
+  }
+
+  BKE_libblock_free_datablock(id, flag);
+
+  /* avoid notifying on removed data */
+  if ((flag & LIB_ID_FREE_NO_MAIN) == 0) {
+    BKE_main_lock(bmain);
+  }
+
+  if ((flag & LIB_ID_FREE_NO_UI_USER) == 0) {
+    if (free_notifier_reference_cb) {
+      free_notifier_reference_cb(id);
+    }
+
+    if (remap_editor_id_reference_cb) {
+      remap_editor_id_reference_cb(id, NULL);
+    }
+  }
+
+  if ((flag & LIB_ID_FREE_NO_MAIN) == 0) {
+    ListBase *lb = which_libbase(bmain, type);
+    BLI_remlink(lb, id);
+  }
+
+  BKE_libblock_free_data(id, (flag & LIB_ID_FREE_NO_USER_REFCOUNT) == 0);
+
+  if ((flag & LIB_ID_FREE_NO_MAIN) == 0) {
+    BKE_main_unlock(bmain);
+  }
+
+  if ((flag & LIB_ID_FREE_NOT_ALLOCATED) == 0) {
+    MEM_fre

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list