[Bf-blender-cvs] [396d39c6b90] master: Cleanup: Declare variables where they are initialized
Hans Goudey
noreply at git.blender.org
Tue Aug 25 21:30:39 CEST 2020
Commit: 396d39c6b904e048e1b076acda383b7226e0c9a7
Author: Hans Goudey
Date: Tue Aug 25 14:28:04 2020 -0500
Branches: master
https://developer.blender.org/rB396d39c6b904e048e1b076acda383b7226e0c9a7
Cleanup: Declare variables where they are initialized
Further changes to interface_handlers.c to avoid a block of variable
declarations at the beginning of functions. Also use const in some
situations. I only made changes where the variable's intended scope
was obvious.
===================================================================
M source/blender/editors/interface/interface_handlers.c
===================================================================
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index eca438415cd..3d5e1372b10 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -667,9 +667,7 @@ static ListBase UIAfterFuncs = {NULL, NULL};
static uiAfterFunc *ui_afterfunc_new(void)
{
- uiAfterFunc *after;
-
- after = MEM_callocN(sizeof(uiAfterFunc), "uiAfterFunc");
+ uiAfterFunc *after = MEM_callocN(sizeof(uiAfterFunc), "uiAfterFunc");
BLI_addtail(&UIAfterFuncs, after);
@@ -718,7 +716,6 @@ static bool ui_afterfunc_check(const uiBlock *block, const uiBut *but)
static void ui_apply_but_func(bContext *C, uiBut *but)
{
- uiAfterFunc *after;
uiBlock *block = but->block;
/* these functions are postponed and only executed after all other
@@ -726,7 +723,7 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
* with these functions removing the buttons we are working with */
if (ui_afterfunc_check(block, but)) {
- after = ui_afterfunc_new();
+ uiAfterFunc *after = ui_afterfunc_new();
if (but->func && ELEM(but, but->func_arg1, but->func_arg2)) {
/* exception, this will crash due to removed button otherwise */
@@ -788,8 +785,6 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
/* typically call ui_apply_but_undo(), ui_apply_but_autokey() */
static void ui_apply_but_undo(uiBut *but)
{
- uiAfterFunc *after;
-
if (but->flag & UI_BUT_UNDO) {
const char *str = NULL;
bool skip_undo = false;
@@ -842,7 +837,7 @@ static void ui_apply_but_undo(uiBut *but)
}
/* delayed, after all other funcs run, popups are closed, etc */
- after = ui_afterfunc_new();
+ uiAfterFunc *after = ui_afterfunc_new();
BLI_strncpy(after->undostr, str, sizeof(after->undostr));
}
}
@@ -874,16 +869,12 @@ static void ui_apply_but_autokey(bContext *C, uiBut *but)
static void ui_apply_but_funcs_after(bContext *C)
{
- uiAfterFunc after;
- PointerRNA opptr;
- ListBase funcs;
-
/* copy to avoid recursive calls */
- funcs = UIAfterFuncs;
+ ListBase funcs = UIAfterFuncs;
BLI_listbase_clear(&UIAfterFuncs);
LISTBASE_FOREACH_MUTABLE (uiAfterFunc *, afterf, &funcs) {
- after = *afterf; /* copy to avoid memleak on exit() */
+ uiAfterFunc after = *afterf; /* copy to avoid memleak on exit() */
BLI_freelinkN(&funcs, afterf);
if (after.context) {
@@ -894,6 +885,7 @@ static void ui_apply_but_funcs_after(bContext *C)
popup_check(C, after.popup_op);
}
+ PointerRNA opptr;
if (after.opptr) {
/* free in advance to avoid leak on exit */
opptr = *after.opptr;
@@ -1142,12 +1134,10 @@ static void ui_apply_but_CURVEPROFILE(bContext *C, uiBut *but, uiHandleButtonDat
/* small multi-but api */
static void ui_multibut_add(uiHandleButtonData *data, uiBut *but)
{
- uiButMultiState *mbut_state;
-
BLI_assert(but->flag & UI_BUT_DRAG_MULTI);
BLI_assert(data->multi_data.has_mbuts);
- mbut_state = MEM_callocN(sizeof(*mbut_state), __func__);
+ uiButMultiState *mbut_state = MEM_callocN(sizeof(*mbut_state), __func__);
mbut_state->but = but;
mbut_state->origvalue = ui_but_value_get(but);
# ifdef USE_ALLSELECT
@@ -1161,9 +1151,7 @@ static void ui_multibut_add(uiHandleButtonData *data, uiBut *but)
static uiButMultiState *ui_multibut_lookup(uiHandleButtonData *data, const uiBut *but)
{
- LinkNode *l;
-
- for (l = data->multi_data.mbuts; l; l = l->next) {
+ for (LinkNode *l = data->multi_data.mbuts; l; l = l->next) {
uiButMultiState *mbut_state;
mbut_state = l->link;
@@ -1487,7 +1475,6 @@ static void ui_drag_toggle_set(bContext *C, uiDragToggleHandle *drag_info, const
{
ARegion *region = CTX_wm_region(C);
bool do_draw = false;
- int xy[2];
/**
* Initialize Locking:
@@ -1526,6 +1513,7 @@ static void ui_drag_toggle_set(bContext *C, uiDragToggleHandle *drag_info, const
}
/* done with axis locking */
+ int xy[2];
xy[0] = (drag_info->xy_lock[0] == false) ? xy_input[0] : drag_info->xy_last[0];
xy[1] = (drag_info->xy_lock[1] == false) ? xy_input[1] : drag_info->xy_last[1];
@@ -1599,17 +1587,16 @@ static bool ui_but_is_drag_toggle(const uiBut *but)
static bool ui_selectcontext_begin(bContext *C, uiBut *but, uiSelectContextStore *selctx_data)
{
- PointerRNA ptr, lptr, idptr;
- PropertyRNA *prop, *lprop;
+ PointerRNA lptr, idptr;
+ PropertyRNA *lprop;
bool success = false;
- int index;
char *path = NULL;
ListBase lb = {NULL};
- ptr = but->rnapoin;
- prop = but->rnaprop;
- index = but->rnaindex;
+ PointerRNA ptr = but->rnapoin;
+ PropertyRNA *prop = but->rnaprop;
+ int index = but->rnaindex;
/* for now don't support whole colors */
if (index == -1) {
@@ -2016,14 +2003,7 @@ static void ui_apply_but_TRACKPREVIEW(bContext *C, uiBut *but, uiHandleButtonDat
static void ui_apply_but(
bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const bool interactive)
{
- const int but_type = but->type; /* Store as const to quiet maybe uninitialized warning. */
-
- char *editstr;
- double *editval;
- float *editvec;
- ColorBand *editcoba;
- CurveMapping *editcumap;
- CurveProfile *editprofile;
+ const eButType but_type = but->type; /* Store as const to quiet maybe uninitialized warning. */
data->retval = 0;
@@ -2076,9 +2056,12 @@ static void ui_apply_but(
}
/* ensures we are writing actual values */
- editstr = but->editstr;
- editval = but->editval;
- editvec = but->editvec;
+ char *editstr = but->editstr;
+ double *editval = but->editval;
+ float *editvec = but->editvec;
+ ColorBand *editcoba;
+ CurveMapping *editcumap;
+ CurveProfile *editprofile;
if (but_type == UI_BTYPE_COLORBAND) {
uiButColorBand *but_coba = (uiButColorBand *)but;
editcoba = but_coba->edit_coba;
@@ -2268,10 +2251,9 @@ static void ui_but_drop(bContext *C, const wmEvent *event, uiBut *but, uiHandleB
static void ui_but_get_pasted_text_from_clipboard(char **buf_paste, int *buf_len)
{
- char *text;
- int length;
/* get only first line even if the clipboard contains multiple lines */
- text = WM_clipboard_text_get_firstline(false, &length);
+ int length;
+ char *text = WM_clipboard_text_get_firstline(false, &length);
if (text) {
*buf_paste = text;
@@ -2398,7 +2380,6 @@ static void ui_but_paste_numeric_value(bContext *C,
char *buf_paste)
{
double value;
-
if (ui_but_string_eval_number(C, but, buf_paste, &value)) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
data->value = value;
@@ -2556,8 +2537,7 @@ static void ui_but_paste_CurveProfile(bContext *C, uiBut *but)
static void ui_but_copy_operator(bContext *C, uiBut *but, char *output, int output_len_max)
{
- PointerRNA *opptr;
- opptr = UI_but_operator_ptr_get(but);
+ PointerRNA *opptr = UI_but_operator_ptr_get(but);
char *str;
str = WM_operator_pystring_ex(C, NULL, false, true, but->optype, opptr);
@@ -2769,10 +2749,8 @@ void ui_but_clipboard_free(void)
static int ui_text_position_from_hidden(uiBut *but, int pos)
{
- const char *strpos, *butstr;
-
- butstr = (but->editstr) ? but->editstr : but->drawstr;
- strpos = butstr;
+ const char *butstr = (but->editstr) ? but->editstr : but->drawstr;
+ const char *strpos = butstr;
for (int i = 0; i < pos; i++) {
strpos = BLI_str_find_next_char_utf8(strpos, NULL);
}
@@ -2790,13 +2768,11 @@ void ui_but_text_password_hide(char password_str[UI_MAX_PASSWORD_STR],
uiBut *but,
const bool restore)
{
- char *butstr;
-
if (!(but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_PASSWORD)) {
return;
}
- butstr = (but->editstr) ? but->editstr : but->drawstr;
+ char *butstr = (but->editstr) ? but->editstr : but->drawstr;
if (restore) {
/* restore original string */
@@ -3166,11 +3142,9 @@ static bool ui_textedit_delete(uiBut *but,
static int ui_textedit_autocomplete(bContext *C, uiBut *but, uiHandleButtonData *data)
{
- char *str;
- int changed;
-
- str = data->str;
+ char *str = data->str;
+ int changed;
if (data->searchbox) {
changed = ui_searchbox_autocomplete(C, data->searchbox, but, data->str);
}
@@ -3193,14 +3167,13 @@ enum {
static bool ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, const int mode)
{
- char *pbuf;
bool changed = false;
- int buf_len;
/* paste */
if (mode == UI_TEXTEDIT_PASTE) {
/* extract the first line from the clipboard */
- pbuf = WM_clipboard_text_get_firstline(false, &buf_len);
+ int buf_len;
+ char *pbuf = WM_clipboard_text_get_firstline(false, &buf_len);
if (pbuf) {
if (UI_but_is_utf8(but)) {
@@ -3280,7 +3253,6 @@ wmIMEData *ui_but_ime_data_get(uiBut *but)
static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data)
{
wmWindow *win = data->window;
- int len;
const bool is_num_but = ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER);
bool no_zero_strip = false;
@@ -3335,7 +3307,7 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data)
}
/* won't change from now on */
- len = strlen(data->str);
+ const int len = strlen(data->str);
data->origstr = BLI_strdupn(data->str, len);
data->sel_pos_init = 0;
@@ -3423,8 +3395,6 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHandleButtonData *data)
{
- uiBut *but;
-
/* label and roundbox can overlap real buttons (backdrops...) */
if (ELEM(actbut->type,
UI_BTYPE_LABEL,
@@ -3435,7 +3405,7 @@ static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHandleButtonDa
return;
}
- for (but = actbut->next; but; but = but->next) {
+ for (uiBut *but = actbut->next; but; but = but->next) {
if (ui_but_is_editable_as_text(but)) {
if (!(but->flag & UI_BUT_DISABLED)) {
data->postbut = but;
@@ -3444,7 +3414,7 @@ static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHand
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list