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.
This commit is contained in:
2022-12-28 20:15:41 -05:00
parent d7dad425c0
commit 8c6fe60844
17 changed files with 52 additions and 38 deletions

View File

@@ -299,12 +299,14 @@ typedef struct bNodeType {
* when it's not just a dummy, that is, if it actually wants to access * when it's not just a dummy, that is, if it actually wants to access
* the returned disabled-hint (null-check needed!). * 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? /** Can this node be added to a node tree?
* \param r_disabled_hint: See `poll()`. * \param r_disabled_hint: See `poll()`.
*/ */
bool (*poll_instance)(struct bNode *node, bool (*poll_instance)(const struct bNode *node,
struct bNodeTree *nodetree, const struct bNodeTree *nodetree,
const char **r_disabled_hint); const char **r_disabled_hint);
/* optional handling of link insertion */ /* optional handling of link insertion */

View File

@@ -4034,14 +4034,16 @@ static void node_type_base_defaults(bNodeType *ntype)
} }
/* allow this node for any tree type */ /* allow this node for any tree type */
static bool node_poll_default(bNodeType * /*ntype*/, static bool node_poll_default(const bNodeType * /*ntype*/,
bNodeTree * /*ntree*/, const bNodeTree * /*ntree*/,
const char ** /*disabled_hint*/) const char ** /*disabled_hint*/)
{ {
return true; 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); return node->typeinfo->poll(node->typeinfo, ntree, disabled_hint);
} }

View File

@@ -1659,7 +1659,9 @@ char *rna_Node_ImageUser_path(const PointerRNA *ptr)
return NULL; 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; extern FunctionRNA rna_Node_poll_func;
@@ -1684,8 +1686,8 @@ static bool rna_Node_poll(bNodeType *ntype, bNodeTree *ntree, const char **UNUSE
return visible; return visible;
} }
static bool rna_Node_poll_instance(bNode *node, static bool rna_Node_poll_instance(const bNode *node,
bNodeTree *ntree, const bNodeTree *ntree,
const char **UNUSED(disabled_info)) const char **UNUSED(disabled_info))
{ {
extern FunctionRNA rna_Node_poll_instance_func; extern FunctionRNA rna_Node_poll_instance_func;
@@ -1696,7 +1698,7 @@ static bool rna_Node_poll_instance(bNode *node,
void *ret; void *ret;
bool visible; 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"); */ func = &rna_Node_poll_instance_func; /* RNA_struct_find_function(&ptr, "poll_instance"); */
RNA_parameter_list_create(&list, &ptr, func); RNA_parameter_list_create(&list, &ptr, func);
@@ -1711,8 +1713,8 @@ static bool rna_Node_poll_instance(bNode *node,
return visible; return visible;
} }
static bool rna_Node_poll_instance_default(bNode *node, static bool rna_Node_poll_instance_default(const bNode *node,
bNodeTree *ntree, const bNodeTree *ntree,
const char **disabled_info) const char **disabled_info)
{ {
/* use the basic poll function */ /* use the basic poll function */

View File

@@ -11,7 +11,9 @@
#include "node_composite_util.hh" #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")) { if (!STREQ(ntree->idname, "CompositorNodeTree")) {
*r_disabled_hint = TIP_("Not a compositor node tree"); *r_disabled_hint = TIP_("Not a compositor node tree");

View File

@@ -21,8 +21,8 @@
#define CMP_SCALE_MAX 12000 #define CMP_SCALE_MAX 12000
bool cmp_node_poll_default(struct bNodeType *ntype, bool cmp_node_poll_default(const struct bNodeType *ntype,
struct bNodeTree *ntree, const struct bNodeTree *ntree,
const char **r_disabled_hint); const char **r_disabled_hint);
void cmp_node_update_default(struct bNodeTree *ntree, struct bNode *node); 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); void cmp_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);

View File

@@ -277,8 +277,8 @@ static void node_copy_cryptomatte(bNodeTree * /*dst_ntree*/,
dest_node->storage = dest_nc; dest_node->storage = dest_nc;
} }
static bool node_poll_cryptomatte(bNodeType * /*ntype*/, static bool node_poll_cryptomatte(const bNodeType * /*ntype*/,
bNodeTree *ntree, const bNodeTree *ntree,
const char **r_disabled_hint) const char **r_disabled_hint)
{ {
if (STREQ(ntree->idname, "CompositorNodeTree")) { if (STREQ(ntree->idname, "CompositorNodeTree")) {

View File

@@ -712,8 +712,8 @@ static void node_composit_init_rlayers(const bContext *C, PointerRNA *ptr)
} }
} }
static bool node_composit_poll_rlayers(bNodeType * /*ntype*/, static bool node_composit_poll_rlayers(const bNodeType * /*ntype*/,
bNodeTree *ntree, const bNodeTree *ntree,
const char **r_disabled_hint) const char **r_disabled_hint)
{ {
if (!STREQ(ntree->idname, "CompositorNodeTree")) { if (!STREQ(ntree->idname, "CompositorNodeTree")) {

View File

@@ -5,8 +5,8 @@
#include "NOD_socket_search_link.hh" #include "NOD_socket_search_link.hh"
static bool fn_node_poll_default(bNodeType * /*ntype*/, static bool fn_node_poll_default(const bNodeType * /*ntype*/,
bNodeTree *ntree, const bNodeTree *ntree,
const char **r_disabled_hint) const char **r_disabled_hint)
{ {
/* Function nodes are only supported in simulation node trees so far. */ /* Function nodes are only supported in simulation node trees so far. */

View File

@@ -41,7 +41,9 @@ std::optional<eCustomDataType> node_socket_to_custom_data_type(const bNodeSocket
} // namespace blender::nodes } // 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")) { if (!STREQ(ntree->idname, "GeometryNodeTree")) {
*r_disabled_hint = TIP_("Not a geometry node tree"); *r_disabled_hint = TIP_("Not a geometry node tree");

View File

@@ -28,8 +28,8 @@
struct BVHTreeFromMesh; struct BVHTreeFromMesh;
void geo_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass); void geo_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);
bool geo_node_poll_default(struct bNodeType *ntype, bool geo_node_poll_default(const struct bNodeType *ntype,
struct bNodeTree *ntree, const struct bNodeTree *ntree,
const char **r_disabled_hint); const char **r_disabled_hint);
namespace blender::nodes { namespace blender::nodes {

View File

@@ -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); 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)) { if (node->typeinfo->poll(node->typeinfo, nodetree, disabled_hint)) {
bNodeTree *grouptree = (bNodeTree *)node->id; const bNodeTree *grouptree = (const bNodeTree *)node->id;
if (grouptree) { if (grouptree) {
return nodeGroupPoll(nodetree, grouptree, disabled_hint); return nodeGroupPoll(nodetree, grouptree, disabled_hint);
} }

View File

@@ -20,8 +20,8 @@ void node_group_label(const struct bNodeTree *ntree,
const struct bNode *node, const struct bNode *node,
char *label, char *label,
int maxlen); int maxlen);
bool node_group_poll_instance(struct bNode *node, bool node_group_poll_instance(const struct bNode *node,
struct bNodeTree *nodetree, const struct bNodeTree *nodetree,
const char **r_disabled_hint); const char **r_disabled_hint);
/** /**

View File

@@ -11,8 +11,8 @@
#include "RNA_access.h" #include "RNA_access.h"
static bool node_undefined_poll(bNodeType * /*ntype*/, static bool node_undefined_poll(const bNodeType * /*ntype*/,
bNodeTree * /*nodetree*/, const bNodeTree * /*nodetree*/,
const char ** /*r_disabled_hint*/) const char ** /*r_disabled_hint*/)
{ {
/* this type can not be added deliberately, it's just a placeholder */ /* this type can not be added deliberately, it's just a placeholder */

View File

@@ -15,7 +15,9 @@
#include "node_exec.h" #include "node_exec.h"
bool sh_node_poll_default(bNodeType * /*ntype*/, bNodeTree *ntree, const char **r_disabled_hint) bool sh_node_poll_default(const bNodeType * /*ntype*/,
const bNodeTree *ntree,
const char **r_disabled_hint)
{ {
if (!STREQ(ntree->idname, "ShaderNodeTree")) { if (!STREQ(ntree->idname, "ShaderNodeTree")) {
*r_disabled_hint = TIP_("Not a shader node tree"); *r_disabled_hint = TIP_("Not a shader node tree");
@@ -24,8 +26,8 @@ bool sh_node_poll_default(bNodeType * /*ntype*/, bNodeTree *ntree, const char **
return true; return true;
} }
static bool sh_fn_poll_default(bNodeType * /*ntype*/, static bool sh_fn_poll_default(const bNodeType * /*ntype*/,
bNodeTree *ntree, const bNodeTree *ntree,
const char **r_disabled_hint) const char **r_disabled_hint)
{ {
if (!STR_ELEM(ntree->idname, "ShaderNodeTree", "GeometryNodeTree")) { if (!STR_ELEM(ntree->idname, "ShaderNodeTree", "GeometryNodeTree")) {

View File

@@ -63,8 +63,8 @@
#include "RNA_access.h" #include "RNA_access.h"
bool sh_node_poll_default(struct bNodeType *ntype, bool sh_node_poll_default(const struct bNodeType *ntype,
struct bNodeTree *ntree, const struct bNodeTree *ntree,
const char **r_disabled_hint); const char **r_disabled_hint);
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass); void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);
void sh_fn_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass); void sh_fn_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);

View File

@@ -23,7 +23,7 @@
#include "node_texture_util.hh" #include "node_texture_util.hh"
bool tex_node_poll_default(bNodeType * /*ntype*/, bNodeTree *ntree, const char **r_disabled_hint) bool tex_node_poll_default(const bNodeType * /*ntype*/, const bNodeTree *ntree, const char **r_disabled_hint)
{ {
if (!STREQ(ntree->idname, "TextureNodeTree")) { if (!STREQ(ntree->idname, "TextureNodeTree")) {
*r_disabled_hint = TIP_("Not a texture node tree"); *r_disabled_hint = TIP_("Not a texture node tree");

View File

@@ -92,8 +92,8 @@ typedef struct TexDelegate {
int type; int type;
} TexDelegate; } TexDelegate;
bool tex_node_poll_default(struct bNodeType *ntype, bool tex_node_poll_default(const struct bNodeType *ntype,
struct bNodeTree *ntree, const struct bNodeTree *ntree,
const char **r_disabled_hint); const char **r_disabled_hint);
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass); void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass);