[Bf-blender-cvs] [8c6fe60844f] master: Cleanup: Use const parameters for node poll functions

Hans Goudey noreply at git.blender.org
Thu Dec 29 02:16:15 CET 2022


Commit: 8c6fe60844f2f970c46500efa27fe9755b91b76d
Author: Hans Goudey
Date:   Wed Dec 28 20:15:41 2022 -0500
Branches: master
https://developer.blender.org/rB8c6fe60844f2f970c46500efa27fe9755b91b76d

Cleanup: Use const parameters for node poll functions

This requires a const cast in RNA, but it really is wrong
to change the nodes and node trees in these callbacks.

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

M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.cc
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/composite/node_composite_util.cc
M	source/blender/nodes/composite/node_composite_util.hh
M	source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
M	source/blender/nodes/composite/nodes/node_composite_image.cc
M	source/blender/nodes/function/node_function_util.cc
M	source/blender/nodes/geometry/node_geometry_util.cc
M	source/blender/nodes/geometry/node_geometry_util.hh
M	source/blender/nodes/intern/node_common.cc
M	source/blender/nodes/intern/node_common.h
M	source/blender/nodes/intern/node_register.cc
M	source/blender/nodes/shader/node_shader_util.cc
M	source/blender/nodes/shader/node_shader_util.hh
M	source/blender/nodes/texture/node_texture_util.cc
M	source/blender/nodes/texture/node_texture_util.hh

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

diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index ff1128246f3..d247ee5eea0 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -299,12 +299,14 @@ typedef struct bNodeType {
    *                         when it's not just a dummy, that is, if it actually wants to access
    *                         the returned disabled-hint (null-check needed!).
    */
-  bool (*poll)(struct bNodeType *ntype, struct bNodeTree *nodetree, const char **r_disabled_hint);
+  bool (*poll)(const struct bNodeType *ntype,
+               const struct bNodeTree *nodetree,
+               const char **r_disabled_hint);
   /** Can this node be added to a node tree?
    * \param r_disabled_hint: See `poll()`.
    */
-  bool (*poll_instance)(struct bNode *node,
-                        struct bNodeTree *nodetree,
+  bool (*poll_instance)(const struct bNode *node,
+                        const struct bNodeTree *nodetree,
                         const char **r_disabled_hint);
 
   /* optional handling of link insertion */
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 9fc2cbde1d5..097d14ae7b9 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -4034,14 +4034,16 @@ static void node_type_base_defaults(bNodeType *ntype)
 }
 
 /* allow this node for any tree type */
-static bool node_poll_default(bNodeType * /*ntype*/,
-                              bNodeTree * /*ntree*/,
+static bool node_poll_default(const bNodeType * /*ntype*/,
+                              const bNodeTree * /*ntree*/,
                               const char ** /*disabled_hint*/)
 {
   return true;
 }
 
-static bool node_poll_instance_default(bNode *node, bNodeTree *ntree, const char **disabled_hint)
+static bool node_poll_instance_default(const bNode *node,
+                                       const bNodeTree *ntree,
+                                       const char **disabled_hint)
 {
   return node->typeinfo->poll(node->typeinfo, ntree, disabled_hint);
 }
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index fbc13229a3d..aa42e9422e2 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -1659,7 +1659,9 @@ char *rna_Node_ImageUser_path(const PointerRNA *ptr)
   return NULL;
 }
 
-static bool rna_Node_poll(bNodeType *ntype, bNodeTree *ntree, const char **UNUSED(r_disabled_hint))
+static bool rna_Node_poll(const bNodeType *ntype,
+                          const bNodeTree *ntree,
+                          const char **UNUSED(r_disabled_hint))
 {
   extern FunctionRNA rna_Node_poll_func;
 
@@ -1684,8 +1686,8 @@ static bool rna_Node_poll(bNodeType *ntype, bNodeTree *ntree, const char **UNUSE
   return visible;
 }
 
-static bool rna_Node_poll_instance(bNode *node,
-                                   bNodeTree *ntree,
+static bool rna_Node_poll_instance(const bNode *node,
+                                   const bNodeTree *ntree,
                                    const char **UNUSED(disabled_info))
 {
   extern FunctionRNA rna_Node_poll_instance_func;
@@ -1696,7 +1698,7 @@ static bool rna_Node_poll_instance(bNode *node,
   void *ret;
   bool visible;
 
-  RNA_pointer_create(NULL, node->typeinfo->rna_ext.srna, node, &ptr); /* dummy */
+  RNA_pointer_create(NULL, node->typeinfo->rna_ext.srna, (bNode *)node, &ptr); /* dummy */
   func = &rna_Node_poll_instance_func; /* RNA_struct_find_function(&ptr, "poll_instance"); */
 
   RNA_parameter_list_create(&list, &ptr, func);
@@ -1711,8 +1713,8 @@ static bool rna_Node_poll_instance(bNode *node,
   return visible;
 }
 
-static bool rna_Node_poll_instance_default(bNode *node,
-                                           bNodeTree *ntree,
+static bool rna_Node_poll_instance_default(const bNode *node,
+                                           const bNodeTree *ntree,
                                            const char **disabled_info)
 {
   /* use the basic poll function */
diff --git a/source/blender/nodes/composite/node_composite_util.cc b/source/blender/nodes/composite/node_composite_util.cc
index afe11de059d..219976e85c0 100644
--- a/source/blender/nodes/composite/node_composite_util.cc
+++ b/source/blender/nodes/composite/node_composite_util.cc
@@ -11,7 +11,9 @@
 
 #include "node_composite_util.hh"
 
-bool cmp_node_poll_default(bNodeType * /*ntype*/, bNodeTree *ntree, const char **r_disabled_hint)
+bool cmp_node_poll_default(const bNodeType * /*ntype*/,
+                           const bNodeTree *ntree,
+                           const char **r_disabled_hint)
 {
   if (!STREQ(ntree->idname, "CompositorNodeTree")) {
     *r_disabled_hint = TIP_("Not a compositor node tree");
diff --git a/source/blender/nodes/composite/node_composite_util.hh b/source/blender/nodes/composite/node_composite_util.hh
index 46330c67996..9049834100e 100644
--- a/source/blender/nodes/composite/node_composite_util.hh
+++ b/source/blender/nodes/composite/node_composite_util.hh
@@ -21,8 +21,8 @@
 
 #define CMP_SCALE_MAX 12000
 
-bool cmp_node_poll_default(struct bNodeType *ntype,
-                           struct bNodeTree *ntree,
+bool cmp_node_poll_default(const struct bNodeType *ntype,
+                           const struct bNodeTree *ntree,
                            const char **r_disabled_hint);
 void cmp_node_update_default(struct bNodeTree *ntree, struct bNode *node);
 void cmp_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);
diff --git a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
index fd4ef63879e..ad170984cd7 100644
--- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.cc
@@ -277,8 +277,8 @@ static void node_copy_cryptomatte(bNodeTree * /*dst_ntree*/,
   dest_node->storage = dest_nc;
 }
 
-static bool node_poll_cryptomatte(bNodeType * /*ntype*/,
-                                  bNodeTree *ntree,
+static bool node_poll_cryptomatte(const bNodeType * /*ntype*/,
+                                  const bNodeTree *ntree,
                                   const char **r_disabled_hint)
 {
   if (STREQ(ntree->idname, "CompositorNodeTree")) {
diff --git a/source/blender/nodes/composite/nodes/node_composite_image.cc b/source/blender/nodes/composite/nodes/node_composite_image.cc
index 9bfb150205b..e743c003701 100644
--- a/source/blender/nodes/composite/nodes/node_composite_image.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_image.cc
@@ -712,8 +712,8 @@ static void node_composit_init_rlayers(const bContext *C, PointerRNA *ptr)
   }
 }
 
-static bool node_composit_poll_rlayers(bNodeType * /*ntype*/,
-                                       bNodeTree *ntree,
+static bool node_composit_poll_rlayers(const bNodeType * /*ntype*/,
+                                       const bNodeTree *ntree,
                                        const char **r_disabled_hint)
 {
   if (!STREQ(ntree->idname, "CompositorNodeTree")) {
diff --git a/source/blender/nodes/function/node_function_util.cc b/source/blender/nodes/function/node_function_util.cc
index 82459815b77..2be0d639bdf 100644
--- a/source/blender/nodes/function/node_function_util.cc
+++ b/source/blender/nodes/function/node_function_util.cc
@@ -5,8 +5,8 @@
 
 #include "NOD_socket_search_link.hh"
 
-static bool fn_node_poll_default(bNodeType * /*ntype*/,
-                                 bNodeTree *ntree,
+static bool fn_node_poll_default(const bNodeType * /*ntype*/,
+                                 const bNodeTree *ntree,
                                  const char **r_disabled_hint)
 {
   /* Function nodes are only supported in simulation node trees so far. */
diff --git a/source/blender/nodes/geometry/node_geometry_util.cc b/source/blender/nodes/geometry/node_geometry_util.cc
index 8b962d39b3c..3c830f978d1 100644
--- a/source/blender/nodes/geometry/node_geometry_util.cc
+++ b/source/blender/nodes/geometry/node_geometry_util.cc
@@ -41,7 +41,9 @@ std::optional<eCustomDataType> node_socket_to_custom_data_type(const bNodeSocket
 
 }  // namespace blender::nodes
 
-bool geo_node_poll_default(bNodeType * /*ntype*/, bNodeTree *ntree, const char **r_disabled_hint)
+bool geo_node_poll_default(const bNodeType * /*ntype*/,
+                           const bNodeTree *ntree,
+                           const char **r_disabled_hint)
 {
   if (!STREQ(ntree->idname, "GeometryNodeTree")) {
     *r_disabled_hint = TIP_("Not a geometry node tree");
diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index d1aeff2cd7a..d99b4c01ed7 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -28,8 +28,8 @@
 struct BVHTreeFromMesh;
 
 void geo_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);
-bool geo_node_poll_default(struct bNodeType *ntype,
-                           struct bNodeTree *ntree,
+bool geo_node_poll_default(const struct bNodeType *ntype,
+                           const struct bNodeTree *ntree,
                            const char **r_disabled_hint);
 
 namespace blender::nodes {
diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc
index b5feea220d1..509921837cc 100644
--- a/source/blender/nodes/intern/node_common.cc
+++ b/source/blender/nodes/intern/node_common.cc
@@ -70,10 +70,12 @@ void node_group_label(const bNodeTree * /*ntree*/, const bNode *node, char *labe
   BLI_strncpy(label, (node->id) ? node->id->name + 2 : IFACE_("Missing Data-Block"), maxlen);
 }
 
-bool node_group_poll_instance(bNode *node, bNodeTree *nodetree, const char **disabled_hint)
+bool node_group_poll_instance(const bNode *node,
+                              const bNodeTree *nodetree,
+                              const char **disabled_hint)
 {
   if (node->typeinfo->poll(node->typeinfo, nodetree, disabled_hint)) {
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list