diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-08-23 09:10:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-08-23 09:10:45 +0300 |
commit | 58a4c767a14b60b903fbe5c5e7e960c57212faeb (patch) | |
tree | 8483aebad87ecc50cdeb8f76e861c755efb2cbd7 /source/blender/makesrna | |
parent | 9cfb72ff81a36c26f4b611ec733432968f15a2de (diff) | |
parent | b8d77c44f112cae1e98308ff33ce055ea4fb46ff (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ID.c | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 32 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_animation.c | 8 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 34 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 17 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_render.c | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 18 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_userdef.c | 9 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 34 |
11 files changed, 129 insertions, 36 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 526aa3ddf55..ad2e0db2147 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -799,6 +799,8 @@ 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); + /* Properties * * Access to struct properties. All this works with RNA pointers rather than diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index 0be3d2fc3c8..7a61b3ec489 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -225,8 +225,8 @@ void RNA_enum_item_end(EnumPropertyItem **items, int *totitem); /* Memory management */ -void RNA_def_struct_duplicate_pointers(StructRNA *srna); -void RNA_def_struct_free_pointers(StructRNA *srna); +void RNA_def_struct_duplicate_pointers(BlenderRNA *brna, StructRNA *srna); +void RNA_def_struct_free_pointers(BlenderRNA *brna, StructRNA *srna); void RNA_def_func_duplicate_pointers(FunctionRNA *func); void RNA_def_func_free_pointers(FunctionRNA *func); void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA *prop); diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 1c6172ef667..0db0fbf7c63 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -290,6 +290,10 @@ StructRNA *rna_PropertyGroup_register(Main *UNUSED(bmain), ReportList *reports, return NULL; } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } + return RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_PropertyGroup); /* XXX */ } diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 9a7fd9589b0..08972eec3b4 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -831,6 +831,38 @@ char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, i return NULL; } +bool RNA_struct_available_or_report(ReportList *reports, const char *identifier) +{ + const StructRNA *srna_exists = RNA_struct_find(identifier); + if (UNLIKELY(srna_exists != NULL)) { + /* Use comprehensive string construction since this is such a rare occurrence + * and information here may cut down time troubleshooting. */ + DynStr *dynstr = BLI_dynstr_new(); + BLI_dynstr_appendf(dynstr, "Type identifier '%s' is already in use: '", identifier); + BLI_dynstr_append(dynstr, srna_exists->identifier); + int i = 0; + if (srna_exists->base) { + for (const StructRNA *base = srna_exists->base; base; base = base->base) { + BLI_dynstr_append(dynstr, "("); + BLI_dynstr_append(dynstr, base->identifier); + i += 1; + } + while (i--) { + BLI_dynstr_append(dynstr, ")"); + } + } + BLI_dynstr_append(dynstr, "'."); + char *result = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + BKE_report(reports, RPT_ERROR, result); + MEM_freeN(result); + return false; + } + else { + return true; + } +} + /* Property Information */ const char *RNA_property_identifier(PropertyRNA *prop) diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c index f49d4717ad6..6bd04fda3d2 100644 --- a/source/blender/makesrna/intern/rna_animation.c +++ b/source/blender/makesrna/intern/rna_animation.c @@ -271,9 +271,13 @@ static StructRNA *rna_KeyingSetInfo_register(Main *bmain, ReportList *reports, v /* check if we have registered this info before, and remove it */ ksi = ANIM_keyingset_info_find_name(dummyksi.idname); - if (ksi && ksi->ext.srna) + if (ksi && ksi->ext.srna) { rna_KeyingSetInfo_unregister(bmain, ksi->ext.srna); - + } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } + /* create a new KeyingSetInfo type */ ksi = MEM_callocN(sizeof(KeyingSetInfo), "python keying set info"); memcpy(ksi, &dummyksi, sizeof(KeyingSetInfo)); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index b10a2b33317..cbe9684e821 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -156,7 +156,7 @@ static void rna_brna_structs_remove_and_free(BlenderRNA *brna, StructRNA *srna) } } - RNA_def_struct_free_pointers(srna); + RNA_def_struct_free_pointers(NULL, srna); if (srna->flag & STRUCT_RUNTIME) { rna_freelinkN(&brna->structs, srna); @@ -3313,21 +3313,37 @@ void RNA_enum_item_end(EnumPropertyItem **items, int *totitem) /* Memory management */ #ifdef RNA_RUNTIME -void RNA_def_struct_duplicate_pointers(StructRNA *srna) +void RNA_def_struct_duplicate_pointers(BlenderRNA *brna, StructRNA *srna) { - if (srna->identifier) srna->identifier = BLI_strdup(srna->identifier); - if (srna->name) srna->name = BLI_strdup(srna->name); - if (srna->description) srna->description = BLI_strdup(srna->description); + if (srna->identifier) { + srna->identifier = BLI_strdup(srna->identifier); + BLI_ghash_replace_key(brna->structs_map, (void *)srna->identifier); + } + if (srna->name) { + srna->name = BLI_strdup(srna->name); + } + if (srna->description) { + srna->description = BLI_strdup(srna->description); + } srna->flag |= STRUCT_FREE_POINTERS; } -void RNA_def_struct_free_pointers(StructRNA *srna) +void RNA_def_struct_free_pointers(BlenderRNA *brna, StructRNA *srna) { if (srna->flag & STRUCT_FREE_POINTERS) { - if (srna->identifier) MEM_freeN((void *)srna->identifier); - if (srna->name) MEM_freeN((void *)srna->name); - if (srna->description) MEM_freeN((void *)srna->description); + if (srna->identifier) { + if (brna != NULL) { + BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, NULL, NULL); + } + MEM_freeN((void *)srna->identifier); + } + if (srna->name) { + MEM_freeN((void *)srna->name); + } + if (srna->description) { + MEM_freeN((void *)srna->description); + } } } diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 51d377ed214..45549e4007f 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -634,9 +634,13 @@ static StructRNA *rna_NodeTree_register( /* check if we have registered this tree type before, and remove it */ nt = ntreeTypeFind(dummynt.idname); - if (nt) + if (nt) { rna_NodeTree_unregister(bmain, nt->ext.srna); - + } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } + /* create a new node tree type */ nt = MEM_callocN(sizeof(bNodeTreeType), "node tree type"); memcpy(nt, &dummynt, sizeof(dummynt)); @@ -1393,11 +1397,18 @@ static bNodeType *rna_Node_register_base(Main *bmain, ReportList *reports, Struc identifier, (int)sizeof(dummynt.idname)); return NULL; } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } /* check if we have registered this node type before, and remove it */ nt = nodeTypeFind(dummynt.idname); - if (nt) + if (nt) { rna_Node_unregister(bmain, nt->ext.srna); + } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } /* create a new node type */ nt = MEM_callocN(sizeof(bNodeType), "node type"); diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c index 7bcf116d6b7..b5115aa3978 100644 --- a/source/blender/makesrna/intern/rna_render.c +++ b/source/blender/makesrna/intern/rna_render.c @@ -341,6 +341,9 @@ static StructRNA *rna_RenderEngine_register(Main *bmain, ReportList *reports, vo break; } } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } /* create a new engine type */ et = MEM_callocN(sizeof(RenderEngineType), "python render engine"); diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 64b41ac789f..0fc0739f860 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -229,6 +229,9 @@ static StructRNA *rna_Panel_register(Main *bmain, ReportList *reports, void *dat break; } } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } /* create a new panel type */ pt = MEM_callocN(sizeof(PanelType), "python buttons panel"); @@ -488,8 +491,12 @@ static StructRNA *rna_UIList_register(Main *bmain, ReportList *reports, void *da /* check if we have registered this uilist type before, and remove it */ ult = WM_uilisttype_find(dummyult.idname, true); - if (ult && ult->ext.srna) + if (ult && ult->ext.srna) { rna_UIList_unregister(bmain, ult->ext.srna); + } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } /* create a new menu type */ ult = MEM_callocN(sizeof(uiListType) + over_alloc, "python uilist"); @@ -592,6 +599,9 @@ static StructRNA *rna_Header_register(Main *bmain, ReportList *reports, void *da break; } } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } /* create a new header type */ ht = MEM_callocN(sizeof(HeaderType), "python buttons header"); @@ -712,8 +722,12 @@ static StructRNA *rna_Menu_register(Main *bmain, ReportList *reports, void *data /* check if we have registered this menu type before, and remove it */ mt = WM_menutype_find(dummymt.idname, true); - if (mt && mt->ext.srna) + if (mt && mt->ext.srna) { rna_Menu_unregister(bmain, mt->ext.srna); + } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } /* create a new menu type */ if (_menu_descr[0]) { diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 628adbddd36..ce0b68eead0 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -615,10 +615,11 @@ static StructRNA *rna_AddonPref_register(Main *bmain, ReportList *reports, void /* check if we have registered this header type before, and remove it */ apt = BKE_addon_pref_type_find(dummyaddon.module, true); - if (apt) { - if (apt->ext.srna) { - rna_AddonPref_unregister(bmain, apt->ext.srna); - } + if (apt && apt->ext.srna) { + rna_AddonPref_unregister(bmain, apt->ext.srna); + } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; } /* create a new header type */ diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 14e27235b81..637ba1d35e5 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -1239,6 +1239,16 @@ static StructRNA *rna_Operator_register( if (validate(&dummyotr, data, have_function) != 0) return NULL; + /* check if we have registered this operator type before, and remove it */ + { + wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true); + if (ot && ot->ext.srna) + rna_Operator_unregister(bmain, ot->ext.srna); + } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } + { /* convert foo.bar to FOO_OT_bar * allocate the description and the idname in 1 go */ @@ -1306,13 +1316,6 @@ static StructRNA *rna_Operator_register( } } - /* check if we have registered this operator type before, and remove it */ - { - wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true); - if (ot && ot->ext.srna) - rna_Operator_unregister(bmain, ot->ext.srna); - } - /* XXX, this doubles up with the operator name [#29666] * for now just remove from dir(bpy.types) */ @@ -1415,6 +1418,16 @@ static StructRNA *rna_MacroOperator_register( return NULL; } + /* check if we have registered this operator type before, and remove it */ + { + wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true); + if (ot && ot->ext.srna) + rna_Operator_unregister(bmain, ot->ext.srna); + } + if (!RNA_struct_available_or_report(reports, identifier)) { + return NULL; + } + { /* convert foo.bar to FOO_OT_bar * allocate the description and the idname in 1 go */ const uint idname_len = strlen(temp_buffers.idname) + 4; @@ -1441,13 +1454,6 @@ static StructRNA *rna_MacroOperator_register( dummyot.undo_group = ch; } - /* check if we have registered this operator type before, and remove it */ - { - wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true); - if (ot && ot->ext.srna) - rna_Operator_unregister(bmain, ot->ext.srna); - } - /* XXX, this doubles up with the operator name [#29666] * for now just remove from dir(bpy.types) */ |