diff --git a/client/mysqltest.cc b/client/mysqltest.cc index c47b33e97f7..ba2fdc028ba 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -12077,8 +12077,10 @@ void replace_dynstr_append_uint(DYNAMIC_STRING *ds, uint val) keep_header If header should not be sorted */ -static int comp_lines(const char **a, const char **b) +static int comp_lines(const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); return (strcmp(*a,*b)); } diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index a82d1143649..5452b56db6f 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -42,6 +42,7 @@ SET(HEADERS my_dbug.h m_string.h my_sys.h + my_cmp.h my_xml.h mysql_embed.h my_decimal_limits.h diff --git a/include/my_cmp.h b/include/my_cmp.h new file mode 100644 index 00000000000..acaa081cf21 --- /dev/null +++ b/include/my_cmp.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2024, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif +typedef int (*qsort_cmp)(const void *, const void *); +typedef int (*qsort_cmp2)(void *param, const void *a, const void *b); +#ifdef __cplusplus +} +#endif diff --git a/include/my_global.h b/include/my_global.h index afc2feeb30d..5e097248c35 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -528,10 +528,7 @@ typedef int pbool; /* Mixed prototypes can't take char */ typedef int pshort; /* Mixed prototypes can't take short int */ typedef double pfloat; /* Mixed prototypes can't take float */ #endif -C_MODE_START -typedef int (*qsort_cmp)(const void *,const void *); -typedef int (*qsort_cmp2)(void*, const void *,const void *); -C_MODE_END +#include #define qsort_t RETQSORTTYPE /* Broken GCC can't handle typedef !!!! */ #ifdef HAVE_SYS_SOCKET_H #include diff --git a/include/my_sys.h b/include/my_sys.h index 2f4fd2e380a..d1a0394086c 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -29,6 +29,7 @@ C_MODE_START #include #include #include +#include #include #include @@ -462,8 +463,6 @@ typedef struct st_io_cache /* Used when caching files */ size_t alloced_buffer; } IO_CACHE; -typedef int (*qsort2_cmp)(const void *, const void *, const void *); - typedef void (*my_error_reporter)(enum loglevel level, const char *format, ...) ATTRIBUTE_FORMAT_FPTR(printf, 2, 3); @@ -763,8 +762,8 @@ extern void radixsort_for_str_ptr(uchar* base[], uint number_of_elements, extern qsort_t my_qsort(void *base_ptr, size_t total_elems, size_t size, qsort_cmp cmp); extern qsort_t my_qsort2(void *base_ptr, size_t total_elems, size_t size, - qsort2_cmp cmp, void *cmp_argument); -extern qsort2_cmp get_ptr_compare(size_t); + qsort_cmp2 cmp, void *cmp_argument); +extern qsort_cmp2 get_ptr_compare(size_t); void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos); my_off_t my_get_ptr(uchar *ptr, size_t pack_length); extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize, diff --git a/include/myisam.h b/include/myisam.h index c90026bfc7a..e75e25623eb 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -373,7 +373,7 @@ typedef struct st_mi_sort_param my_bool fix_datafile, master; my_bool calc_checksum; /* calculate table checksum */ - int (*key_cmp)(struct st_mi_sort_param *, const void *, const void *); + int (*key_cmp)(void *, const void *, const void *); int (*key_read)(struct st_mi_sort_param *,void *); int (*key_write)(struct st_mi_sort_param *, const void *); void (*lock_in_memory)(HA_CHECK *); diff --git a/include/queues.h b/include/queues.h index 9cc7c15a980..44b3c7f4b28 100644 --- a/include/queues.h +++ b/include/queues.h @@ -31,6 +31,8 @@ #ifndef _queues_h #define _queues_h +#include + #ifdef __cplusplus extern "C" { #endif @@ -44,7 +46,7 @@ typedef struct st_queue { uint offset_to_queue_pos; /* If we want to store position in element */ uint auto_extent; int max_at_top; /* Normally 1, set to -1 if queue_top gives max */ - int (*compare)(void *, uchar *,uchar *); + qsort_cmp2 compare; } QUEUE; #define queue_first_element(queue) 1 @@ -58,14 +60,13 @@ typedef struct st_queue { #define queue_set_max_at_top(queue, set_arg) \ (queue)->max_at_top= set_arg ? -1 : 1 #define queue_remove_top(queue_arg) queue_remove((queue_arg), queue_first_element(queue_arg)) -typedef int (*queue_compare)(void *,uchar *, uchar *); int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key, - my_bool max_at_top, queue_compare compare, + my_bool max_at_top, qsort_cmp2 compare, void *first_cmp_arg, uint offset_to_queue_pos, uint auto_extent); int reinit_queue(QUEUE *queue,uint max_elements,uint offset_to_key, - my_bool max_at_top, queue_compare compare, + my_bool max_at_top, qsort_cmp2 compare, void *first_cmp_arg, uint offset_to_queue_pos, uint auto_extent); int resize_queue(QUEUE *queue, uint max_elements); diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index a7d85cfd407..a026009e613 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -3753,8 +3753,10 @@ static void free_block(SIMPLE_KEY_CACHE_CB *keycache, BLOCK_LINK *block) } -static int cmp_sec_link(BLOCK_LINK **a, BLOCK_LINK **b) +static int cmp_sec_link(const void *_a, const void *_b) { + BLOCK_LINK *const *a= _a; + BLOCK_LINK *const *b= _b; return (((*a)->hash_link->diskpos < (*b)->hash_link->diskpos) ? -1 : ((*a)->hash_link->diskpos > (*b)->hash_link->diskpos) ? 1 : 0); } diff --git a/mysys/mf_qsort.c b/mysys/mf_qsort.c index b516639a341..4dee20750c0 100644 --- a/mysys/mf_qsort.c +++ b/mysys/mf_qsort.c @@ -84,7 +84,7 @@ typedef struct st_stack /**************************************************************************** ** 'standard' quicksort with the following extensions: ** -** Can be compiled with the qsort2_cmp compare function +** Can be compiled with the qsort_cmp2 compare function ** Store ranges on stack to avoid recursion ** Use insert sort on small ranges ** Optimize for sorting of pointers (used often by MySQL) @@ -92,7 +92,7 @@ typedef struct st_stack *****************************************************************************/ #ifdef QSORT_EXTRA_CMP_ARGUMENT -qsort_t my_qsort2(void *base_ptr, size_t count, size_t size, qsort2_cmp cmp, +qsort_t my_qsort2(void *base_ptr, size_t count, size_t size, qsort_cmp2 cmp, void *cmp_argument) #else qsort_t my_qsort(void *base_ptr, size_t count, size_t size, qsort_cmp cmp) diff --git a/mysys/my_lib.c b/mysys/my_lib.c index fb03f0aa5c2..f905e757869 100644 --- a/mysys/my_lib.c +++ b/mysys/my_lib.c @@ -57,7 +57,7 @@ #define NAMES_START_SIZE 32768 -static int comp_names(struct fileinfo *a,struct fileinfo *b); +static int comp_names(const void *a, const void *b); typedef struct { MY_DIR dir; @@ -83,8 +83,10 @@ void my_dirend(MY_DIR *dir) /* Compare in sort of filenames */ -static int comp_names(struct fileinfo *a, struct fileinfo *b) +static int comp_names(const void *a_, const void *b_) { + const struct fileinfo *a= a_; + const struct fileinfo *b= b_; return (strcmp(a->name,b->name)); } /* comp_names */ diff --git a/mysys/my_likely.c b/mysys/my_likely.c index d52074f01e4..a685e13d22b 100644 --- a/mysys/my_likely.c +++ b/mysys/my_likely.c @@ -55,8 +55,10 @@ void init_my_likely() pthread_mutex_init(&likely_mutex, MY_MUTEX_INIT_FAST); } -static int likely_cmp(LIKELY_ENTRY **a, LIKELY_ENTRY **b) +static int likely_cmp(const void *a_, const void *b_) { + const LIKELY_ENTRY *const *a= a_; + const LIKELY_ENTRY *const *b= b_; int cmp; if ((cmp= strcmp((*a)->key, (*b)->key))) return cmp; diff --git a/mysys/ptr_cmp.c b/mysys/ptr_cmp.c index 7ea15baf86d..40af3f63afd 100644 --- a/mysys/ptr_cmp.c +++ b/mysys/ptr_cmp.c @@ -44,40 +44,43 @@ #include -static int native_compare(size_t *length, unsigned char **a, unsigned char **b) +static int native_compare(void *length_, const void *a_, const void *b_) { + size_t *length= length_; + const unsigned char *const *a= a_; + const unsigned char *const *b= b_; return memcmp(*a, *b, *length); } -qsort2_cmp get_ptr_compare (size_t size __attribute__((unused))) +qsort_cmp2 get_ptr_compare (size_t size __attribute__((unused))) { - return (qsort2_cmp) native_compare; + return native_compare; } #else /* USE_NATIVE_MEMCMP */ -static int ptr_compare(size_t *compare_length, uchar **a, uchar **b); -static int ptr_compare_0(size_t *compare_length, uchar **a, uchar **b); -static int ptr_compare_1(size_t *compare_length, uchar **a, uchar **b); -static int ptr_compare_2(size_t *compare_length, uchar **a, uchar **b); -static int ptr_compare_3(size_t *compare_length, uchar **a, uchar **b); -static int degenerate_compare_func(size_t *compare_length, uchar **a, uchar **b) +static int ptr_compare(void *compare_length, const void *a, const void *b); +static int ptr_compare_0(void *compare_length, const void *a, const void *b); +static int ptr_compare_1(void *compare_length, const void *a, const void *b); +static int ptr_compare_2(void *compare_length, const void *a, const void *b); +static int ptr_compare_3(void *compare_length, const void *a, const void *b); +static int degenerate_compare_func(void *compare_length, const void *a, const void *b) { - DBUG_ASSERT(*compare_length == 0); + DBUG_ASSERT(*((size_t *) compare_length) == 0); return 0; } -qsort2_cmp get_ptr_compare (size_t size) +qsort_cmp2 get_ptr_compare (size_t size) { if (size == 0) - return (qsort2_cmp) degenerate_compare_func; + return degenerate_compare_func; if (size < 4) - return (qsort2_cmp) ptr_compare; + return ptr_compare; switch (size & 3) { - case 0: return (qsort2_cmp) ptr_compare_0; - case 1: return (qsort2_cmp) ptr_compare_1; - case 2: return (qsort2_cmp) ptr_compare_2; - case 3: return (qsort2_cmp) ptr_compare_3; + case 0: return ptr_compare_0; + case 1: return ptr_compare_1; + case 2: return ptr_compare_2; + case 3: return ptr_compare_3; } return 0; /* Impossible */ } @@ -88,13 +91,13 @@ qsort2_cmp get_ptr_compare (size_t size) #define cmp(N) if (first[N] != last[N]) return (int) first[N] - (int) last[N] -static int ptr_compare(size_t *compare_length, uchar **a, uchar **b) +static int ptr_compare(void *compare_length, const void *a, const void *b) { - size_t length= *compare_length; - uchar *first,*last; + size_t length= *((size_t *) compare_length); + const uchar *first= *((const uchar *const *) a); + const uchar *last= *((const uchar *const *) b); DBUG_ASSERT(length > 0); - first= *a; last= *b; while (--length) { if (*first++ != *last++) @@ -104,12 +107,11 @@ static int ptr_compare(size_t *compare_length, uchar **a, uchar **b) } -static int ptr_compare_0(size_t *compare_length,uchar **a, uchar **b) +static int ptr_compare_0(void *compare_length, const void *a, const void *b) { - size_t length= *compare_length; - uchar *first,*last; - - first= *a; last= *b; + size_t length= *((size_t *) compare_length); + const uchar *first= *((const uchar *const *) a); + const uchar *last= *((const uchar *const *) b); loop: cmp(0); cmp(1); @@ -125,12 +127,13 @@ static int ptr_compare_0(size_t *compare_length,uchar **a, uchar **b) } -static int ptr_compare_1(size_t *compare_length,uchar **a, uchar **b) +static int ptr_compare_1(void *compare_length, const void *a, const void *b) { - size_t length= *compare_length-1; - uchar *first,*last; - first= *a+1; last= *b+1; + size_t length= *((size_t *) compare_length) - 1; + const uchar *first= *((const uchar *const *) a) + 1; + const uchar *last= *((const uchar *const *) b) + 1; + cmp(-1); loop: cmp(0); @@ -146,12 +149,12 @@ static int ptr_compare_1(size_t *compare_length,uchar **a, uchar **b) return (0); } -static int ptr_compare_2(size_t *compare_length,uchar **a, uchar **b) +static int ptr_compare_2(void *compare_length, const void *a, const void *b) { - size_t length= *compare_length-2; - uchar *first,*last; + size_t length= *((size_t *) compare_length) - 2; + const uchar *first= *((const uchar *const *) a) + 2; + const uchar *last= *((const uchar *const *) b) + 2; - first= *a +2 ; last= *b +2; cmp(-2); cmp(-1); loop: @@ -168,12 +171,12 @@ static int ptr_compare_2(size_t *compare_length,uchar **a, uchar **b) return (0); } -static int ptr_compare_3(size_t *compare_length,uchar **a, uchar **b) +static int ptr_compare_3(void *compare_length, const void *a, const void *b) { - size_t length= *compare_length-3; - uchar *first,*last; + size_t length= *((size_t *) compare_length) - 3; + const uchar *first= *((const uchar *const *) a) + 3; + const uchar *last= *((const uchar *const *) b) + 3; - first= *a +3 ; last= *b +3; cmp(-3); cmp(-2); cmp(-1); diff --git a/mysys/queues.c b/mysys/queues.c index 0a1149bf9fc..07b3b4f7ed1 100644 --- a/mysys/queues.c +++ b/mysys/queues.c @@ -70,7 +70,7 @@ */ int init_queue(QUEUE *queue, uint max_elements, uint offset_to_key, - my_bool max_at_top, int (*compare) (void *, uchar *, uchar *), + my_bool max_at_top, qsort_cmp2 compare, void *first_cmp_arg, uint offset_to_queue_pos, uint auto_extent) { @@ -109,7 +109,7 @@ int init_queue(QUEUE *queue, uint max_elements, uint offset_to_key, */ int reinit_queue(QUEUE *queue, uint max_elements, uint offset_to_key, - my_bool max_at_top, int (*compare) (void *, uchar *, uchar *), + my_bool max_at_top, qsort_cmp2 compare, void *first_cmp_arg, uint offset_to_queue_pos, uint auto_extent) { diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index d2b542ee9b6..af22e7cc45c 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -77,10 +77,11 @@ static void *alarm_handler(void *arg); static sig_handler thread_alarm(int sig __attribute__((unused))); static int compare_ulong(void *not_used __attribute__((unused)), - uchar *a_ptr,uchar* b_ptr) + const void *a_ptr, const void *b_ptr) { - ulong a=*((ulong*) a_ptr),b= *((ulong*) b_ptr); - return (a < b) ? -1 : (a == b) ? 0 : 1; + const ulong *ap= a_ptr; + const ulong *bp= b_ptr; + return (*ap < *bp) ? -1 : (*ap == *bp) ? 0 : 1; } void init_thr_alarm(uint max_alarms) diff --git a/mysys/thr_timer.c b/mysys/thr_timer.c index d3627fea983..00fc74cdf77 100644 --- a/mysys/thr_timer.c +++ b/mysys/thr_timer.c @@ -46,10 +46,11 @@ static void *timer_handler(void *arg __attribute__((unused))); */ static int compare_timespec(void *not_used __attribute__((unused)), - uchar *a_ptr, uchar *b_ptr) + const void *a_ptr, const void *b_ptr) { - return cmp_timespec((*(struct timespec*) a_ptr), - (*(struct timespec*) b_ptr)); + const struct timespec *ap= a_ptr; + const struct timespec *bp= b_ptr; + return cmp_timespec((*ap), (*bp)); } diff --git a/plugin/type_inet/sql_type_inet.cc b/plugin/type_inet/sql_type_inet.cc index b566e3c1f9d..d7dccd8b430 100644 --- a/plugin/type_inet/sql_type_inet.cc +++ b/plugin/type_inet/sql_type_inet.cc @@ -594,9 +594,9 @@ public: Inet6_null tmp(arg); return m_null_value || tmp.is_null() ? UNKNOWN : m_native.cmp(tmp) != 0; } - int compare(cmp_item *ci) override + int compare(const cmp_item *ci) const override { - cmp_item_inet6 *tmp= static_cast(ci); + const cmp_item_inet6 *tmp= static_cast(ci); DBUG_ASSERT(!m_null_value); DBUG_ASSERT(!tmp->m_null_value); return m_native.cmp(tmp->m_native); @@ -1293,13 +1293,15 @@ public: class in_inet6 :public in_vector { Inet6 m_value; - static int cmp_inet6(void *cmp_arg, Inet6 *a, Inet6 *b) + static int cmp_inet6(void *, const void *a_, const void *b_) { + const Inet6 *a= static_cast(a_); + const Inet6 *b= static_cast(b_); return a->cmp(*b); } public: in_inet6(THD *thd, uint elements) - :in_vector(thd, elements, sizeof(Inet6), (qsort2_cmp) cmp_inet6, 0), + :in_vector(thd, elements, sizeof(Inet6), cmp_inet6, 0), m_value(Inet6_zero()) { } const Type_handler *type_handler() const override diff --git a/sql/bounded_queue.h b/sql/bounded_queue.h index 07ab6dbaab9..0675135373c 100644 --- a/sql/bounded_queue.h +++ b/sql/bounded_queue.h @@ -62,16 +62,6 @@ public: Element_type *from, bool packing_keys); - /** - Function for comparing two keys. - @param n Pointer to number of bytes to compare. - @param a First key. - @param b Second key. - @retval -1, 0, or 1 depending on whether the left argument is - less than, equal to, or greater than the right argument. - */ - typedef int (*compare_function)(size_t *n, Key_type **a, Key_type **b); - /** Initialize the queue. @@ -81,8 +71,6 @@ public: pop() will return the smallest key in the result set. true: We keep the n smallest elements. pop() will return the largest key in the result set. - @param compare Compare function for elements, takes 3 arguments. - If NULL, we use get_ptr_compare(compare_length). @param compare_length Length of the data (i.e. the keys) used for sorting. @param keymaker Function which generates keys for elements. @param sort_param Sort parameters. @@ -93,7 +81,7 @@ public: We do *not* take ownership of any of the input pointer arguments. */ int init(ha_rows max_elements, bool max_at_top, - compare_function compare, size_t compare_length, + size_t compare_length, keymaker_function keymaker, Sort_param *sort_param, Key_type **sort_keys); @@ -148,7 +136,6 @@ private: template int Bounded_queue::init(ha_rows max_elements, bool max_at_top, - compare_function compare, size_t compare_length, keymaker_function keymaker, Sort_param *sort_param, @@ -163,13 +150,10 @@ int Bounded_queue::init(ha_rows max_elements, // init_queue() takes an uint, and also does (max_elements + 1) if (max_elements >= (UINT_MAX - 1)) return 1; - if (compare == NULL) - compare= - reinterpret_cast(get_ptr_compare(compare_length)); // We allocate space for one extra element, for replace when queue is full. return init_queue(&m_queue, (uint) max_elements + 1, 0, max_at_top, - reinterpret_cast(compare), + get_ptr_compare(compare_length), &m_compare_length, 0, 0); } diff --git a/sql/event_queue.cc b/sql/event_queue.cc index f5aa16dabaf..3671edf8d5e 100644 --- a/sql/event_queue.cc +++ b/sql/event_queue.cc @@ -67,10 +67,10 @@ extern "C" int event_queue_element_compare_q(void *, uchar *, uchar *); -int event_queue_element_compare_q(void *vptr, uchar* a, uchar *b) +int event_queue_element_compare_q(void *, const void *a, const void *b) { - Event_queue_element *left = (Event_queue_element *)a; - Event_queue_element *right = (Event_queue_element *)b; + auto left= static_cast(a); + auto right= static_cast(b); my_time_t lhs = left->execute_at; my_time_t rhs = right->execute_at; diff --git a/sql/filesort.cc b/sql/filesort.cc index 5f23df22342..6f7513275bd 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -283,7 +283,6 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, sort->init_record_pointers(); if (pq.init(param.max_rows, true, // max_at_top - NULL, // compare_function compare_length, &make_sortkey, ¶m, sort->get_sort_keys())) { @@ -1820,7 +1819,7 @@ bool merge_buffers(Sort_param *param, IO_CACHE *from_file, uchar *strpos; Merge_chunk *buffpek; QUEUE queue; - qsort2_cmp cmp; + qsort_cmp2 cmp; void *first_cmp_arg; element_count dupl_count= 0; uchar *src; @@ -1864,9 +1863,9 @@ bool merge_buffers(Sort_param *param, IO_CACHE *from_file, cmp= param->get_compare_function(); first_cmp_arg= param->get_compare_argument(&sort_length); } - if (unlikely(init_queue(&queue, (uint) (Tb-Fb)+1, - offsetof(Merge_chunk,m_current_key), 0, - (queue_compare) cmp, first_cmp_arg, 0, 0))) + if (unlikely(init_queue(&queue, (uint) (Tb - Fb) + 1, + offsetof(Merge_chunk, m_current_key), 0, cmp, + first_cmp_arg, 0, 0))) DBUG_RETURN(1); /* purecov: inspected */ const size_t chunk_sz = (sort_buffer.size()/((uint) (Tb-Fb) +1)); for (buffpek= Fb ; buffpek <= Tb ; buffpek++) @@ -2786,9 +2785,9 @@ void SORT_FIELD_ATTR::set_length_and_original_length(THD *thd, uint length_arg) Compare function used for packing sort keys */ -qsort2_cmp get_packed_keys_compare_ptr() +qsort_cmp2 get_packed_keys_compare_ptr() { - return (qsort2_cmp) compare_packed_sort_keys; + return compare_packed_sort_keys; } @@ -2802,8 +2801,8 @@ qsort2_cmp get_packed_keys_compare_ptr() suffix_bytes are used only for binary columns. */ -int SORT_FIELD_ATTR::compare_packed_varstrings(uchar *a, size_t *a_len, - uchar *b, size_t *b_len) +int SORT_FIELD_ATTR::compare_packed_varstrings(const uchar *a, size_t *a_len, + const uchar *b, size_t *b_len) { int retval; size_t a_length, b_length; @@ -2862,8 +2861,8 @@ int SORT_FIELD_ATTR::compare_packed_varstrings(uchar *a, size_t *a_len, packed-value format. */ -int SORT_FIELD_ATTR::compare_packed_fixed_size_vals(uchar *a, size_t *a_len, - uchar *b, size_t *b_len) +int SORT_FIELD_ATTR::compare_packed_fixed_size_vals(const uchar *a, size_t *a_len, + const uchar *b, size_t *b_len) { if (maybe_null) { @@ -2908,15 +2907,15 @@ int SORT_FIELD_ATTR::compare_packed_fixed_size_vals(uchar *a, size_t *a_len, */ -int compare_packed_sort_keys(void *sort_param, - unsigned char **a_ptr, unsigned char **b_ptr) +int compare_packed_sort_keys(void *sort_param, const void *a_ptr, + const void *b_ptr) { int retval= 0; size_t a_len, b_len; - Sort_param *param= (Sort_param*)sort_param; + Sort_param *param= static_cast(sort_param); Sort_keys *sort_keys= param->sort_keys; - uchar *a= *a_ptr; - uchar *b= *b_ptr; + auto a= *(static_cast(a_ptr)); + auto b= *(static_cast(b_ptr)); a+= Sort_keys::size_of_length_field; b+= Sort_keys::size_of_length_field; diff --git a/sql/filesort_utils.h b/sql/filesort_utils.h index 946b1cb4f06..0dd84d55a95 100644 --- a/sql/filesort_utils.h +++ b/sql/filesort_utils.h @@ -268,8 +268,8 @@ private: longlong m_idx; }; -int compare_packed_sort_keys(void *sort_keys, unsigned char **a, - unsigned char **b); -qsort2_cmp get_packed_keys_compare_ptr(); +int compare_packed_sort_keys(void *sort_param, const void *a_ptr, + const void *b_ptr); +qsort_cmp2 get_packed_keys_compare_ptr(); #endif // FILESORT_UTILS_INCLUDED diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 22d1dca0ad9..d72a836e7ce 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -5515,7 +5515,7 @@ bool ha_partition::init_record_priority_queue() m_start_key.key= (const uchar*)ptr; /* Initialize priority queue, initialized to reading forward. */ - int (*cmp_func)(void *, uchar *, uchar *); + int (*cmp_func)(void *, const void *, const void *); void *cmp_arg= (void*) this; if (!m_using_extended_keys && !(table_flags() & HA_SLOW_CMP_REF)) cmp_func= cmp_key_rowid_part_id; @@ -5763,8 +5763,10 @@ int ha_partition::index_read_map(uchar *buf, const uchar *key, /* Compare two part_no partition numbers */ -static int cmp_part_ids(uchar *ref1, uchar *ref2) +static int cmp_part_ids(const void *ref1_, const void *ref2_) { + auto ref1= static_cast(ref1_); + auto ref2= static_cast(ref2_); uint32 diff2= uint2korr(ref2); uint32 diff1= uint2korr(ref1); if (diff2 > diff1) @@ -5780,9 +5782,12 @@ static int cmp_part_ids(uchar *ref1, uchar *ref2) Provide ordering by (key_value, part_no). */ -extern "C" int cmp_key_part_id(void *ptr, uchar *ref1, uchar *ref2) +extern "C" int cmp_key_part_id(void *ptr, const void *ref1_, const void *ref2_) { - ha_partition *file= (ha_partition*)ptr; + const ha_partition *file= static_cast(ptr); + const uchar *ref1= static_cast(ref1_); + const uchar *ref2= static_cast(ref2_); + if (int res= key_rec_cmp(file->m_curr_key_info, ref1 + PARTITION_BYTES_IN_POS, ref2 + PARTITION_BYTES_IN_POS)) @@ -5794,9 +5799,13 @@ extern "C" int cmp_key_part_id(void *ptr, uchar *ref1, uchar *ref2) @brief Provide ordering by (key_value, underying_table_rowid, part_no). */ -extern "C" int cmp_key_rowid_part_id(void *ptr, uchar *ref1, uchar *ref2) +extern "C" int cmp_key_rowid_part_id(void *ptr, const void *ref1_, + const void *ref2_) { - ha_partition *file= (ha_partition*)ptr; + const ha_partition *file= static_cast(ptr); + const uchar *ref1= static_cast(ref1_); + const uchar *ref2= static_cast(ref2_); + int res; if ((res= key_rec_cmp(file->m_curr_key_info, ref1 + PARTITION_BYTES_IN_POS, @@ -8348,10 +8357,12 @@ int ha_partition::handle_ordered_prev(uchar *buf) Helper function for sorting according to number of rows in descending order. */ -int ha_partition::compare_number_of_records(ha_partition *me, - const uint32 *a, - const uint32 *b) +int ha_partition::compare_number_of_records(void *me_, const void *a_, + const void *b_) { + const ha_partition *me= static_cast(me_); + const uint32 *a= static_cast(a_); + const uint32 *b= static_cast(b_); handler **file= me->m_file; /* Note: sorting in descending order! */ if (file[*a]->stats.records > file[*b]->stats.records) @@ -8651,7 +8662,7 @@ int ha_partition::info(uint flag) my_qsort2((void*) m_part_ids_sorted_by_num_of_records, m_tot_parts, sizeof(uint32), - (qsort2_cmp) compare_number_of_records, + compare_number_of_records, this); file= m_file[handler_instance]; diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 1c50dde348a..b0321578d30 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -277,8 +277,8 @@ typedef struct st_partition_part_key_multi_range_hld } PARTITION_PART_KEY_MULTI_RANGE_HLD; -extern "C" int cmp_key_part_id(void *key_p, uchar *ref1, uchar *ref2); -extern "C" int cmp_key_rowid_part_id(void *ptr, uchar *ref1, uchar *ref2); +extern "C" int cmp_key_part_id(void *key_p, const void *ref1, const void *ref2); +extern "C" int cmp_key_rowid_part_id(void *ptr, const void *ref1, const void *ref2); class ha_partition :public handler { @@ -446,9 +446,7 @@ private: /** Sorted array of partition ids in descending order of number of rows. */ uint32 *m_part_ids_sorted_by_num_of_records; /* Compare function for my_qsort2, for reversed order. */ - static int compare_number_of_records(ha_partition *me, - const uint32 *a, - const uint32 *b); + static int compare_number_of_records(void *me, const void *a, const void *b); /** keep track of partitions to call ha_reset */ MY_BITMAP m_partitions_to_reset; /** partitions that returned HA_ERR_KEY_NOT_FOUND. */ @@ -1635,8 +1633,9 @@ public: int notify_tabledef_changed(LEX_CSTRING *db, LEX_CSTRING *table, LEX_CUSTRING *frm, LEX_CUSTRING *version); - friend int cmp_key_rowid_part_id(void *ptr, uchar *ref1, uchar *ref2); - friend int cmp_key_part_id(void *key_p, uchar *ref1, uchar *ref2); + friend int cmp_key_rowid_part_id(void *ptr, const void *ref1, + const void *ref2); + friend int cmp_key_part_id(void *key_p, const void *ref1, const void *ref2); bool can_convert_nocopy(const Field &field, const Column_definition &new_field) const override; diff --git a/sql/handler.cc b/sql/handler.cc index af282829c3c..10ea7da1088 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6116,15 +6116,19 @@ static int cmp_file_names(const void *a, const void *b) return cs->strnncoll(aa, strlen(aa), bb, strlen(bb)); } -static int cmp_table_names(LEX_CSTRING * const *a, LEX_CSTRING * const *b) +static int cmp_table_names(const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); return my_charset_bin.strnncoll((*a)->str, (*a)->length, (*b)->str, (*b)->length); } #ifndef DBUG_OFF -static int cmp_table_names_desc(LEX_CSTRING * const *a, LEX_CSTRING * const *b) +static int cmp_table_names_desc(const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); return -cmp_table_names(a, b); } #endif diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 7a528fa06d0..e72e825a04d 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -3650,10 +3650,10 @@ static inline int cmp_ulongs (ulonglong a_val, ulonglong b_val) 0 left argument is equal to the right argument. 1 left argument is greater than the right argument. */ -int cmp_longlong(void *cmp_arg, - in_longlong::packed_longlong *a, - in_longlong::packed_longlong *b) +int cmp_longlong(void *, const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); if (a->unsigned_flag != b->unsigned_flag) { /* @@ -3675,19 +3675,26 @@ int cmp_longlong(void *cmp_arg, return cmp_longs(a->val, b->val); } -static int cmp_double(void *cmp_arg, double *a,double *b) +static int cmp_double(void *, const void *a_, const void *b_) { + const double *a= static_cast(a_); + const double *b= static_cast(b_); return *a < *b ? -1 : *a == *b ? 0 : 1; } -static int cmp_row(void *cmp_arg, cmp_item_row *a, cmp_item_row *b) +static int cmp_row(void *, const void *a_, const void *b_) { + const cmp_item_row *a= static_cast(a_); + const cmp_item_row *b= static_cast(b_); return a->compare(b); } -static int cmp_decimal(void *cmp_arg, my_decimal *a, my_decimal *b) +static int cmp_decimal(void *, const void *a_, const void *b_) { + my_decimal *a= const_cast(static_cast(a_)); + my_decimal *b= const_cast(static_cast(b_)); + /* We need call of fixing buffer pointer, because fast sort just copy decimal buffers in memory and pointers left pointing on old buffer place @@ -3710,17 +3717,19 @@ bool in_vector::find(Item *item) { uint mid=(start+end+1)/2; int res; - if ((res=(*compare)(collation, base+mid*size, result)) == 0) + if ((res= (*compare)(const_cast(collation), + base + mid * size, result)) == 0) return true; if (res < 0) start=mid; else end=mid-1; } - return ((*compare)(collation, base+start*size, result) == 0); + return ((*compare)(const_cast(collation), + base + start * size, result) == 0); } -in_string::in_string(THD *thd, uint elements, qsort2_cmp cmp_func, +in_string::in_string(THD *thd, uint elements, qsort_cmp2 cmp_func, CHARSET_INFO *cs) :in_vector(thd, elements, sizeof(String), cmp_func, cs), tmp(buff, sizeof(buff), &my_charset_bin) @@ -3775,7 +3784,7 @@ in_row::in_row(THD *thd, uint elements, Item * item) { base= (char*) new (thd->mem_root) cmp_item_row[count= elements]; size= sizeof(cmp_item_row); - compare= (qsort2_cmp) cmp_row; + compare= cmp_row; /* We need to reset these as otherwise we will call sort() with uninitialized (even if not used) elements @@ -3807,8 +3816,7 @@ bool in_row::set(uint pos, Item *item) } in_longlong::in_longlong(THD *thd, uint elements) - :in_vector(thd, elements, sizeof(packed_longlong), - (qsort2_cmp) cmp_longlong, 0) + : in_vector(thd, elements, sizeof(packed_longlong), cmp_longlong, 0) {} bool in_longlong::set(uint pos, Item *item) @@ -3839,16 +3847,16 @@ Item *in_longlong::create_item(THD *thd) } -static int cmp_timestamp(void *cmp_arg, - Timestamp_or_zero_datetime *a, - Timestamp_or_zero_datetime *b) +static int cmp_timestamp(void *, const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); return a->cmp(*b); } in_timestamp::in_timestamp(THD *thd, uint elements) - :in_vector(thd, elements, sizeof(Value), (qsort2_cmp) cmp_timestamp, 0) + :in_vector(thd, elements, sizeof(Value), cmp_timestamp, 0) {} @@ -3932,7 +3940,7 @@ Item *in_temporal::create_item(THD *thd) in_double::in_double(THD *thd, uint elements) - :in_vector(thd, elements, sizeof(double), (qsort2_cmp) cmp_double, 0) + :in_vector(thd, elements, sizeof(double), cmp_double, 0) {} bool in_double::set(uint pos, Item *item) @@ -3956,7 +3964,7 @@ Item *in_double::create_item(THD *thd) in_decimal::in_decimal(THD *thd, uint elements) - :in_vector(thd, elements, sizeof(my_decimal), (qsort2_cmp) cmp_decimal, 0) + :in_vector(thd, elements, sizeof(my_decimal), cmp_decimal, 0) {} @@ -4201,9 +4209,9 @@ int cmp_item_row::cmp(Item *arg) } -int cmp_item_row::compare(cmp_item *c) +int cmp_item_row::compare(const cmp_item *c) const { - cmp_item_row *l_cmp= (cmp_item_row *) c; + auto l_cmp= static_cast(c); for (uint i=0; i < n; i++) { int res; @@ -4239,9 +4247,9 @@ int cmp_item_decimal::cmp(Item *arg) } -int cmp_item_decimal::compare(cmp_item *arg) +int cmp_item_decimal::compare(const cmp_item *arg) const { - cmp_item_decimal *l_cmp= (cmp_item_decimal*) arg; + auto l_cmp= static_cast(arg); return my_decimal_cmp(&value, &l_cmp->value); } @@ -4282,9 +4290,9 @@ int cmp_item_time::cmp(Item *arg) } -int cmp_item_temporal::compare(cmp_item *ci) +int cmp_item_temporal::compare(const cmp_item *ci) const { - cmp_item_temporal *l_cmp= (cmp_item_temporal *)ci; + auto l_cmp= static_cast(ci); return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1); } @@ -4330,9 +4338,9 @@ int cmp_item_timestamp::cmp(Item *arg) } -int cmp_item_timestamp::compare(cmp_item *arg) +int cmp_item_timestamp::compare(const cmp_item *arg) const { - cmp_item_timestamp *tmp= static_cast(arg); + auto tmp= static_cast(arg); return type_handler_timestamp2.cmp_native(m_native, tmp->m_native); } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index fd5c2bc9873..1bc5f42ab2b 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1365,12 +1365,12 @@ class in_vector :public Sql_alloc public: char *base; uint size; - qsort2_cmp compare; + qsort_cmp2 compare; CHARSET_INFO *collation; uint count; uint used_count; in_vector() = default; - in_vector(THD *thd, uint elements, uint element_length, qsort2_cmp cmp_func, + in_vector(THD *thd, uint elements, uint element_length, qsort_cmp2 cmp_func, CHARSET_INFO *cmp_coll) :base((char*) thd_calloc(thd, elements * element_length)), size(element_length), compare(cmp_func), collation(cmp_coll), @@ -1414,7 +1414,8 @@ public: /* Compare values number pos1 and pos2 for equality */ bool compare_elems(uint pos1, uint pos2) { - return MY_TEST(compare(collation, base + pos1 * size, base + pos2 * size)); + return MY_TEST(compare(const_cast(collation), + base + pos1 * size, base + pos2 * size)); } virtual const Type_handler *type_handler() const= 0; }; @@ -1436,7 +1437,7 @@ class in_string :public in_vector } }; public: - in_string(THD *thd, uint elements, qsort2_cmp cmp_func, CHARSET_INFO *cs); + in_string(THD *thd, uint elements, qsort_cmp2 cmp_func, CHARSET_INFO *cs); ~in_string(); bool set(uint pos, Item *item) override; uchar *get_value(Item *item) override; @@ -1476,7 +1477,7 @@ public: } const Type_handler *type_handler() const override { return &type_handler_slonglong; } - friend int cmp_longlong(void *cmp_arg, packed_longlong *a,packed_longlong *b); + friend int cmp_longlong(void *cmp_arg, const void *a, const void *b); }; @@ -1510,7 +1511,7 @@ public: Item_datetime *dt= static_cast(item); dt->set(val->val, type_handler()->mysql_timestamp_type()); } - friend int cmp_longlong(void *cmp_arg, packed_longlong *a,packed_longlong *b); + friend int cmp_longlong(void *cmp_arg, const void *a, const void *b); }; @@ -1590,7 +1591,7 @@ public: virtual int cmp(Item *item)= 0; virtual int cmp_not_null(const Value *value)= 0; // for optimized IN with row - virtual int compare(cmp_item *item)= 0; + virtual int compare(const cmp_item *item) const = 0; virtual cmp_item *make_same()= 0; /* Store a scalar or a ROW value into "this". @@ -1668,7 +1669,7 @@ public: else return TRUE; } - int compare(cmp_item *ci) override + int compare(const cmp_item *ci) const override { cmp_item_string *l_cmp= (cmp_item_string *) ci; return sortcmp(value_res, l_cmp->value_res, cmp_charset); @@ -1702,7 +1703,7 @@ public: const bool rc= value != arg->val_int(); return (m_null_value || arg->null_value) ? UNKNOWN : rc; } - int compare(cmp_item *ci) override + int compare(const cmp_item *ci) const override { cmp_item_int *l_cmp= (cmp_item_int *)ci; return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1); @@ -1719,7 +1720,7 @@ protected: longlong value; public: cmp_item_temporal() = default; - int compare(cmp_item *ci) override; + int compare(const cmp_item *ci) const override; }; @@ -1765,7 +1766,7 @@ public: void store_value(Item *item) override; int cmp_not_null(const Value *val) override; int cmp(Item *arg) override; - int compare(cmp_item *ci) override; + int compare(const cmp_item *ci) const override; cmp_item *make_same() override; }; @@ -1791,7 +1792,7 @@ public: const bool rc= value != arg->val_real(); return (m_null_value || arg->null_value) ? UNKNOWN : rc; } - int compare(cmp_item *ci) override + int compare(const cmp_item *ci) const override { cmp_item_real *l_cmp= (cmp_item_real *) ci; return (value < l_cmp->value)? -1 : ((value == l_cmp->value) ? 0 : 1); @@ -1808,7 +1809,7 @@ public: void store_value(Item *item) override; int cmp(Item *arg) override; int cmp_not_null(const Value *val) override; - int compare(cmp_item *c) override; + int compare(const cmp_item *c) const override; cmp_item *make_same() override; }; @@ -1841,7 +1842,7 @@ public: DBUG_ASSERT(false); return TRUE; } - int compare(cmp_item *ci) override + int compare(const cmp_item *ci) const override { cmp_item_string *l_cmp= (cmp_item_string *) ci; return sortcmp(value_res, l_cmp->value_res, cmp_charset); @@ -2557,7 +2558,7 @@ public: DBUG_ASSERT(false); return TRUE; } - int compare(cmp_item *arg) override; + int compare(const cmp_item *arg) const override; cmp_item *make_same() override; bool store_value_by_template(THD *thd, cmp_item *tmpl, Item *) override; friend class Item_func_in; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index c006250d97a..c0ac4022cd9 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -6039,7 +6039,7 @@ bool Ordered_key::alloc_keys_buffers() */ int -Ordered_key::cmp_keys_by_row_data(ha_rows a, ha_rows b) +Ordered_key::cmp_keys_by_row_data(const ha_rows a, const ha_rows b) const { uchar *rowid_a, *rowid_b; int error; @@ -6081,10 +6081,12 @@ Ordered_key::cmp_keys_by_row_data(ha_rows a, ha_rows b) } -int -Ordered_key::cmp_keys_by_row_data_and_rownum(Ordered_key *key, - rownum_t* a, rownum_t* b) +int Ordered_key::cmp_keys_by_row_data_and_rownum(void *key_, const void *a_, + const void *b_) { + Ordered_key *key= static_cast(key_); + const rownum_t *a= static_cast(a_); + const rownum_t *b= static_cast(b_); /* The result of comparing the two keys according to their row data. */ int cmp_row_res= key->cmp_keys_by_row_data(*a, *b); if (cmp_row_res) @@ -6098,7 +6100,7 @@ bool Ordered_key::sort_keys() if (tbl->file->ha_rnd_init_with_error(0)) return TRUE; my_qsort2(key_buff, (size_t) key_buff_elements, sizeof(rownum_t), - (qsort2_cmp) &cmp_keys_by_row_data_and_rownum, (void*) this); + &cmp_keys_by_row_data_and_rownum, (void *) this); /* Invalidate the current row position. */ cur_key_idx= HA_POS_ERROR; tbl->file->ha_rnd_end(); @@ -6114,7 +6116,7 @@ bool Ordered_key::sort_keys() @retval 0 if only NULLs */ -double Ordered_key::null_selectivity() +inline double Ordered_key::null_selectivity() const { /* We should not be processing empty tables. */ DBUG_ASSERT(tbl->file->stats.records); @@ -6246,7 +6248,7 @@ bool Ordered_key::next_same() } -void Ordered_key::print(String *str) +void Ordered_key::print(String *str) const { uint i; str->append("{idx="); @@ -6605,10 +6607,11 @@ void subselect_rowid_merge_engine::cleanup() @retval -1 if k1 is more selective than k2 */ -int -subselect_rowid_merge_engine::cmp_keys_by_null_selectivity(Ordered_key **k1, - Ordered_key **k2) +int subselect_rowid_merge_engine::cmp_keys_by_null_selectivity(const void *k1_, + const void *k2_) { + auto k1= static_cast(k1_); + auto k2= static_cast(k2_); double k1_sel= (*k1)->null_selectivity(); double k2_sel= (*k2)->null_selectivity(); if (k1_sel < k2_sel) @@ -6622,12 +6625,14 @@ subselect_rowid_merge_engine::cmp_keys_by_null_selectivity(Ordered_key **k1, /* */ -int -subselect_rowid_merge_engine::cmp_keys_by_cur_rownum(void *arg, - uchar *k1, uchar *k2) +int subselect_rowid_merge_engine::cmp_keys_by_cur_rownum(void *, + const void *k1_, + const void *k2_) { - rownum_t r1= ((Ordered_key*) k1)->current(); - rownum_t r2= ((Ordered_key*) k2)->current(); + auto k1= static_cast(k1_); + auto k2= static_cast(k2_); + rownum_t r1= k1->current(); + rownum_t r2= k2->current(); return (r1 < r2) ? -1 : (r1 > r2) ? 1 : 0; } diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 46fa1fae2df..7c4ca91bfac 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -1296,9 +1296,9 @@ protected: Quick sort comparison function that compares two rows of the same table indentfied with their row numbers. */ - int cmp_keys_by_row_data(rownum_t a, rownum_t b); - static int cmp_keys_by_row_data_and_rownum(Ordered_key *key, - rownum_t* a, rownum_t* b); + int cmp_keys_by_row_data(const rownum_t a, const rownum_t b) const; + static int cmp_keys_by_row_data_and_rownum(void *key, const void *a, + const void *b); int cmp_key_with_search_key(rownum_t row_num); @@ -1314,23 +1314,23 @@ public: /* Initialize a single-column index. */ bool init(int col_idx); - uint get_column_count() { return key_column_count; } - uint get_keyid() { return keyid; } - Field *get_field(uint i) + uint get_column_count() const { return key_column_count; } + uint get_keyid() const { return keyid; } + Field *get_field(uint i) const { DBUG_ASSERT(i < key_column_count); return key_columns[i]->field; } - rownum_t get_min_null_row() { return min_null_row; } - rownum_t get_max_null_row() { return max_null_row; } + rownum_t get_min_null_row() const { return min_null_row; } + rownum_t get_max_null_row() const { return max_null_row; } MY_BITMAP * get_null_key() { return &null_key; } - ha_rows get_null_count() { return null_count; } - ha_rows get_key_buff_elements() { return key_buff_elements; } + ha_rows get_null_count() const { return null_count; } + ha_rows get_key_buff_elements() const { return key_buff_elements; } /* Get the search key element that corresponds to the i-th key part of this index. */ - Item *get_search_key(uint i) + Item *get_search_key(uint i) const { return search_key->element_index(key_columns[i]->field->field_index); } @@ -1343,7 +1343,7 @@ public: } bool sort_keys(); - double null_selectivity(); + inline double null_selectivity() const; /* Position the current element at the first row that matches the key. @@ -1371,7 +1371,7 @@ public: return FALSE; }; /* Return the current index element. */ - rownum_t current() + rownum_t current() const { DBUG_ASSERT(key_buff_elements && cur_key_idx < key_buff_elements); return key_buff[cur_key_idx]; @@ -1381,7 +1381,7 @@ public: { bitmap_set_bit(&null_key, (uint)row_num); } - bool is_null(rownum_t row_num) + bool is_null(rownum_t row_num) const { /* Indexes consisting of only NULLs do not have a bitmap buffer at all. @@ -1397,7 +1397,7 @@ public: return FALSE; return bitmap_is_set(&null_key, (uint)row_num); } - void print(String *str); + void print(String *str) const; }; @@ -1515,12 +1515,12 @@ protected: Comparison function to compare keys in order of decreasing bitmap selectivity. */ - static int cmp_keys_by_null_selectivity(Ordered_key **k1, Ordered_key **k2); + static int cmp_keys_by_null_selectivity(const void *k1, const void *k2); /* Comparison function used by the priority queue pq, the 'smaller' key is the one with the smaller current row number. */ - static int cmp_keys_by_cur_rownum(void *arg, uchar *k1, uchar *k2); + static int cmp_keys_by_cur_rownum(void *, const void *k1, const void *k2); bool test_null_row(rownum_t row_num); bool exists_complementing_null_row(MY_BITMAP *keys_to_complement); diff --git a/sql/item_sum.cc b/sql/item_sum.cc index b2b41fa1948..3b3661004c1 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -654,10 +654,11 @@ bool Item_sum::check_vcol_func_processor(void *arg) @retval > 0 if key1 > key2 */ -int simple_str_key_cmp(void* arg, uchar* key1, uchar* key2) +int simple_str_key_cmp(void *arg, const void *key1, const void *key2) { - Field *f= (Field*) arg; - return f->cmp(key1, key2); + Field *f= static_cast(arg); + return f->cmp(static_cast(key1), + static_cast(key2)); } @@ -687,9 +688,12 @@ C_MODE_END @retval >0 if key1 > key2 */ -int Aggregator_distinct::composite_key_cmp(void* arg, uchar* key1, uchar* key2) +int Aggregator_distinct::composite_key_cmp(void *arg, const void *key1_, + const void *key2_) { - Aggregator_distinct *aggr= (Aggregator_distinct *) arg; + const uchar *key1= static_cast(key1_); + const uchar *key2= static_cast(key2_); + Aggregator_distinct *aggr= static_cast(arg); Field **field = aggr->table->field; Field **field_end= field + aggr->table->s->fields; uint32 *lengths=aggr->field_lengths; @@ -706,7 +710,6 @@ int Aggregator_distinct::composite_key_cmp(void* arg, uchar* key1, uchar* key2) return 0; } - /***************************************************************************/ C_MODE_START @@ -715,7 +718,7 @@ C_MODE_START int simple_raw_key_cmp(void* arg, const void* key1, const void* key2) { - return memcmp(key1, key2, *(uint *) arg); + return memcmp(key1, key2, *(static_cast(arg))); } @@ -837,7 +840,7 @@ bool Aggregator_distinct::setup(THD *thd) if (all_binary) { cmp_arg= (void*) &tree_key_length; - compare_key= (qsort_cmp2) simple_raw_key_cmp; + compare_key= simple_raw_key_cmp; } else { @@ -849,14 +852,14 @@ bool Aggregator_distinct::setup(THD *thd) compare method that can take advantage of not having to worry about other fields. */ - compare_key= (qsort_cmp2) simple_str_key_cmp; + compare_key= simple_str_key_cmp; cmp_arg= (void*) table->field[0]; /* tree_key_length has been set already */ } else { uint32 *length; - compare_key= (qsort_cmp2) composite_key_cmp; + compare_key= composite_key_cmp; cmp_arg= (void*) this; field_lengths= (uint32*) thd->alloc(table->s->fields * sizeof(uint32)); for (tree_key_length= 0, length= field_lengths, field= table->field; @@ -3559,11 +3562,10 @@ String *Item_sum_udf_str::val_str(String *str) @retval 1 : key1 > key2 */ -extern "C" -int group_concat_key_cmp_with_distinct(void* arg, const void* key1, - const void* key2) +extern "C" int group_concat_key_cmp_with_distinct(void *arg, const void *key1, + const void *key2) { - Item_func_group_concat *item_func= (Item_func_group_concat*)arg; + auto item_func= static_cast(arg); for (uint i= 0; i < item_func->arg_count_field; i++) { @@ -3602,11 +3604,11 @@ int group_concat_key_cmp_with_distinct(void* arg, const void* key1, Used for JSON_ARRAYAGG function */ -int group_concat_key_cmp_with_distinct_with_nulls(void* arg, - const void* key1_arg, - const void* key2_arg) +int group_concat_key_cmp_with_distinct_with_nulls(void *arg, + const void *key1_arg, + const void *key2_arg) { - Item_func_group_concat *item_func= (Item_func_group_concat*)arg; + auto item_func= static_cast(arg); uchar *key1= (uchar*)key1_arg + item_func->table->s->null_bytes; uchar *key2= (uchar*)key2_arg + item_func->table->s->null_bytes; @@ -3655,11 +3657,10 @@ int group_concat_key_cmp_with_distinct_with_nulls(void* arg, function of sort for syntax: GROUP_CONCAT(expr,... ORDER BY col,... ) */ -extern "C" -int group_concat_key_cmp_with_order(void* arg, const void* key1, - const void* key2) +extern "C" int group_concat_key_cmp_with_order(void *arg, const void *key1, + const void *key2) { - Item_func_group_concat* grp_item= (Item_func_group_concat*) arg; + auto grp_item= static_cast(arg); ORDER **order_item, **end; for (order_item= grp_item->order, end=order_item+ grp_item->arg_count_order; @@ -3715,10 +3716,11 @@ int group_concat_key_cmp_with_order(void* arg, const void* key1, Used for JSON_ARRAYAGG function */ -int group_concat_key_cmp_with_order_with_nulls(void *arg, const void *key1_arg, +int group_concat_key_cmp_with_order_with_nulls(void *arg, + const void *key1_arg, const void *key2_arg) { - Item_func_group_concat* grp_item= (Item_func_group_concat*) arg; + auto grp_item= static_cast(arg); ORDER **order_item, **end; uchar *key1= (uchar*)key1_arg + grp_item->table->s->null_bytes; diff --git a/sql/item_sum.h b/sql/item_sum.h index d7feb622aa8..2ebe0b554fb 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -714,7 +714,7 @@ public: bool unique_walk_function(void *element); bool unique_walk_function_for_count(void *element); - static int composite_key_cmp(void* arg, uchar* key1, uchar* key2); + static int composite_key_cmp(void *arg, const void *key1, const void *key2); }; @@ -1872,12 +1872,12 @@ public: #endif /* HAVE_DLOPEN */ C_MODE_START -int group_concat_key_cmp_with_distinct(void* arg, const void* key1, - const void* key2); -int group_concat_key_cmp_with_distinct_with_nulls(void* arg, const void* key1, - const void* key2); -int group_concat_key_cmp_with_order(void* arg, const void* key1, - const void* key2); +int group_concat_key_cmp_with_distinct(void *arg, const void *key1, + const void *key2); +int group_concat_key_cmp_with_distinct_with_nulls(void *arg, const void *key1, + const void *key2); +int group_concat_key_cmp_with_order(void *arg, const void *key1, + const void *key2); int group_concat_key_cmp_with_order_with_nulls(void *arg, const void *key1, const void *key2); int dump_leaf_key(void* key_arg, @@ -1940,15 +1940,16 @@ protected: */ bool add(bool exclude_nulls); - friend int group_concat_key_cmp_with_distinct(void* arg, const void* key1, - const void* key2); - friend int group_concat_key_cmp_with_distinct_with_nulls(void* arg, - const void* key1, - const void* key2); - friend int group_concat_key_cmp_with_order(void* arg, const void* key1, - const void* key2); + friend int group_concat_key_cmp_with_distinct(void *arg, const void *key1, + const void *key2); + friend int group_concat_key_cmp_with_distinct_with_nulls(void *arg, + const void *key1, + const void *key2); + friend int group_concat_key_cmp_with_order(void *arg, const void *key1, + const void *key2); friend int group_concat_key_cmp_with_order_with_nulls(void *arg, - const void *key1, const void *key2); + const void *key1, + const void *key2); friend int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)), void* item_arg); diff --git a/sql/key.cc b/sql/key.cc index fa0239b49fc..d3900380922 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -551,10 +551,10 @@ int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length) @retval +1 first_rec is greater than second_rec */ -int key_rec_cmp(void *key_p, uchar *first_rec, uchar *second_rec) +int key_rec_cmp(const KEY *const *key, const uchar *first_rec, + const uchar *second_rec) { - KEY **key= (KEY**) key_p; - KEY *key_info= *(key++); // Start with first key + const KEY *key_info= *(key++); // Start with first key uint key_parts, key_part_num; KEY_PART_INFO *key_part= key_info->key_part; uchar *rec0= key_part->field->ptr - key_part->offset; @@ -642,10 +642,10 @@ next_loop: @retval +1 key1 > key2 */ -int key_tuple_cmp(KEY_PART_INFO *part, uchar *key1, uchar *key2, +int key_tuple_cmp(KEY_PART_INFO *part, const uchar *key1, const uchar *key2, uint tuple_length) { - uchar *key1_end= key1 + tuple_length; + const uchar *key1_end= key1 + tuple_length; int UNINIT_VAR(len); int res; for (;key1 < key1_end; key1 += len, key2 += len, part++) @@ -672,7 +672,6 @@ int key_tuple_cmp(KEY_PART_INFO *part, uchar *key1, uchar *key2, return 0; } - /** Get hash value for the key from a key buffer diff --git a/sql/key.h b/sql/key.h index 871373bfcd5..1af10168357 100644 --- a/sql/key.h +++ b/sql/key.h @@ -38,7 +38,9 @@ int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length); ulong key_hashnr(KEY *key_info, uint used_key_parts, const uchar *key); bool key_buf_cmp(KEY *key_info, uint used_key_parts, const uchar *key1, const uchar *key2); -extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b); -int key_tuple_cmp(KEY_PART_INFO *part, uchar *key1, uchar *key2, uint tuple_length); +extern "C" int key_rec_cmp(const KEY *const *key_info, const uchar *a, + const uchar *b); +int key_tuple_cmp(KEY_PART_INFO *part, const uchar *key1, const uchar *key2, + uint tuple_length); #endif /* KEY_INCLUDED */ diff --git a/sql/multi_range_read.cc b/sql/multi_range_read.cc index 54a0340638c..a25989d2e7c 100644 --- a/sql/multi_range_read.cc +++ b/sql/multi_range_read.cc @@ -761,9 +761,9 @@ int Mrr_ordered_index_reader::refill_buffer(bool initial) status_var_increment(thd->status_var.ha_mrr_key_refills_count); } - key_buffer->sort((key_buffer->type() == Lifo_buffer::FORWARD)? - (qsort2_cmp)Mrr_ordered_index_reader::compare_keys_reverse : - (qsort2_cmp)Mrr_ordered_index_reader::compare_keys, + key_buffer->sort((key_buffer->type() == Lifo_buffer::FORWARD) + ? Mrr_ordered_index_reader::compare_keys_reverse + : Mrr_ordered_index_reader::compare_keys, this); DBUG_RETURN(0); } @@ -795,9 +795,11 @@ int Mrr_ordered_index_reader::init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, } -static int rowid_cmp_reverse(void *file, uchar *a, uchar *b) +static int rowid_cmp_reverse(void *file, const void *a, const void *b) { - return - ((handler*)file)->cmp_ref(a, b); + return -(static_cast(file)) + ->cmp_ref(static_cast(a), + static_cast(b)); } @@ -933,7 +935,7 @@ int Mrr_ordered_rndpos_reader::refill_from_index_reader() if (!index_reader_needs_refill) index_reader->interrupt_read(); /* Sort the buffer contents by rowid */ - rowid_buffer->sort((qsort2_cmp)rowid_cmp_reverse, (void*)file); + rowid_buffer->sort(rowid_cmp_reverse, (void*)file); rowid_buffer->setup_reading(file->ref_length, is_mrr_assoc ? sizeof(range_id_t) : 0); @@ -1402,14 +1404,16 @@ void DsMrr_impl::dsmrr_close() my_qsort2-compatible static member function to compare key tuples */ -int Mrr_ordered_index_reader::compare_keys(void* arg, uchar* key1_arg, - uchar* key2_arg) +int Mrr_ordered_index_reader::compare_keys(void *arg, const void *key1_arg_, + const void *key2_arg_) { - Mrr_ordered_index_reader *reader= (Mrr_ordered_index_reader*)arg; + auto key1_arg= static_cast(key1_arg_); + auto key2_arg= static_cast(key2_arg_); + auto reader= static_cast(arg); TABLE *table= reader->file->get_table(); KEY_PART_INFO *part= table->key_info[reader->file->active_index].key_part; - uchar *key1, *key2; - + const uchar *key1, *key2; + if (reader->keypar.use_key_pointers) { /* the buffer stores pointers to keys, get to the keys */ @@ -1426,8 +1430,8 @@ int Mrr_ordered_index_reader::compare_keys(void* arg, uchar* key1_arg, } -int Mrr_ordered_index_reader::compare_keys_reverse(void* arg, uchar* key1, - uchar* key2) +int Mrr_ordered_index_reader::compare_keys_reverse(void *arg, const void *key1, + const void *key2) { return -compare_keys(arg, key1, key2); } diff --git a/sql/multi_range_read.h b/sql/multi_range_read.h index 32b23c912c1..bdc24fb9324 100644 --- a/sql/multi_range_read.h +++ b/sql/multi_range_read.h @@ -346,9 +346,10 @@ private: */ bool read_was_interrupted; - static int compare_keys(void* arg, uchar* key1, uchar* key2); - static int compare_keys_reverse(void* arg, uchar* key1, uchar* key2); - + static int compare_keys(void *arg, const void *key1, const void *key2); + static int compare_keys_reverse(void *arg, const void *key1, + const void *key2); + friend class Key_value_records_iterator; friend class DsMrr_impl; friend class Mrr_ordered_rndpos_reader; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 7663069e034..b940a40afbf 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7679,10 +7679,10 @@ static void print_version(void) } /** Compares two options' names, treats - and _ the same */ -static int option_cmp(my_option *a, my_option *b) +static int option_cmp(const void *a, const void *b) { - const char *sa= a->name; - const char *sb= b->name; + const char *sa= static_cast(a)->name; + const char *sb= static_cast(b)->name; for (; *sa || *sb; sa++, sb++) { if (*sa < *sb) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index a96014899fd..af00e190e49 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1749,11 +1749,13 @@ QUICK_ROR_UNION_SELECT::QUICK_ROR_UNION_SELECT(THD *thd_param, C_MODE_START -static int QUICK_ROR_UNION_SELECT_queue_cmp(void *arg, uchar *val1, uchar *val2) +static int QUICK_ROR_UNION_SELECT_queue_cmp(void *arg, const void *val1_, + const void *val2_) { - QUICK_ROR_UNION_SELECT *self= (QUICK_ROR_UNION_SELECT*)arg; - return self->head->file->cmp_ref(((QUICK_SELECT_I*)val1)->last_rowid, - ((QUICK_SELECT_I*)val2)->last_rowid); + auto self= static_cast(arg); + auto val1= static_cast(val1_); + auto val2= static_cast(val2_); + return self->head->file->cmp_ref(val1->last_rowid, val2->last_rowid); } C_MODE_END @@ -3346,8 +3348,11 @@ double records_in_column_ranges(PARAM *param, uint idx, */ static -int cmp_quick_ranges(TABLE *table, uint *a, uint *b) +int cmp_quick_ranges(void *table_, const void *a_, const void *b_) { + TABLE *table= static_cast(table_); + const uint *a= static_cast(a_); + const uint *b= static_cast(b_); int tmp= CMP_NUM(table->opt_range[*a].rows, table->opt_range[*b].rows); if (tmp) return tmp; @@ -3440,9 +3445,8 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) if (table->opt_range_keys.is_set(keynr)) optimal_key_order[ranges++]= keynr; - my_qsort2(optimal_key_order, ranges, - sizeof(optimal_key_order[0]), - (qsort2_cmp) cmp_quick_ranges, table); + my_qsort2(optimal_key_order, ranges, sizeof(optimal_key_order[0]), + cmp_quick_ranges, table); for (range_index= 0 ; range_index < ranges ; range_index++) { @@ -5751,8 +5755,10 @@ bool create_fields_bitmap(PARAM *param, MY_BITMAP *fields_bitmap) /* Compare two indexes scans for sort before search for the best intersection */ static -int cmp_intersect_index_scan(INDEX_SCAN_INFO **a, INDEX_SCAN_INFO **b) +int cmp_intersect_index_scan(const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); return (*a)->records < (*b)->records ? -1 : (*a)->records == (*b)->records ? 0 : 1; } @@ -6685,8 +6691,10 @@ ROR_SCAN_INFO *make_ror_scan(const PARAM *param, int idx, SEL_ARG *sel_arg) 1 a > b */ -static int cmp_ror_scan_info(ROR_SCAN_INFO** a, ROR_SCAN_INFO** b) +static int cmp_ror_scan_info(const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); double val1= rows2double((*a)->records) * (*a)->key_rec_length; double val2= rows2double((*b)->records) * (*b)->key_rec_length; return (val1 < val2)? -1: (val1 == val2)? 0 : 1; @@ -6709,8 +6717,10 @@ static int cmp_ror_scan_info(ROR_SCAN_INFO** a, ROR_SCAN_INFO** b) 1 a > b */ -static int cmp_ror_scan_info_covering(ROR_SCAN_INFO** a, ROR_SCAN_INFO** b) +static int cmp_ror_scan_info_covering(const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); if ((*a)->used_fields_covered > (*b)->used_fields_covered) return -1; if ((*a)->used_fields_covered < (*b)->used_fields_covered) diff --git a/sql/opt_split.cc b/sql/opt_split.cc index 0d479bbda3e..5e6d1a829cd 100644 --- a/sql/opt_split.cc +++ b/sql/opt_split.cc @@ -672,8 +672,10 @@ add_ext_keyuse_for_splitting(Dynamic_array *ext_keyuses, static int -sort_ext_keyuse(KEYUSE_EXT *a, KEYUSE_EXT *b) +sort_ext_keyuse(const void *a_, const void *b_) { + const KEYUSE_EXT *a= static_cast(a_); + const KEYUSE_EXT *b= static_cast(b_); if (a->table->tablenr != b->table->tablenr) return (int) (a->table->tablenr - b->table->tablenr); if (a->key != b->key) diff --git a/sql/records.cc b/sql/records.cc index 8da605072a6..e98166b77aa 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -43,7 +43,7 @@ template static int rr_unpack_from_buffer(READ_RECORD *info); int rr_from_pointers(READ_RECORD *info); static int rr_from_cache(READ_RECORD *info); static int init_rr_cache(THD *thd, READ_RECORD *info); -static int rr_cmp(uchar *a,uchar *b); +static int rr_cmp(const void *a, const void *b); static int rr_index_first(READ_RECORD *info); static int rr_index_last(READ_RECORD *info); static int rr_index(READ_RECORD *info); @@ -772,8 +772,10 @@ static int rr_from_cache(READ_RECORD *info) } /* rr_from_cache */ -static int rr_cmp(uchar *a,uchar *b) +static int rr_cmp(const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); if (a[0] != b[0]) return (int) a[0] - (int) b[0]; if (a[1] != b[1]) diff --git a/sql/rowid_filter.cc b/sql/rowid_filter.cc index d85bed96a95..5518c30ffbd 100644 --- a/sql/rowid_filter.cc +++ b/sql/rowid_filter.cc @@ -172,12 +172,12 @@ Rowid_filter_container *Range_rowid_filter_cost_info::create_container() } -static -int compare_range_rowid_filter_cost_info_by_a( - Range_rowid_filter_cost_info **filter_ptr_1, - Range_rowid_filter_cost_info **filter_ptr_2) +static int compare_range_rowid_filter_cost_info_by_a(const void *p1_, + const void *p2_) { - double diff= (*filter_ptr_2)->get_a() - (*filter_ptr_1)->get_a(); + auto p1= static_cast(p1_); + auto p2= static_cast(p2_); + double diff= (*p2)->get_a() - (*p1)->get_a(); return (diff < 0 ? -1 : (diff > 0 ? 1 : 0)); } diff --git a/sql/rowid_filter.h b/sql/rowid_filter.h index 34a3ad252e1..10ddb5d6c36 100644 --- a/sql/rowid_filter.h +++ b/sql/rowid_filter.h @@ -343,11 +343,10 @@ public: uint elements() { return (uint) (array->elements() / elem_size); } - void sort (int (*cmp) (void *ctxt, const void *el1, const void *el2), - void *cmp_arg) + void sort(qsort_cmp2 cmp, void *cmp_arg) { - my_qsort2(array->front(), array->elements()/elem_size, - elem_size, (qsort2_cmp) cmp, cmp_arg); + my_qsort2(array->front(), array->elements() / elem_size, elem_size, cmp, + cmp_arg); } bool is_empty() { return elements() == 0; } @@ -464,7 +463,7 @@ public: Rowid_filter_container *create_container(); - double get_a() { return a; } + double get_a() const { return a; } void trace_info(THD *thd); diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 70f61b7e300..93a83426d37 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -2925,10 +2925,10 @@ gtid_waiting::destroy() static int -cmp_queue_elem(void *, uchar *a, uchar *b) +cmp_queue_elem(void *, const void *a, const void *b) { - uint64 seq_no_a= *(uint64 *)a; - uint64 seq_no_b= *(uint64 *)b; + auto seq_no_a= *(static_cast(a)); + auto seq_no_b= *(static_cast(b)); if (seq_no_a < seq_no_b) return -1; else if (seq_no_a == seq_no_b) diff --git a/sql/set_var.cc b/sql/set_var.cc index 861db2c1b8d..3c5826d4491 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -614,8 +614,10 @@ int mysql_del_sys_var_chain(sys_var *first) } -static int show_cmp(SHOW_VAR *a, SHOW_VAR *b) +static int show_cmp(const void *a_, const void *b_) { + const SHOW_VAR *a= static_cast(a_); + const SHOW_VAR *b= static_cast(b_); return strcmp(a->name, b->name); } diff --git a/sql/slave.cc b/sql/slave.cc index e2dc95b672f..6f4176f233d 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -3383,9 +3383,11 @@ static bool send_show_master_info_data(THD *thd, Master_info *mi, bool full, /* Used to sort connections by name */ -static int cmp_mi_by_name(const Master_info **arg1, - const Master_info **arg2) +static int cmp_mi_by_name(const void *arg1_, + const void *arg2_) { + auto arg1= static_cast(arg1_); + auto arg2= static_cast(arg2_); return my_strcasecmp(system_charset_info, (*arg1)->connection_name.str, (*arg2)->connection_name.str); } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 8c7caf9e022..81f06802fb7 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -997,9 +997,10 @@ sp_head::create_result_field(uint field_max_length, const LEX_CSTRING *field_nam } -int cmp_rqp_locations(Rewritable_query_parameter * const *a, - Rewritable_query_parameter * const *b) +int cmp_rqp_locations(const void *a_, const void *b_) { + auto a= static_cast(a_); + auto b= static_cast(b_); return (int)((*a)->pos_in_query - (*b)->pos_in_query); } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 9a9217fb7da..e7336f1e133 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -657,7 +657,6 @@ bool ROLE_GRANT_PAIR::init(MEM_ROOT *mem, const char *username, static DYNAMIC_ARRAY acl_hosts, acl_users, acl_proxy_users; static Dynamic_array acl_dbs(PSI_INSTRUMENT_MEM, 0U, 50U); -typedef Dynamic_array::CMP_FUNC acl_dbs_cmp; static HASH acl_roles; /* An hash containing mappings user <--> role @@ -675,10 +674,10 @@ static DYNAMIC_ARRAY acl_wild_hosts; static Hash_filo *acl_cache; static uint grant_version=0; /* Version of priv tables. incremented by acl_load */ static privilege_t get_access(TABLE *form, uint fieldnr, uint *next_field=0); -static int acl_compare(const ACL_ACCESS *a, const ACL_ACCESS *b); -static int acl_user_compare(const ACL_USER *a, const ACL_USER *b); +static int acl_compare(const void *a, const void *b); +static int acl_user_compare(const void *a, const void *b); static void rebuild_acl_users(); -static int acl_db_compare(const ACL_DB *a, const ACL_DB *b); +static int acl_db_compare(const void *a, const void *b); static void rebuild_acl_dbs(); static void init_check_host(void); static void rebuild_check_host(void); @@ -3004,8 +3003,10 @@ static privilege_t get_access(TABLE *form, uint fieldnr, uint *next_field) } -static int acl_compare(const ACL_ACCESS *a, const ACL_ACCESS *b) +static int acl_compare(const void *a_, const void *b_) { + const ACL_ACCESS *a= static_cast(a_); + const ACL_ACCESS *b= static_cast(b_); if (a->sort > b->sort) return -1; if (a->sort < b->sort) @@ -3013,8 +3014,11 @@ static int acl_compare(const ACL_ACCESS *a, const ACL_ACCESS *b) return 0; } -static int acl_user_compare(const ACL_USER *a, const ACL_USER *b) +static int acl_user_compare(const void *a_, const void *b_) { + const ACL_USER *a= static_cast(a_); + const ACL_USER *b= static_cast(b_); + int res= strcmp(a->user.str, b->user.str); if (res) return res; @@ -3033,8 +3037,10 @@ static int acl_user_compare(const ACL_USER *a, const ACL_USER *b) return -strcmp(a->host.hostname, b->host.hostname); } -static int acl_db_compare(const ACL_DB *a, const ACL_DB *b) +static int acl_db_compare(const void *a_, const void *b_) { + const ACL_DB *a= static_cast(a_); + const ACL_DB *b= static_cast(b_); int res= strcmp(a->user, b->user); if (res) return res; @@ -6522,8 +6528,10 @@ static bool merge_role_global_privileges(ACL_ROLE *grantee) return old != grantee->access; } -static int db_name_sort(const int *db1, const int *db2) +static int db_name_sort(const void *db1_, const void *db2_) { + auto db1= static_cast(db1_); + auto db2= static_cast(db2_); return strcmp(acl_dbs.at(*db1).db, acl_dbs.at(*db2).db); } @@ -6676,8 +6684,10 @@ static bool merge_role_db_privileges(ACL_ROLE *grantee, const char *dbname, return update_flags; } -static int table_name_sort(GRANT_TABLE * const *tbl1, GRANT_TABLE * const *tbl2) +static int table_name_sort(const void *tbl1_, const void *tbl2_) { + auto tbl1= static_cast(tbl1_); + auto tbl2= static_cast(tbl2_); int res = strcmp((*tbl1)->db, (*tbl2)->db); if (res) return res; return strcmp((*tbl1)->tname, (*tbl2)->tname); @@ -6878,8 +6888,10 @@ static bool merge_role_table_and_column_privileges(ACL_ROLE *grantee, return update_flags; } -static int routine_name_sort(GRANT_NAME * const *r1, GRANT_NAME * const *r2) +static int routine_name_sort(const void *r1_, const void *r2_) { + auto r1= static_cast(r1_); + auto r2= static_cast(r2_); int res= strcmp((*r1)->db, (*r2)->db); if (res) return res; return strcmp((*r1)->tname, (*r2)->tname); diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index e17c6e190e2..f92ab417209 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -38,32 +38,40 @@ #define MAX_TREEMEM 8192 #define MAX_TREE_ELEMENTS 256 -int sortcmp2(void* cmp_arg __attribute__((unused)), - const String *a,const String *b) +int sortcmp2(void *, const void *a_, const void *b_) { + const String *a= static_cast(a_); + const String *b= static_cast(b_); return sortcmp(a,b,a->charset()); } -int compare_double2(void* cmp_arg __attribute__((unused)), - const double *s, const double *t) +int compare_double2(void *, const void *s_, const void *t_) { + const double *s= static_cast(s_); + const double *t= static_cast(t_); + return compare_double(s,t); } -int compare_longlong2(void* cmp_arg __attribute__((unused)), - const longlong *s, const longlong *t) +int compare_longlong2(void *, const void *s_, const void *t_) { + const longlong *s= static_cast(s_); + const longlong *t= static_cast(t_); return compare_longlong(s,t); } -int compare_ulonglong2(void* cmp_arg __attribute__((unused)), - const ulonglong *s, const ulonglong *t) +int compare_ulonglong2(void *, const void *s_, const void *t_) { + const ulonglong *s= static_cast(s_); + const ulonglong *t= static_cast(t_); return compare_ulonglong(s,t); } -int compare_decimal2(int* len, const char *s, const char *t) +int compare_decimal2(void *_len, const void *s_, const void *t_) { + int *len= static_cast(_len); + const char *s= static_cast(s_); + const char *t= static_cast(t_); return memcmp(s, t, *len); } diff --git a/sql/sql_analyse.h b/sql/sql_analyse.h index 07be346ab20..1f3089ae25a 100644 --- a/sql/sql_analyse.h +++ b/sql/sql_analyse.h @@ -57,15 +57,12 @@ uint check_ulonglong(const char *str, uint length); bool get_ev_num_info(EV_NUM_INFO *ev_info, NUM_INFO *info, const char *num); bool test_if_number(NUM_INFO *info, const char *str, uint str_len); int compare_double(const double *s, const double *t); -int compare_double2(void* cmp_arg __attribute__((unused)), - const double *s, const double *t); +int compare_double2(void *, const void *s, const void *t); int compare_longlong(const longlong *s, const longlong *t); -int compare_longlong2(void* cmp_arg __attribute__((unused)), - const longlong *s, const longlong *t); +int compare_longlong2(void *, const void *s, const void *t); int compare_ulonglong(const ulonglong *s, const ulonglong *t); -int compare_ulonglong2(void* cmp_arg __attribute__((unused)), - const ulonglong *s, const ulonglong *t); -int compare_decimal2(int* len, const char *s, const char *t); +int compare_ulonglong2(void *, const void *s, const void *t); +int compare_decimal2(void *len, const void *s, const void *t); Procedure *proc_analyse_init(THD *thd, ORDER *param, select_result *result, List &field_list); int free_string(void* str, TREE_FREE, void*); @@ -102,8 +99,7 @@ public: int collect_string(String *element, element_count count, TREE_INFO *info); -int sortcmp2(void* cmp_arg __attribute__((unused)), - const String *a,const String *b); +int sortcmp2(void *, const void *a, const void *b); class field_str :public field_info { @@ -120,8 +116,10 @@ public: max_arg("",default_charset_info), sum(0), must_be_blob(0), was_zero_fill(0), was_maybe_zerofill(0), can_be_still_num(1) - { init_tree(&tree, 0, 0, sizeof(String), (qsort_cmp2) sortcmp2, - free_string, NULL, MYF(MY_THREAD_SPECIFIC)); }; + { + init_tree(&tree, 0, 0, sizeof(String), sortcmp2, free_string, NULL, + MYF(MY_THREAD_SPECIFIC)); + }; void add() override; void get_opt_type(String*, ha_rows) override; @@ -161,8 +159,8 @@ public: field_decimal(Item* a, analyse* b) :field_info(a,b) { bin_size= my_decimal_get_binary_size(a->max_length, a->decimals); - init_tree(&tree, 0, 0, bin_size, (qsort_cmp2)compare_decimal2, - 0, (void *)&bin_size, MYF(MY_THREAD_SPECIFIC)); + init_tree(&tree, 0, 0, bin_size, compare_decimal2, 0, (void *) &bin_size, + MYF(MY_THREAD_SPECIFIC)); }; void add() override; @@ -189,9 +187,10 @@ class field_real: public field_info public: field_real(Item* a, analyse* b) :field_info(a,b), min_arg(0), max_arg(0), sum(0), sum_sqr(0), max_notzero_dec_len(0) - { init_tree(&tree, 0, 0, sizeof(double), - (qsort_cmp2) compare_double2, NULL, NULL, - MYF(MY_THREAD_SPECIFIC)); } + { + init_tree(&tree, 0, 0, sizeof(double), compare_double2, NULL, NULL, + MYF(MY_THREAD_SPECIFIC)); + } void add() override; void get_opt_type(String*, ha_rows) override; @@ -244,9 +243,10 @@ class field_longlong: public field_info public: field_longlong(Item* a, analyse* b) :field_info(a,b), min_arg(0), max_arg(0), sum(0), sum_sqr(0) - { init_tree(&tree, 0, 0, sizeof(longlong), - (qsort_cmp2) compare_longlong2, NULL, NULL, - MYF(MY_THREAD_SPECIFIC)); } + { + init_tree(&tree, 0, 0, sizeof(longlong), compare_longlong2, NULL, NULL, + MYF(MY_THREAD_SPECIFIC)); + } void add() override; void get_opt_type(String*, ha_rows) override; @@ -290,9 +290,10 @@ class field_ulonglong: public field_info public: field_ulonglong(Item* a, analyse * b) :field_info(a,b), min_arg(0), max_arg(0), sum(0),sum_sqr(0) - { init_tree(&tree, 0, 0, sizeof(ulonglong), - (qsort_cmp2) compare_ulonglong2, NULL, NULL, - MYF(MY_THREAD_SPECIFIC)); } + { + init_tree(&tree, 0, 0, sizeof(ulonglong), compare_ulonglong2, NULL, NULL, + MYF(MY_THREAD_SPECIFIC)); + } void add() override; void get_opt_type(String*, ha_rows) override; String *get_min_arg(String *s) override { s->set(min_arg,my_thd_charset); return s; } diff --git a/sql/sql_array.h b/sql/sql_array.h index bc4afa8906f..054a0ce654b 100644 --- a/sql/sql_array.h +++ b/sql/sql_array.h @@ -289,17 +289,14 @@ public: delete_dynamic(&array); } - typedef int (*CMP_FUNC)(const Elem *el1, const Elem *el2); - - void sort(CMP_FUNC cmp_func) + void sort(int (*cmp_func)(const void *, const void *)) { - my_qsort(array.buffer, array.elements, sizeof(Elem), (qsort_cmp)cmp_func); + my_qsort(array.buffer, array.elements, sizeof(Elem), cmp_func); } - typedef int (*CMP_FUNC2)(void *, const Elem *el1, const Elem *el2); - void sort(CMP_FUNC2 cmp_func, void *data) + void sort(qsort_cmp2 cmp_func, void *data) { - my_qsort2(array.buffer, array.elements, sizeof(Elem), (qsort2_cmp)cmp_func, data); + my_qsort2(array.buffer, array.elements, sizeof(Elem), cmp_func, data); } }; diff --git a/sql/sql_base.h b/sql/sql_base.h index e3d2a1dae56..894c8213e66 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -323,10 +323,9 @@ int dynamic_column_error_message(enum_dyncol_func_result rc); /* open_and_lock_tables with optional derived handling */ int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived); -extern "C" int simple_raw_key_cmp(void* arg, const void* key1, - const void* key2); +extern "C" qsort_cmp2 simple_raw_key_cmp; extern "C" int count_distinct_walk(void *elem, element_count count, void *arg); -int simple_str_key_cmp(void* arg, uchar* key1, uchar* key2); +int simple_str_key_cmp(void *arg, const void *key1, const void *key2); extern Item **not_found_item; extern Field *not_found_field; diff --git a/sql/sql_class.h b/sql/sql_class.h index 3d19b2f71cd..28aef92c31e 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -6759,10 +6759,10 @@ struct SORT_FIELD_ATTR CHARSET_INFO *cs; uint pack_sort_string(uchar *to, const Binary_string *str, CHARSET_INFO *cs) const; - int compare_packed_fixed_size_vals(uchar *a, size_t *a_len, - uchar *b, size_t *b_len); - int compare_packed_varstrings(uchar *a, size_t *a_len, - uchar *b, size_t *b_len); + int compare_packed_fixed_size_vals(const uchar *a, size_t *a_len, + const uchar *b, size_t *b_len); + int compare_packed_varstrings(const uchar *a, size_t *a_len, + const uchar *b, size_t *b_len); bool check_if_packing_possible(THD *thd) const; bool is_variable_sized() { return type == VARIABLE_SIZE; } void set_length_and_original_length(THD *thd, uint length_arg); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 4c5c4fb6ef5..7823350d7a3 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -1108,10 +1108,11 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds, ***************************************************************************/ -extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b) +extern "C" int refpos_order_cmp(void *arg, const void *a, const void *b) { - handler *file= (handler*)arg; - return file->cmp_ref((const uchar*)a, (const uchar*)b); + auto file= static_cast(arg); + return file->cmp_ref(static_cast(a), + static_cast(b)); } /* diff --git a/sql/sql_lifo_buffer.h b/sql/sql_lifo_buffer.h index 04496ef74b8..afe47b5f415 100644 --- a/sql/sql_lifo_buffer.h +++ b/sql/sql_lifo_buffer.h @@ -117,7 +117,7 @@ public: bool is_empty() { return used_size() == 0; } virtual bool read() = 0; - void sort(qsort2_cmp cmp_func, void *cmp_func_arg) + void sort(qsort_cmp2 cmp_func, void *cmp_func_arg) { size_t elem_size= size1 + size2; size_t n_elements= used_size() / elem_size; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c0598bde789..33004a42685 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -100,7 +100,7 @@ static bool update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse, uint tables, COND *conds, table_map table_map, SELECT_LEX *select_lex, SARGABLE_PARAM **sargables); -static int sort_keyuse(KEYUSE *a,KEYUSE *b); +static int sort_keyuse(const void *a, const void *b); static bool are_tables_local(JOIN_TAB *jtab, table_map used_tables); static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, KEYUSE *org_keyuse, bool allow_full_scan, table_map used_tables); @@ -119,9 +119,9 @@ static bool best_extension_by_limited_search(JOIN *join, uint use_cond_selectivity); static uint determine_search_depth(JOIN* join); C_MODE_START -static int join_tab_cmp(const void *dummy, const void* ptr1, const void* ptr2); -static int join_tab_cmp_straight(const void *dummy, const void* ptr1, const void* ptr2); -static int join_tab_cmp_embedded_first(const void *emb, const void* ptr1, const void *ptr2); +static int join_tab_cmp(void *dummy, const void* ptr1, const void* ptr2); +static int join_tab_cmp_straight(void *dummy, const void* ptr1, const void* ptr2); +static int join_tab_cmp_embedded_first(void *emb, const void* ptr1, const void *ptr2); C_MODE_END static uint cache_record_length(JOIN *join,uint index); static store_key *get_store_key(THD *thd, @@ -6838,8 +6838,10 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array, static int -sort_keyuse(KEYUSE *a,KEYUSE *b) +sort_keyuse(const void *a_, const void *b_) { + const KEYUSE *a= static_cast(a_); + const KEYUSE *b= static_cast(b_); int res; if (a->table->tablenr != b->table->tablenr) return (int) (a->table->tablenr - b->table->tablenr); @@ -8650,7 +8652,7 @@ choose_plan(JOIN *join, table_map join_tables) join->cur_embedding_map= 0; reset_nj_counters(join, join->join_list); - qsort2_cmp jtab_sort_func; + qsort_cmp2 jtab_sort_func; if (join->emb_sjm_nest) { @@ -8734,7 +8736,7 @@ choose_plan(JOIN *join, table_map join_tables) 1 - jt1 > jt2 */ -static int compare_embedding_subqueries(JOIN_TAB *jt1, JOIN_TAB *jt2) +static int compare_embedding_subqueries(const JOIN_TAB *jt1, const JOIN_TAB *jt2) { /* Determine if the first table is originally from a subquery */ TABLE_LIST *tbl1= jt1->table->pos_in_table_list; @@ -8809,10 +8811,10 @@ static int compare_embedding_subqueries(JOIN_TAB *jt1, JOIN_TAB *jt2) */ static int -join_tab_cmp(const void *dummy, const void* ptr1, const void* ptr2) +join_tab_cmp(void *, const void* ptr1, const void* ptr2) { - JOIN_TAB *jt1= *(JOIN_TAB**) ptr1; - JOIN_TAB *jt2= *(JOIN_TAB**) ptr2; + auto jt1= *(static_cast(ptr1)); + auto jt2= *(static_cast(ptr2)); int cmp; if ((cmp= compare_embedding_subqueries(jt1, jt2)) != 0) @@ -8839,10 +8841,10 @@ join_tab_cmp(const void *dummy, const void* ptr1, const void* ptr2) */ static int -join_tab_cmp_straight(const void *dummy, const void* ptr1, const void* ptr2) +join_tab_cmp_straight(void *, const void* ptr1, const void* ptr2) { - JOIN_TAB *jt1= *(JOIN_TAB**) ptr1; - JOIN_TAB *jt2= *(JOIN_TAB**) ptr2; + auto jt1= *(static_cast(ptr1)); + auto jt2= *(static_cast(ptr2)); /* We don't do subquery flattening if the parent or child select has @@ -8870,11 +8872,11 @@ join_tab_cmp_straight(const void *dummy, const void* ptr1, const void* ptr2) */ static int -join_tab_cmp_embedded_first(const void *emb, const void* ptr1, const void* ptr2) +join_tab_cmp_embedded_first(void *emb, const void* ptr1, const void* ptr2) { - const TABLE_LIST *emb_nest= (TABLE_LIST*) emb; - JOIN_TAB *jt1= *(JOIN_TAB**) ptr1; - JOIN_TAB *jt2= *(JOIN_TAB**) ptr2; + TABLE_LIST *emb_nest= static_cast(emb); + auto jt1= *(static_cast(ptr1)); + auto jt2= *(static_cast(ptr2)); if (jt1->emb_sj_nest == emb_nest && jt2->emb_sj_nest != emb_nest) return -1; @@ -25079,8 +25081,7 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table, (*field_length++)= (*ptr)->sort_length(); if (my_hash_init(key_memory_hash_index_key_buffer, &hash, &my_charset_bin, - (uint) file->stats.records, 0, key_length, - (my_hash_get_key) 0, 0, 0)) + (uint) file->stats.records, 0, key_length, 0, 0, 0)) { my_free(key_buffer); DBUG_RETURN(1); diff --git a/sql/sql_select.h b/sql/sql_select.h index 0f3eb19ad82..ca34e4a0261 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1945,7 +1945,7 @@ int opt_sum_query(THD* thd, List &tables, List &all_fields, COND *conds); /* from sql_delete.cc, used by opt_range.cc */ -extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b); +extern "C" int refpos_order_cmp(void *arg, const void *a,const void *b); /** class to copying an field/item to a key struct */ diff --git a/sql/sql_sort.h b/sql/sql_sort.h index 7b9512404ff..9f19aeaa996 100644 --- a/sql/sql_sort.h +++ b/sql/sql_sort.h @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ #include "my_base.h" /* ha_rows */ -#include /* qsort2_cmp */ +#include #include "queues.h" #include "sql_string.h" #include "sql_class.h" @@ -565,7 +565,7 @@ public: bool not_killable; String tmp_buffer; // The fields below are used only by Unique class. - qsort2_cmp compare; + qsort_cmp2 compare; BUFFPEK_COMPARE_CONTEXT cmp_context; Sort_param() @@ -669,7 +669,7 @@ public: void try_to_pack_sortkeys(); - qsort2_cmp get_compare_function() const + qsort_cmp2 get_compare_function() const { return using_packed_sortkeys() ? get_packed_keys_compare_ptr() : diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 26b4c088a98..cdbf02cb891 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -1646,8 +1646,8 @@ public: table_field= field; tree_key_length= field->pack_length(); - tree= new Unique((qsort_cmp2) simple_str_key_cmp, (void*) field, - tree_key_length, max_heap_table_size, 1); + tree= new Unique(simple_str_key_cmp, field, tree_key_length, + max_heap_table_size, 1); } virtual ~Count_distinct_field() @@ -1732,13 +1732,13 @@ public: static -int simple_ulonglong_key_cmp(void* arg, uchar* key1, uchar* key2) +int simple_ulonglong_key_cmp(void*, const void* key1, const void* key2) { - ulonglong *val1= (ulonglong *) key1; - ulonglong *val2= (ulonglong *) key2; + const ulonglong *val1= static_cast(key1); + const ulonglong *val2= static_cast(key2); return *val1 > *val2 ? 1 : *val1 == *val2 ? 0 : -1; } - + /* The class Count_distinct_field_bit is derived from the class @@ -1755,8 +1755,7 @@ public: table_field= field; tree_key_length= sizeof(ulonglong); - tree= new Unique((qsort_cmp2) simple_ulonglong_key_cmp, - (void*) &tree_key_length, + tree= new Unique(simple_ulonglong_key_cmp, &tree_key_length, tree_key_length, max_heap_table_size, 1); } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 15b2cac14e9..2119b98a0a2 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2957,8 +2957,10 @@ bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db, PRIMARY keys are prioritized. */ -static int sort_keys(KEY *a, KEY *b) +static int sort_keys(const void *a_, const void *b_) { + const KEY *a= static_cast(a_); + const KEY *b= static_cast(b_); ulong a_flags= a->flags, b_flags= b->flags; /* @@ -7143,8 +7145,10 @@ static bool fix_constraints_names(THD *thd, List } -static int compare_uint(const uint *s, const uint *t) +static int compare_uint(const void *s_, const void *t_) { + const uint *s= static_cast(s_); + const uint *t= static_cast(t_); return (*s < *t) ? -1 : ((*s > *t) ? 1 : 0); } diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 7727610088e..e46a3f2fda4 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -5844,9 +5844,9 @@ cmp_item *Type_handler_timestamp_common::make_cmp_item(THD *thd, /***************************************************************************/ -static int srtcmp_in(const void *cs_, const void *x_, const void *y_) +static int srtcmp_in(void *cs_, const void *x_, const void *y_) { - const CHARSET_INFO *cs= static_cast(cs_); + CHARSET_INFO *cs= static_cast(cs_); const String *x= static_cast(x_); const String *y= static_cast(y_); return cs->strnncollsp(x->ptr(), x->length(), y->ptr(), y->length()); @@ -5856,12 +5856,10 @@ in_vector *Type_handler_string_result::make_in_vector(THD *thd, const Item_func_in *func, uint nargs) const { - return new (thd->mem_root) in_string(thd, nargs, (qsort2_cmp) srtcmp_in, - func->compare_collation()); - + return new (thd->mem_root) + in_string(thd, nargs, srtcmp_in, func->compare_collation()); } - in_vector *Type_handler_int_result::make_in_vector(THD *thd, const Item_func_in *func, uint nargs) const diff --git a/sql/uniques.cc b/sql/uniques.cc index a0cebe3e4dd..2be3ca5d7ed 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -429,11 +429,13 @@ Unique::reset() C_MODE_START -static int buffpek_compare(void *arg, uchar *key_ptr1, uchar *key_ptr2) +static int buffpek_compare(void *arg, const void *key_ptr1, + const void *key_ptr2) { - BUFFPEK_COMPARE_CONTEXT *ctx= (BUFFPEK_COMPARE_CONTEXT *) arg; + auto ctx= static_cast(arg); return ctx->key_compare(ctx->key_compare_arg, - *((uchar **) key_ptr1), *((uchar **)key_ptr2)); + *(static_cast(key_ptr1)), + *(static_cast(key_ptr2))); } C_MODE_END @@ -734,7 +736,7 @@ bool Unique::merge(TABLE *table, uchar *buff, size_t buff_size, sort_param.unique_buff= buff +(sort_param.max_keys_per_buffer * sort_param.sort_length); - sort_param.compare= (qsort2_cmp) buffpek_compare; + sort_param.compare= buffpek_compare; sort_param.cmp_context.key_compare= tree.compare; sort_param.cmp_context.key_compare_arg= tree.custom_arg; diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index 894fdf2f200..7a41b3affdc 100644 --- a/storage/csv/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -96,8 +96,10 @@ static handler *tina_create_handler(handlerton *hton, /* Used for sorting chains with qsort(). */ -int sort_set (tina_set *a, tina_set *b) +int sort_set (const void *a_, const void *b_) { + const tina_set *a= static_cast(a_); + const tina_set *b= static_cast(b_); /* We assume that intervals do not intersect. So, it is enought to compare any two points. Here we take start of intervals for comparison. diff --git a/storage/heap/hp_create.c b/storage/heap/hp_create.c index 935c6f8d0fd..c07a1e968c4 100644 --- a/storage/heap/hp_create.c +++ b/storage/heap/hp_create.c @@ -16,7 +16,7 @@ #include "heapdef.h" -static int keys_compare(heap_rb_param *param, uchar *key1, uchar *key2); +static int keys_compare(void *heap_rb, const void *key1, const void *key2); static void init_block(HP_BLOCK *block,uint reclength,ulong min_records, ulong max_records); @@ -190,7 +190,7 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info, keyseg++; init_tree(&keyinfo->rb_tree, 0, 0, sizeof(uchar*), - (qsort_cmp2)keys_compare, NULL, NULL, + keys_compare, NULL, NULL, MYF((create_info->internal_table ? MY_THREAD_SPECIFIC : 0) | MY_TREE_WITH_DELETE)); keyinfo->delete_key= hp_rb_delete_key; @@ -255,11 +255,15 @@ err: } /* heap_create */ -static int keys_compare(heap_rb_param *param, uchar *key1, uchar *key2) +static int keys_compare(void *heap_rb_, const void *key1_, + const void *key2_) { + heap_rb_param *heap_rb= heap_rb_; + const uchar *key1= key1_; + const uchar *key2= key2_; uint not_used[2]; - return ha_key_cmp(param->keyseg, key1, key2, param->key_length, - param->search_flag, not_used); + return ha_key_cmp(heap_rb->keyseg, key1, key2, heap_rb->key_length, + heap_rb->search_flag, not_used); } static void init_block(HP_BLOCK *block, uint reclength, ulong min_records, diff --git a/storage/maria/aria_pack.c b/storage/maria/aria_pack.c index 40e7e399613..4a9719addd3 100644 --- a/storage/maria/aria_pack.c +++ b/storage/maria/aria_pack.c @@ -135,8 +135,8 @@ static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees, uint trees, HUFF_COUNTS *huff_counts, uint fields); -static int compare_tree(void* cmp_arg __attribute__((unused)), - const uchar *s,const uchar *t); +static int compare_tree(void *cmp_arg __attribute__((unused)), + const void *s, const void *t); static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts); static void check_counts(HUFF_COUNTS *huff_counts,uint trees, my_off_t records); @@ -146,7 +146,8 @@ static int test_space_compress(HUFF_COUNTS *huff_counts,my_off_t records, enum en_fieldtype field_type); static HUFF_TREE* make_huff_trees(HUFF_COUNTS *huff_counts,uint trees); static int make_huff_tree(HUFF_TREE *tree,HUFF_COUNTS *huff_counts); -static int compare_huff_elements(void *not_used, uchar *a,uchar *b); +static int compare_huff_elements(void *not_used, const void *a, + const void *b); static int save_counts_in_queue(uchar *key,element_count count, HUFF_TREE *tree); static my_off_t calc_packed_length(HUFF_COUNTS *huff_counts,uint flag); @@ -180,7 +181,7 @@ static int mrg_rrnd(PACK_MRG_INFO *info,uchar *buf); static void mrg_reset(PACK_MRG_INFO *mrg); #if !defined(DBUG_OFF) static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count); -static int fakecmp(my_off_t **count1, my_off_t **count2); +static int fakecmp(const void *count1, const void *count2); #endif /* @@ -905,8 +906,8 @@ static HUFF_COUNTS *init_huff_count(MARIA_HA *info,my_off_t records) 'tree_pos'. It's keys are implemented by pointers into 'tree_buff'. This is accomplished by '-1' as the element size. */ - init_tree(&count[col_nr].int_tree,0,0,-1,(qsort_cmp2) compare_tree, NULL, - NULL, MYF(0)); + init_tree(&count[col_nr].int_tree, 0, 0, -1, compare_tree, NULL, NULL, + MYF(0)); if (records && type != FIELD_BLOB && type != FIELD_VARCHAR) count[col_nr].tree_pos=count[col_nr].tree_buff = my_malloc(PSI_NOT_INSTRUMENTED, @@ -1258,12 +1259,14 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) } static int compare_huff_elements(void *not_used __attribute__((unused)), - uchar *a, uchar *b) + const void *a_, const void *b_) { - return *((my_off_t*) a) < *((my_off_t*) b) ? -1 : - (*((my_off_t*) a) == *((my_off_t*) b) ? 0 : 1); + const my_off_t *a= a_; + const my_off_t *b= b_; + return *a < *b ? -1 : (*a == *b ? 0 : 1); } + /* Check each tree if we should use pre-space-compress, end-space- compress, empty-field-compress or zero-field-compress */ @@ -1770,9 +1773,11 @@ static int make_huff_tree(HUFF_TREE *huff_tree, HUFF_COUNTS *huff_counts) return 0; } -static int compare_tree(void* cmp_arg __attribute__((unused)), - register const uchar *s, register const uchar *t) +static int compare_tree(void *cmp_arg __attribute__((unused)), const void *s_, + const void *t_) { + const uchar *s= s_; + const uchar *t= t_; uint length; for (length=global_count->field_length; length-- ;) if (*s++ != *t++) @@ -3323,8 +3328,10 @@ static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count) -1 count1 > count2 */ -static int fakecmp(my_off_t **count1, my_off_t **count2) +static int fakecmp(const void *count1_, const void *count2_) { + const my_off_t *const *count1= count1_; + const my_off_t *const *count2= count2_; return ((**count1 < **count2) ? 1 : (**count1 > **count2) ? -1 : 0); } diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index 7f104325d00..761ad0b7443 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -67,8 +67,7 @@ static int sort_one_index(HA_CHECK *param, MARIA_HA *info, static int sort_key_read(MARIA_SORT_PARAM *sort_param, uchar *key); static int sort_maria_ft_key_read(MARIA_SORT_PARAM *sort_param, uchar *key); static int sort_get_next_record(MARIA_SORT_PARAM *sort_param); -static int sort_key_cmp(MARIA_SORT_PARAM *sort_param, const void *a, - const void *b); +static int sort_key_cmp(void *sort_param, const void *a, const void *b); static int sort_maria_ft_key_write(MARIA_SORT_PARAM *sort_param, const uchar *a); static int sort_key_write(MARIA_SORT_PARAM *sort_param, const uchar *a); @@ -5624,9 +5623,9 @@ int _ma_sort_write_record(MARIA_SORT_PARAM *sort_param) /* Compare two keys from _ma_create_index_by_sort */ -static int sort_key_cmp(MARIA_SORT_PARAM *sort_param, const void *a, - const void *b) +static int sort_key_cmp(void *sort_param_, const void *a, const void *b) { + const MARIA_SORT_PARAM *sort_param= sort_param_; uint not_used[2]; return (ha_key_cmp(sort_param->seg, *((uchar* const *) a), *((uchar* const *) b), diff --git a/storage/maria/ma_create.c b/storage/maria/ma_create.c index 7ea8bffca99..db7a50f4f1d 100644 --- a/storage/maria/ma_create.c +++ b/storage/maria/ma_create.c @@ -31,7 +31,7 @@ #endif #include -static int compare_columns(MARIA_COLUMNDEF **a, MARIA_COLUMNDEF **b); +static int compare_columns(const void *a, const void *b); static ulonglong update_tot_length(ulonglong tot_length, ulonglong max_rows, uint length) @@ -1335,9 +1335,11 @@ static inline int sign(long a) } -static int compare_columns(MARIA_COLUMNDEF **a_ptr, MARIA_COLUMNDEF **b_ptr) +static int compare_columns(const void *a_ptr_, const void *b_ptr_) { - MARIA_COLUMNDEF *a= *a_ptr, *b= *b_ptr; + const MARIA_COLUMNDEF *const *a_ptr= a_ptr_; + const MARIA_COLUMNDEF *const *b_ptr= b_ptr_; + const MARIA_COLUMNDEF *a= *a_ptr, *b= *b_ptr; enum en_fieldtype a_type, b_type; a_type= (a->type == FIELD_CHECK) ? FIELD_NORMAL : a->type; diff --git a/storage/maria/ma_ft_boolean_search.c b/storage/maria/ma_ft_boolean_search.c index a7bc2a7f318..4a4bccf9ce5 100644 --- a/storage/maria/ma_ft_boolean_search.c +++ b/storage/maria/ma_ft_boolean_search.c @@ -144,9 +144,12 @@ typedef struct st_ft_info enum { UNINITIALIZED, READY, INDEX_SEARCH, INDEX_DONE } state; } FTB; -static int FTB_WORD_cmp(my_off_t *v, FTB_WORD *a, FTB_WORD *b) +static int FTB_WORD_cmp(void *v_, const void *a_, const void *b_) { int i; + const my_off_t *v= v_; + const FTB_WORD *a= a_; + const FTB_WORD *b= b_; /* if a==curdoc, take it as a < b */ if (v && a->docid[0] == *v) @@ -159,11 +162,15 @@ static int FTB_WORD_cmp(my_off_t *v, FTB_WORD *a, FTB_WORD *b) return i; } -static int FTB_WORD_cmp_list(CHARSET_INFO *cs, FTB_WORD **a, FTB_WORD **b) +static int FTB_WORD_cmp_list(void *cs_, const void *a_, const void *b_) { + CHARSET_INFO *cs= cs_; + const FTB_WORD *const *a= a_; + const FTB_WORD *const *b= b_; + /* ORDER BY word, ndepth */ - int i= ha_compare_word(cs, (uchar*) (*a)->word + 1, (*a)->len - 1, - (uchar*) (*b)->word + 1, (*b)->len - 1); + int i= ha_compare_word(cs, (*a)->word + 1, (*a)->len - 1, (*b)->word + 1, + (*b)->len - 1); if (!i) i=CMP_NUM((*a)->ndepth, (*b)->ndepth); return i; @@ -325,10 +332,12 @@ static int _ftb_parse_query(FTB *ftb, uchar *query, uint len, } -static int _ftb_no_dupes_cmp(void* not_used __attribute__((unused)), - const void *a,const void *b) +static int _ftb_no_dupes_cmp(void *not_used __attribute__((unused)), + const void *a_, const void *b_) { - return CMP_NUM((*((my_off_t*)a)), (*((my_off_t*)b))); + const my_off_t *a= a_; + const my_off_t *b= b_; + return CMP_NUM((*a), (*b)); } @@ -597,14 +606,14 @@ FT_INFO * maria_ft_init_boolean_search(MARIA_HA *info, uint keynr, sizeof(void *)))) goto err; reinit_queue(&ftb->queue, ftb->queue.max_elements, 0, 0, - (int (*)(void*, uchar*, uchar*))FTB_WORD_cmp, 0, 0, 0); + FTB_WORD_cmp, 0, 0, 0); for (ftbw= ftb->last_word; ftbw; ftbw= ftbw->prev) queue_insert(&ftb->queue, (uchar *)ftbw); ftb->list=(FTB_WORD **)alloc_root(&ftb->mem_root, sizeof(FTB_WORD *)*ftb->queue.elements); memcpy(ftb->list, ftb->queue.root+1, sizeof(FTB_WORD *)*ftb->queue.elements); my_qsort2(ftb->list, ftb->queue.elements, sizeof(FTB_WORD *), - (qsort2_cmp)FTB_WORD_cmp_list, (void*) ftb->charset); + FTB_WORD_cmp_list, (void*) ftb->charset); if (ftb->queue.elements<2) ftb->with_scan &= ~FTB_FLAG_TRUNC; ftb->state=READY; return ftb; diff --git a/storage/maria/ma_ft_nlq_search.c b/storage/maria/ma_ft_nlq_search.c index 890de3db0ad..2e5d19a607f 100644 --- a/storage/maria/ma_ft_nlq_search.c +++ b/storage/maria/ma_ft_nlq_search.c @@ -52,9 +52,11 @@ typedef struct st_ft_superdoc } FT_SUPERDOC; -static int FT_SUPERDOC_cmp(void* cmp_arg __attribute__((unused)), - FT_SUPERDOC *p1, FT_SUPERDOC *p2) +static int FT_SUPERDOC_cmp(void *cmp_arg __attribute__((unused)), + const void *p1_, const void *p2_) { + const FT_SUPERDOC *p1= p1_; + const FT_SUPERDOC *p2= p2_; if (p1->doc.dpos < p2->doc.dpos) return -1; if (p1->doc.dpos == p2->doc.dpos) @@ -209,8 +211,10 @@ static int walk_and_push(FT_SUPERDOC *from, static int FT_DOC_cmp(void *unused __attribute__((unused)), - FT_DOC *a, FT_DOC *b) + const void *a_, const void *b_) { + const FT_DOC *a= a_; + const FT_DOC *b= b_; return CMP_NUM(b->weight, a->weight); } @@ -244,8 +248,8 @@ FT_INFO *maria_ft_init_nlq_search(MARIA_HA *info, uint keynr, uchar *query, bzero(&wtree,sizeof(wtree)); - init_tree(&aio.dtree,0,0,sizeof(FT_SUPERDOC),(qsort_cmp2)&FT_SUPERDOC_cmp, - NULL, NULL, MYF(0)); + init_tree(&aio.dtree, 0, 0, sizeof(FT_SUPERDOC), &FT_SUPERDOC_cmp, NULL, + NULL, MYF(0)); maria_ft_parse_init(&wtree, aio.charset); ftparser_param->flags= 0; @@ -260,8 +264,7 @@ FT_INFO *maria_ft_init_nlq_search(MARIA_HA *info, uint keynr, uchar *query, if (flags & FT_EXPAND && ft_query_expansion_limit) { QUEUE best; - init_queue(&best,ft_query_expansion_limit,0,0, (queue_compare) &FT_DOC_cmp, - 0, 0, 0); + init_queue(&best, ft_query_expansion_limit, 0, 0, &FT_DOC_cmp, 0, 0, 0); tree_walk(&aio.dtree, (tree_walk_action) &walk_and_push, &best, left_root_right); while (best.elements) @@ -308,8 +311,7 @@ FT_INFO *maria_ft_init_nlq_search(MARIA_HA *info, uint keynr, uchar *query, &dptr, left_root_right); if (flags & FT_SORTED) - my_qsort2(dlist->doc, dlist->ndocs, sizeof(FT_DOC), - (qsort2_cmp)&FT_DOC_cmp, 0); + my_qsort2(dlist->doc, dlist->ndocs, sizeof(FT_DOC), &FT_DOC_cmp, 0); err: delete_tree(&aio.dtree, 0); diff --git a/storage/maria/ma_ft_parser.c b/storage/maria/ma_ft_parser.c index 4b4c9a94cb9..015fcdd0268 100644 --- a/storage/maria/ma_ft_parser.c +++ b/storage/maria/ma_ft_parser.c @@ -32,10 +32,12 @@ typedef struct st_my_maria_ft_parser_param } MY_FT_PARSER_PARAM; -static int FT_WORD_cmp(CHARSET_INFO* cs, FT_WORD *w1, FT_WORD *w2) +static int FT_WORD_cmp(void *cs_, const void *w1_, const void *w2_) { - return ha_compare_word(cs, (uchar*) w1->pos, w1->len, - (uchar*) w2->pos, w2->len); + CHARSET_INFO *cs= cs_; + const FT_WORD *w1= w1_; + const FT_WORD *w2= w2_; + return ha_compare_word(cs, w1->pos, w1->len, w2->pos, w2->len); } static int walk_and_copy(FT_WORD *word,uint32 count,FT_DOCSTAT *docstat) @@ -255,8 +257,8 @@ void maria_ft_parse_init(TREE *wtree, CHARSET_INFO *cs) { DBUG_ENTER("maria_ft_parse_init"); if (!is_tree_inited(wtree)) - init_tree(wtree,0,0,sizeof(FT_WORD),(qsort_cmp2)&FT_WORD_cmp, NULL, - (void*) cs, MYF(0)); + init_tree(wtree, 0, 0, sizeof(FT_WORD), &FT_WORD_cmp, NULL, (void *) cs, + MYF(0)); DBUG_VOID_RETURN; } diff --git a/storage/maria/ma_pagecache.c b/storage/maria/ma_pagecache.c index d1cfd578367..af7710ba127 100644 --- a/storage/maria/ma_pagecache.c +++ b/storage/maria/ma_pagecache.c @@ -4722,8 +4722,10 @@ static my_bool free_block(PAGECACHE *pagecache, PAGECACHE_BLOCK_LINK *block, } -static int cmp_sec_link(PAGECACHE_BLOCK_LINK **a, PAGECACHE_BLOCK_LINK **b) +static int cmp_sec_link(const void *a_, const void *b_) { + PAGECACHE_BLOCK_LINK *const *a= a_; + PAGECACHE_BLOCK_LINK *const *b= b_; return (((*a)->hash_link->pageno < (*b)->hash_link->pageno) ? -1 : ((*a)->hash_link->pageno > (*b)->hash_link->pageno) ? 1 : 0); } diff --git a/storage/maria/ma_sort.c b/storage/maria/ma_sort.c index 3e56fe51f41..042ae9aa7b0 100644 --- a/storage/maria/ma_sort.c +++ b/storage/maria/ma_sort.c @@ -752,8 +752,8 @@ static int write_keys(MARIA_SORT_PARAM *info, register uchar **sort_keys, if (!buffpek) DBUG_RETURN(1); /* Out of memory */ - my_qsort2((uchar*) sort_keys,(size_t) count, sizeof(uchar*), - (qsort2_cmp) info->key_cmp, info); + my_qsort2(sort_keys, count, sizeof(uchar*), + info->key_cmp, info); if (!my_b_inited(tempfile) && open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw)) @@ -798,8 +798,8 @@ static int write_keys_varlen(MARIA_SORT_PARAM *info, if (!buffpek) DBUG_RETURN(1); /* Out of memory */ - my_qsort2((uchar*) sort_keys, (size_t) count, sizeof(uchar*), - (qsort2_cmp) info->key_cmp, info); + my_qsort2(sort_keys, count, sizeof(uchar*), + info->key_cmp, info); if (!my_b_inited(tempfile) && open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw)) @@ -841,8 +841,8 @@ static int write_index(MARIA_SORT_PARAM *info, register uchar **sort_keys, { DBUG_ENTER("write_index"); - my_qsort2((uchar*) sort_keys,(size_t) count,sizeof(uchar*), - (qsort2_cmp) info->key_cmp,info); + my_qsort2(sort_keys, count,sizeof(uchar*), + info->key_cmp,info); while (count--) { if ((*info->key_write)(info, *sort_keys++)) @@ -1044,8 +1044,8 @@ merge_buffers(MARIA_SORT_PARAM *info, ha_keys keys, IO_CACHE *from_file, sort_length=info->key_length; if (init_queue(&queue,(uint) (Tb-Fb)+1,offsetof(BUFFPEK,key),0, - (int (*)(void*, uchar *,uchar*)) info->key_cmp, - (void*) info, 0, 0)) + info->key_cmp, + info, 0, 0)) DBUG_RETURN(1); /* purecov: inspected */ for (buffpek= Fb ; buffpek <= Tb ; buffpek++) diff --git a/storage/maria/ma_write.c b/storage/maria/ma_write.c index 632d38bbc40..53748a41aea 100644 --- a/storage/maria/ma_write.c +++ b/storage/maria/ma_write.c @@ -1687,8 +1687,12 @@ static my_bool _ma_ck_write_tree(register MARIA_HA *info, MARIA_KEY *key) /* typeof(_ma_keys_compare)=qsort_cmp2 */ -static int keys_compare(bulk_insert_param *param, uchar *key1, uchar *key2) +static int keys_compare(void *param_, const void *key1_, + const void *key2_) { + const bulk_insert_param *param= param_; + const uchar *key1= key1_; + const uchar *key2= key2_; uint not_used[2]; return ha_key_cmp(param->info->s->keyinfo[param->keynr].seg, key1, key2, USE_WHOLE_KEY, SEARCH_SAME, @@ -1794,7 +1798,7 @@ int maria_init_bulk_insert(MARIA_HA *info, size_t cache_size, ha_rows rows) init_tree(&info->bulk_insert[i], cache_size * key[i].maxlength, cache_size * key[i].maxlength, 0, - (qsort_cmp2) keys_compare, keys_free, (void *)params++, MYF(0)); + keys_compare, keys_free, params++, MYF(0)); } else info->bulk_insert[i].root=0; diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h index ee0a36c10bf..0d5ad465ef0 100644 --- a/storage/maria/maria_def.h +++ b/storage/maria/maria_def.h @@ -398,7 +398,7 @@ typedef struct st_maria_sort_param my_bool calc_checksum; /* calculate table checksum */ size_t rec_buff_size; - int (*key_cmp)(struct st_maria_sort_param *, const void *, const void *); + int (*key_cmp)(void *, const void *, const void *); int (*key_read)(struct st_maria_sort_param *, uchar *); int (*key_write)(struct st_maria_sort_param *, const uchar *); void (*lock_in_memory)(HA_CHECK *); diff --git a/storage/myisam/ft_boolean_search.c b/storage/myisam/ft_boolean_search.c index 3d95fffacaf..00ed5ce3163 100644 --- a/storage/myisam/ft_boolean_search.c +++ b/storage/myisam/ft_boolean_search.c @@ -144,9 +144,12 @@ typedef struct st_ft_info enum { UNINITIALIZED, READY, INDEX_SEARCH, INDEX_DONE } state; } FTB; -static int FTB_WORD_cmp(my_off_t *v, FTB_WORD *a, FTB_WORD *b) +static int FTB_WORD_cmp(void *v_, const void *a_, const void *b_) { int i; + const my_off_t *v= v_; + const FTB_WORD *a= a_; + const FTB_WORD *b= b_; /* if a==curdoc, take it as a < b */ if (v && a->docid[0] == *v) @@ -159,11 +162,14 @@ static int FTB_WORD_cmp(my_off_t *v, FTB_WORD *a, FTB_WORD *b) return i; } -static int FTB_WORD_cmp_list(CHARSET_INFO *cs, FTB_WORD **a, FTB_WORD **b) +static int FTB_WORD_cmp_list(void *cs_, const void *a_, const void *b_) { + CHARSET_INFO *cs= cs_; + const FTB_WORD *const *a= a_; + const FTB_WORD *const *b= b_; /* ORDER BY word, ndepth */ - int i= ha_compare_word(cs, (uchar*) (*a)->word + 1, (*a)->len - 1, - (uchar*) (*b)->word + 1, (*b)->len - 1); + int i= ha_compare_word(cs, (*a)->word + 1, (*a)->len - 1, (*b)->word + 1, + (*b)->len - 1); if (!i) i= CMP_NUM((*a)->ndepth, (*b)->ndepth); return i; @@ -327,8 +333,8 @@ static int _ftb_parse_query(FTB *ftb, uchar *query, uint len, } -static int _ftb_no_dupes_cmp(void* not_used __attribute__((unused)), - const void *a,const void *b) +static int _ftb_no_dupes_cmp(void *not_used __attribute__((unused)), + const void *a, const void *b) { return CMP_NUM((*((my_off_t*)a)), (*((my_off_t*)b))); } @@ -607,14 +613,14 @@ FT_INFO * ft_init_boolean_search(MI_INFO *info, uint keynr, uchar *query, sizeof(void *)))) goto err; reinit_queue(&ftb->queue, ftb->queue.max_elements, 0, 0, - (int (*)(void*, uchar*, uchar*))FTB_WORD_cmp, 0, 0, 0); + FTB_WORD_cmp, 0, 0, 0); for (ftbw= ftb->last_word; ftbw; ftbw= ftbw->prev) queue_insert(&ftb->queue, (uchar *)ftbw); ftb->list=(FTB_WORD **)alloc_root(&ftb->mem_root, sizeof(FTB_WORD *)*ftb->queue.elements); memcpy(ftb->list, &queue_top(&ftb->queue), sizeof(FTB_WORD *)*ftb->queue.elements); my_qsort2(ftb->list, ftb->queue.elements, sizeof(FTB_WORD *), - (qsort2_cmp)FTB_WORD_cmp_list, (void*)ftb->charset); + FTB_WORD_cmp_list, (void*)ftb->charset); if (ftb->queue.elements<2) ftb->with_scan &= ~FTB_FLAG_TRUNC; ftb->state=READY; return ftb; diff --git a/storage/myisam/ft_nlq_search.c b/storage/myisam/ft_nlq_search.c index 90a509057cf..3bc1340f670 100644 --- a/storage/myisam/ft_nlq_search.c +++ b/storage/myisam/ft_nlq_search.c @@ -51,9 +51,10 @@ typedef struct st_ft_superdoc double tmp_weight; } FT_SUPERDOC; -static int FT_SUPERDOC_cmp(void* cmp_arg __attribute__((unused)), - FT_SUPERDOC *p1, FT_SUPERDOC *p2) +static int FT_SUPERDOC_cmp(void *cmp_arg __attribute__((unused)), + const void *p1_, const void *p2_) { + const FT_SUPERDOC *p1= p1_, *p2= p2_; if (p1->doc.dpos < p2->doc.dpos) return -1; if (p1->doc.dpos == p2->doc.dpos) @@ -206,9 +207,10 @@ static int walk_and_push(FT_SUPERDOC *from, } -static int FT_DOC_cmp(void *unused __attribute__((unused)), - FT_DOC *a, FT_DOC *b) +static int FT_DOC_cmp(void *unused __attribute__((unused)), const void *a_, + const void *b_) { + const FT_DOC *a= a_, *b= b_; return CMP_NUM(b->weight, a->weight); } @@ -242,7 +244,7 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, uchar *query, bzero(&wtree,sizeof(wtree)); - init_tree(&aio.dtree,0,0,sizeof(FT_SUPERDOC),(qsort_cmp2)&FT_SUPERDOC_cmp, + init_tree(&aio.dtree,0,0,sizeof(FT_SUPERDOC),&FT_SUPERDOC_cmp, NULL, NULL, MYF(0)); ft_parse_init(&wtree, aio.charset); @@ -258,8 +260,7 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, uchar *query, if (flags & FT_EXPAND && ft_query_expansion_limit) { QUEUE best; - init_queue(&best,ft_query_expansion_limit,0,0, (queue_compare) &FT_DOC_cmp, - 0, 0, 0); + init_queue(&best, ft_query_expansion_limit, 0, 0, &FT_DOC_cmp, 0, 0, 0); tree_walk(&aio.dtree, (tree_walk_action) &walk_and_push, &best, left_root_right); while (best.elements) @@ -306,7 +307,7 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, uchar *query, &dptr, left_root_right); if (flags & FT_SORTED) - my_qsort2(dlist->doc, dlist->ndocs, sizeof(FT_DOC), (qsort2_cmp)&FT_DOC_cmp, + my_qsort2(dlist->doc, dlist->ndocs, sizeof(FT_DOC), &FT_DOC_cmp, 0); err: diff --git a/storage/myisam/ft_parser.c b/storage/myisam/ft_parser.c index ec392b6ecd8..47ce67ab0db 100644 --- a/storage/myisam/ft_parser.c +++ b/storage/myisam/ft_parser.c @@ -30,10 +30,11 @@ typedef struct st_my_ft_parser_param MEM_ROOT *mem_root; } MY_FT_PARSER_PARAM; -static int FT_WORD_cmp(CHARSET_INFO* cs, FT_WORD *w1, FT_WORD *w2) +static int FT_WORD_cmp(void *cs_, const void *w1_, const void *w2_) { - return ha_compare_word(cs, (uchar*) w1->pos, w1->len, - (uchar*) w2->pos, w2->len); + CHARSET_INFO *cs= cs_; + const FT_WORD *w1= w1_, *w2= w2_; + return ha_compare_word(cs, w1->pos, w1->len, w2->pos, w2->len); } static int walk_and_copy(FT_WORD *word,uint32 count,FT_DOCSTAT *docstat) @@ -257,8 +258,8 @@ void ft_parse_init(TREE *wtree, CHARSET_INFO *cs) { DBUG_ENTER("ft_parse_init"); if (!is_tree_inited(wtree)) - init_tree(wtree, 0, 0, sizeof(FT_WORD), (qsort_cmp2)&FT_WORD_cmp, 0, - (void*)cs, MYF(0)); + init_tree(wtree, 0, 0, sizeof(FT_WORD), &FT_WORD_cmp, 0, (void *) cs, + MYF(0)); DBUG_VOID_RETURN; } diff --git a/storage/myisam/ft_stopwords.c b/storage/myisam/ft_stopwords.c index b666c1f3a79..b6a07f555a7 100644 --- a/storage/myisam/ft_stopwords.c +++ b/storage/myisam/ft_stopwords.c @@ -30,9 +30,10 @@ typedef struct st_ft_stopwords static TREE *stopwords3=NULL; -static int FT_STOPWORD_cmp(void* cmp_arg __attribute__((unused)), - FT_STOPWORD *w1, FT_STOPWORD *w2) +static int FT_STOPWORD_cmp(void *cmp_arg __attribute__((unused)), + const void *w1_, const void *w2_) { + const FT_STOPWORD *w1= w1_, *w2= w2_; return ha_compare_word(ft_stopword_cs, (uchar *) w1->pos, w1->len, (uchar *) w2->pos, w2->len); @@ -62,7 +63,7 @@ int ft_init_stopwords() if (!(stopwords3=(TREE *)my_malloc(mi_key_memory_ft_stopwords, sizeof(TREE), MYF(0)))) DBUG_RETURN(-1); - init_tree(stopwords3,0,0,sizeof(FT_STOPWORD),(qsort_cmp2)&FT_STOPWORD_cmp, + init_tree(stopwords3,0,0,sizeof(FT_STOPWORD),&FT_STOPWORD_cmp, (ft_stopword_file ? (tree_element_free)&FT_STOPWORD_free : 0), NULL, MYF(0)); /* diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index c4389d3cfa8..2bf400d08f3 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -61,7 +61,7 @@ static int sort_one_index(HA_CHECK *, MI_INFO *, MI_KEYDEF *, my_off_t, File); static int sort_key_read(MI_SORT_PARAM *sort_param,void *key); static int sort_ft_key_read(MI_SORT_PARAM *sort_param,void *key); static int sort_get_next_record(MI_SORT_PARAM *sort_param); -static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a,const void *b); +static int sort_key_cmp(void *sort_param, const void *a, const void *b); static int sort_ft_key_write(MI_SORT_PARAM *sort_param, const void *a); static int sort_key_write(MI_SORT_PARAM *sort_param, const void *a); static my_off_t get_record_for_key(MI_INFO *, MI_KEYDEF *, uchar *); @@ -3805,12 +3805,14 @@ int sort_write_record(MI_SORT_PARAM *sort_param) /* Compare two keys from _create_index_by_sort */ -static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a, - const void *b) +static int sort_key_cmp(void *sort_param_, const void *a_, const void *b_) { + const MI_SORT_PARAM *sort_param= sort_param_; uint not_used[2]; - return (ha_key_cmp(sort_param->seg, *((uchar**) a), *((uchar**) b), - USE_WHOLE_KEY, SEARCH_SAME, not_used)); + const void *const *a= a_; + const void *const *b= b_; + return (ha_key_cmp(sort_param->seg, *a, *b, + USE_WHOLE_KEY, SEARCH_SAME, not_used)); } /* sort_key_cmp */ diff --git a/storage/myisam/mi_write.c b/storage/myisam/mi_write.c index e8a985a5fd4..f7e5ee8d345 100644 --- a/storage/myisam/mi_write.c +++ b/storage/myisam/mi_write.c @@ -923,8 +923,11 @@ int _mi_ck_write_tree(register MI_INFO *info, uint keynr, uchar *key, /* typeof(_mi_keys_compare)=qsort_cmp2 */ -static int keys_compare(bulk_insert_param *param, uchar *key1, uchar *key2) +static int keys_compare(void *param_, const void *key1_, const void *key2_) { + const bulk_insert_param *param= param_; + const uchar *key1= key1_; + const uchar *key2= key2_; uint not_used[2]; return ha_key_cmp(param->info->s->keyinfo[param->keynr].seg, key1, key2, USE_WHOLE_KEY, SEARCH_SAME, @@ -1020,7 +1023,7 @@ int mi_init_bulk_insert(MI_INFO *info, size_t cache_size, ha_rows rows) init_tree(&info->bulk_insert[i], cache_size * key[i].maxlength, cache_size * key[i].maxlength, 0, - (qsort_cmp2)keys_compare, keys_free, (void *)params++, MYF(0)); + keys_compare, keys_free, params++, MYF(0)); } else info->bulk_insert[i].root=0; diff --git a/storage/myisam/myisamlog.c b/storage/myisam/myisamlog.c index 40d473dc532..d227c010608 100644 --- a/storage/myisam/myisamlog.c +++ b/storage/myisam/myisamlog.c @@ -57,7 +57,7 @@ extern int main(int argc,char * *argv); static void get_options(int *argc,char ***argv); static int examine_log(char * file_name,char **table_names); static int read_string(IO_CACHE *file,uchar* *to,uint length); -static int file_info_compare(void *cmp_arg, void *a,void *b); +static int file_info_compare(void *cmp_arg, const void *a, const void *b); static int test_if_open(struct file_info *key,element_count count, struct test_if_open_param *param); static void fix_blob_pointers(MI_INFO *isam,uchar *record); @@ -329,7 +329,7 @@ static int examine_log(char * file_name, char **table_names) init_io_cache(&cache,file,0,READ_CACHE,start_offset,0,MYF(0)); bzero((uchar*) com_count,sizeof(com_count)); - init_tree(&tree,0,0,sizeof(file_info),(qsort_cmp2) file_info_compare, + init_tree(&tree,0,0,sizeof(file_info), file_info_compare, file_info_free, NULL, MYF(MY_TREE_WITH_DELETE)); (void) init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE, 0, 0, 0, 0); @@ -696,8 +696,8 @@ static int read_string(IO_CACHE *file, register uchar* *to, register uint length } /* read_string */ -static int file_info_compare(void* cmp_arg __attribute__((unused)), - void *a, void *b) +static int file_info_compare(void *cmp_arg __attribute__((unused)), + const void *a, const void *b) { long lint; diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index d6cd9334a55..c66dc01bcd5 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -131,8 +131,8 @@ static void free_counts_and_tree_and_queue(HUFF_TREE *huff_trees, uint trees, HUFF_COUNTS *huff_counts, uint fields); -static int compare_tree(void* cmp_arg __attribute__((unused)), - const uchar *s,const uchar *t); +static int compare_tree(void *cmp_arg __attribute__((unused)), + const void *s, const void *t); static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts); static void check_counts(HUFF_COUNTS *huff_counts,uint trees, my_off_t records); @@ -142,7 +142,7 @@ static int test_space_compress(HUFF_COUNTS *huff_counts,my_off_t records, enum en_fieldtype field_type); static HUFF_TREE* make_huff_trees(HUFF_COUNTS *huff_counts,uint trees); static int make_huff_tree(HUFF_TREE *tree,HUFF_COUNTS *huff_counts); -static int compare_huff_elements(void *not_used, uchar *a,uchar *b); +static int compare_huff_elements(void *not_used, const void *a, const void *b); static int save_counts_in_queue(uchar *key,element_count count, HUFF_TREE *tree); static my_off_t calc_packed_length(HUFF_COUNTS *huff_counts,uint flag); @@ -176,7 +176,7 @@ static int mrg_rrnd(PACK_MRG_INFO *info,uchar *buf); static void mrg_reset(PACK_MRG_INFO *mrg); #if !defined(DBUG_OFF) static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count); -static int fakecmp(my_off_t **count1, my_off_t **count2); +static int fakecmp(const void *count1, const void *count2); #endif @@ -822,8 +822,8 @@ static HUFF_COUNTS *init_huff_count(MI_INFO *info,my_off_t records) 'tree_pos'. It's keys are implemented by pointers into 'tree_buff'. This is accomplished by '-1' as the element size. */ - init_tree(&count[i].int_tree,0,0,-1,(qsort_cmp2) compare_tree, NULL, - NULL, MYF(0)); + init_tree(&count[i].int_tree, 0, 0, -1, compare_tree, NULL, NULL, + MYF(0)); if (records && type != FIELD_BLOB && type != FIELD_VARCHAR) count[i].tree_pos=count[i].tree_buff = my_malloc(PSI_NOT_INSTRUMENTED, count[i].field_length > 1 ? tree_buff_length : 2, @@ -1182,10 +1182,11 @@ static int get_statistic(PACK_MRG_INFO *mrg,HUFF_COUNTS *huff_counts) } static int compare_huff_elements(void *not_used __attribute__((unused)), - uchar *a, uchar *b) + const void *a_, const void *b_) { - return *((my_off_t*) a) < *((my_off_t*) b) ? -1 : - (*((my_off_t*) a) == *((my_off_t*) b) ? 0 : 1); + const my_off_t *a= a_; + const my_off_t *b= b_; + return *a < *b ? -1 : (*a == *b ? 0 : 1); } /* Check each tree if we should use pre-space-compress, end-space- @@ -1694,9 +1695,11 @@ static int make_huff_tree(HUFF_TREE *huff_tree, HUFF_COUNTS *huff_counts) return 0; } -static int compare_tree(void* cmp_arg __attribute__((unused)), - register const uchar *s, register const uchar *t) +static int compare_tree(void *cmp_arg __attribute__((unused)), const void *s_, + const void *t_) { + const uchar *s= s_; + const uchar *t= t_; uint length; for (length=global_count->field_length; length-- ;) if (*s++ != *t++) @@ -3227,8 +3230,10 @@ static void fakebigcodes(HUFF_COUNTS *huff_counts, HUFF_COUNTS *end_count) -1 count1 > count2 */ -static int fakecmp(my_off_t **count1, my_off_t **count2) +static int fakecmp(const void *count1_, const void *count2_) { + const my_off_t *const *count1= count1_; + const my_off_t *const *count2= count2_; return ((**count1 < **count2) ? 1 : (**count1 > **count2) ? -1 : 0); } diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c index 92b176018f9..a306cba6f6a 100644 --- a/storage/myisam/sort.c +++ b/storage/myisam/sort.c @@ -730,8 +730,8 @@ static int write_keys(MI_SORT_PARAM *info, register uchar **sort_keys, if (!buffpek) DBUG_RETURN(1); /* Out of memory */ - my_qsort2((uchar*) sort_keys,(size_t) count, sizeof(uchar*), - (qsort2_cmp) info->key_cmp, info); + my_qsort2(sort_keys, count, sizeof(uchar *), + info->key_cmp, info); if (!my_b_inited(tempfile) && open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw)) @@ -776,8 +776,8 @@ static int write_keys_varlen(MI_SORT_PARAM *info, if (!buffpek) DBUG_RETURN(1); /* Out of memory */ - my_qsort2((uchar*) sort_keys, (size_t) count, sizeof(uchar*), - (qsort2_cmp) info->key_cmp, info); + my_qsort2(sort_keys, count, sizeof(uchar *), + info->key_cmp, info); if (!my_b_inited(tempfile) && open_cached_file(tempfile, my_tmpdir(info->tmpdir), "ST", DISK_BUFFER_SIZE, info->sort_info->param->myf_rw)) @@ -818,8 +818,8 @@ static int write_index(MI_SORT_PARAM *info, register uchar **sort_keys, { DBUG_ENTER("write_index"); - my_qsort2((uchar*) sort_keys,(size_t) count,sizeof(uchar*), - (qsort2_cmp) info->key_cmp,info); + my_qsort2(sort_keys, count, sizeof(uchar *), + info->key_cmp, info); while (count--) { if ((*info->key_write)(info,*sort_keys++)) @@ -1004,7 +1004,7 @@ merge_buffers(MI_SORT_PARAM *info, ha_keys keys, IO_CACHE *from_file, sort_length=info->key_length; if (init_queue(&queue,(uint) (Tb-Fb)+1,offsetof(BUFFPEK,key),0, - (int (*)(void*, uchar *,uchar*)) info->key_cmp, + info->key_cmp, (void*) info, 0, 0)) DBUG_RETURN(1); /* purecov: inspected */ diff --git a/storage/myisammrg/myrg_queue.c b/storage/myisammrg/myrg_queue.c index 08d02bd5b12..e1cbeaec6f4 100644 --- a/storage/myisammrg/myrg_queue.c +++ b/storage/myisammrg/myrg_queue.c @@ -15,10 +15,10 @@ #include "myrg_def.h" -static int queue_key_cmp(void *keyseg, uchar *a, uchar *b) +static int queue_key_cmp(void *keyseg, const void *a, const void *b) { - MYRG_TABLE *ma= (MYRG_TABLE *)a; - MYRG_TABLE *mb= (MYRG_TABLE *)b; + const MYRG_TABLE *ma= a; + const MYRG_TABLE *mb= b; MI_INFO *aa= ma->table; MI_INFO *bb= mb->table; uint not_used[2]; diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index d1c08bfba85..5f037659473 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -8069,9 +8069,11 @@ bool spider_check_index_merge( } int spider_compare_for_sort( - SPIDER_SORT *a, - SPIDER_SORT *b + const void *a_, + const void *b_ ) { + const SPIDER_SORT *a= static_cast(a_); + const SPIDER_SORT *b= static_cast(b_); DBUG_ENTER("spider_compare_for_sort"); if (a->sort > b->sort) DBUG_RETURN(-1); diff --git a/storage/spider/spd_table.h b/storage/spider/spd_table.h index e6230110dd6..64aa15df852 100644 --- a/storage/spider/spd_table.h +++ b/storage/spider/spd_table.h @@ -451,8 +451,8 @@ bool spider_check_index_merge( ); int spider_compare_for_sort( - SPIDER_SORT *a, - SPIDER_SORT *b + const void *a, + const void *b ); ulong spider_calc_for_sort( diff --git a/unittest/mysys/queues-t.c b/unittest/mysys/queues-t.c index 23cb0da1a32..ec62f58cd45 100644 --- a/unittest/mysys/queues-t.c +++ b/unittest/mysys/queues-t.c @@ -19,8 +19,10 @@ #include #include "tap.h" -int cmp(void *arg __attribute__((unused)), uchar *a, uchar *b) +int cmp(void *arg __attribute__((unused)), const void *a_, const void *b_) { + const uchar *a= a_; + const uchar *b= b_; return *a < *b ? -1 : *a > *b; }