RNA: fail with an error when unused callbacks are assigned

Exit and fail when set callbacks are assigned to read-only properties
as well as array callbacks for non-array properties.
This commit is contained in:
Campbell Barton
2023-07-27 15:07:39 +10:00
parent 2f39d8df59
commit c7595272eb

View File

@@ -1985,6 +1985,26 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
case PROP_BOOLEAN: {
BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
if (!(prop->flag & PROP_EDITABLE) &&
(bprop->set || bprop->set_ex || bprop->setarray || bprop->setarray_ex))
{
CLOG_ERROR(&LOG,
"%s.%s, is read-only but has defines a \"set\" callback.",
srna->identifier,
prop->identifier);
DefRNA.error = true;
}
if (!prop->arraydimension &&
(bprop->getarray || bprop->getarray_ex || bprop->setarray || bprop->setarray_ex))
{
CLOG_ERROR(&LOG,
"%s.%s, is not an array but defines an array callback.",
srna->identifier,
prop->identifier);
DefRNA.error = true;
}
if (!prop->arraydimension) {
if (!bprop->get && !bprop->set && !dp->booleanbit) {
rna_set_raw_property(dp, prop);
@@ -2006,6 +2026,26 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
case PROP_INT: {
IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
if (!(prop->flag & PROP_EDITABLE) &&
(iprop->set || iprop->set_ex || iprop->setarray || iprop->setarray_ex))
{
CLOG_ERROR(&LOG,
"%s.%s, is read-only but has defines a \"set\" callback.",
srna->identifier,
prop->identifier);
DefRNA.error = true;
}
if (!prop->arraydimension &&
(iprop->getarray || iprop->getarray_ex || iprop->setarray || iprop->setarray_ex))
{
CLOG_ERROR(&LOG,
"%s.%s, is not an array but defines an array callback.",
srna->identifier,
prop->identifier);
DefRNA.error = true;
}
if (!prop->arraydimension) {
if (!iprop->get && !iprop->set) {
rna_set_raw_property(dp, prop);
@@ -2031,6 +2071,26 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
case PROP_FLOAT: {
FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
if (!(prop->flag & PROP_EDITABLE) &&
(fprop->set || fprop->set_ex || fprop->setarray || fprop->setarray_ex))
{
CLOG_ERROR(&LOG,
"%s.%s, is read-only but has defines a \"set\" callback.",
srna->identifier,
prop->identifier);
DefRNA.error = true;
}
if (!prop->arraydimension &&
(fprop->getarray || fprop->getarray_ex || fprop->setarray || fprop->setarray_ex))
{
CLOG_ERROR(&LOG,
"%s.%s, is not an array but defines an array callback.",
srna->identifier,
prop->identifier);
DefRNA.error = true;
}
if (!prop->arraydimension) {
if (!fprop->get && !fprop->set) {
rna_set_raw_property(dp, prop);
@@ -2056,6 +2116,14 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
case PROP_ENUM: {
EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
if (!(prop->flag & PROP_EDITABLE) && (eprop->set || eprop->set_ex)) {
CLOG_ERROR(&LOG,
"%s.%s, is read-only but has defines a \"set\" callback.",
srna->identifier,
prop->identifier);
DefRNA.error = true;
}
if (!eprop->get && !eprop->set) {
rna_set_raw_property(dp, prop);
}
@@ -2069,6 +2137,14 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
case PROP_STRING: {
StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
if (!(prop->flag & PROP_EDITABLE) && (sprop->set || sprop->set_ex)) {
CLOG_ERROR(&LOG,
"%s.%s, is read-only but has defines a \"set\" callback.",
srna->identifier,
prop->identifier);
DefRNA.error = true;
}
sprop->get = reinterpret_cast<PropStringGetFunc>(
rna_def_property_get_func(f, srna, prop, dp, (const char *)sprop->get));
sprop->length = reinterpret_cast<PropStringLengthFunc>(
@@ -2082,6 +2158,14 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
case PROP_POINTER: {
PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
if (!(prop->flag & PROP_EDITABLE) && pprop->set) {
CLOG_ERROR(&LOG,
"%s.%s, is read-only but has defines a \"set\" callback.",
srna->identifier,
prop->identifier);
DefRNA.error = true;
}
pprop->get = reinterpret_cast<PropPointerGetFunc>(
rna_def_property_get_func(f, srna, prop, dp, (const char *)pprop->get));
pprop->set = reinterpret_cast<PropPointerSetFunc>(