cleanup: replace thd->calloc<T>(N) with operator new T[N] {}

### Preamble

C++ initializes objects in three stages:
1. Optionally, zero-initializes the object fields.
2. Member-initializes fields that are explicitly set.
3. If applicable, calls a constructor.

The following expressions:
x = new T[N];
x = new T;
T x;

only member-initialize and call a default constructor. Stage 1 is skipped,
because () braces are omitted.

This is known as default-initialization.

Apart from Stage 2, the following:
x = new T[N]();
x = new T();
const T &x = T();

Is known as value-initialization:
If no default constructor is present, infer zero-initialization.
Otherwise, the default constructor is called.

Note that it's not possible to write `T x();`, as it is ambiguous to a function
call.

Since C++11, it's also possible to zero initialize objects with '{}' braces:
x = new T[N]{};
x = new T{};
T x{};

This also both zero-initializes and calls a default constructor.

There is no much difference in between empty-braced () and {}. Both call a
default constructor or initializer-list constructor, when available. Having both
constructors is ambiguous.

Scalars (i.e. fundamental data types) and POD types have no constructor.
Therefore, stage 2 for them is skipped.

Other than that, there is no much difference in the result

Exambles:
new char[123] -- would return an uninitialized array of char.
new char[123]() -- forces zero-initialization
new char[123]{} -- forces zero-initialization
new char[123]{123} -- forces zero-initialization, and also value-initializes
 the first element to 123

struct A {
  int x = 0xaf;
  int y;
}

All of the following:
A a;
A *a = new A;
A *a = new A[123];

Causes member A::x be initialized to 0xaf, since it happens at
value-initialization stage. A::y is left uninitialized.

A *a = new A[123] {};
and other similars result in {.x=0xaf, .y=0}.

### In this commit

Change all the calls to thd->calloc() to new(thd) T[N]{}, or new(thd) T{}.

POD types will be zero-initialized, so a special attention should be put to
classes with default constructors.

Among all uses, two cases of interest were found:
1. TABLE_LIST: has a default constructor TABLE_LIST() = default. This infers
zero-initialization behavior (i.e. as if there's no constructor).
2. USER_AUTH: has a default constructor, that initializes all fields. Strings
are initialized to "", which is fine.
3. Security_context: had a custom default constructor, initializing only two
fields. It was removed, and fields are made member-initialized.
This commit is contained in:
Nikita Malyavin 2024-12-10 22:56:06 +01:00
commit 5d7f6f7e6e
27 changed files with 82 additions and 92 deletions

View file

@ -1906,7 +1906,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
} while (++i < num_parts);
}
if (m_reorged_parts &&
!(m_reorged_file= thd->calloc<handler*>(m_reorged_parts + 1)))
!(m_reorged_file= new (thd) handler*[m_reorged_parts + 1]()))
{
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
@ -1936,7 +1936,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
}
} while (++i < num_parts);
}
if (!(new_file_array= thd->calloc<handler*>(2*(num_remain_partitions + 1))))
if (!(new_file_array= new (thd) handler*[2*(num_remain_partitions + 1)]()))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
m_added_file= &new_file_array[num_remain_partitions + 1];

View file

@ -2824,8 +2824,8 @@ Item_sp::Item_sp(THD *thd, Name_resolution_context *context_arg,
context(context_arg), m_name(name_arg), m_sp(NULL), func_ctx(NULL),
sp_result_field(NULL)
{
dummy_table= (TABLE*) thd->calloc(sizeof(TABLE) + sizeof(TABLE_SHARE) +
sizeof(Query_arena));
dummy_table= (TABLE*) thd_calloc(thd, sizeof(TABLE) + sizeof(TABLE_SHARE) +
sizeof(Query_arena));
dummy_table->s= (TABLE_SHARE*) (dummy_table + 1);
sp_query_arena= new(dummy_table->s + 1) Query_arena();
memset(&sp_mem_root, 0, sizeof(sp_mem_root));
@ -2835,8 +2835,8 @@ Item_sp::Item_sp(THD *thd, Item_sp *item):
context(item->context), m_name(item->m_name),
m_sp(item->m_sp), func_ctx(NULL), sp_result_field(NULL)
{
dummy_table= (TABLE*) thd->calloc(sizeof(TABLE)+ sizeof(TABLE_SHARE) +
sizeof(Query_arena));
dummy_table= (TABLE*) thd_calloc(thd, sizeof(TABLE)+ sizeof(TABLE_SHARE) +
sizeof(Query_arena));
dummy_table->s= (TABLE_SHARE*) (dummy_table+1);
sp_query_arena= new(dummy_table->s + 1) Query_arena();
memset(&sp_mem_root, 0, sizeof(sp_mem_root));
@ -10899,7 +10899,7 @@ int Item_cache_str::save_in_field(Field *field, bool no_conversions)
bool Item_cache_row::allocate(THD *thd, uint num)
{
item_count= num;
return (!values && !(values= thd->calloc<Item_cache *>(item_count)));
return (!values && !(values= new (thd) Item_cache *[item_count] {}));
}

View file

@ -4066,7 +4066,7 @@ Item *in_decimal::create_item(THD *thd)
bool Predicant_to_list_comparator::alloc_comparators(THD *thd, uint nargs)
{
m_comparators= thd->calloc<Predicant_to_value_comparator>(nargs);
m_comparators= new (thd) Predicant_to_value_comparator[nargs] {};
return m_comparators == NULL;
}
@ -4198,7 +4198,7 @@ bool cmp_item_row::alloc_comparators(THD *thd, uint cols)
DBUG_ASSERT(cols == n);
return false;
}
return !(comparators= thd->calloc<cmp_item *>(n= cols));
return !(comparators= new (thd) cmp_item *[n= cols] {});
}

View file

@ -510,7 +510,7 @@ bool JOIN::check_for_splittable_materialized()
the collected info on potential splittability of T
*/
SplM_opt_info *spl_opt_info= new (thd) SplM_opt_info();
SplM_field_info *spl_field= thd->calloc<SplM_field_info>(spl_field_cnt);
SplM_field_info *spl_field= new (thd) SplM_field_info[spl_field_cnt] {};
if (!(spl_opt_info && spl_field)) // consider T as not good for splitting
return false;

View file

@ -2153,7 +2153,7 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
*remove_item= TRUE;
if (!(tbl_alias.str= thd->calloc(SUBQERY_TEMPTABLE_NAME_MAX_LEN)) ||
if (!(tbl_alias.str= new (thd) char[SUBQERY_TEMPTABLE_NAME_MAX_LEN] {}) ||
!(jtbm= alloc_join_nest(thd))) //todo: this is not a join nest!
{
DBUG_RETURN(TRUE);
@ -2232,8 +2232,8 @@ static bool convert_subq_to_jtbm(JOIN *parent_join,
static TABLE_LIST *alloc_join_nest(THD *thd)
{
TABLE_LIST *tbl;
if (!(tbl= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
sizeof(NESTED_JOIN))))
if (!(tbl= (TABLE_LIST*) thd_calloc(thd, ALIGN_SIZE(sizeof(TABLE_LIST))+
sizeof(NESTED_JOIN))))
return NULL;
tbl->nested_join= (NESTED_JOIN*) ((uchar*)tbl +
ALIGN_SIZE(sizeof(TABLE_LIST)));
@ -4437,7 +4437,7 @@ bool setup_sj_materialization_part2(JOIN_TAB *sjm_tab)
tab_ref->key= 0; /* The only temp table index. */
tab_ref->key_length= tmp_key->key_length;
if (!(tab_ref->key_buff=
thd->calloc<uchar>(ALIGN_SIZE(tmp_key->key_length) * 2)) ||
new (thd) uchar[ALIGN_SIZE(tmp_key->key_length) * 2] {}) ||
!(tab_ref->key_copy= new (thd) store_key*[tmp_key_parts + 1]) ||
!(tab_ref->items= new (thd) Item*[tmp_key_parts]))
DBUG_RETURN(TRUE); /* purecov: inspected */
@ -4477,7 +4477,7 @@ bool setup_sj_materialization_part2(JOIN_TAB *sjm_tab)
We don't ever have guarded conditions for SJM tables, but code at SQL
layer depends on cond_guards array being alloced.
*/
if (!(tab_ref->cond_guards= thd->calloc<bool*>(tmp_key_parts)))
if (!(tab_ref->cond_guards= new (thd) bool*[tmp_key_parts] {}))
{
DBUG_RETURN(TRUE);
}

View file

@ -305,7 +305,7 @@ char *partition_info::create_default_partition_names(THD *thd, uint part_no,
uint num_parts_arg,
uint start_no)
{
char *ptr= thd->calloc(num_parts_arg * MAX_PART_NAME_SIZE + 1);
char *ptr= new (thd) char[num_parts_arg * MAX_PART_NAME_SIZE + 1] {};
char *move_ptr= ptr;
uint i= 0;
DBUG_ENTER("create_default_partition_names");
@ -339,7 +339,7 @@ char *partition_info::create_default_subpartition_name(THD *thd, uint subpart_no
const char *part_name)
{
size_t size_alloc= strlen(part_name) + MAX_PART_NAME_SIZE;
char *ptr= thd->calloc(size_alloc);
char *ptr= new (thd) char[size_alloc] {};
DBUG_ENTER("create_default_subpartition_name");
if (likely(ptr != NULL))
@ -1665,10 +1665,10 @@ bool partition_info::set_up_charset_field_preps(THD *thd)
while ((field= *(ptr++)))
if (field_is_partition_charset(field))
tot_part_fields++;
if (!(char_ptrs= thd->calloc<uchar*>(tot_part_fields)))
if (!(char_ptrs= new (thd) uchar*[tot_part_fields] {}))
goto error;
part_field_buffers= char_ptrs;
if (!(char_ptrs= thd->calloc<uchar*>(tot_part_fields)))
if (!(char_ptrs= new (thd) uchar*[tot_part_fields] {}))
goto error;
restore_part_field_ptrs= char_ptrs;
if (!(char_ptrs= new (thd) uchar*[tot_part_fields + 1]))
@ -1681,7 +1681,7 @@ bool partition_info::set_up_charset_field_preps(THD *thd)
if (field_is_partition_charset(field))
{
uchar *field_buf;
if (!(field_buf= thd->calloc<uchar>(field->pack_length())))
if (!(field_buf= new (thd) uchar[field->pack_length()] {}))
goto error;
part_charset_field_array[i]= field;
part_field_buffers[i++]= field_buf;
@ -1697,10 +1697,10 @@ bool partition_info::set_up_charset_field_preps(THD *thd)
while ((field= *(ptr++)))
if (field_is_partition_charset(field))
tot_subpart_fields++;
if (!(char_ptrs= (uchar**) thd->calloc<uchar*>(tot_subpart_fields)))
if (!(char_ptrs= (uchar**) new (thd) uchar*[tot_subpart_fields] {}))
goto error;
subpart_field_buffers= char_ptrs;
if (!(char_ptrs= (uchar**) thd->calloc<uchar*>(tot_subpart_fields)))
if (!(char_ptrs= (uchar**) new (thd) uchar*[tot_subpart_fields] {}))
goto error;
restore_subpart_field_ptrs= char_ptrs;
if (!(char_ptrs= (uchar**) new (thd) uchar*[tot_subpart_fields + 1]))
@ -1714,7 +1714,7 @@ bool partition_info::set_up_charset_field_preps(THD *thd)
if (!field_is_partition_charset(field))
continue;
if (!(field_buf= thd->calloc<uchar>(field->pack_length())))
if (!(field_buf= new (thd) uchar[field->pack_length()] {}))
goto error;
subpart_charset_field_array[i]= field;
subpart_field_buffers[i++]= field_buf;
@ -2028,7 +2028,7 @@ bool partition_info::init_column_part(THD *thd)
uint loc_num_columns;
DBUG_ENTER("partition_info::init_column_part");
if (!(list_val= thd->calloc<part_elem_value>(1)) ||
if (!(list_val= new (thd) part_elem_value {}) ||
p_elem->list_val_list.push_back(list_val, thd->mem_root))
DBUG_RETURN(TRUE);
@ -2036,7 +2036,7 @@ bool partition_info::init_column_part(THD *thd)
loc_num_columns= num_columns;
else
loc_num_columns= MAX_REF_PARTS;
if (!(col_val_array= thd->calloc<part_column_list_val>(loc_num_columns)))
if (!(col_val_array= new (thd) part_column_list_val[loc_num_columns] {}))
DBUG_RETURN(TRUE);
list_val->col_val_array= col_val_array;

View file

@ -399,11 +399,10 @@ void TABLE::init_cost_info_for_usable_range_rowid_filters(THD *thd)
if (!range_rowid_filter_cost_info_elems)
return;
range_rowid_filter_cost_info_ptr= thd->calloc<Range_rowid_filter_cost_info*>
(range_rowid_filter_cost_info_elems);
range_rowid_filter_cost_info=
new (thd)
Range_rowid_filter_cost_info[range_rowid_filter_cost_info_elems];
size_t arr_sz= range_rowid_filter_cost_info_elems;
range_rowid_filter_cost_info_ptr=
new (thd) Range_rowid_filter_cost_info*[arr_sz] {};
range_rowid_filter_cost_info= new (thd) Range_rowid_filter_cost_info[arr_sz];
if (!range_rowid_filter_cost_info_ptr || !range_rowid_filter_cost_info)
{
range_rowid_filter_cost_info_elems= 0;

View file

@ -1420,7 +1420,7 @@ resolve_engine_list(THD *thd, const char *str_arg, size_t str_arg_len,
}
if (temp_copy)
res= thd->calloc<plugin_ref>(count+1);
res= new (thd) plugin_ref[count+1] {};
else
res= (plugin_ref *)my_malloc(PSI_INSTRUMENT_ME, (count+1)*sizeof(*res), MYF(MY_ZEROFILL|MY_WME));
if (!res)

View file

@ -3577,7 +3577,7 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check)
}
else
{
if (!(tab= thd->calloc<SP_TABLE>(1)))
if (!(tab= new (thd) SP_TABLE {}))
return FALSE;
if ((lex_for_tmp_check->sql_command == SQLCOM_CREATE_TABLE ||
lex_for_tmp_check->sql_command == SQLCOM_CREATE_SEQUENCE) &&
@ -3708,7 +3708,7 @@ sp_add_to_query_tables(THD *thd, LEX *lex,
{
TABLE_LIST *table;
if (!(table= thd->calloc<TABLE_LIST>(1)))
if (!(table= new (thd) TABLE_LIST {}))
return NULL;
if (!thd->make_lex_string(&table->db, db->str, db->length) ||
!thd->make_lex_string(&table->table_name, name->str, name->length) ||

View file

@ -172,7 +172,7 @@ bool sp_rcontext::alloc_arrays(THD *thd)
{
size_t n= m_root_parsing_ctx->get_num_case_exprs();
m_case_expr_holders.reset(thd->calloc<Item_cache *>(n), n);
m_case_expr_holders.reset(new (thd) Item_cache *[n] {}, n);
}
return !m_cstack.array() || !m_case_expr_holders.array();

View file

@ -1196,7 +1196,7 @@ void *thd_alloc(const MYSQL_THD thd, size_t size)
extern "C"
void *thd_calloc(const MYSQL_THD thd, size_t size)
{
return thd->calloc(size);
return new (thd) char[size] {};
}
extern "C"

View file

@ -1278,14 +1278,6 @@ public:
inline bool is_conventional() const
{ return state == STMT_CONVENTIONAL_EXECUTION; }
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
{ return strdup_root(mem_root,str); }
inline char *strmake(const char *str, size_t size) const
@ -1774,10 +1766,6 @@ struct st_savepoint {
class Security_context {
public:
Security_context()
:master_access(NO_ACL),
db_access(NO_ACL)
{} /* Remove gcc warning */
/*
host - host of the client
user - user of the client, set to NULL until the user has been read from
@ -1797,8 +1785,8 @@ public:
char *external_user;
/* points to host if host is available, otherwise points to ip */
const char *host_or_ip;
privilege_t master_access; /* Global privileges from mysql.user */
privilege_t db_access; /* Privileges for current db */
privilege_t master_access= NO_ACL; /* Global privileges from mysql.user */
privilege_t db_access= NO_ACL; /* Privileges for current db */
bool password_expired;

View file

@ -1333,7 +1333,7 @@ static bool find_db_tables_and_rm_known_files(THD *thd, MY_DIR *dirp,
const LEX_CSTRING *table= files.at(idx);
/* Drop the table nicely */
TABLE_LIST *table_list= thd->calloc<TABLE_LIST>(1);
TABLE_LIST *table_list= new (thd) TABLE_LIST {};
if (!table_list)
DBUG_RETURN(true);

View file

@ -1099,7 +1099,7 @@ multi_delete::multi_delete(THD *thd_arg, TABLE_LIST *dt, uint num_of_tables_arg)
num_of_tables(num_of_tables_arg), error(0),
do_delete(0), transactional_tables(0), normal_tables(0), error_handled(0)
{
tempfiles= thd_arg->calloc<Unique*>(num_of_tables);
tempfiles= new (thd_arg) 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);
}
derived->nested_join= thd->calloc<NESTED_JOIN>(1);
derived->nested_join= new (thd) NESTED_JOIN {};
if (!derived->nested_join)
{
res= TRUE;

View file

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

View file

@ -3673,7 +3673,7 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
if (!ref_pointer_array.is_null())
return false;
Item **array= thd->active_stmt_arena_to_use()->calloc<Item*>(n_elems);
Item **array= new (thd->active_stmt_arena_to_use()) Item*[n_elems] {};
if (likely(array != NULL))
ref_pointer_array= Ref_ptr_array(array, n_elems);
return array == NULL;
@ -12360,7 +12360,7 @@ LEX_USER *LEX::current_user_for_set_password(THD *thd)
return NULL;
}
LEX_USER *res;
if (unlikely(!(res= thd->calloc<LEX_USER>(1))))
if (unlikely(!(res= new (thd) LEX_USER {})))
return NULL;
res->user= current_user;
return res;

View file

@ -8233,8 +8233,9 @@ bool st_select_lex::init_nested_join(THD *thd)
NESTED_JOIN *nested_join;
DBUG_ENTER("init_nested_join");
if (unlikely(!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
sizeof(NESTED_JOIN)))))
if (unlikely(!(ptr= (TABLE_LIST*) thd_calloc(thd,
ALIGN_SIZE(sizeof(TABLE_LIST)) +
sizeof(NESTED_JOIN)))))
DBUG_RETURN(1);
nested_join= ptr->nested_join=
((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
@ -8321,8 +8322,9 @@ TABLE_LIST *st_select_lex::nest_last_join(THD *thd)
DBUG_RETURN(head);
}
if (unlikely(!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
sizeof(NESTED_JOIN)))))
if (unlikely(!(ptr= (TABLE_LIST*) thd_calloc(thd,
ALIGN_SIZE(sizeof(TABLE_LIST))+
sizeof(NESTED_JOIN)))))
DBUG_RETURN(0);
nested_join= ptr->nested_join=
((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
@ -8565,8 +8567,8 @@ bool st_select_lex::add_cross_joined_table(TABLE_LIST *left_op,
of left_op in it. Initially the nest is empty.
*/
if (unlikely(!(cj_nest=
(TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
sizeof(NESTED_JOIN)))))
(TABLE_LIST*) thd_calloc(thd, ALIGN_SIZE(sizeof(TABLE_LIST))+
sizeof(NESTED_JOIN)))))
DBUG_RETURN(true);
cj_nest->nested_join=
((NESTED_JOIN*) ((uchar*) cj_nest + ALIGN_SIZE(sizeof(TABLE_LIST))));

View file

@ -364,7 +364,7 @@ static bool set_up_field_array(THD *thd, TABLE *table, bool is_sub_part)
DBUG_ASSERT(!is_sub_part);
DBUG_RETURN(FALSE);
}
field_array= thd->calloc<Field*>(num_fields + 1);
field_array= new (thd) Field*[num_fields + 1] {};
if (unlikely(!field_array))
DBUG_RETURN(TRUE);
@ -484,7 +484,7 @@ static bool create_full_part_field_array(THD *thd, TABLE *table,
if (field->flags & FIELD_IN_PART_FUNC_FLAG)
num_part_fields++;
}
field_array= thd->calloc<Field*>(num_part_fields + 1);
field_array= new (thd) Field*[num_part_fields + 1] {};
if (unlikely(!field_array))
{
result= TRUE;
@ -1286,8 +1286,9 @@ static bool check_range_constants(THD *thd, partition_info *part_info)
part_column_list_val *UNINIT_VAR(current_largest_col_val);
uint num_column_values= part_info->part_field_list.elements;
uint size_entries= sizeof(part_column_list_val) * num_column_values;
part_info->range_col_array= thd->calloc<part_column_list_val>
(part_info->num_parts * num_column_values);
uint arr_size= part_info->num_parts * num_column_values;
part_info->range_col_array= new (thd) part_column_list_val[arr_size] {};
if (unlikely(part_info->range_col_array == NULL))
goto end;
@ -1440,7 +1441,7 @@ static bool check_list_constants(THD *thd, partition_info *part_info)
size_entries= part_info->column_list ?
(num_column_values * sizeof(part_column_list_val)) :
sizeof(LIST_PART_ENTRY);
if (!(ptr= thd->calloc((part_info->num_list_values+1) * size_entries)))
if (!(ptr= new (thd) char[(part_info->num_list_values+1) * size_entries] {}))
goto end;
if (part_info->column_list)
{

View file

@ -13391,7 +13391,7 @@ static bool create_hj_key_for_table(JOIN *join, JOIN_TAB *join_tab,
keyinfo->is_statistics_from_stat_tables= FALSE;
keyinfo->name.str= "$hj";
keyinfo->name.length= 3;
keyinfo->rec_per_key= thd->calloc<ulong>(key_parts);
keyinfo->rec_per_key= new (thd) ulong[key_parts] {};
if (!keyinfo->rec_per_key)
DBUG_RETURN(TRUE);
keyinfo->key_part= key_part_info;
@ -13549,7 +13549,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j,
j->ref.key_parts= keyparts;
j->ref.key_length= length;
j->ref.key= (int) key;
if (!(j->ref.key_buff= thd->calloc<uchar>(ALIGN_SIZE(length)*2)) ||
if (!(j->ref.key_buff= new (thd) uchar[ALIGN_SIZE(length)*2] {}) ||
!(j->ref.key_copy= new (thd) store_key*[keyparts+1]) ||
!(j->ref.items= new (thd) Item*[keyparts]) ||
!(j->ref.cond_guards= new (thd) bool*[keyparts]))
@ -16755,7 +16755,7 @@ bool TABLE_REF::tmp_table_index_lookup_init(THD *thd,
key= 0; /* The only temp table index. */
key_length= tmp_key->key_length;
if (!(key_buff= thd->calloc<uchar>(ALIGN_SIZE(tmp_key->key_length) * 2)) ||
if (!(key_buff= new (thd) uchar[ALIGN_SIZE(tmp_key->key_length) * 2] {}) ||
!(key_copy= new (thd) store_key*[tmp_key_parts + 1]) ||
!(items= new (thd) Item*[tmp_key_parts]))
DBUG_RETURN(TRUE);
@ -28687,7 +28687,7 @@ create_distinct_group(THD *thd, Ref_ptr_array ref_pointer_array,
if ((*ord_iter->item)->eq(item, 1))
goto next_item;
ORDER *ord= thd->calloc<ORDER>(1);
ORDER *ord= new (thd) ORDER {};
if (!ord)
return 0;
@ -29313,7 +29313,7 @@ bool JOIN::alloc_func_list()
}
/* This must use calloc() as rollup_make_fields depends on this */
sum_funcs= (Item_sum**) thd->calloc(sizeof(Item_sum**) * (func_count+1) +
sum_funcs= (Item_sum**) thd_calloc(thd, sizeof(Item_sum**) * (func_count+1) +
sizeof(Item_sum***) * (group_parts+1));
sum_funcs_end= (Item_sum***) (sum_funcs+func_count+1);
DBUG_RETURN(sum_funcs == 0);

View file

@ -3197,7 +3197,7 @@ mysql_prepare_create_table_finalize(THD *thd, HA_CREATE_INFO *create_info,
}
}
KEY *key_info= *key_info_buffer= thd->calloc<KEY>(*key_count);
KEY *key_info= *key_info_buffer= new (thd) KEY[*key_count] {};
if (!*key_info_buffer)
DBUG_RETURN(true); // Out of memory
@ -3260,7 +3260,7 @@ mysql_prepare_create_table_finalize(THD *thd, HA_CREATE_INFO *create_info,
DBUG_RETURN(TRUE);
}
key_part_info= thd->calloc<KEY_PART_INFO>(key_parts);
key_part_info= new (thd) KEY_PART_INFO[key_parts] {};
if (!key_part_info)
DBUG_RETURN(true); // Out of memory
@ -8438,9 +8438,9 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
restore_record(table, s->default_values); // Empty record for DEFAULT
if ((create_info->fields_option_struct=
thd->calloc<ha_field_option_struct*>(table->s->fields)) == NULL ||
new (thd) ha_field_option_struct*[table->s->fields] {}) == NULL ||
(create_info->indexes_option_struct=
thd->calloc<ha_index_option_struct*>(table->s->total_keys)) == NULL)
new (thd) ha_index_option_struct*[table->s->total_keys] {}) == NULL)
DBUG_RETURN(1);
if (merge_engine_options(table->s->option_list, create_info->option_list,

View file

@ -1934,8 +1934,8 @@ int multi_update::prepare(List<Item> &not_used_values,
table_count= update.elements;
update_tables= update.first;
tmp_tables = thd->calloc<TABLE*>(table_count);
tmp_table_param = thd->calloc<TMP_TABLE_PARAM>(table_count);
tmp_tables = new (thd) TABLE*[table_count] {};
tmp_table_param = new (thd) TMP_TABLE_PARAM[table_count] {};
fields_for_table= new (thd) List_item*[table_count];
values_for_table= new (thd) List_item*[table_count];
if (unlikely(thd->is_fatal_error))

View file

@ -1736,7 +1736,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
objects of the view.
*/
if (!(table->view_sctx=
thd->active_stmt_arena_to_use()->calloc<Security_context>(1)))
new (thd->active_stmt_arena_to_use()) Security_context {}))
goto err;
security_ctx= table->view_sctx;
}

View file

@ -14319,7 +14319,7 @@ show_param:
| GRANTS
{
Lex->sql_command= SQLCOM_SHOW_GRANTS;
if (unlikely(!(Lex->grant_user= thd->calloc<LEX_USER>(1))))
if (unlikely(!(Lex->grant_user= new (thd) LEX_USER {})))
MYSQL_YYABORT;
Lex->grant_user->user= current_user_and_current_role;
}
@ -14439,7 +14439,7 @@ show_param:
| CREATE USER_SYM
{
Lex->sql_command= SQLCOM_SHOW_CREATE_USER;
if (unlikely(!(Lex->grant_user= thd->calloc<LEX_USER>(1))))
if (unlikely(!(Lex->grant_user= new (thd) LEX_USER {})))
MYSQL_YYABORT;
Lex->grant_user->user= current_user;
}
@ -15939,7 +15939,7 @@ ident_or_text:
user_maybe_role:
ident_or_text
{
if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
if (unlikely(!($$= new (thd) LEX_USER {})))
MYSQL_YYABORT;
$$->user = $1;
@ -15950,7 +15950,7 @@ user_maybe_role:
}
| ident_or_text '@' ident_or_text
{
if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
if (unlikely(!($$= new (thd) LEX_USER {})))
MYSQL_YYABORT;
$$->user = $1; $$->host=$3;
@ -15974,7 +15974,7 @@ user_maybe_role:
}
| CURRENT_USER optional_braces
{
if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
if (unlikely(!($$= new (thd) LEX_USER {})))
MYSQL_YYABORT;
$$->user= current_user;
$$->auth= new (thd) USER_AUTH();
@ -17205,7 +17205,7 @@ option_value_no_option_type:
MYSQL_YYABORT;
LEX *lex = Lex;
LEX_USER *user;
if (unlikely(!(user= thd->calloc<LEX_USER>(1))))
if (unlikely(!(user= new (thd) LEX_USER {})))
MYSQL_YYABORT;
user->user= current_user;
set_var_default_role *var= (new (thd)
@ -17696,7 +17696,7 @@ role_list:
current_role:
CURRENT_ROLE optional_braces
{
if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
if (unlikely(!($$= new (thd) LEX_USER {})))
MYSQL_YYABORT;
$$->user= current_role;
}
@ -17711,7 +17711,7 @@ role_name: ident_or_text
((char*) $1.str)[$1.length] = '\0';
if (unlikely($1.length == 0))
my_yyabort_error((ER_INVALID_ROLE, MYF(0), ""));
if (unlikely(!($$= thd->calloc<LEX_USER>(1))))
if (unlikely(!($$= new (thd) LEX_USER {})))
MYSQL_YYABORT;
if (lex_string_eq(&$1, &none))
$$->user= none;
@ -17984,18 +17984,18 @@ auth_token:
opt_auth_str:
/* empty */
{
if (!($$=thd->calloc<USER_AUTH>(1)))
if (!($$=new (thd) USER_AUTH {}))
MYSQL_YYABORT;
}
| using_or_as TEXT_STRING_sys
{
if (!($$=thd->calloc<USER_AUTH>(1)))
if (!($$=new (thd) USER_AUTH {}))
MYSQL_YYABORT;
$$->auth_str= $2;
}
| using_or_as PASSWORD_SYM '(' TEXT_STRING ')'
{
if (!($$=thd->calloc<USER_AUTH>(1)))
if (!($$=new (thd) USER_AUTH {}))
MYSQL_YYABORT;
$$->pwtext= $4;
}

View file

@ -10218,7 +10218,7 @@ bool TABLE_LIST::change_refs_to_fields()
if (!used_items.elements)
return FALSE;
materialized_items= thd->calloc<Item*>(table->s->fields);
materialized_items= new (thd) Item*[table->s->fields] {};
ctx= new (thd) Name_resolution_context(this);
if (!materialized_items || !ctx)
return TRUE;

View file

@ -1456,7 +1456,7 @@ void ha_myisammrg::update_create_info(HA_CREATE_INFO *create_info)
{
TABLE_LIST *ptr;
if (!(ptr= thd->calloc<TABLE_LIST>(1)))
if (!(ptr= new (thd) TABLE_LIST()))
DBUG_VOID_RETURN;
if (!(ptr->table_name.str= thd->strmake(child_table->table_name.str,

View file

@ -174,7 +174,7 @@ bool PFS_table_context::initialize(void)
{
THD *thd= current_thd;
ulong words= m_map_size / m_word_size + (m_map_size % m_word_size > 0);
m_map= (ulong *)thd->calloc(words * m_word_size);
m_map= (ulong *)new (thd) char[words * m_word_size] {};
}
/* Write to TLS. */