From df4b1349d9aee465edbb2564a180653cb2031b40 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 6 Nov 2024 14:43:18 +1100 Subject: [PATCH 01/55] fixup of MDEV-26345: make initialisation of a local bitmap earlier This avoids freeing the map without initialisation. --- storage/spider/spd_group_by_handler.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/spider/spd_group_by_handler.cc b/storage/spider/spd_group_by_handler.cc index f5889edc59e..e90129e6113 100644 --- a/storage/spider/spd_group_by_handler.cc +++ b/storage/spider/spd_group_by_handler.cc @@ -1448,6 +1448,7 @@ group_by_handler *spider_create_group_by_handler( if (!(table_holder= spider_create_table_holder(table_count))) DBUG_RETURN(NULL); + my_bitmap_init(&skips, NULL, query->select->elements, TRUE); table_idx = 0; from = query->from; #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -1557,7 +1558,6 @@ group_by_handler *spider_create_group_by_handler( fields_arg->set_table_holder(table_holder, table_count); keep_going = TRUE; it.init(*query->select); - my_bitmap_init(&skips, NULL, query->select->elements, TRUE); int i= -1, n_aux= query->n_aux; while ((item = it++)) { From 1802785cc28c3fbed74e3c625a9a5675dcb18965 Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Fri, 30 Aug 2024 21:47:51 +0200 Subject: [PATCH 02/55] MDEV-34847 : Unquoted argument in {{logger}} call leads to invalid argument warnings Added missing logger command argument quoting. And fixed a wsrep_log call typo. --- scripts/wsrep_sst_mariabackup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index 4db299f7670..4f11c776b72 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -848,7 +848,7 @@ recv_joiner() wsrep_log_error "receiving process ended without creating" \ "magic file ($MAGIC_FILE)" wsrep_log_info "Contents of datadir:" - wsrep_log_info $(ls -l "$dir/"*) + wsrep_log_info "$(ls -l "$dir/"*)" exit 32 fi @@ -1365,7 +1365,7 @@ else # joiner # Compact backups are not supported by mariadb-backup if grep -qw -F 'compact = 1' "$DATA/xtrabackup_checkpoints"; then wsrep_log_info "Index compaction detected" - wsrel_log_error "Compact backups are not supported by mariadb-backup" + wsrep_log_error "Compact backups are not supported by mariadb-backup" exit 2 fi From a927e59e6333ca417fb1dcba6d7f0a3a283e0f0d Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Fri, 30 Aug 2024 22:13:38 +0200 Subject: [PATCH 03/55] MDEV-34847 : Unquoted argument in {{logger}} call leads to invalid argument warnings Make sure that even a quoted argument starting with '-' is not interpreted as a command line option by adding '--' marker before message text --- scripts/wsrep_sst_mariabackup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index 4f11c776b72..aead709a098 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -951,17 +951,17 @@ if [ $ssyslog -eq 1 ]; then wsrep_log_error() { - logger -p daemon.err -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" + logger -p daemon.err -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE -- "$@" } wsrep_log_warning() { - logger -p daemon.warning -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" + logger -p daemon.warning -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE -- "$@" } wsrep_log_info() { - logger -p daemon.info -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" + logger -p daemon.info -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE -- "$@" } else wsrep_log_error "logger not in path: $PATH. Ignoring" From 155a82e0b165453e8566429d10a7a4354ed12761 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Fri, 8 Nov 2024 06:39:55 -0700 Subject: [PATCH 04/55] MDEV-35350: Backport search_pattern_in_file.inc SEARCH_WAIT to 10.5 MDEV-35350 consolidated two methods that MTR tests would wait until a file had certain content written to it, which were only available in 10.6+. This patch only backports the functionality to 10.5 in case some test wants to use it (nothing uses it in 10.5 at present). The cleanup bc46f1a7d95c from 10.6 is also backported so SEARCH_TYPE doesn't need to be accounted for in the new search_pattern_in_file.inc logic. --- mysql-test/include/search_pattern_in_file.inc | 109 +++++++++++------- .../include/print_optional_metadata.inc | 3 +- 2 files changed, 67 insertions(+), 45 deletions(-) diff --git a/mysql-test/include/search_pattern_in_file.inc b/mysql-test/include/search_pattern_in_file.inc index e02b7ac8d64..a3ff4849b15 100644 --- a/mysql-test/include/search_pattern_in_file.inc +++ b/mysql-test/include/search_pattern_in_file.inc @@ -9,22 +9,29 @@ # # The environment variables SEARCH_FILE and SEARCH_PATTERN must be set # before sourcing this routine. -# SEARCH_TYPE can also be set to either NULL(default) or _gm_ -# NULL is equivalent of using m/SEARCH_PATTERN/gs -# _gm_ is equivalent of using m/SEARCH_RANGE/gm # # Optionally, SEARCH_RANGE can be set to the max number of bytes of the file # to search. If negative, it will search that many bytes at the end of the # file. By default the search happens from the last CURRENT_TEST: # marker till the end of file (appropriate for searching error logs). # -# Optionally, SEARCH_ABORT can be set to "FOUND" or "NOT FOUND" and this -# will abort if the search result doesn't match the requested one. +# Optionally, SEARCH_ABORT can be specified to abort the search (in error) +# if a specific search result is found. Its value is a regular expression +# (with an implicit start-of-string anchor '^' prepended), and the search +# result that it will match against is either 1) "FOUND ", where is +# the specific number of matches found, or 2) "NOT FOUND". +# +# Optionally, SEARCH_WAIT can be specified to wait for a specific search +# result. Its usage mimics that of SEARCH_ABORT, in that its value is also +# a '^'-prepended regular expression, which will be matched against the same +# search result. The timeout can be set in SEARCH_TIMEOUT, default is 60 +# seconds. # # Optionally, SEARCH_OUTPUT can be set to control the format of output. # Supported formats: # - (default) : "FOUND n /pattern/ in FILE " or "NOT FOUND ..." # - "matches" : Each match is printed, on a separate line +# - "count" : "FOUND n matches in FILE" or "NOT FOUND ..." (omit pattern) # # In case of # - SEARCH_FILE and/or SEARCH_PATTERN is not set @@ -57,48 +64,64 @@ perl; my @search_files= glob($ENV{SEARCH_FILE}); my $search_pattern= $ENV{SEARCH_PATTERN} or die "SEARCH_PATTERN not set"; my $search_range= $ENV{SEARCH_RANGE}; - my $content; - foreach my $search_file (@search_files) { - open(FILE, '<', $search_file) || die("Can't open file $search_file: $!"); - my $file_content; - if ($search_range > 0) { - read(FILE, $file_content, $search_range, 0); - } elsif ($search_range < 0) { - my $size= -s $search_file; - $search_range = -$size if $size > -$search_range; - seek(FILE, $search_range, 2); - read(FILE, $file_content, -$search_range, 0); - } else { - while() { # error log - if (/^CURRENT_TEST:/) { - $content=''; - } else { - $content.=$_; - } - } - } - close(FILE); - $content.= $file_content; - } + my $timeout= $ENV{SEARCH_TIMEOUT} || 60; my @matches; - if (not defined($ENV{SEARCH_TYPE})) - { - @matches=($content =~ /$search_pattern/gs); + my $res; + + my $start_time= time(); + for (;;) { + my $content; + foreach my $search_file (@search_files) { + open(FILE, '<', $search_file) || die("Can't open file $search_file: $!"); + my $file_content; + if ($search_range > 0) { + read(FILE, $file_content, $search_range, 0); + } elsif ($search_range < 0) { + my $size= -s $search_file; + $search_range = -$size if $size > -$search_range; + seek(FILE, $search_range, 2); + read(FILE, $file_content, -$search_range, 0); + } else { + while() { # error log + if (/^CURRENT_TEST:/) { + $content=''; + } else { + $content.=$_; + } + } + } + close(FILE); + $content.= $file_content; + } + @matches= ($content =~ /$search_pattern/gs); + $res=@matches ? "FOUND " . scalar(@matches) : "NOT FOUND"; + + if ($ENV{SEARCH_WAIT} and not $res =~ /^$ENV{SEARCH_WAIT}/) { + if (time() - $start_time < $timeout) { + # Millisceond sleep emulated with select + select(undef, undef, undef, 0.1); + next; + } + die "Timeout waiting for $ENV{SEARCH_WAIT} ". + "for /$search_pattern/ in $ENV{SEARCH_FILE}\n"; + } + last; } - elsif($ENV{SEARCH_TYPE} == "_gm_") - { - @matches=($content =~ /$search_pattern/gm); - } - my $res=@matches ? "FOUND " . scalar(@matches) : "NOT FOUND"; + $ENV{SEARCH_FILE} =~ s{^.*?([^/\\]+)$}{$1}; if ($ENV{SEARCH_OUTPUT} eq "matches") { - foreach (@matches) { - print $_ . "\n"; - } - } else { - print "$res /$search_pattern/ in $ENV{SEARCH_FILE}\n"; + foreach (@matches) { + print $_ . "\n"; + } + } + elsif ($ENV{SEARCH_OUTPUT} eq "count") + { + print "$res matches in $ENV{SEARCH_FILE}\n"; + } + elsif ($ENV{SEARCH_ABORT} and $res =~ /^$ENV{SEARCH_ABORT}/) { + die "$res /$search_pattern/ in $ENV{SEARCH_FILE}\n"; + } else { + print "$res /$search_pattern/ in $ENV{SEARCH_FILE}\n"; } - die "$ENV{SEARCH_ABORT}\n" - if $ENV{SEARCH_ABORT} && $res =~ /^$ENV{SEARCH_ABORT}/; EOF diff --git a/mysql-test/suite/binlog/include/print_optional_metadata.inc b/mysql-test/suite/binlog/include/print_optional_metadata.inc index 739903ab190..47feede80ec 100644 --- a/mysql-test/suite/binlog/include/print_optional_metadata.inc +++ b/mysql-test/suite/binlog/include/print_optional_metadata.inc @@ -16,10 +16,9 @@ if ($stop_position) --exec $MYSQL_BINLOG -F --print-table-metadata $_stop_position_opt $binlog_file > $output_file ---let SEARCH_PATTERN= # (?:Columns\(| {8}).* +--let SEARCH_PATTERN= (?m-s:# (?:Columns\(| {8}).*) --let SEARCH_FILE= $output_file --let SEARCH_OUTPUT=matches ---let SEARCH_TYPE="_gm_" --source include/search_pattern_in_file.inc if ($print_primary_key) From ce3d0cd5b4351fb1913be5fa3c5d22c1dd73d9be Mon Sep 17 00:00:00 2001 From: Yuriy Kohut Date: Fri, 16 Aug 2024 12:16:11 +0300 Subject: [PATCH 05/55] MDEV-35407 Suppress STDERR while determining rpm package vendor ... and version in %prein scriptlet %prein(MariaDB-server-11.4.3-1.el9.x86_64) scriptlet failed, exit status 1 The message is: "The current MariaDB server package is provided by a different vendor (warning: Signature not supported. Hash algorithm SHA1 not available. MariaDB Foundation)". The "warning: Signature not supported. Hash algorithm SHA1 not available." is taken from the STDERR. warning: Signature not supported. Hash algorithm SHA1 not available. gpg-pubkey-73e3b907-6581b071 rpm package vendor and version should be grepped from STDIN only. Reviewer: Daniel Black --- support-files/rpm/server-prein.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/support-files/rpm/server-prein.sh b/support-files/rpm/server-prein.sh index 200d8bf160f..17cce6b5ba8 100644 --- a/support-files/rpm/server-prein.sh +++ b/support-files/rpm/server-prein.sh @@ -4,8 +4,8 @@ installed=`rpm -q --whatprovides mysql-server 2> /dev/null` if [ $? -eq 0 -a -n "$installed" ]; then installed=`echo "$installed"|sed -n 1p` - vendor=`rpm -q --queryformat='%''{VENDOR}' "$installed" 2>&1 | sed 's/Monty Program AB/MariaDB Foundation/'` - version=`rpm -q --queryformat='%''{VERSION}' "$installed" 2>&1` + vendor=`rpm -q --queryformat='%''{VENDOR}' "$installed" 2> /dev/null | sed 's/Monty Program AB/MariaDB Foundation/'` + version=`rpm -q --queryformat='%''{VERSION}' "$installed" 2> /dev/null` myvendor='%{mysql_vendor}' myversion='%{mysqlversion}' From cad881ab104ac54f5e4c4ddffc3470346f98c38f Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 8 Nov 2024 17:11:41 +1100 Subject: [PATCH 06/55] MDEV-35088 main.timezone failing - MEST vs CET time zone difference Reported in Debian bug #1084293, from the tzdata changelog: * Upstream obsoleted the System V names CET, CST6CDT, EET, EST*, HST, MET, MST*, PST8PDT, and WET. They are symlinks now. Move those zones to tzdata-legacy and update /etc/localtime on package update to the new names. Please use Etc/GMT* in case you want to avoid DST changes. As such the timezone output started to output CET (or CEST) as the current timezone. Due to the way the test was written, its only possible to hit this error when running mtr from a package. The internals of MTR fix the timezone so this will never be hit in a build. As such, added Europe/Budapest as the Central Europe Standard Time (per sql/win_tzname_data.h and its derived unicode.org source) as timezone, hard fixed by timezone.opt file so it will always run. The have_cet_timezone is there to check the zonedata is installed (was absent on buildbot Ubuntu 22.04 and Windows). As replace result to the CET output and treat MET/MEST as the same while its on its way out. Thanks Santiago Vila for the bug report and Otto for forwarding it. --- ...{have_met_timezone.require => have_cet_timezone.require} | 0 mysql-test/main/timezone.opt | 1 + mysql-test/main/timezone.result | 2 +- mysql-test/main/timezone.test | 6 +++--- 4 files changed, 5 insertions(+), 4 deletions(-) rename mysql-test/include/{have_met_timezone.require => have_cet_timezone.require} (100%) create mode 100644 mysql-test/main/timezone.opt diff --git a/mysql-test/include/have_met_timezone.require b/mysql-test/include/have_cet_timezone.require similarity index 100% rename from mysql-test/include/have_met_timezone.require rename to mysql-test/include/have_cet_timezone.require diff --git a/mysql-test/main/timezone.opt b/mysql-test/main/timezone.opt new file mode 100644 index 00000000000..7b6415fb2df --- /dev/null +++ b/mysql-test/main/timezone.opt @@ -0,0 +1 @@ +--timezone=Europe/Budapest diff --git a/mysql-test/main/timezone.result b/mysql-test/main/timezone.result index d84fe54ba8c..67252038e72 100644 --- a/mysql-test/main/timezone.result +++ b/mysql-test/main/timezone.result @@ -1,7 +1,7 @@ DROP TABLE IF EXISTS t1; show variables like "system_time_zone"; Variable_name Value -system_time_zone MET +system_time_zone CET select @a:=FROM_UNIXTIME(1); @a:=FROM_UNIXTIME(1) 1970-01-01 01:00:01 diff --git a/mysql-test/main/timezone.test b/mysql-test/main/timezone.test index ec1d50cf0ae..cdc538540ba 100644 --- a/mysql-test/main/timezone.test +++ b/mysql-test/main/timezone.test @@ -1,8 +1,8 @@ # # Test of SYSTEM time zone handling ( for my_system_gmt_sec()). -# This script must be run with TZ=MET +# This script must have zonedata for CET +-- require include/have_cet_timezone.require --- require include/have_met_timezone.require disable_query_log; select FROM_UNIXTIME(24*3600); enable_query_log; @@ -13,7 +13,7 @@ DROP TABLE IF EXISTS t1; --enable_warnings # The following is because of daylight saving time ---replace_result MEST MET +--replace_result MEST CET MET CET show variables like "system_time_zone"; # From 8a3c53f32be6e45eb6c487593b6dce9e1a45dbbc Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 13 Nov 2024 23:07:02 +0100 Subject: [PATCH 07/55] Connect engine - fix compiler error with MSVC 17.12 error C2664: 'bool TestHr(PGLOBAL,HRESULT)': cannot convert argument 2 from 'MSXML2::IXMLDOMNodePtr' to 'HRESULT' Prior to 17.12, there was a code-analysis warning C6216 at the affected places (compiler generated cast between semantically different integral types). --- storage/connect/domdoc.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/storage/connect/domdoc.cpp b/storage/connect/domdoc.cpp index 268ad771ef9..b881a10628e 100644 --- a/storage/connect/domdoc.cpp +++ b/storage/connect/domdoc.cpp @@ -165,7 +165,8 @@ bool DOMDOC::NewDoc(PGLOBAL g, PCSZ ver) sprintf(buf, "version=\"%s\" encoding=\"%s\"", ver, Encoding); pip = Docp->createProcessingInstruction("xml", buf); - return(TestHr(g, Docp->appendChild(pip))); + Docp->appendChild(pip); + return false; } // end of NewDoc /******************************************************************/ @@ -173,7 +174,7 @@ bool DOMDOC::NewDoc(PGLOBAL g, PCSZ ver) /******************************************************************/ void DOMDOC::AddComment(PGLOBAL g, char *com) { - TestHr(g, Docp->appendChild(Docp->createComment(com))); + Docp->appendChild(Docp->createComment(com)); } // end of AddComment /******************************************************************/ @@ -196,9 +197,9 @@ PXNODE DOMDOC::NewRoot(PGLOBAL g, char *name) { MSXML2::IXMLDOMElementPtr ep = Docp->createElement(name); - if (ep == NULL || TestHr(g, Docp->appendChild(ep))) + if (ep == NULL) return NULL; - + Docp->appendChild(ep); return new(g) DOMNODE(this, ep); } // end of NewRoot @@ -552,9 +553,9 @@ PXNODE DOMNODE::AddChildNode(PGLOBAL g, PCSZ name, PXNODE np) _bstr_t pfx = ep->prefix; _bstr_t uri = ep->namespaceURI; - if (ep == NULL || TestHr(g, Nodep->appendChild(ep))) + if (ep == NULL) return NULL; - + Nodep->appendChild(ep); if (np) ((PDOMNODE)np)->Nodep = ep; else @@ -593,7 +594,7 @@ void DOMNODE::AddText(PGLOBAL g, PCSZ txtp) MSXML2::IXMLDOMTextPtr tp= Docp->createTextNode((_bstr_t)txtp); if (tp != NULL) - TestHr(g, Nodep->appendChild(tp)); + Nodep->appendChild(tp); } // end of AddText @@ -602,7 +603,7 @@ void DOMNODE::AddText(PGLOBAL g, PCSZ txtp) /******************************************************************/ void DOMNODE::DeleteChild(PGLOBAL g, PXNODE dnp) { - TestHr(g, Nodep->removeChild(((PDOMNODE)dnp)->Nodep)); + Nodep->removeChild(((PDOMNODE)dnp)->Nodep); // ((PDOMNODE)dnp)->Nodep->Release(); bad idea, causes a crash Delete(dnp); } // end of DeleteChild From 13a14c0d787141a0e1cdccd5b69e834b323ae9cc Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 14 Nov 2024 11:35:36 +0400 Subject: [PATCH 08/55] MDEV-33987 Server crashes at Item_func_as_wkt::val_str_ascii Item_func_boundary::val_str() did not set null_value when it could not construct a geomery object from the input. --- mysql-test/main/gis.result | 6 ++++++ mysql-test/main/gis.test | 8 ++++++++ sql/item_geofunc.cc | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/gis.result b/mysql-test/main/gis.result index 0a8e53f6bab..a39729c26ae 100644 --- a/mysql-test/main/gis.result +++ b/mysql-test/main/gis.result @@ -5453,4 +5453,10 @@ t2 CREATE TABLE `t2` ( `c` polygon DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci drop table t1, t2; +# +# MDEV-33987 Server crashes at Item_func_as_wkt::val_str_ascii +# +SELECT ST_ASTEXT(BOUNDARY(INET6_ATON('255.255.255.255'))) AS c1; +c1 +NULL # End of 10.5 tests diff --git a/mysql-test/main/gis.test b/mysql-test/main/gis.test index 97938d106e1..eebb4620630 100644 --- a/mysql-test/main/gis.test +++ b/mysql-test/main/gis.test @@ -3456,4 +3456,12 @@ create table t2 as select group_concat(c, c order by 1,2), concat(c), c from t1; show create table t2; drop table t1, t2; + +--echo # +--echo # MDEV-33987 Server crashes at Item_func_as_wkt::val_str_ascii +--echo # + +SELECT ST_ASTEXT(BOUNDARY(INET6_ATON('255.255.255.255'))) AS c1; + + --echo # End of 10.5 tests diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index 86965bcfe78..8546456a360 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -452,7 +452,7 @@ String *Item_func_boundary::val_str(String *str_value) Transporter trn(&res_receiver); Geometry *g= Geometry::construct(&buffer, swkb->ptr(), swkb->length()); - if (!g) + if ((null_value= !g)) DBUG_RETURN(0); if (g->store_shapes(&trn)) From 7f55c610608d45a0958f502a8b428c6d37f86692 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 10 Nov 2024 12:34:02 +1100 Subject: [PATCH 09/55] Update Windows TZ data from unicode source (2024b) --- sql/win_tzname_data.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/win_tzname_data.h b/sql/win_tzname_data.h index 8a240118ac3..fc11578b6ad 100644 --- a/sql/win_tzname_data.h +++ b/sql/win_tzname_data.h @@ -10,7 +10,7 @@ {L"UTC-08","Etc/GMT+8"}, {L"Pacific Standard Time","America/Los_Angeles"}, {L"US Mountain Standard Time","America/Phoenix"}, -{L"Mountain Standard Time (Mexico)","America/Chihuahua"}, +{L"Mountain Standard Time (Mexico)","America/Mazatlan"}, {L"Mountain Standard Time","America/Denver"}, {L"Yukon Standard Time","America/Whitehorse"}, {L"Central America Standard Time","America/Guatemala"}, @@ -93,7 +93,7 @@ {L"India Standard Time","Asia/Calcutta"}, {L"Sri Lanka Standard Time","Asia/Colombo"}, {L"Nepal Standard Time","Asia/Katmandu"}, -{L"Central Asia Standard Time","Asia/Almaty"}, +{L"Central Asia Standard Time","Asia/Bishkek"}, {L"Bangladesh Standard Time","Asia/Dhaka"}, {L"Omsk Standard Time","Asia/Omsk"}, {L"Myanmar Standard Time","Asia/Rangoon"}, From ed72eadfb88271f365bb64ac68cb0bc2953634d9 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Fri, 15 Nov 2024 17:35:57 +0400 Subject: [PATCH 10/55] MDEV-35421 - main.mysql_upgrade fails without unix_socket plugin Fixed main.mysql_upgrade to pass when unix_socket plugin is unavailable. Also don't redefine _GNU_SOURCE, which was previously defined by command line/environment. This fixes silent auth_socket build failure with MYSQL_MAINTAINER_MODE=ERR. --- mysql-test/main/mysql_upgrade.result | 2 +- mysql-test/main/mysql_upgrade.test | 2 +- plugin/auth_socket/CMakeLists.txt | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/mysql_upgrade.result b/mysql-test/main/mysql_upgrade.result index a517a7dca29..bc33cc75cfa 100644 --- a/mysql-test/main/mysql_upgrade.result +++ b/mysql-test/main/mysql_upgrade.result @@ -1062,7 +1062,7 @@ set global sql_safe_updates=@orig_sql_safe_updates; # MDEV-32043 Remove plugins previously external that are now built in (unix_socket) # INSERT INTO mysql.plugin SELECT 'unix_socket', 'auth_socket.so' - FROM dual WHERE convert(@@version_compile_os using latin1) not in ('Win32', 'Win64', 'Windows'); + FROM information_schema.plugins WHERE plugin_name='unix_socket' AND plugin_library IS NULL; # mariadb-upgrade --force --silent 2>&1 SELECT * FROM mysql.plugin WHERE name='unix_socket'; name dl diff --git a/mysql-test/main/mysql_upgrade.test b/mysql-test/main/mysql_upgrade.test index 630f9d4574a..647106facf1 100644 --- a/mysql-test/main/mysql_upgrade.test +++ b/mysql-test/main/mysql_upgrade.test @@ -500,7 +500,7 @@ set global sql_safe_updates=@orig_sql_safe_updates; --echo # INSERT INTO mysql.plugin SELECT 'unix_socket', 'auth_socket.so' - FROM dual WHERE convert(@@version_compile_os using latin1) not in ('Win32', 'Win64', 'Windows'); + FROM information_schema.plugins WHERE plugin_name='unix_socket' AND plugin_library IS NULL; --echo # mariadb-upgrade --force --silent 2>&1 --exec $MYSQL_UPGRADE --force --silent 2>&1 SELECT * FROM mysql.plugin WHERE name='unix_socket'; diff --git a/plugin/auth_socket/CMakeLists.txt b/plugin/auth_socket/CMakeLists.txt index a3f42d416a7..57227b3cc52 100644 --- a/plugin/auth_socket/CMakeLists.txt +++ b/plugin/auth_socket/CMakeLists.txt @@ -15,7 +15,9 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA CHECK_CXX_SOURCE_COMPILES( -"#define _GNU_SOURCE +"#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include int main() { struct ucred cred; From b65504b8db0e1e16757b1d1a1b288760f4f7af3d Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 18 Nov 2024 11:34:13 +0400 Subject: [PATCH 11/55] MDEV-23138 Odd behavior of character_set variables set to utf16 (when allowed) Sys_var_typelib did not work when assigned to an expression with character sets with mbminlen>1. Using val_str_ascii() instead of val_str() to fix this. --- mysql-test/main/ctype_utf16.result | 10 ++++++++++ mysql-test/main/ctype_utf16.test | 9 +++++++++ sql/sys_vars.inl | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/ctype_utf16.result b/mysql-test/main/ctype_utf16.result index 71c7ee77a1d..5df3dbea274 100644 --- a/mysql-test/main/ctype_utf16.result +++ b/mysql-test/main/ctype_utf16.result @@ -2910,5 +2910,15 @@ CAST(_utf16 0x0061D83DDE0E0062 AS INT) Warnings: Warning 1292 Truncated incorrect INTEGER value: 'a?b' # +# MDEV-23138 Odd behavior of character_set variables set to utf16 (when allowed) +# +SET character_set_connection=utf16; +SET tx_isolation= 'READ-COMMITTED'; +SELECT @@tx_isolation; +@@tx_isolation +READ-COMMITTED +SET tx_isolation=DEFAULT; +SET NAMES utf8mb3; +# # End of 10.5 tests # diff --git a/mysql-test/main/ctype_utf16.test b/mysql-test/main/ctype_utf16.test index 9f23f02b0fa..560b48e88f8 100644 --- a/mysql-test/main/ctype_utf16.test +++ b/mysql-test/main/ctype_utf16.test @@ -1029,6 +1029,15 @@ SET NAMES utf8; # surrogate pairs is replaced to a single question mark. SELECT CAST(_utf16 0x0061D83DDE0E0062 AS INT); +--echo # +--echo # MDEV-23138 Odd behavior of character_set variables set to utf16 (when allowed) +--echo # + +SET character_set_connection=utf16; +SET tx_isolation= 'READ-COMMITTED'; +SELECT @@tx_isolation; +SET tx_isolation=DEFAULT; +SET NAMES utf8mb3; --echo # --echo # End of 10.5 tests diff --git a/sql/sys_vars.inl b/sql/sys_vars.inl index 0c106777a3e..b678bbbd1cf 100644 --- a/sql/sys_vars.inl +++ b/sql/sys_vars.inl @@ -334,7 +334,11 @@ public: if (var->value->result_type() == STRING_RESULT) { - if (!(res=var->value->val_str(&str))) + /* + Convert from the expression character set to ascii. + This is OK, as typelib values cannot have non-ascii characters. + */ + if (!(res= var->value->val_str_ascii(&str))) return true; else if (!(var->save_result.ulonglong_value= From 1d6502b4f4688a47a31b2833b1d233d2a1e800b4 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Mon, 18 Nov 2024 21:02:19 +1100 Subject: [PATCH 12/55] MDEV-34534 main.plugin_load(daemon_example) - AddressSanitizer: Joining already joined thread, aborting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Joining with a thread that has previously been joined results in undefined behavior. This example plugin performs the same join to the same thread a few lines later. ASAN keeps track of this and fails. Make the behaviour defined by joining only once. Thanks Vladislav Vaintroub for looking up the behaviour. While here; * init/deinit function argument was actually used. * correct code comments * attribute define not needed Thanks Marko Mäkelä for review and suggesting other fixes. --- plugin/daemon_example/daemon_example.cc | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/plugin/daemon_example/daemon_example.cc b/plugin/daemon_example/daemon_example.cc index 50026e92be1..fc6b9f19bb2 100644 --- a/plugin/daemon_example/daemon_example.cc +++ b/plugin/daemon_example/daemon_example.cc @@ -26,14 +26,6 @@ #include "m_string.h" // strlen #include "sql_plugin.h" // st_plugin_int -/* - Disable __attribute__() on non-gcc compilers. -*/ -#if !defined(__attribute__) && !defined(__GNUC__) -#define __attribute__(A) -#endif - - #define HEART_STRING_BUFFER 100 struct mysql_heartbeat_context @@ -77,14 +69,14 @@ pthread_handler_t mysql_heartbeat(void *p) daemon_example_plugin_init() DESCRIPTION - Starts up heartbeatbeat thread + Starts up heartbeat thread (mysql_heartbeat) RETURN VALUE 0 success 1 failure (cannot happen) */ -static int daemon_example_plugin_init(void *p __attribute__ ((unused))) +static int daemon_example_plugin_init(void *p) { DBUG_ENTER("daemon_example_plugin_init"); @@ -150,7 +142,7 @@ static int daemon_example_plugin_init(void *p __attribute__ ((unused))) */ -static int daemon_example_plugin_deinit(void *p __attribute__ ((unused))) +static int daemon_example_plugin_deinit(void *p) { DBUG_ENTER("daemon_example_plugin_deinit"); char buffer[HEART_STRING_BUFFER]; @@ -162,6 +154,10 @@ static int daemon_example_plugin_deinit(void *p __attribute__ ((unused))) pthread_cancel(con->heartbeat_thread); pthread_join(con->heartbeat_thread, NULL); + /* + As thread is joined, we can close the file it writes to and + free the memory it uses. + */ localtime_r(&result, &tm_tmp); my_snprintf(buffer, sizeof(buffer), @@ -174,12 +170,6 @@ static int daemon_example_plugin_deinit(void *p __attribute__ ((unused))) tm_tmp.tm_sec); my_write(con->heartbeat_file, (uchar*) buffer, strlen(buffer), MYF(0)); - /* - Need to wait for the hearbeat thread to terminate before closing - the file it writes to and freeing the memory it uses. - */ - pthread_join(con->heartbeat_thread, NULL); - my_close(con->heartbeat_file, MYF(0)); my_free(con); From 540288ac7cc40ad8ba895a59b24953f0e6c1a07e Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 15 Nov 2024 11:58:04 +1100 Subject: [PATCH 13/55] Fix URL in mariadb-install (no longer on launchpad) Reviewer: Faustin --- scripts/mysql_install_db.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mysql_install_db.sh b/scripts/mysql_install_db.sh index 70ca9b0e0cb..9140a2fcd47 100644 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@ -628,7 +628,7 @@ else echo "--general-log gives you a log in $ldata that may be helpful." link_to_help echo "You can find the latest source at https://downloads.mariadb.org and" - echo "the maria-discuss email list at https://launchpad.net/~maria-discuss" + echo "the MariaDB discuss email list at https://lists.mariadb.org/postorius/lists/discuss.lists.mariadb.org/" echo echo "Please check all of the above before submitting a bug report" echo "at https://mariadb.org/jira" From 76fc26d6323b209cdb18e166c1686b84ae4d9ae8 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Tue, 19 Nov 2024 03:08:20 +0100 Subject: [PATCH 14/55] galera SST scripts: correction of the grep pattern --- scripts/wsrep_sst_mariabackup.sh | 2 +- scripts/wsrep_sst_rsync.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index aead709a098..d32a24da547 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -848,7 +848,7 @@ recv_joiner() wsrep_log_error "receiving process ended without creating" \ "magic file ($MAGIC_FILE)" wsrep_log_info "Contents of datadir:" - wsrep_log_info "$(ls -l "$dir/"*)" + wsrep_log_info "$(ls -l "$dir"/*)" exit 32 fi diff --git a/scripts/wsrep_sst_rsync.sh b/scripts/wsrep_sst_rsync.sh index eb68d134eff..2b90f2047b3 100644 --- a/scripts/wsrep_sst_rsync.sh +++ b/scripts/wsrep_sst_rsync.sh @@ -108,7 +108,7 @@ check_pid_and_port() if [ $ss_available -ne 0 -o $sockstat_available -ne 0 ]; then if [ $ss_available -ne 0 ]; then port_info=$($socket_utility $ss_opts -t "( sport = :$port )" 2>/dev/null | \ - grep -E '[[:space:]]users:[[:space:]]?(' | \ + grep -E '[[:space:]]users:[[:space:]]?\(' | \ grep -o -E "([^[:space:]]+[[:space:]]+){4}[^[:space:]]+" || :) else if [ $sockstat_available -gt 1 ]; then From 70dbd63e029990730befb192e6a9b521eb135cf2 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 18 Nov 2024 12:38:43 +0400 Subject: [PATCH 15/55] MDEV-24337 Server crash in DTCollation::set_repertoire_from_charset The loop in Item_func_in::get_func_mm_tree incorrectly used array->count in the loop. Fixing it to array->used_count. --- mysql-test/main/gis.result | 7 +++++++ mysql-test/main/gis.test | 8 ++++++++ sql/opt_range.cc | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/gis.result b/mysql-test/main/gis.result index a39729c26ae..c4918809e4d 100644 --- a/mysql-test/main/gis.result +++ b/mysql-test/main/gis.result @@ -5459,4 +5459,11 @@ drop table t1, t2; SELECT ST_ASTEXT(BOUNDARY(INET6_ATON('255.255.255.255'))) AS c1; c1 NULL +# +# Server crash in DTCollation::set_repertoire_from_charset +# +CREATE TABLE t (f POINT, KEY(f)); +DELETE FROM t WHERE f NOT IN (NULL,'x'); +ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field +DROP TABLE t; # End of 10.5 tests diff --git a/mysql-test/main/gis.test b/mysql-test/main/gis.test index eebb4620630..8e392e6b2f4 100644 --- a/mysql-test/main/gis.test +++ b/mysql-test/main/gis.test @@ -3463,5 +3463,13 @@ drop table t1, t2; SELECT ST_ASTEXT(BOUNDARY(INET6_ATON('255.255.255.255'))) AS c1; +--echo # +--echo # Server crash in DTCollation::set_repertoire_from_charset +--echo # + +CREATE TABLE t (f POINT, KEY(f)); +--error ER_CANT_CREATE_GEOMETRY_OBJECT +DELETE FROM t WHERE f NOT IN (NULL,'x'); +DROP TABLE t; --echo # End of 10.5 tests diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 8d36fdb4a18..a96014899fd 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -7982,7 +7982,7 @@ SEL_TREE *Item_func_in::get_func_mm_tree(RANGE_OPT_PARAM *param, if (!tree) break; i++; - } while (i < array->count && tree->type == SEL_TREE::IMPOSSIBLE); + } while (i < array->used_count && tree->type == SEL_TREE::IMPOSSIBLE); if (!tree || tree->type == SEL_TREE::IMPOSSIBLE) { From 09fe74c7fd5a092d053c9704b21f9d20b17dd0b0 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 13 Nov 2024 09:40:18 +0400 Subject: [PATCH 16/55] MDEV-25174 DOUBLE columns do not accept large hex hybrids Limit only signed integer fields fields to LONGLONG_MAX. Double and decimal fields do not need this limit, as they can store integers up to ULONGLONG_MAX without problems. --- mysql-test/main/type_float.result | 13 +++++++++++++ mysql-test/main/type_float.test | 11 +++++++++++ mysql-test/main/type_newdecimal.result | 13 +++++++++++++ mysql-test/main/type_newdecimal.test | 11 +++++++++++ sql/field.cc | 3 ++- 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/type_float.result b/mysql-test/main/type_float.result index e944b4bb64f..ad47afeb06d 100644 --- a/mysql-test/main/type_float.result +++ b/mysql-test/main/type_float.result @@ -1283,5 +1283,18 @@ h varchar(16) YES NULL DROP TABLE t1, t2; SET sql_mode=DEFAULT; # +# MDEV-25174 DOUBLE columns do not accept large hex hybrids +# +CREATE TABLE t1 (a DOUBLE); +INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF); +INSERT INTO t1 VALUES (0x8000000000000000); +INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF); +SELECT * FROM t1 ORDER BY a; +a +9.223372036854776e18 +9.223372036854776e18 +1.8446744073709552e19 +DROP TABLE t1; +# # End of 10.5 tests # diff --git a/mysql-test/main/type_float.test b/mysql-test/main/type_float.test index ebf1883d301..837705f870e 100644 --- a/mysql-test/main/type_float.test +++ b/mysql-test/main/type_float.test @@ -798,6 +798,17 @@ DROP TABLE t1, t2; SET sql_mode=DEFAULT; +--echo # +--echo # MDEV-25174 DOUBLE columns do not accept large hex hybrids +--echo # + +CREATE TABLE t1 (a DOUBLE); +INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF); +INSERT INTO t1 VALUES (0x8000000000000000); +INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF); +SELECT * FROM t1 ORDER BY a; +DROP TABLE t1; + --echo # --echo # End of 10.5 tests --echo # diff --git a/mysql-test/main/type_newdecimal.result b/mysql-test/main/type_newdecimal.result index 9bd848ddea9..41760bcc40b 100644 --- a/mysql-test/main/type_newdecimal.result +++ b/mysql-test/main/type_newdecimal.result @@ -2873,5 +2873,18 @@ h varchar(16) YES NULL DROP TABLE t1, t2; SET sql_mode=DEFAULT; # +# MDEV-25174 DOUBLE columns do not accept large hex hybrids +# +CREATE TABLE t1 (a DECIMAL(30,0)); +INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF); +INSERT INTO t1 VALUES (0x8000000000000000); +INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF); +SELECT * FROM t1 ORDER BY a; +a +9223372036854775807 +9223372036854775808 +18446744073709551615 +DROP TABLE t1; +# # End of 10.5 tests # diff --git a/mysql-test/main/type_newdecimal.test b/mysql-test/main/type_newdecimal.test index babfb4e1db8..21e4e8ccd04 100644 --- a/mysql-test/main/type_newdecimal.test +++ b/mysql-test/main/type_newdecimal.test @@ -2050,6 +2050,17 @@ DROP TABLE t1, t2; SET sql_mode=DEFAULT; +--echo # +--echo # MDEV-25174 DOUBLE columns do not accept large hex hybrids +--echo # + +CREATE TABLE t1 (a DECIMAL(30,0)); +INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF); +INSERT INTO t1 VALUES (0x8000000000000000); +INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF); +SELECT * FROM t1 ORDER BY a; +DROP TABLE t1; + --echo # --echo # End of 10.5 tests --echo # diff --git a/sql/field.cc b/sql/field.cc index 3a8dc305db0..8b96c473ab6 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1339,7 +1339,8 @@ int Field::store_hex_hybrid(const char *str, size_t length) goto warn; } nr= (ulonglong) longlong_from_hex_hybrid(str, length); - if ((length == 8) && !(flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX)) + if ((length == 8) && cmp_type()== INT_RESULT && + !(flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX)) { nr= LONGLONG_MAX; goto warn; From 74184074a06f9fd736064f77c1e78c310f9f0cae Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 11 Nov 2024 10:00:26 +0400 Subject: [PATCH 17/55] MDEV-28652 SUBSTRING(str,pos,len) returns incorrect result in view (returns an empty string) Item_func_substr::fix_length_and_dec() incorrecltly calculated its max_length to 0 when a huge number was passed as the third argument: substring('hello', 1, 4294967295) Fixing this. --- mysql-test/main/func_str.result | 8 ++++++++ mysql-test/main/func_str.test | 7 +++++++ sql/item_strfunc.cc | 8 ++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result index 7aa248bffd4..4c1bcf59d0f 100644 --- a/mysql-test/main/func_str.result +++ b/mysql-test/main/func_str.result @@ -5330,5 +5330,13 @@ BIN(c) DROP TABLE t1; DO OCT(-9223372036854775808); # +# MDEV-28652 SUBSTRING(str,pos,len) returns incorrect result in view (returns an empty string) +# +create view v1 as select substring('hello', 1, 4294967295); +select * from v1; +substring('hello', 1, 4294967295) +hello +drop view v1; +# # End of 10.5 tests # diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test index 952d061c30f..2043eaa2b30 100644 --- a/mysql-test/main/func_str.test +++ b/mysql-test/main/func_str.test @@ -2370,6 +2370,13 @@ DROP TABLE t1; DO OCT(-9223372036854775808); +--echo # +--echo # MDEV-28652 SUBSTRING(str,pos,len) returns incorrect result in view (returns an empty string) +--echo # + +create view v1 as select substring('hello', 1, 4294967295); +select * from v1; +drop view v1; --echo # --echo # End of 10.5 tests diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 4a54cf06b92..b53693a48ae 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1773,11 +1773,11 @@ bool Item_func_substr::fix_length_and_dec() } if (arg_count == 3 && args[2]->const_item()) { - int32 length= (int32) args[2]->val_int(); - if (args[2]->null_value || length <= 0) + longlong length= args[2]->val_int(); + if (args[2]->null_value || (length <= 0 && !args[2]->unsigned_flag)) max_length=0; /* purecov: inspected */ - else - set_if_smaller(max_length,(uint) length); + else if (length < UINT32_MAX) + set_if_smaller(max_length, (uint32) length); } max_length*= collation.collation->mbmaxlen; return FALSE; From ae0cbfe934eacb6744b28fbf9997002ed82c0c49 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 11 Nov 2024 12:50:56 +0400 Subject: [PATCH 18/55] MDEV-28001 greatest/least with bigint unsigned maxium has unexpected results compared to 0 LEAST() and GREATEST() erroneously calcucalted the result as signed for BIGINT UNSIGNED arguments. Adding a new method for unsigned arguments: Item_func_min_max::val_uint_native() --- mysql-test/main/func_hybrid_type.result | 9 +++++++++ mysql-test/main/func_hybrid_type.test | 8 ++++++++ sql/item_func.cc | 21 +++++++++++++++++++++ sql/item_func.h | 1 + sql/sql_type.cc | 2 +- 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/func_hybrid_type.result b/mysql-test/main/func_hybrid_type.result index f20aad9d726..011f97c80f8 100644 --- a/mysql-test/main/func_hybrid_type.result +++ b/mysql-test/main/func_hybrid_type.result @@ -4338,5 +4338,14 @@ SELECT * FROM t0 WHERE LEAST(c0, NULL); c0 DROP TABLE t0; # +# MDEV-28001 greatest/least with bigint unsigned maxium has unexpected results compared to 0 +# +CREATE TABLE t1 (a BIGINT UNSIGNED, b BIGINT UNSIGNED); +INSERT INTO t1 VALUES (18446744073709551615,0); +SELECT a,b, LEAST(a,b), GREATEST(a,b) FROM t1; +a b LEAST(a,b) GREATEST(a,b) +18446744073709551615 0 0 18446744073709551615 +DROP TABLE t1; +# # End of 10.5 tests # diff --git a/mysql-test/main/func_hybrid_type.test b/mysql-test/main/func_hybrid_type.test index 2ebfb3cfdf1..a5ed5d9d604 100644 --- a/mysql-test/main/func_hybrid_type.test +++ b/mysql-test/main/func_hybrid_type.test @@ -1137,6 +1137,14 @@ SELECT * FROM t0 WHERE GREATEST(c0, NULL); SELECT * FROM t0 WHERE LEAST(c0, NULL); DROP TABLE t0; +--echo # +--echo # MDEV-28001 greatest/least with bigint unsigned maxium has unexpected results compared to 0 +--echo # + +CREATE TABLE t1 (a BIGINT UNSIGNED, b BIGINT UNSIGNED); +INSERT INTO t1 VALUES (18446744073709551615,0); +SELECT a,b, LEAST(a,b), GREATEST(a,b) FROM t1; +DROP TABLE t1; --echo # --echo # End of 10.5 tests diff --git a/sql/item_func.cc b/sql/item_func.cc index 553a044eb83..f25ca5ed408 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3051,6 +3051,27 @@ longlong Item_func_min_max::val_int_native() } +longlong Item_func_min_max::val_uint_native() +{ + DBUG_ASSERT(fixed); + ulonglong value= 0; + for (uint i=0; i < arg_count ; i++) + { + if (i == 0) + value= (ulonglong) args[i]->val_int(); + else + { + ulonglong tmp= (ulonglong) args[i]->val_int(); + if (!args[i]->null_value && (tmp < value ? cmp_sign : -cmp_sign) > 0) + value= tmp; + } + if ((null_value= args[i]->null_value)) + return 0; + } + return (longlong) value; +} + + my_decimal *Item_func_min_max::val_decimal_native(my_decimal *dec) { DBUG_ASSERT(fixed == 1); diff --git a/sql/item_func.h b/sql/item_func.h index 1ac6045ee61..f4f0558a77b 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -2118,6 +2118,7 @@ public: String *val_str_native(String *str); double val_real_native(); longlong val_int_native(); + longlong val_uint_native(); my_decimal *val_decimal_native(my_decimal *); bool get_date_native(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); bool get_time_native(THD *thd, MYSQL_TIME *res); diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 98abf154db4..7727610088e 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -6152,7 +6152,7 @@ longlong Type_handler_timestamp_common:: longlong Type_handler_numeric:: Item_func_min_max_val_int(Item_func_min_max *func) const { - return func->val_int_native(); + return is_unsigned() ? func->val_uint_native() : func->val_int_native(); } From 0de9e40f4b167dfb1d600b362f8cf469e992cec7 Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 21 Oct 2024 15:05:14 +0300 Subject: [PATCH 19/55] Added status variable "stack_usable" to be able to check stack usage --- mysql-test/main/stack.result | 46 +++++++++++++++++++++++++++ mysql-test/main/stack.test | 60 ++++++++++++++++++++++++++++++++++++ sql/mysqld.cc | 16 ++++++++++ 3 files changed, 122 insertions(+) create mode 100644 mysql-test/main/stack.result create mode 100644 mysql-test/main/stack.test diff --git a/mysql-test/main/stack.result b/mysql-test/main/stack.result new file mode 100644 index 00000000000..a1f82a66104 --- /dev/null +++ b/mysql-test/main/stack.result @@ -0,0 +1,46 @@ +# Checking stack usage +# +# basic tests +# +select variable_value > 0 from information_schema.session_status where variable_name="stack_usage"; +variable_value > 0 +1 +# +# Ensure stack usage is same for each iteration when using WITH recursive +# +create table t1 +WITH recursive Fibonacci(PrevN, N, Stack) AS +( +SELECT 0, 1, 0 +UNION ALL +SELECT N, PrevN + N, (select variable_value from information_schema.session_status where variable_name="stack_usage") +FROM Fibonacci +WHERE N < 100000 +) +SELECT PrevN as N, Stack FROM Fibonacci; +select (select stack from t1 where n=2) = (select stack from t1 where N=75025); +(select stack from t1 where n=2) = (select stack from t1 where N=75025) +1 +DROP table t1; +# +# Check stack with recursion +# +set @@max_sp_recursion_depth=20; +create or replace procedure recursion(x int, max int, OUT res int) +begin +select variable_value into res from information_schema.session_status where variable_name="stack_usage"; +if (x < max) then +call recursion(x+1, max, res); +end if; +end; +$$ +call recursion(0,2,@s1); +call recursion(0,3,@s2); +call recursion(0,4,@s3); +select @s1 > 0 && @s2 > 0 && @s3 > 0; +@s1 > 0 && @s2 > 0 && @s3 > 0 +1 +drop procedure recursion; +# +# End of 10.5 tests +# diff --git a/mysql-test/main/stack.test b/mysql-test/main/stack.test new file mode 100644 index 00000000000..d25d4620dec --- /dev/null +++ b/mysql-test/main/stack.test @@ -0,0 +1,60 @@ +--echo # Checking stack usage + +--echo # +--echo # basic tests +--echo # + +select variable_value > 0 from information_schema.session_status where variable_name="stack_usage"; + + +--echo # +--echo # Ensure stack usage is same for each iteration when using WITH recursive +--echo # + +create table t1 +WITH recursive Fibonacci(PrevN, N, Stack) AS +( + SELECT 0, 1, 0 + UNION ALL + SELECT N, PrevN + N, (select variable_value from information_schema.session_status where variable_name="stack_usage") + FROM Fibonacci + WHERE N < 100000 +) +SELECT PrevN as N, Stack FROM Fibonacci; + +select (select stack from t1 where n=2) = (select stack from t1 where N=75025); +DROP table t1; + +--echo # +--echo # Check stack with recursion +--echo # + +set @@max_sp_recursion_depth=20; +delimiter $$; +create or replace procedure recursion(x int, max int, OUT res int) +begin + select variable_value into res from information_schema.session_status where variable_name="stack_usage"; + if (x < max) then + call recursion(x+1, max, res); + end if; +end; +$$ + +delimiter ;$$ + +call recursion(0,2,@s1); +call recursion(0,3,@s2); +call recursion(0,4,@s3); + +select @s1 > 0 && @s2 > 0 && @s3 > 0; +if (`select @s2-@s1 <> @s3 - @s2`) +{ + echo "Wrong result"; + select @s1 ,@s2, @s3, @s2-@s1, @s3-@s2; +} + +drop procedure recursion; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f82e8e111c2..7663069e034 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7315,6 +7315,21 @@ static int show_memory_used(THD *thd, SHOW_VAR *var, void *buff, } +static int show_stack_usage(THD *thd, SHOW_VAR *var, void *buff, + system_status_var *, enum_var_type scope) +{ + var->type= SHOW_ULONGLONG; + var->value= buff; + // We cannot get stack usage for 'global' or for another thread + if (scope == OPT_GLOBAL || thd != current_thd) + *(ulonglong*) buff= 0; + else + *(ulonglong*) buff= (ulonglong) (available_stack_size((char*) thd->thread_stack, + my_get_stack_pointer(0))); + return 0; +} + + #ifndef DBUG_OFF static int debug_status_func(THD *thd, SHOW_VAR *var, void *buff, system_status_var *, enum_var_type) @@ -7581,6 +7596,7 @@ SHOW_VAR status_vars[]= { {"Ssl_version", (char*) &show_ssl_get_version, SHOW_SIMPLE_FUNC}, #endif #endif /* HAVE_OPENSSL */ + SHOW_FUNC_ENTRY("stack_usage", &show_stack_usage), {"Syncs", (char*) &my_sync_count, SHOW_LONG_NOFLUSH}, /* Expression cache used only for caching subqueries now, so its statistic From 69be363daa8777071fa6a360af517ee8f2a7d26d Mon Sep 17 00:00:00 2001 From: Monty Date: Tue, 19 Nov 2024 19:05:52 +0200 Subject: [PATCH 20/55] Fixed that internal temporary Aria tables are not flushed to disk This bug was caused by MDEV-17070 Table corruption or Assertion `table->file->stats.records > 0 --- storage/maria/ha_maria.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index c583ef496f0..8656e59bd2a 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -2789,6 +2789,7 @@ int ha_maria::delete_table(const char *name) void ha_maria::drop_table(const char *name) { DBUG_ASSERT(!file || file->s->temporary); + file->s->deleting= 1; // Do not flush data (void) ha_close(); (void) maria_delete_table_files(name, 1, MY_WME); } From 93fb364cd92679e5e7016e642e1afefbf3038d1b Mon Sep 17 00:00:00 2001 From: Monty Date: Tue, 19 Nov 2024 20:15:45 +0200 Subject: [PATCH 21/55] Removed not used ha_drop_table() This was done after changing call in sql_select.cc from ha_drop_table() to drop_table(), like in 11.5 --- sql/handler.cc | 28 ---------------------------- sql/handler.h | 1 - sql/sql_select.cc | 2 +- 3 files changed, 1 insertion(+), 30 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 074bc02efd2..af282829c3c 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -553,13 +553,6 @@ static void update_discovery_counters(handlerton *hton, int val) engines_with_discover+= val; } -int ha_drop_table(THD *thd, handlerton *hton, const char *path) -{ - if (ha_check_if_updates_are_ignored(thd, hton, "DROP")) - return 0; // Simulate dropped - return hton->drop_table(hton, path); -} - static int hton_drop_table(handlerton *hton, const char *path) { char tmp_path[FN_REFLEN]; @@ -5142,27 +5135,6 @@ handler::ha_rename_table(const char *from, const char *to) } -/** - Drop table in the engine: public interface. - - @sa handler::drop_table() - - The difference between this and delete_table() is that the table is open in - drop_table(). -*/ - -void -handler::ha_drop_table(const char *name) -{ - DBUG_ASSERT(m_lock_type == F_UNLCK); - if (check_if_updates_are_ignored("DROP")) - return; - - mark_trx_read_write(); - drop_table(name); -} - - /** Structure used during force drop table. */ diff --git a/sql/handler.h b/sql/handler.h index 3d9db017a5b..ac97a41a4f1 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -3437,7 +3437,6 @@ public: int ha_enable_indexes(key_map map, bool persist); int ha_discard_or_import_tablespace(my_bool discard); int ha_rename_table(const char *from, const char *to); - void ha_drop_table(const char *name); int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a9852b81063..c0598bde789 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -20564,7 +20564,7 @@ free_tmp_table(THD *thd, TABLE *entry) thd->tmp_tables_size+= (entry->file->stats.data_file_length + entry->file->stats.index_file_length); } - entry->file->ha_drop_table(entry->s->path.str); + entry->file->drop_table(entry->s->path.str); delete entry->file; entry->file= NULL; entry->reset_created(); From 32962ea2532ee78bc99d8da950348ba01d38a23b Mon Sep 17 00:00:00 2001 From: Monty Date: Tue, 19 Nov 2024 21:41:06 +0200 Subject: [PATCH 22/55] Do not read aria bitmap page for internal temporary tables Instead create the bitmap page from scratch --- storage/maria/ma_bitmap.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/storage/maria/ma_bitmap.c b/storage/maria/ma_bitmap.c index 613dcd18e02..f7245708546 100644 --- a/storage/maria/ma_bitmap.c +++ b/storage/maria/ma_bitmap.c @@ -1068,19 +1068,30 @@ static my_bool _ma_read_bitmap_page(MARIA_HA *info, adjust_total_size(info, page); bitmap->full_head_size= bitmap->full_tail_size= 0; DBUG_ASSERT(share->pagecache->block_size == bitmap->block_size); - res= pagecache_read(share->pagecache, - &bitmap->file, page, 0, - bitmap->map, PAGECACHE_PLAIN_PAGE, - PAGECACHE_LOCK_LEFT_UNLOCKED, 0) == NULL; - if (!res) + if (share->internal_table && + page == 0 && share->state.state.data_file_length == bitmap->block_size) { - /* Calculate used_size */ - const uchar *data, *end= bitmap->map; - for (data= bitmap->map + bitmap->total_size; --data >= end && *data == 0; ) - {} - bitmap->used_size= (uint) ((data + 1) - end); - DBUG_ASSERT(bitmap->used_size <= bitmap->total_size); + /* Avoid read of bitmap for internal temporary tables */ + bzero(bitmap->map, bitmap->block_size); + bitmap->used_size= 0; + res= 0; + } + else + { + res= pagecache_read(share->pagecache, + &bitmap->file, page, 0, + bitmap->map, PAGECACHE_PLAIN_PAGE, + PAGECACHE_LOCK_LEFT_UNLOCKED, 0) == NULL; + if (!res) + { + /* Calculate used_size */ + const uchar *data, *end= bitmap->map; + for (data= bitmap->map + bitmap->total_size; --data >= end && *data == 0; ) + {} + bitmap->used_size= (uint) ((data + 1) - end); + DBUG_ASSERT(bitmap->used_size <= bitmap->total_size); + } } /* We can't check maria_bitmap_marker here as if the bitmap page From 2c89fe7ea63928d75c46f6cfe3866b36eeb08e7d Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 21 Nov 2024 17:30:13 +1100 Subject: [PATCH 23/55] main.stack view protocol - correct test result View protocol requires expressions include a simple alias. --- mysql-test/main/stack.result | 4 ++-- mysql-test/main/stack.test | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/stack.result b/mysql-test/main/stack.result index a1f82a66104..5444381327d 100644 --- a/mysql-test/main/stack.result +++ b/mysql-test/main/stack.result @@ -18,8 +18,8 @@ FROM Fibonacci WHERE N < 100000 ) SELECT PrevN as N, Stack FROM Fibonacci; -select (select stack from t1 where n=2) = (select stack from t1 where N=75025); -(select stack from t1 where n=2) = (select stack from t1 where N=75025) +select (select stack from t1 where n=2) = (select stack from t1 where N=75025) as c; +c 1 DROP table t1; # diff --git a/mysql-test/main/stack.test b/mysql-test/main/stack.test index d25d4620dec..2277b0f48ff 100644 --- a/mysql-test/main/stack.test +++ b/mysql-test/main/stack.test @@ -22,7 +22,7 @@ WITH recursive Fibonacci(PrevN, N, Stack) AS ) SELECT PrevN as N, Stack FROM Fibonacci; -select (select stack from t1 where n=2) = (select stack from t1 where N=75025); +select (select stack from t1 where n=2) = (select stack from t1 where N=75025) as c; DROP table t1; --echo # From b414eca98df5e8b745c3d8f109830be1dc396cd7 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 21 Nov 2024 16:51:41 +1100 Subject: [PATCH 24/55] Correct cursor protocol tests main.{loaddata,grant_plugin} & innodb_fts.fulltext Cursor protocol cannot handle select... into. Disable this on loaddata. For the grant_plugin/innodb_fts.fulltext changed the tests to use a temporary table rather than a user variable. --- mysql-test/main/grant_plugin.result | 8 +++----- mysql-test/main/grant_plugin.test | 7 ++++--- mysql-test/main/loaddata.test | 4 ++++ mysql-test/suite/innodb_fts/r/fulltext.result | 9 +++++---- mysql-test/suite/innodb_fts/t/fulltext.test | 8 +++++--- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/mysql-test/main/grant_plugin.result b/mysql-test/main/grant_plugin.result index bf5b42b28b6..63bdd42853e 100644 --- a/mysql-test/main/grant_plugin.result +++ b/mysql-test/main/grant_plugin.result @@ -4,14 +4,12 @@ install soname 'auth_0x0100'; CREATE USER foo@localhost IDENTIFIED VIA auth_0x0100; uninstall plugin auth_0x0100; -select Priv from mysql.global_priv where User = "foo" and host="localhost" -into @priv; -Warnings: -Warning 1287 ' INTO FROM...' instead +create table t as select Priv from mysql.global_priv where User = "foo" and host="localhost"; SET PASSWORD FOR foo@localhost = "1111"; ERROR HY000: Plugin 'auth_0x0100' is not loaded -select Priv = @priv as "Nothing changed" from mysql.global_priv where User = "foo" and host="localhost"; +select global_priv.Priv = t.Priv as "Nothing changed" from mysql.global_priv join t where User = "foo" and host="localhost"; Nothing changed 1 +drop table t; DROP USER foo@localhost; # End of 10.5 tests diff --git a/mysql-test/main/grant_plugin.test b/mysql-test/main/grant_plugin.test index 610176b0ce7..7043e159e37 100644 --- a/mysql-test/main/grant_plugin.test +++ b/mysql-test/main/grant_plugin.test @@ -13,11 +13,12 @@ install soname 'auth_0x0100'; CREATE USER foo@localhost IDENTIFIED VIA auth_0x0100; uninstall plugin auth_0x0100; -select Priv from mysql.global_priv where User = "foo" and host="localhost" -into @priv; +create table t as select Priv from mysql.global_priv where User = "foo" and host="localhost"; --error ER_PLUGIN_IS_NOT_LOADED SET PASSWORD FOR foo@localhost = "1111"; -select Priv = @priv as "Nothing changed" from mysql.global_priv where User = "foo" and host="localhost"; +select global_priv.Priv = t.Priv as "Nothing changed" from mysql.global_priv join t where User = "foo" and host="localhost"; + +drop table t; DROP USER foo@localhost; diff --git a/mysql-test/main/loaddata.test b/mysql-test/main/loaddata.test index a625415ad8e..a7a6e2bcfcb 100644 --- a/mysql-test/main/loaddata.test +++ b/mysql-test/main/loaddata.test @@ -843,10 +843,12 @@ CREATE OR REPLACE TABLE t1 ( ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO t1 VALUES (GeomFromText('POINT(37.646944 -75.761111)')); +--disable_cursor_protocol --disable_ps2_protocol --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1.tsv' FROM t1; --enable_ps2_protocol +--enable_cursor_protocol CREATE OR REPLACE TABLE t2 LIKE t1; @@ -863,10 +865,12 @@ CREATE OR REPLACE TABLE t1 ( ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO t1 VALUES (GeomFromText('POINT(37.646944 -75.761111)'),"їєі"); +--disable_cursor_protocol --disable_ps2_protocol --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR eval SELECT * INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/t1.tsv' FROM t1; --enable_ps2_protocol +--enable_cursor_protocol CREATE OR REPLACE TABLE t2 LIKE t1; diff --git a/mysql-test/suite/innodb_fts/r/fulltext.result b/mysql-test/suite/innodb_fts/r/fulltext.result index 54725f489fa..1605a591582 100644 --- a/mysql-test/suite/innodb_fts/r/fulltext.result +++ b/mysql-test/suite/innodb_fts/r/fulltext.result @@ -794,10 +794,10 @@ title VARCHAR(200), book VARCHAR(200), FULLTEXT fidx(title)) ENGINE = InnoDB; INSERT INTO t1(title) VALUES('database'); ALTER TABLE t1 DROP INDEX fidx; -select space into @common_space from information_schema.innodb_sys_tables where name like "test/FTS_%_CONFIG"; +create table t2 as select space from information_schema.innodb_sys_tables where name like "test/FTS_%_CONFIG"; ALTER TABLE t1 ADD FULLTEXT fidx_1(book); -select space=@common_space from information_schema.innodb_sys_tables where name like "test/FTS_%_CONFIG"; -space=@common_space +select i_s.space=t2.space from information_schema.innodb_sys_tables i_s join t2 where name like "test/FTS_%_CONFIG"; +i_s.space=t2.space 1 SHOW CREATE TABLE t1; Table Create Table @@ -808,4 +808,5 @@ t1 CREATE TABLE `t1` ( PRIMARY KEY (`ID`), FULLTEXT KEY `fidx_1` (`book`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci -DROP TABLE t1; +DROP TABLE t1, t2; +# End of 10.5 tests diff --git a/mysql-test/suite/innodb_fts/t/fulltext.test b/mysql-test/suite/innodb_fts/t/fulltext.test index 02a9f32dbed..4c7b69d8ee3 100644 --- a/mysql-test/suite/innodb_fts/t/fulltext.test +++ b/mysql-test/suite/innodb_fts/t/fulltext.test @@ -814,8 +814,10 @@ CREATE TABLE t1 ( FULLTEXT fidx(title)) ENGINE = InnoDB; INSERT INTO t1(title) VALUES('database'); ALTER TABLE t1 DROP INDEX fidx; -select space into @common_space from information_schema.innodb_sys_tables where name like "test/FTS_%_CONFIG"; +create table t2 as select space from information_schema.innodb_sys_tables where name like "test/FTS_%_CONFIG"; ALTER TABLE t1 ADD FULLTEXT fidx_1(book); -select space=@common_space from information_schema.innodb_sys_tables where name like "test/FTS_%_CONFIG"; +select i_s.space=t2.space from information_schema.innodb_sys_tables i_s join t2 where name like "test/FTS_%_CONFIG"; SHOW CREATE TABLE t1; -DROP TABLE t1; +DROP TABLE t1, t2; + +--echo # End of 10.5 tests From cf2d49ddcfdb158e46dcd9cc575c54205b5eef50 Mon Sep 17 00:00:00 2001 From: ParadoxV5 Date: Thu, 14 Nov 2024 17:42:43 -0700 Subject: [PATCH 25/55] Extract some of #3360 fixes to 10.5.x That PR uncovered countless issues on `my_snprintf` uses. This commit backports a squashed subset of their fixes. --- client/mysqldump.c | 2 +- plugin/server_audit/server_audit.c | 22 ++--- sql/item_cmpfunc.cc | 2 +- sql/item_geofunc.cc | 4 +- sql/item_strfunc.cc | 8 +- sql/log_event_server.cc | 4 +- sql/my_decimal.cc | 2 +- sql/slave.cc | 2 +- sql/sql_acl.cc | 16 ++-- sql/sql_class.h | 2 +- sql/sql_trigger.cc | 6 +- sql/sql_type.h | 2 +- sql/sql_yacc.yy | 12 +-- sql/table.cc | 85 ++++++++++--------- sql/wsrep_var.cc | 2 +- storage/innobase/handler/ha_innodb.cc | 4 +- storage/innobase/trx/trx0undo.cc | 4 +- storage/maria/s3_func.c | 2 +- .../lib/mrn_multiple_column_key_codec.cpp | 2 +- storage/myisam/ha_myisam.cc | 4 +- storage/myisam/mi_check.c | 10 +-- storage/myisam/myisamchk.c | 2 +- storage/oqgraph/ha_oqgraph.cc | 2 +- storage/spider/spd_db_mysql.cc | 2 +- 24 files changed, 102 insertions(+), 101 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 7ebf0728900..fbe5ac68765 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1739,7 +1739,7 @@ static int switch_character_set_results(MYSQL *mysql, const char *cs_name) query_length= my_snprintf(query_buffer, sizeof (query_buffer), "SET SESSION character_set_results = '%s'", - (const char *) cs_name); + cs_name); return mysql_real_query(mysql, query_buffer, (ulong)query_length); } diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index 1fc9679e57e..e45282c6e20 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -1398,7 +1398,7 @@ static size_t log_header(char *message, size_t message_len, if (output_type == OUTPUT_SYSLOG) return my_snprintf(message, message_len, "%.*s,%.*s,%.*s,%d,%lld,%s", - (unsigned int) serverhost_len, serverhost, + (int) serverhost_len, serverhost, username_len, username, host_len, host, connection_id, query_id, operation); @@ -1408,7 +1408,7 @@ static size_t log_header(char *message, size_t message_len, "%04d%02d%02d %02d:%02d:%02d,%.*s,%.*s,%.*s,%d,%lld,%s", tm_time.tm_year+1900, tm_time.tm_mon+1, tm_time.tm_mday, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec, - serverhost_len, serverhost, + (int) serverhost_len, serverhost, username_len, username, host_len, host, connection_id, query_id, operation); @@ -1477,7 +1477,7 @@ static int log_connection_event(const struct mysql_event_connection *event, event->ip, event->ip_length, event->thread_id, 0, type); csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, - ",%.*s,,%d", event->database.length, event->database.str, event->status); + ",%.*s,,%d", (int) event->database.length, event->database.str, event->status); message[csize]= '\n'; return write_log(message, csize + 1, 1); } @@ -1909,9 +1909,9 @@ static int log_table(const struct connection_info *cn, event->host, SAFE_STRLEN_UI(event->host), event->ip, SAFE_STRLEN_UI(event->ip), event->thread_id, cn->query_id, type); - csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, - ",%.*s,%.*s,",event->database.length, event->database.str, - event->table.length, event->table.str); + csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, ",%.*s,%.*s,", + (int) event->database.length, event->database.str, + (int) event->table.length, event->table.str); message[csize]= '\n'; return write_log(message, csize + 1, 1); } @@ -1932,10 +1932,11 @@ static int log_rename(const struct connection_info *cn, event->ip, SAFE_STRLEN_UI(event->ip), event->thread_id, cn->query_id, "RENAME"); csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize, - ",%.*s,%.*s|%.*s.%.*s,",event->database.length, event->database.str, - event->table.length, event->table.str, - event->new_database.length, event->new_database.str, - event->new_table.length, event->new_table.str); + ",%.*s,%.*s|%.*s.%.*s,", + (int) event->database.length, event->database.str, + (int) event->table.length, event->table.str, + (int) event->new_database.length, event->new_database.str, + (int) event->new_table.length, event->new_table.str); message[csize]= '\n'; return write_log(message, csize + 1, 1); } @@ -3108,4 +3109,3 @@ exit: return; #endif } - diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index c4c96f6f7ae..7a528fa06d0 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -6105,7 +6105,7 @@ bool Regexp_processor_pcre::compile(String *pattern, bool send_error) (PCRE2_UCHAR8 *)buff, sizeof(buff)); if (lmsg >= 0) my_snprintf(buff+lmsg, sizeof(buff)-lmsg, - " at offset %d", pcreErrorOffset); + " at offset %zu", pcreErrorOffset); my_error(ER_REGEXP_ERROR, MYF(0), buff); } return true; diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index 8546456a360..1c364f7b31d 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -185,8 +185,8 @@ String *Item_func_geometry_from_json::val_str(String *str) if (code) { THD *thd= current_thd; - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, code, - ER_THD(thd, code)); + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, code, + ER_THD(thd, code)); } return 0; } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index b53693a48ae..7e4ba259261 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -4231,9 +4231,9 @@ longlong Item_func_uncompressed_length::val_int() if (res->length() <= 4) { THD *thd= current_thd; - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_ZLIB_Z_DATA_ERROR, - ER_THD(thd, ER_ZLIB_Z_DATA_ERROR)); + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, + ER_ZLIB_Z_DATA_ERROR, + ER_THD(thd, ER_ZLIB_Z_DATA_ERROR)); null_value= 1; return 0; } @@ -4350,7 +4350,7 @@ String *Item_func_uncompress::val_str(String *str) if (res->length() <= 4) { THD *thd= current_thd; - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_ZLIB_Z_DATA_ERROR, ER_THD(thd, ER_ZLIB_Z_DATA_ERROR)); goto err; diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 2a5019281ef..90d4c9c2406 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -4036,7 +4036,7 @@ int Xid_apply_log_event::do_apply_event(rpl_group_info *rgi) } } - general_log_print(thd, COM_QUERY, get_query()); + general_log_print(thd, COM_QUERY, "%s", get_query()); thd->variables.option_bits&= ~OPTION_GTID_BEGIN; res= do_commit(); if (!res && rgi->gtid_pending) @@ -7845,7 +7845,7 @@ void issue_long_find_row_warning(Log_event_type type, "while looking up records to be processed. Consider adding a " "primary key (or unique key) to the table to improve " "performance.", - evt_type, table_name, (long) delta, scan_type); + evt_type, table_name, delta, scan_type); } } } diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc index edf3e82de40..f35df43d044 100644 --- a/sql/my_decimal.cc +++ b/sql/my_decimal.cc @@ -59,7 +59,7 @@ int decimal_operation_results(int result, const char *value, const char *type) value, type); break; case E_DEC_DIV_ZERO: - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_DIVISION_BY_ZERO, ER_THD(thd, ER_DIVISION_BY_ZERO)); break; case E_DEC_BAD_NUM: diff --git a/sql/slave.cc b/sql/slave.cc index 90425b27772..e2dc95b672f 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -7059,7 +7059,7 @@ dbug_gtid_accept: "the last seen GTID is %u-%u-%llu", Log_event::get_type_str((Log_event_type) (uchar) buf[EVENT_TYPE_OFFSET]), - mi->last_queued_gtid); + PARAM_GTID(mi->last_queued_gtid)); goto err; } } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 28858277308..9a9217fb7da 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -12115,9 +12115,9 @@ void Sql_cmd_grant::warn_hostname_requires_resolving(THD *thd, while ((user= it++)) { if (opt_skip_name_resolve && hostname_requires_resolving(user->host.str)) - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_WARN_HOSTNAME_WONT_WORK, - ER_THD(thd, ER_WARN_HOSTNAME_WONT_WORK)); + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_HOSTNAME_WONT_WORK, + ER_THD(thd, ER_WARN_HOSTNAME_WONT_WORK)); } } @@ -13295,7 +13295,7 @@ static bool secure_auth(THD *thd) else { my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0)); - general_log_print(thd, COM_CONNECT, + general_log_print(thd, COM_CONNECT, "%s", ER_THD(thd, ER_NOT_SUPPORTED_AUTH_MODE)); } return 1; @@ -13368,7 +13368,7 @@ static bool send_plugin_request_packet(MPVIO_EXT *mpvio, if (switch_from_short_to_long_scramble) { my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0)); - general_log_print(mpvio->auth_info.thd, COM_CONNECT, + general_log_print(mpvio->auth_info.thd, COM_CONNECT, "%s", ER_THD(mpvio->auth_info.thd, ER_NOT_SUPPORTED_AUTH_MODE)); DBUG_RETURN (1); } @@ -13458,7 +13458,7 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio) !ignore_max_password_errors(mpvio->acl_user)) { my_error(ER_USER_IS_BLOCKED, MYF(0)); - general_log_print(mpvio->auth_info.thd, COM_CONNECT, + general_log_print(mpvio->auth_info.thd, COM_CONNECT, "%s", ER_THD(mpvio->auth_info.thd, ER_USER_IS_BLOCKED)); DBUG_RETURN(1); } @@ -13473,7 +13473,7 @@ static bool find_mpvio_user(MPVIO_EXT *mpvio) DBUG_ASSERT(my_strcasecmp(system_charset_info, mpvio->acl_user->auth->plugin.str, old_password_plugin_name.str)); my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0)); - general_log_print(mpvio->auth_info.thd, COM_CONNECT, + general_log_print(mpvio->auth_info.thd, COM_CONNECT, "%s", ER_THD(mpvio->auth_info.thd, ER_NOT_SUPPORTED_AUTH_MODE)); DBUG_RETURN (1); } @@ -15019,5 +15019,3 @@ extern "C" void maria_update_hostname( *ip_mask= h.ip_mask; #endif } - - diff --git a/sql/sql_class.h b/sql/sql_class.h index 07b225c7d06..3d19b2f71cd 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -67,8 +67,8 @@ void set_thd_stage_info(void *thd, #include "wsrep.h" #include "wsrep_on.h" -#ifdef WITH_WSREP #include +#ifdef WITH_WSREP /* wsrep-lib */ #include "wsrep_client_service.h" #include "wsrep_client_state.h" diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 4f9c71d2bab..c788d66744a 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -1838,10 +1838,8 @@ bool add_table_for_trigger(THD *thd, { if (if_exists) { - push_warning_printf(thd, - Sql_condition::WARN_LEVEL_NOTE, - ER_TRG_DOES_NOT_EXIST, - ER_THD(thd, ER_TRG_DOES_NOT_EXIST)); + push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, + ER_TRG_DOES_NOT_EXIST, ER_THD(thd, ER_TRG_DOES_NOT_EXIST)); *table= NULL; diff --git a/sql/sql_type.h b/sql/sql_type.h index 859b63b5ad1..26ab1514346 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -687,7 +687,7 @@ public: { return m_usec ? my_snprintf(to, nbytes, "%s%llu.%06lu", - m_neg ? "-" : "", m_sec, (uint) m_usec) : + m_neg ? "-" : "", m_sec, m_usec) : my_snprintf(to, nbytes, "%s%llu", m_neg ? "-" : "", m_sec); } void make_truncated_warning(THD *thd, const char *type_str) const; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 155424a3c21..9aab9f97fe0 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2224,17 +2224,17 @@ master_def: if (unlikely(Lex->mi.heartbeat_period > slave_net_timeout)) { - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX, - ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX)); + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, + ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX, + ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX)); } if (unlikely(Lex->mi.heartbeat_period < 0.001)) { if (unlikely(Lex->mi.heartbeat_period != 0.0)) { - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, - ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN, - ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN)); + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, + ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN, + ER_THD(thd, ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN)); Lex->mi.heartbeat_period= 0.0; } Lex->mi.heartbeat_opt= LEX_MASTER_INFO::LEX_MI_DISABLE; diff --git a/sql/table.cc b/sql/table.cc index 31a5afdb125..df85f63ad92 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3830,50 +3830,54 @@ static void print_long_unique_table(TABLE *table) " fields->offset,field->null_bit, field->null_pos and key_info ... \n" "\nPrinting Table keyinfo\n"); str.append(buff, strlen(buff)); - my_snprintf(buff, sizeof(buff), "\ntable->s->reclength %d\n" - "table->s->fields %d\n", + my_snprintf(buff, sizeof(buff), "\ntable->s->reclength %lu\n" + "table->s->fields %u\n", table->s->reclength, table->s->fields); str.append(buff, strlen(buff)); for (uint i= 0; i < table->s->keys; i++) { key_info_table= table->key_info + i; key_info_share= table->s->key_info + i; - my_snprintf(buff, sizeof(buff), "\ntable->key_info[%d] user_defined_key_parts = %d\n" - "table->key_info[%d] algorithm == HA_KEY_ALG_LONG_HASH = %d\n" - "table->key_info[%d] flags & HA_NOSAME = %d\n", - i, key_info_table->user_defined_key_parts, - i, key_info_table->algorithm == HA_KEY_ALG_LONG_HASH, - i, key_info_table->flags & HA_NOSAME); + my_snprintf(buff, sizeof(buff), + "\ntable->key_info[%u] user_defined_key_parts = %u\n" + "table->key_info[%u] algorithm == HA_KEY_ALG_LONG_HASH = %d\n" + "table->key_info[%u] flags & HA_NOSAME = %lu\n", + i, key_info_table->user_defined_key_parts, + i, key_info_table->algorithm == HA_KEY_ALG_LONG_HASH, + i, key_info_table->flags & HA_NOSAME); str.append(buff, strlen(buff)); - my_snprintf(buff, sizeof(buff), "\ntable->s->key_info[%d] user_defined_key_parts = %d\n" - "table->s->key_info[%d] algorithm == HA_KEY_ALG_LONG_HASH = %d\n" - "table->s->key_info[%d] flags & HA_NOSAME = %d\n", - i, key_info_share->user_defined_key_parts, - i, key_info_share->algorithm == HA_KEY_ALG_LONG_HASH, - i, key_info_share->flags & HA_NOSAME); + my_snprintf(buff, sizeof(buff), + "\ntable->s->key_info[%u] user_defined_key_parts = %u\n" + "table->s->key_info[%u] algorithm == HA_KEY_ALG_LONG_HASH = %d\n" + "table->s->key_info[%u] flags & HA_NOSAME = %lu\n", + i, key_info_share->user_defined_key_parts, + i, key_info_share->algorithm == HA_KEY_ALG_LONG_HASH, + i, key_info_share->flags & HA_NOSAME); str.append(buff, strlen(buff)); key_part = key_info_table->key_part; - my_snprintf(buff, sizeof(buff), "\nPrinting table->key_info[%d].key_part[0] info\n" - "key_part->offset = %d\n" - "key_part->field_name = %s\n" - "key_part->length = %d\n" - "key_part->null_bit = %d\n" - "key_part->null_offset = %d\n", - i, key_part->offset, key_part->field->field_name.str, key_part->length, - key_part->null_bit, key_part->null_offset); + my_snprintf(buff, sizeof(buff), + "\nPrinting table->key_info[%u].key_part[0] info\n" + "key_part->offset = %u\n" + "key_part->field_name = %s\n" + "key_part->length = %u\n" + "key_part->null_bit = %u\n" + "key_part->null_offset = %u\n", + i, key_part->offset, key_part->field->field_name.str, key_part->length, + key_part->null_bit, key_part->null_offset); str.append(buff, strlen(buff)); for (uint j= 0; j < key_info_share->user_defined_key_parts; j++) { key_part= key_info_share->key_part + j; - my_snprintf(buff, sizeof(buff), "\nPrinting share->key_info[%d].key_part[%d] info\n" - "key_part->offset = %d\n" - "key_part->field_name = %s\n" - "key_part->length = %d\n" - "key_part->null_bit = %d\n" - "key_part->null_offset = %d\n", - i,j,key_part->offset, key_part->field->field_name.str, key_part->length, - key_part->null_bit, key_part->null_offset); + my_snprintf(buff, sizeof(buff), + "\nPrinting share->key_info[%u].key_part[%u] info\n" + "key_part->offset = %u\n" + "key_part->field_name = %s\n" + "key_part->length = %u\n" + "key_part->null_bit = %u\n" + "key_part->null_offset = %u\n", + i, j, key_part->offset, key_part->field->field_name.str, + key_part->length, key_part->null_bit, key_part->null_offset); str.append(buff, strlen(buff)); } } @@ -3882,16 +3886,17 @@ static void print_long_unique_table(TABLE *table) for(uint i= 0; i < table->s->fields; i++) { field= table->field[i]; - my_snprintf(buff, sizeof(buff), "\ntable->field[%d]->field_name %s\n" - "table->field[%d]->offset = %d\n" - "table->field[%d]->field_length = %d\n" - "table->field[%d]->null_pos wrt to record 0 = %d\n" - "table->field[%d]->null_bit_pos = %d\n", - i, field->field_name.str, - i, field->ptr- table->record[0], - i, field->pack_length(), - i, field->null_bit ? field->null_ptr - table->record[0] : -1, - i, field->null_bit); + my_snprintf(buff, sizeof(buff), + "\ntable->field[%u]->field_name %s\n" + "table->field[%u]->offset = %" PRIdPTR "\n" // `%td` not available + "table->field[%u]->field_length = %d\n" + "table->field[%u]->null_pos wrt to record 0 = %" PRIdPTR "\n" + "table->field[%u]->null_bit_pos = %d\n", + i, field->field_name.str, + i, field->ptr- table->record[0], + i, field->pack_length(), + i, field->null_bit ? field->null_ptr - table->record[0] : -1, + i, field->null_bit); str.append(buff, strlen(buff)); } (*error_handler_hook)(1, str.ptr(), ME_NOTE); diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc index f6a7e25b945..0db2e15d071 100644 --- a/sql/wsrep_var.cc +++ b/sql/wsrep_var.cc @@ -986,7 +986,7 @@ bool wsrep_max_ws_size_update(sys_var *self, THD *thd, enum_var_type) { char max_ws_size_opt[128]; my_snprintf(max_ws_size_opt, sizeof(max_ws_size_opt), - "repl.max_ws_size=%d", wsrep_max_ws_size); + "repl.max_ws_size=%lu", wsrep_max_ws_size); enum wsrep::provider::status ret= Wsrep_server_state::instance().provider().options(max_ws_size_opt); if (ret) { diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 6fd3d6d8cdf..68d486b9457 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -11343,7 +11343,7 @@ create_table_info_t::check_table_options() push_warning_printf( m_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, - "InnoDB: invalid PAGE_COMPRESSION_LEVEL = %lu." + "InnoDB: invalid PAGE_COMPRESSION_LEVEL = %llu." " Valid values are [1, 2, 3, 4, 5, 6, 7, 8, 9]", options->page_compression_level); return "PAGE_COMPRESSION_LEVEL"; @@ -21550,7 +21550,7 @@ ib_foreign_warn(trx_t* trx, /*!< in: trx */ if (trx && trx->mysql_thd) { THD* thd = (THD*)trx->mysql_thd; - push_warning_printf( + push_warning( thd, Sql_condition::WARN_LEVEL_WARN, uint(convert_error_code_to_mysql(error, 0, thd)), buf); } diff --git a/storage/innobase/trx/trx0undo.cc b/storage/innobase/trx/trx0undo.cc index bb327f6cc9d..ccd0838fec8 100644 --- a/storage/innobase/trx/trx0undo.cc +++ b/storage/innobase/trx/trx0undo.cc @@ -877,7 +877,7 @@ corrupted: + block->frame); const trx_id_t trx_id= mach_read_from_8(undo_header + TRX_UNDO_TRX_ID); if (trx_id >> 48) { - sql_print_error("InnoDB: corrupted TRX_ID %llx", trx_id); + sql_print_error("InnoDB: corrupted TRX_ID %" PRIx64, trx_id); goto corrupted; } /* We will increment rseg->needs_purge, like trx_undo_reuse_cached() @@ -913,7 +913,7 @@ corrupted: read_trx_no: trx_no = mach_read_from_8(TRX_UNDO_TRX_NO + undo_header); if (trx_no >> 48) { - sql_print_error("InnoDB: corrupted TRX_NO %llx", + sql_print_error("InnoDB: corrupted TRX_NO %" PRIx64, trx_no); goto corrupted; } diff --git a/storage/maria/s3_func.c b/storage/maria/s3_func.c index 3d18ba8800d..84e46cf944d 100644 --- a/storage/maria/s3_func.c +++ b/storage/maria/s3_func.c @@ -1162,7 +1162,7 @@ my_bool s3_rename_object(ms3_st *s3_client, const char *aws_bucket, if (!(errmsg= ms3_server_error(s3_client))) errmsg= ms3_error(error); - my_printf_error(EE_READ, "Got error from move_object(%s -> %s): %d %", + my_printf_error(EE_READ, "Got error from move_object(%s -> %s): %d %s", error_flags, from_name, to_name, error, errmsg); } diff --git a/storage/mroonga/lib/mrn_multiple_column_key_codec.cpp b/storage/mroonga/lib/mrn_multiple_column_key_codec.cpp index dd3165cdadf..51145440135 100644 --- a/storage/mroonga/lib/mrn_multiple_column_key_codec.cpp +++ b/storage/mroonga/lib/mrn_multiple_column_key_codec.cpp @@ -693,7 +693,7 @@ namespace mrn { "data: <%.*s>", normalized_length, UINT_MAX16, - field->field_name, + field->field_name.str, blob_data_length, blob_data); memcpy(grn_key, normalized, blob_data_length); new_blob_data_length = blob_data_length; diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 05f8238bc20..12987f40220 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1488,7 +1488,7 @@ int ha_myisam::assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt) param->db_name= table->s->db.str; param->table_name= table->s->table_name.str; param->testflag= 0; - mi_check_print_error(param, errmsg); + mi_check_print_error(param, "%s", errmsg); } DBUG_RETURN(error); } @@ -1554,7 +1554,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt) param->db_name= table->s->db.str; param->table_name= table->s->table_name.str; param->testflag= 0; - mi_check_print_error(param, errmsg); + mi_check_print_error(param, "%s", errmsg); DBUG_RETURN(error); } } diff --git a/storage/myisam/mi_check.c b/storage/myisam/mi_check.c index 33fab259a9c..c4389d3cfa8 100644 --- a/storage/myisam/mi_check.c +++ b/storage/myisam/mi_check.c @@ -874,7 +874,7 @@ static int chk_index(HA_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo, if (keypos != endpos) { mi_check_print_error(param,"Keyblock size at page %s is not correct. Block length: %d key length: %d", - llstr(page,llbuff), used_length, (keypos - buff)); + llstr(page,llbuff), used_length, (int) (keypos - buff)); goto err; } my_afree((uchar*) temp_buff); @@ -1167,7 +1167,7 @@ int chk_data_link(HA_CHECK *param, MI_INFO *info, my_bool extend) block_info.rec_len > (uint) info->s->max_pack_length) { mi_check_print_error(param, - "Found block with wrong recordlength: %d at %s", + "Found block with wrong recordlength: %lu at %s", block_info.rec_len, llstr(start_recpos,llbuff)); got_error=1; break; @@ -3389,7 +3389,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param) { if (!searching) mi_check_print_info(param, - "Deleted block with impossible length %u at %s", + "Deleted block with impossible length %lu at %s", block_info.block_len,llstr(pos,llbuff)); error=1; } @@ -3625,7 +3625,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param) block_info.rec_len > (uint) share->max_pack_length) { if (! searching) - mi_check_print_info(param,"Found block with wrong recordlength: %d at %s\n", + mi_check_print_info(param,"Found block with wrong recordlength: %ld at %s\n", block_info.rec_len, llstr(sort_param->pos,llbuff)); continue; @@ -4133,7 +4133,7 @@ static int sort_delete_record(MI_SORT_PARAM *sort_param) if (info->s->options & HA_OPTION_COMPRESS_RECORD) { mi_check_print_error(param, - "Recover aborted; Can't run standard recovery on compressed tables with errors in data-file. Use switch 'myisamchk --safe-recover' to fix it\n",stderr);; + "Recover aborted; Can't run standard recovery on compressed tables with errors in data-file. Use switch 'myisamchk --safe-recover' to fix it\n"); DBUG_RETURN(1); } diff --git a/storage/myisam/myisamchk.c b/storage/myisam/myisamchk.c index 4344ce11420..3f504a2ea44 100644 --- a/storage/myisam/myisamchk.c +++ b/storage/myisam/myisamchk.c @@ -1578,7 +1578,7 @@ static int mi_sort_records(HA_CHECK *param, share->state.key_root[sort_key], MYF(MY_NABP+MY_WME))) { - mi_check_print_error(param,"Can't read indexpage from filepos: %s", + mi_check_print_error(param,"Can't read indexpage from filepos: %lu", (ulong) share->state.key_root[sort_key]); goto err; } diff --git a/storage/oqgraph/ha_oqgraph.cc b/storage/oqgraph/ha_oqgraph.cc index 11bb139fd55..415ac292c35 100644 --- a/storage/oqgraph/ha_oqgraph.cc +++ b/storage/oqgraph/ha_oqgraph.cc @@ -318,7 +318,7 @@ int ha_oqgraph::oqgraph_check_table_structure (TABLE *table_arg) { DBUG_PRINT( "oq-debug", ("Allowing integer no more!")); badColumn = true; - push_warning_printf( current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Integer latch is not supported for new tables.", i); + push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, HA_WRONG_CREATE_OPTION, "Integer latch is not supported for new tables."); } else /* Check Column Type */ if ((*field)->type() != skel[i].coltype) { diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 92885783daf..0c9b3fa6234 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -2315,7 +2315,7 @@ int spider_db_mbase::fetch_and_print_warnings(struct tm *l_time) longlong res_num = (longlong) my_strtoll10(row[1], (char**) NULL, &error_num); DBUG_PRINT("info",("spider res_num=%lld", res_num)); - my_printf_error((int) res_num, row[2], MYF(0)); + my_printf_error((int) res_num, "%s", MYF(0), row[2]); error_num = (int) res_num; row = mysql_fetch_row(res); } From 39f1f30f6817ca9f3811f5253a56f8e32a3dc565 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 22 Nov 2024 12:11:32 +0400 Subject: [PATCH 26/55] MDEV-23687 Assertion `is_valid_value_slow()' failed in Datetime::Datetime upon EXTRACT under mode ZERO_DATE_TIME_CAST Item_{date|datetime}_typecase::get_date() erroneously passed the TIME_INTERVAL_DAY flag from the caller to args[0] which made CAST('100000:00:00' AS DATETIME) parse '100000:00:00' as TIME rather that DATETIME. Suppressing this flag. --- mysql-test/main/func_extract.result | 25 +++++++++++++++++++++++++ mysql-test/main/func_extract.test | 10 ++++++++++ sql/item_timefunc.cc | 6 ++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/func_extract.result b/mysql-test/main/func_extract.result index 7c1fd5009ca..5c651d713ea 100644 --- a/mysql-test/main/func_extract.result +++ b/mysql-test/main/func_extract.result @@ -1478,5 +1478,30 @@ NULL Warnings: Warning 1292 Incorrect interval value: '42949672955000x1' # +# MDEV-23687 Assertion `is_valid_value_slow()' failed in Datetime::Datetime upon EXTRACT under mode ZERO_DATE_TIME_CAST +# +SET SESSION old_mode='ZERO_DATE_TIME_CAST'; +SELECT CAST('100000:00:00' AS DATETIME); +CAST('100000:00:00' AS DATETIME) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '100000:00:00' +SELECT EXTRACT(DAY FROM CAST('100000:00:00' AS DATETIME)); +EXTRACT(DAY FROM CAST('100000:00:00' AS DATETIME)) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '100000:00:00' +SELECT CAST('100000:00:00' AS DATE); +CAST('100000:00:00' AS DATE) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '100000:00:00' +SELECT EXTRACT(DAY FROM CAST('100000:00:00' AS DATE)); +EXTRACT(DAY FROM CAST('100000:00:00' AS DATE)) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '100000:00:00' +SET SESSION old_mode=DEFAULT; +# # End of 10.5 tests # diff --git a/mysql-test/main/func_extract.test b/mysql-test/main/func_extract.test index 6167780b9bf..05c5529659b 100644 --- a/mysql-test/main/func_extract.test +++ b/mysql-test/main/func_extract.test @@ -517,6 +517,16 @@ DROP FUNCTION select02; SELECT EXTRACT(HOUR_MICROSECOND FROM '42949672955000x1'); +--echo # +--echo # MDEV-23687 Assertion `is_valid_value_slow()' failed in Datetime::Datetime upon EXTRACT under mode ZERO_DATE_TIME_CAST +--echo # + +SET SESSION old_mode='ZERO_DATE_TIME_CAST'; +SELECT CAST('100000:00:00' AS DATETIME); +SELECT EXTRACT(DAY FROM CAST('100000:00:00' AS DATETIME)); +SELECT CAST('100000:00:00' AS DATE); +SELECT EXTRACT(DAY FROM CAST('100000:00:00' AS DATE)); +SET SESSION old_mode=DEFAULT; --echo # --echo # End of 10.5 tests diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 072cb34c0f5..a2d1c63f006 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2585,7 +2585,8 @@ Sql_mode_dependency Item_time_typecast::value_depends_on_sql_mode() const bool Item_date_typecast::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd)) & ~TIME_TIME_ONLY; + date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd)) + & ~TIME_TIME_ONLY & ~TIME_INTERVAL_DAY; // Force truncation Date *d= new(ltime) Date(thd, args[0], Date::Options(date_conv_mode_t(tmp))); return (null_value= !d->is_valid_date()); @@ -2594,7 +2595,8 @@ bool Item_date_typecast::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzy bool Item_datetime_typecast::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { - date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd)) & ~TIME_TIME_ONLY; + date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd)) + & ~TIME_TIME_ONLY & ~TIME_INTERVAL_DAY; // Force rounding if the current sql_mode says so Datetime::Options opt(date_conv_mode_t(tmp), thd); Datetime *dt= new(ltime) Datetime(thd, args[0], opt, From 95df7ea33a7502dd5ff84e5703e85e07d24c81fb Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 21 Nov 2024 10:01:48 +0400 Subject: [PATCH 27/55] MDEV-31881 ASAN: unknown-crash in check_ulonglong (sql/sql_analyse.cc) on SELECT ... FROM ... PROCEDURE ANALYSE() Fixing a wrong condition which made the code read 1 byte behind the buffer. --- mysql-test/main/func_analyse.result | 10 ++++++++++ mysql-test/main/func_analyse.test | 9 +++++++++ sql/sql_analyse.cc | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/func_analyse.result b/mysql-test/main/func_analyse.result index 1dfdc828793..dc56cf5d7d7 100644 --- a/mysql-test/main/func_analyse.result +++ b/mysql-test/main/func_analyse.result @@ -245,5 +245,15 @@ Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_ test.t1.c 1.1 1.3 3 3 0 0 3.0000 NULL ENUM('1.1','1.3') NOT NULL DROP TABLE t1; # +# MDEV-31881 ASAN: unknown-crash in check_ulonglong (sql/sql_analyse.cc) on SELECT ... FROM ... PROCEDURE ANALYSE() +# +CREATE TABLE t (a INT, b CHAR(10)); +INSERT INTO t VALUES (0,'0000000000'); +SELECT * FROM t PROCEDURE ANALYSE(); +Field_name Min_value Max_value Min_length Max_length Empties_or_zeros Nulls Avg_value_or_avg_length Std Optimal_fieldtype +test.t.a 0 0 1 1 1 0 0.0000 0.0000 ENUM('0') NOT NULL +test.t.b 0000000000 0000000000 10 10 0 0 10.0000 NULL ENUM('0000000000') NOT NULL +DROP TABLE t; +# # End of 10.5 tests # diff --git a/mysql-test/main/func_analyse.test b/mysql-test/main/func_analyse.test index 8afc2ab34a6..f5c027a5283 100644 --- a/mysql-test/main/func_analyse.test +++ b/mysql-test/main/func_analyse.test @@ -255,6 +255,15 @@ INSERT INTO t1 VALUES (1.3),(1.1); SELECT * FROM t1 PROCEDURE ANALYSE(); DROP TABLE t1; +--echo # +--echo # MDEV-31881 ASAN: unknown-crash in check_ulonglong (sql/sql_analyse.cc) on SELECT ... FROM ... PROCEDURE ANALYSE() +--echo # + +CREATE TABLE t (a INT, b CHAR(10)); +INSERT INTO t VALUES (0,'0000000000'); +SELECT * FROM t PROCEDURE ANALYSE(); +DROP TABLE t; + --echo # --echo # End of 10.5 tests --echo # diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 8dfa1c06d7f..e17c6e190e2 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -1204,7 +1204,7 @@ uint check_ulonglong(const char *str, uint length) const char *long_str = "2147483647", *ulonglong_str = "18446744073709551615"; const uint long_len = 10, ulonglong_len = 20; - while (*str == '0' && length) + while (length && *str == '0') { str++; length--; } From 3997d28f48068fe058e738e70fc6911e1eed5669 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 21 Nov 2024 10:47:56 +0400 Subject: [PATCH 28/55] MDEV-16698 ASAN: heap-use-after-free in field_longstr::uncompress This bug was earlier fixed by MDEV-16699. Adding tests only. --- mysql-test/main/column_compression.result | 35 +++++++++++++++++++++ mysql-test/main/column_compression.test | 37 +++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/mysql-test/main/column_compression.result b/mysql-test/main/column_compression.result index 891f663a872..45e073b72b1 100644 --- a/mysql-test/main/column_compression.result +++ b/mysql-test/main/column_compression.result @@ -2943,4 +2943,39 @@ t2 CREATE TABLE `t2` ( `c` text /*M!100301 COMPRESSED*/ DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci drop table t1, t2; +# +# MDEV-16698 ASAN: heap-use-after-free in field_longstr::uncompress +# +CREATE TABLE t5 ( +i1 smallint(11) unsigned zerofill , +e1 enum('','a') , +b1 mediumblob /*!100301 COMPRESSED*/ , +d2 date NOT NULL DEFAULT '1900-01-01', +pk bigint(20) unsigned NOT NULL DEFAULT 0, +d1 timestamp NULL , +v1 varbinary(3362) , +t1 time NOT NULL DEFAULT '00:00:00' +); +INSERT INTO t5 VALUES +(00000000004,'','ufhjdtv','1992-07-25',1,'2035-06-05 09:02:48','f','13:25:21'), +(00000000001,'','jdt','1998-07-03',2,'1994-05-05 19:59:20','','09:09:19'), +(00000000000,'','d','2007-12-05',3,'0000-00-00 00:00:00','tvs','02:51:15'); +SELECT GROUP_CONCAT(t5.i1, IF(t5.e1, t5.b1, t5.e1), +IF(t5.d1, t5.t1, t5.d1), t5.v1, +IF(t5.i1, t5.i1, t5.d2), t5.v1, t5.b1 +ORDER BY 2,6 SEPARATOR ';') +FROM (t5 JOIN t5 AS tt ON (tt.pk != t5.pk)); +DROP TABLE t5; +create table t1 (pk int not null, b1 blob compressed, v1 varbinary(100))engine=innodb; +insert into t1 values (1,'ufhjdtv','f'),(2,'jdt',''),(3,'d','tvs'); +select group_concat(t1.v1, t1.b1 order by 1) from (t1 join t1 as tt on (tt.pk != t1.pk)); +group_concat(t1.v1, t1.b1 order by 1) +jdt,jdt,fufhjdtv,fufhjdtv,tvsd,tvsd +drop table t1; +CREATE TABLE t1 (a CHAR(1), b TEXT /*!100302 COMPRESSED */); +INSERT INTO t1 VALUES ('c','n'),('d','mmmmmmmmmm'); +SELECT GROUP_CONCAT( b, a ORDER BY 2 ) AS f FROM t1; +f +nc,mmmmmmmmmmd +DROP TABLE t1; # End of 10.5 tests diff --git a/mysql-test/main/column_compression.test b/mysql-test/main/column_compression.test index b520b423865..dffa42e2017 100644 --- a/mysql-test/main/column_compression.test +++ b/mysql-test/main/column_compression.test @@ -480,4 +480,41 @@ create table t2 as select group_concat(c order by 1), concat(c), c from t1; show create table t2; drop table t1, t2; +--echo # +--echo # MDEV-16698 ASAN: heap-use-after-free in field_longstr::uncompress +--echo # + +CREATE TABLE t5 ( + i1 smallint(11) unsigned zerofill , + e1 enum('','a') , + b1 mediumblob /*!100301 COMPRESSED*/ , + d2 date NOT NULL DEFAULT '1900-01-01', + pk bigint(20) unsigned NOT NULL DEFAULT 0, + d1 timestamp NULL , + v1 varbinary(3362) , + t1 time NOT NULL DEFAULT '00:00:00' +); +INSERT INTO t5 VALUES +(00000000004,'','ufhjdtv','1992-07-25',1,'2035-06-05 09:02:48','f','13:25:21'), +(00000000001,'','jdt','1998-07-03',2,'1994-05-05 19:59:20','','09:09:19'), +(00000000000,'','d','2007-12-05',3,'0000-00-00 00:00:00','tvs','02:51:15'); +--disable_result_log +SELECT GROUP_CONCAT(t5.i1, IF(t5.e1, t5.b1, t5.e1), + IF(t5.d1, t5.t1, t5.d1), t5.v1, + IF(t5.i1, t5.i1, t5.d2), t5.v1, t5.b1 + ORDER BY 2,6 SEPARATOR ';') +FROM (t5 JOIN t5 AS tt ON (tt.pk != t5.pk)); +DROP TABLE t5; +--enable_result_log + +create table t1 (pk int not null, b1 blob compressed, v1 varbinary(100))engine=innodb; +insert into t1 values (1,'ufhjdtv','f'),(2,'jdt',''),(3,'d','tvs'); +select group_concat(t1.v1, t1.b1 order by 1) from (t1 join t1 as tt on (tt.pk != t1.pk)); +drop table t1; + +CREATE TABLE t1 (a CHAR(1), b TEXT /*!100302 COMPRESSED */); +INSERT INTO t1 VALUES ('c','n'),('d','mmmmmmmmmm'); +SELECT GROUP_CONCAT( b, a ORDER BY 2 ) AS f FROM t1; +DROP TABLE t1; + --echo # End of 10.5 tests From dbfee9fc2bc8c427d320e04f486c815e79e1cbe6 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Sat, 26 Oct 2024 08:17:03 -0600 Subject: [PATCH 29/55] MDEV-34348: Consolidate cmp function declarations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Partial commit of the greater MDEV-34348 scope. MDEV-34348: MariaDB is violating clang-16 -Wcast-function-type-strict The functions queue_compare, qsort2_cmp, and qsort_cmp2 all had similar interfaces, and were used interchangable and unsafely cast to one another. This patch consolidates the functions all into the qsort_cmp2 interface. Reviewed By: ============ Marko Mäkelä --- client/mysqltest.cc | 4 +- include/CMakeLists.txt | 1 + include/my_cmp.h | 25 +++++++++ include/my_global.h | 5 +- include/my_sys.h | 7 ++- include/myisam.h | 2 +- include/queues.h | 9 ++-- mysys/mf_keycache.c | 4 +- mysys/mf_qsort.c | 4 +- mysys/my_lib.c | 6 ++- mysys/my_likely.c | 4 +- mysys/ptr_cmp.c | 79 +++++++++++++++------------- mysys/queues.c | 4 +- mysys/thr_alarm.c | 7 +-- mysys/thr_timer.c | 7 +-- plugin/type_inet/sql_type_inet.cc | 10 ++-- sql/bounded_queue.h | 20 +------ sql/event_queue.cc | 6 +-- sql/filesort.cc | 31 ++++++----- sql/filesort_utils.h | 6 +-- sql/ha_partition.cc | 31 +++++++---- sql/ha_partition.h | 13 +++-- sql/handler.cc | 8 ++- sql/item_cmpfunc.cc | 60 ++++++++++++--------- sql/item_cmpfunc.h | 31 +++++------ sql/item_subselect.cc | 35 ++++++------ sql/item_subselect.h | 34 ++++++------ sql/item_sum.cc | 50 +++++++++--------- sql/item_sum.h | 31 +++++------ sql/key.cc | 11 ++-- sql/key.h | 6 ++- sql/multi_range_read.cc | 30 ++++++----- sql/multi_range_read.h | 7 +-- sql/mysqld.cc | 6 +-- sql/opt_range.cc | 32 +++++++---- sql/opt_split.cc | 4 +- sql/records.cc | 6 ++- sql/rowid_filter.cc | 10 ++-- sql/rowid_filter.h | 9 ++-- sql/rpl_gtid.cc | 6 +-- sql/set_var.cc | 4 +- sql/slave.cc | 6 ++- sql/sp_head.cc | 5 +- sql/sql_acl.cc | 32 +++++++---- sql/sql_analyse.cc | 26 +++++---- sql/sql_analyse.h | 45 ++++++++-------- sql/sql_array.h | 11 ++-- sql/sql_base.h | 5 +- sql/sql_class.h | 8 +-- sql/sql_delete.cc | 7 +-- sql/sql_lifo_buffer.h | 2 +- sql/sql_select.cc | 39 +++++++------- sql/sql_select.h | 2 +- sql/sql_sort.h | 6 +-- sql/sql_statistics.cc | 15 +++--- sql/sql_table.cc | 8 ++- sql/sql_type.cc | 10 ++-- sql/uniques.cc | 10 ++-- storage/csv/ha_tina.cc | 4 +- storage/heap/hp_create.c | 14 +++-- storage/maria/aria_pack.c | 31 ++++++----- storage/maria/ma_check.c | 7 ++- storage/maria/ma_create.c | 8 +-- storage/maria/ma_ft_boolean_search.c | 27 ++++++---- storage/maria/ma_ft_nlq_search.c | 20 +++---- storage/maria/ma_ft_parser.c | 12 +++-- storage/maria/ma_pagecache.c | 4 +- storage/maria/ma_sort.c | 16 +++--- storage/maria/ma_write.c | 8 ++- storage/maria/maria_def.h | 2 +- storage/myisam/ft_boolean_search.c | 22 +++++--- storage/myisam/ft_nlq_search.c | 17 +++--- storage/myisam/ft_parser.c | 11 ++-- storage/myisam/ft_stopwords.c | 7 +-- storage/myisam/mi_check.c | 12 +++-- storage/myisam/mi_write.c | 7 ++- storage/myisam/myisamlog.c | 8 +-- storage/myisam/myisampack.c | 29 +++++----- storage/myisam/sort.c | 14 ++--- storage/myisammrg/myrg_queue.c | 6 +-- storage/spider/spd_table.cc | 6 ++- storage/spider/spd_table.h | 4 +- unittest/mysys/queues-t.c | 4 +- 83 files changed, 678 insertions(+), 524 deletions(-) create mode 100644 include/my_cmp.h 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; } From 840fe316d414095bc020a97929c2397d9d5405e7 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Sat, 26 Oct 2024 11:34:26 -0600 Subject: [PATCH 30/55] MDEV-34348: my_hash_get_key fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Partial commit of the greater MDEV-34348 scope. MDEV-34348: MariaDB is violating clang-16 -Wcast-function-type-strict Change the type of my_hash_get_key to: 1) Return const 2) Change the context parameter to be const void* Also fix casting in hash adjacent areas. Reviewed By: ============ Marko Mäkelä --- client/mysqldump.c | 14 ++-- client/mysqltest.cc | 9 +- extra/mariabackup/xbstream.cc | 36 ++++---- include/hash.h | 2 +- mysys/charset.c | 9 +- mysys/hash.c | 8 +- mysys/mf_keycache.c | 66 +++++++++------ mysys/my_likely.c | 10 +-- mysys/my_safehash.c | 15 ++-- mysys/waiting_threads.c | 2 +- sql-common/client.c | 9 +- sql/ha_partition.cc | 7 +- sql/hostname.cc | 6 +- sql/item_create.cc | 14 ++-- sql/item_func.cc | 5 +- sql/mdl.cc | 11 ++- sql/partition_info.cc | 12 +-- sql/rpl_filter.cc | 10 +-- sql/rpl_mi.cc | 16 ++-- sql/session_tracker.cc | 8 +- sql/session_tracker.h | 9 +- sql/set_var.cc | 12 +-- sql/sp.cc | 7 +- sql/sp.h | 4 +- sql/sp_cache.cc | 11 ++- sql/sp_head.cc | 8 +- sql/sql_acl.cc | 94 ++++++++++----------- sql/sql_cache.cc | 52 ++++++------ sql/sql_cache.h | 12 +-- sql/sql_class.cc | 66 +++++++-------- sql/sql_connect.cc | 73 ++++++----------- sql/sql_db.cc | 16 ++-- sql/sql_handler.cc | 14 ++-- sql/sql_hset.h | 5 +- sql/sql_plugin.cc | 20 ++--- sql/sql_servers.cc | 13 +-- sql/sql_show.cc | 9 +- sql/sql_udf.cc | 9 +- sql/table.cc | 10 +-- sql/table_cache.cc | 26 +++--- sql/tztime.cc | 21 +++-- sql/xa.cc | 2 +- storage/blackhole/ha_blackhole.cc | 16 ++-- storage/cassandra/ha_cassandra.cc | 11 +-- storage/csv/ha_tina.cc | 11 ++- storage/federated/ha_federated.cc | 9 +- storage/federatedx/ha_federatedx.cc | 27 +++--- storage/maria/aria_read_log.c | 9 +- storage/maria/ma_init.c | 5 +- storage/maria/trnman.c | 7 +- storage/mroonga/ha_mroonga.cpp | 26 +++--- storage/perfschema/pfs_account.cc | 8 +- storage/perfschema/pfs_digest.cc | 8 +- storage/perfschema/pfs_host.cc | 8 +- storage/perfschema/pfs_instr.cc | 8 +- storage/perfschema/pfs_instr_class.cc | 8 +- storage/perfschema/pfs_program.cc | 8 +- storage/perfschema/pfs_setup_actor.cc | 8 +- storage/perfschema/pfs_setup_object.cc | 8 +- storage/perfschema/pfs_user.cc | 8 +- storage/sphinx/ha_sphinx.cc | 9 +- storage/spider/spd_conn.cc | 52 ++++++------ storage/spider/spd_conn.h | 12 +-- storage/spider/spd_db_mysql.cc | 8 +- storage/spider/spd_table.cc | 109 +++++++++++++------------ storage/spider/spd_table.h | 24 ++---- storage/spider/spd_trx.cc | 52 +++++------- 67 files changed, 604 insertions(+), 617 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index fbe5ac68765..716e1f368e4 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -857,11 +857,11 @@ static void write_footer(FILE *sql_file) } /* write_footer */ -uchar* get_table_key(const char *entry, size_t *length, - my_bool not_used __attribute__((unused))) +const uchar *get_table_key(const void *entry, size_t *length, + my_bool not_used __attribute__((unused))) { *length= strlen(entry); - return (uchar*) entry; + return entry; } @@ -1071,11 +1071,11 @@ static int get_options(int *argc, char ***argv) load_defaults_or_exit("my", load_default_groups, argc, argv); defaults_argv= *argv; - if (my_hash_init(PSI_NOT_INSTRUMENTED, &ignore_database, charset_info, 16, 0, 0, - (my_hash_get_key) get_table_key, my_free, 0)) + if (my_hash_init(PSI_NOT_INSTRUMENTED, &ignore_database, charset_info, 16, 0, + 0, get_table_key, my_free, 0)) return(EX_EOM); if (my_hash_init(PSI_NOT_INSTRUMENTED, &ignore_table, charset_info, 16, 0, 0, - (my_hash_get_key) get_table_key, my_free, 0)) + get_table_key, my_free, 0)) return(EX_EOM); /* Don't copy internal log tables */ if (my_hash_insert(&ignore_table, (uchar*) my_strdup(PSI_NOT_INSTRUMENTED, @@ -1091,7 +1091,7 @@ static int get_options(int *argc, char ***argv) return(EX_EOM); if (my_hash_init(PSI_NOT_INSTRUMENTED, &ignore_data, charset_info, 16, 0, 0, - (my_hash_get_key) get_table_key, my_free, 0)) + get_table_key, my_free, 0)) return(EX_EOM); if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option))) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index ba2fdc028ba..3d820834b67 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -2389,13 +2389,12 @@ static void strip_parentheses(struct st_command *command) C_MODE_START -static uchar *get_var_key(const uchar* var, size_t *len, - my_bool __attribute__((unused)) t) +static const uchar *get_var_key(const void *var, size_t *len, my_bool) { char* key; - key = ((VAR*)var)->name; - *len = ((VAR*)var)->name_len; - return (uchar*)key; + key= (static_cast(var))->name; + *len= (static_cast(var))->name_len; + return reinterpret_cast(key); } diff --git a/extra/mariabackup/xbstream.cc b/extra/mariabackup/xbstream.cc index 6306806b867..ed169c73524 100644 --- a/extra/mariabackup/xbstream.cc +++ b/extra/mariabackup/xbstream.cc @@ -358,22 +358,23 @@ err: } static -uchar * -get_file_entry_key(file_entry_t *entry, size_t *length, - my_bool not_used __attribute__((unused))) +const uchar * +get_file_entry_key(const void *entry_, size_t *length, my_bool) { - *length = entry->pathlen; - return (uchar *) entry->path; + const file_entry_t *entry= static_cast(entry_); + *length= entry->pathlen; + return reinterpret_cast(entry->path); } static void -file_entry_free(file_entry_t *entry) +file_entry_free(void *entry_) { - pthread_mutex_destroy(&entry->mutex); - ds_close(entry->file); - my_free(entry->path); - my_free(entry); + file_entry_t *entry= static_cast(entry_); + pthread_mutex_destroy(&entry->mutex); + ds_close(entry->file); + my_free(entry->path); + my_free(entry); } static @@ -493,14 +494,15 @@ mode_extract(int n_threads, int argc __attribute__((unused)), pthread_mutex_t mutex; int ret = 0; - if (my_hash_init(PSI_NOT_INSTRUMENTED, &filehash, &my_charset_bin, - START_FILE_HASH_SIZE, 0, 0, (my_hash_get_key) get_file_entry_key, - (my_hash_free_key) file_entry_free, MYF(0))) { - msg("%s: failed to initialize file hash.", my_progname); - return 1; - } + if (my_hash_init(PSI_NOT_INSTRUMENTED, &filehash, &my_charset_bin, + START_FILE_HASH_SIZE, 0, 0, get_file_entry_key, + file_entry_free, MYF(0))) + { + msg("%s: failed to initialize file hash.", my_progname); + return 1; + } - if (pthread_mutex_init(&mutex, NULL)) { + if (pthread_mutex_init(&mutex, NULL)) { msg("%s: failed to initialize mutex.", my_progname); my_hash_free(&filehash); return 1; diff --git a/include/hash.h b/include/hash.h index 00ffca503fc..bc0bb19473e 100644 --- a/include/hash.h +++ b/include/hash.h @@ -42,7 +42,7 @@ extern "C" { #define HASH_THREAD_SPECIFIC 2 /* Mark allocated memory THREAD_SPECIFIC */ typedef uint32 my_hash_value_type; -typedef uchar *(*my_hash_get_key)(const uchar *,size_t*,my_bool); +typedef const uchar *(*my_hash_get_key)(const void *, size_t *, my_bool); typedef my_hash_value_type (*my_hash_function)(CHARSET_INFO *, const uchar *, size_t); typedef void (*my_hash_free_key)(void *); diff --git a/mysys/charset.c b/mysys/charset.c index 5e58b10e0bd..bba677f6e57 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -669,13 +669,12 @@ const char *my_collation_get_tailoring(uint id) HASH charset_name_hash; -static uchar *get_charset_key(const uchar *object, - size_t *size, - my_bool not_used __attribute__((unused))) +static const uchar *get_charset_key(const void *object, size_t *size, + my_bool not_used __attribute__((unused))) { - CHARSET_INFO *cs= (CHARSET_INFO*) object; + CHARSET_INFO *cs= object; *size= strlen(cs->csname); - return (uchar*) cs->csname; + return (const uchar *) cs->csname; } static void init_available_charsets(void) diff --git a/mysys/hash.c b/mysys/hash.c index c86b0d92cb6..b8c0ca3ff87 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -878,8 +878,8 @@ my_bool my_hash_check(HASH *hash) #define RECORDS 1000 -uchar *test_get_key(uchar *data, size_t *length, - my_bool not_used __attribute__((unused))) +const uchar *test_get_key(const void *data, size_t *length, + my_bool not_used __attribute__((unused))) { *length= 2; return data; @@ -895,8 +895,8 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) DBUG_PUSH("d:t:O,/tmp/test_hash.trace"); printf("my_hash_init\n"); - if (my_hash_init2(PSI_INSTRUMENT_ME, &hash_test, 100, &my_charset_bin, 20, - 0, 0, (my_hash_get_key) test_get_key, 0, 0, HASH_UNIQUE)) + if (my_hash_init2(PSI_INSTRUMENT_ME, &hash_test, 100, &my_charset_bin, 20, 0, + 0, test_get_key, 0, 0, HASH_UNIQUE)) { fprintf(stderr, "hash init failed\n"); exit(1); diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index a026009e613..85812f2edee 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -321,7 +321,7 @@ KEY_CACHE *dflt_key_cache= &dflt_key_cache_var; #define FLUSH_CACHE 2000 /* sort this many blocks at once */ static int flush_all_key_blocks(SIMPLE_KEY_CACHE_CB *keycache); -static void end_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, my_bool cleanup); +static void end_simple_key_cache(void *keycache_, my_bool cleanup); static void wait_on_queue(KEYCACHE_WQUEUE *wqueue, mysql_mutex_t *mutex); static void release_whole_queue(KEYCACHE_WQUEUE *wqueue); @@ -473,11 +473,12 @@ static inline uint next_power(uint value) */ static -int init_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, +int init_simple_key_cache(void *keycache_, uint key_cache_block_size, size_t use_mem, uint division_limit, uint age_threshold, uint changed_blocks_hash_size) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; size_t blocks, hash_links; size_t length; int error; @@ -834,11 +835,12 @@ void finish_resize_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache) */ static -int resize_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, +int resize_simple_key_cache(void *keycache_, uint key_cache_block_size, size_t use_mem, uint division_limit, uint age_threshold, uint changed_blocks_hash_size) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; int blocks= 0; DBUG_ENTER("resize_simple_key_cache"); @@ -914,9 +916,10 @@ static inline void dec_counter_for_resize_op(SIMPLE_KEY_CACHE_CB *keycache) */ static -void change_simple_key_cache_param(SIMPLE_KEY_CACHE_CB *keycache, uint division_limit, +void change_simple_key_cache_param(void *keycache_, uint division_limit, uint age_threshold) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; DBUG_ENTER("change_simple_key_cache_param"); keycache_pthread_mutex_lock(&keycache->cache_lock); if (division_limit) @@ -953,8 +956,9 @@ void change_simple_key_cache_param(SIMPLE_KEY_CACHE_CB *keycache, uint division_ */ static -void end_simple_key_cache(SIMPLE_KEY_CACHE_CB *keycache, my_bool cleanup) +void end_simple_key_cache(void *keycache_, my_bool cleanup) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; DBUG_ENTER("end_simple_key_cache"); DBUG_PRINT("enter", ("key_cache: %p", keycache)); @@ -2763,12 +2767,13 @@ static void read_block_secondary(SIMPLE_KEY_CACHE_CB *keycache, have to be a multiple of key_cache_block_size; */ -uchar *simple_key_cache_read(SIMPLE_KEY_CACHE_CB *keycache, +uchar *simple_key_cache_read(void *keycache_, File file, my_off_t filepos, int level, uchar *buff, uint length, uint block_length __attribute__((unused)), int return_buffer __attribute__((unused))) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; my_bool locked_and_incremented= FALSE; int error=0; uchar *start= buff; @@ -3015,10 +3020,11 @@ end: */ static -int simple_key_cache_insert(SIMPLE_KEY_CACHE_CB *keycache, +int simple_key_cache_insert(void *keycache_, File file, my_off_t filepos, int level, uchar *buff, uint length) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; int error= 0; DBUG_ENTER("key_cache_insert"); DBUG_PRINT("enter", ("fd: %u pos: %lu length: %u", @@ -3280,13 +3286,14 @@ int simple_key_cache_insert(SIMPLE_KEY_CACHE_CB *keycache, */ static -int simple_key_cache_write(SIMPLE_KEY_CACHE_CB *keycache, +int simple_key_cache_write(void *keycache_, File file, void *file_extra __attribute__((unused)), my_off_t filepos, int level, uchar *buff, uint length, uint block_length __attribute__((unused)), int dont_write) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; my_bool locked_and_incremented= FALSE; int error=0; DBUG_ENTER("simple_key_cache_write"); @@ -4365,11 +4372,12 @@ err: */ static -int flush_simple_key_cache_blocks(SIMPLE_KEY_CACHE_CB *keycache, +int flush_simple_key_cache_blocks(void *keycache_, File file, void *file_extra __attribute__((unused)), enum flush_type type) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; int res= 0; DBUG_ENTER("flush_key_blocks"); DBUG_PRINT("enter", ("keycache: %p", keycache)); @@ -4546,8 +4554,9 @@ static int flush_all_key_blocks(SIMPLE_KEY_CACHE_CB *keycache) static int reset_simple_key_cache_counters(const char *name __attribute__((unused)), - SIMPLE_KEY_CACHE_CB *keycache) + void *keycache_) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; DBUG_ENTER("reset_simple_key_cache_counters"); if (!keycache->key_cache_inited) { @@ -4889,10 +4898,11 @@ static int cache_empty(SIMPLE_KEY_CACHE_CB *keycache) */ static -void get_simple_key_cache_statistics(SIMPLE_KEY_CACHE_CB *keycache, +void get_simple_key_cache_statistics(void *keycache_, uint partition_no __attribute__((unused)), KEY_CACHE_STATISTICS *keycache_stats) { + SIMPLE_KEY_CACHE_CB *keycache= keycache_; DBUG_ENTER("simple_get_key_cache_statistics"); keycache_stats->mem_size= (longlong) keycache->key_cache_mem_size; @@ -4980,12 +4990,12 @@ typedef struct st_partitioned_key_cache_cb } PARTITIONED_KEY_CACHE_CB; static -void end_partitioned_key_cache(PARTITIONED_KEY_CACHE_CB *keycache, +void end_partitioned_key_cache(void *keycache_, my_bool cleanup); static int reset_partitioned_key_cache_counters(const char *name, - PARTITIONED_KEY_CACHE_CB *keycache); + void *keycache_); /* Determine the partition to which the index block to read is ascribed @@ -5093,11 +5103,12 @@ static SIMPLE_KEY_CACHE_CB */ static -int init_partitioned_key_cache(PARTITIONED_KEY_CACHE_CB *keycache, +int init_partitioned_key_cache(void *keycache_, uint key_cache_block_size, size_t use_mem, uint division_limit, uint age_threshold, uint changed_blocks_hash_size) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; int i; size_t mem_per_cache; size_t mem_decr; @@ -5259,12 +5270,13 @@ int init_partitioned_key_cache(PARTITIONED_KEY_CACHE_CB *keycache, */ static -int resize_partitioned_key_cache(PARTITIONED_KEY_CACHE_CB *keycache, +int resize_partitioned_key_cache(void *keycache_, uint key_cache_block_size, size_t use_mem, uint division_limit, uint age_threshold, uint changed_blocks_hash_size) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; uint i; uint partitions= keycache->partitions; my_bool cleanup= use_mem == 0; @@ -5323,10 +5335,11 @@ int resize_partitioned_key_cache(PARTITIONED_KEY_CACHE_CB *keycache, */ static -void change_partitioned_key_cache_param(PARTITIONED_KEY_CACHE_CB *keycache, +void change_partitioned_key_cache_param(void *keycache_, uint division_limit, uint age_threshold) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; uint i; uint partitions= keycache->partitions; DBUG_ENTER("partitioned_change_key_cache_param"); @@ -5365,9 +5378,10 @@ void change_partitioned_key_cache_param(PARTITIONED_KEY_CACHE_CB *keycache, */ static -void end_partitioned_key_cache(PARTITIONED_KEY_CACHE_CB *keycache, +void end_partitioned_key_cache(void *keycache_, my_bool cleanup) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; uint i; uint partitions= keycache->partitions; DBUG_ENTER("partitioned_end_key_cache"); @@ -5432,12 +5446,13 @@ void end_partitioned_key_cache(PARTITIONED_KEY_CACHE_CB *keycache, */ static -uchar *partitioned_key_cache_read(PARTITIONED_KEY_CACHE_CB *keycache, +uchar *partitioned_key_cache_read(void *keycache_, File file, my_off_t filepos, int level, uchar *buff, uint length, uint block_length __attribute__((unused)), int return_buffer __attribute__((unused))) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; uint r_length; uint offset= (uint) (filepos % keycache->key_cache_block_size); uchar *start= buff; @@ -5510,10 +5525,11 @@ uchar *partitioned_key_cache_read(PARTITIONED_KEY_CACHE_CB *keycache, */ static -int partitioned_key_cache_insert(PARTITIONED_KEY_CACHE_CB *keycache, +int partitioned_key_cache_insert(void *keycache_, File file, my_off_t filepos, int level, uchar *buff, uint length) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; uint w_length; uint offset= (uint) (filepos % keycache->key_cache_block_size); DBUG_ENTER("partitioned_key_cache_insert"); @@ -5592,13 +5608,14 @@ int partitioned_key_cache_insert(PARTITIONED_KEY_CACHE_CB *keycache, */ static -int partitioned_key_cache_write(PARTITIONED_KEY_CACHE_CB *keycache, +int partitioned_key_cache_write(void *keycache_, File file, void *file_extra, my_off_t filepos, int level, uchar *buff, uint length, uint block_length __attribute__((unused)), int dont_write) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; uint w_length; ulonglong *part_map= (ulonglong *) file_extra; uint offset= (uint) (filepos % keycache->key_cache_block_size); @@ -5676,10 +5693,11 @@ int partitioned_key_cache_write(PARTITIONED_KEY_CACHE_CB *keycache, */ static -int flush_partitioned_key_cache_blocks(PARTITIONED_KEY_CACHE_CB *keycache, +int flush_partitioned_key_cache_blocks(void *keycache_, File file, void *file_extra, enum flush_type type) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; uint i; uint partitions= keycache->partitions; int err= 0; @@ -5726,8 +5744,9 @@ int flush_partitioned_key_cache_blocks(PARTITIONED_KEY_CACHE_CB *keycache, static int reset_partitioned_key_cache_counters(const char *name __attribute__((unused)), - PARTITIONED_KEY_CACHE_CB *keycache) + void *keycache_) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; uint i; uint partitions= keycache->partitions; DBUG_ENTER("partitioned_reset_key_cache_counters"); @@ -5768,10 +5787,11 @@ reset_partitioned_key_cache_counters(const char *name __attribute__((unused)), static void -get_partitioned_key_cache_statistics(PARTITIONED_KEY_CACHE_CB *keycache, +get_partitioned_key_cache_statistics(void *keycache_, uint partition_no, KEY_CACHE_STATISTICS *keycache_stats) { + PARTITIONED_KEY_CACHE_CB *keycache= keycache_; uint i; SIMPLE_KEY_CACHE_CB *partition; uint partitions= keycache->partitions; diff --git a/mysys/my_likely.c b/mysys/my_likely.c index a685e13d22b..0d5463f64b0 100644 --- a/mysys/my_likely.c +++ b/mysys/my_likely.c @@ -35,11 +35,12 @@ typedef struct st_likely_entry ulonglong ok,fail; } LIKELY_ENTRY; -static uchar *get_likely_key(LIKELY_ENTRY *part, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *get_likely_key(const void *part_, size_t *length, + my_bool not_used __attribute__((unused))) { + const LIKELY_ENTRY *part= (const LIKELY_ENTRY *) part_; *length= part->key_length; - return (uchar*) part->key; + return (const uchar *) part->key; } pthread_mutex_t likely_mutex; @@ -49,8 +50,7 @@ void init_my_likely() { /* Allocate big enough to avoid malloc calls */ my_hash_init2(PSI_NOT_INSTRUMENTED, &likely_hash, 10000, &my_charset_bin, - 1024, 0, 0, (my_hash_get_key) get_likely_key, 0, free, - HASH_UNIQUE); + 1024, 0, 0, get_likely_key, 0, free, HASH_UNIQUE); likely_inited= 1; pthread_mutex_init(&likely_mutex, MY_MUTEX_INIT_FAST); } diff --git a/mysys/my_safehash.c b/mysys/my_safehash.c index 7d37b707c3a..70ed450e037 100644 --- a/mysys/my_safehash.c +++ b/mysys/my_safehash.c @@ -50,8 +50,9 @@ This function is called by the hash object on delete */ -static void safe_hash_entry_free(SAFE_HASH_ENTRY *entry) +static void safe_hash_entry_free(void *entry_) { + SAFE_HASH_ENTRY *entry= entry_; DBUG_ENTER("safe_hash_entry_free"); my_free(entry); DBUG_VOID_RETURN; @@ -70,11 +71,13 @@ static void safe_hash_entry_free(SAFE_HASH_ENTRY *entry) # reference on the key */ -static uchar *safe_hash_entry_get(SAFE_HASH_ENTRY *entry, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *safe_hash_entry_get(const void *entry_, size_t *length, + my_bool not_used + __attribute__((unused))) { + const SAFE_HASH_ENTRY *entry= entry_; *length= entry->length; - return (uchar*) entry->key; + return entry->key; } @@ -101,8 +104,8 @@ my_bool safe_hash_init(SAFE_HASH *hash, uint elements, { DBUG_ENTER("safe_hash_init"); if (my_hash_init(key_memory_SAFE_HASH_ENTRY, &hash->hash, &my_charset_bin, - elements, 0, 0, (my_hash_get_key) safe_hash_entry_get, - (void (*)(void*)) safe_hash_entry_free, 0)) + elements, 0, 0, safe_hash_entry_get, safe_hash_entry_free, + 0)) { hash->default_value= 0; DBUG_RETURN(1); diff --git a/mysys/waiting_threads.c b/mysys/waiting_threads.c index 445e9f4781a..ededa24011a 100644 --- a/mysys/waiting_threads.c +++ b/mysys/waiting_threads.c @@ -449,7 +449,7 @@ void wt_init() sizeof_WT_RESOURCE_ID, 0, 0); reshash.alloc.constructor= wt_resource_create; reshash.alloc.destructor= wt_resource_destroy; - reshash.initializer= (lf_hash_initializer) wt_resource_init; + reshash.initializer= wt_resource_init; bzero(wt_wait_stats, sizeof(wt_wait_stats)); bzero(wt_cycle_stats, sizeof(wt_cycle_stats)); diff --git a/sql-common/client.c b/sql-common/client.c index 13882caa340..476b655d6ef 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -4013,12 +4013,13 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) /** A function to return the key from a connection attribute */ -uchar * -get_attr_key(LEX_STRING *part, size_t *length, +const uchar * +get_attr_key(const void *part_, size_t *length, my_bool not_used __attribute__((unused))) { + const LEX_STRING *part= part_; *length= part[0].length; - return (uchar *) part[0].str; + return (const uchar *) part[0].str; } int STDCALL @@ -4067,7 +4068,7 @@ mysql_options4(MYSQL *mysql,enum mysql_option option, { if (my_hash_init(key_memory_mysql_options, &mysql->options.extension->connection_attributes, - &my_charset_bin, 0, 0, 0, (my_hash_get_key) + &my_charset_bin, 0, 0, 0, get_attr_key, my_free, HASH_UNIQUE)) { set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index d72a836e7ce..ed7fb7fe5f9 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -3368,9 +3368,9 @@ bool ha_partition::get_from_handler_file(const char *name, MEM_ROOT *mem_root, @return Partition name */ -static uchar *get_part_name(PART_NAME_DEF *part, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *get_part_name(const void *part_, size_t *length, my_bool) { + auto part= reinterpret_cast(part_); *length= part->length; return part->partition_name; } @@ -3456,8 +3456,7 @@ bool ha_partition::populate_partition_name_hash() tot_names= m_is_sub_partitioned ? m_tot_parts + num_parts : num_parts; if (my_hash_init(key_memory_Partition_share, &part_share->partition_name_hash, system_charset_info, - tot_names, 0, 0, (my_hash_get_key) get_part_name, my_free, - HASH_UNIQUE)) + tot_names, 0, 0, get_part_name, my_free, HASH_UNIQUE)) { unlock_shared_ha_data(); DBUG_RETURN(TRUE); diff --git a/sql/hostname.cc b/sql/hostname.cc index 984c1a219ff..1542c189e44 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -149,9 +149,9 @@ bool hostname_cache_init() Host_entry tmp; uint key_offset= (uint) ((char*) (&tmp.ip_key) - (char*) &tmp); - if (!(hostname_cache= new Hash_filo(key_memory_host_cache_hostname, - host_cache_size, key_offset, HOST_ENTRY_KEY_SIZE, - NULL, (my_hash_free_key) free, &my_charset_bin))) + if (!(hostname_cache= new Hash_filo( + key_memory_host_cache_hostname, host_cache_size, key_offset, + HOST_ENTRY_KEY_SIZE, NULL, free, &my_charset_bin))) return 1; hostname_cache->clear(); diff --git a/sql/item_create.cc b/sql/item_create.cc index 2c54bc9118e..6571f6c60f7 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -38,13 +38,12 @@ #include -extern "C" uchar* -get_native_fct_hash_key(const uchar *buff, size_t *length, - my_bool /* unused */) +extern "C" const uchar *get_native_fct_hash_key(const void *buff, + size_t *length, my_bool) { - Native_func_registry *func= (Native_func_registry*) buff; + auto func= static_cast(buff); *length= func->name.length; - return (uchar*) func->name.str; + return reinterpret_cast(func->name.str); } @@ -5708,9 +5707,8 @@ bool Native_functions_hash::init(size_t count) { DBUG_ENTER("Native_functions_hash::init"); - if (my_hash_init(key_memory_native_functions, this, - system_charset_info, (ulong) count, 0, 0, (my_hash_get_key) - get_native_fct_hash_key, NULL, MYF(0))) + if (my_hash_init(key_memory_native_functions, this, system_charset_info, + (ulong) count, 0, 0, get_native_fct_hash_key, NULL, MYF(0))) DBUG_RETURN(true); DBUG_RETURN(false); diff --git a/sql/item_func.cc b/sql/item_func.cc index f25ca5ed408..34e4727681e 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4146,13 +4146,12 @@ public: /** Extract a hash key from User_level_lock. */ -uchar *ull_get_key(const uchar *ptr, size_t *length, - my_bool not_used __attribute__((unused))) +const uchar *ull_get_key(const void *ptr, size_t *length, my_bool) { User_level_lock *ull = (User_level_lock*) ptr; MDL_key *key = ull->lock->get_key(); *length= key->length(); - return (uchar*) key->ptr(); + return key->ptr(); } diff --git a/sql/mdl.cc b/sql/mdl.cc index 324d95c2fee..93a186c48b3 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -703,13 +703,12 @@ static MDL_map mdl_locks; extern "C" { -static uchar * -mdl_locks_key(const uchar *record, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *mdl_locks_key(const void *record, size_t *length, + my_bool) { - MDL_lock *lock=(MDL_lock*) record; + const MDL_lock *lock= static_cast(record); *length= lock->key.length(); - return (uchar*) lock->key.ptr(); + return lock->key.ptr(); } } /* extern "C" */ @@ -821,7 +820,7 @@ void MDL_map::init() mdl_locks_key, &my_charset_bin); m_locks.alloc.constructor= MDL_lock::lf_alloc_constructor; m_locks.alloc.destructor= MDL_lock::lf_alloc_destructor; - m_locks.initializer= (lf_hash_initializer) MDL_lock::lf_hash_initializer; + m_locks.initializer= MDL_lock::lf_hash_initializer; m_locks.hash_function= mdl_hash_function; } diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 3ac0f144536..c33928f80fe 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -671,11 +671,11 @@ partition_element *partition_info::get_part_elem(const char *partition_name, Helper function to find_duplicate_name. */ -static const char *get_part_name_from_elem(const char *name, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *get_part_name_from_elem(const void *name, size_t *length, + my_bool) { - *length= strlen(name); - return name; + *length= strlen(static_cast(name)); + return static_cast(name); } /* @@ -713,8 +713,8 @@ char *partition_info::find_duplicate_name() max_names= num_parts; if (is_sub_partitioned()) max_names+= num_parts * num_subparts; - if (my_hash_init(PSI_INSTRUMENT_ME, &partition_names, system_charset_info, max_names, 0, 0, - (my_hash_get_key) get_part_name_from_elem, 0, HASH_UNIQUE)) + if (my_hash_init(PSI_INSTRUMENT_ME, &partition_names, system_charset_info, + max_names, 0, 0, get_part_name_from_elem, 0, HASH_UNIQUE)) { DBUG_ASSERT(0); curr_name= (const uchar*) "Internal failure"; diff --git a/sql/rpl_filter.cc b/sql/rpl_filter.cc index 39bdde9ce76..e05da1bd4ec 100644 --- a/sql/rpl_filter.cc +++ b/sql/rpl_filter.cc @@ -580,16 +580,14 @@ Rpl_filter::set_ignore_db(const char* db_spec) } -extern "C" uchar *get_table_key(const uchar *, size_t *, my_bool); +extern "C" const uchar *get_table_key(const void *, size_t *, my_bool); extern "C" void free_table_ent(void* a); -uchar *get_table_key(const uchar* a, size_t *len, - my_bool __attribute__((unused))) +const uchar *get_table_key(const void *a, size_t *len, my_bool) { - TABLE_RULE_ENT *e= (TABLE_RULE_ENT *) a; - + auto e= static_cast(a); *len= e->key_len; - return (uchar*)e->db; + return reinterpret_cast(e->db); } diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc index 7a9dcd49493..951f53bed79 100644 --- a/sql/rpl_mi.cc +++ b/sql/rpl_mi.cc @@ -850,12 +850,12 @@ void end_master_info(Master_info* mi) } /* Multi-Master By P.Linux */ -uchar *get_key_master_info(Master_info *mi, size_t *length, - my_bool not_used __attribute__((unused))) +const uchar *get_key_master_info(const void *mi_, size_t *length, my_bool) { + auto mi= static_cast(mi_); /* Return lower case name */ *length= mi->cmp_connection_name.length; - return (uchar*) mi->cmp_connection_name.str; + return reinterpret_cast(mi->cmp_connection_name.str); } /* @@ -865,8 +865,9 @@ uchar *get_key_master_info(Master_info *mi, size_t *length, Stops associated slave threads and frees master_info */ -void free_key_master_info(Master_info *mi) +void free_key_master_info(void *mi_) { + Master_info *mi= static_cast(mi_); DBUG_ENTER("free_key_master_info"); mysql_mutex_unlock(&LOCK_active_mi); @@ -1101,10 +1102,9 @@ bool Master_info_index::init_all_master_info() } /* Initialize Master_info Hash Table */ - if (my_hash_init(PSI_INSTRUMENT_ME, &master_info_hash, system_charset_info, - MAX_REPLICATION_THREAD, 0, 0, - (my_hash_get_key) get_key_master_info, - (my_hash_free_key)free_key_master_info, HASH_UNIQUE)) + if (my_hash_init(PSI_INSTRUMENT_ME, &master_info_hash, system_charset_info, + MAX_REPLICATION_THREAD, 0, 0, get_key_master_info, + free_key_master_info, HASH_UNIQUE)) { sql_print_error("Initializing Master_info hash table failed"); DBUG_RETURN(1); diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc index 8e5e4d2142d..2b0819398d4 100644 --- a/sql/session_tracker.cc +++ b/sql/session_tracker.cc @@ -556,12 +556,12 @@ void Session_sysvars_tracker::mark_as_changed(THD *thd, const sys_var *var) @return Pointer to the key buffer. */ -uchar *Session_sysvars_tracker::sysvars_get_key(const char *entry, - size_t *length, - my_bool not_used __attribute__((unused))) +const uchar *Session_sysvars_tracker::sysvars_get_key(const void *entry, + size_t *length, my_bool) { *length= sizeof(sys_var *); - return (uchar *) &(((sysvar_node_st *) entry)->m_svar); + return reinterpret_cast( + &((static_cast(entry))->m_svar)); } diff --git a/sql/session_tracker.h b/sql/session_tracker.h index 37a4e0cbe89..666981167c1 100644 --- a/sql/session_tracker.h +++ b/sql/session_tracker.h @@ -145,8 +145,9 @@ class Session_sysvars_tracker: public State_tracker void init() { my_hash_init(PSI_INSTRUMENT_ME, &m_registered_sysvars, &my_charset_bin, - 0, 0, 0, (my_hash_get_key) sysvars_get_key, my_free, - HASH_UNIQUE | (mysqld_server_initialized ? HASH_THREAD_SPECIFIC : 0)); + 0, 0, 0, sysvars_get_key, my_free, + HASH_UNIQUE | + (mysqld_server_initialized ? HASH_THREAD_SPECIFIC : 0)); } void free_hash() { @@ -216,8 +217,8 @@ public: void mark_as_changed(THD *thd, const sys_var *var); void deinit() { orig_list.deinit(); } /* callback */ - static uchar *sysvars_get_key(const char *entry, size_t *length, - my_bool not_used __attribute__((unused))); + static const uchar *sysvars_get_key(const void *entry, size_t *length, + my_bool); friend bool sysvartrack_global_update(THD *thd, char *str, size_t len); }; diff --git a/sql/set_var.cc b/sql/set_var.cc index 3c5826d4491..a06a81fd9a6 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -48,11 +48,12 @@ static ulonglong system_variable_hash_version= 0; Return variable name and length for hashing of variables. */ -static uchar *get_sys_var_length(const sys_var *var, size_t *length, - my_bool first) +static const uchar *get_sys_var_length(const void *var_, size_t *length, + my_bool) { + auto var= static_cast(var_); *length= var->name.length; - return (uchar*) var->name.str; + return reinterpret_cast(var->name.str); } sys_var_chain all_sys_vars = { NULL, NULL }; @@ -64,8 +65,9 @@ int sys_var_init() /* Must be already initialized. */ DBUG_ASSERT(system_charset_info != NULL); - if (my_hash_init(PSI_INSTRUMENT_ME, &system_variable_hash, system_charset_info, 700, 0, - 0, (my_hash_get_key) get_sys_var_length, 0, HASH_UNIQUE)) + if (my_hash_init(PSI_INSTRUMENT_ME, &system_variable_hash, + system_charset_info, 700, 0, 0, get_sys_var_length, 0, + HASH_UNIQUE)) goto error; if (mysql_add_sys_var_chain(all_sys_vars.first)) diff --git a/sql/sp.cc b/sql/sp.cc index ba5a29364da..7d05af54ef6 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -2281,12 +2281,11 @@ Sp_handler::sp_exist_routines(THD *thd, TABLE_LIST *routines) const } -extern "C" uchar* sp_sroutine_key(const uchar *ptr, size_t *plen, - my_bool first) +extern "C" const uchar *sp_sroutine_key(const void *ptr, size_t *plen, my_bool) { - Sroutine_hash_entry *rn= (Sroutine_hash_entry *)ptr; + auto rn= static_cast(ptr); *plen= rn->mdl_request.key.length(); - return (uchar *)rn->mdl_request.key.ptr(); + return rn->mdl_request.key.ptr(); } diff --git a/sql/sp.h b/sql/sp.h index 26cc78aec7d..689d024a261 100644 --- a/sql/sp.h +++ b/sql/sp.h @@ -648,8 +648,8 @@ void sp_update_stmt_used_routines(THD *thd, Query_tables_list *prelocking_ctx, SQL_I_List *src, TABLE_LIST *belong_to_view); -extern "C" uchar* sp_sroutine_key(const uchar *ptr, size_t *plen, - my_bool first); +extern "C" const uchar *sp_sroutine_key(const void *ptr, size_t *plen, + my_bool); /* Routines which allow open/lock and close mysql.proc table even when diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc index f67ef4218af..731a6410a2f 100644 --- a/sql/sp_cache.cc +++ b/sql/sp_cache.cc @@ -269,16 +269,15 @@ sp_cache_enforce_limit(sp_cache *c, ulong upper_limit_for_elements) Internal functions *************************************************************************/ -extern "C" uchar *hash_get_key_for_sp_head(const uchar *ptr, size_t *plen, - my_bool first); +extern "C" const uchar *hash_get_key_for_sp_head(const void *ptr, size_t *plen, + my_bool); extern "C" void hash_free_sp_head(void *p); -uchar *hash_get_key_for_sp_head(const uchar *ptr, size_t *plen, - my_bool first) +const uchar *hash_get_key_for_sp_head(const void *ptr, size_t *plen, my_bool) { - sp_head *sp= (sp_head *)ptr; + auto sp= static_cast(ptr); *plen= sp->m_qname.length; - return (uchar*) sp->m_qname.str; + return reinterpret_cast(sp->m_qname.str); } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 81f06802fb7..506e755c2fd 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -102,7 +102,7 @@ void init_sp_psi_keys() #define MYSQL_RUN_SP(SP, CODE) do { CODE; } while(0) #endif -extern "C" uchar *sp_table_key(const uchar *ptr, size_t *plen, my_bool first); +extern "C" const uchar *sp_table_key(const void *ptr, size_t *plen, my_bool); /** Helper function which operates on a THD object to set the query start_time to @@ -4977,11 +4977,11 @@ typedef struct st_sp_table } SP_TABLE; -uchar *sp_table_key(const uchar *ptr, size_t *plen, my_bool first) +const uchar *sp_table_key(const void *ptr, size_t *plen, my_bool) { - SP_TABLE *tab= (SP_TABLE *)ptr; + auto tab= static_cast(ptr); *plen= tab->qname.length; - return (uchar *)tab->qname.str; + return reinterpret_cast(tab->qname.str); } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index e7336f1e133..5e4053cd7f2 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -538,18 +538,20 @@ public: }; -static uchar* acl_entry_get_key(acl_entry *entry, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *acl_entry_get_key(const void *entry_, size_t *length, + my_bool) { + auto entry= static_cast(entry_); *length=(uint) entry->length; - return (uchar*) entry->key; + return reinterpret_cast(entry->key); } -static uchar* acl_role_get_key(ACL_ROLE *entry, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *acl_role_get_key(const void *entry_, size_t *length, + my_bool) { + auto entry= static_cast(entry_); *length=(uint) entry->user.length; - return (uchar*) entry->user.str; + return reinterpret_cast(entry->user.str); } struct ROLE_GRANT_PAIR : public Sql_alloc @@ -564,11 +566,12 @@ struct ROLE_GRANT_PAIR : public Sql_alloc const char *rolename, bool with_admin_option); }; -static uchar* acl_role_map_get_key(ROLE_GRANT_PAIR *entry, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *acl_role_map_get_key(const void *entry_, size_t *length, + my_bool) { + auto entry= static_cast(entry_); *length=(uint) entry->hashkey.length; - return (uchar*) entry->hashkey.str; + return reinterpret_cast(entry->hashkey.str); } bool ROLE_GRANT_PAIR::init(MEM_ROOT *mem, const char *username, @@ -2202,13 +2205,15 @@ static bool is_invalid_role_name(const char *str) } -static void free_acl_user(ACL_USER *user) +static void free_acl_user(void *user_) { + ACL_USER *user= static_cast(user_); delete_dynamic(&(user->role_grants)); } -static void free_acl_role(ACL_ROLE *role) +static void free_acl_role(void *role_) { + ACL_ROLE *role= static_cast(role_); delete_dynamic(&(role->role_grants)); delete_dynamic(&(role->parent_grantee)); } @@ -2481,10 +2486,9 @@ bool acl_init(bool dont_read_acl_tables) bool return_val; DBUG_ENTER("acl_init"); - acl_cache= new Hash_filo(key_memory_acl_cache, ACL_CACHE_SIZE, 0, 0, - (my_hash_get_key) acl_entry_get_key, - (my_hash_free_key) my_free, - &my_charset_utf8mb3_bin); + acl_cache= new Hash_filo(key_memory_acl_cache, ACL_CACHE_SIZE, 0, + 0, acl_entry_get_key, my_free, + &my_charset_utf8mb3_bin); /* cache built-in native authentication plugins, @@ -2924,12 +2928,11 @@ bool acl_reload(THD *thd) my_init_dynamic_array(key_memory_acl_mem, &acl_users, sizeof(ACL_USER), 50, 100, MYF(0)); acl_dbs.init(key_memory_acl_mem, 50, 100); my_init_dynamic_array(key_memory_acl_mem, &acl_proxy_users, sizeof(ACL_PROXY_USER), 50, 100, MYF(0)); - my_hash_init2(key_memory_acl_mem, &acl_roles,50, &my_charset_utf8mb3_bin, - 0, 0, 0, (my_hash_get_key) acl_role_get_key, 0, - (void (*)(void *))free_acl_role, 0); + my_hash_init2(key_memory_acl_mem, &acl_roles, 50, &my_charset_utf8mb3_bin, 0, + 0, 0, acl_role_get_key, 0, free_acl_role, 0); my_hash_init2(key_memory_acl_mem, &acl_roles_mappings, 50, - &my_charset_utf8mb3_bin, 0, 0, 0, (my_hash_get_key) - acl_role_map_get_key, 0, 0, 0); + &my_charset_utf8mb3_bin, 0, 0, 0, acl_role_map_get_key, 0, 0, + 0); old_mem= acl_memroot; delete_dynamic(&acl_wild_hosts); my_hash_free(&acl_check_hosts); @@ -3429,11 +3432,11 @@ int acl_setrole(THD *thd, const char *rolename, privilege_t access) return 0; } -static uchar* check_get_key(ACL_USER *buff, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *check_get_key(const void *buff_, size_t *length, my_bool) { + auto buff= static_cast(buff_); *length=buff->hostname_length; - return (uchar*) buff->host.hostname; + return reinterpret_cast(buff->host.hostname); } @@ -3745,9 +3748,9 @@ static void init_check_host(void) (void) my_init_dynamic_array(key_memory_acl_mem, &acl_wild_hosts, sizeof(struct acl_host_and_ip), acl_users.elements, 1, MYF(0)); - (void) my_hash_init(key_memory_acl_mem, &acl_check_hosts,system_charset_info, - acl_users.elements, 0, 0, - (my_hash_get_key) check_get_key, 0, 0); + (void) my_hash_init(key_memory_acl_mem, &acl_check_hosts, + system_charset_info, acl_users.elements, 0, 0, + check_get_key, 0, 0); if (!allow_all_hosts) { for (uint i=0 ; i < acl_users.elements ; i++) @@ -5342,11 +5345,12 @@ public: }; -static uchar* get_key_column(GRANT_COLUMN *buff, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *get_key_column(const void *buff_, size_t *length, my_bool) { + auto buff= + static_cast(buff_); *length=buff->key_length; - return (uchar*) buff->column; + return reinterpret_cast(buff->column); } class GRANT_NAME :public Sql_alloc @@ -5390,7 +5394,7 @@ public: void init_hash() { my_hash_init2(key_memory_acl_memex, &hash_columns, 4, system_charset_info, - 0, 0, 0, (my_hash_get_key) get_key_column, 0, 0, 0); + 0, 0, 0, get_key_column, 0, 0, 0); } }; @@ -5573,16 +5577,17 @@ GRANT_TABLE::~GRANT_TABLE() } -static uchar* get_grant_table(GRANT_NAME *buff, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *get_grant_table(const void *buff_, size_t *length, my_bool) { + auto buff= static_cast(buff_); *length=buff->key_length; - return (uchar*) buff->hash_key; + return reinterpret_cast(buff->hash_key); } -static void free_grant_table(GRANT_TABLE *grant_table) +static void free_grant_table(void *grant_table_) { + GRANT_TABLE *grant_table= static_cast(grant_table_); grant_table->~GRANT_TABLE(); } @@ -6506,10 +6511,11 @@ static int traverse_role_graph_down(ACL_USER_BASE *user, void *context, entries using the role hash. We put all these "interesting" entries in a (suposedly small) dynamic array and them use it for merging. */ -static uchar* role_key(const ACL_ROLE *role, size_t *klen, my_bool) +static const uchar *role_key(const void *role_, size_t *klen, my_bool) { + auto role= static_cast(role_); *klen= role->user.length; - return (uchar*) role->user.str; + return reinterpret_cast(role->user.str); } typedef Hash_set role_hash_t; @@ -7988,20 +7994,16 @@ static bool grant_load(THD *thd, Sql_mode_instant_remove sms(thd, MODE_PAD_CHAR_TO_FULL_LENGTH); (void) my_hash_init(key_memory_acl_memex, &column_priv_hash, - &my_charset_utf8mb3_bin, 0,0,0, (my_hash_get_key) - get_grant_table, (my_hash_free_key) free_grant_table, 0); + &my_charset_utf8mb3_bin, 0, 0, 0, get_grant_table, + free_grant_table, 0); (void) my_hash_init(key_memory_acl_memex, &proc_priv_hash, - &my_charset_utf8mb3_bin, 0,0,0, (my_hash_get_key) - get_grant_table, 0,0); + &my_charset_utf8mb3_bin, 0, 0, 0, get_grant_table, 0, 0); (void) my_hash_init(key_memory_acl_memex, &func_priv_hash, - &my_charset_utf8mb3_bin, 0,0,0, (my_hash_get_key) - get_grant_table, 0,0); + &my_charset_utf8mb3_bin, 0, 0, 0, get_grant_table, 0, 0); (void) my_hash_init(key_memory_acl_memex, &package_spec_priv_hash, - &my_charset_utf8mb3_bin, 0,0,0, (my_hash_get_key) - get_grant_table, 0,0); + &my_charset_utf8mb3_bin, 0, 0, 0, get_grant_table, 0, 0); (void) my_hash_init(key_memory_acl_memex, &package_body_priv_hash, - &my_charset_utf8mb3_bin, 0,0,0, (my_hash_get_key) - get_grant_table, 0,0); + &my_charset_utf8mb3_bin, 0, 0, 0, get_grant_table, 0, 0); init_sql_alloc(key_memory_acl_mem, &grant_memroot, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); t_table= tables_priv.table(); diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index c876636d383..a54d1174e35 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -840,13 +840,13 @@ void Query_cache_block::destroy() DBUG_VOID_RETURN; } -uint Query_cache_block::headers_len() +uint Query_cache_block::headers_len() const { return (ALIGN_SIZE(sizeof(Query_cache_block_table)*n_tables) + ALIGN_SIZE(sizeof(Query_cache_block))); } -uchar* Query_cache_block::data(void) +uchar* Query_cache_block::data(void) const { return (uchar*)( ((uchar*)this) + headers_len() ); } @@ -893,14 +893,14 @@ Query_cache_block_table * Query_cache_block::table(TABLE_COUNTER_TYPE n) extern "C" { -uchar *query_cache_table_get_key(const uchar *record, size_t *length, - my_bool not_used __attribute__((unused))) +const uchar *query_cache_table_get_key(const void *record, size_t *length, + my_bool) { - Query_cache_block* table_block = (Query_cache_block*) record; - *length = (table_block->used - table_block->headers_len() - - ALIGN_SIZE(sizeof(Query_cache_table))); - return (((uchar *) table_block->data()) + - ALIGN_SIZE(sizeof(Query_cache_table))); + auto table_block= static_cast(record); + *length= (table_block->used - table_block->headers_len() - + ALIGN_SIZE(sizeof(Query_cache_table))); + return reinterpret_cast( + ((table_block->data()) + ALIGN_SIZE(sizeof(Query_cache_table)))); } } @@ -991,14 +991,14 @@ void Query_cache_query::unlock_n_destroy() extern "C" { -uchar *query_cache_query_get_key(const uchar *record, size_t *length, - my_bool not_used) +const uchar *query_cache_query_get_key(const void *record, size_t *length, + my_bool) { - Query_cache_block *query_block = (Query_cache_block*) record; - *length = (query_block->used - query_block->headers_len() - - ALIGN_SIZE(sizeof(Query_cache_query))); - return (((uchar *) query_block->data()) + - ALIGN_SIZE(sizeof(Query_cache_query))); + auto query_block= static_cast(record); + *length= (query_block->used - query_block->headers_len() - + ALIGN_SIZE(sizeof(Query_cache_query))); + return reinterpret_cast + (((query_block->data()) + ALIGN_SIZE(sizeof(Query_cache_query)))); } } @@ -4326,10 +4326,10 @@ my_bool Query_cache::move_by_type(uchar **border, *new_block =(Query_cache_block *) *border; size_t tablename_offset = block->table()->table() - block->table()->db(); char *data = (char*) block->data(); - uchar *key; + const uchar *key; size_t key_length; - key=query_cache_table_get_key((uchar*) block, &key_length, 0); - my_hash_first(&tables, (uchar*) key, key_length, &record_idx); + key=query_cache_table_get_key( block, &key_length, 0); + my_hash_first(&tables, key, key_length, &record_idx); block->destroy(); new_block->init(len); @@ -4386,10 +4386,10 @@ my_bool Query_cache::move_by_type(uchar **border, char *data = (char*) block->data(); Query_cache_block *first_result_block = ((Query_cache_query *) block->data())->result(); - uchar *key; + const uchar *key; size_t key_length; - key=query_cache_query_get_key((uchar*) block, &key_length, 0); - my_hash_first(&queries, (uchar*) key, key_length, &record_idx); + key=query_cache_query_get_key( block, &key_length, 0); + my_hash_first(&queries, key, key_length, &record_idx); block->query()->unlock_n_destroy(); block->destroy(); // Move table of used tables @@ -5043,9 +5043,9 @@ my_bool Query_cache::check_integrity(bool locked) DBUG_PRINT("qcache", ("block %p, type %u...", block, (uint) block->type)); size_t length; - uchar *key = query_cache_query_get_key((uchar*) block, &length, 0); + const uchar *key= query_cache_query_get_key(block, &length, 0); uchar* val = my_hash_search(&queries, key, length); - if (((uchar*)block) != val) + if ((reinterpret_cast(block)) != val) { DBUG_PRINT("error", ("block %p found in queries hash like %p", block, val)); @@ -5078,9 +5078,9 @@ my_bool Query_cache::check_integrity(bool locked) DBUG_PRINT("qcache", ("block %p, type %u...", block, (uint) block->type)); size_t length; - uchar *key = query_cache_table_get_key((uchar*) block, &length, 0); + const uchar *key= query_cache_table_get_key(block, &length, 0); uchar* val = my_hash_search(&tables, key, length); - if (((uchar*)block) != val) + if (reinterpret_cast(block) != val) { DBUG_PRINT("error", ("block %p found in tables hash like %p", block, val)); diff --git a/sql/sql_cache.h b/sql/sql_cache.h index a02034764a7..a1d28ea2e11 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -141,8 +141,8 @@ struct Query_cache_block inline bool is_free(void) { return type == FREE; } void init(size_t length); void destroy(); - uint headers_len(); - uchar* data(void); + uint headers_len() const; + uchar* data(void) const; Query_cache_query *query(); Query_cache_table *table(); Query_cache_result *result(); @@ -256,10 +256,10 @@ struct Query_cache_result extern "C" { - uchar *query_cache_query_get_key(const uchar *record, size_t *length, - my_bool not_used); - uchar *query_cache_table_get_key(const uchar *record, size_t *length, - my_bool not_used); + const uchar *query_cache_query_get_key(const void *record, size_t *length, + my_bool); + const uchar *query_cache_table_get_key(const void *record, size_t *length, + my_bool); } extern "C" void query_cache_invalidate_by_MyISAM_filename(const char* filename); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index de688b4cb31..73e182edd0f 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -89,15 +89,17 @@ const char * const THD::DEFAULT_WHERE= "field list"; ** User variables ****************************************************************************/ -extern "C" uchar *get_var_key(user_var_entry *entry, size_t *length, - my_bool not_used __attribute__((unused))) +extern "C" const uchar *get_var_key(const void *entry_, size_t *length, + my_bool) { + auto entry= static_cast(entry_); *length= entry->name.length; - return (uchar*) entry->name.str; + return reinterpret_cast(entry->name.str); } -extern "C" void free_user_var(user_var_entry *entry) +extern "C" void free_user_var(void *entry_) { + user_var_entry *entry= static_cast(entry_); char *pos= (char*) entry+ALIGN_SIZE(sizeof(*entry)); if (entry->value && entry->value != pos) my_free(entry->value); @@ -106,18 +108,17 @@ extern "C" void free_user_var(user_var_entry *entry) /* Functions for last-value-from-sequence hash */ -extern "C" uchar *get_sequence_last_key(SEQUENCE_LAST_VALUE *entry, - size_t *length, - my_bool not_used - __attribute__((unused))) +extern "C" const uchar *get_sequence_last_key(const void *entry_, + size_t *length, my_bool) { + auto *entry= static_cast(entry_); *length= entry->length; - return (uchar*) entry->key; + return entry->key; } -extern "C" void free_sequence_last(SEQUENCE_LAST_VALUE *entry) +extern "C" void free_sequence_last(void *entry) { - delete entry; + delete static_cast(entry); } @@ -621,8 +622,9 @@ handle_condition(THD *thd, timeouts at end of query (and thus before THD is destroyed) */ -extern "C" void thd_kill_timeout(THD* thd) +extern "C" void thd_kill_timeout(void *thd_) { + THD *thd= static_cast(thd_); thd->status_var.max_statement_time_exceeded++; /* Kill queries that can't cause data corruptions */ thd->awake(KILL_TIMEOUT); @@ -853,12 +855,11 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) #endif user_connect=(USER_CONN *)0; my_hash_init(key_memory_user_var_entry, &user_vars, system_charset_info, - USER_VARS_HASH_SIZE, 0, 0, (my_hash_get_key) get_var_key, - (my_hash_free_key) free_user_var, HASH_THREAD_SPECIFIC); - my_hash_init(PSI_INSTRUMENT_ME, &sequences, Lex_ident_fs::charset_info(), - SEQUENCES_HASH_SIZE, 0, 0, (my_hash_get_key) - get_sequence_last_key, (my_hash_free_key) free_sequence_last, + USER_VARS_HASH_SIZE, 0, 0, get_var_key, free_user_var, HASH_THREAD_SPECIFIC); + my_hash_init(PSI_INSTRUMENT_ME, &sequences, Lex_ident_fs::charset_info(), + SEQUENCES_HASH_SIZE, 0, 0, get_sequence_last_key, + free_sequence_last, HASH_THREAD_SPECIFIC); /* For user vars replication*/ if (opt_bin_log) @@ -1448,12 +1449,11 @@ void THD::change_user(void) init(); stmt_map.reset(); my_hash_init(key_memory_user_var_entry, &user_vars, system_charset_info, - USER_VARS_HASH_SIZE, 0, 0, (my_hash_get_key) get_var_key, - (my_hash_free_key) free_user_var, HASH_THREAD_SPECIFIC); + USER_VARS_HASH_SIZE, 0, 0, get_var_key, free_user_var, + HASH_THREAD_SPECIFIC); my_hash_init(key_memory_user_var_entry, &sequences, - Lex_ident_fs::charset_info(), - SEQUENCES_HASH_SIZE, 0, 0, (my_hash_get_key) - get_sequence_last_key, (my_hash_free_key) free_sequence_last, + Lex_ident_fs::charset_info(), SEQUENCES_HASH_SIZE, 0, 0, + get_sequence_last_key, free_sequence_last, HASH_THREAD_SPECIFIC); sp_caches_clear(); opt_trace.delete_traces(); @@ -4094,13 +4094,12 @@ Statement::~Statement() = default; C_MODE_START -static uchar * -get_statement_id_as_hash_key(const uchar *record, size_t *key_length, - my_bool not_used __attribute__((unused))) +static const uchar *get_statement_id_as_hash_key(const void *record, + size_t *key_length, my_bool) { - const Statement *statement= (const Statement *) record; + auto statement= static_cast(record); *key_length= sizeof(statement->id); - return (uchar *) &((const Statement *) statement)->id; + return reinterpret_cast(&(statement)->id); } static void delete_statement_as_hash_key(void *key) @@ -4108,11 +4107,12 @@ static void delete_statement_as_hash_key(void *key) delete (Statement *) key; } -static uchar *get_stmt_name_hash_key(Statement *entry, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *get_stmt_name_hash_key(const void *entry_, size_t *length, + my_bool) { + auto entry= static_cast(entry_); *length= entry->name.length; - return (uchar*) entry->name.str; + return reinterpret_cast(entry->name.str); } C_MODE_END @@ -4128,9 +4128,9 @@ Statement_map::Statement_map() : my_hash_init(key_memory_prepared_statement_map, &st_hash, &my_charset_bin, START_STMT_HASH_SIZE, 0, 0, get_statement_id_as_hash_key, delete_statement_as_hash_key, MYF(0)); - my_hash_init(key_memory_prepared_statement_map, &names_hash, system_charset_info, START_NAME_HASH_SIZE, 0, 0, - (my_hash_get_key) get_stmt_name_hash_key, - NULL, MYF(0)); + my_hash_init(key_memory_prepared_statement_map, &names_hash, + system_charset_info, START_NAME_HASH_SIZE, 0, 0, + get_stmt_name_hash_key, NULL, MYF(0)); } diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 825491cad44..f0ef6e730ba 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -305,17 +305,12 @@ end: started with corresponding variable that is greater then 0. */ -extern "C" uchar *get_key_conn(user_conn *buff, size_t *length, - my_bool not_used __attribute__((unused))) +extern "C" const uchar *get_key_conn(const void *buff_, size_t *length, + my_bool) { + auto buff= static_cast(buff_); *length= buff->len; - return (uchar*) buff->user; -} - - -extern "C" void free_user(struct user_conn *uc) -{ - my_free(uc); + return reinterpret_cast(buff->user); } @@ -323,8 +318,8 @@ void init_max_user_conn(void) { #ifndef NO_EMBEDDED_ACCESS_CHECKS my_hash_init(key_memory_user_conn, &hash_user_connections, - system_charset_info, max_connections, 0, 0, (my_hash_get_key) - get_key_conn, (my_hash_free_key) free_user, 0); + system_charset_info, max_connections, 0, 0, get_key_conn, + my_free, 0); #endif } @@ -403,16 +398,12 @@ static const char *get_client_host(THD *client) client->security_ctx->host ? client->security_ctx->host : ""; } -extern "C" uchar *get_key_user_stats(USER_STATS *user_stats, size_t *length, - my_bool not_used __attribute__((unused))) +extern "C" const uchar *get_key_user_stats(const void *user_stats_, + size_t *length, my_bool) { + auto user_stats= static_cast(user_stats_); *length= user_stats->user_name_length; - return (uchar*) user_stats->user; -} - -void free_user_stats(USER_STATS* user_stats) -{ - my_free(user_stats); + return reinterpret_cast(user_stats->user); } void init_user_stats(USER_STATS *user_stats, @@ -483,56 +474,44 @@ void init_user_stats(USER_STATS *user_stats, void init_global_user_stats(void) { - my_hash_init(PSI_INSTRUMENT_ME, &global_user_stats, system_charset_info, max_connections, - 0, 0, (my_hash_get_key) get_key_user_stats, - (my_hash_free_key) free_user_stats, 0); + my_hash_init(PSI_INSTRUMENT_ME, &global_user_stats, system_charset_info, + max_connections, 0, 0, get_key_user_stats, my_free, 0); } void init_global_client_stats(void) { - my_hash_init(PSI_INSTRUMENT_ME, &global_client_stats, system_charset_info, max_connections, - 0, 0, (my_hash_get_key) get_key_user_stats, - (my_hash_free_key) free_user_stats, 0); + my_hash_init(PSI_INSTRUMENT_ME, &global_client_stats, system_charset_info, + max_connections, 0, 0, get_key_user_stats, my_free, 0); } -extern "C" uchar *get_key_table_stats(TABLE_STATS *table_stats, size_t *length, - my_bool not_used __attribute__((unused))) +extern "C" const uchar *get_key_table_stats(const void *table_stats_, + size_t *length, my_bool) { + auto table_stats= static_cast(table_stats_); *length= table_stats->table_name_length; - return (uchar*) table_stats->table; -} - -extern "C" void free_table_stats(TABLE_STATS* table_stats) -{ - my_free(table_stats); + return reinterpret_cast(table_stats->table); } void init_global_table_stats(void) { my_hash_init(PSI_INSTRUMENT_ME, &global_table_stats, - Lex_ident_fs::charset_info(), - max_connections, 0, 0, (my_hash_get_key) get_key_table_stats, - (my_hash_free_key) free_table_stats, 0); + Lex_ident_fs::charset_info(), max_connections, 0, 0, + get_key_table_stats, my_free, 0); } -extern "C" uchar *get_key_index_stats(INDEX_STATS *index_stats, size_t *length, - my_bool not_used __attribute__((unused))) +extern "C" const uchar *get_key_index_stats(const void *index_stats_, + size_t *length, my_bool) { + auto index_stats= static_cast(index_stats_); *length= index_stats->index_name_length; - return (uchar*) index_stats->index; -} - -extern "C" void free_index_stats(INDEX_STATS* index_stats) -{ - my_free(index_stats); + return reinterpret_cast(index_stats->index); } void init_global_index_stats(void) { my_hash_init(PSI_INSTRUMENT_ME, &global_index_stats, - Lex_ident_fs::charset_info(), - max_connections, 0, 0, (my_hash_get_key) get_key_index_stats, - (my_hash_free_key) free_index_stats, 0); + Lex_ident_fs::charset_info(), max_connections, 0, 0, + get_key_index_stats, my_free, 0); } diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 63cd5c83d98..ff3bda951d8 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -109,14 +109,14 @@ cmp_db_names(LEX_CSTRING *db1_name, const LEX_CSTRING *db2_name) Function we use in the creation of our hash to get key. */ -extern "C" uchar* dboptions_get_key(my_dbopt_t *opt, size_t *length, - my_bool not_used); +extern "C" const uchar *dboptions_get_key(const void *opt, size_t *length, + my_bool); -uchar* dboptions_get_key(my_dbopt_t *opt, size_t *length, - my_bool not_used __attribute__((unused))) +const uchar *dboptions_get_key(const void *opt_, size_t *length, my_bool) { + auto opt= static_cast(opt_); *length= opt->name_length; - return (uchar*) opt->name; + return reinterpret_cast(opt->name); } @@ -187,8 +187,8 @@ bool my_dboptions_cache_init(void) { dboptions_init= 1; error= my_hash_init(key_memory_dboptions_hash, &dboptions, - table_alias_charset, 32, 0, 0, (my_hash_get_key) - dboptions_get_key, free_dbopt, 0); + table_alias_charset, 32, 0, 0, dboptions_get_key, + free_dbopt, 0); } return error; } @@ -219,7 +219,7 @@ void my_dbopt_cleanup(void) mysql_rwlock_wrlock(&LOCK_dboptions); my_hash_free(&dboptions); my_hash_init(key_memory_dboptions_hash, &dboptions, table_alias_charset, 32, - 0, 0, (my_hash_get_key) dboptions_get_key, free_dbopt, 0); + 0, 0, dboptions_get_key, free_dbopt, 0); mysql_rwlock_unlock(&LOCK_dboptions); } diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index c549f89b750..b1899e9969e 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -112,11 +112,12 @@ SQL_HANDLER::~SQL_HANDLER() Pointer to the TABLE_LIST struct. */ -static char *mysql_ha_hash_get_key(SQL_HANDLER *table, size_t *key_len, - my_bool first __attribute__((unused))) +static const uchar *mysql_ha_hash_get_key(const void *table_, size_t *key_len, + my_bool) { + auto table= static_cast(table_); *key_len= table->handler_name.length + 1 ; /* include '\0' in comparisons */ - return (char*) table->handler_name.str; + return reinterpret_cast(table->handler_name.str); } @@ -134,9 +135,9 @@ static char *mysql_ha_hash_get_key(SQL_HANDLER *table, size_t *key_len, Nothing */ -static void mysql_ha_hash_free(SQL_HANDLER *table) +static void mysql_ha_hash_free(void *table) { - delete table; + delete static_cast(table); } static void mysql_ha_close_childs(THD *thd, TABLE_LIST *current_table_list, @@ -291,8 +292,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) */ if (my_hash_init(key_memory_THD_handler_tables_hash, &thd->handler_tables_hash, &my_charset_latin1, - HANDLER_TABLES_HASH_SIZE, 0, 0, (my_hash_get_key) - mysql_ha_hash_get_key, (my_hash_free_key) + HANDLER_TABLES_HASH_SIZE, 0, 0, mysql_ha_hash_get_key, mysql_ha_hash_free, 0)) { DBUG_PRINT("exit",("ERROR")); diff --git a/sql/sql_hset.h b/sql/sql_hset.h index b3d8165f6f6..be7fd5b5be4 100644 --- a/sql/sql_hset.h +++ b/sql/sql_hset.h @@ -31,11 +31,12 @@ public: Constructs an empty hash. Does not allocate memory, it is done upon the first insert. Thus does not cause or return errors. */ - Hash_set(PSI_memory_key psi_key, uchar *(*K)(const T *, size_t *, my_bool), + Hash_set(PSI_memory_key psi_key, + const uchar *(*K)(const void *, size_t *, my_bool), CHARSET_INFO *cs= &my_charset_bin) { my_hash_clear(&m_hash); - m_hash.get_key= (my_hash_get_key)K; + m_hash.get_key= K; m_hash.charset= cs; m_hash.array.m_psi_key= psi_key; } diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 5f58c6707b7..624a4fa2e9b 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1513,25 +1513,23 @@ static int plugin_initialize(MEM_ROOT *tmp_root, struct st_plugin_int *plugin, } -extern "C" uchar *get_plugin_hash_key(const uchar *, size_t *, my_bool); -extern "C" uchar *get_bookmark_hash_key(const uchar *, size_t *, my_bool); +extern "C" const uchar *get_plugin_hash_key(const void *, size_t *, my_bool); +extern "C" const uchar *get_bookmark_hash_key(const void *, size_t *, my_bool); -uchar *get_plugin_hash_key(const uchar *buff, size_t *length, - my_bool not_used __attribute__((unused))) +const uchar *get_plugin_hash_key(const void *buff, size_t *length, my_bool) { - struct st_plugin_int *plugin= (st_plugin_int *)buff; - *length= (uint)plugin->name.length; - return((uchar *)plugin->name.str); + auto plugin= static_cast(buff); + *length= plugin->name.length; + return reinterpret_cast(plugin->name.str); } -uchar *get_bookmark_hash_key(const uchar *buff, size_t *length, - my_bool not_used __attribute__((unused))) +const uchar *get_bookmark_hash_key(const void *buff, size_t *length, my_bool) { - struct st_bookmark *var= (st_bookmark *)buff; + auto var= static_cast(buff); *length= var->name_len + 1; - return (uchar*) var->key; + return reinterpret_cast(var->key); } static inline void convert_dash_to_underscore(char *str, size_t len) diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index 6e59feddc3b..8350b9dba9b 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -81,16 +81,17 @@ static int update_server_record_in_cache(FOREIGN_SERVER *existing, /* utility functions */ static void merge_server_struct(FOREIGN_SERVER *from, FOREIGN_SERVER *to); -static uchar *servers_cache_get_key(FOREIGN_SERVER *server, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *servers_cache_get_key(const void *server_, size_t *length, + my_bool) { + auto server= static_cast(server_); DBUG_ENTER("servers_cache_get_key"); DBUG_PRINT("info", ("server_name_length %zd server_name %s", server->server_name_length, server->server_name)); - *length= (uint) server->server_name_length; - DBUG_RETURN((uchar*) server->server_name); + *length= server->server_name_length; + DBUG_RETURN(reinterpret_cast(server->server_name)); } static PSI_memory_key key_memory_servers; @@ -232,8 +233,8 @@ bool servers_init(bool dont_read_servers_table) DBUG_RETURN(TRUE); /* initialise our servers cache */ - if (my_hash_init(key_memory_servers, &servers_cache, system_charset_info, 32, 0, 0, - (my_hash_get_key) servers_cache_get_key, 0, 0)) + if (my_hash_init(key_memory_servers, &servers_cache, system_charset_info, 32, + 0, 0, servers_cache_get_key, 0, 0)) { return_val= TRUE; /* we failed, out of memory? */ goto end; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index e8b4bc5e447..aafaf3b6a41 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -609,14 +609,13 @@ ignore_db_dirs_init() @return a pointer to the key */ -static uchar * -db_dirs_hash_get_key(const uchar *data, size_t *len_ret, - my_bool __attribute__((unused))) +static const uchar *db_dirs_hash_get_key(const void *data, size_t *len_ret, + my_bool) { - LEX_CSTRING *e= (LEX_CSTRING *) data; + auto e= static_cast(data); *len_ret= e->length; - return (uchar *) e->str; + return reinterpret_cast(e->str); } diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index f5eab105335..98a42b480c8 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -104,12 +104,11 @@ static const char *init_syms(udf_func *tmp, char *nm) } -extern "C" uchar* get_hash_key(const uchar *buff, size_t *length, - my_bool not_used __attribute__((unused))) +extern "C" const uchar *get_hash_key(const void *buff, size_t *length, my_bool) { - udf_func *udf=(udf_func*) buff; - *length=(uint) udf->name.length; - return (uchar*) udf->name.str; + auto udf= static_cast(buff); + *length= udf->name.length; + return reinterpret_cast(udf->name.str); } static PSI_memory_key key_memory_udf_mem; diff --git a/sql/table.cc b/sql/table.cc index df85f63ad92..b333cd040f6 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -241,11 +241,11 @@ View_creation_ctx * View_creation_ctx::create(THD *thd, /* Get column name from column hash */ -static uchar *get_field_name(Field **buff, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *get_field_name(const void *buff_, size_t *length, my_bool) { - *length= (uint) (*buff)->field_name.length; - return (uchar*) (*buff)->field_name.str; + auto buff= static_cast(buff_); + *length= (*buff)->field_name.length; + return reinterpret_cast((*buff)->field_name.str); } @@ -2251,7 +2251,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, if (use_hash) use_hash= !my_hash_init(PSI_INSTRUMENT_ME, &share->name_hash, system_charset_info, share->fields, 0, 0, - (my_hash_get_key) get_field_name, 0, 0); + get_field_name, 0, 0); if (share->mysql_version >= 50700 && share->mysql_version < 100000 && vcol_screen_length) diff --git a/sql/table_cache.cc b/sql/table_cache.cc index f073dd1ec87..93c6edcc2e7 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -578,12 +578,11 @@ static void tdc_hash_initializer(LF_HASH *, } -static uchar *tdc_hash_key(const unsigned char *_element, size_t *length, - my_bool) +static const uchar *tdc_hash_key(const void *element_, size_t *length, my_bool) { - const TDC_element *element= (const TDC_element *) _element; + auto element= static_cast(element_); *length= element->m_key_length; - return (uchar*) element->m_key; + return reinterpret_cast(element->m_key); } @@ -604,14 +603,13 @@ bool tdc_init(void) tdc_inited= true; mysql_mutex_init(key_LOCK_unused_shares, &LOCK_unused_shares, MY_MUTEX_INIT_FAST); - lf_hash_init(&tdc_hash, sizeof(TDC_element) + - sizeof(Share_free_tables) * (tc_instances - 1), - LF_HASH_UNIQUE, 0, 0, - (my_hash_get_key) tdc_hash_key, - &my_charset_bin); + lf_hash_init(&tdc_hash, + sizeof(TDC_element) + + sizeof(Share_free_tables) * (tc_instances - 1), + LF_HASH_UNIQUE, 0, 0, tdc_hash_key, &my_charset_bin); tdc_hash.alloc.constructor= lf_alloc_constructor; tdc_hash.alloc.destructor= lf_alloc_destructor; - tdc_hash.initializer= (lf_hash_initializer) tdc_hash_initializer; + tdc_hash.initializer= tdc_hash_initializer; DBUG_RETURN(false); } @@ -1125,12 +1123,12 @@ struct eliminate_duplicates_arg }; -static uchar *eliminate_duplicates_get_key(const uchar *element, size_t *length, - my_bool) +static const uchar *eliminate_duplicates_get_key(const void *element, + size_t *length, my_bool) { - LEX_STRING *key= (LEX_STRING *) element; + auto key= static_cast(element); *length= key->length; - return (uchar *) key->str; + return reinterpret_cast(key->str); } diff --git a/sql/tztime.cc b/sql/tztime.cc index b8f3846a06c..7edaff1d738 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1498,21 +1498,20 @@ public: they should obey C calling conventions. */ -extern "C" uchar * -my_tz_names_get_key(Tz_names_entry *entry, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *my_tz_names_get_key(const void *entry_, size_t *length, + my_bool) { + auto entry= static_cast(entry_); *length= entry->name.length(); - return (uchar*) entry->name.ptr(); + return reinterpret_cast(entry->name.ptr()); } -extern "C" uchar * -my_offset_tzs_get_key(Time_zone_offset *entry, - size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *my_offset_tzs_get_key(const void *entry_, + size_t *length, my_bool) { + auto entry= static_cast(entry_); *length= sizeof(long); - return (uchar*) &entry->offset; + return reinterpret_cast(&entry->offset); } @@ -1626,13 +1625,13 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) /* Init all memory structures that require explicit destruction */ if (my_hash_init(key_memory_tz_storage, &tz_names, &my_charset_latin1, 20, 0, - 0, (my_hash_get_key) my_tz_names_get_key, 0, 0)) + 0, my_tz_names_get_key, 0, 0)) { sql_print_error("Fatal error: OOM while initializing time zones"); goto end; } if (my_hash_init(key_memory_tz_storage, &offset_tzs, &my_charset_latin1, 26, - 0, 0, (my_hash_get_key)my_offset_tzs_get_key, 0, 0)) + 0, 0, my_offset_tzs_get_key, 0, 0)) { sql_print_error("Fatal error: OOM while initializing time zones"); my_hash_free(&tz_names); diff --git a/sql/xa.cc b/sql/xa.cc index 972121a1ee7..0b9c849d377 100644 --- a/sql/xa.cc +++ b/sql/xa.cc @@ -147,7 +147,7 @@ public: DBUG_ASSERT(!reinterpret_cast(ptr + LF_HASH_OVERHEAD) ->is_set(ACQUIRED)); } - static uchar *key(const unsigned char *el, size_t *length, my_bool) + static const uchar *key(const void *el, size_t *length, my_bool) { const XID &xid= reinterpret_cast(el)->xid; *length= xid.key_length(); diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc index 0134032351e..2477d81a872 100644 --- a/storage/blackhole/ha_blackhole.cc +++ b/storage/blackhole/ha_blackhole.cc @@ -354,17 +354,18 @@ static void free_share(st_blackhole_share *share) mysql_mutex_unlock(&blackhole_mutex); } -static void blackhole_free_key(st_blackhole_share *share) +static void blackhole_free_key(void *share) { - thr_lock_delete(&share->lock); + thr_lock_delete(&static_cast(share)->lock); my_free(share); } -static uchar* blackhole_get_key(st_blackhole_share *share, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *blackhole_get_key(const void *share_, size_t *length, + my_bool) { + auto share= static_cast(share_); *length= share->table_name_length; - return (uchar*) share->table_name; + return reinterpret_cast(share->table_name); } #ifdef HAVE_PSI_INTERFACE @@ -405,9 +406,8 @@ static int blackhole_init(void *p) mysql_mutex_init(bh_key_mutex_blackhole, &blackhole_mutex, MY_MUTEX_INIT_FAST); (void) my_hash_init(PSI_INSTRUMENT_ME, &blackhole_open_tables, - system_charset_info, 32, 0, 0, - (my_hash_get_key) blackhole_get_key, - (my_hash_free_key) blackhole_free_key, 0); + system_charset_info, 32, 0, 0, blackhole_get_key, + blackhole_free_key, 0); return 0; } diff --git a/storage/cassandra/ha_cassandra.cc b/storage/cassandra/ha_cassandra.cc index 54812b51db5..d6a060bb721 100644 --- a/storage/cassandra/ha_cassandra.cc +++ b/storage/cassandra/ha_cassandra.cc @@ -203,11 +203,12 @@ Cassandra_status_vars cassandra_counters; Function we use in the creation of our hash to get key. */ -static uchar* cassandra_get_key(CASSANDRA_SHARE *share, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *cassandra_get_key(const void *share_, size_t *length, + my_bool) { + auto share= static_cast(share_); *length=share->table_name_length; - return (uchar*) share->table_name; + return reinterpret_cast(share->table_name); } #ifdef HAVE_PSI_INTERFACE @@ -242,8 +243,8 @@ static int cassandra_init_func(void *p) cassandra_hton= (handlerton *)p; mysql_mutex_init(ex_key_mutex_example, &cassandra_mutex, MY_MUTEX_INIT_FAST); - (void) my_hash_init(PSI_INSTRUMENT_ME, &cassandra_open_tables,system_charset_info,32,0,0, - (my_hash_get_key) cassandra_get_key,0,0); + (void) my_hash_init(PSI_INSTRUMENT_ME, &cassandra_open_tables, + system_charset_info, 32, 0, 0, cassandra_get_key, 0, 0); cassandra_hton->create= cassandra_create_handler; /* diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index 7a41b3affdc..ef7865b366c 100644 --- a/storage/csv/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -107,11 +107,11 @@ int sort_set (const void *a_, const void *b_) return ( a->begin > b->begin ? 1 : ( a->begin < b->begin ? -1 : 0 ) ); } -static uchar* tina_get_key(TINA_SHARE *share, size_t *length, - my_bool not_used __attribute__((unused))) +static const uchar *tina_get_key(const void *share_, size_t *length, my_bool) { + const TINA_SHARE *share= static_cast(share_); *length=share->table_name_length; - return (uchar*) share->table_name; + return reinterpret_cast(share->table_name); } static PSI_memory_key csv_key_memory_tina_share; @@ -186,9 +186,8 @@ static int tina_init_func(void *p) tina_hton= (handlerton *)p; mysql_mutex_init(csv_key_mutex_tina, &tina_mutex, MY_MUTEX_INIT_FAST); (void) my_hash_init(csv_key_memory_tina_share, &tina_open_tables, - Lex_ident_table::charset_info(), - 32, 0, 0, (my_hash_get_key) - tina_get_key, 0, 0); + Lex_ident_table::charset_info(), 32, 0, 0, tina_get_key, + 0, 0); tina_hton->db_type= DB_TYPE_CSV_DB; tina_hton->create= tina_create_handler; tina_hton->flags= (HTON_CAN_RECREATE | HTON_SUPPORT_LOG_TABLES | diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc index 37d518eaaf1..1570a0af1f6 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -430,11 +430,12 @@ static handler *federated_create_handler(handlerton *hton, /* Function we use in the creation of our hash to get key */ -static uchar *federated_get_key(FEDERATED_SHARE *share, size_t *length, - my_bool not_used __attribute__ ((unused))) +static const uchar *federated_get_key(const void *share_, size_t *length, + my_bool) { + auto share= static_cast(share_); *length= share->share_key_length; - return (uchar*) share->share_key; + return reinterpret_cast(share->share_key); } #ifdef HAVE_PSI_INTERFACE @@ -498,7 +499,7 @@ int federated_db_init(void *p) &federated_mutex, MY_MUTEX_INIT_FAST)) goto error; if (!my_hash_init(PSI_INSTRUMENT_ME, &federated_open_tables, &my_charset_bin, - 32, 0, 0, (my_hash_get_key) federated_get_key, 0, 0)) + 32, 0, 0, federated_get_key, 0, 0)) { DBUG_RETURN(FALSE); } diff --git a/storage/federatedx/ha_federatedx.cc b/storage/federatedx/ha_federatedx.cc index 6c476661c1d..4653692b7b0 100644 --- a/storage/federatedx/ha_federatedx.cc +++ b/storage/federatedx/ha_federatedx.cc @@ -363,21 +363,20 @@ static handler *federatedx_create_handler(handlerton *hton, /* Function we use in the creation of our hash to get key */ -static uchar * -federatedx_share_get_key(FEDERATEDX_SHARE *share, size_t *length, - my_bool not_used __attribute__ ((unused))) +static const uchar *federatedx_share_get_key(const void *share_, + size_t *length, my_bool) { + auto share= static_cast(share_); *length= share->share_key_length; - return (uchar*) share->share_key; + return reinterpret_cast(share->share_key); } - -static uchar * -federatedx_server_get_key(FEDERATEDX_SERVER *server, size_t *length, - my_bool not_used __attribute__ ((unused))) +static const uchar *federatedx_server_get_key(const void *server_, + size_t *length, my_bool) { + auto server= static_cast(server_); *length= server->key_length; - return server->key; + return reinterpret_cast(server->key); } #ifdef HAVE_PSI_INTERFACE @@ -447,10 +446,12 @@ int federatedx_db_init(void *p) if (mysql_mutex_init(fe_key_mutex_federatedx, &federatedx_mutex, MY_MUTEX_INIT_FAST)) goto error; - if (!my_hash_init(PSI_INSTRUMENT_ME, &federatedx_open_tables, &my_charset_bin, 32, 0, 0, - (my_hash_get_key) federatedx_share_get_key, 0, 0) && - !my_hash_init(PSI_INSTRUMENT_ME, &federatedx_open_servers, &my_charset_bin, 32, 0, 0, - (my_hash_get_key) federatedx_server_get_key, 0, 0)) + if (!my_hash_init(PSI_INSTRUMENT_ME, &federatedx_open_tables, + &my_charset_bin, 32, 0, 0, federatedx_share_get_key, 0, + 0) && + !my_hash_init(PSI_INSTRUMENT_ME, &federatedx_open_servers, + &my_charset_bin, 32, 0, 0, federatedx_server_get_key, 0, + 0)) { DBUG_RETURN(FALSE); } diff --git a/storage/maria/aria_read_log.c b/storage/maria/aria_read_log.c index 51bfa879702..eeec5370df2 100644 --- a/storage/maria/aria_read_log.c +++ b/storage/maria/aria_read_log.c @@ -333,11 +333,12 @@ static void usage(void) } -static uchar* my_hash_get_string(const uchar *record, size_t *length, - my_bool first __attribute__ ((unused))) +static const uchar *my_hash_get_string(const void *record_, size_t *length, + my_bool first __attribute__((unused))) { - *length= (size_t) (strcend((const char*) record,',')- (const char*) record); - return (uchar*) record; + const char *record= record_; + *length= (strcend(record, ',') - record); + return record_; } diff --git a/storage/maria/ma_init.c b/storage/maria/ma_init.c index 029ce4b9128..65beb345b2b 100644 --- a/storage/maria/ma_init.c +++ b/storage/maria/ma_init.c @@ -22,8 +22,9 @@ #include "ma_checkpoint.h" #include -void history_state_free(MARIA_STATE_HISTORY_CLOSED *closed_history) +void history_state_free(void *closed_history_) { + MARIA_STATE_HISTORY_CLOSED *closed_history= closed_history_; MARIA_STATE_HISTORY *history, *next; /* @@ -72,7 +73,7 @@ int maria_init(void) maria_create_trn_hook= dummy_maria_create_trn_hook; } my_hash_init(PSI_INSTRUMENT_ME, &maria_stored_state, &my_charset_bin, 32, 0, - sizeof(LSN), 0, (my_hash_free_key) history_state_free, 0); + sizeof(LSN), 0, history_state_free, 0); DBUG_PRINT("info",("dummy_transaction_object: %p", &dummy_transaction_object)); return 0; } diff --git a/storage/maria/trnman.c b/storage/maria/trnman.c index 56f6c52b2f5..1a8c193d970 100644 --- a/storage/maria/trnman.c +++ b/storage/maria/trnman.c @@ -126,11 +126,12 @@ default_trnman_end_trans_hook(TRN *trn __attribute__ ((unused)), } -static uchar *trn_get_hash_key(const uchar *trn, size_t *len, - my_bool unused __attribute__ ((unused))) +static const uchar *trn_get_hash_key(const void *trn_, size_t *len, + my_bool unused __attribute__((unused))) { + const TRN *const *trn= trn_; *len= sizeof(TrID); - return (uchar *) & ((*((TRN **)trn))->trid); + return (const uchar *) &((*trn)->trid); } diff --git a/storage/mroonga/ha_mroonga.cpp b/storage/mroonga/ha_mroonga.cpp index 442146fae95..38e139ac0db 100644 --- a/storage/mroonga/ha_mroonga.cpp +++ b/storage/mroonga/ha_mroonga.cpp @@ -597,25 +597,22 @@ static const char *mrn_inspect_extra_function(enum ha_extra_function operation) } #endif -static uchar *mrn_open_tables_get_key(const uchar *record, - size_t *length, - my_bool not_used __attribute__ ((unused))) +static const uchar *mrn_open_tables_get_key(const void *record, size_t *length, + my_bool) { MRN_DBUG_ENTER_FUNCTION(); - MRN_SHARE *share = reinterpret_cast(const_cast(record)); + auto share = static_cast(record); *length = share->table_name_length; - DBUG_RETURN(reinterpret_cast(share->table_name)); + DBUG_RETURN(reinterpret_cast(share->table_name)); } -static uchar *mrn_long_term_share_get_key(const uchar *record, - size_t *length, - my_bool not_used __attribute__ ((unused))) +static const uchar *mrn_long_term_share_get_key(const void *record, + size_t *length, my_bool) { MRN_DBUG_ENTER_FUNCTION(); - MRN_LONG_TERM_SHARE *long_term_share = - reinterpret_cast(const_cast(record)); + auto long_term_share= static_cast(record); *length = long_term_share->table_name_length; - DBUG_RETURN(reinterpret_cast(long_term_share->table_name)); + DBUG_RETURN(reinterpret_cast(long_term_share->table_name)); } /* status */ @@ -693,13 +690,12 @@ static grn_logger mrn_logger = { NULL }; -static uchar *mrn_allocated_thds_get_key(const uchar *record, - size_t *length, - my_bool not_used __attribute__ ((unused))) +static const uchar *mrn_allocated_thds_get_key(const void *record, + size_t *length, my_bool) { MRN_DBUG_ENTER_FUNCTION(); *length = sizeof(THD *); - DBUG_RETURN(const_cast(record)); + DBUG_RETURN(static_cast(record)); } /* system functions */ diff --git a/storage/perfschema/pfs_account.cc b/storage/perfschema/pfs_account.cc index 84257d9dc38..2a877836649 100644 --- a/storage/perfschema/pfs_account.cc +++ b/storage/perfschema/pfs_account.cc @@ -67,19 +67,19 @@ void cleanup_account(void) } C_MODE_START -static uchar *account_hash_get_key(const uchar *entry, size_t *length, - my_bool) +static const uchar *account_hash_get_key(const void *entry, size_t *length, + my_bool) { const PFS_account * const *typed_entry; const PFS_account *account; const void *result; - typed_entry= reinterpret_cast (entry); + typed_entry= static_cast (entry); assert(typed_entry != NULL); account= *typed_entry; assert(account != NULL); *length= account->m_key.m_key_length; result= account->m_key.m_hash_key; - return const_cast (reinterpret_cast (result)); + return reinterpret_cast(result); } C_MODE_END diff --git a/storage/perfschema/pfs_digest.cc b/storage/perfschema/pfs_digest.cc index 46a97534bb2..f6c89d6e1dd 100644 --- a/storage/perfschema/pfs_digest.cc +++ b/storage/perfschema/pfs_digest.cc @@ -145,19 +145,19 @@ void cleanup_digest(void) } C_MODE_START -static uchar *digest_hash_get_key(const uchar *entry, size_t *length, - my_bool) +static const uchar *digest_hash_get_key(const void *entry, size_t *length, + my_bool) { const PFS_statements_digest_stat * const *typed_entry; const PFS_statements_digest_stat *digest; const void *result; - typed_entry= reinterpret_cast(entry); + typed_entry= static_cast(entry); assert(typed_entry != NULL); digest= *typed_entry; assert(digest != NULL); *length= sizeof (PFS_digest_key); result= & digest->m_digest_key; - return const_cast (reinterpret_cast (result)); + return reinterpret_cast(result); } C_MODE_END diff --git a/storage/perfschema/pfs_host.cc b/storage/perfschema/pfs_host.cc index 9012d01004c..a0c02c2ff2f 100644 --- a/storage/perfschema/pfs_host.cc +++ b/storage/perfschema/pfs_host.cc @@ -64,19 +64,19 @@ void cleanup_host(void) } C_MODE_START -static uchar *host_hash_get_key(const uchar *entry, size_t *length, - my_bool) +static const uchar *host_hash_get_key(const void *entry, size_t *length, + my_bool) { const PFS_host * const *typed_entry; const PFS_host *host; const void *result; - typed_entry= reinterpret_cast (entry); + typed_entry= static_cast (entry); assert(typed_entry != NULL); host= *typed_entry; assert(host != NULL); *length= host->m_key.m_key_length; result= host->m_key.m_hash_key; - return const_cast (reinterpret_cast (result)); + return reinterpret_cast(result); } C_MODE_END diff --git a/storage/perfschema/pfs_instr.cc b/storage/perfschema/pfs_instr.cc index 9e2d0a81f13..3eb025c78cb 100644 --- a/storage/perfschema/pfs_instr.cc +++ b/storage/perfschema/pfs_instr.cc @@ -252,19 +252,19 @@ void cleanup_instruments(void) C_MODE_START /** Get hash table key for instrumented files. */ -static uchar *filename_hash_get_key(const uchar *entry, size_t *length, - my_bool) +static const uchar *filename_hash_get_key(const void *entry, size_t *length, + my_bool) { const PFS_file * const *typed_entry; const PFS_file *file; const void *result; - typed_entry= reinterpret_cast (entry); + typed_entry= static_cast (entry); assert(typed_entry != NULL); file= *typed_entry; assert(file != NULL); *length= file->m_filename_length; result= file->m_filename; - return const_cast (reinterpret_cast (result)); + return reinterpret_cast(result); } C_MODE_END diff --git a/storage/perfschema/pfs_instr_class.cc b/storage/perfschema/pfs_instr_class.cc index 49aa73f078a..86cc6365c31 100644 --- a/storage/perfschema/pfs_instr_class.cc +++ b/storage/perfschema/pfs_instr_class.cc @@ -403,19 +403,19 @@ void cleanup_table_share(void) C_MODE_START /** get_key function for @c table_share_hash. */ -static uchar *table_share_hash_get_key(const uchar *entry, size_t *length, - my_bool) +static const uchar *table_share_hash_get_key(const void *entry, size_t *length, + my_bool) { const PFS_table_share * const *typed_entry; const PFS_table_share *share; const void *result; - typed_entry= reinterpret_cast (entry); + typed_entry= static_cast (entry); assert(typed_entry != NULL); share= *typed_entry; assert(share != NULL); *length= share->m_key.m_key_length; result= &share->m_key.m_hash_key[0]; - return const_cast (reinterpret_cast (result)); + return reinterpret_cast(result); } C_MODE_END diff --git a/storage/perfschema/pfs_program.cc b/storage/perfschema/pfs_program.cc index de456610519..20b0aaa8489 100644 --- a/storage/perfschema/pfs_program.cc +++ b/storage/perfschema/pfs_program.cc @@ -63,19 +63,19 @@ void cleanup_program(void) } C_MODE_START -static uchar *program_hash_get_key(const uchar *entry, size_t *length, - my_bool) +static const uchar *program_hash_get_key(const void *entry, size_t *length, + my_bool) { const PFS_program * const *typed_entry; const PFS_program *program; const void *result; - typed_entry= reinterpret_cast (entry); + typed_entry= static_cast (entry); assert(typed_entry != NULL); program= *typed_entry; assert(program != NULL); *length= program->m_key.m_key_length; result= program->m_key.m_hash_key; - return const_cast (reinterpret_cast (result)); + return reinterpret_cast(result); } C_MODE_END diff --git a/storage/perfschema/pfs_setup_actor.cc b/storage/perfschema/pfs_setup_actor.cc index c2b53bf2d1e..638b2e5648d 100644 --- a/storage/perfschema/pfs_setup_actor.cc +++ b/storage/perfschema/pfs_setup_actor.cc @@ -63,19 +63,19 @@ void cleanup_setup_actor(void) } C_MODE_START -static uchar *setup_actor_hash_get_key(const uchar *entry, size_t *length, - my_bool) +static const uchar *setup_actor_hash_get_key(const void *entry, size_t *length, + my_bool) { const PFS_setup_actor * const *typed_entry; const PFS_setup_actor *setup_actor; const void *result; - typed_entry= reinterpret_cast (entry); + typed_entry= static_cast (entry); assert(typed_entry != NULL); setup_actor= *typed_entry; assert(setup_actor != NULL); *length= setup_actor->m_key.m_key_length; result= setup_actor->m_key.m_hash_key; - return const_cast (reinterpret_cast (result)); + return reinterpret_cast(result); } C_MODE_END diff --git a/storage/perfschema/pfs_setup_object.cc b/storage/perfschema/pfs_setup_object.cc index b18bc2fd5ba..a961c51d0e9 100644 --- a/storage/perfschema/pfs_setup_object.cc +++ b/storage/perfschema/pfs_setup_object.cc @@ -63,19 +63,19 @@ void cleanup_setup_object(void) } C_MODE_START -static uchar *setup_object_hash_get_key(const uchar *entry, size_t *length, - my_bool) +static const uchar *setup_object_hash_get_key(const void *entry, + size_t *length, my_bool) { const PFS_setup_object * const *typed_entry; const PFS_setup_object *setup_object; const void *result; - typed_entry= reinterpret_cast (entry); + typed_entry= static_cast (entry); assert(typed_entry != NULL); setup_object= *typed_entry; assert(setup_object != NULL); *length= setup_object->m_key.m_key_length; result= setup_object->m_key.m_hash_key; - return const_cast (reinterpret_cast (result)); + return reinterpret_cast(result); } C_MODE_END diff --git a/storage/perfschema/pfs_user.cc b/storage/perfschema/pfs_user.cc index fa39b330f75..d83ee52a77d 100644 --- a/storage/perfschema/pfs_user.cc +++ b/storage/perfschema/pfs_user.cc @@ -64,19 +64,19 @@ void cleanup_user(void) } C_MODE_START -static uchar *user_hash_get_key(const uchar *entry, size_t *length, - my_bool) +static const uchar *user_hash_get_key(const void *entry, size_t *length, + my_bool) { const PFS_user * const *typed_entry; const PFS_user *user; const void *result; - typed_entry= reinterpret_cast (entry); + typed_entry= static_cast (entry); assert(typed_entry != NULL); user= *typed_entry; assert(user != NULL); *length= user->m_key.m_key_length; result= user->m_key.m_hash_key; - return const_cast (reinterpret_cast (result)); + return reinterpret_cast(result); } C_MODE_END diff --git a/storage/sphinx/ha_sphinx.cc b/storage/sphinx/ha_sphinx.cc index 6bc6e274d00..0b63b2bb8a4 100644 --- a/storage/sphinx/ha_sphinx.cc +++ b/storage/sphinx/ha_sphinx.cc @@ -720,11 +720,12 @@ typedef size_t GetKeyLength_t; typedef uint GetKeyLength_t; #endif -static byte * sphinx_get_key ( const byte * pSharePtr, GetKeyLength_t * pLength, my_bool ) +static const uchar *sphinx_get_key(const void *pSharePtr, + GetKeyLength_t *pLength, my_bool) { - CSphSEShare * pShare = (CSphSEShare *) pSharePtr; - *pLength = (size_t) pShare->m_iTableNameLen; - return (byte*) pShare->m_sTable; + const CSphSEShare *pShare= static_cast(pSharePtr); + *pLength= pShare->m_iTableNameLen; + return reinterpret_cast(pShare->m_sTable); } #if MYSQL_VERSION_ID<50100 diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index 356d324cd1f..2faeba56b23 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -104,49 +104,53 @@ ulong spider_open_connections_line_no; pthread_mutex_t spider_conn_mutex; /* for spider_open_connections and trx_conn_hash */ -uchar *spider_conn_get_key( - SPIDER_CONN *conn, +const uchar *spider_conn_get_key( + const void *conn_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto conn= static_cast(conn_); DBUG_ENTER("spider_conn_get_key"); *length = conn->conn_key_length; DBUG_PRINT("info",("spider conn_kind=%u", conn->conn_kind)); #ifdef DBUG_TRACE spider_print_keys(conn->conn_key, conn->conn_key_length); #endif - DBUG_RETURN((uchar*) conn->conn_key); + DBUG_RETURN(reinterpret_cast(conn->conn_key)); } -uchar *spider_ipport_conn_get_key( - SPIDER_IP_PORT_CONN *ip_port, +const uchar *spider_ipport_conn_get_key( + const void *ip_port_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto ip_port= static_cast(ip_port_); DBUG_ENTER("spider_ipport_conn_get_key"); *length = ip_port->key_len; - DBUG_RETURN((uchar*) ip_port->key); + DBUG_RETURN(reinterpret_cast(ip_port->key)); } -static uchar *spider_loop_check_full_get_key( - SPIDER_CONN_LOOP_CHECK *ptr, +static const uchar *spider_loop_check_full_get_key( + const void *ptr_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto ptr= static_cast(ptr_); DBUG_ENTER("spider_loop_check_full_get_key"); *length = ptr->full_name.length; - DBUG_RETURN((uchar*) ptr->full_name.str); + DBUG_RETURN(reinterpret_cast(ptr->full_name.str)); } -static uchar *spider_loop_check_to_get_key( - SPIDER_CONN_LOOP_CHECK *ptr, +static const uchar *spider_loop_check_to_get_key( + const void *ptr_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto ptr= static_cast(ptr_); DBUG_ENTER("spider_loop_check_to_get_key"); *length = ptr->to_name.length; - DBUG_RETURN((uchar*) ptr->to_name.str); + DBUG_RETURN(reinterpret_cast(ptr->to_name.str)); } int spider_conn_init( @@ -159,10 +163,10 @@ int spider_conn_init( { goto error_loop_check_mutex_init; } - if ( - my_hash_init(PSI_INSTRUMENT_ME, &conn->loop_checked, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_loop_check_full_get_key, 0, 0) - ) { + if (my_hash_init(PSI_INSTRUMENT_ME, &conn->loop_checked, + spd_charset_utf8mb3_bin, 32, 0, 0, + spider_loop_check_full_get_key, 0, 0)) + { goto error_loop_checked_hash_init; } spider_alloc_calc_mem_init(conn->loop_checked, SPD_MID_CONN_INIT_1); @@ -170,10 +174,10 @@ int spider_conn_init( conn->loop_checked, conn->loop_checked.array.max_element * conn->loop_checked.array.size_of_element); - if ( - my_hash_init(PSI_INSTRUMENT_ME, &conn->loop_check_queue, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_loop_check_to_get_key, 0, 0) - ) { + if (my_hash_init(PSI_INSTRUMENT_ME, &conn->loop_check_queue, + spd_charset_utf8mb3_bin, 32, 0, 0, + spider_loop_check_to_get_key, 0, 0)) + { goto error_loop_check_queue_hash_init; } spider_alloc_calc_mem_init(conn->loop_check_queue, SPD_MID_CONN_INIT_2); diff --git a/storage/spider/spd_conn.h b/storage/spider/spd_conn.h index 59802b00712..ba02178a608 100644 --- a/storage/spider/spd_conn.h +++ b/storage/spider/spd_conn.h @@ -82,16 +82,16 @@ typedef struct st_spider_conn_loop_check LEX_CSTRING merged_value; } SPIDER_CONN_LOOP_CHECK; -uchar *spider_conn_get_key( - SPIDER_CONN *conn, +const uchar *spider_conn_get_key( + const void *conn, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ); -uchar *spider_ipport_conn_get_key( - SPIDER_IP_PORT_CONN *ip_port, +const uchar *spider_ipport_conn_get_key( + const void *ip_port, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ); int spider_conn_init( diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 0c9b3fa6234..0cb4b657a2b 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -1853,10 +1853,10 @@ int spider_db_mbase::init() { DBUG_ENTER("spider_db_mbase::init"); DBUG_PRINT("info",("spider this=%p", this)); - if ( - my_hash_init(PSI_INSTRUMENT_ME, &lock_table_hash, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_link_get_key, 0, 0) - ) { + if (my_hash_init(PSI_INSTRUMENT_ME, &lock_table_hash, + spd_charset_utf8mb3_bin, 32, 0, 0, spider_link_get_key, 0, + 0)) + { DBUG_RETURN(HA_ERR_OUT_OF_MEM); } spider_alloc_calc_mem_init(lock_table_hash, SPD_MID_DB_MBASE_INIT_1); diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index 5f037659473..9a4924c42d1 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -376,76 +376,73 @@ static char spider_unique_id_buf[1 + 12 + 1 + (16 * 2) + 1 + 1]; LEX_CSTRING spider_unique_id; // for spider_open_tables -uchar *spider_tbl_get_key( - SPIDER_SHARE *share, +const uchar *spider_tbl_get_key( + const void *share_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto share= static_cast(share_); DBUG_ENTER("spider_tbl_get_key"); *length = share->table_name_length; - DBUG_RETURN((uchar*) share->table_name); + DBUG_RETURN(reinterpret_cast(share->table_name)); } -uchar *spider_wide_share_get_key( - SPIDER_WIDE_SHARE *share, +const uchar *spider_wide_share_get_key( + const void *share_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto share= static_cast(share_); DBUG_ENTER("spider_wide_share_get_key"); *length = share->table_name_length; - DBUG_RETURN((uchar*) share->table_name); + DBUG_RETURN(reinterpret_cast(share->table_name)); } -uchar *spider_lgtm_tblhnd_share_hash_get_key( - SPIDER_LGTM_TBLHND_SHARE *share, +const uchar *spider_lgtm_tblhnd_share_hash_get_key( + const void *share_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto share= static_cast(share_); DBUG_ENTER("spider_lgtm_tblhnd_share_hash_get_key"); *length = share->table_name_length; - DBUG_RETURN((uchar*) share->table_name); + DBUG_RETURN(reinterpret_cast(share->table_name)); } -uchar *spider_link_get_key( - SPIDER_LINK_FOR_HASH *link_for_hash, +const uchar *spider_link_get_key( + const void *link_for_hash_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto link_for_hash= + static_cast(link_for_hash_); DBUG_ENTER("spider_link_get_key"); *length = link_for_hash->db_table_str->length(); - DBUG_RETURN((uchar*) link_for_hash->db_table_str->ptr()); + DBUG_RETURN(reinterpret_cast(link_for_hash->db_table_str->ptr())); } -uchar *spider_ha_get_key( - ha_spider *spider, +const uchar *spider_udf_tbl_mon_list_key( + const void *table_mon_list_, size_t *length, - my_bool not_used __attribute__ ((unused)) -) { - DBUG_ENTER("spider_ha_get_key"); - *length = spider->share->table_name_length; - DBUG_RETURN((uchar*) spider->share->table_name); -} - -uchar *spider_udf_tbl_mon_list_key( - SPIDER_TABLE_MON_LIST *table_mon_list, - size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto table_mon_list= + static_cast(table_mon_list_); DBUG_ENTER("spider_udf_tbl_mon_list_key"); DBUG_PRINT("info",("spider hash key=%s", table_mon_list->key)); DBUG_PRINT("info",("spider hash key length=%u", table_mon_list->key_length)); *length = table_mon_list->key_length; - DBUG_RETURN((uchar*) table_mon_list->key); + DBUG_RETURN(reinterpret_cast(table_mon_list->key)); } -uchar *spider_allocated_thds_get_key( - THD *thd, +const uchar *spider_allocated_thds_get_key( + const void *thd, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { DBUG_ENTER("spider_allocated_thds_get_key"); *length = sizeof(THD *); - DBUG_RETURN((uchar*) thd); + DBUG_RETURN(reinterpret_cast(thd)); } #ifdef HAVE_PSI_INTERFACE @@ -6333,8 +6330,9 @@ int spider_db_init( &spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) goto error_mem_calc_mutex_init; - if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_tables, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_tbl_get_key, 0, 0)) + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_tables, + spd_charset_utf8mb3_bin, 32, 0, 0, spider_tbl_get_key, 0, + 0)) goto error_open_tables_hash_init; spider_alloc_calc_mem_init(spider_open_tables, SPD_MID_DB_INIT_1); @@ -6342,8 +6340,9 @@ int spider_db_init( spider_open_tables, spider_open_tables.array.max_element * spider_open_tables.array.size_of_element); - if (my_hash_init(PSI_INSTRUMENT_ME, &spider_init_error_tables, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_tbl_get_key, 0, 0)) + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_init_error_tables, + spd_charset_utf8mb3_bin, 32, 0, 0, spider_tbl_get_key, 0, + 0)) goto error_init_error_tables_hash_init; spider_alloc_calc_mem_init(spider_init_error_tables, SPD_MID_DB_INIT_2); @@ -6352,10 +6351,9 @@ int spider_db_init( spider_init_error_tables.array.max_element * spider_init_error_tables.array.size_of_element); #ifdef WITH_PARTITION_STORAGE_ENGINE - if( - my_hash_init(PSI_INSTRUMENT_ME, &spider_open_wide_share, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_wide_share_get_key, 0, 0) - ) + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_wide_share, + spd_charset_utf8mb3_bin, 32, 0, 0, + spider_wide_share_get_key, 0, 0)) goto error_open_wide_share_hash_init; spider_alloc_calc_mem_init(spider_open_wide_share, SPD_MID_DB_INIT_3); @@ -6366,7 +6364,7 @@ int spider_db_init( #endif if (my_hash_init(PSI_INSTRUMENT_ME, &spider_lgtm_tblhnd_share_hash, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_lgtm_tblhnd_share_hash_get_key, 0, 0)) + spider_lgtm_tblhnd_share_hash_get_key, 0, 0)) goto error_lgtm_tblhnd_share_hash_init; spider_alloc_calc_mem_init(spider_lgtm_tblhnd_share_hash, SPD_MID_DB_INIT_4); @@ -6374,22 +6372,24 @@ int spider_db_init( spider_lgtm_tblhnd_share_hash, spider_lgtm_tblhnd_share_hash.array.max_element * spider_lgtm_tblhnd_share_hash.array.size_of_element); - if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_connections, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_conn_get_key, 0, 0)) + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_connections, + spd_charset_utf8mb3_bin, 32, 0, 0, spider_conn_get_key, 0, + 0)) goto error_open_connections_hash_init; - if (my_hash_init(PSI_INSTRUMENT_ME, &spider_ipport_conns, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_ipport_conn_get_key, - spider_free_ipport_conn, 0)) - goto error_ipport_conn__hash_init; + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_ipport_conns, + spd_charset_utf8mb3_bin, 32, 0, 0, + spider_ipport_conn_get_key, spider_free_ipport_conn, 0)) + goto error_ipport_conn__hash_init; spider_alloc_calc_mem_init(spider_open_connections, SPD_MID_DB_INIT_5); spider_alloc_calc_mem(NULL, spider_open_connections, spider_open_connections.array.max_element * spider_open_connections.array.size_of_element); - if (my_hash_init(PSI_INSTRUMENT_ME, &spider_allocated_thds, spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_allocated_thds_get_key, 0, 0)) + if (my_hash_init(PSI_INSTRUMENT_ME, &spider_allocated_thds, + spd_charset_utf8mb3_bin, 32, 0, 0, + spider_allocated_thds_get_key, 0, 0)) goto error_allocated_thds_hash_init; spider_alloc_calc_mem_init(spider_allocated_thds, SPD_MID_DB_INIT_8); @@ -6440,9 +6440,10 @@ int spider_db_init( roop_count < (int) spider_param_udf_table_mon_mutex_count(); roop_count++) { - if (my_hash_init(PSI_INSTRUMENT_ME, &spider_udf_table_mon_list_hash[roop_count], - spd_charset_utf8mb3_bin, 32, 0, 0, - (my_hash_get_key) spider_udf_tbl_mon_list_key, 0, 0)) + if (my_hash_init(PSI_INSTRUMENT_ME, + &spider_udf_table_mon_list_hash[roop_count], + spd_charset_utf8mb3_bin, 32, 0, 0, + spider_udf_tbl_mon_list_key, 0, 0)) goto error_init_udf_table_mon_list_hash; spider_alloc_calc_mem_init(spider_udf_table_mon_list_hash, SPD_MID_DB_INIT_11); diff --git a/storage/spider/spd_table.h b/storage/spider/spd_table.h index 64aa15df852..04d75065051 100644 --- a/storage/spider/spd_table.h +++ b/storage/spider/spd_table.h @@ -47,28 +47,22 @@ typedef struct st_spider_param_string_parse bool locate_param_def(char*& start_param); } SPIDER_PARAM_STRING_PARSE; -uchar *spider_tbl_get_key( - SPIDER_SHARE *share, +const uchar *spider_tbl_get_key( + const void *share, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ); -uchar *spider_wide_share_get_key( - SPIDER_WIDE_SHARE *share, +const uchar *spider_wide_share_get_key( + const void *share, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ); -uchar *spider_link_get_key( - SPIDER_LINK_FOR_HASH *link_for_hash, +const uchar *spider_link_get_key( + const void *link_for_hash, size_t *length, - my_bool not_used __attribute__ ((unused)) -); - -uchar *spider_ha_get_key( - ha_spider *spider, - size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ); int spider_get_server( diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc index 694b75dfbce..105cf7b744b 100644 --- a/storage/spider/spd_trx.cc +++ b/storage/spider/spd_trx.cc @@ -62,29 +62,31 @@ extern ulong spider_allocated_thds_line_no; extern pthread_mutex_t spider_allocated_thds_mutex; // for spider_alter_tables -uchar *spider_alter_tbl_get_key( - SPIDER_ALTER_TABLE *alter_table, +const uchar *spider_alter_tbl_get_key( + const void *alter_table_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto alter_table= static_cast(alter_table_); DBUG_ENTER("spider_alter_tbl_get_key"); *length = alter_table->table_name_length; DBUG_PRINT("info",("spider table_name_length=%zu", *length)); DBUG_PRINT("info",("spider table_name=%s", alter_table->table_name)); - DBUG_RETURN((uchar*) alter_table->table_name); + DBUG_RETURN(reinterpret_cast(alter_table->table_name)); } // for SPIDER_TRX_HA -uchar *spider_trx_ha_get_key( - SPIDER_TRX_HA *trx_ha, +const uchar *spider_trx_ha_get_key( + const void *trx_ha_, size_t *length, - my_bool not_used __attribute__ ((unused)) + my_bool ) { + auto trx_ha= static_cast(trx_ha_); DBUG_ENTER("spider_trx_ha_get_key"); *length = trx_ha->table_name_length; DBUG_PRINT("info",("spider table_name_length=%zu", *length)); DBUG_PRINT("info",("spider table_name=%s", trx_ha->table_name)); - DBUG_RETURN((uchar*) trx_ha->table_name); + DBUG_RETURN(reinterpret_cast(trx_ha->table_name)); } /* @@ -1121,11 +1123,9 @@ SPIDER_TRX *spider_get_trx( goto error_init_udf_table_mutex; } - if ( - my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_conn_hash, - spd_charset_utf8mb3_bin, 32, 0, 0, (my_hash_get_key) - spider_conn_get_key, 0, 0) - ) + if (my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_conn_hash, + spd_charset_utf8mb3_bin, 32, 0, 0, spider_conn_get_key, 0, + 0)) goto error_init_hash; spider_alloc_calc_mem_init(trx->trx_conn_hash, SPD_MID_GET_TRX_2); spider_alloc_calc_mem( @@ -1134,11 +1134,9 @@ SPIDER_TRX *spider_get_trx( trx->trx_conn_hash.array.max_element * trx->trx_conn_hash.array.size_of_element); - if ( - my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_another_conn_hash, - spd_charset_utf8mb3_bin, 32, 0, 0, (my_hash_get_key) - spider_conn_get_key, 0, 0) - ) + if (my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_another_conn_hash, + spd_charset_utf8mb3_bin, 32, 0, 0, spider_conn_get_key, 0, + 0)) goto error_init_another_hash; spider_alloc_calc_mem_init(trx->trx_another_conn_hash, SPD_MID_GET_TRX_3); spider_alloc_calc_mem( @@ -1147,13 +1145,9 @@ SPIDER_TRX *spider_get_trx( trx->trx_another_conn_hash.array.max_element * trx->trx_another_conn_hash.array.size_of_element); - - - if ( - my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_alter_table_hash, - spd_charset_utf8mb3_bin, 32, 0, 0, (my_hash_get_key) - spider_alter_tbl_get_key, 0, 0) - ) + if (my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_alter_table_hash, + spd_charset_utf8mb3_bin, 32, 0, 0, + spider_alter_tbl_get_key, 0, 0)) goto error_init_alter_hash; spider_alloc_calc_mem_init(trx->trx_alter_table_hash, SPD_MID_GET_TRX_8); spider_alloc_calc_mem( @@ -1162,11 +1156,9 @@ SPIDER_TRX *spider_get_trx( trx->trx_alter_table_hash.array.max_element * trx->trx_alter_table_hash.array.size_of_element); - if ( - my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_ha_hash, - spd_charset_utf8mb3_bin, 32, 0, 0, (my_hash_get_key) - spider_trx_ha_get_key, 0, 0) - ) + if (my_hash_init(PSI_INSTRUMENT_ME, &trx->trx_ha_hash, + spd_charset_utf8mb3_bin, 32, 0, 0, spider_trx_ha_get_key, + 0, 0)) goto error_init_trx_ha_hash; spider_alloc_calc_mem_init(trx->trx_ha_hash, SPD_MID_GET_TRX_9); spider_alloc_calc_mem( From 7a8eb26bda74348e98aa5b1ef91b0473ec5e767a Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Sat, 26 Oct 2024 13:53:51 -0600 Subject: [PATCH 31/55] MDEV-34348: Fix casting related to plugins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Partial commit of the greater MDEV-34348 scope. MDEV-34348: MariaDB is violating clang-16 -Wcast-function-type-strict Reviewed By: ============ Marko Mäkelä --- extra/mariabackup/encryption_plugin.cc | 2 +- sql/encryption.cc | 6 ++++-- sql/handler.cc | 6 ++++-- sql/handler.h | 4 ++-- sql/sql_audit.cc | 14 ++++++++------ sql/sql_plugin.cc | 18 ++++++++++-------- sql/sql_plugin.h | 2 +- sql/sql_show.cc | 8 +++++--- sql/sql_type.cc | 6 ++++-- 9 files changed, 39 insertions(+), 27 deletions(-) diff --git a/extra/mariabackup/encryption_plugin.cc b/extra/mariabackup/encryption_plugin.cc index ab87ce0b7bd..04e8ae83957 100644 --- a/extra/mariabackup/encryption_plugin.cc +++ b/extra/mariabackup/encryption_plugin.cc @@ -194,7 +194,7 @@ const char *encryption_plugin_get_config() return encryption_plugin_config.c_str(); } -extern int finalize_encryption_plugin(st_plugin_int *plugin); +extern int finalize_encryption_plugin(void *plugin); void encryption_plugin_prepare_init(int argc, char **argv) diff --git a/sql/encryption.cc b/sql/encryption.cc index 13239b91910..79939cdc012 100644 --- a/sql/encryption.cc +++ b/sql/encryption.cc @@ -59,8 +59,9 @@ uint ctx_size(unsigned int, unsigned int) } /* extern "C" */ -int initialize_encryption_plugin(st_plugin_int *plugin) +int initialize_encryption_plugin(void *plugin_) { + st_plugin_int *plugin= static_cast(plugin_); if (encryption_manager) return 1; @@ -107,8 +108,9 @@ int initialize_encryption_plugin(st_plugin_int *plugin) return 0; } -int finalize_encryption_plugin(st_plugin_int *plugin) +int finalize_encryption_plugin(void *plugin_) { + st_plugin_int *plugin= static_cast(plugin_); bool used= plugin_ref_to_int(encryption_manager) == plugin; if (used) diff --git a/sql/handler.cc b/sql/handler.cc index 10ea7da1088..4ecd1ea2048 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -566,8 +566,9 @@ static int hton_drop_table(handlerton *hton, const char *path) } -int ha_finalize_handlerton(st_plugin_int *plugin) +int ha_finalize_handlerton(void *plugin_) { + st_plugin_int *plugin= static_cast(plugin_); handlerton *hton= (handlerton *)plugin->data; DBUG_ENTER("ha_finalize_handlerton"); @@ -618,8 +619,9 @@ int ha_finalize_handlerton(st_plugin_int *plugin) } -int ha_initialize_handlerton(st_plugin_int *plugin) +int ha_initialize_handlerton(void *plugin_) { + st_plugin_int *plugin= static_cast(plugin_); handlerton *hton; static const char *no_exts[]= { 0 }; int ret= 0; diff --git a/sql/handler.h b/sql/handler.h index ac97a41a4f1..fc3d00d43d5 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -5101,8 +5101,8 @@ static inline bool ha_storage_engine_is_enabled(const handlerton *db_type) int ha_init_errors(void); int ha_init(void); int ha_end(void); -int ha_initialize_handlerton(st_plugin_int *plugin); -int ha_finalize_handlerton(st_plugin_int *plugin); +int ha_initialize_handlerton(void *plugin); +int ha_finalize_handlerton(void *plugin); TYPELIB *ha_known_exts(void); int ha_panic(enum ha_panic_function flag); diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 6ee6ede31b8..6f0d3afbff7 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -18,8 +18,8 @@ #include "mysqld.h" #include "sql_audit.h" -extern int initialize_audit_plugin(st_plugin_int *plugin); -extern int finalize_audit_plugin(st_plugin_int *plugin); +extern int initialize_audit_plugin(void *plugin); +extern int finalize_audit_plugin(void *plugin); #ifndef EMBEDDED_LIBRARY @@ -262,8 +262,9 @@ void mysql_audit_finalize() @retval TRUE There was an error. */ -int initialize_audit_plugin(st_plugin_int *plugin) +int initialize_audit_plugin(void *plugin_) { + st_plugin_int *plugin= static_cast(plugin_); st_mysql_audit *data= (st_mysql_audit*) plugin->plugin->info; if (!data->event_notify || !data->class_mask[0]) @@ -346,8 +347,9 @@ static my_bool calc_class_mask(THD *thd, plugin_ref plugin, void *arg) @retval FALSE OK @retval TRUE There was an error. */ -int finalize_audit_plugin(st_plugin_int *plugin) +int finalize_audit_plugin(void *plugin_) { + st_plugin_int *plugin= static_cast(plugin_); unsigned long event_class_mask[MYSQL_AUDIT_CLASS_MASK_SIZE]; if (plugin->plugin->deinit && plugin->plugin->deinit(NULL)) @@ -458,13 +460,13 @@ void mysql_audit_finalize() } -int initialize_audit_plugin(st_plugin_int *plugin) +int initialize_audit_plugin(void *plugin) { return 1; } -int finalize_audit_plugin(st_plugin_int *plugin) +int finalize_audit_plugin(void *plugin) { return 0; } diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 624a4fa2e9b..56c7b3332a2 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -103,16 +103,16 @@ const LEX_CSTRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]= { STRING_WITH_LEN("FUNCTION") } }; -extern int initialize_schema_table(st_plugin_int *plugin); -extern int finalize_schema_table(st_plugin_int *plugin); +extern int initialize_schema_table(void *plugin); +extern int finalize_schema_table(void *plugin); -extern int initialize_audit_plugin(st_plugin_int *plugin); -extern int finalize_audit_plugin(st_plugin_int *plugin); +extern int initialize_audit_plugin(void *plugin); +extern int finalize_audit_plugin(void *plugin); -extern int initialize_encryption_plugin(st_plugin_int *plugin); -extern int finalize_encryption_plugin(st_plugin_int *plugin); +extern int initialize_encryption_plugin(void *plugin); +extern int finalize_encryption_plugin(void *plugin); -extern int initialize_data_type_plugin(st_plugin_int *plugin); +extern int initialize_data_type_plugin(void *plugin); /* The number of elements in both plugin_type_initialize and @@ -1446,8 +1446,9 @@ static int plugin_do_initialize(struct st_plugin_int *plugin, uint &state) mysql_mutex_assert_not_owner(&LOCK_plugin); plugin_type_init init= plugin_type_initialize[plugin->plugin->type]; if (!init) - init= (plugin_type_init) plugin->plugin->init; + init= plugin->plugin->init; if (init) + { if (int ret= init(plugin)) { /* Plugin init failed and did not requested a retry */ @@ -1455,6 +1456,7 @@ static int plugin_do_initialize(struct st_plugin_int *plugin, uint &state) print_init_failed_error(plugin); DBUG_RETURN(ret); } + } state= PLUGIN_IS_READY; // plugin->init() succeeded if (plugin->plugin->status_vars) diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h index eaf0b40f34a..5e62f2a5e45 100644 --- a/sql/sql_plugin.h +++ b/sql/sql_plugin.h @@ -152,7 +152,7 @@ typedef struct st_plugin_int **plugin_ref; #define plugin_equals(p1,p2) ((p1) && (p2) && (p1)[0] == (p2)[0]) #endif -typedef int (*plugin_type_init)(struct st_plugin_int *); +typedef int (*plugin_type_init)(void *); extern I_List *opt_plugin_load_list_ptr; extern char *opt_plugin_dir_ptr; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index aafaf3b6a41..2965cdf0199 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -9938,8 +9938,9 @@ ST_SCHEMA_TABLE schema_tables[]= }; -int initialize_schema_table(st_plugin_int *plugin) +int initialize_schema_table(void *plugin_) { + st_plugin_int *plugin= static_cast(plugin_); ST_SCHEMA_TABLE *schema_table; int err; DBUG_ENTER("initialize_schema_table"); @@ -9984,9 +9985,10 @@ int initialize_schema_table(st_plugin_int *plugin) DBUG_RETURN(0); } -int finalize_schema_table(st_plugin_int *plugin) +int finalize_schema_table(void *plugin_) { - ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data; + st_plugin_int *plugin= static_cast(plugin_); + ST_SCHEMA_TABLE *schema_table= static_cast(plugin->data); DBUG_ENTER("finalize_schema_table"); if (schema_table) diff --git a/sql/sql_type.cc b/sql/sql_type.cc index e46a3f2fda4..114c5ab9786 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -9566,9 +9566,11 @@ Charset::eq_collation_specific_names(CHARSET_INFO *cs) const return name0.length && !cmp(&name0, &name1); } -int initialize_data_type_plugin(st_plugin_int *plugin) +int initialize_data_type_plugin(void *plugin_) { - st_mariadb_data_type *data= (st_mariadb_data_type*) plugin->plugin->info; + st_plugin_int *plugin= static_cast(plugin_); + st_mariadb_data_type *data= + static_cast(plugin->plugin->info); data->type_handler->set_name(Name(plugin->name)); if (plugin->plugin->init && plugin->plugin->init(NULL)) { From 5432fa802b53ee8d9d2a47584610aab7ed67a5ca Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Sat, 26 Oct 2024 14:00:11 -0600 Subject: [PATCH 32/55] MDEV-34348: Fix casts in sql_acl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Partial commit of the greater MDEV-34348 scope. MDEV-34348: MariaDB is violating clang-16 -Wcast-function-type-strict Reviewed By: ============ Marko Mäkelä --- sql/sql_acl.cc | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 5e4053cd7f2..f59df5df37a 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -697,9 +697,9 @@ static bool add_role_user_mapping(const char *uname, const char *hname, const ch static bool get_YN_as_bool(Field *field); #define ROLE_CYCLE_FOUND 2 -static int traverse_role_graph_up(ACL_ROLE *, void *, - int (*) (ACL_ROLE *, void *), - int (*) (ACL_ROLE *, ACL_ROLE *, void *)); +static int +traverse_role_graph_up(ACL_ROLE *, void *, int (*)(ACL_USER_BASE *, void *), + int (*)(ACL_USER_BASE *, ACL_ROLE *, void *)); static int traverse_role_graph_down(ACL_USER_BASE *, void *, int (*) (ACL_USER_BASE *, void *), @@ -2848,7 +2848,7 @@ void acl_free(bool end) my_hash_free(&acl_roles); free_root(&acl_memroot,MYF(0)); delete_dynamic(&acl_hosts); - delete_dynamic_with_callback(&acl_users, (FREE_FUNC) free_acl_user); + delete_dynamic_with_callback(&acl_users, free_acl_user); acl_dbs.free_memory(); delete_dynamic(&acl_wild_hosts); delete_dynamic(&acl_proxy_users); @@ -2956,7 +2956,7 @@ bool acl_reload(THD *thd) my_hash_free(&old_acl_roles); free_root(&old_mem,MYF(0)); delete_dynamic(&old_acl_hosts); - delete_dynamic_with_callback(&old_acl_users, (FREE_FUNC) free_acl_user); + delete_dynamic_with_callback(&old_acl_users, free_acl_user); delete_dynamic(&old_acl_proxy_users); my_hash_free(&old_acl_roles_mappings); } @@ -6222,19 +6222,20 @@ static enum PRIVS_TO_MERGE::what sp_privs_to_merge(enum_sp_type type) } -static int init_role_for_merging(ACL_ROLE *role, void *context) +static int init_role_for_merging(ACL_USER_BASE *role_, void *context) { + ACL_ROLE *role= static_cast(role_); role->counter= 0; return 0; } -static int count_subgraph_nodes(ACL_ROLE *role, ACL_ROLE *grantee, void *context) +static int count_subgraph_nodes(ACL_USER_BASE *, ACL_ROLE *grantee, void *context) { grantee->counter++; return 0; } -static int merge_role_privileges(ACL_ROLE *, ACL_ROLE *, void *); +static int merge_role_privileges(ACL_USER_BASE *, ACL_ROLE *, void *); static bool merge_one_role_privileges(ACL_ROLE *grantee, PRIVS_TO_MERGE what); /** @@ -6474,13 +6475,11 @@ end: */ static int traverse_role_graph_up(ACL_ROLE *role, void *context, - int (*on_node) (ACL_ROLE *role, void *context), - int (*on_edge) (ACL_ROLE *current, ACL_ROLE *neighbour, void *context)) + int (*on_node) (ACL_USER_BASE *role, void *context), + int (*on_edge) (ACL_USER_BASE *current, ACL_ROLE *neighbour, void *context)) { - return traverse_role_graph_impl(role, context, - my_offsetof(ACL_ROLE, parent_grantee), - (int (*)(ACL_USER_BASE *, void *))on_node, - (int (*)(ACL_USER_BASE *, ACL_ROLE *, void *))on_edge); + return traverse_role_graph_impl( + role, context, my_offsetof(ACL_ROLE, parent_grantee), on_node, on_edge); } /** @@ -7020,7 +7019,7 @@ static bool merge_role_routine_grant_privileges(ACL_ROLE *grantee, /** update privileges of the 'grantee' from all roles, granted to it */ -static int merge_role_privileges(ACL_ROLE *role __attribute__((unused)), +static int merge_role_privileges(ACL_USER_BASE *, ACL_ROLE *grantee, void *context) { PRIVS_TO_MERGE *data= (PRIVS_TO_MERGE *)context; From 3c785499da049dd75de8c03ca79cc5b82a35ee9d Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Sat, 26 Oct 2024 14:13:32 -0600 Subject: [PATCH 33/55] MDEV-34348: Fix casts relating to tree_walk_action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Partial commit of the greater MDEV-34348 scope. MDEV-34348: MariaDB is violating clang-16 -Wcast-function-type-strict Reviewed By: ============ Marko Mäkelä --- include/my_global.h | 2 ++ sql/sql_analyse.cc | 28 +++++++++++++++------------- sql/sql_analyse.h | 25 ++++++++++--------------- sql/uniques.cc | 29 ++++++++++++++++++++--------- sql/uniques.h | 12 ++++++------ storage/maria/aria_pack.c | 8 ++++---- storage/maria/ma_ft_nlq_search.c | 26 +++++++++++++++++--------- storage/maria/ma_ft_parser.c | 7 +++++-- storage/myisam/ft_nlq_search.c | 25 ++++++++++++++++--------- storage/myisam/ft_parser.c | 6 ++++-- storage/myisam/ft_stopwords.c | 3 ++- storage/myisam/mi_locking.c | 4 +++- storage/myisam/myisamdef.h | 2 +- storage/myisam/myisamlog.c | 23 +++++++++++++---------- storage/myisam/myisampack.c | 9 +++++---- 15 files changed, 123 insertions(+), 86 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index 5e097248c35..a98a99217b8 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -528,7 +528,9 @@ 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 + #include + #define qsort_t RETQSORTTYPE /* Broken GCC can't handle typedef !!!! */ #ifdef HAVE_SYS_SOCKET_H #include diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index f92ab417209..e01e26b7a74 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -1073,10 +1073,10 @@ String *field_decimal::std(String *s, ha_rows rows) } -int collect_string(String *element, - element_count count __attribute__((unused)), - TREE_INFO *info) +int collect_string(void *element_, element_count, void *info_) { + String *element= static_cast(element_); + TREE_INFO *info= static_cast(info_); if (info->found) info->str->append(','); else @@ -1089,9 +1089,10 @@ int collect_string(String *element, } // collect_string -int collect_real(double *element, element_count count __attribute__((unused)), - TREE_INFO *info) +int collect_real(void *element_, element_count, void *info_) { + double *element= static_cast(element_); + TREE_INFO *info= static_cast(info_); char buff[MAX_FIELD_WIDTH]; String s(buff, sizeof(buff),current_thd->charset()); @@ -1107,9 +1108,10 @@ int collect_real(double *element, element_count count __attribute__((unused)), } // collect_real -int collect_decimal(uchar *element, element_count count, - TREE_INFO *info) +int collect_decimal(void *element_, element_count count, void *info_) { + uchar *element= static_cast(element_); + TREE_INFO *info= static_cast(info_); char buff[DECIMAL_MAX_STR_LENGTH]; String s(buff, sizeof(buff),&my_charset_bin); @@ -1126,10 +1128,10 @@ int collect_decimal(uchar *element, element_count count, } -int collect_longlong(longlong *element, - element_count count __attribute__((unused)), - TREE_INFO *info) +int collect_longlong(void *element_, element_count, void *info_) { + longlong *element= static_cast(element_); + TREE_INFO *info= static_cast(info_); char buff[MAX_FIELD_WIDTH]; String s(buff, sizeof(buff),&my_charset_bin); @@ -1145,10 +1147,10 @@ int collect_longlong(longlong *element, } // collect_longlong -int collect_ulonglong(ulonglong *element, - element_count count __attribute__((unused)), - TREE_INFO *info) +int collect_ulonglong(void *element_, element_count, void *info_) { + ulonglong *element= static_cast(element_); + TREE_INFO *info= static_cast(info_); char buff[MAX_FIELD_WIDTH]; String s(buff, sizeof(buff),&my_charset_bin); diff --git a/sql/sql_analyse.h b/sql/sql_analyse.h index 1f3089ae25a..89f4c0f3e15 100644 --- a/sql/sql_analyse.h +++ b/sql/sql_analyse.h @@ -95,9 +95,7 @@ public: friend class analyse; }; - -int collect_string(String *element, element_count count, - TREE_INFO *info); +int collect_string(void *element, element_count count, void *info); int sortcmp2(void *, const void *a, const void *b); @@ -139,15 +137,14 @@ public: friend int collect_string(String *element, element_count count, TREE_INFO *info); tree_walk_action collect_enum() override - { return (tree_walk_action) collect_string; } + { return collect_string; } String *std(String *s __attribute__((unused)), ha_rows rows __attribute__((unused))) override { return (String*) 0; } }; -int collect_decimal(uchar *element, element_count count, - TREE_INFO *info); +int collect_decimal(void *element, element_count count, void *info); class field_decimal :public field_info { @@ -171,12 +168,12 @@ public: friend int collect_decimal(uchar *element, element_count count, TREE_INFO *info); tree_walk_action collect_enum() override - { return (tree_walk_action) collect_decimal; } + { return collect_decimal; } String *std(String *s, ha_rows rows) override; }; -int collect_real(double *element, element_count count, TREE_INFO *info); +int collect_real(void *element, element_count count, void *info); class field_real: public field_info { @@ -229,11 +226,10 @@ public: friend int collect_real(double *element, element_count count, TREE_INFO *info); tree_walk_action collect_enum() override - { return (tree_walk_action) collect_real;} + { return collect_real;} }; -int collect_longlong(longlong *element, element_count count, - TREE_INFO *info); +int collect_longlong(void *element, element_count count, void *info); class field_longlong: public field_info { @@ -276,11 +272,10 @@ public: friend int collect_longlong(longlong *element, element_count count, TREE_INFO *info); tree_walk_action collect_enum() override - { return (tree_walk_action) collect_longlong;} + { return collect_longlong;} }; -int collect_ulonglong(ulonglong *element, element_count count, - TREE_INFO *info); +int collect_ulonglong(void *element, element_count count, void *info); class field_ulonglong: public field_info { @@ -324,7 +319,7 @@ public: friend int collect_ulonglong(ulonglong *element, element_count count, TREE_INFO *info); tree_walk_action collect_enum() override - { return (tree_walk_action) collect_ulonglong; } + { return collect_ulonglong; } }; diff --git a/sql/uniques.cc b/sql/uniques.cc index 2be3ca5d7ed..1f2fbf8e785 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -40,8 +40,10 @@ #include "uniques.h" // Unique #include "sql_sort.h" -int unique_write_to_file(uchar* key, element_count count, Unique *unique) +int unique_write_to_file(void* key_, element_count, void *unique_) { + uchar *key= static_cast(key_); + Unique *unique= static_cast(unique_); /* Use unique->size (size of element stored in the tree) and not unique->tree.size_of_element. The latter is different from unique->size @@ -51,21 +53,30 @@ int unique_write_to_file(uchar* key, element_count count, Unique *unique) return my_b_write(&unique->file, key, unique->size) ? 1 : 0; } -int unique_write_to_file_with_count(uchar* key, element_count count, Unique *unique) +int unique_write_to_file_with_count(void* key_, element_count count, void *unique_) { + uchar *key= static_cast(key_); + Unique *unique= static_cast(unique_); return my_b_write(&unique->file, key, unique->size) || - my_b_write(&unique->file, (uchar*)&count, sizeof(element_count)) ? 1 : 0; + my_b_write(&unique->file, reinterpret_cast(&count), + sizeof(element_count)) + ? 1 + : 0; } -int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique) +int unique_write_to_ptrs(void* key_, element_count, void *unique_) { + uchar *key= static_cast(key_); + Unique *unique= static_cast(unique_); memcpy(unique->sort.record_pointers, key, unique->size); unique->sort.record_pointers+=unique->size; return 0; } -int unique_intersect_write_to_ptrs(uchar* key, element_count count, Unique *unique) +int unique_intersect_write_to_ptrs(void* key_, element_count count, void *unique_) { + uchar *key= static_cast(key_); + Unique *unique= static_cast(unique_); if (count >= unique->min_dupl_count) { memcpy(unique->sort.record_pointers, key, unique->size); @@ -383,8 +394,8 @@ bool Unique::flush() file_ptr.set_file_position(my_b_tell(&file)); tree_walk_action action= min_dupl_count ? - (tree_walk_action) unique_write_to_file_with_count : - (tree_walk_action) unique_write_to_file; + unique_write_to_file_with_count : + unique_write_to_file; if (tree_walk(&tree, action, (void*) this, left_root_right) || insert_dynamic(&file_ptrs, (uchar*) &file_ptr)) @@ -800,8 +811,8 @@ bool Unique::get(TABLE *table) { uchar *save_record_pointers= sort.record_pointers; tree_walk_action action= min_dupl_count ? - (tree_walk_action) unique_intersect_write_to_ptrs : - (tree_walk_action) unique_write_to_ptrs; + unique_intersect_write_to_ptrs : + unique_write_to_ptrs; filtered_out_elems= 0; (void) tree_walk(&tree, action, this, left_root_right); diff --git a/sql/uniques.h b/sql/uniques.h index 7e12a391fbd..583c7514db1 100644 --- a/sql/uniques.h +++ b/sql/uniques.h @@ -98,13 +98,13 @@ public: uint get_size() const { return size; } size_t get_max_in_memory_size() const { return max_in_memory_size; } - friend int unique_write_to_file(uchar* key, element_count count, Unique *unique); - friend int unique_write_to_ptrs(uchar* key, element_count count, Unique *unique); + friend int unique_write_to_file(void* key, element_count count, void *unique); + friend int unique_write_to_ptrs(void* key, element_count count, void *unique); - friend int unique_write_to_file_with_count(uchar* key, element_count count, - Unique *unique); - friend int unique_intersect_write_to_ptrs(uchar* key, element_count count, - Unique *unique); + friend int unique_write_to_file_with_count(void *key, element_count count, + void *unique); + friend int unique_intersect_write_to_ptrs(void *key, element_count count, + void *unique); }; #endif /* UNIQUE_INCLUDED */ diff --git a/storage/maria/aria_pack.c b/storage/maria/aria_pack.c index 4a9719addd3..5e07c3311a7 100644 --- a/storage/maria/aria_pack.c +++ b/storage/maria/aria_pack.c @@ -148,8 +148,7 @@ 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, const void *a, const void *b); -static int save_counts_in_queue(uchar *key,element_count count, - HUFF_TREE *tree); +static int save_counts_in_queue(void *key, element_count count, void *tree); static my_off_t calc_packed_length(HUFF_COUNTS *huff_counts,uint flag); static uint join_same_trees(HUFF_COUNTS *huff_counts,uint trees); static int make_huff_decode_table(HUFF_TREE *huff_tree,uint trees); @@ -1806,9 +1805,10 @@ static int compare_tree(void *cmp_arg __attribute__((unused)), const void *s_, 0 */ -static int save_counts_in_queue(uchar *key, element_count count, - HUFF_TREE *tree) +static int save_counts_in_queue(void *key_, element_count count, void *tree_) { + uchar *key= key_; + HUFF_TREE *tree= tree_; HUFF_ELEMENT *new_huff_el; new_huff_el=tree->element_buffer+(tree->elements++); diff --git a/storage/maria/ma_ft_nlq_search.c b/storage/maria/ma_ft_nlq_search.c index 2e5d19a607f..db3ebc220f6 100644 --- a/storage/maria/ma_ft_nlq_search.c +++ b/storage/maria/ma_ft_nlq_search.c @@ -64,8 +64,10 @@ static int FT_SUPERDOC_cmp(void *cmp_arg __attribute__((unused)), return 1; } -static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) +static int walk_and_match(void *word_, element_count count, void *aio_) { + FT_WORD *word= word_; + ALL_IN_ONE *aio= aio_; FT_WEIGTH subkeys; int r; uint doc_cnt; @@ -188,9 +190,11 @@ do_skip: } -static int walk_and_copy(FT_SUPERDOC *from, - uint32 count __attribute__((unused)), FT_DOC **to) +static int walk_and_copy(void *from_, uint32 count __attribute__((unused)), + void *to_) { + FT_SUPERDOC *from= from_; + FT_DOC **to= to_; DBUG_ENTER("walk_and_copy"); from->doc.weight+=from->tmp_weight*from->word_ptr->weight; (*to)->dpos=from->doc.dpos; @@ -199,9 +203,13 @@ static int walk_and_copy(FT_SUPERDOC *from, DBUG_RETURN(0); } -static int walk_and_push(FT_SUPERDOC *from, - uint32 count __attribute__((unused)), QUEUE *best) +static int walk_and_push(void *from_, + element_count count __attribute__((unused)), + void *best_) { + FT_SUPERDOC *from= from_; + QUEUE *best= best_; + DBUG_ENTER("walk_and_copy"); from->doc.weight+=from->tmp_weight*from->word_ptr->weight; set_if_smaller(best->elements, ft_query_expansion_limit-1); @@ -257,7 +265,7 @@ FT_INFO *maria_ft_init_nlq_search(MARIA_HA *info, uint keynr, uchar *query, &wtree.mem_root)) goto err; - if (tree_walk(&wtree, (tree_walk_action)&walk_and_match, &aio, + if (tree_walk(&wtree, &walk_and_match, &aio, left_root_right)) goto err; @@ -265,7 +273,7 @@ FT_INFO *maria_ft_init_nlq_search(MARIA_HA *info, uint keynr, uchar *query, { QUEUE best; 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, + tree_walk(&aio.dtree, &walk_and_push, &best, left_root_right); while (best.elements) { @@ -284,7 +292,7 @@ FT_INFO *maria_ft_init_nlq_search(MARIA_HA *info, uint keynr, uchar *query, } delete_queue(&best); reset_tree(&aio.dtree); - if (tree_walk(&wtree, (tree_walk_action)&walk_and_match, &aio, + if (tree_walk(&wtree, &walk_and_match, &aio, left_root_right)) goto err; @@ -307,7 +315,7 @@ FT_INFO *maria_ft_init_nlq_search(MARIA_HA *info, uint keynr, uchar *query, dlist->info=aio.info; dptr=dlist->doc; - tree_walk(&aio.dtree, (tree_walk_action) &walk_and_copy, + tree_walk(&aio.dtree, &walk_and_copy, &dptr, left_root_right); if (flags & FT_SORTED) diff --git a/storage/maria/ma_ft_parser.c b/storage/maria/ma_ft_parser.c index 015fcdd0268..86810f73a2a 100644 --- a/storage/maria/ma_ft_parser.c +++ b/storage/maria/ma_ft_parser.c @@ -40,8 +40,11 @@ static int FT_WORD_cmp(void *cs_, const void *w1_, const void *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) + +static int walk_and_copy(void *word_, element_count count, void *docstat_) { + FT_WORD *word= word_; + FT_DOCSTAT *docstat= docstat_; word->weight=LWS_IN_USE; docstat->sum+=word->weight; memcpy((docstat->list)++, word, sizeof(FT_WORD)); @@ -62,7 +65,7 @@ FT_WORD * maria_ft_linearize(TREE *wtree, MEM_ROOT *mem_root) docstat.list=wlist; docstat.uniq=wtree->elements_in_tree; docstat.sum=0; - tree_walk(wtree,(tree_walk_action)&walk_and_copy,&docstat,left_root_right); + tree_walk(wtree,&walk_and_copy,&docstat,left_root_right); } delete_tree(wtree, 0); if (!wlist) diff --git a/storage/myisam/ft_nlq_search.c b/storage/myisam/ft_nlq_search.c index 3bc1340f670..dd89e36f41a 100644 --- a/storage/myisam/ft_nlq_search.c +++ b/storage/myisam/ft_nlq_search.c @@ -62,8 +62,10 @@ static int FT_SUPERDOC_cmp(void *cmp_arg __attribute__((unused)), return 1; } -static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) +static int walk_and_match(void *word_, element_count count, void *aio_) { + FT_WORD *word= word_; + ALL_IN_ONE *aio= aio_; FT_WEIGTH subkeys; int r; uint keylen, doc_cnt; @@ -185,9 +187,11 @@ do_skip: } -static int walk_and_copy(FT_SUPERDOC *from, - uint32 count __attribute__((unused)), FT_DOC **to) +static int walk_and_copy(void *from_, uint32 count __attribute__((unused)), + void *to_) { + FT_SUPERDOC *from= from_; + FT_DOC **to= to_; DBUG_ENTER("walk_and_copy"); from->doc.weight+=from->tmp_weight*from->word_ptr->weight; (*to)->dpos=from->doc.dpos; @@ -196,9 +200,12 @@ static int walk_and_copy(FT_SUPERDOC *from, DBUG_RETURN(0); } -static int walk_and_push(FT_SUPERDOC *from, - uint32 count __attribute__((unused)), QUEUE *best) +static int walk_and_push(void *from_, + element_count count __attribute__((unused)), + void *best_) { + FT_SUPERDOC *from= from_; + QUEUE *best= best_; DBUG_ENTER("walk_and_copy"); from->doc.weight+=from->tmp_weight*from->word_ptr->weight; set_if_smaller(best->elements, ft_query_expansion_limit-1); @@ -253,7 +260,7 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, uchar *query, &wtree.mem_root)) goto err; - if (tree_walk(&wtree, (tree_walk_action)&walk_and_match, &aio, + if (tree_walk(&wtree, &walk_and_match, &aio, left_root_right)) goto err; @@ -261,7 +268,7 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, uchar *query, { QUEUE best; 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, + tree_walk(&aio.dtree, &walk_and_push, &best, left_root_right); while (best.elements) { @@ -280,7 +287,7 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, uchar *query, } delete_queue(&best); reset_tree(&aio.dtree); - if (tree_walk(&wtree, (tree_walk_action)&walk_and_match, &aio, + if (tree_walk(&wtree, &walk_and_match, &aio, left_root_right)) goto err; @@ -303,7 +310,7 @@ FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, uchar *query, dlist->info=aio.info; dptr=dlist->doc; - tree_walk(&aio.dtree, (tree_walk_action) &walk_and_copy, + tree_walk(&aio.dtree, &walk_and_copy, &dptr, left_root_right); if (flags & FT_SORTED) diff --git a/storage/myisam/ft_parser.c b/storage/myisam/ft_parser.c index 47ce67ab0db..25ef65d33af 100644 --- a/storage/myisam/ft_parser.c +++ b/storage/myisam/ft_parser.c @@ -37,8 +37,10 @@ static int FT_WORD_cmp(void *cs_, const void *w1_, const void *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) +static int walk_and_copy(void *word_, element_count count, void *docstat_) { + FT_WORD *word= word_; + FT_DOCSTAT *docstat= docstat_; word->weight=LWS_IN_USE; docstat->sum+=word->weight; memcpy((docstat->list)++, word, sizeof(FT_WORD)); @@ -59,7 +61,7 @@ FT_WORD * ft_linearize(TREE *wtree, MEM_ROOT *mem_root) docstat.list=wlist; docstat.uniq=wtree->elements_in_tree; docstat.sum=0; - tree_walk(wtree,(tree_walk_action)&walk_and_copy,&docstat,left_root_right); + tree_walk(wtree,&walk_and_copy,&docstat,left_root_right); } delete_tree(wtree, 0); if (!wlist) diff --git a/storage/myisam/ft_stopwords.c b/storage/myisam/ft_stopwords.c index b6a07f555a7..4ada6cecc58 100644 --- a/storage/myisam/ft_stopwords.c +++ b/storage/myisam/ft_stopwords.c @@ -39,9 +39,10 @@ static int FT_STOPWORD_cmp(void *cmp_arg __attribute__((unused)), (uchar *) w2->pos, w2->len); } -static int FT_STOPWORD_free(FT_STOPWORD *w, TREE_FREE action, +static int FT_STOPWORD_free(void *w_, TREE_FREE action, void *arg __attribute__((unused))) { + FT_STOPWORD *w= w_; if (action == free_free) my_free((void*)w->pos); return 0; diff --git a/storage/myisam/mi_locking.c b/storage/myisam/mi_locking.c index 33a1c86c0d7..103fa725723 100644 --- a/storage/myisam/mi_locking.c +++ b/storage/myisam/mi_locking.c @@ -452,8 +452,10 @@ my_bool mi_check_status(void *param) structure. */ -void mi_fix_status(MI_INFO *org_table, MI_INFO *new_table) +void mi_fix_status(void *ord_table_, void *new_table_) { + MI_INFO *org_table= ord_table_; + MI_INFO *new_table= new_table_; DBUG_ENTER("mi_fix_status"); if (!new_table) { diff --git a/storage/myisam/myisamdef.h b/storage/myisam/myisamdef.h index f84ad6fa184..fe1d450e2c3 100644 --- a/storage/myisam/myisamdef.h +++ b/storage/myisam/myisamdef.h @@ -731,7 +731,7 @@ void mi_update_status(void *param); void mi_restore_status(void *param); void mi_copy_status(void *to, void *from); my_bool mi_check_status(void *param); -void mi_fix_status(MI_INFO *org_table, MI_INFO *new_table); +void mi_fix_status(void *org_table, void *new_table); extern MI_INFO *test_if_reopen(char *filename); my_bool check_table_is_closed(const char *name, const char *where); int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share); diff --git a/storage/myisam/myisamlog.c b/storage/myisam/myisamlog.c index d227c010608..d39bc510871 100644 --- a/storage/myisam/myisamlog.c +++ b/storage/myisam/myisamlog.c @@ -58,11 +58,10 @@ 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, 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 int test_if_open(void *key, element_count count, void *param); static void fix_blob_pointers(MI_INFO *isam,uchar *record); -static int test_when_accessed(struct file_info *key,element_count count, - struct st_access_param *access_param); +static int test_when_accessed(void *key, element_count count, + void *access_param); static int file_info_free(void*, TREE_FREE, void *); static int close_some_file(TREE *tree); static int reopen_closed_file(TREE *tree,struct file_info *file_info); @@ -411,7 +410,7 @@ static int examine_log(char * file_name, char **table_names) } open_param.name=file_info.name; open_param.max_id=0; - (void) tree_walk(&tree,(tree_walk_action) test_if_open,(void*) &open_param, + (void) tree_walk(&tree, test_if_open,(void*) &open_param, left_root_right); file_info.id=open_param.max_id+1; /* @@ -709,10 +708,12 @@ static int file_info_compare(void *cmp_arg __attribute__((unused)), /* ARGSUSED */ -static int test_if_open (struct file_info *key, +static int test_if_open (void *key_, element_count count __attribute__((unused)), - struct test_if_open_param *param) + void *param_) { + struct file_info *key= key_; + struct test_if_open_param *param= param_; if (!strcmp(key->name,param->name) && key->id > param->max_id) param->max_id=key->id; return 0; @@ -737,10 +738,12 @@ static void fix_blob_pointers(MI_INFO *info, uchar *record) /* close the file with hasn't been accessed for the longest time */ /* ARGSUSED */ -static int test_when_accessed (struct file_info *key, +static int test_when_accessed (void *key_, element_count count __attribute__((unused)), - struct st_access_param *access_param) + void *access_param_) { + struct file_info *key= key_; + struct st_access_param *access_param= access_param_; if (key->accessed < access_param->min_accessed && ! key->closed) { access_param->min_accessed=key->accessed; @@ -776,7 +779,7 @@ static int close_some_file(TREE *tree) access_param.min_accessed=LONG_MAX; access_param.found=0; - (void) tree_walk(tree,(tree_walk_action) test_when_accessed, + (void) tree_walk(tree, test_when_accessed, (void*) &access_param,left_root_right); if (!access_param.found) return 1; /* No open file that is possibly to close */ diff --git a/storage/myisam/myisampack.c b/storage/myisam/myisampack.c index c66dc01bcd5..77fdaf8e164 100644 --- a/storage/myisam/myisampack.c +++ b/storage/myisam/myisampack.c @@ -143,8 +143,8 @@ static int test_space_compress(HUFF_COUNTS *huff_counts,my_off_t records, 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, const void *a, const void *b); -static int save_counts_in_queue(uchar *key,element_count count, - HUFF_TREE *tree); +static int save_counts_in_queue(void *key, element_count count, + void *tree); static my_off_t calc_packed_length(HUFF_COUNTS *huff_counts,uint flag); static uint join_same_trees(HUFF_COUNTS *huff_counts,uint trees); static int make_huff_decode_table(HUFF_TREE *huff_tree,uint trees); @@ -1728,9 +1728,10 @@ static int compare_tree(void *cmp_arg __attribute__((unused)), const void *s_, 0 */ -static int save_counts_in_queue(uchar *key, element_count count, - HUFF_TREE *tree) +static int save_counts_in_queue(void *key_, element_count count, void *tree_) { + uchar *key= key_; + HUFF_TREE *tree= tree_; HUFF_ELEMENT *new_huff_el; new_huff_el=tree->element_buffer+(tree->elements++); From 78d7bb1d27daf8d86fae9c54dbfe35f803531c1e Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Sat, 26 Oct 2024 14:19:57 -0600 Subject: [PATCH 34/55] MDEV-34348: Miscellaneous fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Partial commit of the greater MDEV-34348 scope. MDEV-34348: MariaDB is violating clang-16 -Wcast-function-type-strict Various additional fixes, each too small to put into their own commit. Reviewed By: ============ Marko Mäkelä --- sql/sql_list.h | 9 ++++----- sql/sql_udf.h | 2 +- storage/csv/ha_tina.cc | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/sql/sql_list.h b/sql/sql_list.h index 277d5bc3808..8ec61bcd749 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -129,8 +129,6 @@ struct list_node :public Sql_alloc } }; -typedef bool List_eq(void *a, void *b); - extern MYSQL_PLUGIN_IMPORT list_node end_of_list; class base_list :public Sql_alloc @@ -301,11 +299,12 @@ public: inline void **head_ref() { return first != &end_of_list ? &first->info : 0; } inline bool is_empty() { return first == &end_of_list ; } inline list_node *last_ref() { return &end_of_list; } - inline bool add_unique(void *info, List_eq *eq) + template + inline bool add_unique(T *info, bool (*eq)(T *a, T *b)) { list_node *node= first; for (; - node != &end_of_list && (!(*eq)(node->info, info)); + node != &end_of_list && (!(*eq)(static_cast(node->info), info)); node= node->next) ; if (node == &end_of_list) return push_back(info); @@ -513,7 +512,7 @@ public: inline void prepend(List *list) { base_list::prepend(list); } inline void disjoin(List *list) { base_list::disjoin(list); } inline bool add_unique(T *a, bool (*eq)(T *a, T *b)) - { return base_list::add_unique(a, (List_eq *)eq); } + { return base_list::add_unique(a, eq); } inline bool copy(const List *list, MEM_ROOT *root) { return base_list::copy(list, root); } void delete_elements(void) diff --git a/sql/sql_udf.h b/sql/sql_udf.h index 5bd2c6e5445..83e2df48eda 100644 --- a/sql/sql_udf.h +++ b/sql/sql_udf.h @@ -30,7 +30,7 @@ typedef void (*Udf_func_clear)(UDF_INIT *, uchar *, uchar *); typedef void (*Udf_func_add)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *); typedef void (*Udf_func_deinit)(UDF_INIT*); typedef my_bool (*Udf_func_init)(UDF_INIT *, UDF_ARGS *, char *); -typedef void (*Udf_func_any)(); +typedef void *Udf_func_any; typedef double (*Udf_func_double)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *); typedef longlong (*Udf_func_longlong)(UDF_INIT *, UDF_ARGS *, uchar *, uchar *); diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index ef7865b366c..71c06776cfe 100644 --- a/storage/csv/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -183,7 +183,7 @@ static int tina_init_func(void *p) init_tina_psi_keys(); #endif - tina_hton= (handlerton *)p; + tina_hton= static_cast(p); mysql_mutex_init(csv_key_mutex_tina, &tina_mutex, MY_MUTEX_INIT_FAST); (void) my_hash_init(csv_key_memory_tina_share, &tina_open_tables, Lex_ident_table::charset_info(), 32, 0, 0, tina_get_key, From 971a0ba23c18d81f73076351cf426467282a1aef Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 14 Jun 2024 13:13:40 +1000 Subject: [PATCH 35/55] MDEV-34408: Facilitate the addition of warnings into the build system Create a MY_WARNING_FLAGS_NON_FATAL for testing warnings Add -Weffc++ as no-error espect, disabling from rocksdb due to excessive errors that will be corrected later. --- cmake/maintainer.cmake | 10 ++++++++++ storage/rocksdb/CMakeLists.txt | 1 + 2 files changed, 11 insertions(+) diff --git a/cmake/maintainer.cmake b/cmake/maintainer.cmake index 11d4b896f45..20cf377d5d9 100644 --- a/cmake/maintainer.cmake +++ b/cmake/maintainer.cmake @@ -41,10 +41,20 @@ SET(MY_WARNING_FLAGS -Wwrite-strings ) +# Warning flags that are in testing before moving +# to MY_WARNING_FLAGS if stable. +SET(MY_WARNING_FLAGS_NON_FATAL + effc++ + ) + FOREACH(F ${MY_WARNING_FLAGS}) MY_CHECK_AND_SET_COMPILER_FLAG(${F} DEBUG RELWITHDEBINFO) ENDFOREACH() +FOREACH(F ${MY_WARNING_FLAGS_NON_FATAL}) + MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-error=${F} DEBUG RELWITHDEBINFO) +ENDFOREACH() + SET(MY_ERROR_FLAGS -Werror -fno-operator-names) IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0.0") diff --git a/storage/rocksdb/CMakeLists.txt b/storage/rocksdb/CMakeLists.txt index 976b7fb2f51..629c71ec95f 100644 --- a/storage/rocksdb/CMakeLists.txt +++ b/storage/rocksdb/CMakeLists.txt @@ -10,6 +10,7 @@ SET(CPACK_RPM_rocksdb-engine_PACKAGE_DESCRIPTION "The RocksDB storage engine is at maximising storage efficiency while maintaining InnoDB-like performance." PARENT_SCOPE) MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-range-loop-construct) +MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-effc++ DEBUG RELWITHDEBINFO) MACRO(SKIP_ROCKSDB_PLUGIN msg) MESSAGE_ONCE(SKIP_ROCKSDB_PLUGIN "Can't build rocksdb engine - ${msg}") From 6456e437f2960fec3c231656829f02c9fb110ab3 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 9 Jul 2024 18:29:11 +1000 Subject: [PATCH 36/55] MDEV-34348: Add cast-function-type-strict to warnings --- cmake/maintainer.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/maintainer.cmake b/cmake/maintainer.cmake index 20cf377d5d9..cbfdab4413f 100644 --- a/cmake/maintainer.cmake +++ b/cmake/maintainer.cmake @@ -44,7 +44,7 @@ SET(MY_WARNING_FLAGS # Warning flags that are in testing before moving # to MY_WARNING_FLAGS if stable. SET(MY_WARNING_FLAGS_NON_FATAL - effc++ + cast-function-type-strict ) FOREACH(F ${MY_WARNING_FLAGS}) @@ -52,6 +52,7 @@ FOREACH(F ${MY_WARNING_FLAGS}) ENDFOREACH() FOREACH(F ${MY_WARNING_FLAGS_NON_FATAL}) + MY_CHECK_AND_SET_COMPILER_FLAG(-W${F} DEBUG RELWITHDEBINFO) MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-error=${F} DEBUG RELWITHDEBINFO) ENDFOREACH() From 773cb726a8437d911d3f7ceedf4839dab6124484 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Mon, 15 Jul 2024 07:54:38 -0600 Subject: [PATCH 37/55] MDEV-34348: MariaDB is violating clang-16 -Wcast-function-type-strict This HEAD commit just makes cast-function-type-strict fatal. It will stay at the HEAD, and prior commits contain the actual fixes, organized by the part of the code that the fix targets. Future changes will be force pushed to have their fixes come before this HEAD. This branch cherry-picks patches from daniel@mariadb.org (in bb-10.5-MDEV-34508-ubsan-errors) which initially incorporate the flag into the build, as well as fix some of its findings. --- cmake/maintainer.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/maintainer.cmake b/cmake/maintainer.cmake index cbfdab4413f..a728925721a 100644 --- a/cmake/maintainer.cmake +++ b/cmake/maintainer.cmake @@ -39,12 +39,12 @@ SET(MY_WARNING_FLAGS -Wsuggest-override -Wvla -Wwrite-strings + -Wcast-function-type-strict ) # Warning flags that are in testing before moving # to MY_WARNING_FLAGS if stable. SET(MY_WARNING_FLAGS_NON_FATAL - cast-function-type-strict ) FOREACH(F ${MY_WARNING_FLAGS}) From 2e404c98507740ebffcb23cfbf35d10c62916af5 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 12 Nov 2024 11:06:32 +0400 Subject: [PATCH 38/55] MDEV-21029 Incorrect result for expression with the <=> operator and IS NULL Item_func_equal erroneously derived is_null() from the parent class. Overriding it to return false because <=> can never return NULL. --- mysql-test/main/func_equal.result | 11 +++++++++++ mysql-test/main/func_equal.test | 15 +++++++++++++++ sql/item_cmpfunc.h | 1 + 3 files changed, 27 insertions(+) diff --git a/mysql-test/main/func_equal.result b/mysql-test/main/func_equal.result index f20b259191c..4f876b4f27b 100644 --- a/mysql-test/main/func_equal.result +++ b/mysql-test/main/func_equal.result @@ -43,3 +43,14 @@ a 4828532208463511553 drop table t1; #End of 4.1 tests +# Start of 10.5 tests +# +# MDEV-21029 Incorrect result for expression with the <=> operator and IS NULL +# +CREATE TABLE t0(c0 INT); +INSERT INTO t0 VALUES (1); +SELECT (c0 > (NULL <=> 0)) IS NULL AS c1 FROM t0; +c1 +0 +DROP TABLE t0; +# End of 10.5 tests diff --git a/mysql-test/main/func_equal.test b/mysql-test/main/func_equal.test index f17ebb5bd84..88cab9e95a0 100644 --- a/mysql-test/main/func_equal.test +++ b/mysql-test/main/func_equal.test @@ -44,3 +44,18 @@ select * from t1 where a in ('4828532208463511553'); drop table t1; --echo #End of 4.1 tests + + +--echo # Start of 10.5 tests + +--echo # +--echo # MDEV-21029 Incorrect result for expression with the <=> operator and IS NULL +--echo # + +CREATE TABLE t0(c0 INT); +INSERT INTO t0 VALUES (1); +SELECT (c0 > (NULL <=> 0)) IS NULL AS c1 FROM t0; +DROP TABLE t0; + + +--echo # End of 10.5 tests diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 1bc5f42ab2b..3d15a6f3dc1 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -782,6 +782,7 @@ public: enum Functype functype() const override { return EQUAL_FUNC; } enum Functype rev_functype() const override { return EQUAL_FUNC; } cond_result eq_cmp_result() const override { return COND_TRUE; } + bool is_null() override { return false; } const char *func_name() const override { return "<=>"; } Item *neg_transformer(THD *thd) override { return 0; } void add_key_fields(JOIN *join, KEY_FIELD **key_fields, From 20eba06d9b6ed88a02b425f1716ada15ffd745ba Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 25 Nov 2024 16:13:16 +0400 Subject: [PATCH 39/55] MDEV-35489 Assertion `!ldate->neg' or unexpected result upon extracting unit from invalid value The patch for MDEV-23687 easlier fixed this problem. Adding tests only. --- mysql-test/main/func_extract.result | 23 +++++++++++++++++++++++ mysql-test/main/func_extract.test | 10 ++++++++++ 2 files changed, 33 insertions(+) diff --git a/mysql-test/main/func_extract.result b/mysql-test/main/func_extract.result index 5c651d713ea..86b6f13a0ed 100644 --- a/mysql-test/main/func_extract.result +++ b/mysql-test/main/func_extract.result @@ -1503,5 +1503,28 @@ Warnings: Warning 1292 Incorrect datetime value: '100000:00:00' SET SESSION old_mode=DEFAULT; # +# MDEV-35489 Assertion `!ldate->neg' or unexpected result upon extracting unit from invalid value +# +SELECT EXTRACT(DAY FROM TIMESTAMP(-177498480000)); +EXTRACT(DAY FROM TIMESTAMP(-177498480000)) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '-177498480000' +SELECT EXTRACT(DAY FROM TIMESTAMP(-177498480001)); +EXTRACT(DAY FROM TIMESTAMP(-177498480001)) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '-177498480001' +SELECT EXTRACT(DAY FROM TIMESTAMP(-200000000000)); +EXTRACT(DAY FROM TIMESTAMP(-200000000000)) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '-200000000000' +SELECT EXTRACT(DAY FROM TIMESTAMP(-221938034527)); +EXTRACT(DAY FROM TIMESTAMP(-221938034527)) +NULL +Warnings: +Warning 1292 Incorrect datetime value: '-221938034527' +# # End of 10.5 tests # diff --git a/mysql-test/main/func_extract.test b/mysql-test/main/func_extract.test index 05c5529659b..234a65547f1 100644 --- a/mysql-test/main/func_extract.test +++ b/mysql-test/main/func_extract.test @@ -528,6 +528,16 @@ SELECT CAST('100000:00:00' AS DATE); SELECT EXTRACT(DAY FROM CAST('100000:00:00' AS DATE)); SET SESSION old_mode=DEFAULT; +--echo # +--echo # MDEV-35489 Assertion `!ldate->neg' or unexpected result upon extracting unit from invalid value +--echo # + +SELECT EXTRACT(DAY FROM TIMESTAMP(-177498480000)); +SELECT EXTRACT(DAY FROM TIMESTAMP(-177498480001)); +SELECT EXTRACT(DAY FROM TIMESTAMP(-200000000000)); +SELECT EXTRACT(DAY FROM TIMESTAMP(-221938034527)); + + --echo # --echo # End of 10.5 tests --echo # From 425d2521ec5967026b553aef43da65216d964812 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 12 Nov 2024 08:58:48 +0400 Subject: [PATCH 40/55] MDEV-33472 Assertion `0' failed in Item_row::illegal_method_call on CREATE EVENT Do not accept rows as event parameters. --- mysql-test/main/events_bugs.result | 11 +++++++++++ mysql-test/main/events_bugs.test | 17 +++++++++++++++++ sql/event_parse_data.cc | 27 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/mysql-test/main/events_bugs.result b/mysql-test/main/events_bugs.result index e3984bcd67a..d40bad9804a 100644 --- a/mysql-test/main/events_bugs.result +++ b/mysql-test/main/events_bugs.result @@ -869,3 +869,14 @@ USE test; DROP DATABASE events_test; SET GLOBAL event_scheduler= 'ON'; SET @@global.concurrent_insert= @concurrent_insert; +# +# MDEV-33472 Assertion `0' failed in Item_row::illegal_method_call on CREATE EVENT +# +CREATE EVENT e ON SCHEDULE EVERY 1 HOUR STARTS ROW(1,2) DO SELECT 1; +ERROR 21000: Operand should contain 1 column(s) +CREATE EVENT e ON SCHEDULE EVERY 1 HOUR ENDS ROW(1,2) DO SELECT 1; +ERROR 21000: Operand should contain 1 column(s) +CREATE EVENT e ON SCHEDULE AT ROW(1,2) DO SELECT *; +ERROR 21000: Operand should contain 1 column(s) +CREATE EVENT e ON SCHEDULE EVERY ROW(1,2) HOUR DO SELECT 1; +ERROR 21000: Operand should contain 1 column(s) diff --git a/mysql-test/main/events_bugs.test b/mysql-test/main/events_bugs.test index 3c4836af9e5..f0a429c1617 100644 --- a/mysql-test/main/events_bugs.test +++ b/mysql-test/main/events_bugs.test @@ -1308,3 +1308,20 @@ SET GLOBAL event_scheduler= 'ON'; --source include/running_event_scheduler.inc SET @@global.concurrent_insert= @concurrent_insert; # THIS MUST BE THE LAST LINE in this file. + + +--echo # +--echo # MDEV-33472 Assertion `0' failed in Item_row::illegal_method_call on CREATE EVENT +--echo # + +--error ER_OPERAND_COLUMNS +CREATE EVENT e ON SCHEDULE EVERY 1 HOUR STARTS ROW(1,2) DO SELECT 1; + +--error ER_OPERAND_COLUMNS +CREATE EVENT e ON SCHEDULE EVERY 1 HOUR ENDS ROW(1,2) DO SELECT 1; + +--error ER_OPERAND_COLUMNS +CREATE EVENT e ON SCHEDULE AT ROW(1,2) DO SELECT *; + +--error ER_OPERAND_COLUMNS +CREATE EVENT e ON SCHEDULE EVERY ROW(1,2) HOUR DO SELECT 1; diff --git a/sql/event_parse_data.cc b/sql/event_parse_data.cc index d2a168e538e..fb3197db2b0 100644 --- a/sql/event_parse_data.cc +++ b/sql/event_parse_data.cc @@ -211,6 +211,12 @@ Event_parse_data::init_execute_at(THD *thd) if (item_execute_at->fix_fields(thd, &item_execute_at)) goto wrong_value; + if (item_execute_at->check_cols(1)) + { + // Don't go to wrong_value, it will call val_str() and hit DBUG_ASSERT(0) + DBUG_RETURN(ER_WRONG_VALUE); + } + /* no starts and/or ends in case of execute_at */ DBUG_PRINT("info", ("starts_null && ends_null should be 1 is %d", (starts_null && ends_null))); @@ -281,6 +287,12 @@ Event_parse_data::init_interval(THD *thd) if (item_expression->fix_fields(thd, &item_expression)) goto wrong_value; + if (item_expression->check_cols(1)) + { + // Don't go to wrong_value, it will call val_str() and hit DBUG_ASSERT(0) + DBUG_RETURN(ER_WRONG_VALUE); + } + if (get_interval_value(thd, item_expression, interval, &interval_tmp)) goto wrong_value; @@ -384,6 +396,12 @@ Event_parse_data::init_starts(THD *thd) if (item_starts->fix_fields(thd, &item_starts)) goto wrong_value; + if (item_starts->check_cols(1)) + { + // Don't go to wrong_value, it will call val_str() and hit DBUG_ASSERT(0) + DBUG_RETURN(ER_WRONG_VALUE); + } + if (item_starts->get_date(thd, <ime, TIME_NO_ZERO_DATE | thd->temporal_round_mode())) goto wrong_value; @@ -439,6 +457,15 @@ Event_parse_data::init_ends(THD *thd) if (item_ends->fix_fields(thd, &item_ends)) goto error_bad_params; + if (item_ends->check_cols(1)) + { + /* + Don't go to error_bad_params it will call val_str() and + hit DBUG_ASSERT(0) + */ + DBUG_RETURN(EVEX_BAD_PARAMS); + } + DBUG_PRINT("info", ("convert to TIME")); if (item_ends->get_date(thd, <ime, TIME_NO_ZERO_DATE | thd->temporal_round_mode())) From 225c17d35cc03e4eda64f6a6b92d4ec46ab7be43 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 7 Nov 2024 12:16:33 +0400 Subject: [PATCH 41/55] MDEV-34090 Client allows to set character set to utf32 and crashes on the next command Disallowing character sets with mbminlen>1 in the client. --- client/mysql.cc | 3 +++ mysql-test/main/mysql_not_windows.result | 8 ++++++++ mysql-test/main/mysql_not_windows.test | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/client/mysql.cc b/client/mysql.cc index aadfa72fcf7..0d41ab928ec 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -3292,6 +3292,9 @@ static int com_charset(String *, char *line) new_cs= get_charset_by_csname(param, MY_CS_PRIMARY, MYF(MY_WME)); if (new_cs) { + if (new_cs->mbminlen > 1) + return put_info("Character sets with mbminlen>1 are not supported", + INFO_ERROR, 0); charset_info= new_cs; mysql_set_character_set(&mysql, charset_info->csname); default_charset= (char *)charset_info->csname; diff --git a/mysql-test/main/mysql_not_windows.result b/mysql-test/main/mysql_not_windows.result index 96210a366a6..1f76491d5eb 100644 --- a/mysql-test/main/mysql_not_windows.result +++ b/mysql-test/main/mysql_not_windows.result @@ -11,3 +11,11 @@ X 3 ERROR 1300 (HY000): Invalid utf8 character string: 'test\xF0\x9F\x98\x81 ' ERROR 1300 (HY000): Invalid binary character string: 'test\xF0\x9F\x98\x81 ' +# Start of 10.5 tests +# +# MDEV-34090 Client allows to set character set to utf32 and crashes on the next command +# +SELECT "Success" AS c1; +c1 +Success +# End of 10.5 tests diff --git a/mysql-test/main/mysql_not_windows.test b/mysql-test/main/mysql_not_windows.test index 816160c4f3e..00d8ed8c4f9 100644 --- a/mysql-test/main/mysql_not_windows.test +++ b/mysql-test/main/mysql_not_windows.test @@ -29,3 +29,16 @@ exec $MYSQL test -e "$query"; --exec $MYSQL --default-character-set=utf8 -e "select 1" "test😁 " 2>&1 --error 1 --exec $MYSQL --default-character-set=binary -e "select 1" "test😁 " 2>&1 + + +--echo # Start of 10.5 tests + +--echo # +--echo # MDEV-34090 Client allows to set character set to utf32 and crashes on the next command +--echo # + +--error 1 +--exec $MYSQL test -e '\C utf32 ; SELECT 1' +SELECT "Success" AS c1; + +--echo # End of 10.5 tests From f09020b3bb392bd27887f238ded959911cd8a3ab Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 25 Nov 2024 10:28:44 +0200 Subject: [PATCH 42/55] Fixed bug in subselect3.inc (not notable) --- mysql-test/main/subselect3.inc | 2 +- mysql-test/main/subselect3.result | 2 +- mysql-test/main/subselect3_jcl6.result | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/subselect3.inc b/mysql-test/main/subselect3.inc index 6516c6a6ef0..0f943a6c6ff 100644 --- a/mysql-test/main/subselect3.inc +++ b/mysql-test/main/subselect3.inc @@ -998,7 +998,7 @@ select count(*) from t0 A, t0 B, t0 C, t0 D where D.a in (select a from t1 E whe --enable_ps2_protocol show status like 'Created_tmp_disk_tables'; --enable_cursor_protocol -set @save_max_heap_table_size=@@max_heap_table_size; +set @@max_heap_table_size=@save_max_heap_table_size; set @@optimizer_switch=@save_optimizer_switch; drop table t0, t1; diff --git a/mysql-test/main/subselect3.result b/mysql-test/main/subselect3.result index ebae260fdc5..48d53a8bd3e 100644 --- a/mysql-test/main/subselect3.result +++ b/mysql-test/main/subselect3.result @@ -1169,7 +1169,7 @@ count(*) show status like 'Created_tmp_disk_tables'; Variable_name Value Created_tmp_disk_tables 1 -set @save_max_heap_table_size=@@max_heap_table_size; +set @@max_heap_table_size=@save_max_heap_table_size; set @@optimizer_switch=@save_optimizer_switch; drop table t0, t1; create table t0 (a int); diff --git a/mysql-test/main/subselect3_jcl6.result b/mysql-test/main/subselect3_jcl6.result index 854793442c6..5df46b543aa 100644 --- a/mysql-test/main/subselect3_jcl6.result +++ b/mysql-test/main/subselect3_jcl6.result @@ -1172,7 +1172,7 @@ count(*) show status like 'Created_tmp_disk_tables'; Variable_name Value Created_tmp_disk_tables 1 -set @save_max_heap_table_size=@@max_heap_table_size; +set @@max_heap_table_size=@save_max_heap_table_size; set @@optimizer_switch=@save_optimizer_switch; drop table t0, t1; create table t0 (a int); From 142851f1205d98270b917a98e1bdd483e1b8af0e Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 25 Nov 2024 10:31:37 +0200 Subject: [PATCH 43/55] Update my_print_defaults to accept --mariadbd as an option --mariadbd and --mysqld are now synonymes for my_print_defaults Other things - Removed safemalloc warnings when using an unknown argument to my_print_defaults --- extra/my_print_defaults.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c index 70eab12dcc2..2c8755b3917 100644 --- a/extra/my_print_defaults.c +++ b/extra/my_print_defaults.c @@ -62,7 +62,9 @@ static struct my_option my_long_options[] = "In addition to the given groups, read also groups with this suffix", (char**) &my_defaults_group_suffix, (char**) &my_defaults_group_suffix, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"mysqld", 0, "Read the same set of groups that the mysqld binary does.", + {"mysqld", 0, "Read the same set of groups that the mariadbd (previously known as mysqld) binary does.", + &opt_mysqld, &opt_mysqld, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"mariadbd", 0, "Read the same set of groups that the mariadbd binary does.", &opt_mysqld, &opt_mysqld, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"no-defaults", 'n', "Return an empty string (useful for scripts).", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -84,7 +86,7 @@ static void cleanup_and_exit(int exit_code) static void version() { - printf("%s Ver 1.7 for %s at %s\n",my_progname,SYSTEM_TYPE, MACHINE_TYPE); + printf("%s Ver 1.8 for %s at %s\n",my_progname,SYSTEM_TYPE, MACHINE_TYPE); } @@ -136,7 +138,7 @@ static int get_options(int *argc,char ***argv) int ho_error; if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) - exit(ho_error); + cleanup_and_exit(ho_error); return 0; } @@ -195,7 +197,8 @@ int main(int argc, char **argv) load_default_groups=(char**) my_malloc(PSI_NOT_INSTRUMENTED, nargs*sizeof(char*), MYF(MY_WME)); if (!load_default_groups) - exit(1); + cleanup_and_exit(1); + if (opt_mysqld) { for (; mysqld_groups[i]; i++) From a8cc40d9a42e69cc39242f0a2824cd9cdd852a80 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Fri, 4 Oct 2024 16:49:53 +1000 Subject: [PATCH 44/55] MDEV-35064 Reduce the default spider connect retry counts to 2 The existing default value 1000 is too big and could result in "hanging" when failing to connect a remote server. Three tries in total is a more sensible default. --- .../spider/bugfix/r/mdev_35064.result | 14 +++++++++++++ .../spider/bugfix/t/mdev_35064.test | 20 +++++++++++++++++++ storage/spider/spd_db_mysql.cc | 2 +- storage/spider/spd_param.cc | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_35064.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_35064.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_35064.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_35064.result new file mode 100644 index 00000000000..ee13fe625ee --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_35064.result @@ -0,0 +1,14 @@ +for master_1 +for child2 +for child3 +CREATE SERVER s FOREIGN DATA WRAPPER mysql OPTIONS(HOST '1'); +CREATE TABLE t(c INT)ENGINE=Spider COMMENT='WRAPPER "mysql",SRV "s",TABLE "foo"'; +INSERT INTO t VALUES(1); +ERROR HY000: Unable to connect to foreign data source: s +INSERT INTO t VALUES(1); +ERROR HY000: Unable to connect to foreign data source: s +drop table t; +drop server s; +for master_1 +for child2 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_35064.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_35064.test new file mode 100644 index 00000000000..fcf2bb361af --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_35064.test @@ -0,0 +1,20 @@ +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +CREATE SERVER s FOREIGN DATA WRAPPER mysql OPTIONS(HOST '1'); +CREATE TABLE t(c INT)ENGINE=Spider COMMENT='WRAPPER "mysql",SRV "s",TABLE "foo"'; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +INSERT INTO t VALUES(1); +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +INSERT INTO t VALUES(1); # Hangs +drop table t; +drop server s; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 0cb4b657a2b..4b232c18166 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -2042,7 +2042,7 @@ int spider_db_mbase::connect( DBUG_RETURN(ER_CONNECT_TO_FOREIGN_DATA_SOURCE); } connect_retry_count--; - my_sleep((ulong) connect_retry_interval); + my_sleep((ulong) connect_retry_interval * 1000); } else { db_conn->net.thd = NULL; if (connect_mutex) diff --git a/storage/spider/spd_param.cc b/storage/spider/spd_param.cc index 55842682782..1913e6f91c7 100644 --- a/storage/spider/spd_param.cc +++ b/storage/spider/spd_param.cc @@ -1803,7 +1803,7 @@ static MYSQL_THDVAR_INT( "Connect retry count", /* comment */ NULL, /* check */ NULL, /* update */ - 1000, /* def */ + 2, /* def */ 0, /* min */ 2147483647, /* max */ 0 /* blk */ From 5be859d52ccefcd8d63ff5b00167383e4d9837df Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 27 Nov 2024 10:25:09 +1100 Subject: [PATCH 45/55] MDEV-30649 Adding a spider testcase showing copying from a remote to a local table Also deleted some trailing whitespace in mdev_30191.test. --- .../spider/bugfix/r/mdev_30649.result | 45 ++++++++++++++++++ .../mysql-test/spider/bugfix/t/mdev_30649.cnf | 3 ++ .../spider/bugfix/t/mdev_30649.test | 47 +++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_30649.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_30649.cnf create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_30649.test diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_30649.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_30649.result new file mode 100644 index 00000000000..45f097d9705 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_30649.result @@ -0,0 +1,45 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 +connection child2_1; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +CREATE TABLE src (c INT, d DATE, PRIMARY KEY(c)); +INSERT INTO src VALUES (42, '2024-08-27'), (73, '2024-07-12'); +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +SET spider_same_server_link=1; +CREATE TABLE dst (c INT, d DATE, PRIMARY KEY(c)) ENGINE=INNODB; +INSERT INTO dst VALUES (555, '1999-12-12'); +CREATE TABLE t (c INT, d DATE, PRIMARY KEY(c)) ENGINE=SPIDER +COMMENT='table "src dst", srv "s_2_1 s_1"'; +SELECT spider_copy_tables('t', '0', '1'); +spider_copy_tables('t', '0', '1') +1 +SELECT * FROM dst; +c d +42 2024-08-27 +73 2024-07-12 +555 1999-12-12 +connection child2_1; +DROP TABLE src; +DROP DATABASE auto_test_remote; +connection master_1; +DROP TABLE t; +SELECT * FROM dst; +c d +42 2024-08-27 +73 2024-07-12 +555 1999-12-12 +DROP TABLE dst; +DROP DATABASE auto_test_local; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_30649.cnf b/storage/spider/mysql-test/spider/bugfix/t/mdev_30649.cnf new file mode 100644 index 00000000000..05dfd8a0bce --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_30649.cnf @@ -0,0 +1,3 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_30649.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_30649.test new file mode 100644 index 00000000000..02df6032887 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_30649.test @@ -0,0 +1,47 @@ +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +--enable_result_log +--enable_query_log + +--connection child2_1 +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +# works without primary key +CREATE TABLE src (c INT, d DATE, PRIMARY KEY(c)); +INSERT INTO src VALUES (42, '2024-08-27'), (73, '2024-07-12'); + +--connection master_1 +CREATE DATABASE auto_test_local; +USE auto_test_local; +SET spider_same_server_link=1; + +# works without primary key +CREATE TABLE dst (c INT, d DATE, PRIMARY KEY(c)) ENGINE=INNODB; +INSERT INTO dst VALUES (555, '1999-12-12'); + +# requires primary key, but it is ok if the data node tables have no +# primary key and the corresponding column has duplicate values. +# possibly a bug, e.g. an unnecessary requirement. +evalp CREATE TABLE t (c INT, d DATE, PRIMARY KEY(c)) ENGINE=SPIDER +COMMENT='table "src dst", srv "s_2_1 s_1"'; +SELECT spider_copy_tables('t', '0', '1'); + +SELECT * FROM dst; + +--connection child2_1 +DROP TABLE src; +DROP DATABASE auto_test_remote; + +--connection master_1 + +DROP TABLE t; +SELECT * FROM dst; +DROP TABLE dst; +DROP DATABASE auto_test_local; + +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log From 490274e85036789024e33bfd54a33f808f00b6e1 Mon Sep 17 00:00:00 2001 From: Ivan Prisyazhnyy Date: Sun, 18 Aug 2024 21:40:34 +0200 Subject: [PATCH 46/55] MDEV-33075 [backport/2f5174e556] eliminated support for `#ifndef HAVE_POLL` Backport of 2f5174e556cd247133aa14d7b37372ae49fe83c5: MDEV-33075 Resolve server shutdown issues on macOS, Solaris, and FreeBSD. Eliminated support for `#ifndef HAVE_POLL` in `handle_connection_sockets` This code is also dead, since 10.4 Signed-off-by: Ivan Prisyazhnyy --- sql/mysqld.cc | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index b940a40afbf..acc40691186 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -6270,7 +6270,6 @@ void handle_connections_sockets() uint error_count=0; struct sockaddr_storage cAddr; int retval; -#ifdef HAVE_POLL int socket_count= 0; struct pollfd fds[3]; // for ip_sock, unix_sock and extra_ip_sock MYSQL_SOCKET pfs_fds[3]; // for performance schema @@ -6280,11 +6279,6 @@ void handle_connections_sockets() fds[socket_count].fd= mysql_socket_getfd(X); \ fds[socket_count].events= POLLIN; \ socket_count++ -#else -#define setup_fds(X) FD_SET(mysql_socket_getfd(X),&clientFDs) - fd_set readFDs,clientFDs; - FD_ZERO(&clientFDs); -#endif DBUG_ENTER("handle_connections_sockets"); @@ -6309,12 +6303,7 @@ void handle_connections_sockets() DBUG_PRINT("general",("Waiting for connections.")); while (!abort_loop) { -#ifdef HAVE_POLL retval= poll(fds, socket_count, -1); -#else - readFDs=clientFDs; - retval= select((int) 0,&readFDs,0,0,0); -#endif if (retval < 0) { @@ -6336,7 +6325,6 @@ void handle_connections_sockets() break; /* Is this a new connection request ? */ -#ifdef HAVE_POLL for (int i= 0; i < socket_count; ++i) { if (fds[i].revents & POLLIN) @@ -6345,15 +6333,6 @@ void handle_connections_sockets() break; } } -#else // HAVE_POLL - if (FD_ISSET(mysql_socket_getfd(base_ip_sock),&readFDs)) - sock= base_ip_sock; - else - if (FD_ISSET(mysql_socket_getfd(extra_ip_sock),&readFDs)) - sock= extra_ip_sock; - else - sock = unix_sock; -#endif // HAVE_POLL for (uint retry=0; retry < MAX_ACCEPT_RETRY && !abort_loop; retry++) { From 821470769996f787ef54f6c8d74bd12f6e11664d Mon Sep 17 00:00:00 2001 From: Ivan Prisyazhnyy Date: Tue, 13 Aug 2024 15:43:33 +0200 Subject: [PATCH 47/55] MDEV-33075 [backport/2f5174e556] fix signal handler thread exit on abort Backport of 2f5174e556cd247133aa14d7b37372ae49fe83c5: MDEV-33075 Resolve server shutdown issues on macOS, Solaris, and FreeBSD. This commit addresses multiple server shutdown problems observed on macOS, Solaris, and FreeBSD: 3. Made sure, that signal handler thread always exits once `abort_loop` is set, and also calls `my_thread_end()` and clears `signal_thread_in_use` when exiting. This fixes warning "1 thread did not exit" by `my_global_thread_end()` seen on FreeBSD/macOS when the process is terminated via signal. Additionally, the shutdown code underwent light refactoring for better readability and maintainability: - Removed dead code related to the unused `USE_ONE_SIGNAL_HAND` preprocessor constant. Signed-off-by: Ivan Prisyazhnyy --- sql/mysqld.cc | 55 +++++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index acc40691186..99dbbc189b4 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2960,23 +2960,14 @@ static void start_signal_handler(void) DBUG_VOID_RETURN; } -/** Called only from signal_hand function. */ -static void* exit_signal_handler() -{ - my_thread_end(); - signal_thread_in_use= 0; - pthread_exit(0); // Safety - return nullptr; // Avoid compiler warnings -} - - -/** This threads handles all signals and alarms. */ +/** This threads handles all signals */ /* ARGSUSED */ -pthread_handler_t signal_hand(void *arg __attribute__((unused))) +pthread_handler_t signal_hand(void *) { sigset_t set; int sig; my_thread_init(); // Init new thread + DBUG_ENTER("signal_hand"); signal_thread_in_use= 1; /* @@ -3025,16 +3016,17 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) int error; int origin; - while ((error= my_sigwait(&set, &sig, &origin)) == EINTR) /* no-op */; if (abort_loop) - { - DBUG_PRINT("quit",("signal_handler: calling my_thread_end()")); - return exit_signal_handler(); - } + break; + + while ((error= my_sigwait(&set, &sig, &origin)) == EINTR) /* no-op */; + + if (abort_loop) + break; + switch (sig) { case SIGTERM: case SIGQUIT: - case SIGKILL: #ifdef EXTRA_DEBUG sql_print_information("Got signal %d to shutdown mysqld",sig); #endif @@ -3042,22 +3034,15 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) logger.set_handlers(global_system_variables.sql_log_slow ? LOG_FILE:LOG_NONE, opt_log ? LOG_FILE:LOG_NONE); DBUG_PRINT("info",("Got signal: %d abort_loop: %d",sig,abort_loop)); - if (!abort_loop) - { - /* Delete the instrumentation for the signal thread */ - PSI_CALL_delete_current_thread(); - my_sigset(sig, SIG_IGN); - break_connect_loop(); // MIT THREAD has a alarm thread - return exit_signal_handler(); - } + + break_connect_loop(); + DBUG_ASSERT(abort_loop); break; case SIGHUP: #if defined(SI_KERNEL) - if (!abort_loop && origin != SI_KERNEL) + if (origin != SI_KERNEL) #elif defined(SI_USER) - if (!abort_loop && origin <= SI_USER) -#else - if (!abort_loop) + if (origin <= SI_USER) #endif { int not_used; @@ -3077,11 +3062,6 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) opt_log ? fixed_log_output_options : LOG_NONE); } break; -#ifdef USE_ONE_SIGNAL_HAND - case THR_SERVER_ALARM: - process_alarm(sig); // Trigger alarms. - break; -#endif default: #ifdef EXTRA_DEBUG sql_print_warning("Got signal: %d error: %d",sig,error); /* purecov: tested */ @@ -3089,6 +3069,11 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) break; /* purecov: tested */ } } + DBUG_PRINT("quit", ("signal_handler: calling my_thread_end()")); + my_thread_end(); + DBUG_LEAVE; // Must match DBUG_ENTER() + signal_thread_in_use= 0; + pthread_exit(0); // Safety return(0); /* purecov: deadcode */ } From c4cadb768f66748a77475eb32529d5c99e649f09 Mon Sep 17 00:00:00 2001 From: Ivan Prisyazhnyy Date: Tue, 13 Aug 2024 15:53:42 +0200 Subject: [PATCH 48/55] MDEV-33075 [backport/2f5174e556] fix rnd crash on macOS from pthread_kill(signal_handler) Backport of 2f5174e556cd247133aa14d7b37372ae49fe83c5: MDEV-33075 Resolve server shutdown issues on macOS, Solaris, and FreeBSD. This commit addresses multiple server shutdown problems observed on macOS, Solaris, and FreeBSD: 2. Fixed a random crash on macOS from pthread_kill(signal_handler) when the signal_handler was detached and the thread had already exited. Use more robust `kill(getpid(), SIGTERM)` to wake up the signal handler thread. Additionally, the shutdown code underwent light refactoring for better readability and maintainability: - Modified `break_connect_loop()` to no longer wait for the main thread, aligning behavior with Windows (since 10.4). --- sql/mysqld.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 99dbbc189b4..7120e01c45d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2091,6 +2091,7 @@ static void clean_up(bool print_message) */ static void wait_for_signal_thread_to_end() { +#ifndef _WIN32 uint i, n_waits= DBUG_EVALUATE("force_sighup_processing_timeout", 5, 100); int err= 0; /* @@ -2099,9 +2100,7 @@ static void wait_for_signal_thread_to_end() */ for (i= 0 ; i < n_waits && signal_thread_in_use; i++) { - err= pthread_kill(signal_thread, MYSQL_KILL_SIGNAL); - if (err) - break; + kill(getpid(), MYSQL_KILL_SIGNAL); my_sleep(100000); // Give it time to die, .1s per iteration } @@ -2118,6 +2117,7 @@ static void wait_for_signal_thread_to_end() "Continuing to wait for it to stop.."); pthread_join(signal_thread, NULL); } +#endif } #endif /*EMBEDDED_LIBRARY*/ From f39a61505f1f3fb82af480e8020c02bccd84d9e7 Mon Sep 17 00:00:00 2001 From: Ivan Prisyazhnyy Date: Tue, 13 Aug 2024 15:56:03 +0200 Subject: [PATCH 49/55] MDEV-33075 [backport/2f5174e556] use more robust self-pipe to wake up poll() in break_connect_loop() Backport of 2f5174e556cd247133aa14d7b37372ae49fe83c5: MDEV-33075 Resolve server shutdown issues on macOS, Solaris, and FreeBSD. This commit addresses multiple server shutdown problems observed on macOS, Solaris, and FreeBSD: 1. Corrected a non-portable assumption where socket shutdown was expected to wake up poll() with listening sockets in the main thread. Use more robust self-pipe to wake up poll() by writing to the pipe's write end. Signed-off-by: Ivan Prisyazhnyy --- sql/mysqld.cc | 74 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 7120e01c45d..dd2d9df4c1c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1343,6 +1343,11 @@ struct my_rnd_struct sql_rand; ///< used by sql_class.cc:THD::THD() #ifndef EMBEDDED_LIBRARY MYSQL_SOCKET unix_sock, base_ip_sock, extra_ip_sock; + +/** wakeup listening(main) thread by writing to this descriptor */ +static int termination_event_fd= -1; + + C_MODE_START #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE /** @@ -1615,45 +1620,21 @@ static my_bool warn_threads_active_after_phase_2(THD *thd, void *) static void break_connect_loop() { -#ifdef EXTRA_DEBUG - int count=0; -#endif - abort_loop= 1; #if defined(__WIN__) if (!SetEvent(hEventShutdown)) DBUG_PRINT("error", ("Got error: %ld from SetEvent", GetLastError())); #else - /* Avoid waiting for ourselves when thread-handling=no-threads. */ - if (pthread_equal(pthread_self(), select_thread)) - return; - DBUG_PRINT("quit", ("waiting for select thread: %lu", - (ulong)select_thread)); - mysql_mutex_lock(&LOCK_start_thread); - while (select_thread_in_use) + if (termination_event_fd >= 0) { - struct timespec abstime; - int UNINIT_VAR(error); - DBUG_PRINT("info",("Waiting for select thread")); - -#ifndef DONT_USE_THR_ALARM - if (pthread_kill(select_thread, thr_client_alarm)) - break; // allready dead -#endif - set_timespec(abstime, 2); - for (uint tmp=0 ; tmp < 10 && select_thread_in_use; tmp++) + uint64_t u= 1; + if(write(termination_event_fd, &u, sizeof(uint64_t)) < 0) { - error= mysql_cond_timedwait(&COND_start_thread, &LOCK_start_thread, - &abstime); - if (error != EINTR) - break; + sql_print_error("Couldn't send event to terminate listen loop"); + abort(); } -#ifdef EXTRA_DEBUG - if (error != 0 && error != ETIMEDOUT && !count++) - sql_print_error("Got error %d from mysql_cond_timedwait", error); -#endif close_server_sock(); } mysql_mutex_unlock(&LOCK_start_thread); @@ -6256,8 +6237,8 @@ void handle_connections_sockets() struct sockaddr_storage cAddr; int retval; int socket_count= 0; - struct pollfd fds[3]; // for ip_sock, unix_sock and extra_ip_sock - MYSQL_SOCKET pfs_fds[3]; // for performance schema + struct pollfd fds[4]; // for ip_sock, unix_sock, extra_ip_sock and termination_fd + MYSQL_SOCKET pfs_fds[4]; // for performance schema #define setup_fds(X) \ mysql_socket_set_thread_owner(X); \ pfs_fds[socket_count]= (X); \ @@ -6281,6 +6262,31 @@ void handle_connections_sockets() setup_fds(unix_sock); set_non_blocking_if_supported(unix_sock); #endif + int termination_fds[2]; + if (pipe(termination_fds)) + { + sql_print_error("pipe() failed %d", errno); + DBUG_VOID_RETURN; + } +#ifdef FD_CLOEXEC + for (int fd : termination_fds) + (void)fcntl(fd, F_SETFD, FD_CLOEXEC); +#endif + + mysql_mutex_lock(&LOCK_start_thread); + termination_event_fd= termination_fds[1]; + mysql_mutex_unlock(&LOCK_start_thread); + + struct pollfd event_fd; + event_fd.fd= termination_fds[0]; + event_fd.events= POLLIN; + MYSQL_SOCKET event_socket; + event_socket.fd= event_fd.fd; + event_socket.m_psi= NULL; + set_non_blocking_if_supported(event_socket); + pfs_fds[socket_count]= event_socket; + fds[socket_count]= event_fd; + socket_count++; sd_notify(0, "READY=1\n" "STATUS=Taking your SQL requests now...\n"); @@ -6347,6 +6353,12 @@ void handle_connections_sockets() } } } + mysql_mutex_lock(&LOCK_start_thread); + for(int fd : termination_fds) + close(fd); + termination_event_fd= -1; + mysql_mutex_unlock(&LOCK_start_thread); + sd_notify(0, "STOPPING=1\n" "STATUS=Shutdown in progress\n"); DBUG_VOID_RETURN; From 0ea19c12fdd9ed6b6c00f4493033d0433f110e71 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 27 Nov 2024 14:40:02 +0100 Subject: [PATCH 50/55] MDEV-35507 ed25519 authentication plugin create user statement trigger plain text password in audit log Mask also all cases of "password(PWD" in CREATE/ALTER USER and GRANT. (minimal fix) --- .../plugins/r/server_audit_pwd_mask.result | 22 ++++++++ .../plugins/t/server_audit_pwd_mask.test | 46 ++++++++++++++++ plugin/server_audit/server_audit.c | 55 ++++++++++++++++--- 3 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 mysql-test/suite/plugins/r/server_audit_pwd_mask.result create mode 100644 mysql-test/suite/plugins/t/server_audit_pwd_mask.test diff --git a/mysql-test/suite/plugins/r/server_audit_pwd_mask.result b/mysql-test/suite/plugins/r/server_audit_pwd_mask.result new file mode 100644 index 00000000000..7cf3b05bcf1 --- /dev/null +++ b/mysql-test/suite/plugins/r/server_audit_pwd_mask.result @@ -0,0 +1,22 @@ +install plugin ed25519 soname 'auth_ed25519'; +install plugin server_audit soname 'server_audit'; +set global server_audit_file_path='server_audit.log'; +set global server_audit_output_type=file; +set global server_audit_logging=on; +# unsafe to log passwords (pwd-123) +CREATE USER u1 IDENTIFIED BY 'pwd_123'; +create user u2 IDENTIFIED VIA ed25519 USING PASSWORD('pwd_123'); +SET PASSWORD FOR u1 = PASSWORD('pwd_123'); +ALTER USER u1 IDENTIFIED BY 'pwd_123'; +alter user u2 identified VIA ed25519 USING password('pwd_123'); +GRANT ALL ON test TO u1 IDENTIFIED BY "pwd_123"; +GRANT ALL ON test TO u1 identified VIA ed25519 as password('pwd_123') or ed25519 using password('pwd_123'); +# pattern should not be found +NOT FOUND /pwd_123/ in server_audit.log +# pattern should not be found +# cleaunup +DROP USER u1; +DROP USER u2; +set global server_audit_logging=off; +UNINSTALL PLUGIN ed25519; +UNINSTALL PLUGIN server_audit; diff --git a/mysql-test/suite/plugins/t/server_audit_pwd_mask.test b/mysql-test/suite/plugins/t/server_audit_pwd_mask.test new file mode 100644 index 00000000000..af6425b2035 --- /dev/null +++ b/mysql-test/suite/plugins/t/server_audit_pwd_mask.test @@ -0,0 +1,46 @@ + +--source include/have_plugin_auth.inc +--source include/not_embedded.inc + +if (!$SERVER_AUDIT_SO) { + skip No SERVER_AUDIT plugin; +} +if (!$AUTH_ED25519_SO) { + skip No auth_ed25519 plugin; +} +--disable_ps2_protocol + +let $MYSQLD_DATADIR= `SELECT @@datadir`; +let SEARCH_FILE= $MYSQLD_DATADIR/server_audit.log; + +install plugin ed25519 soname 'auth_ed25519'; +install plugin server_audit soname 'server_audit'; + + +set global server_audit_file_path='server_audit.log'; +set global server_audit_output_type=file; +set global server_audit_logging=on; + +--echo # unsafe to log passwords (pwd-123) + +CREATE USER u1 IDENTIFIED BY 'pwd_123'; +create user u2 IDENTIFIED VIA ed25519 USING PASSWORD('pwd_123'); +SET PASSWORD FOR u1 = PASSWORD('pwd_123'); +ALTER USER u1 IDENTIFIED BY 'pwd_123'; +alter user u2 identified VIA ed25519 USING password('pwd_123'); +GRANT ALL ON test TO u1 IDENTIFIED BY "pwd_123"; +GRANT ALL ON test TO u1 identified VIA ed25519 as password('pwd_123') or ed25519 using password('pwd_123'); +--let SEARCH_PATTERN=pwd_123 +--echo # pattern should not be found +--source include/search_pattern_in_file.inc +--echo # pattern should not be found + +--echo # cleaunup +DROP USER u1; +DROP USER u2; +set global server_audit_logging=off; +--remove_file $SEARCH_FILE +--disable_warnings +UNINSTALL PLUGIN ed25519; +UNINSTALL PLUGIN server_audit; +--enable_warnings diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index e45282c6e20..2de27215ed9 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -1512,12 +1512,33 @@ static size_t escape_string(const char *str, unsigned int len, return result - res_start; } +/* + Replace "password" with "*****" in + + "password" + + if is 0 + + "password" + + or + + "password" + + if is 0 + + "password" + + NOTE: there can be " or ' around the password, the words are case + insensitive. +*/ static size_t escape_string_hide_passwords(const char *str, unsigned int len, char *result, size_t result_len, const char *word1, size_t word1_len, const char *word2, size_t word2_len, - int next_text_string) + const char *word0, size_t word0_len, + char chr0) { const char *res_start= result; const char *res_end= result + result_len - 2; @@ -1525,18 +1546,32 @@ static size_t escape_string_hide_passwords(const char *str, unsigned int len, while (len) { - if (len > word1_len + 1 && strncasecmp(str, word1, word1_len) == 0) + int word1_found= (word1 && len > word1_len + 1 && + strncasecmp(str, word1, word1_len) == 0); + int word0_found= (word0 && len > word0_len + 1 && + strncasecmp(str, word0, word0_len) == 0); + if (word1_found || word0_found) { - const char *next_s= str + word1_len; + const char *next_s; size_t c; - if (next_text_string) + if (word0_found) { + next_s= str + word0_len; + if (chr0) + { + SKIP_SPACES(next_s); + if (len < (size_t)(next_s - str) + 1 + 1 || + next_s[0] != chr0) + goto no_password; + next_s++; + } while (*next_s && *next_s != '\'' && *next_s != '"') ++next_s; } else { + next_s= str + word1_len; if (word2) { SKIP_SPACES(next_s); @@ -1851,23 +1886,27 @@ do_log_query: case SQLCOM_ALTER_USER: csize+= escape_string_hide_passwords(query, query_len, uh_buffer, uh_buffer_size, - "IDENTIFIED", 10, "BY", 2, 0); + "IDENTIFIED", 10, "BY", 2, + "PASSWORD", 8, '('); break; case SQLCOM_CHANGE_MASTER: csize+= escape_string_hide_passwords(query, query_len, uh_buffer, uh_buffer_size, - "MASTER_PASSWORD", 15, "=", 1, 0); + "MASTER_PASSWORD", 15, "=", 1, + 0, 0, 0); break; case SQLCOM_CREATE_SERVER: case SQLCOM_ALTER_SERVER: csize+= escape_string_hide_passwords(query, query_len, uh_buffer, uh_buffer_size, - "PASSWORD", 8, NULL, 0, 0); + "PASSWORD", 8, NULL, 0, + 0, 0, 0); break; case SQLCOM_SET_OPTION: csize+= escape_string_hide_passwords(query, query_len, uh_buffer, uh_buffer_size, - "=", 1, NULL, 0, 1); + NULL, 0, NULL, 0, + "=", 1, 0); break; default: csize+= escape_string(query, query_len, From 8bc254dd6285c3258971bc5501f2abc1a2eed19c Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Wed, 20 Nov 2024 17:47:24 +0100 Subject: [PATCH 51/55] MDEV-26516: WSREP: Record locking is disabled in this thread, but the table being modified We periodically observe assertion failures in the mtr tests, specifically in the /storage/innobase/row/row0ins.cc file, following a WSREP error. The error message is: 'WSREP: record locking is disabled in this thread, but the table being modified is not mysql/wsrep_streaming_log: mysql/innodb_table_stats.'" This issue seems to occur because, upon opening the table, innodb_stats_auto_recalc may trigger, which Galera does not anticipate. This commit should fix this bug. --- storage/innobase/dict/dict0stats.cc | 9 ++++++++- storage/innobase/row/row0ins.cc | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc index 485b1916a66..228479b44c2 100644 --- a/storage/innobase/dict/dict0stats.cc +++ b/storage/innobase/dict/dict0stats.cc @@ -34,6 +34,9 @@ Created Jan 06, 2010 Vasil Dimov #include #include "btr0btr.h" #include "sync0sync.h" +#ifdef WITH_WSREP +#include +#endif #include #include @@ -3355,7 +3358,11 @@ dict_stats_update( if (srv_read_only_mode) { goto transient; } - +#ifdef WITH_WSREP + if (wsrep_thd_skip_locking(current_thd)) { + goto transient; + } +#endif if (dict_stats_auto_recalc_is_enabled(table)) { return(dict_stats_update( table, diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index d0b640338e4..ca43e9045e1 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -3238,7 +3238,8 @@ row_ins_clust_index_entry( #ifdef WITH_WSREP const bool skip_locking - = wsrep_thd_skip_locking(thr_get_trx(thr)->mysql_thd); + = thr_get_trx(thr)->is_wsrep() && + wsrep_thd_skip_locking(thr_get_trx(thr)->mysql_thd); ulint flags = index->table->no_rollback() ? BTR_NO_ROLLBACK : (index->table->is_temporary() || skip_locking) ? BTR_NO_LOCKING_FLAG : 0; From ff45fdac29937a1eef2d630c4b234864a717bb25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 22 Nov 2024 15:31:48 +0200 Subject: [PATCH 52/55] MDEV-35440 : Protocol error warning in the galera_wsrep_schema_detached test Make sure that node_1 remains in primary view by increasing it's weight. Add suppression on expected warnings because we kill node_2. Signed-off-by: Julius Goryavsky --- .../r/galera_wsrep_schema_detached.result | 35 ++++++++++++++++--- .../t/galera_wsrep_schema_detached.test | 19 +++++++--- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/galera/r/galera_wsrep_schema_detached.result b/mysql-test/suite/galera/r/galera_wsrep_schema_detached.result index 493bf9d3cac..4667aa98ccc 100644 --- a/mysql-test/suite/galera/r/galera_wsrep_schema_detached.result +++ b/mysql-test/suite/galera/r/galera_wsrep_schema_detached.result @@ -3,8 +3,9 @@ connection node_1; connection node_1; connection node_2; connection node_1; -call mtr.add_suppression("WSREP: async IST sender failed to serve.*"); +call mtr.add_suppression("WSREP:.*"); SET @wsrep_provider_options_orig = @@GLOBAL.wsrep_provider_options; +SET GLOBAL wsrep_provider_options ='pc.ignore_sb=true;pc.weight=2'; connection node_2; SET @wsrep_cluster_address_orig = @@GLOBAL.wsrep_cluster_address; SET GLOBAL WSREP_ON=0; @@ -17,11 +18,37 @@ EXPECT_1 SELECT COUNT(*) AS EXPECT_2 FROM mysql.wsrep_cluster_members; EXPECT_2 2 -connection node_1; -SET GLOBAL wsrep_provider_options ='pc.ignore_sb=true'; connection node_2; Killing server ... connection node_1; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +EXPECT_0 +0 +SELECT COUNT(*) AS EXPECT_1 FROM mysql.wsrep_cluster; +EXPECT_1 +1 +SELECT COUNT(*) AS EXPECT_1 FROM mysql.wsrep_cluster_members; +EXPECT_1 +1 connection node_2; connection node_1; -SET GLOBAL wsrep_provider_options ='pc.ignore_sb=false'; +SET GLOBAL wsrep_provider_options ='pc.ignore_sb=false;pc.weight=1'; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +EXPECT_0 +0 +SELECT COUNT(*) AS EXPECT_1 FROM mysql.wsrep_cluster; +EXPECT_1 +1 +SELECT COUNT(*) AS EXPECT_2 FROM mysql.wsrep_cluster_members; +EXPECT_2 +2 +connection node_2; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +EXPECT_0 +0 +SELECT COUNT(*) AS EXPECT_1 FROM mysql.wsrep_cluster; +EXPECT_1 +1 +SELECT COUNT(*) AS EXPECT_2 FROM mysql.wsrep_cluster_members; +EXPECT_2 +2 diff --git a/mysql-test/suite/galera/t/galera_wsrep_schema_detached.test b/mysql-test/suite/galera/t/galera_wsrep_schema_detached.test index f67091a5fb9..cddf4d6315a 100644 --- a/mysql-test/suite/galera/t/galera_wsrep_schema_detached.test +++ b/mysql-test/suite/galera/t/galera_wsrep_schema_detached.test @@ -6,8 +6,9 @@ --source include/auto_increment_offset_save.inc --connection node_1 -call mtr.add_suppression("WSREP: async IST sender failed to serve.*"); +call mtr.add_suppression("WSREP:.*"); SET @wsrep_provider_options_orig = @@GLOBAL.wsrep_provider_options; +SET GLOBAL wsrep_provider_options ='pc.ignore_sb=true;pc.weight=2'; --connection node_2 SET @wsrep_cluster_address_orig = @@GLOBAL.wsrep_cluster_address; @@ -16,15 +17,15 @@ SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; SELECT COUNT(*) AS EXPECT_1 FROM mysql.wsrep_cluster; SELECT COUNT(*) AS EXPECT_2 FROM mysql.wsrep_cluster_members; ---connection node_1 -SET GLOBAL wsrep_provider_options ='pc.ignore_sb=true'; - --connection node_2 --source include/kill_galera.inc --connection node_1 --let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' --source include/wait_condition.inc +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +SELECT COUNT(*) AS EXPECT_1 FROM mysql.wsrep_cluster; +SELECT COUNT(*) AS EXPECT_1 FROM mysql.wsrep_cluster_members; --connection node_2 --source include/start_mysqld.inc @@ -33,7 +34,15 @@ SET GLOBAL wsrep_provider_options ='pc.ignore_sb=true'; --let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' --source include/wait_condition.inc -SET GLOBAL wsrep_provider_options ='pc.ignore_sb=false'; +SET GLOBAL wsrep_provider_options ='pc.ignore_sb=false;pc.weight=1'; +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +SELECT COUNT(*) AS EXPECT_1 FROM mysql.wsrep_cluster; +SELECT COUNT(*) AS EXPECT_2 FROM mysql.wsrep_cluster_members; + +--connection node_2 +SELECT COUNT(*) AS EXPECT_0 FROM mysql.wsrep_streaming_log; +SELECT COUNT(*) AS EXPECT_1 FROM mysql.wsrep_cluster; +SELECT COUNT(*) AS EXPECT_2 FROM mysql.wsrep_cluster_members; # Cleanup --source include/auto_increment_offset_restore.inc From e7e06b3cb7697e49a4dca01c696ef9d1e36a0255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 22 Nov 2024 11:58:06 +0200 Subject: [PATCH 53/55] MDEV-35481 : ER_LOCK_DEADLOCK instead of ER_NO_SUCH_TABLE in galera_var_ignore_apply_errors Add wait_condition before select and set wsrep_sync_wait=0 to avoid possible deadlock. Signed-off-by: Julius Goryavsky --- .../suite/galera/r/galera_var_ignore_apply_errors.result | 1 + mysql-test/suite/galera/t/galera_var_ignore_apply_errors.test | 3 +++ 2 files changed, 4 insertions(+) diff --git a/mysql-test/suite/galera/r/galera_var_ignore_apply_errors.result b/mysql-test/suite/galera/r/galera_var_ignore_apply_errors.result index 17b06017287..a3237bcffc2 100644 --- a/mysql-test/suite/galera/r/galera_var_ignore_apply_errors.result +++ b/mysql-test/suite/galera/r/galera_var_ignore_apply_errors.result @@ -206,6 +206,7 @@ connection node_1; CREATE TABLE t1 (f1 INTEGER, f2 INTEGER); DROP TABLE t1; connection node_2; +set session wsrep_sync_wait=0; SELECT * FROM t1; ERROR 42S02: Table 'test.t1' doesn't exist SET GLOBAL wsrep_ignore_apply_errors = 10; diff --git a/mysql-test/suite/galera/t/galera_var_ignore_apply_errors.test b/mysql-test/suite/galera/t/galera_var_ignore_apply_errors.test index 02dd9fa8416..feec79196c3 100644 --- a/mysql-test/suite/galera/t/galera_var_ignore_apply_errors.test +++ b/mysql-test/suite/galera/t/galera_var_ignore_apply_errors.test @@ -259,6 +259,9 @@ CREATE TABLE t1 (f1 INTEGER, f2 INTEGER); DROP TABLE t1; --connection node_2 +set session wsrep_sync_wait=0; +--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1' +--source include/wait_condition.inc --error ER_NO_SUCH_TABLE SELECT * FROM t1; SET GLOBAL wsrep_ignore_apply_errors = 10; From f39217da0cae45b11aea2e91547a1a6e71640bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 22 Nov 2024 08:10:58 +0200 Subject: [PATCH 54/55] MDEV-35473 : Sporadic failures in the galera_3nodes.galera_evs_suspect_timeout mtr test Remove unnecessary sleep and replace it with proper wait_conditions. Signed-off-by: Julius Goryavsky --- .../r/galera_evs_suspect_timeout.result | 6 ------ .../t/galera_evs_suspect_timeout.test | 20 +++++++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/galera_3nodes/r/galera_evs_suspect_timeout.result b/mysql-test/suite/galera_3nodes/r/galera_evs_suspect_timeout.result index b280a803b37..2ecd5edfa99 100644 --- a/mysql-test/suite/galera_3nodes/r/galera_evs_suspect_timeout.result +++ b/mysql-test/suite/galera_3nodes/r/galera_evs_suspect_timeout.result @@ -12,16 +12,10 @@ connection node_3; Suspending node ... connection node_1; SET SESSION wsrep_sync_wait=0; -SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -VARIABLE_VALUE = 2 -1 CREATE TABLE t1 (f1 INTEGER) engine=InnoDB; INSERT INTO t1 VALUES (1); connection node_2; SET SESSION wsrep_sync_wait=0; -SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; -VARIABLE_VALUE = 2 -1 SET SESSION wsrep_sync_wait = 15; SELECT COUNT(*) FROM t1; COUNT(*) diff --git a/mysql-test/suite/galera_3nodes/t/galera_evs_suspect_timeout.test b/mysql-test/suite/galera_3nodes/t/galera_evs_suspect_timeout.test index c0b23e4cc8e..c52bebc7019 100644 --- a/mysql-test/suite/galera_3nodes/t/galera_evs_suspect_timeout.test +++ b/mysql-test/suite/galera_3nodes/t/galera_evs_suspect_timeout.test @@ -18,6 +18,9 @@ --source ../galera/include/auto_increment_offset_save.inc --connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + --let $wsrep_provider_options_node1 = `SELECT @@wsrep_provider_options` SET GLOBAL wsrep_provider_options = 'evs.inactive_timeout=PT100M; evs.suspect_timeout=PT1S'; @@ -26,20 +29,20 @@ SET GLOBAL wsrep_provider_options = 'evs.inactive_timeout=PT100M; evs.suspect_ti SET GLOBAL wsrep_provider_options = 'evs.inactive_timeout=PT100M; evs.suspect_timeout=PT1S'; --connection node_3 ---source include/wait_until_connected_again.inc --let $wsrep_cluster_address_node3 = `SELECT @@wsrep_cluster_address` +--let $wsrep_provider_options_node3 = `SELECT @@wsrep_provider_options` # Suspend node #3 --connection node_3 --source include/galera_suspend.inc ---sleep 5 # Confirm that the other nodes have booted it out --connection node_1 ---source include/wait_until_connected_again.inc SET SESSION wsrep_sync_wait=0; -SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + --disable_query_log --eval SET GLOBAL wsrep_provider_options = '$wsrep_provider_options_node1'; --enable_query_log @@ -49,9 +52,10 @@ CREATE TABLE t1 (f1 INTEGER) engine=InnoDB; INSERT INTO t1 VALUES (1); --connection node_2 ---source include/wait_until_connected_again.inc SET SESSION wsrep_sync_wait=0; -SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + --disable_query_log --eval SET GLOBAL wsrep_provider_options = '$wsrep_provider_options_node2'; --enable_query_log @@ -67,6 +71,7 @@ SELECT COUNT(*) FROM t1; --source include/wait_until_connected_again.inc --disable_query_log +--eval SET GLOBAL wsrep_provider_options = '$wsrep_provider_options_node3'; --eval SET GLOBAL wsrep_cluster_address = '$wsrep_cluster_address_node3'; --enable_query_log --source include/galera_wait_ready.inc @@ -78,6 +83,9 @@ SET SESSION wsrep_sync_wait = 15; SELECT COUNT(*) FROM t1; --connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 3 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + DROP TABLE t1; # Restore original auto_increment_offset values. --source ../galera/include/auto_increment_offset_restore.inc From fdb6db6b47f1825eabffde76c29d9b94545f1ef4 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 6 Nov 2024 10:21:08 +0400 Subject: [PATCH 55/55] MDEV-29462 ASAN: heap-use-after-free in Binary_string::copy on DO CONVERT Item_char_typecast::val_str_generic() uses Item::str_value as a buffer. Item::val_str_ascii() also used Item::str_value as a buffer. As a result, str_value tried to copy to itself. Fixing val_str_ascii() to use a local buffer instead of str_value. --- mysql-test/main/func_misc.result | 13 +++++++++++++ mysql-test/main/func_misc.test | 10 ++++++++++ sql/item.cc | 28 ++++++++++++++++------------ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/mysql-test/main/func_misc.result b/mysql-test/main/func_misc.result index a6869296090..59e62af37f2 100644 --- a/mysql-test/main/func_misc.result +++ b/mysql-test/main/func_misc.result @@ -1743,5 +1743,18 @@ count(*) 0 drop table t1; # +# MDEV-29462 ASAN: heap-use-after-free in Binary_string::copy on DO CONVERT +# +DO CONVERT (INET_ATON (CAST(LEFT (-1,1) as BINARY (30))) USING utf8); +DO FROM_BASE64(CAST((MID(UUID(),20,64)) AS BINARY (55))); +Warnings: +Warning 1958 Bad base64 data as position 4 +DO FROM_BASE64(CAST((MID(17653,ROW('-688:20:162697', (NULL))>=ROW(('*.)$'),(0xc254b6)),1)) AS BINARY (34))); +Warnings: +Warning 1958 Bad base64 data as position 1 +DO FROM_BASE64(CAST(LEFT (-1,1) as BINARY (30))); +Warnings: +Warning 1958 Bad base64 data as position 0 +# # End of 10.5 tests # diff --git a/mysql-test/main/func_misc.test b/mysql-test/main/func_misc.test index 498c8a94df9..70581d55067 100644 --- a/mysql-test/main/func_misc.test +++ b/mysql-test/main/func_misc.test @@ -1375,6 +1375,16 @@ SELECT r as r1, r FROM cte; select count(*) from t1 where r1!=r; drop table t1; +--echo # +--echo # MDEV-29462 ASAN: heap-use-after-free in Binary_string::copy on DO CONVERT +--echo # + +DO CONVERT (INET_ATON (CAST(LEFT (-1,1) as BINARY (30))) USING utf8); +DO FROM_BASE64(CAST((MID(UUID(),20,64)) AS BINARY (55))); +DO FROM_BASE64(CAST((MID(17653,ROW('-688:20:162697', (NULL))>=ROW(('*.)$'),(0xc254b6)),1)) AS BINARY (34))); +DO FROM_BASE64(CAST(LEFT (-1,1) as BINARY (30))); + --echo # --echo # End of 10.5 tests --echo # + diff --git a/sql/item.cc b/sql/item.cc index 439778f654c..dc27feb759a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -163,20 +163,24 @@ longlong Item::val_time_packed_result(THD *thd) String *Item::val_str_ascii(String *str) { DBUG_ASSERT(str != &str_value); - - uint errors; - String *res= val_str(&str_value); + + if (!(collation.collation->state & MY_CS_NONASCII)) + return val_str(str); + + /* + We cannot use str_value as a buffer here, + because val_str() can use it. Let's have a local buffer. + */ + StringBuffer tmp; + String *res= val_str(&tmp); + if (!res) return 0; - - if (!(res->charset()->state & MY_CS_NONASCII)) - str= res; - else - { - if ((null_value= str->copy(res->ptr(), res->length(), collation.collation, - &my_charset_latin1, &errors))) - return 0; - } + + uint errors; + if ((null_value= str->copy(res->ptr(), res->length(), collation.collation, + &my_charset_latin1, &errors))) + return 0; return str; }