Skip to content

Commit

Permalink
- Renaming variables so that they don't shadow others (After this pat…
Browse files Browse the repository at this point in the history
…ch one can compile with -Wshadow and get much fewer warnings)

- Changed ER(ER_...) to ER_THD(thd, ER_...) when thd was known or if there was many calls to current_thd in the same function.
- Changed ER(ER_..) to ER_THD_OR_DEFAULT(current_thd, ER...) in some places where current_thd is not necessary defined.
- Removing calls to current_thd when we have access to thd

Part of this is optimization (not calling current_thd when not needed),
but part is bug fixing for error condition when current_thd is not defined
(For example on startup and end of mysqld)

Notable renames done as otherwise a lot of functions would have to be changed:
- In JOIN structure renamed:
   examined_rows -> join_examined_rows
   record_count -> join_record_count
- In Field, renamed new_field() to make_new_field()

Other things:
- Added DBUG_ASSERT(thd == tmp_thd) in Item_singlerow_subselect() just to be safe.
- Removed old 'tab' prefix in JOIN_TAB::save_explain_data() and use members directly
- Added 'thd' as argument to a few functions to avoid calling current_thd.
  • Loading branch information
montywi committed Jul 6, 2015
1 parent 8d4d185 commit 7332af4
Show file tree
Hide file tree
Showing 107 changed files with 1,562 additions and 1,290 deletions.
7 changes: 3 additions & 4 deletions mysys/ma_dyncol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2578,7 +2578,6 @@ find_place(DYN_HEADER *hdr, void *key, my_bool string_keys)
mid= 1;
while (start != end)
{
uint val;
mid= (start + end) / 2;
hdr->entry= hdr->header + mid * hdr->entry_size;
if (!string_keys)
Expand Down Expand Up @@ -3894,11 +3893,11 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
}
case DYN_COL_DECIMAL:
{
int len= sizeof(buff);
decimal2string(&val->x.decimal.value, buff, &len,
int tmp_len= sizeof(buff);
decimal2string(&val->x.decimal.value, buff, &tmp_len,
0, val->x.decimal.value.frac,
'0');
if (dynstr_append_mem(str, buff, len))
if (dynstr_append_mem(str, buff, tmp_len))
return ER_DYNCOL_RESOURCE;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion mysys/mf_keycache.c
Original file line number Diff line number Diff line change
Expand Up @@ -4160,10 +4160,10 @@ static int flush_key_blocks_int(SIMPLE_KEY_CACHE_CB *keycache,

if (! (type == FLUSH_KEEP || type == FLUSH_FORCE_WRITE))
{
BLOCK_LINK *last_for_update= NULL;
BLOCK_LINK *last_in_switch= NULL;
uint total_found= 0;
uint found;
last_for_update= NULL;

/*
Finally free all clean blocks for this file.
Expand Down
9 changes: 5 additions & 4 deletions mysys/my_getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,8 @@ void my_cleanup_options(const struct my_option *options)
SYNOPSIS
init_variables()
options Array of options
options Array of options
func_init_one_value Call this function to init the variable
NOTES
We will initialize the value that is pointed to by options->value.
Expand All @@ -1287,7 +1288,7 @@ void my_cleanup_options(const struct my_option *options)
*/

static void init_variables(const struct my_option *options,
init_func_p init_one_value)
init_func_p func_init_one_value)
{
DBUG_ENTER("init_variables");
for (; options->name; options++)
Expand All @@ -1300,11 +1301,11 @@ static void init_variables(const struct my_option *options,
set the value to default value.
*/
if (options->u_max_value)
init_one_value(options, options->u_max_value, options->max_value);
func_init_one_value(options, options->u_max_value, options->max_value);
value= (options->var_type & GET_ASK_ADDR ?
(*getopt_get_addr)("", 0, options, 0) : options->value);
if (value)
init_one_value(options, value, options->def_value);
func_init_one_value(options, value, options->def_value);
}
DBUG_VOID_RETURN;
}
Expand Down
7 changes: 2 additions & 5 deletions mysys/my_rdtsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,6 @@ void my_timer_init(MY_TIMER_INFO *mti)
mti->cycles.frequency= mti->microseconds.frequency;
else
{
ulonglong time1, time2;
time1= my_timer_init_frequency(mti);
/* Repeat once in case there was an interruption. */
time2= my_timer_init_frequency(mti);
Expand All @@ -750,8 +749,7 @@ void my_timer_init(MY_TIMER_INFO *mti)
&& mti->microseconds.routine
&& mti->cycles.routine)
{
int i;
ulonglong time1, time2, time3, time4;
ulonglong time3, time4;
time1= my_timer_cycles();
time2= my_timer_milliseconds();
time3= time2; /* Avoids a Microsoft/IBM compiler warning */
Expand All @@ -776,8 +774,7 @@ void my_timer_init(MY_TIMER_INFO *mti)
&& mti->microseconds.routine
&& mti->cycles.routine)
{
int i;
ulonglong time1, time2, time3, time4;
ulonglong time3, time4;
time1= my_timer_cycles();
time2= my_timer_ticks();
time3= time2; /* Avoids a Microsoft/IBM compiler warning */
Expand Down
6 changes: 2 additions & 4 deletions mysys/thr_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,14 @@ static void check_locks(THR_LOCK *lock, const char *where,
"Warning at '%s': Write lock %d waiting while no exclusive read locks\n",where,(int) lock->write_wait.data->type);
DBUG_PRINT("warning", ("Warning at '%s': Write lock %d waiting while no exclusive read locks",where,(int) lock->write_wait.data->type));
}
}
}
}
else
{
/* We have at least one write lock */
if (lock->write.data->type == TL_WRITE_CONCURRENT_INSERT)
{
THR_LOCK_DATA *data;
uint count= 0;
count= 0;
for (data=lock->write.data->next;
data && count < MAX_LOCKS;
data=data->next)
Expand Down Expand Up @@ -386,7 +385,6 @@ static void check_locks(THR_LOCK *lock, const char *where,
}
if (lock->read.data)
{
THR_LOCK_DATA *data;
for (data=lock->read.data ; data ; data=data->next)
{
if (!thr_lock_owner_equal(lock->write.data->owner,
Expand Down
5 changes: 3 additions & 2 deletions sql/create_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static bool report_wrong_value(THD *thd, const char *name, const char *val,
}

push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_BAD_OPTION_VALUE,
ER(ER_BAD_OPTION_VALUE), val, name);
ER_THD(thd, ER_BAD_OPTION_VALUE), val, name);
return 0;
}

Expand All @@ -111,7 +111,8 @@ static bool report_unknown_option(THD *thd, engine_option_value *val,
}

push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_UNKNOWN_OPTION, ER(ER_UNKNOWN_OPTION), val->name.str);
ER_UNKNOWN_OPTION, ER_THD(thd, ER_UNKNOWN_OPTION),
val->name.str);
DBUG_RETURN(FALSE);
}

Expand Down
3 changes: 2 additions & 1 deletion sql/debug_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,8 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
const bool save_abort_on_warning= thd->abort_on_warning;
thd->abort_on_warning= false;
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_DEBUG_SYNC_TIMEOUT, ER(ER_DEBUG_SYNC_TIMEOUT));
ER_DEBUG_SYNC_TIMEOUT,
ER_THD(thd, ER_DEBUG_SYNC_TIMEOUT));
thd->abort_on_warning= save_abort_on_warning;
DBUG_EXECUTE_IF("debug_sync_abort_on_timeout", DBUG_ABORT(););
break;
Expand Down
30 changes: 15 additions & 15 deletions sql/derror.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,20 @@ static void init_myfunc_errs()
init_glob_errs(); /* Initiate english errors */
if (!(specialflag & SPECIAL_ENGLISH))
{
EE(EE_FILENOTFOUND) = ER(ER_FILE_NOT_FOUND);
EE(EE_CANTCREATEFILE) = ER(ER_CANT_CREATE_FILE);
EE(EE_READ) = ER(ER_ERROR_ON_READ);
EE(EE_WRITE) = ER(ER_ERROR_ON_WRITE);
EE(EE_BADCLOSE) = ER(ER_ERROR_ON_CLOSE);
EE(EE_OUTOFMEMORY) = ER(ER_OUTOFMEMORY);
EE(EE_DELETE) = ER(ER_CANT_DELETE_FILE);
EE(EE_LINK) = ER(ER_ERROR_ON_RENAME);
EE(EE_EOFERR) = ER(ER_UNEXPECTED_EOF);
EE(EE_CANTLOCK) = ER(ER_CANT_LOCK);
EE(EE_DIR) = ER(ER_CANT_READ_DIR);
EE(EE_STAT) = ER(ER_CANT_GET_STAT);
EE(EE_GETWD) = ER(ER_CANT_GET_WD);
EE(EE_SETWD) = ER(ER_CANT_SET_WD);
EE(EE_DISK_FULL) = ER(ER_DISK_FULL);
EE(EE_FILENOTFOUND) = ER_DEFAULT(ER_FILE_NOT_FOUND);
EE(EE_CANTCREATEFILE) = ER_DEFAULT(ER_CANT_CREATE_FILE);
EE(EE_READ) = ER_DEFAULT(ER_ERROR_ON_READ);
EE(EE_WRITE) = ER_DEFAULT(ER_ERROR_ON_WRITE);
EE(EE_BADCLOSE) = ER_DEFAULT(ER_ERROR_ON_CLOSE);
EE(EE_OUTOFMEMORY) = ER_DEFAULT(ER_OUTOFMEMORY);
EE(EE_DELETE) = ER_DEFAULT(ER_CANT_DELETE_FILE);
EE(EE_LINK) = ER_DEFAULT(ER_ERROR_ON_RENAME);
EE(EE_EOFERR) = ER_DEFAULT(ER_UNEXPECTED_EOF);
EE(EE_CANTLOCK) = ER_DEFAULT(ER_CANT_LOCK);
EE(EE_DIR) = ER_DEFAULT(ER_CANT_READ_DIR);
EE(EE_STAT) = ER_DEFAULT(ER_CANT_GET_STAT);
EE(EE_GETWD) = ER_DEFAULT(ER_CANT_GET_WD);
EE(EE_SETWD) = ER_DEFAULT(ER_CANT_SET_WD);
EE(EE_DISK_FULL) = ER_DEFAULT(ER_DISK_FULL);
}
}
2 changes: 1 addition & 1 deletion sql/event_data_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ Event_timed::load_from_row(THD *thd, TABLE *table)
push_warning_printf(thd,
Sql_condition::WARN_LEVEL_WARN,
ER_EVENT_INVALID_CREATION_CTX,
ER(ER_EVENT_INVALID_CREATION_CTX),
ER_THD(thd, ER_EVENT_INVALID_CREATION_CTX),
(const char *) dbname.str,
(const char *) name.str);
}
Expand Down
5 changes: 3 additions & 2 deletions sql/event_db_repository.cc
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data,
{
*event_already_exists= true;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_EVENT_ALREADY_EXISTS, ER(ER_EVENT_ALREADY_EXISTS),
ER_EVENT_ALREADY_EXISTS,
ER_THD(thd, ER_EVENT_ALREADY_EXISTS),
parse_data->name.str);
ret= 0;
goto end;
Expand Down Expand Up @@ -922,7 +923,7 @@ Event_db_repository::drop_event(THD *thd, LEX_STRING db, LEX_STRING name,
}

push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST),
ER_SP_DOES_NOT_EXIST, ER_THD(thd, ER_SP_DOES_NOT_EXIST),
"Event", name.str);
ret= 0;

Expand Down
4 changes: 2 additions & 2 deletions sql/event_parse_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Event_parse_data::check_if_in_the_past(THD *thd, my_time_t ltime_utc)
case SQLCOM_CREATE_EVENT:
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_EVENT_CANNOT_CREATE_IN_THE_PAST,
ER(ER_EVENT_CANNOT_CREATE_IN_THE_PAST));
ER_THD(thd, ER_EVENT_CANNOT_CREATE_IN_THE_PAST));
break;
case SQLCOM_ALTER_EVENT:
my_error(ER_EVENT_CANNOT_ALTER_IN_THE_PAST, MYF(0));
Expand All @@ -146,7 +146,7 @@ Event_parse_data::check_if_in_the_past(THD *thd, my_time_t ltime_utc)
status_changed= true;
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_EVENT_EXEC_TIME_IN_THE_PAST,
ER(ER_EVENT_EXEC_TIME_IN_THE_PAST));
ER_THD(thd, ER_EVENT_EXEC_TIME_IN_THE_PAST));
}
}

Expand Down
Loading

0 comments on commit 7332af4

Please sign in to comment.