Refactor libquery ID looper callback to take a single parameter.
authorBastien Montagne <b.mont29@gmail.com>
Thu, 13 Feb 2020 11:56:10 +0000 (12:56 +0100)
committerBastien Montagne <b.mont29@gmail.com>
Thu, 13 Feb 2020 15:23:42 +0000 (16:23 +0100)
Using a struct here allows to change given parameters to the callbacks
without having to edit all callbacks functions, which is always noisy
and time consuming.

12 files changed:
source/blender/blenkernel/BKE_lib_query.h
source/blender/blenkernel/intern/lib_id.c
source/blender/blenkernel/intern/lib_query.c
source/blender/blenkernel/intern/lib_remap.c
source/blender/blenkernel/intern/main.c
source/blender/blenkernel/intern/mesh_convert.c
source/blender/blenloader/intern/readfile.c
source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
source/blender/editors/object/object_relations.c
source/blender/editors/render/render_opengl.c
source/blender/python/intern/bpy_rna_id_collection.c
source/blender/windowmanager/intern/wm_operators.c

index 36aa69bf7953535bcffcb90a943db064f64209de..4d1b924b0d37880e155770266f3023bace0aaadb 100644 (file)
@@ -83,15 +83,19 @@ enum {
   IDWALK_RET_STOP_RECURSION = 1 << 1,
 };
 
+typedef struct LibraryIDLinkCallbackData {
+  void *user_data;
+  struct ID *id_self;
+  struct ID **id_pointer;
+  int cb_flag;
+} LibraryIDLinkCallbackData;
+
 /**
  * Call a callback for each ID link which the given ID uses.
  *
  * \return a set of flags to control further iteration (0 to keep going).
  */
-typedef int (*LibraryIDLinkCallback)(void *user_data,
-                                     struct ID *id_self,
-                                     struct ID **id_pointer,
-                                     int cb_flag);
+typedef int (*LibraryIDLinkCallback)(LibraryIDLinkCallbackData *cb_data);
 
 /* Flags for the foreach function itself. */
 enum {
index 18faf00d60f883e55a730132caf3b638189f8524..1cb5905cc94dd0c473b615db22887be5dd877ea0 100644 (file)
@@ -294,11 +294,11 @@ void BKE_id_clear_newpoin(ID *id)
   id->newid = NULL;
 }
 
-static int id_expand_local_callback(void *UNUSED(user_data),
-                                    struct ID *id_self,
-                                    struct ID **id_pointer,
-                                    int cb_flag)
+static int id_expand_local_callback(LibraryIDLinkCallbackData *cb_data)
 {
+  ID *id_self = cb_data->id_self;
+  ID **id_pointer = cb_data->id_pointer;
+  int const cb_flag = cb_data->cb_flag;
   if (cb_flag & IDWALK_CB_PRIVATE) {
     return IDWALK_RET_NOP;
   }
@@ -581,13 +581,12 @@ struct IDCopyLibManagementData {
 };
 
 /* Increases usercount as required, and remap self ID pointers. */
-static int id_copy_libmanagement_cb(void *user_data,
-                                    ID *UNUSED(id_self),
-                                    ID **id_pointer,
-                                    int cb_flag)
+static int id_copy_libmanagement_cb(LibraryIDLinkCallbackData *cb_data)
 {
-  struct IDCopyLibManagementData *data = user_data;
+  ID **id_pointer = cb_data->id_pointer;
   ID *id = *id_pointer;
+  const int cb_flag = cb_data->cb_flag;
+  struct IDCopyLibManagementData *data = cb_data->user_data;
 
   /* Remap self-references to new copied ID. */
   if (id == data->id_src) {
@@ -900,11 +899,10 @@ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop)
   return false;
 }
 
-static int libblock_management_us_plus(void *UNUSED(user_data),
-                                       ID *UNUSED(id_self),
-                                       ID **id_pointer,
-                                       int cb_flag)
+static int libblock_management_us_plus(LibraryIDLinkCallbackData *cb_data)
 {
+  ID **id_pointer = cb_data->id_pointer;
+  const int cb_flag = cb_data->cb_flag;
   if (cb_flag & IDWALK_CB_USER) {
     id_us_plus(*id_pointer);
   }
@@ -915,11 +913,10 @@ static int libblock_management_us_plus(void *UNUSED(user_data),
   return IDWALK_RET_NOP;
 }
 
-static int libblock_management_us_min(void *UNUSED(user_data),
-                                      ID *UNUSED(id_self),
-                                      ID **id_pointer,
-                                      int cb_flag)
+static int libblock_management_us_min(LibraryIDLinkCallbackData *cb_data)
 {
+  ID **id_pointer = cb_data->id_pointer;
+  const int cb_flag = cb_data->cb_flag;
   if (cb_flag & IDWALK_CB_USER) {
     id_us_min(*id_pointer);
   }
@@ -1978,12 +1975,11 @@ void BKE_main_id_clear_newpoins(Main *bmain)
   FOREACH_MAIN_ID_END;
 }
 
-static int id_refcount_recompute_callback(void *user_data,
-                                          struct ID *UNUSED(id_self),
-                                          struct ID **id_pointer,
-                                          int cb_flag)
+static int id_refcount_recompute_callback(LibraryIDLinkCallbackData *cb_data)
 {
-  const bool do_linked_only = (bool)POINTER_AS_INT(user_data);
+  ID **id_pointer = cb_data->id_pointer;
+  const int cb_flag = cb_data->cb_flag;
+  const bool do_linked_only = (bool)POINTER_AS_INT(cb_data->user_data);
 
   if (*id_pointer == NULL) {
     return IDWALK_RET_NOP;
index cf4c96a70e9a277c471d548624e6ae6fa7e5916f..44a8647fcebfb445e973c79f31271bff8d3ce58c 100644 (file)
   if (!((_data)->status & IDWALK_STOP)) { \
     const int _flag = (_data)->flag; \
     ID *old_id = *(id_pp); \
-    const int callback_return = (_data)->callback((_data)->user_data, \
-                                                  (_data)->self_id, \
-                                                  id_pp, \
-                                                  (_cb_flag | (_data)->cb_flag) & \
-                                                      ~(_data)->cb_flag_clear); \
+    const int callback_return = (_data)->callback(&(struct LibraryIDLinkCallbackData){ \
+        .user_data = (_data)->user_data, \
+        .id_self = (_data)->self_id, \
+        .id_pointer = id_pp, \
+        .cb_flag = ((_cb_flag | (_data)->cb_flag) & ~(_data)->cb_flag_clear)}); \
     if (_flag & IDWALK_READONLY) { \
       BLI_assert(*(id_pp) == old_id); \
     } \
@@ -1226,12 +1226,11 @@ typedef struct IDUsersIter {
   int count_direct, count_indirect; /* Set by callback. */
 } IDUsersIter;
 
-static int foreach_libblock_id_users_callback(void *user_data,
-                                              ID *UNUSED(self_id),
-                                              ID **id_p,
-                                              int cb_flag)
+static int foreach_libblock_id_users_callback(LibraryIDLinkCallbackData *cb_data)
 {
-  IDUsersIter *iter = user_data;
+  ID **id_p = cb_data->id_pointer;
+  const int cb_flag = cb_data->cb_flag;
+  IDUsersIter *iter = cb_data->user_data;
 
   if (*id_p) {
     /* 'Loopback' ID pointers (the ugly 'from' ones, Object->proxy_from and Key->from).
@@ -1379,12 +1378,12 @@ void BKE_library_ID_test_usages(Main *bmain, void *idv, bool *is_used_local, boo
 }
 
 /* ***** IDs usages.checking/tagging. ***** */
-static int foreach_libblock_used_linked_data_tag_clear_cb(void *user_data,
-                                                          ID *self_id,
-                                                          ID **id_p,
-                                                          int cb_flag)
+static int foreach_libblock_used_linked_data_tag_clear_cb(LibraryIDLinkCallbackData *cb_data)
 {
-  bool *is_changed = user_data;
+  ID *self_id = cb_data->id_self;
+  ID **id_p = cb_data->id_pointer;
+  const int cb_flag = cb_data->cb_flag;
+  bool *is_changed = cb_data->user_data;
 
   if (*id_p) {
     /* The infamous 'from' pointers (Key.from, Object.proxy_from, ...).
index 9b6d62a87aa00b6eabcd38ce19c47eddabb4e22d..d8b32b6e04c36b09c625fe93204be0458d8905f2 100644 (file)
@@ -97,13 +97,17 @@ enum {
   ID_REMAP_IS_USER_ONE_SKIPPED = 1 << 1, /* There was some skipped 'user_one' usages of old_id. */
 };
 
-static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id_p, int cb_flag)
+static int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data)
 {
+  const int cb_flag = cb_data->cb_flag;
+
   if (cb_flag & IDWALK_CB_PRIVATE) {
     return IDWALK_RET_NOP;
   }
 
-  IDRemap *id_remap_data = user_data;
+  ID *id_self = cb_data->id_self;
+  ID **id_p = cb_data->id_pointer;
+  IDRemap *id_remap_data = cb_data->user_data;
   ID *old_id = id_remap_data->old_id;
   ID *new_id = id_remap_data->new_id;
   ID *id = id_remap_data->id;
@@ -642,15 +646,14 @@ void BKE_libblock_relink_ex(
   DEG_relations_tag_update(bmain);
 }
 
-static int id_relink_to_newid_looper(void *UNUSED(user_data),
-                                     ID *UNUSED(self_id),
-                                     ID **id_pointer,
-                                     const int cb_flag)
+static int id_relink_to_newid_looper(LibraryIDLinkCallbackData *cb_data)
 {
+  const int cb_flag = cb_data->cb_flag;
   if (cb_flag & IDWALK_CB_PRIVATE) {
     return IDWALK_RET_NOP;
   }
 
+  ID **id_pointer = cb_data->id_pointer;
   ID *id = *id_pointer;
   if (id) {
     /* See: NEW_ID macro */
index 0c17a2c08566e476269fafacc23d284c71bcb0e5..75bf74f63bf115ef2d7e3d16c3424a6d62834826 100644 (file)
@@ -209,12 +209,12 @@ void BKE_main_unlock(struct Main *bmain)
   BLI_spin_unlock((SpinLock *)bmain->lock);
 }
 
-static int main_relations_create_idlink_cb(void *user_data,
-                                           ID *id_self,
-                                           ID **id_pointer,
-                                           int cb_flag)
+static int main_relations_create_idlink_cb(LibraryIDLinkCallbackData *cb_data)
 {
-  MainIDRelations *rel = user_data;
+  MainIDRelations *rel = cb_data->user_data;
+  ID *id_self = cb_data->id_self;
+  ID **id_pointer = cb_data->id_pointer;
+  const int cb_flag = cb_data->cb_flag;
 
   if (*id_pointer) {
     MainIDRelationsEntry *entry, **entry_p;
index 68d535e6405d24d81f67cb2a303b04bdd249b132..014ccdb913e460183108af6598d0b31e171e19c8 100644 (file)
@@ -1167,11 +1167,9 @@ Mesh *BKE_mesh_new_from_object(Depsgraph *depsgraph, Object *object, bool preser
   return new_mesh;
 }
 
-static int foreach_libblock_make_original_callback(void *UNUSED(user_data_v),
-                                                   ID *UNUSED(id_self),
-                                                   ID **id_p,
-                                                   int UNUSED(cb_flag))
+static int foreach_libblock_make_original_callback(LibraryIDLinkCallbackData *cb_data)
 {
+  ID **id_p = cb_data->id_pointer;
   if (*id_p == NULL) {
     return IDWALK_RET_NOP;
   }
@@ -1180,15 +1178,14 @@ static int foreach_libblock_make_original_callback(void *UNUSED(user_data_v),
   return IDWALK_RET_NOP;
 }
 
-static int foreach_libblock_make_usercounts_callback(void *UNUSED(user_data_v),
-                                                     ID *UNUSED(id_self),
-                                                     ID **id_p,
-                                                     int cb_flag)
+static int foreach_libblock_make_usercounts_callback(LibraryIDLinkCallbackData *cb_data)
 {
+  ID **id_p = cb_data->id_pointer;
   if (*id_p == NULL) {
     return IDWALK_RET_NOP;
   }
 
+  const int cb_flag = cb_data->cb_flag;
   if (cb_flag & IDWALK_CB_USER) {
     id_us_plus(*id_p);
   }
index d9849cfa770204fb7fa947332af40f9b1bdcf8e5..b06571e5f407ab11054d91eac1283f8b14441fc0 100644 (file)
@@ -7744,11 +7744,10 @@ static void lib_link_clipboard_restore(struct IDNameLib_Map *id_map)
   BKE_sequencer_base_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map);
 }
 
-static int lib_link_main_data_restore_cb(void *user_data,
-                                         ID *UNUSED(id_self),
-                                         ID **id_pointer,
-                                         int cb_flag)
+static int lib_link_main_data_restore_cb(LibraryIDLinkCallbackData *cb_data)
 {
+  const int cb_flag = cb_data->cb_flag;
+  ID **id_pointer = cb_data->id_pointer;
   if (cb_flag & IDWALK_CB_PRIVATE || *id_pointer == NULL) {
     return IDWALK_RET_NOP;
   }
@@ -7763,7 +7762,7 @@ static int lib_link_main_data_restore_cb(void *user_data,
     }
   }
 
-  struct IDNameLib_Map *id_map = user_data;
+  struct IDNameLib_Map *id_map = cb_data->user_data;
 
   /* Note: Handling of usercount here is really bad, defining its own system...
    * Will have to be refactored at some point, but that is not top priority task for now.
index c2222bfcbce986ad26ff784e1a867821064e4836..edb02ee331f57a9dd489e43d441a22c613b4d7ea 100644 (file)
@@ -513,12 +513,15 @@ struct RemapCallbackUserData {
   bool create_placeholders;
 };
 
-int foreach_libblock_remap_callback(void *user_data_v, ID *id_self, ID **id_p, int /*cb_flag*/)
+int foreach_libblock_remap_callback(LibraryIDLinkCallbackData *cb_data)
 {
+  ID **id_p = cb_data->id_pointer;
   if (*id_p == nullptr) {
     return IDWALK_RET_NOP;
   }
-  RemapCallbackUserData *user_data = (RemapCallbackUserData *)user_data_v;
+
+  ID *id_self = cb_data->id_self;
+  RemapCallbackUserData *user_data = (RemapCallbackUserData *)cb_data->user_data;
   const Depsgraph *depsgraph = user_data->depsgraph;
   ID *id_orig = *id_p;
   if (deg_copy_on_write_is_needed(id_orig)) {
@@ -813,12 +816,11 @@ void update_id_after_copy(const Depsgraph *depsgraph,
 
 /* This callback is used to validate that all nested ID data-blocks are
  * properly expanded. */
-int foreach_libblock_validate_callback(void *user_data,
-                                       ID * /*id_self*/,
-                                       ID **id_p,
-                                       int /*cb_flag*/)
+int foreach_libblock_validate_callback(LibraryIDLinkCallbackData *cb_data)
 {
-  ValidateData *data = (ValidateData *)user_data;
+  ValidateData *data = (ValidateData *)cb_data->user_data;
+  ID **id_p = cb_data->id_pointer;
+
   if (*id_p != nullptr) {
     if (!check_datablock_expanded(*id_p)) {
       data->is_valid = false;
index 8ee061efc08d0598aa7aee5a2247acc79c7c21c6..b1e3e4b64f237314f159b1656726d9710b55d521 100644 (file)
@@ -2087,11 +2087,9 @@ enum {
   MAKE_LOCAL_ALL = 4,
 };
 
-static int tag_localizable_looper(void *UNUSED(user_data),
-                                  ID *UNUSED(self_id),
-                                  ID **id_pointer,
-                                  const int UNUSED(cb_flag))
+static int tag_localizable_looper(LibraryIDLinkCallbackData *cb_data)
 {
+  ID **id_pointer = cb_data->id_pointer;
   if (*id_pointer) {
     (*id_pointer)->tag &= ~LIB_TAG_DOIT;
   }
index 26fd9f14c643078c6405727e14acb3fc7978757c..a434ecad48da6875e09dd25218b81ffdc881979f 100644 (file)
@@ -584,20 +584,23 @@ static void gather_frames_to_render_for_grease_pencil(const OGLRender *oglrender
   }
 }
 
-static int gather_frames_to_render_for_id(void *user_data_v, ID *id_self, ID **id_p, int cb_flag)
+static int gather_frames_to_render_for_id(LibraryIDLinkCallbackData *cb_data)
 {
-  if (id_p == NULL || *id_p == NULL) {
+  ID **id_p = cb_data->id_pointer;
+  if (*id_p == NULL) {
     return IDWALK_RET_NOP;
   }
   ID *id = *id_p;
 
+  ID *id_self = cb_data->id_self;
+  const int cb_flag = cb_data->cb_flag;
   if (cb_flag == IDWALK_CB_LOOPBACK || id == id_self) {
     /* IDs may end up referencing themselves one way or the other, and those
      * (the id_self ones) have always already been processed. */
     return IDWALK_RET_STOP_RECURSION;
   }
 
-  OGLRender *oglrender = user_data_v;
+  OGLRender *oglrender = cb_data->user_data;
 
   /* Whitelist of datablocks to follow pointers into. */
   const ID_Type id_type = GS(id->name);
index 68e1678027ea81a136ce1eae1f6a0cfbef8583d3..6084f3f3ad929797479c4b6f7b19afeed4918c32 100644 (file)
@@ -82,12 +82,11 @@ static bool id_check_type(const ID *id, const BLI_bitmap *types_bitmap)
   return BLI_BITMAP_TEST_BOOL(types_bitmap, id_code_as_index(GS(id->name)));
 }
 
-static int foreach_libblock_id_user_map_callback(void *user_data,
-                                                 ID *self_id,
-                                                 ID **id_p,
-                                                 int UNUSED(cb_flag))
+static int foreach_libblock_id_user_map_callback(LibraryIDLinkCallbackData *cb_data)
 {
-  IDUserMapData *data = user_data;
+  IDUserMapData *data = cb_data->user_data;
+  ID *self_id = cb_data->id_self;
+  ID **id_p = cb_data->id_pointer;
 
   if (*id_p) {
 
index 7dc5f1d7917b059923a686efd244da13ad7805f2..d50bbf49dae461e915dc351bd02f4ba4a0e8621d 100644 (file)
@@ -3334,17 +3334,16 @@ static void previews_id_ensure(bContext *C, Scene *scene, ID *id)
   }
 }
 
-static int previews_id_ensure_callback(void *userdata,
-                                       ID *UNUSED(self_id),
-                                       ID **idptr,
-                                       int cb_flag)
+static int previews_id_ensure_callback(LibraryIDLinkCallbackData *cb_data)
 {
+  const int cb_flag = cb_data->cb_flag;
+
   if (cb_flag & IDWALK_CB_PRIVATE) {
     return IDWALK_RET_NOP;
   }
 
-  PreviewsIDEnsureData *data = userdata;
-  ID *id = *idptr;
+  PreviewsIDEnsureData *data = cb_data->user_data;
+  ID *id = *cb_data->id_pointer;
 
   if (id && (id->tag & LIB_TAG_DOIT)) {
     BLI_assert(ELEM(GS(id->name), ID_MA, ID_TE, ID_IM, ID_WO, ID_LA));