makesrna: type check bool/int/float/enum get/set callbacks
While converting types from callbacks isn't a bug, it's unlikely we ever want to do this on purpose and can hide mistakes such as silently converting floating point values to ints as happened with Sequencer.frame_start.
This commit is contained in:
parent
5bd4aea29c
commit
e77ac31799
|
@ -826,7 +826,23 @@ static char *rna_def_property_get_func(
|
|||
fprintf(f, "{\n");
|
||||
|
||||
if (manualfunc) {
|
||||
fprintf(f, " %s(ptr, values);\n", manualfunc);
|
||||
/* Assign `fn` to ensure function signatures match. */
|
||||
if (prop->type == PROP_BOOLEAN) {
|
||||
fprintf(f, " PropBooleanArrayGetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, values);\n");
|
||||
}
|
||||
else if (prop->type == PROP_INT) {
|
||||
fprintf(f, " PropIntArrayGetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, values);\n");
|
||||
}
|
||||
else if (prop->type == PROP_FLOAT) {
|
||||
fprintf(f, " PropFloatArrayGetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, values);\n");
|
||||
}
|
||||
else {
|
||||
BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
|
||||
fprintf(f, " %s(ptr, values);\n", manualfunc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
rna_print_data_get(f, dp);
|
||||
|
@ -902,7 +918,27 @@ static char *rna_def_property_get_func(
|
|||
fprintf(f, "{\n");
|
||||
|
||||
if (manualfunc) {
|
||||
fprintf(f, " return %s(ptr);\n", manualfunc);
|
||||
/* Assign `fn` to ensure function signatures match. */
|
||||
if (prop->type == PROP_BOOLEAN) {
|
||||
fprintf(f, " PropBooleanGetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " return fn(ptr);\n");
|
||||
}
|
||||
else if (prop->type == PROP_INT) {
|
||||
fprintf(f, " PropIntGetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " return fn(ptr);\n");
|
||||
}
|
||||
else if (prop->type == PROP_FLOAT) {
|
||||
fprintf(f, " PropFloatGetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " return fn(ptr);\n");
|
||||
}
|
||||
else if (prop->type == PROP_ENUM) {
|
||||
fprintf(f, " PropEnumGetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " return fn(ptr);\n");
|
||||
}
|
||||
else {
|
||||
BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
|
||||
fprintf(f, " return %s(ptr);\n", manualfunc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
rna_print_data_get(f, dp);
|
||||
|
@ -1197,7 +1233,23 @@ static char *rna_def_property_set_func(
|
|||
fprintf(f, "{\n");
|
||||
|
||||
if (manualfunc) {
|
||||
fprintf(f, " %s(ptr, values);\n", manualfunc);
|
||||
/* Assign `fn` to ensure function signatures match. */
|
||||
if (prop->type == PROP_BOOLEAN) {
|
||||
fprintf(f, " PropBooleanArraySetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, values);\n");
|
||||
}
|
||||
else if (prop->type == PROP_INT) {
|
||||
fprintf(f, " PropIntArraySetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, values);\n");
|
||||
}
|
||||
else if (prop->type == PROP_FLOAT) {
|
||||
fprintf(f, " PropFloatArraySetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, values);\n");
|
||||
}
|
||||
else {
|
||||
BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
|
||||
fprintf(f, " %s(ptr, values);\n", manualfunc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
rna_print_data_get(f, dp);
|
||||
|
@ -1289,7 +1341,27 @@ static char *rna_def_property_set_func(
|
|||
fprintf(f, "{\n");
|
||||
|
||||
if (manualfunc) {
|
||||
fprintf(f, " %s(ptr, value);\n", manualfunc);
|
||||
/* Assign `fn` to ensure function signatures match. */
|
||||
if (prop->type == PROP_BOOLEAN) {
|
||||
fprintf(f, " PropBooleanSetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, value);\n");
|
||||
}
|
||||
else if (prop->type == PROP_INT) {
|
||||
fprintf(f, " PropIntSetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, value);\n");
|
||||
}
|
||||
else if (prop->type == PROP_FLOAT) {
|
||||
fprintf(f, " PropFloatSetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, value);\n");
|
||||
}
|
||||
else if (prop->type == PROP_ENUM) {
|
||||
fprintf(f, " PropEnumSetFunc fn = %s;\n", manualfunc);
|
||||
fprintf(f, " fn(ptr, value);\n");
|
||||
}
|
||||
else {
|
||||
BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
|
||||
fprintf(f, " %s(ptr, value);\n", manualfunc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
rna_print_data_get(f, dp);
|
||||
|
|
Loading…
Reference in New Issue