[Bf-blender-cvs] [0b3313e5323] master: Cleanup: LibOverride: Replace raw pointers checks by proper macros.

Bastien Montagne noreply at git.blender.org
Tue Jun 30 12:19:17 CEST 2020


Commit: 0b3313e53230914e79dd5c8f02b90fbaf6a8874b
Author: Bastien Montagne
Date:   Tue Jun 30 10:52:02 2020 +0200
Branches: master
https://developer.blender.org/rB0b3313e53230914e79dd5c8f02b90fbaf6a8874b

Cleanup: LibOverride: Replace raw pointers checks by proper macros.

This is cleaner, but also crucial to avoid weird issues when behaviors
of those checks are modified...

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

M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/interface/interface_ops.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/makesrna/intern/rna_access_compare_override.c

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

diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index b983249994b..7c09ae51344 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -1229,7 +1229,7 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int ori
 
   /* We may need our own flag to control that at some point, but for now 'no main' one should be
    * good enough. */
-  if ((orig_flag & LIB_ID_CREATE_NO_MAIN) == 0 && id->override_library != NULL) {
+  if ((orig_flag & LIB_ID_CREATE_NO_MAIN) == 0 && ID_IS_OVERRIDE_LIBRARY(id)) {
     /* We do not want to copy existing override rules here, as they would break the proper
      * remapping between IDs. Proper overrides rules will be re-generated anyway. */
     BKE_lib_override_library_copy(new_id, id, false);
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index f30a82fb9f6..ec353bb82fc 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -114,7 +114,7 @@ IDOverrideLibrary *BKE_lib_override_library_init(ID *local_id, ID *reference_id)
 /** Shalow or deep copy of a whole override from \a src_id to \a dst_id. */
 void BKE_lib_override_library_copy(ID *dst_id, const ID *src_id, const bool do_full_copy)
 {
-  BLI_assert(src_id->override_library != NULL);
+  BLI_assert(ID_IS_OVERRIDE_LIBRARY(src_id));
 
   if (dst_id->override_library != NULL) {
     if (src_id->override_library == NULL) {
@@ -620,7 +620,7 @@ bool BKE_lib_override_library_property_operation_operands_validate(
  * \return true if status is OK, false otherwise. */
 bool BKE_lib_override_library_status_check_local(Main *bmain, ID *local)
 {
-  BLI_assert(local->override_library != NULL);
+  BLI_assert(ID_IS_OVERRIDE_LIBRARY(local));
 
   ID *reference = local->override_library->reference;
 
@@ -676,7 +676,7 @@ bool BKE_lib_override_library_status_check_local(Main *bmain, ID *local)
  * \return true if status is OK, false otherwise. */
 bool BKE_lib_override_library_status_check_reference(Main *bmain, ID *local)
 {
-  BLI_assert(local->override_library != NULL);
+  BLI_assert(ID_IS_OVERRIDE_LIBRARY(local));
 
   ID *reference = local->override_library->reference;
 
@@ -895,7 +895,7 @@ void BKE_lib_override_library_main_tag(struct Main *bmain, const short tag, cons
 /** Remove all tagged-as-unused properties and operations from that ID override data. */
 void BKE_lib_override_library_id_unused_cleanup(struct ID *local)
 {
-  if (local->override_library != NULL) {
+  if (ID_IS_OVERRIDE_LIBRARY(local)) {
     LISTBASE_FOREACH_MUTABLE (
         IDOverrideLibraryProperty *, op, &local->override_library->properties) {
       if (op->tag & IDOVERRIDE_LIBRARY_TAG_UNUSED) {
@@ -928,7 +928,7 @@ void BKE_lib_override_library_main_unused_cleanup(struct Main *bmain)
 /** Update given override from its reference (re-applying overridden properties). */
 void BKE_lib_override_library_update(Main *bmain, ID *local)
 {
-  if (local->override_library == NULL || local->override_library->reference == NULL) {
+  if (!ID_IS_OVERRIDE_LIBRARY(local)) {
     return;
   }
 
@@ -1054,15 +1054,14 @@ ID *BKE_lib_override_library_operations_store_start(Main *bmain,
                                                     OverrideLibraryStorage *override_storage,
                                                     ID *local)
 {
-  BLI_assert(local->override_library != NULL);
-  BLI_assert(override_storage != NULL);
-  const bool is_template = (local->override_library->reference == NULL);
-
-  if (is_template) {
+  if (ID_IS_OVERRIDE_LIBRARY_TEMPLATE(local)) {
     /* This is actually purely local data with an override template, nothing to do here! */
     return NULL;
   }
 
+  BLI_assert(ID_IS_OVERRIDE_LIBRARY(local));
+  BLI_assert(override_storage != NULL);
+
   /* Forcefully ensure we know about all needed override operations. */
   BKE_lib_override_library_operations_create(bmain, local);
 
@@ -1106,7 +1105,7 @@ ID *BKE_lib_override_library_operations_store_start(Main *bmain,
 void BKE_lib_override_library_operations_store_end(
     OverrideLibraryStorage *UNUSED(override_storage), ID *local)
 {
-  BLI_assert(local->override_library != NULL);
+  BLI_assert(ID_IS_OVERRIDE_LIBRARY(local));
 
   /* Nothing else to do here really, we need to keep all temp override storage data-blocks in
    * memory until whole file is written anyway (otherwise we'd get mem pointers overlap...). */
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 83c587cc446..86e878147e5 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -4070,7 +4070,8 @@ static bool write_file_handle(Main *mainvar,
         BLI_assert(
             (id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
 
-        const bool do_override = !ELEM(override_storage, NULL, bmain) && id->override_library;
+        const bool do_override = !ELEM(override_storage, NULL, bmain) &&
+                                 ID_IS_OVERRIDE_LIBRARY(id);
 
         if (do_override) {
           BKE_lib_override_library_operations_store_start(bmain, override_storage, id);
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index d7f7f02c535..cb8f8be6361 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -613,7 +613,7 @@ static bool override_remove_button_poll(bContext *C)
 
   UI_context_active_but_prop_get(C, &ptr, &prop, &index);
 
-  const int override_status = RNA_property_override_library_status(&ptr, prop, index);
+  const uint override_status = RNA_property_override_library_status(&ptr, prop, index);
 
   return (ptr.data && ptr.owner_id && prop && (override_status & RNA_OVERRIDE_STATUS_OVERRIDDEN));
 }
@@ -634,7 +634,7 @@ static int override_remove_button_exec(bContext *C, wmOperator *op)
   BLI_assert(oprop != NULL);
   BLI_assert(id != NULL && id->override_library != NULL);
 
-  const bool is_template = (id->override_library->reference == NULL);
+  const bool is_template = ID_IS_OVERRIDE_LIBRARY_TEMPLATE(id);
 
   /* We need source (i.e. linked data) to restore values of deleted overrides...
    * If this is an override template, we obviously do not need to restore anything. */
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index de5894388a6..75706653a7c 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -584,7 +584,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
       }
       break;
     case UI_ID_OVERRIDE:
-      if (id && id->override_library) {
+      if (id && ID_IS_OVERRIDE_LIBRARY(id)) {
         BKE_lib_override_library_free(&id->override_library, true);
         /* reassign to get get proper updates/notifiers */
         idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop);
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index b7090f4fb56..cb9679ad925 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -2064,9 +2064,10 @@ bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop_orig)
   PropertyRNA *prop = rna_ensure_property(prop_orig);
   flag = prop->editable ? prop->editable(ptr, &dummy_info) : prop->flag;
 
-  return ((flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0 &&
-          (!id || ((!ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)) &&
-                   (!id->override_library || RNA_property_overridable_get(ptr, prop_orig)))));
+  return (
+      (flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0 &&
+      (!id || ((!ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)) &&
+               (!ID_IS_OVERRIDE_LIBRARY(id) || RNA_property_overridable_get(ptr, prop_orig)))));
 }
 
 /**
@@ -2100,7 +2101,7 @@ bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char *
       }
       return false;
     }
-    if (id->override_library != NULL) {
+    if (ID_IS_OVERRIDE_LIBRARY(id)) {
       /* We need the real data property in case of IDProperty here... */
       PropertyRNA *real_prop = rna_ensure_property_realdata(&prop, ptr);
       if (real_prop == NULL || !RNA_property_overridable_get(ptr, real_prop)) {
diff --git a/source/blender/makesrna/intern/rna_access_compare_override.c b/source/blender/makesrna/intern/rna_access_compare_override.c
index 28ee5eca723..cc4daf017eb 100644
--- a/source/blender/makesrna/intern/rna_access_compare_override.c
+++ b/source/blender/makesrna/intern/rna_access_compare_override.c
@@ -108,7 +108,7 @@ bool RNA_property_overridden(PointerRNA *ptr, PropertyRNA *prop)
   char *rna_path = RNA_path_from_ID_to_property(ptr, prop);
   ID *id = ptr->owner_id;
 
-  if (rna_path == NULL || id == NULL || id->override_library == NULL) {
+  if (rna_path == NULL || id == NULL || !ID_IS_OVERRIDE_LIBRARY(id)) {
     return false;
   }
 
@@ -1156,7 +1156,7 @@ eRNAOverrideStatus RNA_property_override_library_status(PointerRNA *ptr,
     return override_status;
   }
 
-  if (!ptr || !prop || !ptr->owner_id || !(ptr->owner_id)->override_library) {
+  if (!ptr || !prop || !ptr->owner_id || !ID_IS_OVERRIDE_LIBRARY(ptr->owner_id)) {
     return override_status;
   }



More information about the Bf-blender-cvs mailing list