diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-08-31 17:58:18 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-08-31 18:00:57 +0300 |
commit | 0bbae3f3f6593614e2056518f534c42a30a47ebd (patch) | |
tree | 195b7424f4339b74222ee2fb4954abf65d146984 /source/blender/makesrna/intern | |
parent | 217fddcb8ebe5ee6d3e311bb757d113b517850e6 (diff) |
RNA: strict naming for types in bpy.types
Blender scripts already do this, some addons will need updating.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 40 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 12 |
2 files changed, 52 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 6f2cfbdb6bd..09d2d91a51c 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -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) diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 0e8f47e59ef..12af5dc8287 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -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]) { |