cleanup: thd->alloc<>() and thd->calloc<>()

create templates

  thd->alloc<X>(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.
This commit is contained in:
Sergei Golubchik 2024-06-01 16:15:53 +02:00
parent eff16d7593
commit 44c6328cbb
63 changed files with 262 additions and 362 deletions

View File

@ -1283,7 +1283,7 @@ Event_job_data::construct_sp_sql(THD *thd, String *sp_sql)
root to avoid multiple [re]allocations on system heap root to avoid multiple [re]allocations on system heap
*/ */
buffer.length= STATIC_SQL_LENGTH + name.length + body.length; 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); DBUG_RETURN(TRUE);
sp_sql->set(buffer.str, buffer.length, system_charset_info); 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"); DBUG_ENTER("Event_job_data::construct_drop_event_sql");
buffer.length= STATIC_SQL_LENGTH + name.length*2 + dbname.length*2; 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); DBUG_RETURN(TRUE);
sp_sql->set(buffer.str, buffer.length, system_charset_info); sp_sql->set(buffer.str, buffer.length, system_charset_info);

View File

@ -544,7 +544,7 @@ Event_parse_data::init_definer(THD *thd)
/* + 1 for @ */ /* + 1 for @ */
DBUG_PRINT("info",("init definer as whole")); DBUG_PRINT("info",("init definer as whole"));
definer.length= definer_user_len + definer_host_len + 1; 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")); DBUG_PRINT("info",("copy the user"));
strmake(tmp, definer_user, definer_user_len); strmake(tmp, definer_user, definer_user_len);

View File

@ -642,7 +642,7 @@ Filesort::make_sortorder(THD *thd, JOIN *join, table_map first_table_bit)
DBUG_ASSERT(sort_keys == NULL); DBUG_ASSERT(sort_keys == NULL);
sortorder= (SORT_FIELD*) thd->alloc(sizeof(SORT_FIELD) * count); sortorder= thd->alloc<SORT_FIELD>(count);
pos= sort= sortorder; pos= sort= sortorder;
if (!pos) if (!pos)

View File

@ -1906,8 +1906,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
} while (++i < num_parts); } while (++i < num_parts);
} }
if (m_reorged_parts && if (m_reorged_parts &&
!(m_reorged_file= (handler**) thd->calloc(sizeof(handler*)* !(m_reorged_file= thd->calloc<handler*>(m_reorged_parts + 1)))
(m_reorged_parts + 1))))
{ {
DBUG_RETURN(HA_ERR_OUT_OF_MEM); 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); } while (++i < num_parts);
} }
if (!(new_file_array= ((handler**) if (!(new_file_array= thd->calloc<handler*>(2*(num_remain_partitions + 1))))
thd->calloc(sizeof(handler*)*
(2*(num_remain_partitions + 1))))))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
m_added_file= &new_file_array[num_remain_partitions + 1]; 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) if (!part_inplace_ctx)
DBUG_RETURN(HA_ALTER_ERROR); DBUG_RETURN(HA_ALTER_ERROR);
part_inplace_ctx->handler_ctx_array= (inplace_alter_handler_ctx **) part_inplace_ctx->handler_ctx_array=
thd->alloc(sizeof(inplace_alter_handler_ctx *) * (m_tot_parts + 1)); thd->alloc<inplace_alter_handler_ctx *>(m_tot_parts + 1);
if (!part_inplace_ctx->handler_ctx_array) if (!part_inplace_ctx->handler_ctx_array)
DBUG_RETURN(HA_ALTER_ERROR); DBUG_RETURN(HA_ALTER_ERROR);

View File

@ -1184,7 +1184,7 @@ make_name(THD *thd,
uint errors; uint errors;
size_t dst_nbytes= length * system_charset_info->mbmaxlen; size_t dst_nbytes= length * system_charset_info->mbmaxlen;
set_if_smaller(dst_nbytes, max_octet_length); 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) if (!dst)
return Lex_ident_column(); return Lex_ident_column();
uint32 cnv_length= my_convert_using_func(dst, dst_nbytes, system_charset_info, 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, bool mark_unsupported_function(const char *w1, const char *w2,
void *store, uint result) 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) if (ptr)
strxmov(ptr, w1, w2, NullS); strxmov(ptr, w1, w2, NullS);
return mark_unsupported_function(ptr, store, result); 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]) if (db_name.str && db_name.str[0])
{ {
THD *thd= current_thd; tmp= current_thd->alloc((uint) db_name.length+ (uint) table_name.length +
tmp=(char*) thd->alloc((uint) db_name.length+ (uint) table_name.length + (uint) field_name.length+3);
(uint) field_name.length+3);
length= (strxmov(tmp,db_name.str,".",table_name.str,".",field_name.str, length= (strxmov(tmp,db_name.str,".",table_name.str,".",field_name.str,
NullS) - tmp); NullS) - tmp);
} }
@ -3363,9 +3362,7 @@ LEX_CSTRING Item_ident::full_name_cstring() const
if (!table_name.str[0]) if (!table_name.str[0])
return field_name; return field_name;
THD *thd= current_thd; tmp= current_thd->alloc((uint) table_name.length + field_name.length + 2);
tmp= (char*) thd->alloc((uint) table_name.length +
field_name.length + 2);
length= (strxmov(tmp, table_name.str, ".", field_name.str, NullS) - tmp); length= (strxmov(tmp, table_name.str, ".", field_name.str, NullS) - tmp);
} }
return {tmp, length}; return {tmp, length};
@ -5222,7 +5219,7 @@ static Field *make_default_field(THD *thd, Field *field_arg)
if (def_field->default_value && if (def_field->default_value &&
(def_field->default_value->flags || (def_field->flags & BLOB_FLAG))) (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) if (!newptr)
return nullptr; return nullptr;
@ -7265,7 +7262,7 @@ Item *Item_float::neg(THD *thd)
else else
{ {
size_t presentation_length= strlen(presentation); 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]= '-'; tmp[0]= '-';
// Copy with the trailing '\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) void Item_hex_constant::hex_string_init(THD *thd, const char *str, size_t str_length)
{ {
max_length=(uint)((str_length+1)/2); max_length=(uint)((str_length+1)/2);
char *ptr=(char*) thd->alloc(max_length+1); char *ptr= thd->alloc(max_length+1);
if (!ptr) if (!ptr)
{ {
str_value.set("", 0, &my_charset_bin); 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; uint power= 1;
max_length= (uint)((str_length + 7) >> 3); max_length= (uint)((str_length + 7) >> 3);
if (!(ptr= (char*) thd->alloc(max_length + 1))) if (!(ptr= thd->alloc(max_length + 1)))
return; return;
str_value.set(ptr, max_length, &my_charset_bin); 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) bool Item_cache_row::allocate(THD *thd, uint num)
{ {
item_count= num; item_count= num;
return (!values && return (!values && !(values= thd->calloc<Item_cache *>(item_count)));
!(values=
(Item_cache **) thd->calloc(sizeof(Item_cache *)*item_count)));
} }

View File

@ -2020,8 +2020,7 @@ bool Item_func_interval::fix_length_and_dec(THD *thd)
if (not_null_consts) if (not_null_consts)
{ {
intervals= (interval_range*) current_thd->alloc(sizeof(interval_range) * intervals= current_thd->alloc<interval_range>(rows - 1);
(rows - 1));
if (!intervals) if (!intervals)
return TRUE; return TRUE;
@ -4072,11 +4071,8 @@ Item *in_decimal::create_item(THD *thd)
bool Predicant_to_list_comparator::alloc_comparators(THD *thd, uint nargs) bool Predicant_to_list_comparator::alloc_comparators(THD *thd, uint nargs)
{ {
size_t nbytes= sizeof(Predicant_to_value_comparator) * nargs; m_comparators= thd->calloc<Predicant_to_value_comparator>(nargs);
if (!(m_comparators= (Predicant_to_value_comparator *) thd->alloc(nbytes))) return m_comparators == NULL;
return true;
memset(m_comparators, 0, nbytes);
return false;
} }
@ -4207,8 +4203,7 @@ bool cmp_item_row::alloc_comparators(THD *thd, uint cols)
DBUG_ASSERT(cols == n); DBUG_ASSERT(cols == n);
return false; return false;
} }
return return !(comparators= thd->calloc<cmp_item *>(n= cols));
!(comparators= (cmp_item **) thd->calloc(sizeof(cmp_item *) * (n= cols)));
} }
@ -4239,7 +4234,7 @@ bool cmp_item_row::store_value_by_template(THD *thd, cmp_item *t, Item *item)
} }
n= tmpl->n; n= tmpl->n;
bool rc= false; bool rc= false;
if ((comparators= (cmp_item **) thd->alloc(sizeof(cmp_item *)*n))) if ((comparators= thd->alloc<cmp_item *>(n)))
{ {
item->bring_value(); item->bring_value();
item->null_value= 0; item->null_value= 0;
@ -6076,9 +6071,7 @@ bool Item_func_like::fix_fields(THD *thd, Item **ref)
pattern_len = (int) len - 2; pattern_len = (int) len - 2;
pattern = thd->strmake(first + 1, pattern_len); pattern = thd->strmake(first + 1, pattern_len);
DBUG_PRINT("info", ("Initializing pattern: '%s'", first)); DBUG_PRINT("info", ("Initializing pattern: '%s'", first));
int *suff = (int*) thd->alloc((int) (sizeof(int)* int *suff = thd->alloc<int>((pattern_len + 1) * 2 + alphabet_size);
((pattern_len + 1)*2+
alphabet_size)));
bmGs = suff + pattern_len + 1; bmGs = suff + pattern_len + 1;
bmBc = bmGs + pattern_len + 1; bmBc = bmGs + pattern_len + 1;
turboBM_compute_good_suffix_shifts(suff); 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; THD *thd= data->table->in_use;
COND_STATISTIC *stat; COND_STATISTIC *stat;
Item *arg0; Item *arg0;
if (!(stat= (COND_STATISTIC *) thd->alloc(sizeof(COND_STATISTIC)))) if (!(stat= thd->alloc<COND_STATISTIC>(1)))
return TRUE; return TRUE;
stat->cond= this; stat->cond= this;
arg0= args[0]->real_item(); 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 strlen= nm->length() * DYNCOL_UTF->mbmaxlen + 1;
uint dummy_errors; uint dummy_errors;
buf.str= (char *) current_thd->alloc(strlen); buf.str= current_thd->alloc(strlen);
if (buf.str) if (buf.str)
{ {
buf.length= buf.length=

View File

@ -93,7 +93,7 @@ bool Item_args::alloc_arguments(THD *thd, uint count)
args= tmp_arg; args= tmp_arg;
return false; return false;
} }
if ((args= (Item**) thd->alloc(sizeof(Item*) * count)) == NULL) if ((args= thd->alloc<Item*>(count)) == NULL)
{ {
arg_count= 0; arg_count= 0;
return true; return true;
@ -120,7 +120,7 @@ Item_args::Item_args(THD *thd, const Item_args *other)
{ {
args= tmp_arg; args= tmp_arg;
} }
else if (!(args= (Item**) thd->alloc(sizeof(Item*) * arg_count))) else if (!(args= thd->alloc<Item*>(arg_count)))
{ {
arg_count= 0; arg_count= 0;
return; return;
@ -2831,8 +2831,8 @@ bool Item_func_rand::fix_fields(THD *thd,Item **ref)
Query_arena::STMT_SP_QUERY_ARGUMENTS Query_arena::STMT_SP_QUERY_ARGUMENTS
) )
) || rand); ) || rand);
if (!rand && !(rand= (struct my_rnd_struct*) if (!rand &&
thd->active_stmt_arena_to_use()->alloc(sizeof(*rand)))) !(rand= thd->active_stmt_arena_to_use()->alloc<my_rnd_struct>(1)))
return TRUE; return TRUE;
} }
else 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_count=arg_count))
{ {
if (!(f_args.arg_type= (Item_result*) if (!(f_args.arg_type= thd->alloc<Item_result>(f_args.arg_count)))
thd->alloc(f_args.arg_count*sizeof(Item_result))))
{ {
err_exit: err_exit:

View File

@ -2653,9 +2653,8 @@ String *Item_func_password::val_str_ascii(String *str)
char *Item_func_password::alloc(THD *thd, const char *password, char *Item_func_password::alloc(THD *thd, const char *password,
size_t pass_len, enum PW_Alg al) size_t pass_len, enum PW_Alg al)
{ {
char *buff= (char *) thd->alloc((al==NEW)? char *buff= thd->alloc(al==NEW ? SCRAMBLED_PASSWORD_CHAR_LENGTH + 1
SCRAMBLED_PASSWORD_CHAR_LENGTH + 1: : SCRAMBLED_PASSWORD_CHAR_LENGTH_323 + 1);
SCRAMBLED_PASSWORD_CHAR_LENGTH_323 + 1);
if (!buff) if (!buff)
return NULL; 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 strlen= res->length() * DYNCOL_UTF->mbmaxlen + 1;
uint dummy_errors; uint dummy_errors;
if (char *str= (char *) thd->alloc(strlen)) if (char *str= thd->alloc(strlen))
{ {
keys_str[i].length= keys_str[i].length=
copy_and_convert(str, strlen, DYNCOL_UTF, 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 strlen= nm->length() * DYNCOL_UTF->mbmaxlen + 1;
uint dummy_errors; uint dummy_errors;
buf.str= (char *) thd->alloc(strlen); buf.str= thd->alloc(strlen);
if (buf.str) if (buf.str)
{ {
buf.length= buf.length=

View File

@ -1313,8 +1313,7 @@ bool Item_singlerow_subselect::fix_length_and_dec()
} }
else else
{ {
if (!(row= (Item_cache**) current_thd->alloc(sizeof(Item_cache*) * if (!(row= current_thd->alloc<Item_cache*>(max_columns)) ||
max_columns)) ||
engine->fix_length_and_dec(row)) engine->fix_length_and_dec(row))
return TRUE; return TRUE;
value= *row; value= *row;
@ -3741,7 +3740,7 @@ bool Item_in_subselect::init_cond_guards()
if (!is_top_level_item() && !pushed_cond_guards && if (!is_top_level_item() && !pushed_cond_guards &&
(left_expr->maybe_null() || cols_num > 1)) (left_expr->maybe_null() || cols_num > 1))
{ {
if (!(pushed_cond_guards= (bool*)thd->alloc(sizeof(bool) * cols_num))) if (!(pushed_cond_guards= thd->alloc<bool>(cols_num)))
return TRUE; return TRUE;
for (uint i= 0; i < cols_num; i++) for (uint i= 0; i < cols_num; i++)
pushed_cond_guards[i]= TRUE; 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))) if (!(semi_join_conds= new (thd->mem_root) Item_cond_and(thd)))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
if (!(tmp_table_ref= (TABLE_LIST*) thd->alloc(sizeof(TABLE_LIST)))) if (!(tmp_table_ref= thd->alloc<TABLE_LIST>(1)))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
table_name.str= tmp_table->alias.c_ptr(); 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 - here we initialize only those members that are used by
subselect_uniquesubquery_engine, so these objects are incomplete. subselect_uniquesubquery_engine, so these objects are incomplete.
*/ */
if (!(tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)))) if (!(tab= thd->alloc<JOIN_TAB>(1)))
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
tab->table= tmp_table; tab->table= tmp_table;
@ -6024,10 +6023,8 @@ bool Ordered_key::init(MY_BITMAP *columns_to_index)
Item_func_lt *fn_less_than; Item_func_lt *fn_less_than;
key_column_count= bitmap_bits_set(columns_to_index); key_column_count= bitmap_bits_set(columns_to_index);
key_columns= (Item_field**) thd->alloc(key_column_count * key_columns= thd->alloc<Item_field*>(key_column_count);
sizeof(Item_field*)); compare_pred= thd->alloc<Item_func_lt*>(key_column_count);
compare_pred= (Item_func_lt**) thd->alloc(key_column_count *
sizeof(Item_func_lt*));
if (!key_columns || !compare_pred) if (!key_columns || !compare_pred)
return TRUE; /* Revert to table scan partial match. */ 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 // TIMOUR: check for mem allocation err, revert to scan
key_columns= (Item_field**) thd->alloc(sizeof(Item_field*)); key_columns= thd->alloc<Item_field*>(1);
compare_pred= (Item_func_lt**) thd->alloc(sizeof(Item_func_lt*)); compare_pred= thd->alloc<Item_func_lt*>(1);
key_columns[0]= new (thd->mem_root) Item_field(thd, tbl->field[col_idx]); key_columns[0]= new (thd->mem_root) Item_field(thd, tbl->field[col_idx]);
/* Create the predicate (tmp_column[i] < outer_ref[i]). */ /* 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 row numbers. All small buffers are allocated in the runtime memroot. Big
buffers are allocated from the OS via malloc. buffers are allocated from the OS via malloc.
*/ */
if (!(merge_keys= (Ordered_key**) thd->alloc(merge_keys_count * if (!(merge_keys= thd->alloc<Ordered_key*>(merge_keys_count)) ||
sizeof(Ordered_key*))) || !(null_bitmaps= thd->alloc<MY_BITMAP*>(merge_keys_count)) ||
!(null_bitmaps= (MY_BITMAP**) thd->alloc(merge_keys_count *
sizeof(MY_BITMAP*))) ||
!(row_num_to_rowid= (uchar*) my_malloc(PSI_INSTRUMENT_ME, !(row_num_to_rowid= (uchar*) my_malloc(PSI_INSTRUMENT_ME,
static_cast<size_t>(row_count * rowid_length), static_cast<size_t>(row_count * rowid_length),
MYF(MY_WME | MY_THREAD_SPECIFIC)))) MYF(MY_WME | MY_THREAD_SPECIFIC))))

View File

@ -463,10 +463,8 @@ bool Item_sum::collect_outer_ref_processor(void *param)
Item_sum::Item_sum(THD *thd, List<Item> &list): Item_func_or_sum(thd, list) Item_sum::Item_sum(THD *thd, List<Item> &list): Item_func_or_sum(thd, list)
{ {
if (!(orig_args= (Item **) thd->alloc(sizeof(Item *) * arg_count))) if (!(orig_args= thd->alloc<Item *>(arg_count)))
{
args= NULL; args= NULL;
}
mark_as_sum_func(); mark_as_sum_func();
init_aggregator(); init_aggregator();
list.empty(); // Fields are used list.empty(); // Fields are used
@ -490,7 +488,7 @@ Item_sum::Item_sum(THD *thd, Item_sum *item):
} }
else else
{ {
if (!(orig_args= (Item**) thd->alloc(sizeof(Item*)*arg_count))) if (!(orig_args= thd->alloc<Item*>(arg_count)))
return; return;
} }
if (arg_count) if (arg_count)
@ -872,7 +870,7 @@ bool Aggregator_distinct::setup(THD *thd)
uint32 *length; uint32 *length;
compare_key= (qsort_cmp2) composite_key_cmp; compare_key= (qsort_cmp2) composite_key_cmp;
cmp_arg= (void*) this; cmp_arg= (void*) this;
field_lengths= (uint32*) thd->alloc(table->s->fields * sizeof(uint32)); field_lengths= thd->alloc<uint32>(table->s->fields);
for (tree_key_length= 0, length= field_lengths, field= table->field; for (tree_key_length= 0, length= field_lengths, field= table->field;
field < field_end; ++field, ++length) field < field_end; ++field, ++length)
{ {
@ -4309,7 +4307,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref)
is_conventional() || is_conventional() ||
thd->active_stmt_arena_to_use()->state == thd->active_stmt_arena_to_use()->state ==
Query_arena::STMT_SP_QUERY_ARGUMENTS); 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) !(new_separator= new(thd->active_stmt_arena_to_use()->mem_root)
String(buf, buflen, collation.collation))) String(buf, buflen, collation.collation)))
return TRUE; return TRUE;
@ -4370,7 +4368,7 @@ bool Item_func_group_concat::setup(THD *thd)
if (arg_count_order) if (arg_count_order)
{ {
uint n_elems= arg_count_order + all_fields.elements; uint n_elems= arg_count_order + all_fields.elements;
ref_pointer_array= static_cast<Item**>(thd->alloc(sizeof(Item*) * n_elems)); ref_pointer_array= thd->alloc<Item*>(n_elems);
if (!ref_pointer_array) if (!ref_pointer_array)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
memcpy(ref_pointer_array, args, arg_count * sizeof(Item*)); memcpy(ref_pointer_array, args, arg_count * sizeof(Item*));

View File

@ -3518,8 +3518,7 @@ Table_map_log_event::Table_map_log_event(const uchar *buf, uint event_len,
#ifdef MYSQL_SERVER #ifdef MYSQL_SERVER
if (!m_table) if (!m_table)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
binlog_type_info_array= (Binlog_type_info *)thd->alloc(m_table->s->fields * binlog_type_info_array= thd->alloc<Binlog_type_info>(m_table->s->fields);
sizeof(Binlog_type_info));
for (uint i= 0; i < m_table->s->fields; i++) for (uint i= 0; i < m_table->s->fields; i++)
binlog_type_info_array[i]= m_table->field[i]->binlog_type_info(); binlog_type_info_array[i]= m_table->field[i]->binlog_type_info();
#endif #endif

View File

@ -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)); (tbl->s->db.str[tbl->s->db.length] == 0));
DBUG_ASSERT(tbl->s->table_name.str[tbl->s->table_name.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 * binlog_type_info_array= thd->alloc<Binlog_type_info>(m_table->s->fields);
sizeof(Binlog_type_info));
for (uint i= 0; i < m_table->s->fields; i++) for (uint i= 0; i < m_table->s->fields; i++)
binlog_type_info_array[i]= m_table->field[i]->binlog_type_info(); binlog_type_info_array[i]= m_table->field[i]->binlog_type_info();

View File

@ -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); thd->set_killed_no_mutex(KILL_QUERY);
my_snprintf(buf, sizeof(buf), "--max-session-mem-used=%llu", my_snprintf(buf, sizeof(buf), "--max-session-mem-used=%llu",
thd->variables.max_mem_used); thd->variables.max_mem_used);
if ((buf2= (char*) thd->alloc(256))) if ((buf2= thd->alloc(256)))
{ {
my_snprintf(buf2, 256, my_snprintf(buf2, 256,
ER_THD(thd, ER_OPTION_PREVENTS_STATEMENT), buf); ER_THD(thd, ER_OPTION_PREVENTS_STATEMENT), buf);

View File

@ -1298,7 +1298,7 @@ QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint key_nr,
record= head->record[0]; record= head->record[0];
my_init_dynamic_array2(PSI_INSTRUMENT_ME, &ranges, sizeof(QUICK_RANGE*), my_init_dynamic_array2(PSI_INSTRUMENT_ME, &ranges, sizeof(QUICK_RANGE*),
thd->alloc(sizeof(QUICK_RANGE*) * 16), 16, 16, thd->alloc<QUICK_RANGE>(16), 16, 16,
MYF(MY_THREAD_SPECIFIC)); MYF(MY_THREAD_SPECIFIC));
/* Allocate a bitmap for used columns */ /* Allocate a bitmap for used columns */

View File

@ -510,9 +510,7 @@ bool JOIN::check_for_splittable_materialized()
the collected info on potential splittability of T the collected info on potential splittability of T
*/ */
SplM_opt_info *spl_opt_info= new (thd->mem_root) SplM_opt_info(); SplM_opt_info *spl_opt_info= new (thd->mem_root) SplM_opt_info();
SplM_field_info *spl_field= SplM_field_info *spl_field= thd->calloc<SplM_field_info>(spl_field_cnt);
(SplM_field_info *) (thd->calloc(sizeof(SplM_field_info) *
spl_field_cnt));
if (!(spl_opt_info && spl_field)) // consider T as not good for splitting if (!(spl_opt_info && spl_field)) // consider T as not good for splitting
return false; return false;
@ -615,8 +613,7 @@ void TABLE::add_splitting_info_for_key_field(KEY_FIELD *key_field)
} }
if (!eq_item) if (!eq_item)
return; return;
KEY_FIELD *added_key_field= KEY_FIELD *added_key_field= thd->alloc<KEY_FIELD>(1);
(KEY_FIELD *) thd->alloc(sizeof(KEY_FIELD));
if (!added_key_field || if (!added_key_field ||
spl_opt_info->added_key_fields.push_back(added_key_field,thd->mem_root)) spl_opt_info->added_key_fields.push_back(added_key_field,thd->mem_root))
return; return;
@ -1106,9 +1103,8 @@ SplM_plan_info * JOIN_TAB::choose_best_splitting(uint idx,
key_map spl_keys= table->keys_usable_for_splitting; key_map spl_keys= table->keys_usable_for_splitting;
if (!(first_non_const_pos->key && if (!(first_non_const_pos->key &&
spl_keys.is_set(first_non_const_pos->key->key)) || spl_keys.is_set(first_non_const_pos->key->key)) ||
!(spl_plan= (SplM_plan_info *) thd->alloc(sizeof(SplM_plan_info))) || !(spl_plan= thd->alloc<SplM_plan_info>(1)) ||
!(spl_plan->best_positions= !(spl_plan->best_positions= thd->alloc<POSITION>(join->table_count)) ||
(POSITION *) thd->alloc(sizeof(POSITION) * join->table_count)) ||
spl_opt_info->plan_cache.push_back(spl_plan)) spl_opt_info->plan_cache.push_back(spl_plan))
{ {
reset_validity_vars_for_keyuses(best_key_keyuse_ext_start, best_table, reset_validity_vars_for_keyuses(best_key_keyuse_ext_start, best_table,

View File

@ -2153,7 +2153,7 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
*remove_item= TRUE; *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! !(jtbm= alloc_join_nest(thd))) //todo: this is not a join nest!
{ {
DBUG_RETURN(TRUE); 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); uint n_tables= my_count_bits(sj_nest->sj_inner_tables & ~join->const_table_map);
SJ_MATERIALIZATION_INFO* sjm; SJ_MATERIALIZATION_INFO* sjm;
if (!(sjm= new SJ_MATERIALIZATION_INFO) || if (!(sjm= new SJ_MATERIALIZATION_INFO) ||
!(sjm->positions= (POSITION*)join->thd->alloc(sizeof(POSITION)* !(sjm->positions= join->thd->alloc<POSITION>(n_tables)))
n_tables)))
DBUG_RETURN(TRUE); /* purecov: inspected */ DBUG_RETURN(TRUE); /* purecov: inspected */
sjm->tables= n_tables; sjm->tables= n_tables;
sjm->is_used= FALSE; 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= 0; /* The only temp table index. */
tab_ref->key_length= tmp_key->key_length; tab_ref->key_length= tmp_key->key_length;
if (!(tab_ref->key_buff= if (!(tab_ref->key_buff=
(uchar*) thd->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) || thd->calloc<uchar>(ALIGN_SIZE(tmp_key->key_length) * 2)) ||
!(tab_ref->key_copy= !(tab_ref->key_copy= thd->alloc<store_key*>(tmp_key_parts + 1)) ||
(store_key**) thd->alloc((sizeof(store_key*) * !(tab_ref->items= thd->alloc<Item*>(tmp_key_parts)))
(tmp_key_parts + 1)))) ||
!(tab_ref->items=
(Item**) thd->alloc(sizeof(Item*) * tmp_key_parts)))
DBUG_RETURN(TRUE); /* purecov: inspected */ DBUG_RETURN(TRUE); /* purecov: inspected */
tab_ref->key_buff2=tab_ref->key_buff+ALIGN_SIZE(tmp_key->key_length); 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 We don't ever have guarded conditions for SJM tables, but code at SQL
layer depends on cond_guards array being alloced. 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<bool*>(tmp_key_parts)))
{ {
DBUG_RETURN(TRUE); 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; SJ_TMP_TABLE *sjtbl;
if (jt_rowid_offset) /* Temptable has at least one rowid */ if (jt_rowid_offset) /* Temptable has at least one rowid */
{ {
size_t tabs_size= (last_tab - sjtabs) * sizeof(SJ_TMP_TABLE::TAB); size_t ntabs= last_tab - sjtabs;
if (!(sjtbl= (SJ_TMP_TABLE*)thd->alloc(sizeof(SJ_TMP_TABLE))) || if (!(sjtbl= thd->alloc<SJ_TMP_TABLE>(1)) ||
!(sjtbl->tabs= (SJ_TMP_TABLE::TAB*) thd->alloc(tabs_size))) !(sjtbl->tabs= thd->alloc<SJ_TMP_TABLE::TAB>(ntabs)))
DBUG_RETURN(TRUE); /* purecov: inspected */ 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->is_degenerate= FALSE;
sjtbl->tabs_end= sjtbl->tabs + (last_tab - sjtabs); sjtbl->tabs_end= sjtbl->tabs + (last_tab - sjtabs);
sjtbl->rowid_len= jt_rowid_offset; 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 not depend on anything at all, ie this is
WHERE const IN (uncorrelated select) WHERE const IN (uncorrelated select)
*/ */
if (!(sjtbl= (SJ_TMP_TABLE*)thd->alloc(sizeof(SJ_TMP_TABLE)))) if (!(sjtbl= thd->alloc<SJ_TMP_TABLE>(1)))
DBUG_RETURN(TRUE); /* purecov: inspected */ DBUG_RETURN(TRUE); /* purecov: inspected */
sjtbl->tmp_table= NULL; sjtbl->tmp_table= NULL;
sjtbl->is_degenerate= TRUE; sjtbl->is_degenerate= TRUE;
@ -6048,7 +6044,7 @@ int select_value_catcher::setup(List<Item> *items)
assigned= FALSE; assigned= FALSE;
n_elements= items->elements; n_elements= items->elements;
if (!(row= (Item_cache**) thd->alloc(sizeof(Item_cache*) * n_elements))) if (!(row= thd->alloc<Item_cache*>(n_elements)))
return TRUE; return TRUE;
Item *sel_item; Item *sel_item;

View File

@ -1729,7 +1729,7 @@ void Dep_analysis_context::create_unique_pseudo_key_if_needed(
auto max_possible_elements= first_select->join->fields_list.elements; auto max_possible_elements= first_select->join->fields_list.elements;
void *buf; void *buf;
MY_BITMAP *exposed_fields= (MY_BITMAP*) MY_BITMAP *exposed_fields= (MY_BITMAP*)
current_thd->alloc(sizeof(MY_BITMAP)); current_thd->alloc<MY_BITMAP>(1);
if (!(buf= current_thd->alloc(bitmap_buffer_size(max_possible_elements))) || if (!(buf= current_thd->alloc(bitmap_buffer_size(max_possible_elements))) ||
my_bitmap_init(exposed_fields, (my_bitmap_map*)buf, my_bitmap_init(exposed_fields, (my_bitmap_map*)buf,
max_possible_elements)) max_possible_elements))

View File

@ -305,7 +305,7 @@ char *partition_info::create_default_partition_names(THD *thd, uint part_no,
uint num_parts_arg, uint num_parts_arg,
uint start_no) 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; char *move_ptr= ptr;
uint i= 0; uint i= 0;
DBUG_ENTER("create_default_partition_names"); 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) const char *part_name)
{ {
size_t size_alloc= strlen(part_name) + MAX_PART_NAME_SIZE; 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"); DBUG_ENTER("create_default_subpartition_name");
if (likely(ptr != NULL)) if (likely(ptr != NULL))
@ -1653,7 +1653,6 @@ bool partition_info::set_up_charset_field_preps(THD *thd)
Field *field, **ptr; Field *field, **ptr;
uchar **char_ptrs; uchar **char_ptrs;
unsigned i; unsigned i;
size_t size;
uint tot_part_fields= 0; uint tot_part_fields= 0;
uint tot_subpart_fields= 0; uint tot_subpart_fields= 0;
DBUG_ENTER("set_up_charset_field_preps"); DBUG_ENTER("set_up_charset_field_preps");
@ -1667,15 +1666,13 @@ bool partition_info::set_up_charset_field_preps(THD *thd)
while ((field= *(ptr++))) while ((field= *(ptr++)))
if (field_is_partition_charset(field)) if (field_is_partition_charset(field))
tot_part_fields++; tot_part_fields++;
size= tot_part_fields * sizeof(char*); if (!(char_ptrs= thd->calloc<uchar*>(tot_part_fields)))
if (!(char_ptrs= (uchar**)thd->calloc(size)))
goto error; goto error;
part_field_buffers= char_ptrs; part_field_buffers= char_ptrs;
if (!(char_ptrs= (uchar**)thd->calloc(size))) if (!(char_ptrs= thd->calloc<uchar*>(tot_part_fields)))
goto error; goto error;
restore_part_field_ptrs= char_ptrs; restore_part_field_ptrs= char_ptrs;
size= (tot_part_fields + 1) * sizeof(Field*); if (!(char_ptrs= thd->alloc<uchar*>(tot_part_fields + 1)))
if (!(char_ptrs= (uchar**)thd->alloc(size)))
goto error; goto error;
part_charset_field_array= (Field**)char_ptrs; part_charset_field_array= (Field**)char_ptrs;
ptr= part_field_array; ptr= part_field_array;
@ -1685,8 +1682,7 @@ bool partition_info::set_up_charset_field_preps(THD *thd)
if (field_is_partition_charset(field)) if (field_is_partition_charset(field))
{ {
uchar *field_buf; uchar *field_buf;
size= field->pack_length(); if (!(field_buf= thd->calloc<uchar>(field->pack_length())))
if (!(field_buf= (uchar*) thd->calloc(size)))
goto error; goto error;
part_charset_field_array[i]= field; part_charset_field_array[i]= field;
part_field_buffers[i++]= field_buf; part_field_buffers[i++]= field_buf;
@ -1702,15 +1698,13 @@ bool partition_info::set_up_charset_field_preps(THD *thd)
while ((field= *(ptr++))) while ((field= *(ptr++)))
if (field_is_partition_charset(field)) if (field_is_partition_charset(field))
tot_subpart_fields++; tot_subpart_fields++;
size= tot_subpart_fields * sizeof(char*); if (!(char_ptrs= (uchar**) thd->calloc<uchar*>(tot_subpart_fields)))
if (!(char_ptrs= (uchar**) thd->calloc(size)))
goto error; goto error;
subpart_field_buffers= char_ptrs; subpart_field_buffers= char_ptrs;
if (!(char_ptrs= (uchar**) thd->calloc(size))) if (!(char_ptrs= (uchar**) thd->calloc<uchar*>(tot_subpart_fields)))
goto error; goto error;
restore_subpart_field_ptrs= char_ptrs; restore_subpart_field_ptrs= char_ptrs;
size= (tot_subpart_fields + 1) * sizeof(Field*); if (!(char_ptrs= (uchar**) thd->alloc<uchar*>(tot_subpart_fields + 1)))
if (!(char_ptrs= (uchar**) thd->alloc(size)))
goto error; goto error;
subpart_charset_field_array= (Field**)char_ptrs; subpart_charset_field_array= (Field**)char_ptrs;
ptr= subpart_field_array; ptr= subpart_field_array;
@ -1721,8 +1715,7 @@ bool partition_info::set_up_charset_field_preps(THD *thd)
if (!field_is_partition_charset(field)) if (!field_is_partition_charset(field))
continue; continue;
size= field->pack_length(); if (!(field_buf= thd->calloc<uchar>(field->pack_length())))
if (!(field_buf= (uchar*) thd->calloc(size)))
goto error; goto error;
subpart_charset_field_array[i]= field; subpart_charset_field_array[i]= field;
subpart_field_buffers[i++]= field_buf; subpart_field_buffers[i++]= field_buf;
@ -2036,8 +2029,7 @@ bool partition_info::init_column_part(THD *thd)
uint loc_num_columns; uint loc_num_columns;
DBUG_ENTER("partition_info::init_column_part"); DBUG_ENTER("partition_info::init_column_part");
if (!(list_val= if (!(list_val= thd->calloc<part_elem_value>(1)) ||
(part_elem_value*) thd->calloc(sizeof(part_elem_value))) ||
p_elem->list_val_list.push_back(list_val, thd->mem_root)) p_elem->list_val_list.push_back(list_val, thd->mem_root))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
@ -2045,9 +2037,7 @@ bool partition_info::init_column_part(THD *thd)
loc_num_columns= num_columns; loc_num_columns= num_columns;
else else
loc_num_columns= MAX_REF_PARTS; loc_num_columns= MAX_REF_PARTS;
if (!(col_val_array= if (!(col_val_array= thd->calloc<part_column_list_val>(loc_num_columns)))
(part_column_list_val*) thd->calloc(loc_num_columns *
sizeof(part_column_list_val))))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
list_val->col_val_array= col_val_array; list_val->col_val_array= col_val_array;

View File

@ -1226,8 +1226,7 @@ bool Protocol::send_result_set_metadata(List<Item> *list, uint flags)
Item *item; Item *item;
Protocol_text prot(thd, thd->variables.net_buffer_length); Protocol_text prot(thd, thd->variables.net_buffer_length);
#ifndef DBUG_OFF #ifndef DBUG_OFF
field_handlers= (const Type_handler **) thd->alloc( field_handlers= thd->alloc<const Type_handler *>(list->elements);
sizeof(field_handlers[0]) * list->elements);
#endif #endif
for (uint pos= 0; (item= it++); pos++) for (uint pos= 0; (item= it++); pos++)
@ -1276,8 +1275,7 @@ bool Protocol::send_list_fields(List<Field> *list, const TABLE_LIST *table_list)
Protocol_text prot(thd, thd->variables.net_buffer_length); Protocol_text prot(thd, thd->variables.net_buffer_length);
#ifndef DBUG_OFF #ifndef DBUG_OFF
field_handlers= (const Type_handler **) thd->alloc(sizeof(field_handlers[0]) * field_handlers= thd->alloc<const Type_handler *>(list->elements);
list->elements);
#endif #endif
for (uint pos= 0; (fld= it++); pos++) for (uint pos= 0; (fld= it++); pos++)

View File

@ -399,10 +399,8 @@ void TABLE::init_cost_info_for_usable_range_rowid_filters(THD *thd)
if (!range_rowid_filter_cost_info_elems) if (!range_rowid_filter_cost_info_elems)
return; return;
range_rowid_filter_cost_info_ptr= range_rowid_filter_cost_info_ptr= thd->calloc<Range_rowid_filter_cost_info*>
(Range_rowid_filter_cost_info **) (range_rowid_filter_cost_info_elems);
thd->calloc(sizeof(Range_rowid_filter_cost_info *) *
range_rowid_filter_cost_info_elems);
range_rowid_filter_cost_info= range_rowid_filter_cost_info=
new (thd->mem_root) new (thd->mem_root)
Range_rowid_filter_cost_info[range_rowid_filter_cost_info_elems]; Range_rowid_filter_cost_info[range_rowid_filter_cost_info_elems];

View File

@ -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) SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted, enum enum_var_type scope)
{ {
int count= system_variable_hash.records, i; int count= system_variable_hash.records, i;
int size= sizeof(SHOW_VAR) * (count + 1); SHOW_VAR *result= thd->alloc<SHOW_VAR>(count + 1);
SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
if (result) if (result)
{ {
@ -1416,7 +1415,7 @@ resolve_engine_list(THD *thd, const char *str_arg, size_t str_arg_len,
} }
if (temp_copy) if (temp_copy)
res= (plugin_ref *)thd->calloc((count+1)*sizeof(*res)); res= thd->calloc<plugin_ref>(count+1);
else else
res= (plugin_ref *)my_malloc(PSI_INSTRUMENT_ME, (count+1)*sizeof(*res), MYF(MY_ZEROFILL|MY_WME)); res= (plugin_ref *)my_malloc(PSI_INSTRUMENT_ME, (count+1)*sizeof(*res), MYF(MY_ZEROFILL|MY_WME));
if (!res) if (!res)
@ -1494,7 +1493,7 @@ temp_copy_engine_list(THD *thd, plugin_ref *list)
for (p= list, count= 0; *p; ++p, ++count) for (p= list, count= 0; *p; ++p, ++count)
; ;
p= (plugin_ref *)thd->alloc((count+1)*sizeof(*p)); p= thd->alloc<plugin_ref>(count+1);
if (!p) if (!p)
{ {
my_error(ER_OUTOFMEMORY, MYF(0), (int)((count+1)*sizeof(*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; size= 0;
for (p= list; *p; ++p) for (p= list; *p; ++p)
size+= plugin_name(*p)->length + 1; size+= plugin_name(*p)->length + 1;
buf= static_cast<char *>(thd->alloc(size)); buf= thd->alloc(size);
if (!buf) if (!buf)
return NULL; return NULL;
pos= buf; pos= buf;

View File

@ -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())) if (!my_hash_search(&prelocking_ctx->sroutines, key->ptr(), key->length()))
{ {
Sroutine_hash_entry *rn= Sroutine_hash_entry *rn= arena->alloc<Sroutine_hash_entry>(1);
(Sroutine_hash_entry *)arena->alloc(sizeof(Sroutine_hash_entry));
if (unlikely(!rn)) // OOM. Error will be reported using fatal_error(). if (unlikely(!rn)) // OOM. Error will be reported using fatal_error().
return FALSE; return FALSE;
MDL_REQUEST_INIT_BY_KEY(&rn->mdl_request, key, MDL_SHARED, MDL_TRANSACTION); MDL_REQUEST_INIT_BY_KEY(&rn->mdl_request, key, MDL_SHARED, MDL_TRANSACTION);

View File

@ -2572,7 +2572,7 @@ int
sp_head::push_backpatch(THD *thd, sp_instr *i, sp_label *lab, sp_head::push_backpatch(THD *thd, sp_instr *i, sp_label *lab,
List<bp_t> *list, backpatch_instr_type itype) List<bp_t> *list, backpatch_instr_type itype)
{ {
bp_t *bp= (bp_t *) thd->alloc(sizeof(bp_t)); bp_t *bp= thd->alloc<bp_t>(1);
if (!bp) if (!bp)
return 1; return 1;
@ -3576,7 +3576,7 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check)
} }
else else
{ {
if (!(tab= (SP_TABLE *)thd->calloc(sizeof(SP_TABLE)))) if (!(tab= thd->calloc<SP_TABLE>(1)))
return FALSE; return FALSE;
if ((lex_for_tmp_check->sql_command == SQLCOM_CREATE_TABLE || if ((lex_for_tmp_check->sql_command == SQLCOM_CREATE_TABLE ||
lex_for_tmp_check->sql_command == SQLCOM_CREATE_SEQUENCE) && 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) if (stab->temp)
continue; 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)) || stab->lock_count)) ||
!(key_buff= (char*)thd->memdup(stab->qname.str, !(key_buff= (char*)thd->memdup(stab->qname.str,
stab->qname.length))) stab->qname.length)))
@ -3707,7 +3707,7 @@ sp_add_to_query_tables(THD *thd, LEX *lex,
{ {
TABLE_LIST *table; TABLE_LIST *table;
if (!(table= (TABLE_LIST *)thd->calloc(sizeof(TABLE_LIST)))) if (!(table= thd->calloc<TABLE_LIST>(1)))
return NULL; return NULL;
if (!thd->make_lex_string(&table->db, db->str, db->length) || if (!thd->make_lex_string(&table->db, db->str, db->length) ||
!thd->make_lex_string(&table->table_name, name->str, name->length) || !thd->make_lex_string(&table->table_name, name->str, name->length) ||

View File

@ -167,18 +167,12 @@ bool sp_rcontext::alloc_arrays(THD *thd)
{ {
{ {
size_t n= m_root_parsing_ctx->max_cursor_index(); size_t n= m_root_parsing_ctx->max_cursor_index();
m_cstack.reset( m_cstack.reset(thd->alloc<sp_cursor*>(n), n);
static_cast<sp_cursor **> (
thd->alloc(n * sizeof (sp_cursor*))),
n);
} }
{ {
size_t n= m_root_parsing_ctx->get_num_case_exprs(); size_t n= m_root_parsing_ctx->get_num_case_exprs();
m_case_expr_holders.reset( m_case_expr_holders.reset(thd->calloc<Item_cache *>(n), n);
static_cast<Item_cache **> (
thd->calloc(n * sizeof (Item_cache*))),
n);
} }
return !m_cstack.array() || !m_case_expr_holders.array(); 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(); uint num_vars= m_root_parsing_ctx->max_var_index();
m_var_items.reset( m_var_items.reset(thd->alloc<Item_field*>(num_vars), num_vars);
static_cast<Item_field **> (
thd->alloc(num_vars * sizeof (Item *))),
num_vars);
if (!m_var_items.array()) if (!m_var_items.array())
return true; return true;

View File

@ -12019,7 +12019,7 @@ bool sp_grant_privileges(THD *thd,
Lex_cstring_strlen sctx_user(sctx->priv_user); Lex_cstring_strlen sctx_user(sctx->priv_user);
Lex_cstring_strlen sctx_host(sctx->priv_host); Lex_cstring_strlen sctx_host(sctx->priv_host);
if (!(combo=(LEX_USER*) thd->alloc(sizeof(LEX_USER)))) if (!(combo= thd->alloc<LEX_USER>(1)))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
mysql_mutex_lock(&acl_cache->lock); mysql_mutex_lock(&acl_cache->lock);

View File

@ -282,9 +282,9 @@ uint Alter_info::check_vcol_field(Item_field *item) const
((item->db_name.length && !db.streq(item->db_name)) || ((item->db_name.length && !db.streq(item->db_name)) ||
(item->table_name.length && !table_name.streq(item->table_name)))) (item->table_name.length && !table_name.streq(item->table_name))))
{ {
char *ptr= (char*)current_thd->alloc(item->db_name.length + char *ptr= current_thd->alloc(item->db_name.length +
item->table_name.length + item->table_name.length +
item->field_name.length + 3); item->field_name.length + 3);
strxmov(ptr, safe_str(item->db_name.str), item->db_name.length ? "." : "", strxmov(ptr, safe_str(item->db_name.str), item->db_name.length ? "." : "",
item->table_name.str, ".", item->field_name.str, NullS); item->table_name.str, ".", item->field_name.str, NullS);
item->field_name.str= ptr; item->field_name.str= ptr;

View File

@ -126,8 +126,7 @@ proc_analyse_init(THD *thd, ORDER *param, select_result *result,
pc->max_treemem = MAX_TREEMEM; pc->max_treemem = MAX_TREEMEM;
} }
if (!(pc->f_info= if (!(pc->f_info= thd->alloc<field_info*>(field_list.elements)))
(field_info**) thd->alloc(sizeof(field_info*) * field_list.elements)))
goto err; goto err;
pc->f_end = pc->f_info + field_list.elements; pc->f_end = pc->f_info + field_list.elements;
pc->fields = field_list; pc->fields = field_list;

View File

@ -3391,7 +3391,7 @@ request_backoff_action(enum_open_table_action action_arg,
{ {
DBUG_ASSERT(action_arg == OT_DISCOVER || action_arg == OT_REPAIR || DBUG_ASSERT(action_arg == OT_DISCOVER || action_arg == OT_REPAIR ||
action_arg == OT_ADD_HISTORY_PARTITION); action_arg == OT_ADD_HISTORY_PARTITION);
m_failed_table= (TABLE_LIST*) m_thd->alloc(sizeof(TABLE_LIST)); m_failed_table= m_thd->alloc<TABLE_LIST>(1);
if (m_failed_table == NULL) if (m_failed_table == NULL)
return TRUE; return TRUE;
m_failed_table->init_one_table(&table->db, &table->table_name, &table->alias, TL_WRITE); 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; continue;
} }
TABLE_LIST *tl= (TABLE_LIST *) thd->alloc(sizeof(TABLE_LIST)); TABLE_LIST *tl= thd->alloc<TABLE_LIST>(1);
if (!tl) if (!tl)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
tl->init_one_table_for_prelocking(&tables->db, 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; lock_type= TL_READ;
if (table_already_fk_prelocked(prelocking_ctx->query_tables, if (table_already_fk_prelocked(prelocking_ctx->query_tables,
fk->foreign_db, fk->foreign_table, fk->foreign_db, fk->foreign_table, lock_type))
lock_type))
continue; continue;
TABLE_LIST *tl= (TABLE_LIST *) thd->alloc(sizeof(TABLE_LIST)); TABLE_LIST *tl= thd->alloc<TABLE_LIST>(1);
tl->init_one_table_for_prelocking(fk->foreign_db, tl->init_one_table_for_prelocking(fk->foreign_db, fk->foreign_table,
fk->foreign_table, NULL, lock_type, TABLE_LIST::PRELOCK_FK, table_list->belong_to_view,
NULL, lock_type, op, &prelocking_ctx->query_tables_last, table_list->for_insert_data);
TABLE_LIST::PRELOCK_FK,
table_list->belong_to_view, op,
&prelocking_ctx->query_tables_last,
table_list->for_insert_data);
} }
if (arena) if (arena)
thd->restore_active_arena(arena, &backup); 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; TABLE **start,**ptr;
bool found_first_not_own= 0; bool found_first_not_own= 0;
if (!(ptr=start=(TABLE**) thd->alloc(sizeof(TABLE*)*count))) if (!(ptr= start= thd->alloc<TABLE*>(count)))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
/* /*

View File

@ -2543,7 +2543,7 @@ bool THD::reinterpret_string_from_binary(LEX_CSTRING *to, CHARSET_INFO *cs,
{ {
size_t zeros= cs->mbminlen - incomplete; size_t zeros= cs->mbminlen - incomplete;
size_t aligned_length= zeros + length; size_t aligned_length= zeros + length;
char *dst= (char*) alloc(aligned_length + 1); char *dst= alloc(aligned_length + 1);
if (!dst) if (!dst)
{ {
to->str= NULL; // Safety to->str= NULL; // Safety
@ -4517,8 +4517,7 @@ create_result_table(THD *thd_arg, List<Item> *column_types,
!create_table, keep_row_order))) !create_table, keep_row_order)))
return TRUE; return TRUE;
col_stat= (Column_statistics*) table->in_use->alloc(table->s->fields * col_stat= table->in_use->alloc<Column_statistics>(table->s->fields);
sizeof(Column_statistics));
if (!col_stat) if (!col_stat)
return TRUE; 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 */ /* Purge already hold the MDL for the table */
Open_table_context ot_ctx(thd, MYSQL_OPEN_HAS_MDL_LOCK); 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<TABLE_LIST>(1);
LEX_CSTRING db_name= {db, dblen }; LEX_CSTRING db_name= {db, dblen };
LEX_CSTRING table_name= { tb, tblen }; LEX_CSTRING table_name= { tb, tblen };

View File

@ -1278,13 +1278,19 @@ public:
inline bool is_conventional() const inline bool is_conventional() const
{ return state == STMT_CONVENTIONAL_EXECUTION; } { return state == STMT_CONVENTIONAL_EXECUTION; }
inline void* alloc(size_t size) const { return alloc_root(mem_root,size); } template <typename T=char>
inline void* calloc(size_t size) const inline T* alloc(size_t size) const
{ {
void *ptr; return (T*)alloc_root(mem_root, sizeof(T)*size);
if (likely((ptr=alloc_root(mem_root,size)))) }
bzero(ptr, size);
return ptr; template <typename T=char>
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 inline char *strdup(const char *str) const
{ return strdup_root(mem_root,str); } { return strdup_root(mem_root,str); }
@ -1292,7 +1298,7 @@ public:
{ return strmake_root(mem_root,str,size); } { return strmake_root(mem_root,str,size); }
inline LEX_CSTRING strcat(const LEX_CSTRING &a, const LEX_CSTRING &b) const 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)) if (unlikely(!buf))
return null_clex_str; return null_clex_str;
memcpy(buf, a.str, a.length); memcpy(buf, a.str, a.length);
@ -1398,7 +1404,7 @@ public:
// Allocate LEX_STRING for character set conversion // Allocate LEX_STRING for character set conversion
bool alloc_lex_string(LEX_STRING *dst, size_t length) const 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; return false;
dst->length= 0; // Safety dst->length= 0; // Safety
return true; // EOM return true; // EOM
@ -1411,7 +1417,7 @@ public:
const char *tmp= src->str; const char *tmp= src->str;
const char *tmpend= src->str + src->length; const char *tmpend= src->str + src->length;
char *to; char *to;
if (!(dst->str= to= (char *) alloc(src->length + 1))) if (!(dst->str= to= alloc(src->length + 1)))
{ {
dst->length= 0; // Safety dst->length= 0; // Safety
return true; return true;

View File

@ -1222,7 +1222,7 @@ update_binlog:
char *query, *query_pos, *query_end, *query_data_start; char *query, *query_pos, *query_end, *query_data_start;
TABLE_LIST *tbl; 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 */ goto exit; /* not much else we can do */
query_pos= query_data_start= strmov(query,"DROP TABLE IF EXISTS "); query_pos= query_data_start= strmov(query,"DROP TABLE IF EXISTS ");
query_end= query + MAX_DROP_TABLE_Q_LEN; 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); const LEX_CSTRING *table= files.at(idx);
/* Drop the table nicely */ /* Drop the table nicely */
TABLE_LIST *table_list=(TABLE_LIST*)thd->calloc(sizeof(*table_list)); TABLE_LIST *table_list= thd->calloc<TABLE_LIST>(1);
if (!table_list) if (!table_list)
DBUG_RETURN(true); DBUG_RETURN(true);

View File

@ -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), num_of_tables(num_of_tables_arg), error(0),
do_delete(0), transactional_tables(0), normal_tables(0), error_handled(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<Unique*>(num_of_tables);
} }

View File

@ -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); 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<NESTED_JOIN>(1);
if (!derived->nested_join) if (!derived->nested_join)
{ {
res= TRUE; res= TRUE;

View File

@ -949,7 +949,7 @@ retry:
{ {
DBUG_ASSERT(keyname != 0); DBUG_ASSERT(keyname != 0);
if (unlikely(!(key= (uchar*) thd->calloc(ALIGN_SIZE(handler->key_len))))) if (unlikely(!(key= thd->calloc<uchar>(ALIGN_SIZE(handler->key_len)))))
goto err; goto err;
if (unlikely((error= table->file->ha_index_or_rnd_end()))) if (unlikely((error= table->file->ha_index_or_rnd_end())))
break; break;

View File

@ -2835,7 +2835,7 @@ int JOIN_CACHE_HASHED::init(bool for_explain)
if (for_explain) if (for_explain)
DBUG_RETURN(0); DBUG_RETURN(0);
if (!(key_buff= (uchar*) join->thd->alloc(key_length))) if (!(key_buff= join->thd->alloc<uchar>(key_length)))
DBUG_RETURN(1); DBUG_RETURN(1);
/* Take into account a reference to the next record in the key chain */ /* Take into account a reference to the next record in the key chain */

View File

@ -809,7 +809,7 @@ bool Lex_input_stream::init(THD *thd,
DBUG_EXECUTE_IF("bug42064_simulate_oom", DBUG_EXECUTE_IF("bug42064_simulate_oom",
DBUG_SET("+d,simulate_out_of_memory");); 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_EXECUTE_IF("bug42064_simulate_oom",
DBUG_SET("-d,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); 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= m_body_utf8;
*m_body_utf8_ptr= 0; *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; end -= post_skip;
DBUG_ASSERT(end >= str); 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'); dst->set(&empty_clex_str, 0, '\0');
return true; // Sql_alloc has set error flag 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()) if (!ref_pointer_array.is_null())
return false; return false;
Item **array= static_cast<Item**>( Item **array= thd->active_stmt_arena_to_use()->alloc<Item*>(n_elems);
thd->active_stmt_arena_to_use()->alloc(sizeof(Item*) * n_elems));
if (likely(array != NULL)) if (likely(array != NULL))
ref_pointer_array= Ref_ptr_array(array, n_elems); ref_pointer_array= Ref_ptr_array(array, n_elems);
return array == NULL; return array == NULL;
@ -4864,7 +4863,7 @@ void st_select_lex::fix_prepare_information(THD *thd, Item **conds,
{ {
if (!group_list_ptrs) if (!group_list_ptrs)
{ {
void *mem= active_arena->alloc(sizeof(Group_list_ptrs)); void *mem= active_arena->alloc<Group_list_ptrs>(1);
group_list_ptrs= new (mem) Group_list_ptrs(active_arena->mem_root); group_list_ptrs= new (mem) Group_list_ptrs(active_arena->mem_root);
} }
group_list_ptrs->reserve(group_list.elements); group_list_ptrs->reserve(group_list.elements);
@ -12364,7 +12363,7 @@ LEX_USER *LEX::current_user_for_set_password(THD *thd)
return NULL; return NULL;
} }
LEX_USER *res; LEX_USER *res;
if (unlikely(!(res= (LEX_USER*) thd->calloc(sizeof(LEX_USER))))) if (unlikely(!(res= thd->calloc<LEX_USER>(1))))
return NULL; return NULL;
res->user= current_user; res->user= current_user;
return res; return res;

View File

@ -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(), uint length= MY_MAX(charset()->mbmaxlen, MY_MAX(m_field_term.length(),
m_line_term.length())) + 1; m_line_term.length())) + 1;
set_if_bigger(length,line_start.length()); set_if_bigger(length,line_start.length());
stack= stack_pos= (int*) thd->alloc(sizeof(int) * length); stack= stack_pos= thd->alloc<int>(length);
DBUG_ASSERT(m_fixed_length < UINT_MAX32); DBUG_ASSERT(m_fixed_length < UINT_MAX32);
if (data.reserve((size_t) m_fixed_length)) if (data.reserve((size_t) m_fixed_length))

View File

@ -2264,8 +2264,7 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD *
char buff[250]; char buff[250];
uint buff_len= sizeof(buff); uint buff_len= sizeof(buff);
if (!(current_global_status_var= (STATUS_VAR*) if (!(current_global_status_var= thd->alloc<STATUS_VAR>(1)))
thd->alloc(sizeof(STATUS_VAR))))
break; break;
general_log_print(thd, command, NullS); general_log_print(thd, command, NullS);
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]); 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; ORDER *order;
Item **item_ptr; 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; return 1;
item_ptr = (Item**) (order+1); item_ptr = (Item**) (order+1);
*item_ptr= item; *item_ptr= item;
@ -7990,7 +7989,7 @@ bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *item,bool asc)
{ {
ORDER *order; ORDER *order;
DBUG_ENTER("add_to_list"); DBUG_ENTER("add_to_list");
if (unlikely(!(order = (ORDER *) thd->alloc(sizeof(ORDER))))) if (unlikely(!(order= thd->alloc<ORDER>(1))))
DBUG_RETURN(1); DBUG_RETURN(1);
order->item_ptr= item; order->item_ptr= item;
order->item= &order->item_ptr; 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 */ /* Fix is using unix filename format on dos */
strmov(buff,*filename_ptr); strmov(buff,*filename_ptr);
end=convert_dirname(buff, *filename_ptr, NullS); end=convert_dirname(buff, *filename_ptr, NullS);
if (unlikely(!(ptr= (char*) thd->alloc((size_t) (end-buff) + if (unlikely(!(ptr= thd->alloc((size_t)(end-buff) + table_name->length + 1))))
table_name->length + 1))))
return 1; // End of memory return 1; // End of memory
*filename_ptr=ptr; *filename_ptr=ptr;
strxmov(ptr,buff,table_name->str,NullS); strxmov(ptr,buff,table_name->str,NullS);
@ -9989,7 +9987,7 @@ LEX_USER *create_default_definer(THD *thd, bool role)
{ {
LEX_USER *definer; LEX_USER *definer;
if (unlikely(! (definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER))))) if (unlikely(!(definer= thd->alloc<LEX_USER>(1))))
return 0; return 0;
thd->get_definer(definer, role); thd->get_definer(definer, role);
@ -10024,7 +10022,7 @@ LEX_USER *create_definer(THD *thd, LEX_CSTRING *user_name,
/* Create and initialize. */ /* Create and initialize. */
if (unlikely(!(definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER))))) if (unlikely(!(definer= thd->alloc<LEX_USER>(1))))
return 0; return 0;
definer->user= *user_name; definer->user= *user_name;

View File

@ -322,12 +322,10 @@ err:
function. function.
*/ */
static bool set_up_field_array(THD *thd, TABLE *table, static bool set_up_field_array(THD *thd, TABLE *table, bool is_sub_part)
bool is_sub_part)
{ {
Field **ptr, *field, **field_array; Field **ptr, *field, **field_array;
uint num_fields= 0; uint num_fields= 0;
uint size_field_array;
uint i= 0; uint i= 0;
uint inx; uint inx;
partition_info *part_info= table->part_info; 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_ASSERT(!is_sub_part);
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
size_field_array= (num_fields+1)*sizeof(Field*); field_array= thd->calloc<Field*>(num_fields + 1);
field_array= (Field**) thd->calloc(size_field_array);
if (unlikely(!field_array)) if (unlikely(!field_array))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
@ -480,15 +477,14 @@ static bool create_full_part_field_array(THD *thd, TABLE *table,
else else
{ {
Field *field, **field_array; Field *field, **field_array;
uint num_part_fields=0, size_field_array; uint num_part_fields=0;
ptr= table->field; ptr= table->field;
while ((field= *(ptr++))) while ((field= *(ptr++)))
{ {
if (field->flags & FIELD_IN_PART_FUNC_FLAG) if (field->flags & FIELD_IN_PART_FUNC_FLAG)
num_part_fields++; num_part_fields++;
} }
size_field_array= (num_part_fields+1)*sizeof(Field*); field_array= thd->calloc<Field*>(num_part_fields + 1);
field_array= (Field**) thd->calloc(size_field_array);
if (unlikely(!field_array)) if (unlikely(!field_array))
{ {
result= TRUE; 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); part_column_list_val *UNINIT_VAR(current_largest_col_val);
uint num_column_values= part_info->part_field_list.elements; uint num_column_values= part_info->part_field_list.elements;
uint size_entries= sizeof(part_column_list_val) * num_column_values; uint size_entries= sizeof(part_column_list_val) * num_column_values;
part_info->range_col_array= (part_column_list_val*) part_info->range_col_array= thd->calloc<part_column_list_val>
thd->calloc(part_info->num_parts * size_entries); (part_info->num_parts * num_column_values);
if (unlikely(part_info->range_col_array == NULL)) if (unlikely(part_info->range_col_array == NULL))
goto end; goto end;
@ -1326,8 +1322,7 @@ static bool check_range_constants(THD *thd, partition_info *part_info)
longlong part_range_value; longlong part_range_value;
bool signed_flag= !part_info->part_expr->unsigned_flag; bool signed_flag= !part_info->part_expr->unsigned_flag;
part_info->range_int_array= (longlong*) part_info->range_int_array= thd->alloc<longlong>(part_info->num_parts);
thd->alloc(part_info->num_parts * sizeof(longlong));
if (unlikely(part_info->range_int_array == NULL)) if (unlikely(part_info->range_int_array == NULL))
goto end; goto end;
@ -1554,8 +1549,7 @@ static bool check_vers_constants(THD *thd, partition_info *part_info)
if (!vers_info->interval.is_set()) if (!vers_info->interval.is_set())
return 0; return 0;
part_info->range_int_array= part_info->range_int_array= thd->alloc<longlong>(part_info->num_parts);
(longlong*) thd->alloc(part_info->num_parts * sizeof(longlong));
MYSQL_TIME ltime; MYSQL_TIME ltime;
List_iterator<partition_element> it(part_info->partitions); List_iterator<partition_element> it(part_info->partitions);

View File

@ -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 when only using temporary tables. We don't need the log as
all temporary tables will disappear anyway in a crash. all temporary tables will disappear anyway in a crash.
*/ */
TABLE_PAIR *pair= (TABLE_PAIR*) thd->alloc(sizeof(*pair)); TABLE_PAIR *pair= thd->alloc<TABLE_PAIR>(1);
if (! pair || tmp_tables.push_front(pair, thd->mem_root)) if (! pair || tmp_tables.push_front(pair, thd->mem_root))
goto revert_rename; goto revert_rename;
pair->from= ren_table; pair->from= ren_table;

View File

@ -3521,7 +3521,7 @@ setup_subq_exit:
if (select_lex->have_window_funcs()) if (select_lex->have_window_funcs())
{ {
if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)))) if (!(join_tab= thd->alloc<JOIN_TAB>(1)))
DBUG_RETURN(1); DBUG_RETURN(1);
#ifndef DBUG_OFF #ifndef DBUG_OFF
dbug_join_tab_array_size= 1; 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; (*sargables)[0].field= 0;
if (my_init_dynamic_array2(thd->mem_root->psi_key, keyuse, sizeof(KEYUSE), if (my_init_dynamic_array2(thd->mem_root->psi_key, keyuse, sizeof(KEYUSE),
thd->alloc(sizeof(KEYUSE) * 20), 20, 64, thd->alloc<KEYUSE>(20), 20, 64,
MYF(MY_THREAD_SPECIFIC))) MYF(MY_THREAD_SPECIFIC)))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
@ -13125,8 +13125,7 @@ bool JOIN::get_best_combination()
*/ */
aggr_tables= 2; aggr_tables= 2;
DBUG_ASSERT(!tmp_table_param.using_outer_summary_function); DBUG_ASSERT(!tmp_table_param.using_outer_summary_function);
if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)* if (!(join_tab= thd->alloc<JOIN_TAB>(top_join_tab_count + aggr_tables)))
(top_join_tab_count + aggr_tables))))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
if (inject_splitting_cond_for_all_tables_with_split_opt()) if (inject_splitting_cond_for_all_tables_with_split_opt())
@ -13176,7 +13175,7 @@ bool JOIN::get_best_combination()
j->join_loops= 0.0; j->join_loops= 0.0;
JOIN_TAB *jt; JOIN_TAB *jt;
JOIN_TAB_RANGE *jt_range; JOIN_TAB_RANGE *jt_range;
if (!(jt= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)*sjm->tables)) || if (!(jt= thd->alloc<JOIN_TAB>(sjm->tables)) ||
!(jt_range= new JOIN_TAB_RANGE)) !(jt_range= new JOIN_TAB_RANGE))
goto error; goto error;
jt_range->start= jt; jt_range->start= jt;
@ -13356,9 +13355,8 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab,
if (!key_parts) if (!key_parts)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
/* This memory is allocated only once for the joined table join_tab */ /* This memory is allocated only once for the joined table join_tab */
if (!(keyinfo= (KEY *) thd->alloc(sizeof(KEY))) || if (!(keyinfo= thd->alloc<KEY>(1)) ||
!(key_part_info = (KEY_PART_INFO *) thd->alloc(sizeof(KEY_PART_INFO)* !(key_part_info = thd->alloc<KEY_PART_INFO>(key_parts)))
key_parts)))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
keyinfo->usable_key_parts= keyinfo->user_defined_key_parts = key_parts; keyinfo->usable_key_parts= keyinfo->user_defined_key_parts = key_parts;
keyinfo->ext_key_parts= keyinfo->user_defined_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->is_statistics_from_stat_tables= FALSE;
keyinfo->name.str= "$hj"; keyinfo->name.str= "$hj";
keyinfo->name.length= 3; keyinfo->name.length= 3;
keyinfo->rec_per_key= (ulong*) thd->calloc(sizeof(ulong)*key_parts); keyinfo->rec_per_key= thd->calloc<ulong>(key_parts);
if (!keyinfo->rec_per_key) if (!keyinfo->rec_per_key)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
keyinfo->key_part= key_part_info; 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_parts= keyparts;
j->ref.key_length= length; j->ref.key_length= length;
j->ref.key= (int) key; j->ref.key= (int) key;
if (!(j->ref.key_buff= (uchar*) thd->calloc(ALIGN_SIZE(length)*2)) || if (!(j->ref.key_buff= thd->calloc<uchar>(ALIGN_SIZE(length)*2)) ||
!(j->ref.key_copy= (store_key**) thd->alloc((sizeof(store_key*) * !(j->ref.key_copy= thd->alloc<store_key*>(keyparts+1)) ||
(keyparts+1)))) || !(j->ref.items= thd->alloc<Item*>(keyparts)) ||
!(j->ref.items=(Item**) thd->alloc(sizeof(Item*)*keyparts)) || !(j->ref.cond_guards= thd->alloc<bool*>(keyparts)))
!(j->ref.cond_guards= (bool**) thd->alloc(sizeof(uint*)*keyparts)))
{ {
DBUG_RETURN(TRUE); 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_match_tab)
{ {
if (!(tab->loosescan_buf= (uchar*)join->thd->alloc(tab-> if (!(tab->loosescan_buf= join->thd->alloc<uchar>(tab->loosescan_key_len)))
loosescan_key_len)))
return TRUE; /* purecov: inspected */ return TRUE; /* purecov: inspected */
tab->sorted= TRUE; 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= 0; /* The only temp table index. */
key_length= tmp_key->key_length; key_length= tmp_key->key_length;
if (!(key_buff= if (!(key_buff= thd->calloc<uchar>(ALIGN_SIZE(tmp_key->key_length) * 2)) ||
(uchar*) thd->calloc(ALIGN_SIZE(tmp_key->key_length) * 2)) || !(key_copy= thd->alloc<store_key*>(tmp_key_parts + 1)) ||
!(key_copy= !(items= thd->alloc<Item*>(tmp_key_parts)))
(store_key**) thd->alloc((sizeof(store_key*) *
(tmp_key_parts + 1)))) ||
!(items=
(Item**) thd->alloc(sizeof(Item*) * tmp_key_parts)))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
key_buff2= key_buff + ALIGN_SIZE(tmp_key->key_length); 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 uint null_pack_length= (s->null_fields + 7) / 8; // NULL-bit array length
s->reclength+= null_pack_length; s->reclength+= null_pack_length;
s->rec_buff_length= ALIGN_SIZE(s->reclength + 1); 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<uchar>(s->rec_buff_length)))
return true; return true;
if (null_pack_length) 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)) if ((*ord_iter->item)->eq(item, 1))
goto next_item; goto next_item;
ORDER *ord=(ORDER*) thd->calloc(sizeof(ORDER)); ORDER *ord= thd->calloc<ORDER>(1);
if (!ord) if (!ord)
return 0; 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 another extra byte to not get warnings from purify in
Field_string::val_int Field_string::val_int
*/ */
if (!(tmp= (uchar*) thd->alloc(field->pack_length()+2))) if (!(tmp= thd->alloc<uchar>(field->pack_length()+2)))
goto err; goto err;
if (copy) if (copy)
{ {
@ -29888,16 +29880,14 @@ bool JOIN::rollup_init()
*/ */
tmp_table_param.group_parts= send_group_parts; tmp_table_param.group_parts= send_group_parts;
Item_null_result **null_items= Item_null_result **null_items= thd->alloc<Item_null_result*>(send_group_parts);
static_cast<Item_null_result**>(thd->alloc(sizeof(Item*)*send_group_parts));
rollup.null_items= Item_null_array(null_items, send_group_parts); rollup.null_items= Item_null_array(null_items, send_group_parts);
rollup.ref_pointer_arrays= rollup.ref_pointer_arrays=
static_cast<Ref_ptr_array*> reinterpret_cast<Ref_ptr_array*>
(thd->alloc((sizeof(Ref_ptr_array) + (thd->alloc((sizeof(Ref_ptr_array) +
all_fields.elements * sizeof(Item*)) * send_group_parts)); all_fields.elements * sizeof(Item*)) * send_group_parts));
rollup.fields= rollup.fields= thd->alloc<List<Item> >(send_group_parts);
static_cast<List<Item>*>(thd->alloc(sizeof(List<Item>) * send_group_parts));
if (!null_items || !rollup.ref_pointer_arrays || !rollup.fields) if (!null_items || !rollup.ref_pointer_arrays || !rollup.fields)
return true; return true;
@ -31386,8 +31376,7 @@ static void print_join(THD *thd,
} }
ti.rewind(); ti.rewind();
if (!(table= static_cast<TABLE_LIST **>(thd->alloc(sizeof(TABLE_LIST*) * if (!(table= thd->alloc<TABLE_LIST*>(tables_to_print)))
tables_to_print))))
DBUG_VOID_RETURN; // out of memory DBUG_VOID_RETURN; // out of memory
TABLE_LIST *tmp, **t= table + (tables_to_print - 1); TABLE_LIST *tmp, **t= table + (tables_to_print - 1);

View File

@ -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) && if (tmp->peer_port && (tmp_sctx->host || tmp_sctx->ip) &&
arg->thd->security_ctx->host_or_ip[0]) 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, my_snprintf((char *) thd_info->host, LIST_PROCESS_HOST_LEN,
"%s:%u", tmp_sctx->host_or_ip, tmp->peer_port); "%s:%u", tmp_sctx->host_or_ip, tmp->peer_port);
} }
@ -3181,7 +3181,7 @@ int select_result_text_buffer::append_row(List<Item> &items, bool send_names)
char **row; char **row;
int column= 0; int column= 0;
if (!(row= (char**) thd->alloc(sizeof(char*) * n_columns)) || if (!(row= thd->alloc<char*>(n_columns)) ||
rows.push_back(row, thd->mem_root)) rows.push_back(row, thd->mem_root))
return true; return true;
@ -3354,7 +3354,7 @@ int fill_show_explain_or_analyze(THD *thd, TABLE_LIST *table, COND *cond,
fromcs->mbminlen; fromcs->mbminlen;
uint dummy_errors; uint dummy_errors;
char *to, *p; char *to, *p;
if (!(to= (char*)thd->alloc(conv_length + 1))) if (!(to= thd->alloc(conv_length + 1)))
DBUG_RETURN(1); DBUG_RETURN(1);
p= to; p= to;
p+= copy_and_convert(to, conv_length, tocs, 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 Sort lines to get them into a predicted order
(needed for test cases and to not confuse users) (needed for test cases and to not confuse users)
*/ */
if (!(tmp= (Master_info**) thd->alloc(sizeof(Master_info*) * elements))) if (!(tmp= thd->alloc<Master_info*>(elements)))
goto error; goto error;
if (single_slave) if (single_slave)
@ -9247,10 +9247,8 @@ int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
DBUG_RETURN(0); DBUG_RETURN(0);
} }
List_iterator_fast<Item> it(sel->item_list); List_iterator_fast<Item> it(sel->item_list);
if (!(transl= if (!(transl= thd->active_stmt_arena_to_use()->
(Field_translator*)(thd->active_stmt_arena_to_use()-> alloc<Field_translator>(sel->item_list.elements))) // ???
alloc(sel->item_list.elements *
sizeof(Field_translator))))) // ???
{ {
DBUG_RETURN(1); DBUG_RETURN(1);
} }
@ -11071,7 +11069,7 @@ TABLE_LIST *get_trigger_table(THD *thd, const sp_name *trg_name)
return NULL; return NULL;
/* We need to reset statement table list to be PS/SP friendly. */ /* 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<TABLE_LIST>(1)))
return NULL; return NULL;
db= thd->make_ident_opt_casedn(trg_name->m_db, lower_case_table_names); db= thd->make_ident_opt_casedn(trg_name->m_db, lower_case_table_names);

View File

@ -1987,8 +1987,7 @@ public:
return; return;
} }
if ((calc_state= if ((calc_state= thd->alloc<Prefix_calc_state>(key_parts)))
(Prefix_calc_state *) thd->alloc(sizeof(Prefix_calc_state)*key_parts)))
{ {
uint keyno= (uint)(key_info-table->key_info); uint keyno= (uint)(key_info-table->key_info);
for (i= 0, state= calc_state; i < key_parts; i++, state++) for (i= 0, state= calc_state; i < key_parts; i++, state++)

View File

@ -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>(*key_count);
if (!*key_info_buffer) if (!*key_info_buffer)
DBUG_RETURN(true); // Out of memory 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); DBUG_RETURN(TRUE);
} }
key_part_info=(KEY_PART_INFO*) thd->calloc(sizeof(KEY_PART_INFO)*key_parts); key_part_info= thd->calloc<KEY_PART_INFO>(key_parts);
if (!key_part_info) if (!key_part_info)
DBUG_RETURN(true); // Out of memory DBUG_RETURN(true); // Out of memory
@ -6633,15 +6633,12 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table,
/* Allocate result buffers. */ /* Allocate result buffers. */
DBUG_ASSERT(ha_alter_info->rename_keys.mem_root() == thd->mem_root); DBUG_ASSERT(ha_alter_info->rename_keys.mem_root() == thd->mem_root);
if (! (ha_alter_info->index_drop_buffer= if (! (ha_alter_info->index_drop_buffer= thd->alloc<KEY*>(table->s->keys)) ||
(KEY**) thd->alloc(sizeof(KEY*) * table->s->keys)) ||
! (ha_alter_info->index_add_buffer= ! (ha_alter_info->index_add_buffer=
(uint*) thd->alloc(sizeof(uint) * thd->alloc<uint>(alter_info->key_list.elements)) ||
alter_info->key_list.elements)) ||
ha_alter_info->rename_keys.reserve(ha_alter_info->index_add_count) || ha_alter_info->rename_keys.reserve(ha_alter_info->index_add_count) ||
! (ha_alter_info->index_altered_ignorability_buffer= ! (ha_alter_info->index_altered_ignorability_buffer=
(KEY_PAIR*)thd->alloc(sizeof(KEY_PAIR) * thd->alloc<KEY_PAIR>(alter_info->alter_index_ignorability_list.elements)))
alter_info->alter_index_ignorability_list.elements)))
DBUG_RETURN(true); 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 restore_record(table, s->default_values); // Empty record for DEFAULT
if ((create_info->fields_option_struct= (ha_field_option_struct**) if ((create_info->fields_option_struct=
thd->calloc(sizeof(void*) * table->s->fields)) == NULL || thd->calloc<ha_field_option_struct*>(table->s->fields)) == NULL ||
(create_info->indexes_option_struct= (ha_index_option_struct**) (create_info->indexes_option_struct=
thd->calloc(sizeof(void*) * table->s->keys)) == NULL) thd->calloc<ha_index_option_struct*>(table->s->keys)) == NULL)
DBUG_RETURN(1); DBUG_RETURN(1);
if (merge_engine_options(table->s->option_list, create_info->option_list, 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 dflt{STRING_WITH_LEN("DEFAULT")};
LEX_CSTRING nxvl{STRING_WITH_LEN("NEXTVAL()")}; LEX_CSTRING nxvl{STRING_WITH_LEN("NEXTVAL()")};
size_t len= strlen(fmt) + nxvl.length + c.field_name.length + dflt.length; 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 // expression %s cannot be used in the %s clause of %`s
my_snprintf(resp, len, fmt, nxvl.str, dflt.str, c.field_name.str); my_snprintf(resp, len, fmt, nxvl.str, dflt.str, c.field_name.str);
return resp; return resp;

View File

@ -957,7 +957,7 @@ public:
{ {
static Name name= singleton()->name(); static Name name= singleton()->name();
size_t len= 9+name.length()+1; 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()); strmov(strmov(buf, "cast_as_"), name.ptr());
return { buf, len }; return { buf, len };
} }

View File

@ -1931,13 +1931,10 @@ int multi_update::prepare(List<Item> &not_used_values,
table_count= update.elements; table_count= update.elements;
update_tables= update.first; update_tables= update.first;
tmp_tables = (TABLE**) thd->calloc(sizeof(TABLE *) * table_count); tmp_tables = thd->calloc<TABLE*>(table_count);
tmp_table_param = (TMP_TABLE_PARAM*) thd->calloc(sizeof(TMP_TABLE_PARAM) * tmp_table_param = thd->calloc<TMP_TABLE_PARAM>(table_count);
table_count); fields_for_table= thd->alloc<List_item*>(table_count);
fields_for_table= (List_item **) thd->alloc(sizeof(List_item *) * values_for_table= thd->alloc<List_item*>(table_count);
table_count);
values_for_table= (List_item **) thd->alloc(sizeof(List_item *) *
table_count);
if (unlikely(thd->is_fatal_error)) if (unlikely(thd->is_fatal_error))
DBUG_RETURN(1); DBUG_RETURN(1);
for (i=0 ; i < table_count ; i++) for (i=0 ; i < table_count ; i++)

View File

@ -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.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); DBUG_RETURN(HA_ADMIN_FAILED);
} }
view->calc_md5(const_cast<char*>(view->md5.str)); view->calc_md5(const_cast<char*>(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 For suid views prepare a security context for checking underlying
objects of the view. objects of the view.
*/ */
if (!(table->view_sctx= (Security_context *) if (!(table->view_sctx=
thd->active_stmt_arena_to_use()->calloc(sizeof(Security_context)))) thd->active_stmt_arena_to_use()->calloc<Security_context>(1)))
goto err; goto err;
security_ctx= table->view_sctx; security_ctx= table->view_sctx;
} }

View File

@ -14273,8 +14273,7 @@ show_param:
| GRANTS | GRANTS
{ {
Lex->sql_command= SQLCOM_SHOW_GRANTS; Lex->sql_command= SQLCOM_SHOW_GRANTS;
if (unlikely(!(Lex->grant_user= if (unlikely(!(Lex->grant_user= thd->calloc<LEX_USER>(1))))
(LEX_USER*)thd->calloc(sizeof(LEX_USER)))))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->grant_user->user= current_user_and_current_role; Lex->grant_user->user= current_user_and_current_role;
} }
@ -14394,8 +14393,7 @@ show_param:
| CREATE USER_SYM | CREATE USER_SYM
{ {
Lex->sql_command= SQLCOM_SHOW_CREATE_USER; Lex->sql_command= SQLCOM_SHOW_CREATE_USER;
if (unlikely(!(Lex->grant_user= if (unlikely(!(Lex->grant_user= thd->calloc<LEX_USER>(1))))
(LEX_USER*)thd->calloc(sizeof(LEX_USER)))))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->grant_user->user= current_user; Lex->grant_user->user= current_user;
} }
@ -15893,7 +15891,7 @@ ident_or_text:
user_maybe_role: user_maybe_role:
ident_or_text ident_or_text
{ {
if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER))))) if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
MYSQL_YYABORT; MYSQL_YYABORT;
$$->user = $1; $$->user = $1;
@ -15904,7 +15902,7 @@ user_maybe_role:
} }
| ident_or_text '@' ident_or_text | ident_or_text '@' ident_or_text
{ {
if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER))))) if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
MYSQL_YYABORT; MYSQL_YYABORT;
$$->user = $1; $$->host=$3; $$->user = $1; $$->host=$3;
@ -15928,7 +15926,7 @@ user_maybe_role:
} }
| CURRENT_USER optional_braces | CURRENT_USER optional_braces
{ {
if (unlikely(!($$=(LEX_USER*)thd->calloc(sizeof(LEX_USER))))) if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
MYSQL_YYABORT; MYSQL_YYABORT;
$$->user= current_user; $$->user= current_user;
$$->auth= new (thd->mem_root) USER_AUTH(); $$->auth= new (thd->mem_root) USER_AUTH();
@ -17158,7 +17156,7 @@ option_value_no_option_type:
MYSQL_YYABORT; MYSQL_YYABORT;
LEX *lex = Lex; LEX *lex = Lex;
LEX_USER *user; LEX_USER *user;
if (unlikely(!(user=(LEX_USER *) thd->calloc(sizeof(LEX_USER))))) if (unlikely(!(user= thd->calloc<LEX_USER>(1))))
MYSQL_YYABORT; MYSQL_YYABORT;
user->user= current_user; user->user= current_user;
set_var_default_role *var= (new (thd->mem_root) set_var_default_role *var= (new (thd->mem_root)
@ -17649,7 +17647,7 @@ role_list:
current_role: current_role:
CURRENT_ROLE optional_braces CURRENT_ROLE optional_braces
{ {
if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER))))) if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
MYSQL_YYABORT; MYSQL_YYABORT;
$$->user= current_role; $$->user= current_role;
} }
@ -17664,7 +17662,7 @@ role_name: ident_or_text
((char*) $1.str)[$1.length] = '\0'; ((char*) $1.str)[$1.length] = '\0';
if (unlikely($1.length == 0)) if (unlikely($1.length == 0))
my_yyabort_error((ER_INVALID_ROLE, MYF(0), "")); my_yyabort_error((ER_INVALID_ROLE, MYF(0), ""));
if (unlikely(!($$=(LEX_USER*) thd->calloc(sizeof(LEX_USER))))) if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
MYSQL_YYABORT; MYSQL_YYABORT;
if (lex_string_eq(&$1, &none)) if (lex_string_eq(&$1, &none))
$$->user= none; $$->user= none;
@ -17937,18 +17935,18 @@ auth_token:
opt_auth_str: opt_auth_str:
/* empty */ /* empty */
{ {
if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH)))) if (!($$=thd->calloc<USER_AUTH>(1)))
MYSQL_YYABORT; MYSQL_YYABORT;
} }
| using_or_as TEXT_STRING_sys | using_or_as TEXT_STRING_sys
{ {
if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH)))) if (!($$=thd->calloc<USER_AUTH>(1)))
MYSQL_YYABORT; MYSQL_YYABORT;
$$->auth_str= $2; $$->auth_str= $2;
} }
| using_or_as PASSWORD_SYM '(' TEXT_STRING ')' | using_or_as PASSWORD_SYM '(' TEXT_STRING ')'
{ {
if (!($$=(USER_AUTH*) thd->calloc(sizeof(USER_AUTH)))) if (!($$=thd->calloc<USER_AUTH>(1)))
MYSQL_YYABORT; MYSQL_YYABORT;
$$->pwtext= $4; $$->pwtext= $4;
} }
@ -18441,14 +18439,14 @@ xid:
text_string text_string
{ {
MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE); MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE);
if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID))))) if (unlikely(!(Lex->xid= thd->alloc<XID>(1))))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->xid->set(1L, $1->ptr(), $1->length(), 0, 0); Lex->xid->set(1L, $1->ptr(), $1->length(), 0, 0);
} }
| text_string ',' text_string | text_string ',' text_string
{ {
MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE); MYSQL_YYABORT_UNLESS($1->length() <= MAXGTRIDSIZE && $3->length() <= MAXBQUALSIZE);
if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID))))) if (unlikely(!(Lex->xid= thd->alloc<XID>(1))))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->xid->set(1L, $1->ptr(), $1->length(), $3->ptr(), $3->length()); Lex->xid->set(1L, $1->ptr(), $1->length(), $3->ptr(), $3->length());
} }
@ -18458,7 +18456,7 @@ xid:
$3->length() <= MAXBQUALSIZE && $3->length() <= MAXBQUALSIZE &&
$5 <= static_cast<ulong>( $5 <= static_cast<ulong>(
std::numeric_limits<int32_t>::max())); std::numeric_limits<int32_t>::max()));
if (unlikely(!(Lex->xid=(XID *)thd->alloc(sizeof(XID))))) if (unlikely(!(Lex->xid= thd->alloc<XID>(1))))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->xid->set($5, $1->ptr(), $1->length(), $3->ptr(), $3->length()); Lex->xid->set($5, $1->ptr(), $1->length(), $3->ptr(), $3->length());
} }

View File

@ -2932,7 +2932,7 @@ private:
break; break;
case SYSTEM_TIME_AS_OF: 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; MYSQL_TIME ltime;
thd->variables.time_zone->gmt_sec_to_TIME(&ltime, val.unix_time); thd->variables.time_zone->gmt_sec_to_TIME(&ltime, val.unix_time);
@ -2993,7 +2993,7 @@ private:
const Charset_collation_map_st &map) const Charset_collation_map_st &map)
{ {
size_t nbytes= map.text_format_nbytes_needed(); 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); size_t length= map.print(buf, nbytes);
buf[length]= '\0'; buf[length]= '\0';
return (uchar *) buf; return (uchar *) buf;
@ -3003,8 +3003,7 @@ private:
bool do_check(THD *thd, set_var *var) override bool do_check(THD *thd, set_var *var) override
{ {
Charset_collation_map_st *map= (Charset_collation_map_st*) Charset_collation_map_st *map= thd->alloc<Charset_collation_map_st>(1);
thd->alloc(sizeof(Charset_collation_map_st));
if (!map || charset_collation_map_from_item(map, var->value, if (!map || charset_collation_map_from_item(map, var->value,
thd->get_utf8_flag())) thd->get_utf8_flag()))
return true; return true;

View File

@ -6122,10 +6122,7 @@ allocate:
/* Create view fields translation table */ /* Create view fields translation table */
if (!(transl= if (!(transl= thd->alloc<Field_translator>(select->item_list.elements)))
(Field_translator*)(thd->
alloc(select->item_list.elements *
sizeof(Field_translator)))))
{ {
res= TRUE; res= TRUE;
goto exit; goto exit;
@ -10186,7 +10183,7 @@ bool TABLE_LIST::change_refs_to_fields()
if (!used_items.elements) if (!used_items.elements)
return FALSE; return FALSE;
materialized_items= (Item **)thd->calloc(sizeof(void *) * table->s->fields); materialized_items= thd->calloc<Item*>(table->s->fields);
ctx= new (thd->mem_root) Name_resolution_context(this); ctx= new (thd->mem_root) Name_resolution_context(this);
if (!materialized_items || !ctx) if (!materialized_items || !ctx)
return TRUE; return TRUE;

View File

@ -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 max_res_length--; // Reserve place for end null
set_if_smaller(new_length, max_res_length); 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 return pos; // Error
if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin)) if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin))

View File

@ -374,7 +374,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING &table,
if (!create_info->tabledef_version.str) if (!create_info->tabledef_version.str)
{ {
uchar *to= (uchar*) thd->alloc(MY_UUID_SIZE); uchar *to= thd->alloc<uchar>(MY_UUID_SIZE);
if (unlikely(!to)) if (unlikely(!to))
DBUG_RETURN(frm); DBUG_RETURN(frm);
my_uuid(to); my_uuid(to);
@ -911,12 +911,10 @@ static bool pack_header(THD *thd, uchar *forminfo,
*/ */
uint count= field->typelib()->count; uint count= field->typelib()->count;
field->save_interval= field->typelib(); field->save_interval= field->typelib();
field->set_typelib(tmpint= (TYPELIB*) thd->alloc(sizeof(TYPELIB))); field->set_typelib(tmpint= thd->alloc<TYPELIB>(1));
*tmpint= *field->save_interval; *tmpint= *field->save_interval;
tmpint->type_names= tmpint->type_names= thd->alloc<const char*>(count + 1);
(const char **) thd->alloc(sizeof(char*) * tmpint->type_lengths= thd->alloc<uint>(count + 1);
(count + 1));
tmpint->type_lengths= (uint *) thd->alloc(sizeof(uint) * (count + 1));
tmpint->type_names[count]= 0; tmpint->type_names[count]= 0;
tmpint->type_lengths[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]; length= field->save_interval->type_lengths[pos];
hex_length= length * 2; hex_length= length * 2;
tmpint->type_lengths[pos]= (uint) hex_length; 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); octet2hex(dst, (uchar*)src, length);
} }
} }

View File

@ -1239,7 +1239,7 @@ int ha_maria::write_row(const uchar * buf)
int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt)
{ {
int error, fatal_error; int error, fatal_error;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
MARIA_SHARE *share= file->s; MARIA_SHARE *share= file->s;
const char *old_proc_info; const char *old_proc_info;
TRN *old_trn= file->trn; 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 ha_maria::analyze(THD *thd, HA_CHECK_OPT * check_opt)
{ {
int error= 0; int error= 0;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
MARIA_SHARE *share= file->s; MARIA_SHARE *share= file->s;
const char *old_proc_info; 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 ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
ha_rows start_records; ha_rows start_records;
const char *old_proc_info; 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 ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
TRN *old_trn; TRN *old_trn;
MARIA_SHARE *share= file->s; 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 ha_maria::optimize(THD * thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
if (!file || !param) if (!file || !param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
@ -1921,7 +1921,7 @@ int ha_maria::preload_keys(THD * thd, HA_CHECK_OPT *check_opt)
errmsg= buf; errmsg= buf;
} }
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
if (!param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
@ -2032,7 +2032,7 @@ int ha_maria::enable_indexes(key_map map, bool persist)
else else
{ {
THD *thd= table->in_use; THD *thd= table->in_use;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
if (!param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;

View File

@ -997,7 +997,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
{ {
if (!file) return HA_ADMIN_INTERNAL_ERROR; if (!file) return HA_ADMIN_INTERNAL_ERROR;
int error; int error;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
MYISAM_SHARE* share = file->s; MYISAM_SHARE* share = file->s;
const char *old_proc_info=thd->proc_info; 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 ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
{ {
int error=0; int error=0;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
MYISAM_SHARE* share = file->s; MYISAM_SHARE* share = file->s;
if (!param) 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 ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
ha_rows start_records; ha_rows start_records;
if (!file || !param) return HA_ADMIN_INTERNAL_ERROR; 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 ha_myisam::optimize(THD* thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
if (!file || !param) return HA_ADMIN_INTERNAL_ERROR; 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) if (error != HA_ADMIN_OK)
{ {
/* Send error to user */ /* Send error to user */
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
if (!param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
@ -1528,7 +1528,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt)
err: err:
{ {
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
if (!param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
myisamchk_init(param); myisamchk_init(param);
@ -1633,7 +1633,7 @@ int ha_myisam::enable_indexes(key_map map, bool persist)
{ {
THD *thd= table->in_use; THD *thd= table->in_use;
int was_error= thd->is_error(); int was_error= thd->is_error();
HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param); HA_CHECK *param= thd->alloc<HA_CHECK>(1);
const char *save_proc_info=thd->proc_info; const char *save_proc_info=thd->proc_info;
if (!param) if (!param)

View File

@ -462,7 +462,7 @@ int ha_myisammrg::add_children_list(void)
LEX_CSTRING db; LEX_CSTRING db;
LEX_CSTRING table_name; LEX_CSTRING table_name;
child_l= (TABLE_LIST*) thd->alloc(sizeof(TABLE_LIST)); child_l= thd->alloc<TABLE_LIST>(1);
db.str= (char*) thd->memdup(mrg_child_def->db.str, mrg_child_def->db.length+1); db.str= (char*) thd->memdup(mrg_child_def->db.str, mrg_child_def->db.length+1);
db.length= mrg_child_def->db.length; db.length= mrg_child_def->db.length;
table_name.str= (char*) thd->memdup(mrg_child_def->name.str, 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; TABLE_LIST *ptr;
if (!(ptr= (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST)))) if (!(ptr= thd->calloc<TABLE_LIST>(1)))
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
if (!(ptr->table_name.str= thd->strmake(child_table->table_name.str, 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++; ntables++;
/* Allocate a table_names array in thread mem_root. */ /* 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<const char*>(ntables + 1)))
DBUG_RETURN(HA_ERR_OUT_OF_MEM); /* purecov: inspected */ DBUG_RETURN(HA_ERR_OUT_OF_MEM); /* purecov: inspected */
/* Create child path names. */ /* Create child path names. */

View File

@ -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 == true, then allocate a new context from mem_root and store in TLS.
If scan == false, then restore from TLS. If scan == false, then restore from TLS.
*/ */
m_context= (table_global_status_context *)current_thd->alloc(sizeof(table_global_status_context)); m_context= current_thd->alloc<table_global_status_context>(1);
new(m_context) table_global_status_context(status_version, !scan); new (m_context) table_global_status_context(status_version, !scan);
return 0; return 0;
} }

View File

@ -146,7 +146,7 @@ void table_host_cache::materialize(THD *thd)
goto end; goto end;
} }
rows= (row_host_cache*) thd->alloc(size * sizeof(row_host_cache)); rows= thd->alloc<row_host_cache>(size);
if (rows == NULL) if (rows == NULL)
{ {
/* Out of memory, this thread will error out. */ /* Out of memory, this thread will error out. */

View File

@ -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 == true, then allocate a new context from mem_root and store in TLS.
If scan == false, then restore from TLS. If scan == false, then restore from TLS.
*/ */
m_context= (table_session_status_context *)current_thd->alloc(sizeof(table_session_status_context)); m_context= current_thd->alloc<table_session_status_context>(1);
new(m_context) table_session_status_context(status_version, !scan); new (m_context) table_session_status_context(status_version, !scan);
return 0; return 0;
} }

View File

@ -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, allocate a new context from mem_root and store in TLS. If scan == false,
then restore from TLS. then restore from TLS.
*/ */
m_context= (table_status_by_account_context *)current_thd->alloc(sizeof(table_status_by_account_context)); m_context= current_thd->alloc<table_status_by_account_context>(1);
new(m_context) table_status_by_account_context(status_version, !scan); new (m_context) table_status_by_account_context(status_version, !scan);
return 0; return 0;
} }

View File

@ -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, allocate a new context from mem_root and store in TLS. If scan == false,
then restore from TLS. then restore from TLS.
*/ */
m_context= (table_status_by_host_context *)current_thd->alloc(sizeof(table_status_by_host_context)); m_context= current_thd->alloc<table_status_by_host_context>(1);
new(m_context) table_status_by_host_context(status_version, !scan); new (m_context) table_status_by_host_context(status_version, !scan);
return 0; return 0;
} }

View File

@ -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, allocate a new context from mem_root and store in TLS. If scan == false,
then restore from TLS. then restore from TLS.
*/ */
m_context= (table_status_by_thread_context *)current_thd->alloc(sizeof(table_status_by_thread_context)); m_context= current_thd->alloc<table_status_by_thread_context>(1);
new(m_context) table_status_by_thread_context(status_version, !scan); new (m_context) table_status_by_thread_context(status_version, !scan);
return 0; return 0;
} }

View File

@ -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, allocate a new context from mem_root and store in TLS. If scan == false,
then restore from TLS. then restore from TLS.
*/ */
m_context= (table_status_by_user_context *)current_thd->alloc(sizeof(table_status_by_user_context)); m_context= current_thd->alloc<table_status_by_user_context>(1);
new(m_context) table_status_by_user_context(status_version, !scan); new (m_context) table_status_by_user_context(status_version, !scan);
return 0; return 0;
} }

View File

@ -6431,8 +6431,7 @@ int spider_db_mbase_util::append_join(spider_fields *fields,
} }
ti.rewind(); ti.rewind();
if (!(table= static_cast<TABLE_LIST **>(thd->alloc(sizeof(TABLE_LIST*) * if (!(table= thd->alloc<TABLE_LIST *>(tables_to_print)))
tables_to_print))))
DBUG_RETURN(HA_ERR_OUT_OF_MEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM);
TABLE_LIST *tmp, **t= table + (tables_to_print - 1); TABLE_LIST *tmp, **t= table + (tables_to_print - 1);