diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-03-29 13:47:16 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-03-29 14:05:05 +0300 |
commit | e0ce76f1c5eb70ab66755dce4627b918fc102cbd (patch) | |
tree | eb357ee487240b35705a530312a4723e2e97aecd /source/blender/makesrna | |
parent | 1ea51570514e5731ca8327f9dafbe6b7515a8142 (diff) |
Fix T86983: `bl_description = None` crash on RNA class registration
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 103 |
1 files changed, 57 insertions, 46 deletions
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index d67d62d7af9..4a51db4e652 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -1781,41 +1781,40 @@ static void rna_Operator_bl_label_set(PointerRNA *ptr, const char *value) } } -static void rna_Operator_bl_translation_context_set(PointerRNA *ptr, const char *value) -{ - wmOperator *data = (wmOperator *)(ptr->data); - char *str = (char *)data->type->translation_context; - if (!str[0]) { - BLI_strncpy(str, value, RNA_DYN_DESCR_MAX); /* utf8 already ensured */ - } - else { - BLI_assert(!"setting the bl_translation_context on a non-builtin operator"); - } -} - -static void rna_Operator_bl_description_set(PointerRNA *ptr, const char *value) -{ - wmOperator *data = (wmOperator *)(ptr->data); - char *str = (char *)data->type->description; - if (!str[0]) { - BLI_strncpy(str, value, RNA_DYN_DESCR_MAX); /* utf8 already ensured */ - } - else { - BLI_assert(!"setting the bl_description on a non-builtin operator"); - } -} +/** + * Use callbacks that check for NULL instead of clearing #PROP_NEVER_NULL on the string property, + * so the internal value may be NULL, without allowing Python to assign `None` which doesn't + * make any sense in this case. + */ +# define OPERATOR_STR_MAYBE_NULL_GETSET(attr, len) \ + static void rna_Operator_bl_##attr##_set(PointerRNA *ptr, const char *value) \ + { \ + wmOperator *data = (wmOperator *)(ptr->data); \ + char *str = (char *)data->type->attr; \ + if (str && !str[0]) { \ + BLI_strncpy(str, value, len); /* utf8 already ensured */ \ + } \ + else { \ + BLI_assert( \ + !"setting the bl_" STRINGIFY(translation_context) " on a non-builtin operator"); \ + } \ + } \ + static void rna_Operator_bl_##attr##_get(PointerRNA *ptr, char *value) \ + { \ + const wmOperator *data = (wmOperator *)(ptr->data); \ + const char *str = data->type->attr; \ + BLI_strncpy(value, str ? str : "", len); \ + } \ + static int rna_Operator_bl_##attr##_length(PointerRNA *ptr) \ + { \ + const wmOperator *data = (wmOperator *)(ptr->data); \ + const char *str = data->type->attr; \ + return BLI_strnlen(str ? str : "", len); \ + } -static void rna_Operator_bl_undo_group_set(PointerRNA *ptr, const char *value) -{ - wmOperator *data = (wmOperator *)(ptr->data); - char *str = (char *)data->type->undo_group; - if (!str[0]) { - BLI_strncpy(str, value, OP_MAX_TYPENAME); /* utf8 already ensured */ - } - else { - BLI_assert(!"setting the bl_undo_group on a non-builtin operator"); - } -} +OPERATOR_STR_MAYBE_NULL_GETSET(translation_context, RNA_DYN_DESCR_MAX) +OPERATOR_STR_MAYBE_NULL_GETSET(description, RNA_DYN_DESCR_MAX) +OPERATOR_STR_MAYBE_NULL_GETSET(undo_group, OP_MAX_TYPENAME) static void rna_KeyMapItem_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { @@ -1930,26 +1929,32 @@ static void rna_def_operator(BlenderRNA *brna) prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->translation_context"); RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */ - RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_translation_context_set"); + RNA_def_property_string_funcs(prop, + "rna_Operator_bl_translation_context_get", + "rna_Operator_bl_translation_context_length", + "rna_Operator_bl_translation_context_set"); RNA_def_property_string_default(prop, BLT_I18NCONTEXT_OPERATOR_DEFAULT); RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); - RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */ prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->description"); RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */ - RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_description_set"); + RNA_def_property_string_funcs(prop, + "rna_Operator_bl_description_get", + "rna_Operator_bl_description_length", + "rna_Operator_bl_description_set"); /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); - RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */ prop = RNA_def_property(srna, "bl_undo_group", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->undo_group"); RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */ - RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_undo_group_set"); + RNA_def_property_string_funcs(prop, + "rna_Operator_bl_undo_group_get", + "rna_Operator_bl_undo_group_length", + "rna_Operator_bl_undo_group_set"); /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); - RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */ prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "type->flag"); @@ -2022,26 +2027,32 @@ static void rna_def_macro_operator(BlenderRNA *brna) prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->translation_context"); RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */ - RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_translation_context_set"); + RNA_def_property_string_funcs(prop, + "rna_Operator_bl_translation_context_get", + "rna_Operator_bl_translation_context_length", + "rna_Operator_bl_translation_context_set"); RNA_def_property_string_default(prop, BLT_I18NCONTEXT_OPERATOR_DEFAULT); RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); - RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */ prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->description"); RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */ - RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_description_set"); + RNA_def_property_string_funcs(prop, + "rna_Operator_bl_description_get", + "rna_Operator_bl_description_length", + "rna_Operator_bl_description_set"); /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); - RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */ prop = RNA_def_property(srna, "bl_undo_group", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->undo_group"); RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */ - RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_undo_group_set"); + RNA_def_property_string_funcs(prop, + "rna_Operator_bl_undo_group_get", + "rna_Operator_bl_undo_group_length", + "rna_Operator_bl_undo_group_set"); /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); - RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */ prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "type->flag"); |