From 51bada696f77de9d7f673884cec9560218654fae Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 11 Jan 2012 08:51:06 +0000 Subject: Longer names support for all ID and other object names This commit extends limit of ID and objects to 64 (it means 63 meaning characters and 1 for zero-terminator). CustomData layers names are also extended. Changed DNA structures and all places where length constants were hardcoded. All names which are "generating" from ID block should be limited by MAX_ID_NAME-2, all non-id names now has got own define called MAX_NAME which should be used all over for non-id names to make further name migration stuff easier. All name fields in DNA now have comment with constant which corresponds to hardcoded numeric value which should make it easier to further update this limits or even switch to non-hardcoded values in DNA. Special thanks to Campbell who helped figuring out some issues and helped a lot in finding all cases where hardcoded valued were still used in code. Both of forwards and backwards compatibility is stored with blender versions newer than January 5, 2011. Older versions had issue with placing null-terminator to DNA strings on file load which will lead to some unpredictable behavior or even crashes. --- source/blender/editors/interface/interface_templates.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/interface/interface_templates.c') diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 3ffc38791d6..573b6cd0b08 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -140,7 +140,7 @@ static void id_search_cb(const bContext *C, void *arg_template, const char *str, continue; if(BLI_strcasestr(id->name+2, str)) { - char name_ui[32]; + char name_ui[MAX_ID_NAME]; name_uiprefix_id(name_ui, id); iconid= ui_id_icon_get((bContext*)C, id, 1); -- cgit v1.2.3 From 535d27eb4923d5582ff16b4016344e8f712608d7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 11 Jan 2012 09:33:44 +0000 Subject: minor cleanup for string use - no functional changes - use more logical names for strings, noticed too many strings called `str` when reviewing name patch. - pass __func__ macro to uiBeginBlock(), quite a few names were wrong (copy/paste error). --- .../blender/editors/interface/interface_templates.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'source/blender/editors/interface/interface_templates.c') diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 573b6cd0b08..ccca0c8f7cf 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -413,11 +413,11 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str } if(id->us > 1) { - char str[32]; + char numstr[32]; - BLI_snprintf(str, sizeof(str), "%d", id->us); + BLI_snprintf(numstr, sizeof(numstr), "%d", id->us); - but= uiDefBut(block, BUT, 0, str, 0,0,UI_UNIT_X + ((id->us < 10) ? 0:10), UI_UNIT_Y, NULL, 0, 0, 0, 0, + but= uiDefBut(block, BUT, 0, numstr, 0,0,UI_UNIT_X + ((id->us < 10) ? 0:10), UI_UNIT_Y, NULL, 0, 0, 0, 0, TIP_("Display number of users of this data (click to make a single-user copy)")); uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ALONE)); @@ -1621,7 +1621,7 @@ static uiBlock *curvemap_clipping_func(bContext *C, struct ARegion *ar, void *cu uiBut *bt; float width= 8*UI_UNIT_X; - block= uiBeginBlock(C, ar, "curvemap_clipping_func", UI_EMBOSS); + block = uiBeginBlock(C, ar, __func__, UI_EMBOSS); /* use this for a fake extra empy space around the buttons */ uiDefBut(block, LABEL, 0, "", -4, 16, width+8, 6*UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); @@ -1680,7 +1680,7 @@ static uiBlock *curvemap_tools_func(bContext *C, struct ARegion *ar, void *cumap uiBlock *block; short yco= 0, menuwidth=10*UI_UNIT_X; - block= uiBeginBlock(C, ar, "curvemap_tools_func", UI_EMBOSS); + block= uiBeginBlock(C, ar, __func__, UI_EMBOSS); uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset View"), 0, yco-=UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 1, ""); @@ -1702,7 +1702,7 @@ static uiBlock *curvemap_brush_tools_func(bContext *C, struct ARegion *ar, void uiBlock *block; short yco= 0, menuwidth=10*UI_UNIT_X; - block= uiBeginBlock(C, ar, "curvemap_tools_func", UI_EMBOSS); + block= uiBeginBlock(C, ar, __func__, UI_EMBOSS); uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, IFACE_("Reset View"), 0, yco-=UI_UNIT_Y, menuwidth, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 1, ""); @@ -2281,7 +2281,8 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * uiBlock *block; uiBut *but; Panel *pa; - char *name, str[32]; + const char *name; + char numstr[32]; int rnaicon=0, icon=0, i= 0, activei= 0, len= 0, items, found, min, max; /* validate arguments */ @@ -2372,7 +2373,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * uiItemL(row, (name)? name: "", icon); if(name) - MEM_freeN(name); + MEM_freeN((void *)name); } i++; @@ -2385,8 +2386,8 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * uiItemL(row, "", ICON_NONE); /* next/prev button */ - BLI_snprintf(str, sizeof(str), "%d :", i); - but= uiDefIconTextButR_prop(block, NUM, 0, 0, str, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activeprop, 0, 0, 0, 0, 0, ""); + BLI_snprintf(numstr, sizeof(numstr), "%d :", i); + but= uiDefIconTextButR_prop(block, NUM, 0, 0, numstr, 0,0,UI_UNIT_X*5,UI_UNIT_Y, activeptr, activeprop, 0, 0, 0, 0, 0, ""); if(i == 0) uiButSetFlag(but, UI_BUT_DISABLED); } -- cgit v1.2.3 From e10fd04db0bdcdbc326fce6cddc8af1179a5de5c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 11 Jan 2012 12:33:51 +0000 Subject: use BLI_strncpy and BLI_snprintf when the size of the string is known. fix for sequencer unique naming which was missed with string length update. --- source/blender/editors/interface/interface_templates.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source/blender/editors/interface/interface_templates.c') diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index ccca0c8f7cf..379a253a5c9 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2471,12 +2471,15 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char int len= strlen(ot->name); /* display name for menu, can hold hotkey */ - BLI_strncpy(name, ot->name, 256); + BLI_strncpy(name, ot->name, sizeof(name)); /* check for hotkey */ - if(len < 256-6) { - if(WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, TRUE, &name[len+1], 256-len-1)) + if(len < sizeof(name)-6) { + if (WM_key_event_operator_string(C, ot->idname, WM_OP_EXEC_DEFAULT, NULL, TRUE, + &name[len+1], sizeof(name)-len-1)) + { name[len]= '|'; + } } if(0==uiSearchItemAdd(items, name, ot, 0)) -- cgit v1.2.3 From 9f2443293e81b206b782ea320e28c9255f471b42 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 12 Jan 2012 13:16:30 +0000 Subject: replace fixed sizes with sizeof when passing string length since size wasn't always correct. --- source/blender/editors/interface/interface_templates.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/interface/interface_templates.c') diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 379a253a5c9..96d2077b9b4 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -181,7 +181,7 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem) /* fake button, it holds space for search items */ uiDefBut(block, LABEL, 0, "", 10, 15, w, h, NULL, 0, 0, 0, 0, NULL); - but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, w, 19, template.prv_rows, template.prv_cols, ""); + but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, 19, template.prv_rows, template.prv_cols, ""); uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data); } /* list view */ @@ -189,7 +189,7 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem) /* fake button, it holds space for search items */ uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL); - but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, 0, 0, ""); + but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, 150, 19, 0, 0, ""); uiButSetSearchFunc(but, id_search_cb, &template, id_search_call_cb, idptr.data); } -- cgit v1.2.3