Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/mysqldump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,10 @@ static void write_footer(FILE *sql_file)
} /* write_footer */


const uchar *get_table_key(const void *entry, size_t *length, my_bool)
const void *get_table_key(const void *entry, size_t *length, my_bool)
{
*length= strlen(static_cast<const char*>(entry));
return static_cast<const uchar*>(entry);
return entry;
}


Expand Down
6 changes: 2 additions & 4 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2787,12 +2787,10 @@ static void strip_parentheses(struct st_command *command)

C_MODE_START

static const uchar *get_var_key(const void *var, size_t *len, my_bool)
static const void *get_var_key(const void *var, size_t *len, my_bool)
{
char* key;
key= (static_cast<const VAR *>(var))->name;
*len= (static_cast<const VAR *>(var))->name_len;
return reinterpret_cast<const uchar *>(key);
return (static_cast<const VAR *>(var))->name;
}


Expand Down
4 changes: 2 additions & 2 deletions extra/mariabackup/xbstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ file_entry_new(extract_ctxt_t *ctxt, const char *path, uint pathlen,
}

static
const uchar *
const void *
get_file_entry_key(const void *entry_, size_t *length, my_bool)
{
const file_entry_t *entry= static_cast<const file_entry_t *>(entry_);
*length= entry->pathlen;
return reinterpret_cast<const uchar *>(entry->path);
return entry->path;
}

static
Expand Down
36 changes: 18 additions & 18 deletions include/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern "C" {
#define HASH_THREAD_SPECIFIC 2 /* Mark allocated memory THREAD_SPECIFIC */

typedef uint32 my_hash_value_type;
typedef const uchar *(*my_hash_get_key)(const void *, size_t *, my_bool);
typedef const void *(*my_hash_get_key)(const void *, size_t *, my_bool);
typedef my_hash_value_type (*my_hash_function)(CHARSET_INFO *,
const uchar *, size_t);
typedef void (*my_hash_free_key)(void *);
Expand Down Expand Up @@ -71,28 +71,28 @@ my_bool my_hash_init2(PSI_memory_key psi_key, HASH *hash, size_t growth_size,
void (*free_element)(void*), uint flags);
void my_hash_free(HASH *tree);
void my_hash_reset(HASH *hash);
uchar *my_hash_element(const HASH *hash, size_t idx);
uchar *my_hash_search(const HASH *info, const uchar *key, size_t length);
uchar *my_hash_search_using_hash_value(const HASH *info,
my_hash_value_type hash_value,
const uchar *key, size_t length);
void *my_hash_element(const HASH *hash, size_t idx);
void *my_hash_search(const HASH *info, const uchar *key, size_t length);
void *my_hash_search_using_hash_value(const HASH *info,
my_hash_value_type hash_value,
const uchar *key, size_t length);
my_hash_value_type my_hash_sort(CHARSET_INFO *cs,
const uchar *key, size_t length);
#define my_calc_hash(A, B, C) my_hash_sort((A)->charset, B, C)
uchar *my_hash_first(const HASH *info, const uchar *key, size_t length,
HASH_SEARCH_STATE *state);
uchar *my_hash_first_from_hash_value(const HASH *info,
my_hash_value_type hash_value,
const uchar *key,
size_t length,
HASH_SEARCH_STATE *state);
uchar *my_hash_next(const HASH *info, const uchar *key, size_t length,
void *my_hash_first(const HASH *info, const uchar *key, size_t length,
HASH_SEARCH_STATE *state);
my_bool my_hash_insert(HASH *info, const uchar *data);
my_bool my_hash_delete(HASH *hash, uchar *record);
my_bool my_hash_update(HASH *hash, uchar *record, uchar *old_key,
void *my_hash_first_from_hash_value(const HASH *info,
my_hash_value_type hash_value,
const uchar *key,
size_t length,
HASH_SEARCH_STATE *state);
void *my_hash_next(const HASH *info, const uchar *key, size_t length,
HASH_SEARCH_STATE *state);
my_bool my_hash_insert(HASH *info, const void *data);
my_bool my_hash_delete(HASH *hash, void *record);
my_bool my_hash_update(HASH *hash, void *record, uchar *old_key,
size_t old_key_length);
void my_hash_replace(HASH *hash, HASH_SEARCH_STATE *state, uchar *new_row);
void my_hash_replace(HASH *hash, HASH_SEARCH_STATE *state, void *new_row);
my_bool my_hash_check(HASH *hash); /* Only in debug library */
my_bool my_hash_iterate(HASH *hash, my_hash_walk_action action, void *argument);

Expand Down
12 changes: 6 additions & 6 deletions mysys/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,20 +685,20 @@ const char *my_collation_get_tailoring(uint id)
}


static const uchar *get_charset_key(const void *object, size_t *size,
my_bool not_used __attribute__((unused)))
static const void *get_charset_key(const void *object, size_t *size,
my_bool not_used __attribute__((unused)))
{
CHARSET_INFO *cs= object;
*size= cs->cs_name.length;
return (const uchar*) cs->cs_name.str;
return cs->cs_name.str;
}

static const uchar *get_collation_key(const void *object, size_t *length,
my_bool not_used __attribute__((unused)))
static const void *get_collation_key(const void *object, size_t *length,
my_bool not_used __attribute__((unused)))
{
CHARSET_INFO *cs= (CHARSET_INFO*) object;
*length= cs->coll_name.length;
return (const uchar*) cs->coll_name.str;
return cs->coll_name.str;
}

static void init_available_charsets(void)
Expand Down
58 changes: 29 additions & 29 deletions mysys/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
typedef struct st_hash_info {
uint32 next; /* index to next key */
my_hash_value_type hash_nr;
uchar *data; /* data for current entry */
void *data; /* data for current entry */
} HASH_LINK;

static uint my_hash_mask(my_hash_value_type hashnr,
Expand Down Expand Up @@ -190,7 +190,7 @@ void my_hash_reset(HASH *hash)
*/

static inline char*
my_hash_key(const HASH *hash, const uchar *record, size_t *length,
my_hash_key(const HASH *hash, const void *record, size_t *length,
my_bool first)
{
if (hash->get_key)
Expand Down Expand Up @@ -222,24 +222,24 @@ static
#if !defined(__USLC__) && !defined(__sgi)
inline
#endif
my_hash_value_type rec_hashnr(HASH *hash,const uchar *record)
my_hash_value_type rec_hashnr(HASH *hash, const void *record)
{
size_t length;
uchar *key= (uchar*) my_hash_key(hash, record, &length, 0);
return hash->hash_function(hash->charset, key, length);
}


uchar* my_hash_search(const HASH *hash, const uchar *key, size_t length)
void* my_hash_search(const HASH *hash, const uchar *key, size_t length)
{
HASH_SEARCH_STATE state;
return my_hash_first(hash, key, length, &state);
}

uchar* my_hash_search_using_hash_value(const HASH *hash,
my_hash_value_type hash_value,
const uchar *key,
size_t length)
void* my_hash_search_using_hash_value(const HASH *hash,
my_hash_value_type hash_value,
const uchar *key,
size_t length)
{
HASH_SEARCH_STATE state;
return my_hash_first_from_hash_value(hash, hash_value,
Expand All @@ -254,10 +254,10 @@ uchar* my_hash_search_using_hash_value(const HASH *hash,
Assigns the number of the found record to HASH_SEARCH_STATE state
*/

uchar* my_hash_first(const HASH *hash, const uchar *key, size_t length,
HASH_SEARCH_STATE *current_record)
void* my_hash_first(const HASH *hash, const uchar *key, size_t length,
HASH_SEARCH_STATE *current_record)
{
uchar *res;
void *res;
DBUG_ASSERT(my_hash_inited(hash));

res= my_hash_first_from_hash_value(hash,
Expand All @@ -269,11 +269,11 @@ uchar* my_hash_first(const HASH *hash, const uchar *key, size_t length,
}


uchar* my_hash_first_from_hash_value(const HASH *hash,
my_hash_value_type hash_value,
const uchar *key,
size_t length,
HASH_SEARCH_STATE *current_record)
void* my_hash_first_from_hash_value(const HASH *hash,
my_hash_value_type hash_value,
const uchar *key,
size_t length,
HASH_SEARCH_STATE *current_record)
{
HASH_LINK *pos;
DBUG_ENTER("my_hash_first_from_hash_value");
Expand Down Expand Up @@ -310,8 +310,8 @@ uchar* my_hash_first_from_hash_value(const HASH *hash,
/* Get next record with identical key */
/* Can only be called if previous calls was my_hash_search */

uchar* my_hash_next(const HASH *hash, const uchar *key, size_t length,
HASH_SEARCH_STATE *current_record)
void* my_hash_next(const HASH *hash, const uchar *key, size_t length,
HASH_SEARCH_STATE *current_record)
{
HASH_LINK *pos;
uint idx;
Expand Down Expand Up @@ -391,7 +391,7 @@ static int hashcmp(const HASH *hash, HASH_LINK *pos, const uchar *key,
@retval 1 Duplicate key or out of memory
*/

my_bool my_hash_insert(HASH *info, const uchar *record)
my_bool my_hash_insert(HASH *info, const void *record)
{
int flag;
size_t idx, halfbuff, first_index;
Expand Down Expand Up @@ -531,7 +531,7 @@ my_bool my_hash_insert(HASH *info, const uchar *record)
movelink(data,(uint) (pos-data),(uint) (gpos-data),(uint) (empty-data));
}
}
pos->data= (uchar*) record;
pos->data= (void*) record;
pos->hash_nr= current_hash_nr;
if (++info->records == info->blength)
info->blength+= info->blength;
Expand All @@ -558,7 +558,7 @@ my_bool my_hash_insert(HASH *info, const uchar *record)
@retval 1 Record not found
*/

my_bool my_hash_delete(HASH *hash, uchar *record)
my_bool my_hash_delete(HASH *hash, void *record)
{
uint pos2,idx,empty_index;
my_hash_value_type pos_hashnr, lastpos_hashnr;
Expand Down Expand Up @@ -637,7 +637,7 @@ my_bool my_hash_delete(HASH *hash, uchar *record)
exit:
(void) pop_dynamic(&hash->array);
if (hash->free)
(*hash->free)((uchar*) record);
(*hash->free)(record);
DBUG_RETURN(0);
}

Expand All @@ -647,7 +647,7 @@ my_bool my_hash_delete(HASH *hash, uchar *record)
This is much more efficient than using a delete & insert.
*/

my_bool my_hash_update(HASH *hash, uchar *record, uchar *old_key,
my_bool my_hash_update(HASH *hash, void *record, uchar *old_key,
size_t old_key_length)
{
uint new_index, new_pos_index, org_index, records, idx;
Expand All @@ -659,11 +659,11 @@ my_bool my_hash_update(HASH *hash, uchar *record, uchar *old_key,

new_key= (uchar*) my_hash_key(hash, record, &length, 1);
hash_nr= hash->hash_function(hash->charset, new_key, length);

if (HASH_UNIQUE & hash->flags)
{
HASH_SEARCH_STATE state;
uchar *found;
void *found;

if ((found= my_hash_first_from_hash_value(hash, hash_nr, new_key, length,
&state)))
Expand Down Expand Up @@ -762,7 +762,7 @@ my_bool my_hash_update(HASH *hash, uchar *record, uchar *old_key,
}


uchar *my_hash_element(const HASH *hash, size_t idx)
void *my_hash_element(const HASH *hash, size_t idx)
{
if (idx < hash->records)
return dynamic_element(&hash->array,idx,HASH_LINK*)->data;
Expand All @@ -776,7 +776,7 @@ uchar *my_hash_element(const HASH *hash, size_t idx)
*/

void my_hash_replace(HASH *hash, HASH_SEARCH_STATE *current_record,
uchar *new_row)
void *new_row)
{
if (*current_record != NO_RECORD) /* Safety */
dynamic_element(&hash->array, *current_record, HASH_LINK*)->data= new_row;
Expand Down Expand Up @@ -885,8 +885,8 @@ my_bool my_hash_check(HASH *hash)

#define RECORDS 1000

const uchar *test_get_key(const void *data, size_t *length,
my_bool not_used __attribute__((unused)))
const void *test_get_key(const void *data, size_t *length,
my_bool not_used __attribute__((unused)))
{
*length= 2;
return data;
Expand Down
2 changes: 1 addition & 1 deletion mysys/lf_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static inline const uchar* hash_key(const LF_HASH *hash,
const uchar *record, size_t *length)
{
if (hash->get_key)
return (*hash->get_key)(record, length, 0);
return (const uchar*) (*hash->get_key)(record, length, 0);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In C++ files, static_cast is preferred over C-style casts for converting from void* to other pointer types. This improves type safety and adheres to modern C++ standards.

    return static_cast<const uchar*>((*hash->get_key)(record, length, 0));
References
  1. In C++ files, static_cast is preferred over C-style casts for converting from void* to other pointer types. (link)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. You are making it more compatible. Please use one of the cast templates.

*length= hash->key_length;
return record + hash->key_offset;
}
Expand Down
6 changes: 3 additions & 3 deletions mysys/my_likely.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ typedef struct st_likely_entry
ulonglong ok,fail;
} LIKELY_ENTRY;

static const uchar *get_likely_key(const void *part_, size_t *length,
my_bool not_used __attribute__((unused)))
static const void *get_likely_key(const void *part_, size_t *length,
my_bool not_used __attribute__((unused)))
{
const LIKELY_ENTRY *part= (const LIKELY_ENTRY *) part_;
*length= part->key_length;
return (const uchar *) part->key;
return part->key;
}

pthread_mutex_t likely_mutex;
Expand Down
6 changes: 3 additions & 3 deletions mysys/my_safehash.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ static void safe_hash_entry_free(void *entry_)
# reference on the key
*/

static const uchar *safe_hash_entry_get(const void *entry_, size_t *length,
my_bool not_used
__attribute__((unused)))
static const void *safe_hash_entry_get(const void *entry_, size_t *length,
my_bool not_used
__attribute__((unused)))
{
const SAFE_HASH_ENTRY *entry= entry_;
*length= entry->length;
Expand Down
2 changes: 1 addition & 1 deletion plugin/qc_info/qc_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static int qc_info_fill_table(THD *thd, TABLE_LIST *tables,
/* loop through all queries in the query cache */
for (uint i= 0; i < queries->records; i++)
{
const uchar *query_cache_block_raw;
const void *query_cache_block_raw;
Query_cache_block* query_cache_block;
Query_cache_query* query_cache_query;
Query_cache_query_flags flags;
Expand Down
4 changes: 2 additions & 2 deletions sql-common/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3963,13 +3963,13 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg)
/**
A function to return the key from a connection attribute
*/
const uchar *
const void *
get_attr_key(const void *part_, size_t *length,
my_bool not_used __attribute__((unused)))
{
const LEX_STRING *part= part_;
*length= part[0].length;
return (const uchar *) part[0].str;
return part[0].str;
}

int STDCALL
Expand Down
4 changes: 2 additions & 2 deletions sql/debug_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ struct st_debug_sync_globals
}

/* Hash key function for ds_signal_set. */
static const uchar *signal_key(const void *str_, size_t *klen, my_bool)
static const void *signal_key(const void *str_, size_t *klen, my_bool)
{
const LEX_CSTRING *str= static_cast<const LEX_CSTRING*>(str_);
*klen= str->length;
return reinterpret_cast<const uchar*>(str->str);
return str->str;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3460,7 +3460,7 @@ bool ha_partition::re_create_par_file(const char *name)
@return Partition name
*/

static const uchar *get_part_name(const void *part_, size_t *length, my_bool)
static const void *get_part_name(const void *part_, size_t *length, my_bool)
{
auto part= reinterpret_cast<const PART_NAME_DEF *>(part_);
*length= part->length;
Expand Down
2 changes: 1 addition & 1 deletion sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6137,7 +6137,7 @@ class handler_binlog_xid_info {
enum binlog_xid_state xid_state;

/* The key function to use for the HASH. */
static const uchar *get_key(const void *p, size_t *out_len, my_bool)
static const void *get_key(const void *p, size_t *out_len, my_bool)
{
const XID *xid=
&(reinterpret_cast<const handler_binlog_xid_info *>(p)->xid);
Expand Down
Loading
Loading