Skip to content

Commit 68aaaba

Browse files
committed
Bug#29806684: REMOVE UNNECESSARY CONST_CAST [noclose]
Remove unnecessary explicit const_cast. Follow-up to Bug#28787273: FIX -WCAST-QUAL COMPILATION WARNINGS. Patch 2. Change-Id: I83d6cbf7b5f2a137391ff95e431fb0c86992d599
1 parent d580bd9 commit 68aaaba

18 files changed

+153
-184
lines changed

sql/auth/sql_security_ctx.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void Security_context::copy_security_ctx(const Security_context &src_sctx) {
276276

277277
bool Security_context::change_security_context(
278278
THD *thd, const LEX_CSTRING &definer_user, const LEX_CSTRING &definer_host,
279-
LEX_STRING *db, Security_context **backup, bool force) {
279+
const char *db, Security_context **backup, bool force) {
280280
bool needs_change;
281281

282282
DBUG_TRACE;
@@ -289,10 +289,8 @@ bool Security_context::change_security_context(
289289
my_strcasecmp(system_charset_info, definer_host.str,
290290
thd->security_context()->priv_host().str));
291291
if (needs_change || force) {
292-
if (acl_getroot(thd, this, const_cast<char *>(definer_user.str),
293-
const_cast<char *>(definer_host.str),
294-
const_cast<char *>(definer_host.str),
295-
(db ? db->str : nullptr))) {
292+
if (acl_getroot(thd, this, definer_user.str, definer_host.str,
293+
definer_host.str, db)) {
296294
my_error(ER_NO_SUCH_USER, MYF(0), definer_user.str, definer_host.str);
297295
return true;
298296
}

sql/auth/sql_security_ctx.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class Security_context {
262262
void set_password_expired(bool password_expired);
263263

264264
bool change_security_context(THD *thd, const LEX_CSTRING &definer_user,
265-
const LEX_CSTRING &definer_host, LEX_STRING *db,
265+
const LEX_CSTRING &definer_host, const char *db,
266266
Security_context **backup, bool force = false);
267267

268268
void restore_security_context(THD *thd, Security_context *backup);

sql/dd/dd_routine.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void fill_dd_function_return_type(THD *thd, sp_head *sp, Function *sf) {
9494

9595
// Reset result data type in utf8
9696
sf->set_result_data_type_utf8(
97-
get_sql_type_by_create_field(&table, return_field));
97+
get_sql_type_by_create_field(&table, *return_field));
9898

9999
// Set result is_zerofill flag.
100100
sf->set_result_zerofill(return_field->is_zerofill);
@@ -160,7 +160,7 @@ static void fill_parameter_info_from_field(THD *thd, Create_field *field,
160160
table.s->db_low_byte_first = 1;
161161

162162
// Reset data type in utf8
163-
param->set_data_type_utf8(get_sql_type_by_create_field(&table, field));
163+
param->set_data_type_utf8(get_sql_type_by_create_field(&table, *field));
164164

165165
// Set is_zerofill flag.
166166
param->set_zerofill(field->is_zerofill);

sql/dd/dd_table.cc

+54-57
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ dd::enum_column_types get_new_field_type(enum_field_types type) {
226226
*/
227227

228228
dd::String_type get_sql_type_by_create_field(TABLE *table,
229-
Create_field *field) {
229+
const Create_field &field) {
230230
DBUG_TRACE;
231231

232-
unique_ptr_destroy_only<Field> fld(make_field(*field, table->s));
232+
unique_ptr_destroy_only<Field> fld(make_field(field, table->s));
233233
fld->init(table);
234234

235235
// Read column display type.
@@ -539,72 +539,69 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
539539
//
540540
// Iterate through all the table columns
541541
//
542-
Create_field *field;
543-
List_iterator<Create_field> it(
544-
const_cast<List<Create_field> &>(create_fields));
545-
while ((field = it++)) {
542+
for (const Create_field &field : create_fields) {
546543
//
547544
// Add new DD column
548545
//
549546

550547
dd::Column *col_obj = tab_obj->add_column();
551548

552-
col_obj->set_name(field->field_name);
549+
col_obj->set_name(field.field_name);
553550

554-
col_obj->set_type(dd::get_new_field_type(field->sql_type));
551+
col_obj->set_type(dd::get_new_field_type(field.sql_type));
555552

556-
col_obj->set_char_length(field->max_display_width_in_bytes());
553+
col_obj->set_char_length(field.max_display_width_in_bytes());
557554

558555
// Set result numeric scale.
559556
uint value = 0;
560-
if (get_field_numeric_scale(field, &value) == false)
557+
if (get_field_numeric_scale(&field, &value) == false)
561558
col_obj->set_numeric_scale(value);
562559

563560
// Set result numeric precision.
564-
if (get_field_numeric_precision(field, &value) == false)
561+
if (get_field_numeric_precision(&field, &value) == false)
565562
col_obj->set_numeric_precision(value);
566563

567564
// Set result datetime precision.
568-
if (get_field_datetime_precision(field, &value) == false)
565+
if (get_field_datetime_precision(&field, &value) == false)
569566
col_obj->set_datetime_precision(value);
570567

571-
col_obj->set_nullable(field->maybe_null);
568+
col_obj->set_nullable(field.maybe_null);
572569

573-
col_obj->set_unsigned(field->is_unsigned);
570+
col_obj->set_unsigned(field.is_unsigned);
574571

575-
col_obj->set_zerofill(field->is_zerofill);
572+
col_obj->set_zerofill(field.is_zerofill);
576573

577-
col_obj->set_srs_id(field->m_srid);
574+
col_obj->set_srs_id(field.m_srid);
578575

579576
// Check that the hidden type isn't the type that is used internally by
580577
// storage engines.
581-
DBUG_ASSERT(field->hidden != dd::Column::enum_hidden_type::HT_HIDDEN_SE);
582-
col_obj->set_hidden(field->hidden);
578+
DBUG_ASSERT(field.hidden != dd::Column::enum_hidden_type::HT_HIDDEN_SE);
579+
col_obj->set_hidden(field.hidden);
583580

584581
/*
585582
AUTO_INCREMENT, DEFAULT/ON UPDATE CURRENT_TIMESTAMP properties are
586583
stored in Create_field::auto_flags.
587584
*/
588-
if (field->auto_flags & Field::DEFAULT_NOW)
589-
col_obj->set_default_option(now_with_opt_decimals(field->decimals));
585+
if (field.auto_flags & Field::DEFAULT_NOW)
586+
col_obj->set_default_option(now_with_opt_decimals(field.decimals));
590587

591-
if (field->auto_flags & Field::ON_UPDATE_NOW)
592-
col_obj->set_update_option(now_with_opt_decimals(field->decimals));
588+
if (field.auto_flags & Field::ON_UPDATE_NOW)
589+
col_obj->set_update_option(now_with_opt_decimals(field.decimals));
593590

594-
col_obj->set_auto_increment((field->auto_flags & Field::NEXT_NUMBER) != 0);
591+
col_obj->set_auto_increment((field.auto_flags & Field::NEXT_NUMBER) != 0);
595592

596593
// Handle generated default
597-
if (field->m_default_val_expr) {
594+
if (field.m_default_val_expr) {
598595
char buffer[128];
599596
String default_val_expr(buffer, sizeof(buffer), &my_charset_bin);
600597
// Convert the expression from Item* to text
601-
field->m_default_val_expr->print_expr(thd, &default_val_expr);
598+
field.m_default_val_expr->print_expr(thd, &default_val_expr);
602599
col_obj->set_default_option(
603600
dd::String_type(default_val_expr.ptr(), default_val_expr.length()));
604601
}
605602

606603
// Handle generated columns
607-
if (field->gcol_info) {
604+
if (field.gcol_info) {
608605
/*
609606
It is important to normalize the expression's text into the DD, to
610607
make it independent from sql_mode. For example, 'a||b' means 'a OR b'
@@ -614,8 +611,8 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
614611
*/
615612
char buffer[128];
616613
String gc_expr(buffer, sizeof(buffer), &my_charset_bin);
617-
col_obj->set_virtual(!field->stored_in_db);
618-
field->gcol_info->print_expr(thd, &gc_expr);
614+
col_obj->set_virtual(!field.stored_in_db);
615+
field.gcol_info->print_expr(thd, &gc_expr);
619616
col_obj->set_generation_expression(
620617
dd::String_type(gc_expr.ptr(), gc_expr.length()));
621618

@@ -627,41 +624,41 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
627624
dd::String_type(gc_expr_for_IS.ptr(), gc_expr_for_IS.length()));
628625
}
629626

630-
if (field->comment.str && field->comment.length)
627+
if (field.comment.str && field.comment.length)
631628
col_obj->set_comment(
632-
dd::String_type(field->comment.str, field->comment.length));
629+
dd::String_type(field.comment.str, field.comment.length));
633630

634631
// Collation ID
635-
col_obj->set_collation_id(field->charset->number);
632+
col_obj->set_collation_id(field.charset->number);
636633

637634
// Was collation supplied explicitly ?
638-
col_obj->set_is_explicit_collation(field->is_explicit_collation);
635+
col_obj->set_is_explicit_collation(field.is_explicit_collation);
639636

640637
/*
641638
Store numeric scale for types relying on this info (old and new decimal
642639
and floating point types). Also store 0 for integer types to simplify I_S
643640
implementation.
644641
*/
645-
switch (field->sql_type) {
642+
switch (field.sql_type) {
646643
case MYSQL_TYPE_FLOAT:
647644
case MYSQL_TYPE_DOUBLE:
648645
/* For these types we show NULL in I_S if scale was not given. */
649-
if (field->decimals != DECIMAL_NOT_SPECIFIED)
650-
col_obj->set_numeric_scale(field->decimals);
646+
if (field.decimals != DECIMAL_NOT_SPECIFIED)
647+
col_obj->set_numeric_scale(field.decimals);
651648
else {
652649
DBUG_ASSERT(col_obj->is_numeric_scale_null());
653650
}
654651
break;
655652
case MYSQL_TYPE_NEWDECIMAL:
656653
case MYSQL_TYPE_DECIMAL:
657-
col_obj->set_numeric_scale(field->decimals);
654+
col_obj->set_numeric_scale(field.decimals);
658655
break;
659656
case MYSQL_TYPE_TINY:
660657
case MYSQL_TYPE_SHORT:
661658
case MYSQL_TYPE_LONG:
662659
case MYSQL_TYPE_INT24:
663660
case MYSQL_TYPE_LONGLONG:
664-
DBUG_ASSERT(field->decimals == 0);
661+
DBUG_ASSERT(field.decimals == 0);
665662
col_obj->set_numeric_scale(0);
666663
break;
667664
default:
@@ -681,41 +678,41 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
681678
when SE starts supporting optimized BIT storage but still needs
682679
to handle correctly columns which were created before this change.
683680
*/
684-
if (field->sql_type == MYSQL_TYPE_BIT)
685-
col_options->set("treat_bit_as_char", field->treat_bit_as_char);
681+
if (field.sql_type == MYSQL_TYPE_BIT)
682+
col_options->set("treat_bit_as_char", field.treat_bit_as_char);
686683

687684
// Store geometry sub type
688-
if (field->sql_type == MYSQL_TYPE_GEOMETRY) {
689-
col_options->set("geom_type", field->geom_type);
685+
if (field.sql_type == MYSQL_TYPE_GEOMETRY) {
686+
col_options->set("geom_type", field.geom_type);
690687
}
691688

692689
// Field storage media and column format options
693-
if (field->field_storage_type() != HA_SM_DEFAULT)
690+
if (field.field_storage_type() != HA_SM_DEFAULT)
694691
col_options->set("storage",
695-
static_cast<uint32>(field->field_storage_type()));
692+
static_cast<uint32>(field.field_storage_type()));
696693

697-
if (field->column_format() != COLUMN_FORMAT_TYPE_DEFAULT)
694+
if (field.column_format() != COLUMN_FORMAT_TYPE_DEFAULT)
698695
col_options->set("column_format",
699-
static_cast<uint32>(field->column_format()));
696+
static_cast<uint32>(field.column_format()));
700697

701698
// NOT SECONDARY column option.
702-
if (field->flags & NOT_SECONDARY_FLAG)
699+
if (field.flags & NOT_SECONDARY_FLAG)
703700
col_options->set("not_secondary", true);
704701

705-
if (field->is_array) {
702+
if (field.is_array) {
706703
col_options->set("is_array", true);
707704
}
708705

709706
//
710707
// Write intervals
711708
//
712709
uint i = 0;
713-
if (field->interval) {
710+
if (field.interval) {
714711
uchar buff[MAX_FIELD_WIDTH];
715712
String tmp((char *)buff, sizeof(buff), &my_charset_bin);
716713
tmp.length(0);
717714

718-
for (const char **pos = field->interval->type_names; *pos; pos++) {
715+
for (const char **pos = field.interval->type_names; *pos; pos++) {
719716
//
720717
// Create enum/set object
721718
//
@@ -726,7 +723,7 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
726723

727724
// Copy type_lengths[i] bytes including '\0'
728725
// This helps store typelib names that are of different charsets.
729-
dd::String_type interval_name(*pos, field->interval->type_lengths[i]);
726+
dd::String_type interval_name(*pos, field.interval->type_lengths[i]);
730727
elem_obj->set_name(interval_name);
731728

732729
i++;
@@ -740,13 +737,13 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
740737
col_options->set("interval_count", i);
741738

742739
// Store geometry sub type
743-
if (field->sql_type == MYSQL_TYPE_GEOMETRY) {
744-
col_options->set("geom_type", field->geom_type);
740+
if (field.sql_type == MYSQL_TYPE_GEOMETRY) {
741+
col_options->set("geom_type", field.geom_type);
745742
}
746743

747744
// Reset the buffer and assign the column's default value.
748745
memset(buf, 0, bufsize);
749-
if (prepare_default_value(thd, buf, table, *field, col_obj)) return true;
746+
if (prepare_default_value(thd, buf, table, field, col_obj)) return true;
750747

751748
/**
752749
Storing default value specified for column in
@@ -763,7 +760,7 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
763760
prepared in prepare_default_value() is used.
764761
*/
765762
String def_val;
766-
prepare_default_value_string(buf, &table, *field, col_obj, &def_val);
763+
prepare_default_value_string(buf, &table, field, col_obj, &def_val);
767764
if (def_val.ptr() != nullptr)
768765
col_obj->set_default_value_utf8(
769766
dd::String_type(def_val.ptr(), def_val.length()));
@@ -917,7 +914,7 @@ static void fill_dd_index_elements_from_key_parts(
917914
}
918915

919916
// Check if a given key is candidate to be promoted to primary key.
920-
static bool is_candidate_primary_key(THD *thd, KEY *key,
917+
static bool is_candidate_primary_key(THD *thd, const KEY *key,
921918
const List<Create_field> &create_fields) {
922919
KEY_PART_INFO *key_part;
923920
KEY_PART_INFO *key_part_end = key->key_part + key->user_defined_key_parts;
@@ -1095,7 +1092,7 @@ static void fill_dd_indexes_from_keyinfo(
10951092
fill_dd_index_elements_from_key_parts() about the same.
10961093
*/
10971094
if (primary_key_info == nullptr &&
1098-
is_candidate_primary_key(thd, const_cast<KEY *>(key), create_fields)) {
1095+
is_candidate_primary_key(thd, key, create_fields)) {
10991096
primary_key_info = key;
11001097
}
11011098

@@ -2630,7 +2627,7 @@ dd::String_type get_sql_type_by_field_info(THD *thd,
26302627
is_unsigned, 0);
26312628
field.charset = field_charset;
26322629

2633-
return get_sql_type_by_create_field(&table, &field);
2630+
return get_sql_type_by_create_field(&table, field);
26342631
}
26352632

26362633
bool fix_row_type(THD *thd, dd::Table *table_def, row_type correct_row_type) {

sql/dd/dd_table.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ bool fill_dd_columns_from_create_fields(THD *thd, Abstract_table *tab_obj,
362362
@return dd::String_type representing column type.
363363
*/
364364

365-
dd::String_type get_sql_type_by_create_field(TABLE *table, Create_field *field);
365+
dd::String_type get_sql_type_by_create_field(TABLE *table,
366+
const Create_field &field);
366367

367368
/**
368369
Helper method to get numeric scale for types using Create_field type

sql/dd/upgrade_57/event.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ static void load_event_creation_context(THD *thd, TABLE *table,
279279
*/
280280

281281
static bool update_event_timing_fields(THD *thd, TABLE *table,
282-
char *event_db_name, char *event_name) {
282+
const char *event_db_name,
283+
const char *event_name) {
283284
dd::Event *new_event = nullptr;
284285
dd::cache::Dictionary_client::Auto_releaser releaser(thd->dd_client());
285286

0 commit comments

Comments
 (0)