[Bf-blender-cvs] [03ef0cfe3c3] master: Refactor `BKE_id_copy` to return the new ID pointer.

Bastien Montagne noreply at git.blender.org
Wed Oct 7 18:05:18 CEST 2020


Commit: 03ef0cfe3c3327647be5289d8ecddea820401221
Author: Bastien Montagne
Date:   Wed Oct 7 16:13:01 2020 +0200
Branches: master
https://developer.blender.org/rB03ef0cfe3c3327647be5289d8ecddea820401221

Refactor `BKE_id_copy` to return the new ID pointer.

No reasons to keep the new ID pointer as parameter here.

Part of T71219.

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

M	source/blender/blenkernel/BKE_lib_id.h
M	source/blender/blenkernel/intern/action.c
M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/cachefile.c
M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/hair.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/lattice.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/blenkernel/intern/light.c
M	source/blender/blenkernel/intern/lightprobe.c
M	source/blender/blenkernel/intern/linestyle.c
M	source/blender/blenkernel/intern/mask.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/mball.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/movieclip.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/pointcloud.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/speaker.c
M	source/blender/blenkernel/intern/text.c
M	source/blender/blenkernel/intern/texture.c
M	source/blender/blenkernel/intern/volume.cc
M	source/blender/editors/object/object_relations.c
M	source/blender/makesrna/intern/rna_ID.c

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

diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index 9b1e2c0d41b..e54e2fb4b87 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -237,7 +237,7 @@ bool id_single_user(struct bContext *C,
                     struct PointerRNA *ptr,
                     struct PropertyRNA *prop);
 bool BKE_id_copy_is_allowed(const struct ID *id);
-bool BKE_id_copy(struct Main *bmain, const struct ID *id, struct ID **newid);
+struct ID *BKE_id_copy(struct Main *bmain, const struct ID *id);
 struct ID *BKE_id_copy_ex(struct Main *bmain,
                           const struct ID *id,
                           struct ID **r_newid,
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 3b02087e2d2..4d92390cdcb 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -312,9 +312,7 @@ bAction *BKE_action_add(Main *bmain, const char name[])
 
 bAction *BKE_action_copy(Main *bmain, const bAction *act_src)
 {
-  bAction *act_copy;
-  BKE_id_copy(bmain, &act_src->id, (ID **)&act_copy);
-  return act_copy;
+  return (bAction *)BKE_id_copy(bmain, &act_src->id);
 }
 
 /* *************** Action Groups *************** */
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 0a731f0a7f0..742f57f32a3 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -428,9 +428,7 @@ static void copy_bonechildren_custom_handles(Bone *bone_dst, bArmature *arm_dst)
 
 bArmature *BKE_armature_copy(Main *bmain, const bArmature *arm)
 {
-  bArmature *arm_copy;
-  BKE_id_copy(bmain, &arm->id, (ID **)&arm_copy);
-  return arm_copy;
+  return (bArmature *)BKE_id_copy(bmain, &arm->id);
 }
 
 /** \} */
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index f559689608f..e1524422c3b 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -1533,9 +1533,7 @@ struct Brush *BKE_brush_first_search(struct Main *bmain, const eObjectMode ob_mo
 
 Brush *BKE_brush_copy(Main *bmain, const Brush *brush)
 {
-  Brush *brush_copy;
-  BKE_id_copy(bmain, &brush->id, (ID **)&brush_copy);
-  return brush_copy;
+  return (Brush *)BKE_id_copy(bmain, &brush->id);
 }
 
 void BKE_brush_debug_print_state(Brush *br)
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 9475ba7efcf..65dcf3673d6 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -256,9 +256,7 @@ void *BKE_cachefile_add(Main *bmain, const char *name)
 
 CacheFile *BKE_cachefile_copy(Main *bmain, const CacheFile *cache_file)
 {
-  CacheFile *cache_file_copy;
-  BKE_id_copy(bmain, &cache_file->id, (ID **)&cache_file_copy);
-  return cache_file_copy;
+  return (CacheFile *)BKE_id_copy(bmain, &cache_file->id);
 }
 
 void BKE_cachefile_reload(Depsgraph *depsgraph, CacheFile *cache_file)
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 4fe3ddc81a1..1183e359d93 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -222,9 +222,7 @@ void *BKE_camera_add(Main *bmain, const char *name)
 
 Camera *BKE_camera_copy(Main *bmain, const Camera *cam)
 {
-  Camera *cam_copy;
-  BKE_id_copy(bmain, &cam->id, (ID **)&cam_copy);
-  return cam_copy;
+  return (Camera *)BKE_id_copy(bmain, &cam->id);
 }
 
 /* get the camera's dof value, takes the dof object into account */
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 64785248daf..eb469f5400f 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -427,9 +427,7 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type)
 
 Curve *BKE_curve_copy(Main *bmain, const Curve *cu)
 {
-  Curve *cu_copy;
-  BKE_id_copy(bmain, &cu->id, (ID **)&cu_copy);
-  return cu_copy;
+  return (Curve *)BKE_id_copy(bmain, &cu->id);
 }
 
 /* Get list of nurbs from editnurbs structure */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 980d608df77..f40cfba5077 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -980,9 +980,7 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
  */
 bGPdata *BKE_gpencil_copy(Main *bmain, const bGPdata *gpd)
 {
-  bGPdata *gpd_copy;
-  BKE_id_copy(bmain, &gpd->id, (ID **)&gpd_copy);
-  return gpd_copy;
+  return (bGPdata *)BKE_id_copy(bmain, &gpd->id);
 }
 
 /**
@@ -1009,7 +1007,7 @@ bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool in
   }
   else {
     BLI_assert(bmain != NULL);
-    BKE_id_copy(bmain, &gpd_src->id, (ID **)&gpd_dst);
+    gpd_dst = (bGPdata *)BKE_id_copy(bmain, &gpd_src->id);
   }
 
   /* Copy internal data (layers, etc.) */
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index edbc13d8773..5d995cbbb4d 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -253,9 +253,7 @@ void *BKE_hair_add(Main *bmain, const char *name)
 
 Hair *BKE_hair_copy(Main *bmain, const Hair *hair)
 {
-  Hair *hair_copy;
-  BKE_id_copy(bmain, &hair->id, (ID **)&hair_copy);
-  return hair_copy;
+  return (Hair *)BKE_id_copy(bmain, &hair->id);
 }
 
 BoundBox *BKE_hair_boundbox_get(Object *ob)
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index a02f2222503..d1f29c39f63 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -603,9 +603,7 @@ static void copy_image_packedfiles(ListBase *lb_dst, const ListBase *lb_src)
 /* empty image block, of similar type and filename */
 Image *BKE_image_copy(Main *bmain, const Image *ima)
 {
-  Image *ima_copy;
-  BKE_id_copy(bmain, &ima->id, (ID **)&ima_copy);
-  return ima_copy;
+  return (Image *)BKE_id_copy(bmain, &ima->id);
 }
 
 void BKE_image_merge(Main *bmain, Image *dest, Image *source)
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 1b63aa1a8af..a0c4405535a 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -298,9 +298,7 @@ Key *BKE_key_add(Main *bmain, ID *id) /* common function */
 
 Key *BKE_key_copy(Main *bmain, const Key *key)
 {
-  Key *key_copy;
-  BKE_id_copy(bmain, &key->id, (ID **)&key_copy);
-  return key_copy;
+  return (Key *)BKE_id_copy(bmain, &key->id);
 }
 
 /* XXX TODO get rid of this! */
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index b9745c67c66..950c08bf770 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -403,9 +403,7 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name)
 
 Lattice *BKE_lattice_copy(Main *bmain, const Lattice *lt)
 {
-  Lattice *lt_copy;
-  BKE_id_copy(bmain, &lt->id, (ID **)&lt_copy);
-  return lt_copy;
+  return (Lattice *)BKE_id_copy(bmain, &lt->id);
 }
 
 bool object_deform_mball(Object *ob, ListBase *dispbase)
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index f69bada0fe8..cfe81531204 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -414,11 +414,11 @@ void BKE_lib_id_make_local_generic(Main *bmain, ID *id, const int flags)
       BKE_lib_id_expand_local(bmain, id);
     }
     else {
-      ID *id_new;
+      ID *id_new = BKE_id_copy(bmain, id);
 
       /* Should not fail in expected use cases,
        * but a few ID types cannot be copied (LIB, WM, SCR...). */
-      if (BKE_id_copy(bmain, id, &id_new)) {
+      if (id_new != NULL) {
         id_new->us = 0;
 
         /* setting newid is mandatory for complex make_lib_local logic... */
@@ -614,9 +614,9 @@ ID *BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
  * Invokes the appropriate copy method for the block and returns the result in
  * newid, unless test. Returns true if the block can be copied.
  */
-bool BKE_id_copy(Main *bmain, const ID *id, ID **newid)
+ID *BKE_id_copy(Main *bmain, const ID *id)
 {
-  return (BKE_id_copy_ex(bmain, id, newid, LIB_ID_COPY_DEFAULT) != NULL);
+  return BKE_id_copy_ex(bmain, id, NULL, LIB_ID_COPY_DEFAULT);
 }
 
 /**
@@ -634,8 +634,7 @@ ID *BKE_id_copy_for_duplicate(Main *bmain, ID *id, const eDupli_ID_Flags duplica
       return id;
     }
 
-    ID *id_new;
-    BKE_id_copy(bmain, id, &id_new);
+    ID *id_new = BKE_id_copy(bmain, id);
     /* Copying add one user by default, need to get rid of that one. */
     id_us_min(id_new);
     ID_NEW_SET(id, id_new);
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 7fd8b05ec0a..a989a865994 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -189,9 +189,9 @@ void BKE_lib_override_library_free(struct IDOverrideLibrary **override, const bo
 
 static ID *lib_override_library_create_from(Main *bmain, ID *reference_id)
 {
-  ID *local_id;
+  ID *local_id = BKE_id_copy(bmain, reference_id);
 
-  if (!BKE_id_copy(bmain, reference_id, (ID **)&local_id)) {
+  if (local_id == NULL) {
     return NULL;
   }
   id_us_min(local_id);
@@ -1699,8 +1699,7 @@ void BKE_lib_override_library_update(Main *bmain, ID *local)
    * Not impossible to do, but would rather see first if extra useless usual user handling
    * is actually a (performances) issue here. */
 
-  ID *tmp_id;
-  BKE_id_copy(bmain, local->override_library->reference, &tmp_id);
+  ID *tmp_id = BKE_id_copy(bmain, local->override_library->reference);
 
   if (tmp_id == NULL) {
     return;
@@ -1868,7 +1867,7 @@ ID *BKE_lib_override_library_operations_store_start(Main *bmain,
    * (and possibly all over Blender code).
    * Not im

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list