Cleanup: BKE: Use StringRefNull instead of char *

Use StringRefNull for all function arguments and return types.
Not a StringRef but StringRefNull since there is still large
interaction with C api so null-termination usually necessary.

If string is expected to be not only empty but also a null then
optional is used. This change depends on #130935.

Pull Request: https://projects.blender.org/blender/blender/pulls/131204
This commit is contained in:
Iliya Katueshenock
2024-12-02 19:24:07 +01:00
committed by Hans Goudey
parent bc430c4e67
commit 7348e670b3
22 changed files with 216 additions and 185 deletions

View File

@@ -157,7 +157,7 @@ struct bNodeSocketType {
char subtype_label[64];
void (*draw)(
bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, const char *text);
bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, StringRefNull text);
void (*draw_color)(bContext *C, PointerRNA *ptr, PointerRNA *node_ptr, float *r_color);
void (*draw_color_simple)(const bNodeSocketType *socket_type, float *r_color);
@@ -166,7 +166,7 @@ struct bNodeSocketType {
const bNodeTreeInterfaceSocket *interface_socket,
bNode *node,
bNodeSocket *socket,
const char *data_path);
StringRefNull data_path);
void (*interface_from_socket)(ID *id,
bNodeTreeInterfaceSocket *interface_socket,
const bNode *node,
@@ -443,7 +443,7 @@ enum class NodeGroupColorTag {
Vector = 13,
};
using bNodeClassCallback = void (*)(void *calldata, int nclass, const char *name);
using bNodeClassCallback = void (*)(void *calldata, int nclass, StringRefNull name);
struct bNodeTreeType {
int type; /* type identifier */
@@ -489,7 +489,7 @@ struct bNodeTreeType {
/** \name Generic API, Trees
* \{ */
bNodeTreeType *node_tree_type_find(const char *idname);
bNodeTreeType *node_tree_type_find(StringRefNull idname);
void node_tree_type_add(bNodeTreeType *nt);
void node_tree_type_free_link(const bNodeTreeType *nt);
bool node_tree_is_registered(const bNodeTree *ntree);
@@ -521,7 +521,7 @@ GHashIterator *node_tree_type_get_iterator();
*/
void node_tree_set_type(const bContext *C, bNodeTree *ntree);
bNodeTree *node_tree_add_tree(Main *bmain, const char *name, const char *idname);
bNodeTree *node_tree_add_tree(Main *bmain, StringRefNull name, StringRefNull idname);
/**
* Add a new (non-embedded) node tree, like #node_tree_add_tree, but allows to create it inside a
@@ -529,8 +529,8 @@ bNodeTree *node_tree_add_tree(Main *bmain, const char *name, const char *idname)
*/
bNodeTree *node_tree_add_in_lib(Main *bmain,
Library *owner_library,
const char *name,
const char *idname);
StringRefNull name,
StringRefNull idname);
/**
* Free tree which is embedded into another data-block.
@@ -586,11 +586,11 @@ void node_tree_blend_write(BlendWriter *writer, bNodeTree *ntree);
/** \name Generic API, Nodes
* \{ */
bNodeType *node_type_find(const char *idname);
const char *node_type_find_alias(const char *idname);
bNodeType *node_type_find(StringRefNull idname);
StringRefNull node_type_find_alias(StringRefNull idname);
void node_register_type(bNodeType *ntype);
void node_unregister_type(bNodeType *ntype);
void node_register_alias(bNodeType *nt, const char *alias);
void node_register_alias(bNodeType *nt, StringRefNull alias);
GHashIterator *node_type_get_iterator();
/* Helper macros for iterating over node types. */
@@ -608,16 +608,16 @@ GHashIterator *node_type_get_iterator();
} \
((void)0)
bNodeSocketType *node_socket_type_find(const char *idname);
bNodeSocketType *node_socket_type_find(StringRefNull idname);
void node_register_socket_type(bNodeSocketType *stype);
void node_unregister_socket_type(bNodeSocketType *stype);
bool node_socket_is_registered(const bNodeSocket *sock);
GHashIterator *node_socket_type_get_iterator();
const char *node_socket_type_label(const bNodeSocketType *stype);
StringRefNull node_socket_type_label(const bNodeSocketType *stype);
const char *node_static_socket_type(int type, int subtype);
const char *node_static_socket_interface_type_new(int type, int subtype);
const char *node_static_socket_label(int type, int subtype);
std::optional<StringRefNull> node_static_socket_type(int type, int subtype);
std::optional<StringRefNull> node_static_socket_interface_type_new(int type, int subtype);
std::optional<StringRefNull> node_static_socket_label(int type, int subtype);
/* Helper macros for iterating over node types. */
#define NODE_SOCKET_TYPES_BEGIN(stype) \
@@ -642,22 +642,22 @@ const bNodeSocket *node_find_socket(const bNode *node,
bNodeSocket *node_add_socket(bNodeTree *ntree,
bNode *node,
eNodeSocketInOut in_out,
const char *idname,
const char *identifier,
const char *name);
StringRefNull idname,
StringRefNull identifier,
StringRefNull name);
bNodeSocket *node_add_static_socket(bNodeTree *ntree,
bNode *node,
eNodeSocketInOut in_out,
int type,
int subtype,
const char *identifier,
const char *name);
StringRefNull identifier,
StringRefNull name);
void node_remove_socket(bNodeTree *ntree, bNode *node, bNodeSocket *sock);
void node_modify_socket_type_static(
bNodeTree *ntree, bNode *node, bNodeSocket *sock, int type, int subtype);
bNode *node_add_node(const bContext *C, bNodeTree *ntree, const char *idname);
bNode *node_add_node(const bContext *C, bNodeTree *ntree, StringRefNull idname);
bNode *node_add_static_node(const bContext *C, bNodeTree *ntree, int type);
/**
@@ -704,7 +704,7 @@ void node_find_node(bNodeTree *ntree, bNodeSocket *sock, bNode **r_node, int *r_
/**
* Finds a node based on its name.
*/
bNode *node_find_node_by_name(bNodeTree *ntree, const char *name);
bNode *node_find_node_by_name(bNodeTree *ntree, StringRefNull name);
bool node_is_parent_and_child(const bNode *parent, const bNode *child);
@@ -748,7 +748,7 @@ bNodeInstanceKey node_instance_key(bNodeInstanceKey parent_key,
const bNodeTree *ntree,
const bNode *node);
bNodeInstanceHash *node_instance_hash_new(const char *info);
bNodeInstanceHash *node_instance_hash_new(StringRefNull info);
void node_instance_hash_free(bNodeInstanceHash *hash, bNodeInstanceValueFP valfreefp);
void node_instance_hash_insert(bNodeInstanceHash *hash, bNodeInstanceKey key, void *value);
void *node_instance_hash_lookup(bNodeInstanceHash *hash, bNodeInstanceKey key);
@@ -775,15 +775,19 @@ bool node_group_poll(const bNodeTree *nodetree,
const bNodeTree *grouptree,
const char **r_disabled_hint);
void node_type_base_custom(
bNodeType *ntype, const char *idname, const char *name, const char *enum_name, short nclass);
void node_type_base_custom(bNodeType *ntype,
StringRefNull idname,
StringRefNull name,
StringRefNull enum_name,
short nclass);
/**
* \warning Nodes defining a storage type _must_ allocate this for new nodes.
* Otherwise nodes will reload as undefined (#46619).
* #storagename is optional due to some compositor nodes use non-DNA storage type.
*/
void node_type_storage(bNodeType *ntype,
const char *storagename,
std::optional<StringRefNull> storagename,
void (*freefunc)(bNode *node),
void (*copyfunc)(bNodeTree *dest_ntree,
bNode *dest_node,
@@ -1438,8 +1442,8 @@ void node_system_exit();
bNodeTree *node_tree_add_tree_embedded(Main *bmain,
ID *owner_id,
const char *name,
const char *idname);
StringRefNull name,
StringRefNull idname);
/* Copy/free functions, need to manage ID users. */
@@ -1477,11 +1481,14 @@ bool node_type_is_undefined(const bNode *node);
bool node_is_static_socket_type(const bNodeSocketType *stype);
const char *node_socket_sub_type_label(int subtype);
StringRefNull node_socket_sub_type_label(int subtype);
void node_remove_socket_ex(bNodeTree *ntree, bNode *node, bNodeSocket *sock, bool do_id_user);
void node_modify_socket_type(bNodeTree *ntree, bNode *node, bNodeSocket *sock, const char *idname);
void node_modify_socket_type(bNodeTree *ntree,
bNode *node,
bNodeSocket *sock,
StringRefNull idname);
/**
* \note Goes over entire tree.
@@ -1705,18 +1712,18 @@ void nodeLabel(const bNodeTree *ntree, const bNode *node, char *label, int maxle
/**
* Get node socket label if it is set.
*/
const char *nodeSocketLabel(const bNodeSocket *sock);
StringRefNull nodeSocketLabel(const bNodeSocket *sock);
/**
* Get node socket short label if it is set.
* It is used when grouping sockets under panels, to avoid redundancy in the label.
*/
const char *nodeSocketShortLabel(const bNodeSocket *sock);
std::optional<StringRefNull> nodeSocketShortLabel(const bNodeSocket *sock);
/**
* Initialize a new node type struct with default values and callbacks.
*/
void node_type_base(bNodeType *ntype, int type, const char *name, short nclass);
void node_type_base(bNodeType *ntype, int type, StringRefNull name, short nclass);
void node_type_socket_templates(bNodeType *ntype,
bNodeSocketTemplate *inputs,

View File

@@ -236,7 +236,7 @@ static void restore_data_blocks(const Span<GeometrySet *> geometries,
static void default_initialize_socket_value(const eNodeSocketDatatype socket_type, void *r_value)
{
const char *socket_idname = bke::node_static_socket_type(socket_type, 0);
const StringRefNull socket_idname = *bke::node_static_socket_type(socket_type, 0);
const bke::bNodeSocketType *typeinfo = bke::node_socket_type_find(socket_idname);
if (typeinfo->geometry_nodes_default_cpp_value) {
typeinfo->geometry_nodes_cpp_type->copy_construct(typeinfo->geometry_nodes_default_cpp_value,

View File

@@ -1610,10 +1610,11 @@ static GHash *nodetypes_hash = nullptr;
static GHash *nodetypes_alias_hash = nullptr;
static GHash *nodesockettypes_hash = nullptr;
bNodeTreeType *node_tree_type_find(const char *idname)
bNodeTreeType *node_tree_type_find(const StringRefNull idname)
{
if (idname[0]) {
bNodeTreeType *nt = static_cast<bNodeTreeType *>(BLI_ghash_lookup(nodetreetypes_hash, idname));
bNodeTreeType *nt = static_cast<bNodeTreeType *>(
BLI_ghash_lookup(nodetreetypes_hash, idname.c_str()));
if (nt) {
return nt;
}
@@ -1656,10 +1657,10 @@ GHashIterator *node_tree_type_get_iterator()
return BLI_ghashIterator_new(nodetreetypes_hash);
}
bNodeType *node_type_find(const char *idname)
bNodeType *node_type_find(const StringRefNull idname)
{
if (idname[0]) {
bNodeType *nt = static_cast<bNodeType *>(BLI_ghash_lookup(nodetypes_hash, idname));
bNodeType *nt = static_cast<bNodeType *>(BLI_ghash_lookup(nodetypes_hash, idname.c_str()));
if (nt) {
return nt;
}
@@ -1668,10 +1669,11 @@ bNodeType *node_type_find(const char *idname)
return nullptr;
}
const char *node_type_find_alias(const char *alias)
StringRefNull node_type_find_alias(const StringRefNull alias)
{
if (alias[0]) {
const char *idname = static_cast<const char *>(BLI_ghash_lookup(nodetypes_alias_hash, alias));
const char *idname = static_cast<const char *>(
BLI_ghash_lookup(nodetypes_alias_hash, alias.c_str()));
if (idname) {
return idname;
}
@@ -1720,9 +1722,9 @@ void node_unregister_type(bNodeType *nt)
BLI_ghash_remove(nodetypes_hash, nt->idname, nullptr, node_free_type);
}
void node_register_alias(bNodeType *nt, const char *alias)
void node_register_alias(bNodeType *nt, const StringRefNull alias)
{
BLI_ghash_insert(nodetypes_alias_hash, BLI_strdup(alias), BLI_strdup(nt->idname));
BLI_ghash_insert(nodetypes_alias_hash, BLI_strdup(alias.c_str()), BLI_strdup(nt->idname));
}
bool node_type_is_undefined(const bNode *node)
@@ -1752,11 +1754,11 @@ GHashIterator *node_type_get_iterator()
return BLI_ghashIterator_new(nodetypes_hash);
}
bNodeSocketType *node_socket_type_find(const char *idname)
bNodeSocketType *node_socket_type_find(const StringRefNull idname)
{
if (idname && idname[0]) {
if (idname[0]) {
bNodeSocketType *st = static_cast<bNodeSocketType *>(
BLI_ghash_lookup(nodesockettypes_hash, idname));
BLI_ghash_lookup(nodesockettypes_hash, idname.c_str()));
if (st) {
return st;
}
@@ -1800,7 +1802,7 @@ GHashIterator *node_socket_type_get_iterator()
return BLI_ghashIterator_new(nodesockettypes_hash);
}
const char *node_socket_type_label(const bNodeSocketType *stype)
StringRefNull node_socket_type_label(const bNodeSocketType *stype)
{
/* Use socket type name as a fallback if label is undefined. */
if (stype->label[0] == '\0') {
@@ -1809,7 +1811,7 @@ const char *node_socket_type_label(const bNodeSocketType *stype)
return stype->label;
}
const char *node_socket_sub_type_label(int subtype)
StringRefNull node_socket_sub_type_label(int subtype)
{
const char *name;
if (RNA_enum_name(rna_enum_property_subtype_items, subtype, &name)) {
@@ -1877,19 +1879,19 @@ static bNodeSocket *make_socket(bNodeTree *ntree,
bNode * /*node*/,
const int in_out,
ListBase *lb,
const char *idname,
const char *identifier,
const char *name)
const StringRefNull idname,
const StringRefNull identifier,
const StringRefNull name)
{
char auto_identifier[MAX_NAME];
if (identifier && identifier[0] != '\0') {
if (identifier[0] != '\0') {
/* use explicit identifier */
STRNCPY(auto_identifier, identifier);
STRNCPY(auto_identifier, identifier.c_str());
}
else {
/* if no explicit identifier is given, assign a unique identifier based on the name */
STRNCPY(auto_identifier, name);
STRNCPY(auto_identifier, name.c_str());
}
/* Make the identifier unique. */
BLI_uniquename_cb(
@@ -1902,12 +1904,12 @@ static bNodeSocket *make_socket(bNodeTree *ntree,
STRNCPY(sock->identifier, auto_identifier);
sock->limit = (in_out == SOCK_IN ? 1 : 0xFFF);
STRNCPY(sock->name, name);
STRNCPY(sock->name, name.c_str());
sock->storage = nullptr;
sock->flag |= SOCK_COLLAPSED;
sock->type = SOCK_CUSTOM; /* int type undefined by default */
STRNCPY(sock->idname, idname);
STRNCPY(sock->idname, idname.c_str());
node_socket_set_typeinfo(ntree, sock, node_socket_type_find(idname));
return sock;
@@ -2012,7 +2014,7 @@ static bool socket_id_user_decrement(bNodeSocket *sock)
void node_modify_socket_type(bNodeTree *ntree,
bNode * /*node*/,
bNodeSocket *sock,
const char *idname)
const StringRefNull idname)
{
bNodeSocketType *socktype = node_socket_type_find(idname);
@@ -2067,29 +2069,29 @@ void node_modify_socket_type(bNodeTree *ntree,
}
}
STRNCPY(sock->idname, idname);
STRNCPY(sock->idname, idname.c_str());
node_socket_set_typeinfo(ntree, sock, socktype);
}
void node_modify_socket_type_static(
bNodeTree *ntree, bNode *node, bNodeSocket *sock, const int type, const int subtype)
{
const char *idname = node_static_socket_type(type, subtype);
const std::optional<StringRefNull> idname = node_static_socket_type(type, subtype);
if (!idname) {
if (!idname.has_value()) {
CLOG_ERROR(&LOG, "static node socket type %d undefined", type);
return;
}
node_modify_socket_type(ntree, node, sock, idname);
node_modify_socket_type(ntree, node, sock, *idname);
}
bNodeSocket *node_add_socket(bNodeTree *ntree,
bNode *node,
const eNodeSocketInOut in_out,
const char *idname,
const char *identifier,
const char *name)
const StringRefNull idname,
const StringRefNull identifier,
const StringRefNull name)
{
BLI_assert(node->type != NODE_FRAME);
BLI_assert(!(in_out == SOCK_IN && node->type == NODE_GROUP_INPUT));
@@ -2115,7 +2117,7 @@ bool node_is_static_socket_type(const bNodeSocketType *stype)
return RNA_struct_is_a(stype->ext_socket.srna, &RNA_NodeSocketStandard);
}
const char *node_static_socket_type(const int type, const int subtype)
std::optional<StringRefNull> node_static_socket_type(const int type, const int subtype)
{
switch (eNodeSocketDatatype(type)) {
case SOCK_FLOAT:
@@ -2208,10 +2210,11 @@ const char *node_static_socket_type(const int type, const int subtype)
case SOCK_CUSTOM:
break;
}
return nullptr;
return std::nullopt;
}
const char *node_static_socket_interface_type_new(const int type, const int subtype)
std::optional<StringRefNull> node_static_socket_interface_type_new(const int type,
const int subtype)
{
switch (eNodeSocketDatatype(type)) {
case SOCK_FLOAT:
@@ -2304,10 +2307,10 @@ const char *node_static_socket_interface_type_new(const int type, const int subt
case SOCK_CUSTOM:
break;
}
return nullptr;
return std::nullopt;
}
const char *node_static_socket_label(const int type, const int /*subtype*/)
std::optional<StringRefNull> node_static_socket_label(const int type, const int /*subtype*/)
{
switch (eNodeSocketDatatype(type)) {
case SOCK_FLOAT:
@@ -2345,7 +2348,7 @@ const char *node_static_socket_label(const int type, const int /*subtype*/)
case SOCK_CUSTOM:
break;
}
return nullptr;
return std::nullopt;
}
bNodeSocket *node_add_static_socket(bNodeTree *ntree,
@@ -2353,17 +2356,17 @@ bNodeSocket *node_add_static_socket(bNodeTree *ntree,
eNodeSocketInOut in_out,
int type,
int subtype,
const char *identifier,
const char *name)
const StringRefNull identifier,
const StringRefNull name)
{
const char *idname = node_static_socket_type(type, subtype);
const std::optional<StringRefNull> idname = node_static_socket_type(type, subtype);
if (!idname) {
if (!idname.has_value()) {
CLOG_ERROR(&LOG, "static node socket type %d undefined", type);
return nullptr;
}
bNodeSocket *sock = node_add_socket(ntree, node, in_out, idname, identifier, name);
bNodeSocket *sock = node_add_socket(ntree, node, in_out, *idname, identifier, name);
sock->type = type;
return sock;
}
@@ -2426,9 +2429,10 @@ void node_remove_socket_ex(bNodeTree *ntree, bNode *node, bNodeSocket *sock, con
BKE_ntree_update_tag_socket_removed(ntree);
}
bNode *node_find_node_by_name(bNodeTree *ntree, const char *name)
bNode *node_find_node_by_name(bNodeTree *ntree, const StringRefNull name)
{
return reinterpret_cast<bNode *>(BLI_findstring(&ntree->nodes, name, offsetof(bNode, name)));
return reinterpret_cast<bNode *>(
BLI_findstring(&ntree->nodes, name.c_str(), offsetof(bNode, name)));
}
void node_find_node(bNodeTree *ntree, bNodeSocket *sock, bNode **r_node, int *r_sockindex)
@@ -2606,7 +2610,7 @@ void node_unique_id(bNodeTree *ntree, bNode *node)
BLI_assert(node->runtime->index_in_tree == ntree->runtime->nodes_by_id.index_of(node));
}
bNode *node_add_node(const bContext *C, bNodeTree *ntree, const char *idname)
bNode *node_add_node(const bContext *C, bNodeTree *ntree, const StringRefNull idname)
{
bNode *node = MEM_cnew<bNode>("new node");
node->runtime = MEM_new<bNodeRuntime>(__func__);
@@ -2614,7 +2618,7 @@ bNode *node_add_node(const bContext *C, bNodeTree *ntree, const char *idname)
node_unique_id(ntree, node);
node->ui_order = ntree->all_nodes().size();
STRNCPY(node->idname, idname);
STRNCPY(node->idname, idname.c_str());
node_set_typeinfo(C, ntree, node, node_type_find(idname));
BKE_ntree_update_tag_node_new(ntree, node);
@@ -3182,8 +3186,8 @@ static bNodeTree *node_tree_add_tree_do(Main *bmain,
std::optional<Library *> owner_library,
ID *owner_id,
const bool is_embedded,
const char *name,
const char *idname)
const StringRefNull name,
const StringRefNull idname)
{
/* trees are created as local trees for compositor, material or texture nodes,
* node groups and other tree types are created as library data.
@@ -3195,7 +3199,7 @@ static bNodeTree *node_tree_add_tree_do(Main *bmain,
BLI_assert_msg(!owner_library || !owner_id,
"Embedded NTrees should never have a defined owner library here");
bNodeTree *ntree = reinterpret_cast<bNodeTree *>(
BKE_libblock_alloc_in_lib(bmain, owner_library, ID_NT, name, flag));
BKE_libblock_alloc_in_lib(bmain, owner_library, ID_NT, name.c_str(), flag));
BKE_libblock_init_empty(&ntree->id);
if (is_embedded) {
BLI_assert(owner_id != nullptr);
@@ -3209,29 +3213,29 @@ static bNodeTree *node_tree_add_tree_do(Main *bmain,
BLI_assert(owner_id == nullptr);
}
STRNCPY(ntree->idname, idname);
STRNCPY(ntree->idname, idname.c_str());
ntree_set_typeinfo(ntree, node_tree_type_find(idname));
return ntree;
}
bNodeTree *node_tree_add_tree(Main *bmain, const char *name, const char *idname)
bNodeTree *node_tree_add_tree(Main *bmain, const StringRefNull name, const StringRefNull idname)
{
return node_tree_add_tree_do(bmain, std::nullopt, nullptr, false, name, idname);
}
bNodeTree *node_tree_add_in_lib(Main *bmain,
Library *owner_library,
const char *name,
const char *idname)
const StringRefNull name,
const StringRefNull idname)
{
return node_tree_add_tree_do(bmain, owner_library, nullptr, false, name, idname);
}
bNodeTree *node_tree_add_tree_embedded(Main * /*bmain*/,
ID *owner_id,
const char *name,
const char *idname)
const StringRefNull name,
const StringRefNull idname)
{
return node_tree_add_tree_do(nullptr, std::nullopt, owner_id, true, name, idname);
}
@@ -4056,10 +4060,10 @@ static bool node_instance_hash_key_cmp(const void *a, const void *b)
return (value_a != value_b);
}
bNodeInstanceHash *node_instance_hash_new(const char *info)
bNodeInstanceHash *node_instance_hash_new(const StringRefNull info)
{
bNodeInstanceHash *hash = static_cast<bNodeInstanceHash *>(
MEM_mallocN(sizeof(bNodeInstanceHash), info));
MEM_mallocN(sizeof(bNodeInstanceHash), info.c_str()));
hash->ghash = BLI_ghash_new(
node_instance_hash_key, node_instance_hash_key_cmp, "node instance hash ghash");
return hash;
@@ -4274,7 +4278,7 @@ void nodeLabel(const bNodeTree *ntree, const bNode *node, char *label, const int
BLI_strncpy(label, IFACE_(node->typeinfo->ui_name), label_maxncpy);
}
const char *nodeSocketShortLabel(const bNodeSocket *sock)
std::optional<StringRefNull> nodeSocketShortLabel(const bNodeSocket *sock)
{
if (sock->runtime->declaration != nullptr) {
StringRefNull short_label = sock->runtime->declaration->short_label;
@@ -4282,10 +4286,10 @@ const char *nodeSocketShortLabel(const bNodeSocket *sock)
return sock->runtime->declaration->short_label.data();
}
}
return nullptr;
return std::nullopt;
}
const char *nodeSocketLabel(const bNodeSocket *sock)
StringRefNull nodeSocketLabel(const bNodeSocket *sock)
{
return (sock->label[0] != '\0') ? sock->label : sock->name;
}
@@ -4314,7 +4318,7 @@ static bool node_poll_instance_default(const bNode *node,
return node->typeinfo->poll(node->typeinfo, ntree, r_disabled_hint);
}
void node_type_base(bNodeType *ntype, const int type, const char *name, const short nclass)
void node_type_base(bNodeType *ntype, const int type, const StringRefNull name, const short nclass)
{
/* Use static type info header to map static int type to identifier string and RNA struct type.
* Associate the RNA struct type with the bNodeType.
@@ -4344,7 +4348,7 @@ void node_type_base(bNodeType *ntype, const int type, const char *name, const sh
BLI_assert(ntype->idname[0] != '\0');
ntype->type = type;
STRNCPY(ntype->ui_name, name);
STRNCPY(ntype->ui_name, name.c_str());
ntype->nclass = nclass;
node_type_base_defaults(ntype);
@@ -4354,16 +4358,16 @@ void node_type_base(bNodeType *ntype, const int type, const char *name, const sh
}
void node_type_base_custom(bNodeType *ntype,
const char *idname,
const char *name,
const char *enum_name,
const StringRefNull idname,
const StringRefNull name,
const StringRefNull enum_name,
const short nclass)
{
STRNCPY(ntype->idname, idname);
STRNCPY(ntype->idname, idname.c_str());
ntype->type = NODE_CUSTOM;
STRNCPY(ntype->ui_name, name);
STRNCPY(ntype->ui_name, name.c_str());
ntype->nclass = nclass;
ntype->enum_name_legacy = enum_name;
ntype->enum_name_legacy = enum_name.c_str();
node_type_base_defaults(ntype);
}
@@ -4422,7 +4426,7 @@ std::optional<eNodeSocketDatatype> custom_data_type_to_socket_type(eCustomDataTy
static const CPPType *slow_socket_type_to_geo_nodes_base_cpp_type(const eNodeSocketDatatype type)
{
const char *socket_idname = node_static_socket_type(type, 0);
const StringRefNull socket_idname = *node_static_socket_type(type, 0);
const bNodeSocketType *typeinfo = node_socket_type_find(socket_idname);
return typeinfo->base_cpp_type;
}
@@ -4622,14 +4626,14 @@ void node_type_size_preset(bNodeType *ntype, const eNodeSizePreset size)
}
void node_type_storage(bNodeType *ntype,
const char *storagename,
const std::optional<StringRefNull> storagename,
void (*freefunc)(bNode *node),
void (*copyfunc)(bNodeTree *dest_ntree,
bNode *dest_node,
const bNode *src_node))
{
if (storagename) {
STRNCPY(ntype->storagename, storagename);
if (storagename.has_value()) {
STRNCPY(ntype->storagename, storagename->c_str());
}
else {
ntype->storagename[0] = '\0';

View File

@@ -49,7 +49,12 @@ static const char *try_get_supported_socket_type(const StringRef socket_type)
}
/* For builtin socket types only the base type is supported. */
if (node_is_static_socket_type(typeinfo)) {
return bke::node_static_socket_type(typeinfo->type, PROP_NONE);
const std::optional<StringRefNull> type_name = bke::node_static_socket_type(typeinfo->type,
PROP_NONE);
if (type_name.has_value()) {
return type_name->c_str();
}
return nullptr;
}
return typeinfo->idname;
}

View File

@@ -856,33 +856,33 @@ static const char *node_get_static_idname(int type, int treetype)
return "";
}
static const char *node_socket_get_static_idname(bNodeSocket *sock)
static blender::StringRefNull node_socket_get_static_idname(bNodeSocket *sock)
{
switch (sock->type) {
case SOCK_FLOAT: {
bNodeSocketValueFloat *dval = sock->default_value_typed<bNodeSocketValueFloat>();
return blender::bke::node_static_socket_type(SOCK_FLOAT, dval->subtype);
return *blender::bke::node_static_socket_type(SOCK_FLOAT, dval->subtype);
}
case SOCK_INT: {
bNodeSocketValueInt *dval = sock->default_value_typed<bNodeSocketValueInt>();
return blender::bke::node_static_socket_type(SOCK_INT, dval->subtype);
return *blender::bke::node_static_socket_type(SOCK_INT, dval->subtype);
}
case SOCK_BOOLEAN: {
return blender::bke::node_static_socket_type(SOCK_BOOLEAN, PROP_NONE);
return *blender::bke::node_static_socket_type(SOCK_BOOLEAN, PROP_NONE);
}
case SOCK_VECTOR: {
bNodeSocketValueVector *dval = sock->default_value_typed<bNodeSocketValueVector>();
return blender::bke::node_static_socket_type(SOCK_VECTOR, dval->subtype);
return *blender::bke::node_static_socket_type(SOCK_VECTOR, dval->subtype);
}
case SOCK_RGBA: {
return blender::bke::node_static_socket_type(SOCK_RGBA, PROP_NONE);
return *blender::bke::node_static_socket_type(SOCK_RGBA, PROP_NONE);
}
case SOCK_STRING: {
bNodeSocketValueString *dval = sock->default_value_typed<bNodeSocketValueString>();
return blender::bke::node_static_socket_type(SOCK_STRING, dval->subtype);
return *blender::bke::node_static_socket_type(SOCK_STRING, dval->subtype);
}
case SOCK_SHADER: {
return blender::bke::node_static_socket_type(SOCK_SHADER, PROP_NONE);
return *blender::bke::node_static_socket_type(SOCK_SHADER, PROP_NONE);
}
}
return "";
@@ -917,18 +917,18 @@ static void do_versions_nodetree_customnodes(bNodeTree *ntree, int /*is_group*/)
/* sockets idname */
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
STRNCPY(sock->idname, node_socket_get_static_idname(sock));
STRNCPY(sock->idname, node_socket_get_static_idname(sock).c_str());
}
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
STRNCPY(sock->idname, node_socket_get_static_idname(sock));
STRNCPY(sock->idname, node_socket_get_static_idname(sock).c_str());
}
}
/* tree sockets idname */
LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs_legacy) {
STRNCPY(sock->idname, node_socket_get_static_idname(sock));
STRNCPY(sock->idname, node_socket_get_static_idname(sock).c_str());
}
LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs_legacy) {
STRNCPY(sock->idname, node_socket_get_static_idname(sock));
STRNCPY(sock->idname, node_socket_get_static_idname(sock).c_str());
}
}

View File

@@ -1497,7 +1497,7 @@ static bNodeSocket *do_version_replace_float_size_with_vector(bNodeTree *ntree,
ntree,
node,
SOCK_IN,
blender::bke::node_static_socket_type(SOCK_VECTOR, PROP_TRANSLATION),
*blender::bke::node_static_socket_type(SOCK_VECTOR, PROP_TRANSLATION),
"Size",
"Size");
bNodeSocketValueVector *value_vector = (bNodeSocketValueVector *)new_socket->default_value;

View File

@@ -62,7 +62,7 @@ static void draw_node_input(bContext *C,
}
PointerRNA socket_ptr = RNA_pointer_create(node_ptr->owner_id, &RNA_NodeSocket, &socket);
const char *text = IFACE_(bke::nodeSocketLabel(&socket));
const StringRefNull text(IFACE_(bke::nodeSocketLabel(&socket).c_str()));
uiLayout *row = uiLayoutRow(layout, true);
socket.typeinfo->draw(C, row, &socket_ptr, node_ptr, text);
}

View File

@@ -83,9 +83,9 @@ static void node_socket_button_label(bContext * /*C*/,
uiLayout *layout,
PointerRNA * /*ptr*/,
PointerRNA * /*node_ptr*/,
const char *text)
const StringRefNull text)
{
uiItemL(layout, text, ICON_NONE);
uiItemL(layout, text.c_str(), ICON_NONE);
}
/* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
@@ -1027,7 +1027,7 @@ static void node_socket_undefined_draw(bContext * /*C*/,
uiLayout *layout,
PointerRNA * /*ptr*/,
PointerRNA * /*node_ptr*/,
const char * /*text*/)
StringRefNull /*text*/)
{
uiItemL(layout, IFACE_("Undefined Socket Type"), ICON_ERROR);
}
@@ -1257,7 +1257,7 @@ static void draw_node_socket_without_value(uiLayout *layout, bNodeSocket *sock,
}
static void std_node_socket_draw(
bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, const char *text)
bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, StringRefNull text)
{
bNode *node = (bNode *)node_ptr->data;
bNodeSocket *sock = (bNodeSocket *)ptr->data;
@@ -1288,13 +1288,13 @@ static void std_node_socket_draw(
if (node->is_group_input()) {
uiLayout *row = uiLayoutRow(layout, false);
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
node_socket_button_label(C, row, ptr, node_ptr, text);
node_socket_button_label(C, row, ptr, node_ptr, text.c_str());
uiItemL(row, "", ICON_GIZMO);
}
else if (nodes::partial_eval::is_supported_value_node(*node)) {
uiLayout *row = uiLayoutRow(layout, false);
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
node_socket_button_label(C, row, ptr, node_ptr, text);
node_socket_button_label(C, row, ptr, node_ptr, text.c_str());
draw_gizmo_pin_icon(row, ptr);
}
return;
@@ -1303,7 +1303,7 @@ static void std_node_socket_draw(
nodes::gizmos::is_builtin_gizmo_node(*node))
{
uiLayout *row = uiLayoutRow(layout, false);
node_socket_button_label(C, row, ptr, node_ptr, text);
node_socket_button_label(C, row, ptr, node_ptr, text.c_str());
draw_gizmo_pin_icon(row, ptr);
return;
}
@@ -1312,11 +1312,11 @@ static void std_node_socket_draw(
if ((sock->in_out == SOCK_OUT) || (sock->flag & SOCK_HIDE_VALUE) ||
((sock->flag & SOCK_IS_LINKED) && !all_links_muted(*sock)))
{
draw_node_socket_without_value(layout, sock, text);
draw_node_socket_without_value(layout, sock, text.c_str());
return;
}
const char *label = text;
const StringRefNull label = text.c_str();
text = (sock->flag & SOCK_HIDE_LABEL) ? "" : text;
/* Some socket types draw the gizmo icon in a special way to look better. All others use a
@@ -1327,11 +1327,11 @@ static void std_node_socket_draw(
case SOCK_FLOAT:
case SOCK_INT:
case SOCK_BOOLEAN:
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text, ICON_NONE);
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text.c_str(), ICON_NONE);
break;
case SOCK_VECTOR:
if (sock->flag & SOCK_COMPACT) {
uiTemplateComponentMenu(layout, ptr, "default_value", text);
uiTemplateComponentMenu(layout, ptr, "default_value", text.c_str());
}
else {
if (sock->typeinfo->subtype == PROP_DIRECTION) {
@@ -1341,7 +1341,7 @@ static void std_node_socket_draw(
uiLayout *column = uiLayoutColumn(layout, false);
{
uiLayout *row = uiLayoutRow(column, true);
draw_node_socket_name_editable(row, sock, text);
draw_node_socket_name_editable(row, sock, text.c_str());
if (has_gizmo) {
draw_gizmo_pin_icon(row, ptr);
gizmo_handled = true;
@@ -1355,7 +1355,7 @@ static void std_node_socket_draw(
uiLayout *column = uiLayoutColumn(layout, false);
{
uiLayout *row = uiLayoutRow(column, true);
draw_node_socket_name_editable(row, sock, text);
draw_node_socket_name_editable(row, sock, text.c_str());
if (has_gizmo) {
draw_gizmo_pin_icon(row, ptr);
gizmo_handled = true;
@@ -1365,7 +1365,7 @@ static void std_node_socket_draw(
break;
}
case SOCK_MATRIX: {
draw_node_socket_name_editable(layout, sock, text);
draw_node_socket_name_editable(layout, sock, text.c_str());
break;
}
case SOCK_RGBA: {
@@ -1374,7 +1374,7 @@ static void std_node_socket_draw(
}
else {
uiLayout *row = uiLayoutSplit(layout, 0.4f, false);
uiItemL(row, text, ICON_NONE);
uiItemL(row, text.c_str(), ICON_NONE);
uiItemR(row, ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
}
break;
@@ -1382,11 +1382,11 @@ static void std_node_socket_draw(
case SOCK_STRING: {
if (socket_needs_attribute_search(*node, *sock)) {
if (text[0] == '\0') {
node_geometry_add_attribute_search_button(*C, *node, *ptr, *layout, label);
node_geometry_add_attribute_search_button(*C, *node, *ptr, *layout, label.c_str());
}
else {
uiLayout *row = uiLayoutSplit(layout, 0.4f, false);
uiItemL(row, text, ICON_NONE);
uiItemL(row, text.c_str(), ICON_NONE);
node_geometry_add_attribute_search_button(*C, *node, *ptr, *row);
}
}
@@ -1400,11 +1400,11 @@ static void std_node_socket_draw(
UI_ITEM_NONE,
"",
ICON_NONE,
label);
label.c_str());
}
else {
uiLayout *row = uiLayoutSplit(layout, 0.4f, false);
uiItemL(row, text, ICON_NONE);
uiItemL(row, text.c_str(), ICON_NONE);
uiItemR(row, ptr, "default_value", DEFAULT_FLAGS, "", ICON_NONE);
}
}
@@ -1416,7 +1416,7 @@ static void std_node_socket_draw(
if (default_value->enum_items) {
if (default_value->enum_items->items.is_empty()) {
uiLayout *row = uiLayoutSplit(layout, 0.4f, false);
uiItemL(row, text, ICON_NONE);
uiItemL(row, text.c_str(), ICON_NONE);
uiItemL(row, IFACE_("No Items"), ICON_NONE);
}
else {
@@ -1432,7 +1432,7 @@ static void std_node_socket_draw(
break;
}
case SOCK_OBJECT: {
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text, ICON_NONE);
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text.c_str(), ICON_NONE);
break;
}
case SOCK_IMAGE: {
@@ -1444,17 +1444,17 @@ static void std_node_socket_draw(
else {
/* 0.3 split ratio is inconsistent, but use it here because the "New" button is large. */
uiLayout *row = uiLayoutSplit(layout, 0.3f, false);
uiItemL(row, text, ICON_NONE);
uiItemL(row, text.c_str(), ICON_NONE);
uiTemplateID(row, C, ptr, "default_value", "image.new", "image.open", nullptr);
}
}
else {
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text, ICON_NONE);
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text.c_str(), ICON_NONE);
}
break;
}
case SOCK_COLLECTION: {
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text, ICON_NONE);
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text.c_str(), ICON_NONE);
break;
}
case SOCK_TEXTURE: {
@@ -1464,18 +1464,18 @@ static void std_node_socket_draw(
else {
/* 0.3 split ratio is inconsistent, but use it here because the "New" button is large. */
uiLayout *row = uiLayoutSplit(layout, 0.3f, false);
uiItemL(row, text, ICON_NONE);
uiItemL(row, text.c_str(), ICON_NONE);
uiTemplateID(row, C, ptr, "default_value", "texture.new", nullptr, nullptr);
}
break;
}
case SOCK_MATERIAL: {
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text, ICON_NONE);
uiItemR(layout, ptr, "default_value", DEFAULT_FLAGS, text.c_str(), ICON_NONE);
break;
}
default:
draw_node_socket_without_value(layout, sock, text);
draw_node_socket_without_value(layout, sock, text.c_str());
break;
}

View File

@@ -446,15 +446,16 @@ const char *node_socket_get_label(const bNodeSocket *socket, const char *panel_l
{
/* Get the short label if possible. This is used when grouping sockets under panels,
* to avoid redundancy in the label. */
const char *socket_short_label = bke::nodeSocketShortLabel(socket);
const std::optional<StringRefNull> socket_short_label = bke::nodeSocketShortLabel(socket);
const char *socket_translation_context = node_socket_get_translation_context(*socket);
if (socket_short_label) {
return CTX_IFACE_(socket_translation_context, socket_short_label);
if (socket_short_label.has_value()) {
return CTX_IFACE_(socket_translation_context, socket_short_label->c_str());
}
const char *socket_label = bke::nodeSocketLabel(socket);
const char *translated_socket_label = CTX_IFACE_(socket_translation_context, socket_label);
const StringRefNull socket_label = bke::nodeSocketLabel(socket);
const char *translated_socket_label = CTX_IFACE_(socket_translation_context,
socket_label.c_str());
/* Shorten socket label if it begins with the panel label. */
if (panel_label) {

View File

@@ -607,12 +607,12 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
}
}
static void node_menu_column_foreach_cb(void *calldata, int nclass, const char *name)
static void node_menu_column_foreach_cb(void *calldata, int nclass, const StringRefNull name)
{
NodeLinkArg *arg = (NodeLinkArg *)calldata;
if (!ELEM(nclass, NODE_CLASS_GROUP, NODE_CLASS_LAYOUT)) {
ui_node_menu_column(arg, nclass, name);
ui_node_menu_column(arg, nclass, name.c_str());
}
}

View File

@@ -45,6 +45,8 @@ const EnumPropertyItem rna_enum_node_socket_type_items[] = {
# include "DNA_material_types.h"
# include "BLI_string_ref.hh"
# include "BKE_node.hh"
# include "BKE_node_enum.hh"
# include "BKE_node_runtime.hh"
@@ -62,8 +64,11 @@ extern FunctionRNA rna_NodeSocket_draw_color_simple_func;
/* ******** Node Socket ******** */
static void rna_NodeSocket_draw(
bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *node_ptr, const char *text)
static void rna_NodeSocket_draw(bContext *C,
uiLayout *layout,
PointerRNA *ptr,
PointerRNA *node_ptr,
const blender::StringRefNull text)
{
bNodeSocket *sock = static_cast<bNodeSocket *>(ptr->data);
ParameterList list;

View File

@@ -30,6 +30,8 @@ static const EnumPropertyItem node_tree_interface_socket_in_out_items[] = {
# include <fmt/format.h>
# include "BLI_string_ref.hh"
# include "BKE_attribute.hh"
# include "BKE_node.hh"
# include "BKE_node_enum.hh"
@@ -195,7 +197,7 @@ static void rna_NodeTreeInterfaceSocket_init_socket_custom(
const bNodeTreeInterfaceSocket *interface_socket,
bNode *node,
bNodeSocket *socket,
const char *data_path)
const blender::StringRefNull data_path)
{
blender::bke::bNodeSocketType *typeinfo = blender::bke::node_socket_type_find(
interface_socket->socket_type);

View File

@@ -795,7 +795,7 @@ const EnumPropertyItem *rna_node_socket_type_itemf(
tmp.value = i;
tmp.identifier = stype->idname;
tmp.icon = RNA_struct_ui_icon(srna);
tmp.name = blender::bke::node_socket_type_label(stype);
tmp.name = blender::bke::node_socket_type_label(stype).c_str();
tmp.description = RNA_struct_ui_description(srna);
RNA_enum_item_add(&item, &totitem, &tmp);
@@ -1174,7 +1174,7 @@ static const EnumPropertyItem *rna_NodeTree_color_tag_itemf(bContext * /*C*/,
static bNode *rna_NodeTree_node_new(bNodeTree *ntree,
bContext *C,
ReportList *reports,
const char *type)
blender::StringRefNull type)
{
blender::bke::bNodeType *ntype;
bNode *node;
@@ -1188,7 +1188,7 @@ static bNode *rna_NodeTree_node_new(bNodeTree *ntree,
ntype = blender::bke::node_type_find(type);
if (!ntype) {
BKE_reportf(reports, RPT_ERROR, "Node type %s undefined", type);
BKE_reportf(reports, RPT_ERROR, "Node type %s undefined", type.c_str());
return nullptr;
}
@@ -1198,7 +1198,7 @@ static bNode *rna_NodeTree_node_new(bNodeTree *ntree,
BKE_reportf(reports,
RPT_ERROR,
"Cannot add node of type %s to node tree '%s'\n %s",
type,
type.c_str(),
ntree->id.name + 2,
disabled_hint);
return nullptr;
@@ -1207,7 +1207,7 @@ static bNode *rna_NodeTree_node_new(bNodeTree *ntree,
BKE_reportf(reports,
RPT_ERROR,
"Cannot add node of type %s to node tree '%s'",
type,
type.c_str(),
ntree->id.name + 2);
return nullptr;
}
@@ -3696,9 +3696,9 @@ static void rna_Node_ItemArray_item_color_get(PointerRNA *ptr, float *values)
{
using ItemT = typename Accessors::ItemT;
ItemT &item = *static_cast<ItemT *>(ptr->data);
const char *socket_type_idname = blender::bke::node_static_socket_type(
const blender::StringRefNull socket_type_idname = *blender::bke::node_static_socket_type(
Accessors::get_socket_type(item), 0);
ED_node_type_draw_color(socket_type_idname, values);
ED_node_type_draw_color(socket_type_idname.c_str(), values);
}
template<typename Accessor>
@@ -4191,6 +4191,9 @@ static void rna_reroute_node_socket_type_set(PointerRNA *ptr, const char *value)
bNode &node = *static_cast<bNode *>(ptr->data);
if (value == nullptr) {
return;
}
blender::bke::bNodeSocketType *socket_type = blender::bke::node_socket_type_find(value);
if (socket_type == nullptr) {
return;

View File

@@ -95,9 +95,9 @@ inline void set_item_name_and_make_unique(bNode &node,
{
using ItemT = typename Accessor::ItemT;
SocketItemsRef array = Accessor::get_items_from_node(node);
const char *default_name = "Item";
StringRefNull default_name = "Item";
if constexpr (Accessor::has_type) {
default_name = bke::node_static_socket_label(Accessor::get_socket_type(item), 0);
default_name = *bke::node_static_socket_label(Accessor::get_socket_type(item), 0);
}
char unique_name[MAX_NAME + 4];
@@ -120,7 +120,7 @@ inline void set_item_name_and_make_unique(bNode &node,
return false;
},
&args,
default_name,
default_name.c_str(),
'.',
unique_name,
ARRAY_SIZE(unique_name));

View File

@@ -820,8 +820,10 @@ void register_node_type_cmp_rlayers()
ntype.realtime_compositor_unsupported_message = N_(
"Render passes not supported in the Viewport compositor");
ntype.flag |= NODE_PREVIEW;
blender::bke::node_type_storage(
&ntype, nullptr, file_ns::node_composit_free_rlayers, file_ns::node_composit_copy_rlayers);
blender::bke::node_type_storage(&ntype,
std::nullopt,
file_ns::node_composit_free_rlayers,
file_ns::node_composit_copy_rlayers);
ntype.updatefunc = file_ns::cmp_node_rlayers_update;
ntype.initfunc = node_cmp_rlayers_outputs;
blender::bke::node_type_size_preset(&ntype, blender::bke::eNodeSizePreset::Large);

View File

@@ -186,7 +186,8 @@ void register_node_type_cmp_moviedistortion()
ntype.draw_buttons = file_ns::node_composit_buts_moviedistortion;
ntype.labelfunc = file_ns::label;
ntype.initfunc_api = file_ns::init;
blender::bke::node_type_storage(&ntype, nullptr, file_ns::storage_free, file_ns::storage_copy);
blender::bke::node_type_storage(
&ntype, std::nullopt, file_ns::storage_free, file_ns::storage_copy);
ntype.get_compositor_operation = file_ns::get_compositor_operation;
blender::bke::node_register_type(&ntype);

View File

@@ -122,7 +122,7 @@ static bool node_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
static const CPPType &get_item_cpp_type(const eNodeSocketDatatype socket_type)
{
const char *socket_idname = bke::node_static_socket_type(socket_type, 0);
const StringRefNull socket_idname = *bke::node_static_socket_type(socket_type, 0);
const bke::bNodeSocketType *typeinfo = bke::node_socket_type_find(socket_idname);
BLI_assert(typeinfo);
BLI_assert(typeinfo->geometry_nodes_cpp_type);

View File

@@ -237,7 +237,7 @@ class LazyFunctionForMenuSwitchNode : public LazyFunction {
const eNodeSocketDatatype data_type = eNodeSocketDatatype(storage.data_type);
can_be_field_ = socket_type_supports_fields(data_type);
const bke::bNodeSocketType *socket_type = bke::node_socket_type_find(
bke::node_static_socket_type(data_type, PROP_NONE));
*bke::node_static_socket_type(data_type, PROP_NONE));
BLI_assert(socket_type != nullptr);
cpp_type_ = socket_type->geometry_nodes_cpp_type;
field_base_type_ = socket_type->base_cpp_type;

View File

@@ -65,7 +65,7 @@ namespace blender::nodes::node_geo_simulation_cc {
static const CPPType &get_simulation_item_cpp_type(const eNodeSocketDatatype socket_type)
{
const char *socket_idname = bke::node_static_socket_type(socket_type, 0);
const StringRefNull socket_idname = *bke::node_static_socket_type(socket_type, 0);
const bke::bNodeSocketType *typeinfo = bke::node_socket_type_find(socket_idname);
BLI_assert(typeinfo);
BLI_assert(typeinfo->geometry_nodes_cpp_type);

View File

@@ -825,7 +825,7 @@ static void standard_node_socket_interface_init_socket(
const bNodeTreeInterfaceSocket *interface_socket,
bNode * /*node*/,
bNodeSocket *sock,
const char * /*data_path*/)
StringRefNull /*data_path*/)
{
/* initialize the type value */
sock->type = sock->typeinfo->type;
@@ -849,28 +849,29 @@ void ED_init_standard_node_socket_type(bke::bNodeSocketType *);
static bke::bNodeSocketType *make_standard_socket_type(int type, int subtype)
{
const char *socket_idname = bke::node_static_socket_type(type, subtype);
const char *interface_idname = bke::node_static_socket_interface_type_new(type, subtype);
const char *socket_label = bke::node_static_socket_label(type, subtype);
const char *socket_subtype_label = blender::bke::node_socket_sub_type_label(subtype);
const StringRefNull socket_idname = *bke::node_static_socket_type(type, subtype);
const StringRefNull interface_idname = *bke::node_static_socket_interface_type_new(type,
subtype);
const StringRefNull socket_label = *bke::node_static_socket_label(type, subtype);
const StringRefNull socket_subtype_label = blender::bke::node_socket_sub_type_label(subtype);
bke::bNodeSocketType *stype;
StructRNA *srna;
stype = MEM_cnew<bke::bNodeSocketType>("node socket C type");
stype->free_self = (void (*)(bke::bNodeSocketType *stype))MEM_freeN;
STRNCPY(stype->idname, socket_idname);
STRNCPY(stype->label, socket_label);
STRNCPY(stype->subtype_label, socket_subtype_label);
STRNCPY(stype->idname, socket_idname.c_str());
STRNCPY(stype->label, socket_label.c_str());
STRNCPY(stype->subtype_label, socket_subtype_label.c_str());
/* set the RNA type
* uses the exact same identifier as the socket type idname */
srna = stype->ext_socket.srna = RNA_struct_find(socket_idname);
srna = stype->ext_socket.srna = RNA_struct_find(socket_idname.c_str());
BLI_assert(srna != nullptr);
/* associate the RNA type with the socket type */
RNA_struct_blender_type_set(srna, stype);
/* set the interface RNA type */
srna = stype->ext_interface.srna = RNA_struct_find(interface_idname);
srna = stype->ext_interface.srna = RNA_struct_find(interface_idname.c_str());
BLI_assert(srna != nullptr);
/* associate the RNA type with the socket type */
RNA_struct_blender_type_set(srna, stype);

View File

@@ -62,8 +62,8 @@ static bool basic_types_can_connect(const SocketDeclaration & /*socket_decl*/,
static void modify_subtype_except_for_storage(bNodeSocket &socket, int new_subtype)
{
const char *idname = bke::node_static_socket_type(socket.type, new_subtype);
STRNCPY(socket.idname, idname);
const StringRefNull idname = *bke::node_static_socket_type(socket.type, new_subtype);
STRNCPY(socket.idname, idname.c_str());
bke::bNodeSocketType *socktype = bke::node_socket_type_find(idname);
socket.typeinfo = socktype;
}

View File

@@ -4144,7 +4144,7 @@ static PyObject *pyrna_struct_bl_rna_get_subclass(PyObject *cls, PyObject *args)
if (srna_base == &RNA_Node) {
/* If the given idname is an alias, translate it to the proper idname. */
id = blender::bke::node_type_find_alias(id);
id = blender::bke::node_type_find_alias(id).c_str();
blender::bke::bNodeType *nt = blender::bke::node_type_find(id);
if (nt) {