From 44c6328cbb4cfccc821f50ea5fa2f8aac85866e2 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 1 Jun 2024 16:15:53 +0200 Subject: [PATCH] cleanup: thd->alloc<>() and thd->calloc<>() create templates thd->alloc(n) to use instead of (X*)thd->alloc(sizeof(X)*n) and the same for thd->calloc(). By the default the type is char, so old usage of thd->alloc(size) works too. --- sql/event_data_objects.cc | 4 +- sql/event_parse_data.cc | 2 +- sql/filesort.cc | 2 +- sql/ha_partition.cc | 13 ++--- sql/item.cc | 25 ++++----- sql/item_cmpfunc.cc | 23 +++----- sql/item_func.cc | 11 ++-- sql/item_strfunc.cc | 9 ++- sql/item_subselect.cc | 25 ++++----- sql/item_sum.cc | 12 ++-- sql/log_event.cc | 3 +- sql/log_event_server.cc | 3 +- sql/mysqld.cc | 2 +- sql/opt_range.cc | 2 +- sql/opt_split.cc | 12 ++-- sql/opt_subselect.cc | 28 ++++------ sql/opt_table_elimination.cc | 2 +- sql/partition_info.cc | 34 ++++-------- sql/protocol.cc | 6 +- sql/rowid_filter.cc | 6 +- sql/set_var.cc | 9 ++- sql/sp.cc | 3 +- sql/sp_head.cc | 8 +-- sql/sp_rcontext.cc | 15 +---- sql/sql_acl.cc | 2 +- sql/sql_alter.cc | 6 +- sql/sql_analyse.cc | 3 +- sql/sql_base.cc | 21 +++---- sql/sql_class.cc | 7 +-- sql/sql_class.h | 24 +++++--- sql/sql_db.cc | 4 +- sql/sql_delete.cc | 2 +- sql/sql_derived.cc | 2 +- sql/sql_handler.cc | 2 +- sql/sql_join_cache.cc | 2 +- sql/sql_lex.cc | 13 ++--- sql/sql_load.cc | 2 +- sql/sql_parse.cc | 14 ++--- sql/sql_partition.cc | 22 +++----- sql/sql_rename.cc | 2 +- sql/sql_select.cc | 55 ++++++++----------- sql/sql_show.cc | 16 +++--- sql/sql_statistics.cc | 3 +- sql/sql_table.cc | 23 ++++---- sql/sql_type_fixedbin.h | 2 +- sql/sql_update.cc | 11 ++-- sql/sql_view.cc | 6 +- sql/sql_yacc.yy | 30 +++++----- sql/sys_vars.inl | 7 +-- sql/table.cc | 7 +-- sql/thr_malloc.cc | 2 +- sql/unireg.cc | 12 ++-- storage/maria/ha_maria.cc | 14 ++--- storage/myisam/ha_myisam.cc | 14 ++--- storage/myisammrg/ha_myisammrg.cc | 6 +- storage/perfschema/table_global_status.cc | 4 +- storage/perfschema/table_host_cache.cc | 2 +- storage/perfschema/table_session_status.cc | 4 +- storage/perfschema/table_status_by_account.cc | 4 +- storage/perfschema/table_status_by_host.cc | 4 +- storage/perfschema/table_status_by_thread.cc | 4 +- storage/perfschema/table_status_by_user.cc | 4 +- storage/spider/spd_db_mysql.cc | 3 +- 63 files changed, 262 insertions(+), 362 deletions(-) diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index 3486e76f19d..4238cd90e02 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -1283,7 +1283,7 @@ Event_job_data::construct_sp_sql(THD *thd, String *sp_sql) root to avoid multiple [re]allocations on system heap */ buffer.length= STATIC_SQL_LENGTH + name.length + body.length; - if (! (buffer.str= (char*) thd->alloc(buffer.length))) + if (! (buffer.str= thd->alloc(buffer.length))) DBUG_RETURN(TRUE); sp_sql->set(buffer.str, buffer.length, system_charset_info); @@ -1332,7 +1332,7 @@ Event_job_data::construct_drop_event_sql(THD *thd, String *sp_sql) DBUG_ENTER("Event_job_data::construct_drop_event_sql"); buffer.length= STATIC_SQL_LENGTH + name.length*2 + dbname.length*2; - if (! (buffer.str= (char*) thd->alloc(buffer.length))) + if (! (buffer.str= thd->alloc(buffer.length))) DBUG_RETURN(TRUE); sp_sql->set(buffer.str, buffer.length, system_charset_info); diff --git a/sql/event_parse_data.cc b/sql/event_parse_data.cc index 80d2f9c9fe4..44716ad6dd3 100644 --- a/sql/event_parse_data.cc +++ b/sql/event_parse_data.cc @@ -544,7 +544,7 @@ Event_parse_data::init_definer(THD *thd) /* + 1 for @ */ DBUG_PRINT("info",("init definer as whole")); definer.length= definer_user_len + definer_host_len + 1; - definer.str= tmp= (char*) thd->alloc(definer.length + 1); + definer.str= tmp= thd->alloc(definer.length + 1); DBUG_PRINT("info",("copy the user")); strmake(tmp, definer_user, definer_user_len); diff --git a/sql/filesort.cc b/sql/filesort.cc index 274aaf318cc..4fbc2a64b5b 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -642,7 +642,7 @@ Filesort::make_sortorder(THD *thd, JOIN *join, table_map first_table_bit) DBUG_ASSERT(sort_keys == NULL); - sortorder= (SORT_FIELD*) thd->alloc(sizeof(SORT_FIELD) * count); + sortorder= thd->alloc(count); pos= sort= sortorder; if (!pos) diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 68d4c287377..a5fe0243bfd 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -1906,8 +1906,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info, } while (++i < num_parts); } if (m_reorged_parts && - !(m_reorged_file= (handler**) thd->calloc(sizeof(handler*)* - (m_reorged_parts + 1)))) + !(m_reorged_file= thd->calloc(m_reorged_parts + 1))) { DBUG_RETURN(HA_ERR_OUT_OF_MEM); } @@ -1937,12 +1936,8 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info, } } while (++i < num_parts); } - if (!(new_file_array= ((handler**) - thd->calloc(sizeof(handler*)* - (2*(num_remain_partitions + 1)))))) - { + if (!(new_file_array= thd->calloc(2*(num_remain_partitions + 1)))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); - } m_added_file= &new_file_array[num_remain_partitions + 1]; /* @@ -10635,8 +10630,8 @@ ha_partition::check_if_supported_inplace_alter(TABLE *altered_table, if (!part_inplace_ctx) DBUG_RETURN(HA_ALTER_ERROR); - part_inplace_ctx->handler_ctx_array= (inplace_alter_handler_ctx **) - thd->alloc(sizeof(inplace_alter_handler_ctx *) * (m_tot_parts + 1)); + part_inplace_ctx->handler_ctx_array= + thd->alloc(m_tot_parts + 1); if (!part_inplace_ctx->handler_ctx_array) DBUG_RETURN(HA_ALTER_ERROR); diff --git a/sql/item.cc b/sql/item.cc index e7357658ef3..3b979ea2d14 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1184,7 +1184,7 @@ make_name(THD *thd, uint errors; size_t dst_nbytes= length * system_charset_info->mbmaxlen; set_if_smaller(dst_nbytes, max_octet_length); - char *dst= (char*) thd->alloc(dst_nbytes + 1); + char *dst= thd->alloc(dst_nbytes + 1); if (!dst) return Lex_ident_column(); uint32 cnv_length= my_convert_using_func(dst, dst_nbytes, system_charset_info, @@ -1569,7 +1569,7 @@ bool mark_unsupported_function(const char *where, void *store, uint result) bool mark_unsupported_function(const char *w1, const char *w2, void *store, uint result) { - char *ptr= (char*)current_thd->alloc(strlen(w1) + strlen(w2) + 1); + char *ptr= current_thd->alloc(strlen(w1) + strlen(w2) + 1); if (ptr) strxmov(ptr, w1, w2, NullS); return mark_unsupported_function(ptr, store, result); @@ -3352,9 +3352,8 @@ LEX_CSTRING Item_ident::full_name_cstring() const } if (db_name.str && db_name.str[0]) { - THD *thd= current_thd; - tmp=(char*) thd->alloc((uint) db_name.length+ (uint) table_name.length + - (uint) field_name.length+3); + tmp= current_thd->alloc((uint) db_name.length+ (uint) table_name.length + + (uint) field_name.length+3); length= (strxmov(tmp,db_name.str,".",table_name.str,".",field_name.str, NullS) - tmp); } @@ -3363,9 +3362,7 @@ LEX_CSTRING Item_ident::full_name_cstring() const if (!table_name.str[0]) return field_name; - THD *thd= current_thd; - tmp= (char*) thd->alloc((uint) table_name.length + - field_name.length + 2); + tmp= current_thd->alloc((uint) table_name.length + field_name.length + 2); length= (strxmov(tmp, table_name.str, ".", field_name.str, NullS) - tmp); } return {tmp, length}; @@ -5222,7 +5219,7 @@ static Field *make_default_field(THD *thd, Field *field_arg) if (def_field->default_value && (def_field->default_value->flags || (def_field->flags & BLOB_FLAG))) { - uchar *newptr= (uchar*) thd->alloc(1+def_field->pack_length()); + uchar *newptr= (uchar*)thd->alloc(1+def_field->pack_length()); if (!newptr) return nullptr; @@ -7265,7 +7262,7 @@ Item *Item_float::neg(THD *thd) else { size_t presentation_length= strlen(presentation); - if (char *tmp= (char*) thd->alloc(presentation_length + 2)) + if (char *tmp= thd->alloc(presentation_length + 2)) { tmp[0]= '-'; // Copy with the trailing '\0' @@ -7404,7 +7401,7 @@ inline uint char_val(char X) void Item_hex_constant::hex_string_init(THD *thd, const char *str, size_t str_length) { max_length=(uint)((str_length+1)/2); - char *ptr=(char*) thd->alloc(max_length+1); + char *ptr= thd->alloc(max_length+1); if (!ptr) { str_value.set("", 0, &my_charset_bin); @@ -7471,7 +7468,7 @@ Item_bin_string::Item_bin_string(THD *thd, const char *str, size_t str_length): uint power= 1; max_length= (uint)((str_length + 7) >> 3); - if (!(ptr= (char*) thd->alloc(max_length + 1))) + if (!(ptr= thd->alloc(max_length + 1))) return; str_value.set(ptr, max_length, &my_charset_bin); @@ -10864,9 +10861,7 @@ int Item_cache_str::save_in_field(Field *field, bool no_conversions) bool Item_cache_row::allocate(THD *thd, uint num) { item_count= num; - return (!values && - !(values= - (Item_cache **) thd->calloc(sizeof(Item_cache *)*item_count))); + return (!values && !(values= thd->calloc(item_count))); } diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fa34c95eee6..b97d258abb7 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2020,8 +2020,7 @@ bool Item_func_interval::fix_length_and_dec(THD *thd) if (not_null_consts) { - intervals= (interval_range*) current_thd->alloc(sizeof(interval_range) * - (rows - 1)); + intervals= current_thd->alloc(rows - 1); if (!intervals) return TRUE; @@ -4072,11 +4071,8 @@ Item *in_decimal::create_item(THD *thd) bool Predicant_to_list_comparator::alloc_comparators(THD *thd, uint nargs) { - size_t nbytes= sizeof(Predicant_to_value_comparator) * nargs; - if (!(m_comparators= (Predicant_to_value_comparator *) thd->alloc(nbytes))) - return true; - memset(m_comparators, 0, nbytes); - return false; + m_comparators= thd->calloc(nargs); + return m_comparators == NULL; } @@ -4207,8 +4203,7 @@ bool cmp_item_row::alloc_comparators(THD *thd, uint cols) DBUG_ASSERT(cols == n); return false; } - return - !(comparators= (cmp_item **) thd->calloc(sizeof(cmp_item *) * (n= cols))); + return !(comparators= thd->calloc(n= cols)); } @@ -4239,7 +4234,7 @@ bool cmp_item_row::store_value_by_template(THD *thd, cmp_item *t, Item *item) } n= tmpl->n; bool rc= false; - if ((comparators= (cmp_item **) thd->alloc(sizeof(cmp_item *)*n))) + if ((comparators= thd->alloc(n))) { item->bring_value(); item->null_value= 0; @@ -6076,9 +6071,7 @@ bool Item_func_like::fix_fields(THD *thd, Item **ref) pattern_len = (int) len - 2; pattern = thd->strmake(first + 1, pattern_len); DBUG_PRINT("info", ("Initializing pattern: '%s'", first)); - int *suff = (int*) thd->alloc((int) (sizeof(int)* - ((pattern_len + 1)*2+ - alphabet_size))); + int *suff = thd->alloc((pattern_len + 1) * 2 + alphabet_size); bmGs = suff + pattern_len + 1; bmBc = bmGs + pattern_len + 1; turboBM_compute_good_suffix_shifts(suff); @@ -6108,7 +6101,7 @@ bool Item_func_like::find_selective_predicates_list_processor(void *arg) THD *thd= data->table->in_use; COND_STATISTIC *stat; Item *arg0; - if (!(stat= (COND_STATISTIC *) thd->alloc(sizeof(COND_STATISTIC)))) + if (!(stat= thd->alloc(1))) return TRUE; stat->cond= this; arg0= args[0]->real_item(); @@ -7719,7 +7712,7 @@ longlong Item_func_dyncol_exists::val_int() { uint strlen= nm->length() * DYNCOL_UTF->mbmaxlen + 1; uint dummy_errors; - buf.str= (char *) current_thd->alloc(strlen); + buf.str= current_thd->alloc(strlen); if (buf.str) { buf.length= diff --git a/sql/item_func.cc b/sql/item_func.cc index 5e126390931..fb48b2bc89f 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -93,7 +93,7 @@ bool Item_args::alloc_arguments(THD *thd, uint count) args= tmp_arg; return false; } - if ((args= (Item**) thd->alloc(sizeof(Item*) * count)) == NULL) + if ((args= thd->alloc(count)) == NULL) { arg_count= 0; return true; @@ -120,7 +120,7 @@ Item_args::Item_args(THD *thd, const Item_args *other) { args= tmp_arg; } - else if (!(args= (Item**) thd->alloc(sizeof(Item*) * arg_count))) + else if (!(args= thd->alloc(arg_count))) { arg_count= 0; return; @@ -2831,8 +2831,8 @@ bool Item_func_rand::fix_fields(THD *thd,Item **ref) Query_arena::STMT_SP_QUERY_ARGUMENTS ) ) || rand); - if (!rand && !(rand= (struct my_rnd_struct*) - thd->active_stmt_arena_to_use()->alloc(sizeof(*rand)))) + if (!rand && + !(rand= thd->active_stmt_arena_to_use()->alloc(1))) return TRUE; } else @@ -3521,8 +3521,7 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func, if ((f_args.arg_count=arg_count)) { - if (!(f_args.arg_type= (Item_result*) - thd->alloc(f_args.arg_count*sizeof(Item_result)))) + if (!(f_args.arg_type= thd->alloc(f_args.arg_count))) { err_exit: diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index a5e118333df..be01fdaed7e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2653,9 +2653,8 @@ String *Item_func_password::val_str_ascii(String *str) char *Item_func_password::alloc(THD *thd, const char *password, size_t pass_len, enum PW_Alg al) { - char *buff= (char *) thd->alloc((al==NEW)? - SCRAMBLED_PASSWORD_CHAR_LENGTH + 1: - SCRAMBLED_PASSWORD_CHAR_LENGTH_323 + 1); + char *buff= thd->alloc(al==NEW ? SCRAMBLED_PASSWORD_CHAR_LENGTH + 1 + : SCRAMBLED_PASSWORD_CHAR_LENGTH_323 + 1); if (!buff) return NULL; @@ -4968,7 +4967,7 @@ bool Item_func_dyncol_create::prepare_arguments(THD *thd, bool force_names_arg) { uint strlen= res->length() * DYNCOL_UTF->mbmaxlen + 1; uint dummy_errors; - if (char *str= (char *) thd->alloc(strlen)) + if (char *str= thd->alloc(strlen)) { keys_str[i].length= copy_and_convert(str, strlen, DYNCOL_UTF, @@ -5308,7 +5307,7 @@ bool Item_dyncol_get::get_dyn_value(THD *thd, DYNAMIC_COLUMN_VALUE *val, { uint strlen= nm->length() * DYNCOL_UTF->mbmaxlen + 1; uint dummy_errors; - buf.str= (char *) thd->alloc(strlen); + buf.str= thd->alloc(strlen); if (buf.str) { buf.length= diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 257af28a1bc..501ff7892fa 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1313,8 +1313,7 @@ bool Item_singlerow_subselect::fix_length_and_dec() } else { - if (!(row= (Item_cache**) current_thd->alloc(sizeof(Item_cache*) * - max_columns)) || + if (!(row= current_thd->alloc(max_columns)) || engine->fix_length_and_dec(row)) return TRUE; value= *row; @@ -3741,7 +3740,7 @@ bool Item_in_subselect::init_cond_guards() if (!is_top_level_item() && !pushed_cond_guards && (left_expr->maybe_null() || cols_num > 1)) { - if (!(pushed_cond_guards= (bool*)thd->alloc(sizeof(bool) * cols_num))) + if (!(pushed_cond_guards= thd->alloc(cols_num))) return TRUE; for (uint i= 0; i < cols_num; i++) pushed_cond_guards[i]= TRUE; @@ -5392,7 +5391,7 @@ bool subselect_hash_sj_engine::make_semi_join_conds() if (!(semi_join_conds= new (thd->mem_root) Item_cond_and(thd))) DBUG_RETURN(TRUE); - if (!(tmp_table_ref= (TABLE_LIST*) thd->alloc(sizeof(TABLE_LIST)))) + if (!(tmp_table_ref= thd->alloc(1))) DBUG_RETURN(TRUE); table_name.str= tmp_table->alias.c_ptr(); @@ -5460,7 +5459,7 @@ subselect_hash_sj_engine::make_unique_engine() - here we initialize only those members that are used by subselect_uniquesubquery_engine, so these objects are incomplete. */ - if (!(tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)))) + if (!(tab= thd->alloc(1))) DBUG_RETURN(NULL); tab->table= tmp_table; @@ -6024,10 +6023,8 @@ bool Ordered_key::init(MY_BITMAP *columns_to_index) Item_func_lt *fn_less_than; key_column_count= bitmap_bits_set(columns_to_index); - key_columns= (Item_field**) thd->alloc(key_column_count * - sizeof(Item_field*)); - compare_pred= (Item_func_lt**) thd->alloc(key_column_count * - sizeof(Item_func_lt*)); + key_columns= thd->alloc(key_column_count); + compare_pred= thd->alloc(key_column_count); if (!key_columns || !compare_pred) return TRUE; /* Revert to table scan partial match. */ @@ -6067,8 +6064,8 @@ bool Ordered_key::init(int col_idx) // TIMOUR: check for mem allocation err, revert to scan - key_columns= (Item_field**) thd->alloc(sizeof(Item_field*)); - compare_pred= (Item_func_lt**) thd->alloc(sizeof(Item_func_lt*)); + key_columns= thd->alloc(1); + compare_pred= thd->alloc(1); key_columns[0]= new (thd->mem_root) Item_field(thd, tbl->field[col_idx]); /* Create the predicate (tmp_column[i] < outer_ref[i]). */ @@ -6539,10 +6536,8 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts, row numbers. All small buffers are allocated in the runtime memroot. Big buffers are allocated from the OS via malloc. */ - if (!(merge_keys= (Ordered_key**) thd->alloc(merge_keys_count * - sizeof(Ordered_key*))) || - !(null_bitmaps= (MY_BITMAP**) thd->alloc(merge_keys_count * - sizeof(MY_BITMAP*))) || + if (!(merge_keys= thd->alloc(merge_keys_count)) || + !(null_bitmaps= thd->alloc(merge_keys_count)) || !(row_num_to_rowid= (uchar*) my_malloc(PSI_INSTRUMENT_ME, static_cast(row_count * rowid_length), MYF(MY_WME | MY_THREAD_SPECIFIC)))) diff --git a/sql/item_sum.cc b/sql/item_sum.cc index eade6d35749..0c125085397 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -463,10 +463,8 @@ bool Item_sum::collect_outer_ref_processor(void *param) Item_sum::Item_sum(THD *thd, List &list): Item_func_or_sum(thd, list) { - if (!(orig_args= (Item **) thd->alloc(sizeof(Item *) * arg_count))) - { + if (!(orig_args= thd->alloc(arg_count))) args= NULL; - } mark_as_sum_func(); init_aggregator(); list.empty(); // Fields are used @@ -490,7 +488,7 @@ Item_sum::Item_sum(THD *thd, Item_sum *item): } else { - if (!(orig_args= (Item**) thd->alloc(sizeof(Item*)*arg_count))) + if (!(orig_args= thd->alloc(arg_count))) return; } if (arg_count) @@ -872,7 +870,7 @@ bool Aggregator_distinct::setup(THD *thd) uint32 *length; compare_key= (qsort_cmp2) composite_key_cmp; cmp_arg= (void*) this; - field_lengths= (uint32*) thd->alloc(table->s->fields * sizeof(uint32)); + field_lengths= thd->alloc(table->s->fields); for (tree_key_length= 0, length= field_lengths, field= table->field; field < field_end; ++field, ++length) { @@ -4309,7 +4307,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref) is_conventional() || thd->active_stmt_arena_to_use()->state == Query_arena::STMT_SP_QUERY_ARGUMENTS); - if (!(buf= (char*) thd->active_stmt_arena_to_use()->alloc(buflen)) || + if (!(buf= thd->active_stmt_arena_to_use()->alloc(buflen)) || !(new_separator= new(thd->active_stmt_arena_to_use()->mem_root) String(buf, buflen, collation.collation))) return TRUE; @@ -4370,7 +4368,7 @@ bool Item_func_group_concat::setup(THD *thd) if (arg_count_order) { uint n_elems= arg_count_order + all_fields.elements; - ref_pointer_array= static_cast(thd->alloc(sizeof(Item*) * n_elems)); + ref_pointer_array= thd->alloc(n_elems); if (!ref_pointer_array) DBUG_RETURN(TRUE); memcpy(ref_pointer_array, args, arg_count * sizeof(Item*)); diff --git a/sql/log_event.cc b/sql/log_event.cc index d5c33d1859c..afd171f9047 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3518,8 +3518,7 @@ Table_map_log_event::Table_map_log_event(const uchar *buf, uint event_len, #ifdef MYSQL_SERVER if (!m_table) DBUG_VOID_RETURN; - binlog_type_info_array= (Binlog_type_info *)thd->alloc(m_table->s->fields * - sizeof(Binlog_type_info)); + binlog_type_info_array= thd->alloc(m_table->s->fields); for (uint i= 0; i < m_table->s->fields; i++) binlog_type_info_array[i]= m_table->field[i]->binlog_type_info(); #endif diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index bc6a71da919..6c0ea9a10eb 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -5750,8 +5750,7 @@ Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulonglong tid, (tbl->s->db.str[tbl->s->db.length] == 0)); DBUG_ASSERT(tbl->s->table_name.str[tbl->s->table_name.length] == 0); - binlog_type_info_array= (Binlog_type_info *)thd->alloc(m_table->s->fields * - sizeof(Binlog_type_info)); + binlog_type_info_array= thd->alloc(m_table->s->fields); for (uint i= 0; i < m_table->s->fields; i++) binlog_type_info_array[i]= m_table->field[i]->binlog_type_info(); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index bc235d2e999..9fd9a354e6d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3768,7 +3768,7 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific) thd->set_killed_no_mutex(KILL_QUERY); my_snprintf(buf, sizeof(buf), "--max-session-mem-used=%llu", thd->variables.max_mem_used); - if ((buf2= (char*) thd->alloc(256))) + if ((buf2= thd->alloc(256))) { my_snprintf(buf2, 256, ER_THD(thd, ER_OPTION_PREVENTS_STATEMENT), buf); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 0f5bea4874f..c0aa724e929 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1298,7 +1298,7 @@ QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint key_nr, record= head->record[0]; my_init_dynamic_array2(PSI_INSTRUMENT_ME, &ranges, sizeof(QUICK_RANGE*), - thd->alloc(sizeof(QUICK_RANGE*) * 16), 16, 16, + thd->alloc(16), 16, 16, MYF(MY_THREAD_SPECIFIC)); /* Allocate a bitmap for used columns */ diff --git a/sql/opt_split.cc b/sql/opt_split.cc index 9ae3eb47cf3..af03360f419 100644 --- a/sql/opt_split.cc +++ b/sql/opt_split.cc @@ -510,9 +510,7 @@ bool JOIN::check_for_splittable_materialized() the collected info on potential splittability of T */ SplM_opt_info *spl_opt_info= new (thd->mem_root) SplM_opt_info(); - SplM_field_info *spl_field= - (SplM_field_info *) (thd->calloc(sizeof(SplM_field_info) * - spl_field_cnt)); + SplM_field_info *spl_field= thd->calloc(spl_field_cnt); if (!(spl_opt_info && spl_field)) // consider T as not good for splitting return false; @@ -615,8 +613,7 @@ void TABLE::add_splitting_info_for_key_field(KEY_FIELD *key_field) } if (!eq_item) return; - KEY_FIELD *added_key_field= - (KEY_FIELD *) thd->alloc(sizeof(KEY_FIELD)); + KEY_FIELD *added_key_field= thd->alloc(1); if (!added_key_field || spl_opt_info->added_key_fields.push_back(added_key_field,thd->mem_root)) return; @@ -1106,9 +1103,8 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(uint idx, key_map spl_keys= table->keys_usable_for_splitting; if (!(first_non_const_pos->key && spl_keys.is_set(first_non_const_pos->key->key)) || - !(spl_plan= (SplM_plan_info *) thd->alloc(sizeof(SplM_plan_info))) || - !(spl_plan->best_positions= - (POSITION *) thd->alloc(sizeof(POSITION) * join->table_count)) || + !(spl_plan= thd->alloc(1)) || + !(spl_plan->best_positions= thd->alloc(join->table_count)) || spl_opt_info->plan_cache.push_back(spl_plan)) { reset_validity_vars_for_keyuses(best_key_keyuse_ext_start, best_table, diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 8cbb3678ffa..87719717faa 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -2153,7 +2153,7 @@ static bool convert_subq_to_jtbm(JOIN *parent_join, *remove_item= TRUE; - if (!(tbl_alias.str= (char*)thd->calloc(SUBQERY_TEMPTABLE_NAME_MAX_LEN)) || + if (!(tbl_alias.str= thd->calloc(SUBQERY_TEMPTABLE_NAME_MAX_LEN)) || !(jtbm= alloc_join_nest(thd))) //todo: this is not a join nest! { DBUG_RETURN(TRUE); @@ -2577,8 +2577,7 @@ bool optimize_semijoin_nests(JOIN *join, table_map all_table_map) uint n_tables= my_count_bits(sj_nest->sj_inner_tables & ~join->const_table_map); SJ_MATERIALIZATION_INFO* sjm; if (!(sjm= new SJ_MATERIALIZATION_INFO) || - !(sjm->positions= (POSITION*)join->thd->alloc(sizeof(POSITION)* - n_tables))) + !(sjm->positions= join->thd->alloc(n_tables))) DBUG_RETURN(TRUE); /* purecov: inspected */ sjm->tables= n_tables; sjm->is_used= FALSE; @@ -4437,12 +4436,9 @@ bool setup_sj_materialization_part2(JOIN_TAB *sjm_tab) tab_ref->key= 0; /* The only temp table index. */ tab_ref->key_length= tmp_key->key_length; if (!(tab_ref->key_buff= - (uchar*) thd->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) || - !(tab_ref->key_copy= - (store_key**) thd->alloc((sizeof(store_key*) * - (tmp_key_parts + 1)))) || - !(tab_ref->items= - (Item**) thd->alloc(sizeof(Item*) * tmp_key_parts))) + thd->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) || + !(tab_ref->key_copy= thd->alloc(tmp_key_parts + 1)) || + !(tab_ref->items= thd->alloc(tmp_key_parts))) DBUG_RETURN(TRUE); /* purecov: inspected */ tab_ref->key_buff2=tab_ref->key_buff+ALIGN_SIZE(tmp_key->key_length); @@ -4480,7 +4476,7 @@ bool setup_sj_materialization_part2(JOIN_TAB *sjm_tab) We don't ever have guarded conditions for SJM tables, but code at SQL layer depends on cond_guards array being alloced. */ - if (!(tab_ref->cond_guards= (bool**) thd->calloc(sizeof(uint*)*tmp_key_parts))) + if (!(tab_ref->cond_guards= thd->calloc(tmp_key_parts))) { DBUG_RETURN(TRUE); } @@ -5177,11 +5173,11 @@ int init_dups_weedout(JOIN *join, uint first_table, int first_fanout_table, uint SJ_TMP_TABLE *sjtbl; if (jt_rowid_offset) /* Temptable has at least one rowid */ { - size_t tabs_size= (last_tab - sjtabs) * sizeof(SJ_TMP_TABLE::TAB); - if (!(sjtbl= (SJ_TMP_TABLE*)thd->alloc(sizeof(SJ_TMP_TABLE))) || - !(sjtbl->tabs= (SJ_TMP_TABLE::TAB*) thd->alloc(tabs_size))) + size_t ntabs= last_tab - sjtabs; + if (!(sjtbl= thd->alloc(1)) || + !(sjtbl->tabs= thd->alloc(ntabs))) DBUG_RETURN(TRUE); /* purecov: inspected */ - memcpy(sjtbl->tabs, sjtabs, tabs_size); + memcpy(sjtbl->tabs, sjtabs, ntabs * sizeof(SJ_TMP_TABLE::TAB)); sjtbl->is_degenerate= FALSE; sjtbl->tabs_end= sjtbl->tabs + (last_tab - sjtabs); sjtbl->rowid_len= jt_rowid_offset; @@ -5198,7 +5194,7 @@ int init_dups_weedout(JOIN *join, uint first_table, int first_fanout_table, uint not depend on anything at all, ie this is WHERE const IN (uncorrelated select) */ - if (!(sjtbl= (SJ_TMP_TABLE*)thd->alloc(sizeof(SJ_TMP_TABLE)))) + if (!(sjtbl= thd->alloc(1))) DBUG_RETURN(TRUE); /* purecov: inspected */ sjtbl->tmp_table= NULL; sjtbl->is_degenerate= TRUE; @@ -6048,7 +6044,7 @@ int select_value_catcher::setup(List *items) assigned= FALSE; n_elements= items->elements; - if (!(row= (Item_cache**) thd->alloc(sizeof(Item_cache*) * n_elements))) + if (!(row= thd->alloc(n_elements))) return TRUE; Item *sel_item; diff --git a/sql/opt_table_elimination.cc b/sql/opt_table_elimination.cc index 5528d4c13aa..4cc1e264cd0 100644 --- a/sql/opt_table_elimination.cc +++ b/sql/opt_table_elimination.cc @@ -1729,7 +1729,7 @@ void Dep_analysis_context::create_unique_pseudo_key_if_needed( auto max_possible_elements= first_select->join->fields_list.elements; void *buf; MY_BITMAP *exposed_fields= (MY_BITMAP*) - current_thd->alloc(sizeof(MY_BITMAP)); + current_thd->alloc(1); if (!(buf= current_thd->alloc(bitmap_buffer_size(max_possible_elements))) || my_bitmap_init(exposed_fields, (my_bitmap_map*)buf, max_possible_elements)) diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 7a72544ad84..37b6ef1de59 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -305,7 +305,7 @@ char *partition_info::create_default_partition_names(THD *thd, uint part_no, uint num_parts_arg, uint start_no) { - char *ptr= (char*) thd->calloc(num_parts_arg * MAX_PART_NAME_SIZE + 1); + char *ptr= thd->calloc(num_parts_arg * MAX_PART_NAME_SIZE + 1); char *move_ptr= ptr; uint i= 0; DBUG_ENTER("create_default_partition_names"); @@ -339,7 +339,7 @@ char *partition_info::create_default_subpartition_name(THD *thd, uint subpart_no const char *part_name) { size_t size_alloc= strlen(part_name) + MAX_PART_NAME_SIZE; - char *ptr= (char*) thd->calloc(size_alloc); + char *ptr= thd->calloc(size_alloc); DBUG_ENTER("create_default_subpartition_name"); if (likely(ptr != NULL)) @@ -1653,7 +1653,6 @@ bool partition_info::set_up_charset_field_preps(THD *thd) Field *field, **ptr; uchar **char_ptrs; unsigned i; - size_t size; uint tot_part_fields= 0; uint tot_subpart_fields= 0; DBUG_ENTER("set_up_charset_field_preps"); @@ -1667,15 +1666,13 @@ bool partition_info::set_up_charset_field_preps(THD *thd) while ((field= *(ptr++))) if (field_is_partition_charset(field)) tot_part_fields++; - size= tot_part_fields * sizeof(char*); - if (!(char_ptrs= (uchar**)thd->calloc(size))) + if (!(char_ptrs= thd->calloc(tot_part_fields))) goto error; part_field_buffers= char_ptrs; - if (!(char_ptrs= (uchar**)thd->calloc(size))) + if (!(char_ptrs= thd->calloc(tot_part_fields))) goto error; restore_part_field_ptrs= char_ptrs; - size= (tot_part_fields + 1) * sizeof(Field*); - if (!(char_ptrs= (uchar**)thd->alloc(size))) + if (!(char_ptrs= thd->alloc(tot_part_fields + 1))) goto error; part_charset_field_array= (Field**)char_ptrs; ptr= part_field_array; @@ -1685,8 +1682,7 @@ bool partition_info::set_up_charset_field_preps(THD *thd) if (field_is_partition_charset(field)) { uchar *field_buf; - size= field->pack_length(); - if (!(field_buf= (uchar*) thd->calloc(size))) + if (!(field_buf= thd->calloc(field->pack_length()))) goto error; part_charset_field_array[i]= field; part_field_buffers[i++]= field_buf; @@ -1702,15 +1698,13 @@ bool partition_info::set_up_charset_field_preps(THD *thd) while ((field= *(ptr++))) if (field_is_partition_charset(field)) tot_subpart_fields++; - size= tot_subpart_fields * sizeof(char*); - if (!(char_ptrs= (uchar**) thd->calloc(size))) + if (!(char_ptrs= (uchar**) thd->calloc(tot_subpart_fields))) goto error; subpart_field_buffers= char_ptrs; - if (!(char_ptrs= (uchar**) thd->calloc(size))) + if (!(char_ptrs= (uchar**) thd->calloc(tot_subpart_fields))) goto error; restore_subpart_field_ptrs= char_ptrs; - size= (tot_subpart_fields + 1) * sizeof(Field*); - if (!(char_ptrs= (uchar**) thd->alloc(size))) + if (!(char_ptrs= (uchar**) thd->alloc(tot_subpart_fields + 1))) goto error; subpart_charset_field_array= (Field**)char_ptrs; ptr= subpart_field_array; @@ -1721,8 +1715,7 @@ bool partition_info::set_up_charset_field_preps(THD *thd) if (!field_is_partition_charset(field)) continue; - size= field->pack_length(); - if (!(field_buf= (uchar*) thd->calloc(size))) + if (!(field_buf= thd->calloc(field->pack_length()))) goto error; subpart_charset_field_array[i]= field; subpart_field_buffers[i++]= field_buf; @@ -2036,8 +2029,7 @@ bool partition_info::init_column_part(THD *thd) uint loc_num_columns; DBUG_ENTER("partition_info::init_column_part"); - if (!(list_val= - (part_elem_value*) thd->calloc(sizeof(part_elem_value))) || + if (!(list_val= thd->calloc(1)) || p_elem->list_val_list.push_back(list_val, thd->mem_root)) DBUG_RETURN(TRUE); @@ -2045,9 +2037,7 @@ bool partition_info::init_column_part(THD *thd) loc_num_columns= num_columns; else loc_num_columns= MAX_REF_PARTS; - if (!(col_val_array= - (part_column_list_val*) thd->calloc(loc_num_columns * - sizeof(part_column_list_val)))) + if (!(col_val_array= thd->calloc(loc_num_columns))) DBUG_RETURN(TRUE); list_val->col_val_array= col_val_array; diff --git a/sql/protocol.cc b/sql/protocol.cc index 66b4e5ee248..d7c52a08338 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -1226,8 +1226,7 @@ bool Protocol::send_result_set_metadata(List *list, uint flags) Item *item; Protocol_text prot(thd, thd->variables.net_buffer_length); #ifndef DBUG_OFF - field_handlers= (const Type_handler **) thd->alloc( - sizeof(field_handlers[0]) * list->elements); + field_handlers= thd->alloc(list->elements); #endif for (uint pos= 0; (item= it++); pos++) @@ -1276,8 +1275,7 @@ bool Protocol::send_list_fields(List *list, const TABLE_LIST *table_list) Protocol_text prot(thd, thd->variables.net_buffer_length); #ifndef DBUG_OFF - field_handlers= (const Type_handler **) thd->alloc(sizeof(field_handlers[0]) * - list->elements); + field_handlers= thd->alloc(list->elements); #endif for (uint pos= 0; (fld= it++); pos++) diff --git a/sql/rowid_filter.cc b/sql/rowid_filter.cc index d4fb958fb26..1ccedee2009 100644 --- a/sql/rowid_filter.cc +++ b/sql/rowid_filter.cc @@ -399,10 +399,8 @@ void TABLE::init_cost_info_for_usable_range_rowid_filters(THD *thd) if (!range_rowid_filter_cost_info_elems) return; - range_rowid_filter_cost_info_ptr= - (Range_rowid_filter_cost_info **) - thd->calloc(sizeof(Range_rowid_filter_cost_info *) * - range_rowid_filter_cost_info_elems); + range_rowid_filter_cost_info_ptr= thd->calloc + (range_rowid_filter_cost_info_elems); range_rowid_filter_cost_info= new (thd->mem_root) Range_rowid_filter_cost_info[range_rowid_filter_cost_info_elems]; diff --git a/sql/set_var.cc b/sql/set_var.cc index 6f09490f715..c009ea992fa 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -650,8 +650,7 @@ ulong get_system_variable_hash_records(void) SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted, enum enum_var_type scope) { int count= system_variable_hash.records, i; - int size= sizeof(SHOW_VAR) * (count + 1); - SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size); + SHOW_VAR *result= thd->alloc(count + 1); if (result) { @@ -1416,7 +1415,7 @@ resolve_engine_list(THD *thd, const char *str_arg, size_t str_arg_len, } if (temp_copy) - res= (plugin_ref *)thd->calloc((count+1)*sizeof(*res)); + res= thd->calloc(count+1); else res= (plugin_ref *)my_malloc(PSI_INSTRUMENT_ME, (count+1)*sizeof(*res), MYF(MY_ZEROFILL|MY_WME)); if (!res) @@ -1494,7 +1493,7 @@ temp_copy_engine_list(THD *thd, plugin_ref *list) for (p= list, count= 0; *p; ++p, ++count) ; - p= (plugin_ref *)thd->alloc((count+1)*sizeof(*p)); + p= thd->alloc(count+1); if (!p) { my_error(ER_OUTOFMEMORY, MYF(0), (int)((count+1)*sizeof(*p))); @@ -1520,7 +1519,7 @@ pretty_print_engine_list(THD *thd, plugin_ref *list) size= 0; for (p= list; *p; ++p) size+= plugin_name(*p)->length + 1; - buf= static_cast(thd->alloc(size)); + buf= thd->alloc(size); if (!buf) return NULL; pos= buf; diff --git a/sql/sp.cc b/sql/sp.cc index 80d2ee37648..e9d59f9cb6d 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -2410,8 +2410,7 @@ bool sp_add_used_routine(Query_tables_list *prelocking_ctx, Query_arena *arena, if (!my_hash_search(&prelocking_ctx->sroutines, key->ptr(), key->length())) { - Sroutine_hash_entry *rn= - (Sroutine_hash_entry *)arena->alloc(sizeof(Sroutine_hash_entry)); + Sroutine_hash_entry *rn= arena->alloc(1); if (unlikely(!rn)) // OOM. Error will be reported using fatal_error(). return FALSE; MDL_REQUEST_INIT_BY_KEY(&rn->mdl_request, key, MDL_SHARED, MDL_TRANSACTION); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index d3d57c5334b..9d39856f333 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -2572,7 +2572,7 @@ int sp_head::push_backpatch(THD *thd, sp_instr *i, sp_label *lab, List *list, backpatch_instr_type itype) { - bp_t *bp= (bp_t *) thd->alloc(sizeof(bp_t)); + bp_t *bp= thd->alloc(1); if (!bp) return 1; @@ -3576,7 +3576,7 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check) } else { - if (!(tab= (SP_TABLE *)thd->calloc(sizeof(SP_TABLE)))) + if (!(tab= thd->calloc(1))) return FALSE; if ((lex_for_tmp_check->sql_command == SQLCOM_CREATE_TABLE || lex_for_tmp_check->sql_command == SQLCOM_CREATE_SEQUENCE) && @@ -3655,7 +3655,7 @@ sp_head::add_used_tables_to_table_list(THD *thd, if (stab->temp) continue; - if (!(tab_buff= (char *)thd->alloc(ALIGN_SIZE(sizeof(TABLE_LIST)) * + if (!(tab_buff= thd->alloc(ALIGN_SIZE(sizeof(TABLE_LIST)) * stab->lock_count)) || !(key_buff= (char*)thd->memdup(stab->qname.str, stab->qname.length))) @@ -3707,7 +3707,7 @@ sp_add_to_query_tables(THD *thd, LEX *lex, { TABLE_LIST *table; - if (!(table= (TABLE_LIST *)thd->calloc(sizeof(TABLE_LIST)))) + if (!(table= thd->calloc(1))) return NULL; if (!thd->make_lex_string(&table->db, db->str, db->length) || !thd->make_lex_string(&table->table_name, name->str, name->length) || diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index e50ef625edb..5509fc77d7e 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -167,18 +167,12 @@ bool sp_rcontext::alloc_arrays(THD *thd) { { size_t n= m_root_parsing_ctx->max_cursor_index(); - m_cstack.reset( - static_cast ( - thd->alloc(n * sizeof (sp_cursor*))), - n); + m_cstack.reset(thd->alloc(n), n); } { size_t n= m_root_parsing_ctx->get_num_case_exprs(); - m_case_expr_holders.reset( - static_cast ( - thd->calloc(n * sizeof (Item_cache*))), - n); + m_case_expr_holders.reset(thd->calloc(n), n); } return !m_cstack.array() || !m_case_expr_holders.array(); @@ -374,10 +368,7 @@ bool sp_rcontext::init_var_items(THD *thd, { uint num_vars= m_root_parsing_ctx->max_var_index(); - m_var_items.reset( - static_cast ( - thd->alloc(num_vars * sizeof (Item *))), - num_vars); + m_var_items.reset(thd->alloc(num_vars), num_vars); if (!m_var_items.array()) return true; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 92d9134223b..7b8be5a1313 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -12019,7 +12019,7 @@ bool sp_grant_privileges(THD *thd, Lex_cstring_strlen sctx_user(sctx->priv_user); Lex_cstring_strlen sctx_host(sctx->priv_host); - if (!(combo=(LEX_USER*) thd->alloc(sizeof(LEX_USER)))) + if (!(combo= thd->alloc(1))) DBUG_RETURN(TRUE); mysql_mutex_lock(&acl_cache->lock); diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc index c40867b5043..f03fe0ea094 100644 --- a/sql/sql_alter.cc +++ b/sql/sql_alter.cc @@ -282,9 +282,9 @@ uint Alter_info::check_vcol_field(Item_field *item) const ((item->db_name.length && !db.streq(item->db_name)) || (item->table_name.length && !table_name.streq(item->table_name)))) { - char *ptr= (char*)current_thd->alloc(item->db_name.length + - item->table_name.length + - item->field_name.length + 3); + char *ptr= current_thd->alloc(item->db_name.length + + item->table_name.length + + item->field_name.length + 3); strxmov(ptr, safe_str(item->db_name.str), item->db_name.length ? "." : "", item->table_name.str, ".", item->field_name.str, NullS); item->field_name.str= ptr; diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 15c1277fdc8..51e0da5543f 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -126,8 +126,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result, pc->max_treemem = MAX_TREEMEM; } - if (!(pc->f_info= - (field_info**) thd->alloc(sizeof(field_info*) * field_list.elements))) + if (!(pc->f_info= thd->alloc(field_list.elements))) goto err; pc->f_end = pc->f_info + field_list.elements; pc->fields = field_list; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index b5e1a1d5236..f6814e733a6 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3391,7 +3391,7 @@ request_backoff_action(enum_open_table_action action_arg, { DBUG_ASSERT(action_arg == OT_DISCOVER || action_arg == OT_REPAIR || action_arg == OT_ADD_HISTORY_PARTITION); - m_failed_table= (TABLE_LIST*) m_thd->alloc(sizeof(TABLE_LIST)); + m_failed_table= m_thd->alloc(1); if (m_failed_table == NULL) return TRUE; m_failed_table->init_one_table(&table->db, &table->table_name, &table->alias, TL_WRITE); @@ -4997,7 +4997,7 @@ add_internal_tables(THD *thd, Query_tables_list *prelocking_ctx, continue; } - TABLE_LIST *tl= (TABLE_LIST *) thd->alloc(sizeof(TABLE_LIST)); + TABLE_LIST *tl= thd->alloc(1); if (!tl) DBUG_RETURN(TRUE); tl->init_one_table_for_prelocking(&tables->db, @@ -5069,18 +5069,13 @@ prepare_fk_prelocking_list(THD *thd, Query_tables_list *prelocking_ctx, lock_type= TL_READ; if (table_already_fk_prelocked(prelocking_ctx->query_tables, - fk->foreign_db, fk->foreign_table, - lock_type)) + fk->foreign_db, fk->foreign_table, lock_type)) continue; - TABLE_LIST *tl= (TABLE_LIST *) thd->alloc(sizeof(TABLE_LIST)); - tl->init_one_table_for_prelocking(fk->foreign_db, - fk->foreign_table, - NULL, lock_type, - TABLE_LIST::PRELOCK_FK, - table_list->belong_to_view, op, - &prelocking_ctx->query_tables_last, - table_list->for_insert_data); + TABLE_LIST *tl= thd->alloc(1); + tl->init_one_table_for_prelocking(fk->foreign_db, fk->foreign_table, + NULL, lock_type, TABLE_LIST::PRELOCK_FK, table_list->belong_to_view, + op, &prelocking_ctx->query_tables_last, table_list->for_insert_data); } if (arena) thd->restore_active_arena(arena, &backup); @@ -5881,7 +5876,7 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, uint flags) TABLE **start,**ptr; bool found_first_not_own= 0; - if (!(ptr=start=(TABLE**) thd->alloc(sizeof(TABLE*)*count))) + if (!(ptr= start= thd->alloc(count))) DBUG_RETURN(TRUE); /* diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 1f21d35d4e4..ec5b335d97e 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -2543,7 +2543,7 @@ bool THD::reinterpret_string_from_binary(LEX_CSTRING *to, CHARSET_INFO *cs, { size_t zeros= cs->mbminlen - incomplete; size_t aligned_length= zeros + length; - char *dst= (char*) alloc(aligned_length + 1); + char *dst= alloc(aligned_length + 1); if (!dst) { to->str= NULL; // Safety @@ -4517,8 +4517,7 @@ create_result_table(THD *thd_arg, List *column_types, !create_table, keep_row_order))) return TRUE; - col_stat= (Column_statistics*) table->in_use->alloc(table->s->fields * - sizeof(Column_statistics)); + col_stat= table->in_use->alloc(table->s->fields); if (!col_stat) return TRUE; @@ -5136,7 +5135,7 @@ TABLE *open_purge_table(THD *thd, const char *db, size_t dblen, /* Purge already hold the MDL for the table */ Open_table_context ot_ctx(thd, MYSQL_OPEN_HAS_MDL_LOCK); - TABLE_LIST *tl= (TABLE_LIST*)thd->alloc(sizeof(TABLE_LIST)); + TABLE_LIST *tl= thd->alloc(1); LEX_CSTRING db_name= {db, dblen }; LEX_CSTRING table_name= { tb, tblen }; diff --git a/sql/sql_class.h b/sql/sql_class.h index d49f6ceb3c9..931b8049273 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1278,13 +1278,19 @@ public: inline bool is_conventional() const { return state == STMT_CONVENTIONAL_EXECUTION; } - inline void* alloc(size_t size) const { return alloc_root(mem_root,size); } - inline void* calloc(size_t size) const + template + inline T* alloc(size_t size) const { - void *ptr; - if (likely((ptr=alloc_root(mem_root,size)))) - bzero(ptr, size); - return ptr; + return (T*)alloc_root(mem_root, sizeof(T)*size); + } + + template + inline T* calloc(size_t size) const + { + void* ptr= alloc_root(mem_root, sizeof(T)*size); + if (ptr) + bzero(ptr, sizeof(T)*size); + return (T*)ptr; } inline char *strdup(const char *str) const { return strdup_root(mem_root,str); } @@ -1292,7 +1298,7 @@ public: { return strmake_root(mem_root,str,size); } inline LEX_CSTRING strcat(const LEX_CSTRING &a, const LEX_CSTRING &b) const { - char *buf= (char*)alloc(a.length + b.length + 1); + char *buf= alloc(a.length + b.length + 1); if (unlikely(!buf)) return null_clex_str; memcpy(buf, a.str, a.length); @@ -1398,7 +1404,7 @@ public: // Allocate LEX_STRING for character set conversion bool alloc_lex_string(LEX_STRING *dst, size_t length) const { - if (likely((dst->str= (char*) alloc(length)))) + if (likely((dst->str= alloc(length)))) return false; dst->length= 0; // Safety return true; // EOM @@ -1411,7 +1417,7 @@ public: const char *tmp= src->str; const char *tmpend= src->str + src->length; char *to; - if (!(dst->str= to= (char *) alloc(src->length + 1))) + if (!(dst->str= to= alloc(src->length + 1))) { dst->length= 0; // Safety return true; diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 651ebe0074b..549c69371cb 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -1222,7 +1222,7 @@ update_binlog: char *query, *query_pos, *query_end, *query_data_start; TABLE_LIST *tbl; - if (!(query= (char*) thd->alloc(MAX_DROP_TABLE_Q_LEN))) + if (!(query= thd->alloc(MAX_DROP_TABLE_Q_LEN))) goto exit; /* not much else we can do */ query_pos= query_data_start= strmov(query,"DROP TABLE IF EXISTS "); query_end= query + MAX_DROP_TABLE_Q_LEN; @@ -1332,7 +1332,7 @@ static bool find_db_tables_and_rm_known_files(THD *thd, MY_DIR *dirp, const LEX_CSTRING *table= files.at(idx); /* Drop the table nicely */ - TABLE_LIST *table_list=(TABLE_LIST*)thd->calloc(sizeof(*table_list)); + TABLE_LIST *table_list= thd->calloc(1); if (!table_list) DBUG_RETURN(true); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 7120fa21189..8796b6cd738 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -1095,7 +1095,7 @@ multi_delete::multi_delete(THD *thd_arg, TABLE_LIST *dt, uint num_of_tables_arg) num_of_tables(num_of_tables_arg), error(0), do_delete(0), transactional_tables(0), normal_tables(0), error_handled(0) { - tempfiles= (Unique **) thd_arg->calloc(sizeof(Unique *) * num_of_tables); + tempfiles= thd_arg->calloc(num_of_tables); } diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index b23293f46ea..73739b5cf0b 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -388,7 +388,7 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived) make_leaves_list(thd, dt_select->leaf_tables, derived, TRUE, 0); } - derived->nested_join= (NESTED_JOIN*) thd->calloc(sizeof(NESTED_JOIN)); + derived->nested_join= thd->calloc(1); if (!derived->nested_join) { res= TRUE; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 3957854a06d..9d00c9eda80 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -949,7 +949,7 @@ retry: { DBUG_ASSERT(keyname != 0); - if (unlikely(!(key= (uchar*) thd->calloc(ALIGN_SIZE(handler->key_len))))) + if (unlikely(!(key= thd->calloc(ALIGN_SIZE(handler->key_len))))) goto err; if (unlikely((error= table->file->ha_index_or_rnd_end()))) break; diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 6c0064e4127..37a5bfb5114 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -2835,7 +2835,7 @@ int JOIN_CACHE_HASHED::init(bool for_explain) if (for_explain) DBUG_RETURN(0); - if (!(key_buff= (uchar*) join->thd->alloc(key_length))) + if (!(key_buff= join->thd->alloc(key_length))) DBUG_RETURN(1); /* Take into account a reference to the next record in the key chain */ diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index bebfef4d231..f313e675998 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -809,7 +809,7 @@ bool Lex_input_stream::init(THD *thd, DBUG_EXECUTE_IF("bug42064_simulate_oom", DBUG_SET("+d,simulate_out_of_memory");); - m_cpp_buf= (char*) thd->alloc(length + 1); + m_cpp_buf= thd->alloc(length + 1); DBUG_EXECUTE_IF("bug42064_simulate_oom", DBUG_SET("-d,bug42064_simulate_oom");); @@ -881,7 +881,7 @@ void Lex_input_stream::body_utf8_start(THD *thd, const char *begin_ptr) size_t body_utf8_length= get_body_utf8_maximum_length(thd); - m_body_utf8= (char *) thd->alloc(body_utf8_length + 1); + m_body_utf8= thd->alloc(body_utf8_length + 1); m_body_utf8_ptr= m_body_utf8; *m_body_utf8_ptr= 0; @@ -1682,7 +1682,7 @@ bool Lex_input_stream::get_text(Lex_string_with_metadata_st *dst, uint sep, end -= post_skip; DBUG_ASSERT(end >= str); - if (!(to= (char*) m_thd->alloc((uint) (end - str) + 1))) + if (!(to= m_thd->alloc((uint) (end - str) + 1))) { dst->set(&empty_clex_str, 0, '\0'); return true; // Sql_alloc has set error flag @@ -3673,8 +3673,7 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num) if (!ref_pointer_array.is_null()) return false; - Item **array= static_cast( - thd->active_stmt_arena_to_use()->alloc(sizeof(Item*) * n_elems)); + Item **array= thd->active_stmt_arena_to_use()->alloc(n_elems); if (likely(array != NULL)) ref_pointer_array= Ref_ptr_array(array, n_elems); return array == NULL; @@ -4864,7 +4863,7 @@ void st_select_lex::fix_prepare_information(THD *thd, Item **conds, { if (!group_list_ptrs) { - void *mem= active_arena->alloc(sizeof(Group_list_ptrs)); + void *mem= active_arena->alloc(1); group_list_ptrs= new (mem) Group_list_ptrs(active_arena->mem_root); } group_list_ptrs->reserve(group_list.elements); @@ -12364,7 +12363,7 @@ LEX_USER *LEX::current_user_for_set_password(THD *thd) return NULL; } LEX_USER *res; - if (unlikely(!(res= (LEX_USER*) thd->calloc(sizeof(LEX_USER))))) + if (unlikely(!(res= thd->calloc(1)))) return NULL; res->user= current_user; return res; diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 1509adc24b2..55184af93b6 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -1441,7 +1441,7 @@ READ_INFO::READ_INFO(THD *thd, File file_par, uint length= MY_MAX(charset()->mbmaxlen, MY_MAX(m_field_term.length(), m_line_term.length())) + 1; set_if_bigger(length,line_start.length()); - stack= stack_pos= (int*) thd->alloc(sizeof(int) * length); + stack= stack_pos= thd->alloc(length); DBUG_ASSERT(m_fixed_length < UINT_MAX32); if (data.reserve((size_t) m_fixed_length)) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 64f7222b769..c37e199e6ac 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2264,8 +2264,7 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD * char buff[250]; uint buff_len= sizeof(buff); - if (!(current_global_status_var= (STATUS_VAR*) - thd->alloc(sizeof(STATUS_VAR)))) + if (!(current_global_status_var= thd->alloc(1))) break; general_log_print(thd, command, NullS); status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]); @@ -7972,7 +7971,7 @@ add_proc_to_list(THD* thd, Item *item) ORDER *order; Item **item_ptr; - if (unlikely(!(order = (ORDER *) thd->alloc(sizeof(ORDER)+sizeof(Item*))))) + if (unlikely(!(order= (ORDER *) thd->alloc(sizeof(ORDER)+sizeof(Item*))))) return 1; item_ptr = (Item**) (order+1); *item_ptr= item; @@ -7990,7 +7989,7 @@ bool add_to_list(THD *thd, SQL_I_List &list, Item *item,bool asc) { ORDER *order; DBUG_ENTER("add_to_list"); - if (unlikely(!(order = (ORDER *) thd->alloc(sizeof(ORDER))))) + if (unlikely(!(order= thd->alloc(1)))) DBUG_RETURN(1); order->item_ptr= item; order->item= &order->item_ptr; @@ -9340,8 +9339,7 @@ bool append_file_to_dir(THD *thd, const char **filename_ptr, /* Fix is using unix filename format on dos */ strmov(buff,*filename_ptr); end=convert_dirname(buff, *filename_ptr, NullS); - if (unlikely(!(ptr= (char*) thd->alloc((size_t) (end-buff) + - table_name->length + 1)))) + if (unlikely(!(ptr= thd->alloc((size_t)(end-buff) + table_name->length + 1)))) return 1; // End of memory *filename_ptr=ptr; strxmov(ptr,buff,table_name->str,NullS); @@ -9989,7 +9987,7 @@ LEX_USER *create_default_definer(THD *thd, bool role) { LEX_USER *definer; - if (unlikely(! (definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER))))) + if (unlikely(!(definer= thd->alloc(1)))) return 0; thd->get_definer(definer, role); @@ -10024,7 +10022,7 @@ LEX_USER *create_definer(THD *thd, LEX_CSTRING *user_name, /* Create and initialize. */ - if (unlikely(!(definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER))))) + if (unlikely(!(definer= thd->alloc(1)))) return 0; definer->user= *user_name; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index a95323d8d43..46370f12f6b 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -322,12 +322,10 @@ err: function. */ -static bool set_up_field_array(THD *thd, TABLE *table, - bool is_sub_part) +static bool set_up_field_array(THD *thd, TABLE *table, bool is_sub_part) { Field **ptr, *field, **field_array; uint num_fields= 0; - uint size_field_array; uint i= 0; uint inx; partition_info *part_info= table->part_info; @@ -366,8 +364,7 @@ static bool set_up_field_array(THD *thd, TABLE *table, DBUG_ASSERT(!is_sub_part); DBUG_RETURN(FALSE); } - size_field_array= (num_fields+1)*sizeof(Field*); - field_array= (Field**) thd->calloc(size_field_array); + field_array= thd->calloc(num_fields + 1); if (unlikely(!field_array)) DBUG_RETURN(TRUE); @@ -480,15 +477,14 @@ static bool create_full_part_field_array(THD *thd, TABLE *table, else { Field *field, **field_array; - uint num_part_fields=0, size_field_array; + uint num_part_fields=0; ptr= table->field; while ((field= *(ptr++))) { if (field->flags & FIELD_IN_PART_FUNC_FLAG) num_part_fields++; } - size_field_array= (num_part_fields+1)*sizeof(Field*); - field_array= (Field**) thd->calloc(size_field_array); + field_array= thd->calloc(num_part_fields + 1); if (unlikely(!field_array)) { result= TRUE; @@ -1290,8 +1286,8 @@ static bool check_range_constants(THD *thd, partition_info *part_info) part_column_list_val *UNINIT_VAR(current_largest_col_val); uint num_column_values= part_info->part_field_list.elements; uint size_entries= sizeof(part_column_list_val) * num_column_values; - part_info->range_col_array= (part_column_list_val*) - thd->calloc(part_info->num_parts * size_entries); + part_info->range_col_array= thd->calloc + (part_info->num_parts * num_column_values); if (unlikely(part_info->range_col_array == NULL)) goto end; @@ -1326,8 +1322,7 @@ static bool check_range_constants(THD *thd, partition_info *part_info) longlong part_range_value; bool signed_flag= !part_info->part_expr->unsigned_flag; - part_info->range_int_array= (longlong*) - thd->alloc(part_info->num_parts * sizeof(longlong)); + part_info->range_int_array= thd->alloc(part_info->num_parts); if (unlikely(part_info->range_int_array == NULL)) goto end; @@ -1554,8 +1549,7 @@ static bool check_vers_constants(THD *thd, partition_info *part_info) if (!vers_info->interval.is_set()) return 0; - part_info->range_int_array= - (longlong*) thd->alloc(part_info->num_parts * sizeof(longlong)); + part_info->range_int_array= thd->alloc(part_info->num_parts); MYSQL_TIME ltime; List_iterator it(part_info->partitions); diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 1c0641516c1..18a22ec1f8d 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -508,7 +508,7 @@ rename_tables(THD *thd, TABLE_LIST *table_list, DDL_LOG_STATE *ddl_log_state, when only using temporary tables. We don't need the log as all temporary tables will disappear anyway in a crash. */ - TABLE_PAIR *pair= (TABLE_PAIR*) thd->alloc(sizeof(*pair)); + TABLE_PAIR *pair= thd->alloc(1); if (! pair || tmp_tables.push_front(pair, thd->mem_root)) goto revert_rename; pair->from= ren_table; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 73cd2e7f06c..10244d2e7ef 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3521,7 +3521,7 @@ setup_subq_exit: if (select_lex->have_window_funcs()) { - if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)))) + if (!(join_tab= thd->alloc(1))) DBUG_RETURN(1); #ifndef DBUG_OFF dbug_join_tab_array_size= 1; @@ -7571,7 +7571,7 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, (*sargables)[0].field= 0; if (my_init_dynamic_array2(thd->mem_root->psi_key, keyuse, sizeof(KEYUSE), - thd->alloc(sizeof(KEYUSE) * 20), 20, 64, + thd->alloc(20), 20, 64, MYF(MY_THREAD_SPECIFIC))) DBUG_RETURN(TRUE); @@ -13125,8 +13125,7 @@ bool JOIN::get_best_combination() */ aggr_tables= 2; DBUG_ASSERT(!tmp_table_param.using_outer_summary_function); - if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)* - (top_join_tab_count + aggr_tables)))) + if (!(join_tab= thd->alloc(top_join_tab_count + aggr_tables))) DBUG_RETURN(TRUE); if (inject_splitting_cond_for_all_tables_with_split_opt()) @@ -13176,7 +13175,7 @@ bool JOIN::get_best_combination() j->join_loops= 0.0; JOIN_TAB *jt; JOIN_TAB_RANGE *jt_range; - if (!(jt= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)*sjm->tables)) || + if (!(jt= thd->alloc(sjm->tables)) || !(jt_range= new JOIN_TAB_RANGE)) goto error; jt_range->start= jt; @@ -13356,9 +13355,8 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab, if (!key_parts) DBUG_RETURN(TRUE); /* This memory is allocated only once for the joined table join_tab */ - if (!(keyinfo= (KEY *) thd->alloc(sizeof(KEY))) || - !(key_part_info = (KEY_PART_INFO *) thd->alloc(sizeof(KEY_PART_INFO)* - key_parts))) + if (!(keyinfo= thd->alloc(1)) || + !(key_part_info = thd->alloc(key_parts))) DBUG_RETURN(TRUE); keyinfo->usable_key_parts= keyinfo->user_defined_key_parts = key_parts; keyinfo->ext_key_parts= keyinfo->user_defined_key_parts; @@ -13369,7 +13367,7 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab, keyinfo->is_statistics_from_stat_tables= FALSE; keyinfo->name.str= "$hj"; keyinfo->name.length= 3; - keyinfo->rec_per_key= (ulong*) thd->calloc(sizeof(ulong)*key_parts); + keyinfo->rec_per_key= thd->calloc(key_parts); if (!keyinfo->rec_per_key) DBUG_RETURN(TRUE); keyinfo->key_part= key_part_info; @@ -13527,11 +13525,10 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, j->ref.key_parts= keyparts; j->ref.key_length= length; j->ref.key= (int) key; - if (!(j->ref.key_buff= (uchar*) thd->calloc(ALIGN_SIZE(length)*2)) || - !(j->ref.key_copy= (store_key**) thd->alloc((sizeof(store_key*) * - (keyparts+1)))) || - !(j->ref.items=(Item**) thd->alloc(sizeof(Item*)*keyparts)) || - !(j->ref.cond_guards= (bool**) thd->alloc(sizeof(uint*)*keyparts))) + if (!(j->ref.key_buff= thd->calloc(ALIGN_SIZE(length)*2)) || + !(j->ref.key_copy= thd->alloc(keyparts+1)) || + !(j->ref.items= thd->alloc(keyparts)) || + !(j->ref.cond_guards= thd->alloc(keyparts))) { DBUG_RETURN(TRUE); } @@ -16038,8 +16035,7 @@ make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after) if (tab->loosescan_match_tab) { - if (!(tab->loosescan_buf= (uchar*)join->thd->alloc(tab-> - loosescan_key_len))) + if (!(tab->loosescan_buf= join->thd->alloc(tab->loosescan_key_len))) return TRUE; /* purecov: inspected */ tab->sorted= TRUE; } @@ -16702,13 +16698,9 @@ bool TABLE_REF::tmp_table_index_lookup_init(THD *thd, key= 0; /* The only temp table index. */ key_length= tmp_key->key_length; - if (!(key_buff= - (uchar*) thd->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) || - !(key_copy= - (store_key**) thd->alloc((sizeof(store_key*) * - (tmp_key_parts + 1)))) || - !(items= - (Item**) thd->alloc(sizeof(Item*) * tmp_key_parts))) + if (!(key_buff= thd->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) || + !(key_copy= thd->alloc(tmp_key_parts + 1)) || + !(items= thd->alloc(tmp_key_parts))) DBUG_RETURN(TRUE); key_buff2= key_buff + ALIGN_SIZE(tmp_key->key_length); @@ -22630,7 +22622,7 @@ bool Virtual_tmp_table::open() uint null_pack_length= (s->null_fields + 7) / 8; // NULL-bit array length s->reclength+= null_pack_length; s->rec_buff_length= ALIGN_SIZE(s->reclength + 1); - if (!(record[0]= (uchar*) in_use->alloc(s->rec_buff_length))) + if (!(record[0]= in_use->alloc(s->rec_buff_length))) return true; if (null_pack_length) { @@ -28611,7 +28603,7 @@ create_distinct_group(THD *thd, Ref_ptr_array ref_pointer_array, if ((*ord_iter->item)->eq(item, 1)) goto next_item; - ORDER *ord=(ORDER*) thd->calloc(sizeof(ORDER)); + ORDER *ord= thd->calloc(1); if (!ord) return 0; @@ -29103,7 +29095,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, another extra byte to not get warnings from purify in Field_string::val_int */ - if (!(tmp= (uchar*) thd->alloc(field->pack_length()+2))) + if (!(tmp= thd->alloc(field->pack_length()+2))) goto err; if (copy) { @@ -29888,16 +29880,14 @@ bool JOIN::rollup_init() */ tmp_table_param.group_parts= send_group_parts; - Item_null_result **null_items= - static_cast(thd->alloc(sizeof(Item*)*send_group_parts)); + Item_null_result **null_items= thd->alloc(send_group_parts); rollup.null_items= Item_null_array(null_items, send_group_parts); rollup.ref_pointer_arrays= - static_cast + reinterpret_cast (thd->alloc((sizeof(Ref_ptr_array) + all_fields.elements * sizeof(Item*)) * send_group_parts)); - rollup.fields= - static_cast*>(thd->alloc(sizeof(List) * send_group_parts)); + rollup.fields= thd->alloc >(send_group_parts); if (!null_items || !rollup.ref_pointer_arrays || !rollup.fields) return true; @@ -31386,8 +31376,7 @@ static void print_join(THD *thd, } ti.rewind(); - if (!(table= static_cast(thd->alloc(sizeof(TABLE_LIST*) * - tables_to_print)))) + if (!(table= thd->alloc(tables_to_print))) DBUG_VOID_RETURN; // out of memory TABLE_LIST *tmp, **t= table + (tables_to_print - 1); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 64bc41a3eb2..65f8e42a4ca 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2937,7 +2937,7 @@ static my_bool list_callback(THD *tmp, list_callback_arg *arg) if (tmp->peer_port && (tmp_sctx->host || tmp_sctx->ip) && arg->thd->security_ctx->host_or_ip[0]) { - if ((thd_info->host= (char*) arg->thd->alloc(LIST_PROCESS_HOST_LEN+1))) + if ((thd_info->host= arg->thd->alloc(LIST_PROCESS_HOST_LEN+1))) my_snprintf((char *) thd_info->host, LIST_PROCESS_HOST_LEN, "%s:%u", tmp_sctx->host_or_ip, tmp->peer_port); } @@ -3181,7 +3181,7 @@ int select_result_text_buffer::append_row(List &items, bool send_names) char **row; int column= 0; - if (!(row= (char**) thd->alloc(sizeof(char*) * n_columns)) || + if (!(row= thd->alloc(n_columns)) || rows.push_back(row, thd->mem_root)) return true; @@ -3354,7 +3354,7 @@ int fill_show_explain_or_analyze(THD *thd, TABLE_LIST *table, COND *cond, fromcs->mbminlen; uint dummy_errors; char *to, *p; - if (!(to= (char*)thd->alloc(conv_length + 1))) + if (!(to= thd->alloc(conv_length + 1))) DBUG_RETURN(1); p= to; p+= copy_and_convert(to, conv_length, tocs, @@ -8903,7 +8903,7 @@ int fill_slave_status(THD *thd, TABLE_LIST *tables, COND *cond) Sort lines to get them into a predicted order (needed for test cases and to not confuse users) */ - if (!(tmp= (Master_info**) thd->alloc(sizeof(Master_info*) * elements))) + if (!(tmp= thd->alloc(elements))) goto error; if (single_slave) @@ -9247,10 +9247,8 @@ int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list) DBUG_RETURN(0); } List_iterator_fast it(sel->item_list); - if (!(transl= - (Field_translator*)(thd->active_stmt_arena_to_use()-> - alloc(sel->item_list.elements * - sizeof(Field_translator))))) // ??? + if (!(transl= thd->active_stmt_arena_to_use()-> + alloc(sel->item_list.elements))) // ??? { DBUG_RETURN(1); } @@ -11071,7 +11069,7 @@ TABLE_LIST *get_trigger_table(THD *thd, const sp_name *trg_name) return NULL; /* We need to reset statement table list to be PS/SP friendly. */ - if (!(table= (TABLE_LIST*) thd->alloc(sizeof(TABLE_LIST)))) + if (!(table= thd->alloc(1))) return NULL; db= thd->make_ident_opt_casedn(trg_name->m_db, lower_case_table_names); diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 3b241ffead2..7d0a71c25ac 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -1987,8 +1987,7 @@ public: return; } - if ((calc_state= - (Prefix_calc_state *) thd->alloc(sizeof(Prefix_calc_state)*key_parts))) + if ((calc_state= thd->alloc(key_parts))) { uint keyno= (uint)(key_info-table->key_info); for (i= 0, state= calc_state; i < key_parts; i++, state++) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 6e87d529c83..ad39e9c8798 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3088,7 +3088,7 @@ mysql_prepare_create_table_finalize(THD *thd, HA_CREATE_INFO *create_info, } } - KEY *key_info= *key_info_buffer= (KEY*)thd->calloc(sizeof(KEY) * (*key_count)); + KEY *key_info= *key_info_buffer= thd->calloc(*key_count); if (!*key_info_buffer) DBUG_RETURN(true); // Out of memory @@ -3151,7 +3151,7 @@ mysql_prepare_create_table_finalize(THD *thd, HA_CREATE_INFO *create_info, DBUG_RETURN(TRUE); } - key_part_info=(KEY_PART_INFO*) thd->calloc(sizeof(KEY_PART_INFO)*key_parts); + key_part_info= thd->calloc(key_parts); if (!key_part_info) DBUG_RETURN(true); // Out of memory @@ -6633,15 +6633,12 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, /* Allocate result buffers. */ DBUG_ASSERT(ha_alter_info->rename_keys.mem_root() == thd->mem_root); - if (! (ha_alter_info->index_drop_buffer= - (KEY**) thd->alloc(sizeof(KEY*) * table->s->keys)) || + if (! (ha_alter_info->index_drop_buffer= thd->alloc(table->s->keys)) || ! (ha_alter_info->index_add_buffer= - (uint*) thd->alloc(sizeof(uint) * - alter_info->key_list.elements)) || + thd->alloc(alter_info->key_list.elements)) || ha_alter_info->rename_keys.reserve(ha_alter_info->index_add_count) || ! (ha_alter_info->index_altered_ignorability_buffer= - (KEY_PAIR*)thd->alloc(sizeof(KEY_PAIR) * - alter_info->alter_index_ignorability_list.elements))) + thd->alloc(alter_info->alter_index_ignorability_list.elements))) DBUG_RETURN(true); /* @@ -8247,10 +8244,10 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, restore_record(table, s->default_values); // Empty record for DEFAULT - if ((create_info->fields_option_struct= (ha_field_option_struct**) - thd->calloc(sizeof(void*) * table->s->fields)) == NULL || - (create_info->indexes_option_struct= (ha_index_option_struct**) - thd->calloc(sizeof(void*) * table->s->keys)) == NULL) + if ((create_info->fields_option_struct= + thd->calloc(table->s->fields)) == NULL || + (create_info->indexes_option_struct= + thd->calloc(table->s->keys)) == NULL) DBUG_RETURN(1); if (merge_engine_options(table->s->option_list, create_info->option_list, @@ -10200,7 +10197,7 @@ const char *online_alter_check_supported(THD *thd, LEX_CSTRING dflt{STRING_WITH_LEN("DEFAULT")}; LEX_CSTRING nxvl{STRING_WITH_LEN("NEXTVAL()")}; size_t len= strlen(fmt) + nxvl.length + c.field_name.length + dflt.length; - char *resp= (char*)thd->alloc(len); + char *resp= thd->alloc(len); // expression %s cannot be used in the %s clause of %`s my_snprintf(resp, len, fmt, nxvl.str, dflt.str, c.field_name.str); return resp; diff --git a/sql/sql_type_fixedbin.h b/sql/sql_type_fixedbin.h index c6eb56c4769..f89cd4900ab 100644 --- a/sql/sql_type_fixedbin.h +++ b/sql/sql_type_fixedbin.h @@ -957,7 +957,7 @@ public: { static Name name= singleton()->name(); size_t len= 9+name.length()+1; - char *buf= (char*)current_thd->alloc(len); + char *buf= current_thd->alloc(len); strmov(strmov(buf, "cast_as_"), name.ptr()); return { buf, len }; } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 06841adbb83..ad449fc8f7c 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1931,13 +1931,10 @@ int multi_update::prepare(List ¬_used_values, table_count= update.elements; update_tables= update.first; - tmp_tables = (TABLE**) thd->calloc(sizeof(TABLE *) * table_count); - tmp_table_param = (TMP_TABLE_PARAM*) thd->calloc(sizeof(TMP_TABLE_PARAM) * - table_count); - fields_for_table= (List_item **) thd->alloc(sizeof(List_item *) * - table_count); - values_for_table= (List_item **) thd->alloc(sizeof(List_item *) * - table_count); + tmp_tables = thd->calloc(table_count); + tmp_table_param = thd->calloc(table_count); + fields_for_table= thd->alloc(table_count); + values_for_table= thd->alloc(table_count); if (unlikely(thd->is_fatal_error)) DBUG_RETURN(1); for (i=0 ; i < table_count ; i++) diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 8e339d7b314..52c229b4486 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -917,7 +917,7 @@ int mariadb_fix_view(THD *thd, TABLE_LIST *view, bool wrong_checksum, { if (view->md5.length != VIEW_MD5_LEN) { - if ((view->md5.str= (char *)thd->alloc(VIEW_MD5_LEN + 1)) == NULL) + if ((view->md5.str= thd->alloc(VIEW_MD5_LEN + 1)) == NULL) DBUG_RETURN(HA_ADMIN_FAILED); } view->calc_md5(const_cast(view->md5.str)); @@ -1735,8 +1735,8 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, For suid views prepare a security context for checking underlying objects of the view. */ - if (!(table->view_sctx= (Security_context *) - thd->active_stmt_arena_to_use()->calloc(sizeof(Security_context)))) + if (!(table->view_sctx= + thd->active_stmt_arena_to_use()->calloc(1))) goto err; security_ctx= table->view_sctx; } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index fca67ee0d1a..2a38737b2f2 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -14273,8 +14273,7 @@ show_param: | GRANTS { Lex->sql_command= SQLCOM_SHOW_GRANTS; - if (unlikely(!(Lex->grant_user= - (LEX_USER*)thd->calloc(sizeof(LEX_USER))))) + if (unlikely(!(Lex->grant_user= thd->calloc(1)))) MYSQL_YYABORT; Lex->grant_user->user= current_user_and_current_role; } @@ -14394,8 +14393,7 @@ show_param: | CREATE USER_SYM { Lex->sql_command= SQLCOM_SHOW_CREATE_USER; - if (unlikely(!(Lex->grant_user= - (LEX_USER*)thd->calloc(sizeof(LEX_USER))))) + if (unlikely(!(Lex->grant_user= thd->calloc(1)))) MYSQL_YYABORT; Lex->grant_user->user= current_user; } @@ -15893,7 +15891,7 @@ ident_or_text: user_maybe_role: ident_or_text { - if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER))))) + if (unlikely(!($$= thd->calloc(1)))) MYSQL_YYABORT; $$->user = $1; @@ -15904,7 +15902,7 @@ user_maybe_role: } | ident_or_text '@' ident_or_text { - if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER))))) + if (unlikely(!($$= thd->calloc(1)))) MYSQL_YYABORT; $$->user = $1; $$->host=$3; @@ -15928,7 +15926,7 @@ user_maybe_role: } | CURRENT_USER optional_braces { - if (unlikely(!($$=(LEX_USER*)thd->calloc(sizeof(LEX_USER))))) + if (unlikely(!($$= thd->calloc(1)))) MYSQL_YYABORT; $$->user= current_user; $$->auth= new (thd->mem_root) USER_AUTH(); @@ -17158,7 +17156,7 @@ option_value_no_option_type: MYSQL_YYABORT; LEX *lex = Lex; LEX_USER *user; - if (unlikely(!(user=(LEX_USER *) thd->calloc(sizeof(LEX_USER))))) + if (unlikely(!(user= thd->calloc(1)))) MYSQL_YYABORT; user->user= current_user; set_var_default_role *var= (new (thd->mem_root) @@ -17649,7 +17647,7 @@ role_list: current_role: CURRENT_ROLE optional_braces { - if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER))))) + if (unlikely(!($$= thd->calloc(1)))) MYSQL_YYABORT; $$->user= current_role; } @@ -17664,7 +17662,7 @@ role_name: ident_or_text ((char*) $1.str)[$1.length] = '\0'; if (unlikely($1.length == 0)) my_yyabort_error((ER_INVALID_ROLE, MYF(0), "")); - if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER))))) + if (unlikely(!($$= thd->calloc(1)))) MYSQL_YYABORT; if (lex_string_eq(&$1, &none)) $$->user= none; @@ -17937,18 +17935,18 @@ auth_token: opt_auth_str: /* empty */ { - if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH)))) + if (!($$=thd->calloc(1))) MYSQL_YYABORT; } | using_or_as TEXT_STRING_sys { - if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH)))) + if (!($$=thd->calloc(1))) MYSQL_YYABORT; $$->auth_str= $2; } | using_or_as PASSWORD_SYM '(' TEXT_STRING ')' { - if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH)))) + if (!($$=thd->calloc(1))) MYSQL_YYABORT; $$->pwtext= $4; } @@ -18441,14 +18439,14 @@ xid: text_string { MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE); - if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID))))) + if (unlikely(!(Lex->xid= thd->alloc(1)))) MYSQL_YYABORT; Lex->xid->set(1L, $1->ptr(), $1->length(), 0, 0); } | text_string ',' text_string { MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE); - if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID))))) + if (unlikely(!(Lex->xid= thd->alloc(1)))) MYSQL_YYABORT; Lex->xid->set(1L, $1->ptr(), $1->length(), $3->ptr(), $3->length()); } @@ -18458,7 +18456,7 @@ xid: $3->length() <= MAXBQUALSIZE && $5 <= static_cast( std::numeric_limits::max())); - if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID))))) + if (unlikely(!(Lex->xid= thd->alloc(1)))) MYSQL_YYABORT; Lex->xid->set($5, $1->ptr(), $1->length(), $3->ptr(), $3->length()); } diff --git a/sql/sys_vars.inl b/sql/sys_vars.inl index 507cf7b5b24..71d55c0a558 100644 --- a/sql/sys_vars.inl +++ b/sql/sys_vars.inl @@ -2932,7 +2932,7 @@ private: break; case SYSTEM_TIME_AS_OF: { - char *buf= (char*) thd->alloc(MAX_DATE_STRING_REP_LENGTH); + char *buf= thd->alloc(MAX_DATE_STRING_REP_LENGTH); MYSQL_TIME ltime; thd->variables.time_zone->gmt_sec_to_TIME(<ime, val.unix_time); @@ -2993,7 +2993,7 @@ private: const Charset_collation_map_st &map) { size_t nbytes= map.text_format_nbytes_needed(); - char *buf= (char *) thd->alloc(nbytes + 1); + char *buf= thd->alloc(nbytes + 1); size_t length= map.print(buf, nbytes); buf[length]= '\0'; return (uchar *) buf; @@ -3003,8 +3003,7 @@ private: bool do_check(THD *thd, set_var *var) override { - Charset_collation_map_st *map= (Charset_collation_map_st*) - thd->alloc(sizeof(Charset_collation_map_st)); + Charset_collation_map_st *map= thd->alloc(1); if (!map || charset_collation_map_from_item(map, var->value, thd->get_utf8_flag())) return true; diff --git a/sql/table.cc b/sql/table.cc index 7ee6e031afd..17b577502f8 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -6122,10 +6122,7 @@ allocate: /* Create view fields translation table */ - if (!(transl= - (Field_translator*)(thd-> - alloc(select->item_list.elements * - sizeof(Field_translator))))) + if (!(transl= thd->alloc(select->item_list.elements))) { res= TRUE; goto exit; @@ -10186,7 +10183,7 @@ bool TABLE_LIST::change_refs_to_fields() if (!used_items.elements) return FALSE; - materialized_items= (Item **)thd->calloc(sizeof(void *) * table->s->fields); + materialized_items= thd->calloc(table->s->fields); ctx= new (thd->mem_root) Name_resolution_context(this); if (!materialized_items || !ctx) return TRUE; diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc index 8f5cd6921d4..711a7976224 100644 --- a/sql/thr_malloc.cc +++ b/sql/thr_malloc.cc @@ -76,7 +76,7 @@ char *sql_strmake_with_convert(THD *thd, const char *str, size_t arg_length, max_res_length--; // Reserve place for end null set_if_smaller(new_length, max_res_length); - if (!(pos= (char*) thd->alloc(new_length + 1))) + if (!(pos= thd->alloc(new_length + 1))) return pos; // Error if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin)) diff --git a/sql/unireg.cc b/sql/unireg.cc index 185f1df4f54..f70f62b18e6 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -374,7 +374,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table, if (!create_info->tabledef_version.str) { - uchar *to= (uchar*) thd->alloc(MY_UUID_SIZE); + uchar *to= thd->alloc(MY_UUID_SIZE); if (unlikely(!to)) DBUG_RETURN(frm); my_uuid(to); @@ -911,12 +911,10 @@ static bool pack_header(THD *thd, uchar *forminfo, */ uint count= field->typelib()->count; field->save_interval= field->typelib(); - field->set_typelib(tmpint= (TYPELIB*) thd->alloc(sizeof(TYPELIB))); + field->set_typelib(tmpint= thd->alloc(1)); *tmpint= *field->save_interval; - tmpint->type_names= - (const char **) thd->alloc(sizeof(char*) * - (count + 1)); - tmpint->type_lengths= (uint *) thd->alloc(sizeof(uint) * (count + 1)); + tmpint->type_names= thd->alloc(count + 1); + tmpint->type_lengths= thd->alloc(count + 1); tmpint->type_names[count]= 0; tmpint->type_lengths[count]= 0; @@ -928,7 +926,7 @@ static bool pack_header(THD *thd, uchar *forminfo, length= field->save_interval->type_lengths[pos]; hex_length= length * 2; tmpint->type_lengths[pos]= (uint) hex_length; - tmpint->type_names[pos]= dst= (char*) thd->alloc(hex_length + 1); + tmpint->type_names[pos]= dst= thd->alloc(hex_length + 1); octet2hex(dst, (uchar*)src, length); } } diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index b135c5a83ad..c85f1450b0b 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -1239,7 +1239,7 @@ int ha_maria::write_row(const uchar * buf) int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) { int error, fatal_error; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); MARIA_SHARE *share= file->s; const char *old_proc_info; TRN *old_trn= file->trn; @@ -1393,7 +1393,7 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) int ha_maria::analyze(THD *thd, HA_CHECK_OPT * check_opt) { int error= 0; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); MARIA_SHARE *share= file->s; const char *old_proc_info; @@ -1432,7 +1432,7 @@ int ha_maria::analyze(THD *thd, HA_CHECK_OPT * check_opt) int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt) { int error; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); ha_rows start_records; const char *old_proc_info; @@ -1519,7 +1519,7 @@ int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt) int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt) { int error; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); TRN *old_trn; MARIA_SHARE *share= file->s; @@ -1558,7 +1558,7 @@ int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt) int ha_maria::optimize(THD * thd, HA_CHECK_OPT *check_opt) { int error; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); if (!file || !param) return HA_ADMIN_INTERNAL_ERROR; @@ -1921,7 +1921,7 @@ int ha_maria::preload_keys(THD * thd, HA_CHECK_OPT *check_opt) errmsg= buf; } - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); if (!param) return HA_ADMIN_INTERNAL_ERROR; @@ -2032,7 +2032,7 @@ int ha_maria::enable_indexes(key_map map, bool persist) else { THD *thd= table->in_use; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); if (!param) return HA_ADMIN_INTERNAL_ERROR; diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index cd5457c3c36..98d729cc9be 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -997,7 +997,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) { if (!file) return HA_ADMIN_INTERNAL_ERROR; int error; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); MYISAM_SHARE* share = file->s; const char *old_proc_info=thd->proc_info; @@ -1103,7 +1103,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) { int error=0; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); MYISAM_SHARE* share = file->s; if (!param) @@ -1141,7 +1141,7 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) { int error; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); ha_rows start_records; if (!file || !param) return HA_ADMIN_INTERNAL_ERROR; @@ -1198,7 +1198,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) int ha_myisam::optimize(THD* thd, HA_CHECK_OPT *check_opt) { int error; - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); if (!file || !param) return HA_ADMIN_INTERNAL_ERROR; @@ -1461,7 +1461,7 @@ int ha_myisam::assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt) if (error != HA_ADMIN_OK) { /* Send error to user */ - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); if (!param) return HA_ADMIN_INTERNAL_ERROR; @@ -1528,7 +1528,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt) err: { - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); if (!param) return HA_ADMIN_INTERNAL_ERROR; myisamchk_init(param); @@ -1633,7 +1633,7 @@ int ha_myisam::enable_indexes(key_map map, bool persist) { THD *thd= table->in_use; int was_error= thd->is_error(); - HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); + HA_CHECK *param= thd->alloc(1); const char *save_proc_info=thd->proc_info; if (!param) diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 4bc30f815ea..3b3850ea77e 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -462,7 +462,7 @@ int ha_myisammrg::add_children_list(void) LEX_CSTRING db; LEX_CSTRING table_name; - child_l= (TABLE_LIST*) thd->alloc(sizeof(TABLE_LIST)); + child_l= thd->alloc(1); db.str= (char*) thd->memdup(mrg_child_def->db.str, mrg_child_def->db.length+1); db.length= mrg_child_def->db.length; table_name.str= (char*) thd->memdup(mrg_child_def->name.str, @@ -1456,7 +1456,7 @@ void ha_myisammrg::update_create_info(HA_CREATE_INFO *create_info) { TABLE_LIST *ptr; - if (!(ptr= (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST)))) + if (!(ptr= thd->calloc(1))) DBUG_VOID_RETURN; if (!(ptr->table_name.str= thd->strmake(child_table->table_name.str, @@ -1501,7 +1501,7 @@ int ha_myisammrg::create_mrg(const char *name, HA_CREATE_INFO *create_info) ntables++; /* Allocate a table_names array in thread mem_root. */ - if (!(pos= table_names= (const char**) thd->alloc((ntables + 1) * sizeof(char*)))) + if (!(pos= table_names= thd->alloc(ntables + 1))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); /* purecov: inspected */ /* Create child path names. */ diff --git a/storage/perfschema/table_global_status.cc b/storage/perfschema/table_global_status.cc index 08531b555f7..796126478e0 100644 --- a/storage/perfschema/table_global_status.cc +++ b/storage/perfschema/table_global_status.cc @@ -109,8 +109,8 @@ int table_global_status::rnd_init(bool scan) If scan == true, then allocate a new context from mem_root and store in TLS. If scan == false, then restore from TLS. */ - m_context= (table_global_status_context *)current_thd->alloc(sizeof(table_global_status_context)); - new(m_context) table_global_status_context(status_version, !scan); + m_context= current_thd->alloc(1); + new (m_context) table_global_status_context(status_version, !scan); return 0; } diff --git a/storage/perfschema/table_host_cache.cc b/storage/perfschema/table_host_cache.cc index 03bfc151e37..b987de23805 100644 --- a/storage/perfschema/table_host_cache.cc +++ b/storage/perfschema/table_host_cache.cc @@ -146,7 +146,7 @@ void table_host_cache::materialize(THD *thd) goto end; } - rows= (row_host_cache*) thd->alloc(size * sizeof(row_host_cache)); + rows= thd->alloc(size); if (rows == NULL) { /* Out of memory, this thread will error out. */ diff --git a/storage/perfschema/table_session_status.cc b/storage/perfschema/table_session_status.cc index 3baad528f66..8cdaae4426f 100644 --- a/storage/perfschema/table_session_status.cc +++ b/storage/perfschema/table_session_status.cc @@ -97,8 +97,8 @@ int table_session_status::rnd_init(bool scan) If scan == true, then allocate a new context from mem_root and store in TLS. If scan == false, then restore from TLS. */ - m_context= (table_session_status_context *)current_thd->alloc(sizeof(table_session_status_context)); - new(m_context) table_session_status_context(status_version, !scan); + m_context= current_thd->alloc(1); + new (m_context) table_session_status_context(status_version, !scan); return 0; } diff --git a/storage/perfschema/table_status_by_account.cc b/storage/perfschema/table_status_by_account.cc index 55a6fc10158..1f607a182a9 100644 --- a/storage/perfschema/table_status_by_account.cc +++ b/storage/perfschema/table_status_by_account.cc @@ -116,8 +116,8 @@ int table_status_by_account::rnd_init(bool scan) allocate a new context from mem_root and store in TLS. If scan == false, then restore from TLS. */ - m_context= (table_status_by_account_context *)current_thd->alloc(sizeof(table_status_by_account_context)); - new(m_context) table_status_by_account_context(status_version, !scan); + m_context= current_thd->alloc(1); + new (m_context) table_status_by_account_context(status_version, !scan); return 0; } diff --git a/storage/perfschema/table_status_by_host.cc b/storage/perfschema/table_status_by_host.cc index 52d723dca4e..d34c45fc523 100644 --- a/storage/perfschema/table_status_by_host.cc +++ b/storage/perfschema/table_status_by_host.cc @@ -116,8 +116,8 @@ int table_status_by_host::rnd_init(bool scan) allocate a new context from mem_root and store in TLS. If scan == false, then restore from TLS. */ - m_context= (table_status_by_host_context *)current_thd->alloc(sizeof(table_status_by_host_context)); - new(m_context) table_status_by_host_context(status_version, !scan); + m_context= current_thd->alloc(1); + new (m_context) table_status_by_host_context(status_version, !scan); return 0; } diff --git a/storage/perfschema/table_status_by_thread.cc b/storage/perfschema/table_status_by_thread.cc index ea1218a04ec..a9e70c51343 100644 --- a/storage/perfschema/table_status_by_thread.cc +++ b/storage/perfschema/table_status_by_thread.cc @@ -116,8 +116,8 @@ int table_status_by_thread::rnd_init(bool scan) allocate a new context from mem_root and store in TLS. If scan == false, then restore from TLS. */ - m_context= (table_status_by_thread_context *)current_thd->alloc(sizeof(table_status_by_thread_context)); - new(m_context) table_status_by_thread_context(status_version, !scan); + m_context= current_thd->alloc(1); + new (m_context) table_status_by_thread_context(status_version, !scan); return 0; } diff --git a/storage/perfschema/table_status_by_user.cc b/storage/perfschema/table_status_by_user.cc index dcafa3a8b76..9699dfb3a1a 100644 --- a/storage/perfschema/table_status_by_user.cc +++ b/storage/perfschema/table_status_by_user.cc @@ -117,8 +117,8 @@ int table_status_by_user::rnd_init(bool scan) allocate a new context from mem_root and store in TLS. If scan == false, then restore from TLS. */ - m_context= (table_status_by_user_context *)current_thd->alloc(sizeof(table_status_by_user_context)); - new(m_context) table_status_by_user_context(status_version, !scan); + m_context= current_thd->alloc(1); + new (m_context) table_status_by_user_context(status_version, !scan); return 0; } diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 6726f55d1df..cca98023d30 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -6431,8 +6431,7 @@ int spider_db_mbase_util::append_join(spider_fields *fields, } ti.rewind(); - if (!(table= static_cast(thd->alloc(sizeof(TABLE_LIST*) * - tables_to_print)))) + if (!(table= thd->alloc(tables_to_print))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); TABLE_LIST *tmp, **t= table + (tables_to_print - 1);