forked from bartvdbraak/blender
RNA: strict naming for types in bpy.types
Blender scripts already do this, some addons will need updating.
This commit is contained in:
parent
217fddcb8e
commit
0bbae3f3f6
@ -784,6 +784,7 @@ const struct ListBase *RNA_struct_type_functions(StructRNA *srna);
|
||||
char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len);
|
||||
|
||||
bool RNA_struct_available_or_report(struct ReportList *reports, const char *identifier);
|
||||
bool RNA_struct_bl_idname_ok_or_report(struct ReportList *reports, const char *identifier, const char *sep);
|
||||
|
||||
/* Properties
|
||||
*
|
||||
|
@ -850,6 +850,46 @@ bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
|
||||
}
|
||||
}
|
||||
|
||||
bool RNA_struct_bl_idname_ok_or_report(ReportList *reports, const char *identifier, const char *sep)
|
||||
{
|
||||
const int len_sep = strlen(sep);
|
||||
const int len_id = strlen(identifier);
|
||||
const char *p = strstr(identifier, sep);
|
||||
if (p == NULL || p == identifier || p + len_sep >= identifier + len_id) {
|
||||
BKE_reportf(reports, RPT_ERROR, "'%s' doesn't contain '%s' with prefix & suffix", identifier, sep);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *c, *start, *end, *last;
|
||||
start = identifier;
|
||||
end = p;
|
||||
last = end - 1;
|
||||
for (c = start; c != end; c++) {
|
||||
if (((*c >= 'A' && *c <= 'Z') ||
|
||||
((c != start) && (*c >= '0' && *c <= '9')) ||
|
||||
((c != start) && (c != last) && (*c == '_'))) == 0)
|
||||
{
|
||||
BKE_reportf(reports, RPT_ERROR, "'%s' doesn't have upper case alpha-numeric prefix", identifier);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
start = p + len_sep;
|
||||
end = identifier + len_id;
|
||||
last = end - 1;
|
||||
for (c = start; c != end; c++) {
|
||||
if (((*c >= 'A' && *c <= 'Z') ||
|
||||
(*c >= 'a' && *c <= 'z') ||
|
||||
(*c >= '0' && *c <= '9') ||
|
||||
((c != start) && (c != last) && (*c == '_'))) == 0)
|
||||
{
|
||||
BKE_reportf(reports, RPT_ERROR, "'%s' doesn't have an alpha-numeric suffix", identifier);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Property Information */
|
||||
|
||||
const char *RNA_property_identifier(PropertyRNA *prop)
|
||||
|
@ -232,6 +232,9 @@ static StructRNA *rna_Panel_register(Main *bmain, ReportList *reports, void *dat
|
||||
if (!RNA_struct_available_or_report(reports, dummypt.idname)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!RNA_struct_bl_idname_ok_or_report(reports, dummypt.idname, "_PT_")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create a new panel type */
|
||||
pt = MEM_callocN(sizeof(PanelType), "python buttons panel");
|
||||
@ -497,6 +500,9 @@ static StructRNA *rna_UIList_register(Main *bmain, ReportList *reports, void *da
|
||||
if (!RNA_struct_available_or_report(reports, dummyult.idname)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!RNA_struct_bl_idname_ok_or_report(reports, dummyult.idname, "_UL_")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create a new menu type */
|
||||
ult = MEM_callocN(sizeof(uiListType) + over_alloc, "python uilist");
|
||||
@ -602,6 +608,9 @@ static StructRNA *rna_Header_register(Main *bmain, ReportList *reports, void *da
|
||||
if (!RNA_struct_available_or_report(reports, dummyht.idname)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!RNA_struct_bl_idname_ok_or_report(reports, dummyht.idname, "_HT_")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create a new header type */
|
||||
ht = MEM_callocN(sizeof(HeaderType), "python buttons header");
|
||||
@ -728,6 +737,9 @@ static StructRNA *rna_Menu_register(Main *bmain, ReportList *reports, void *data
|
||||
if (!RNA_struct_available_or_report(reports, dummymt.idname)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!RNA_struct_bl_idname_ok_or_report(reports, dummymt.idname, "_MT_")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create a new menu type */
|
||||
if (_menu_descr[0]) {
|
||||
|
Loading…
Reference in New Issue
Block a user