Skip to content

Commit e17a193

Browse files
committed
Bug#21121042: CODE TESTING MYSQL_VERSION_ID IS BRITTLE
Several places in the code we do compile-time checks of MYSQL_VERSION_ID without including mysql_version.h where MYSQL_VERSION_ID is defined. This patch makes such checks less brittle by: - Removing them where possible - Explicitly including mysql_version.h otherwise The patch also fixes a similar problem where some files related to MyISAM full text search use the HA_KEYTYPE_FLOAT symbol without including my_base.h where it is defined. These problems were identified by studying the output from the -Wundef Clang compiler warning option.
1 parent 1b36d3a commit e17a193

File tree

14 files changed

+14
-44
lines changed

14 files changed

+14
-44
lines changed

client/mysqladmin.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
306306
error++;
307307
break;
308308
case OPT_CHARSETS_DIR:
309-
#if MYSQL_VERSION_ID > 32300
310309
charsets_dir = argument;
311-
#endif
312310
break;
313311
case OPT_MYSQL_PROTOCOL:
314312
opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
@@ -1286,11 +1284,9 @@ static void usage(void)
12861284
flush-threads Flush the thread cache\n\
12871285
flush-privileges Reload grant tables (same as reload)\n\
12881286
kill id,id,... Kill mysql threads");
1289-
#if MYSQL_VERSION_ID >= 32200
12901287
puts("\
12911288
password [new-password] Change old password to new-password in current format\n\
12921289
old-password [new-password] Change old password to new-password in old format");
1293-
#endif
12941290
puts("\
12951291
ping Check if mysqld is alive\n\
12961292
processlist Show list of active threads in server\n\

client/mysqldump.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,11 +1719,9 @@ static void unescape(FILE *file,char *pos,uint length)
17191719

17201720
static my_bool test_if_special_chars(const char *str)
17211721
{
1722-
#if MYSQL_VERSION_ID >= 32300
17231722
for ( ; *str ; str++)
17241723
if (!my_isvar(charset_info,*str) && *str != '$')
17251724
return 1;
1726-
#endif
17271725
return 0;
17281726
} /* test_if_special_chars */
17291727

client/mysqltest.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5399,11 +5399,7 @@ void set_reconnect(MYSQL* mysql, int val)
53995399
my_bool reconnect= val;
54005400
DBUG_ENTER("set_reconnect");
54015401
DBUG_PRINT("info", ("val: %d", val));
5402-
#if MYSQL_VERSION_ID < 50000
5403-
mysql->reconnect= reconnect;
5404-
#else
54055402
mysql_options(mysql, MYSQL_OPT_RECONNECT, (char *)&reconnect);
5406-
#endif
54075403
DBUG_VOID_RETURN;
54085404
}
54095405

@@ -8111,7 +8107,6 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
81118107
parameter markers.
81128108
*/
81138109

8114-
#if MYSQL_VERSION_ID >= 50000
81158110
if (cursor_protocol_enabled)
81168111
{
81178112
/*
@@ -8122,7 +8117,6 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
81228117
die("mysql_stmt_attr_set(STMT_ATTR_CURSOR_TYPE) failed': %d %s",
81238118
mysql_stmt_errno(stmt), mysql_stmt_error(stmt));
81248119
}
8125-
#endif
81268120

81278121
/*
81288122
Execute the query

client/upgrade/program.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "mysqld_error.h"
2727
#include "my_default.h"
2828
#include "check/mysqlcheck.h"
29+
#include "mysql_version.h"
2930
#include "../scripts/mysql_fix_privilege_tables_sql.c"
3031
#include "../scripts/sql_commands_sys_schema.h"
3132

include/mysql/plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#ifndef MYSQL_ABI_CHECK
2020
#include <stddef.h>
21+
#include "mysql_version.h" /* MYSQL_VERSION_ID */
2122
#endif
2223

2324
/*

include/mysql_com.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,7 @@ enum mysql_enum_shutdown_level {
455455
/* don't flush InnoDB buffers, flush other storage engines' buffers*/
456456
SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1,
457457
/* Now the 2 levels of the KILL command */
458-
#if MYSQL_VERSION_ID >= 50000
459458
KILL_QUERY= 254,
460-
#endif
461459
KILL_CONNECTION= 255
462460
};
463461

sql-common/client.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4880,10 +4880,9 @@ void mysql_close_free(MYSQL *mysql)
48804880
if (mysql->extension)
48814881
mysql_extension_free(mysql->extension);
48824882

4883-
#if defined(EMBEDDED_LIBRARY) || MYSQL_VERSION_ID >= 50100
48844883
my_free(mysql->info_buffer);
48854884
mysql->info_buffer= 0;
4886-
#endif
4885+
48874886
/* Clear pointers for better safety */
48884887
mysql->host_info= NULL;
48894888
mysql->user= NULL;

sql/handler.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include "my_bit.h" // my_count_bits
2525
#include "myisam.h" // TT_FOR_UPGRADE
26+
#include "mysql_version.h" // MYSQL_VERSION_ID
27+
2628
#include "binlog.h" // mysql_bin_log
2729
#include "debug_sync.h" // DEBUG_SYNC
2830
#include "discover.h" // writefrm

sql/mysqld.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#include "replication.h" // thd_enter_cond
102102

103103
#include "my_default.h"
104+
#include "mysql_version.h"
104105

105106
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
106107
#include "../storage/perfschema/pfs_server.h"

sql/sql_lex.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "sql_lex.h"
2121

22+
#include "mysql_version.h" // MYSQL_VERSION_ID
2223
#include "sp_head.h" // sp_head
2324
#include "sql_class.h" // THD
2425
#include "sql_parse.h" // add_to_list

sql/table.cc

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "my_md5.h" // compute_md5_hash
2020
#include "myisam.h" // MI_MAX_KEY_LENGTH
21+
#include "mysql_version.h" // MYSQL_VERSION_ID
22+
2123
#include "auth_common.h" // acl_getroot
2224
#include "binlog.h" // mysql_bin_log
2325
#include "debug_sync.h" // DEBUG_SYNC
@@ -1646,20 +1648,6 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
16461648
}
16471649
next_chunk+= 5 + partition_info_str_len;
16481650
}
1649-
#if MYSQL_VERSION_ID < 50200
1650-
if (share->mysql_version >= 50106 && share->mysql_version <= 50109)
1651-
{
1652-
/*
1653-
Partition state array was here in version 5.1.6 to 5.1.9, this code
1654-
makes it possible to load a 5.1.6 table in later versions. Can most
1655-
likely be removed at some point in time. Will only be used for
1656-
upgrades within 5.1 series of versions. Upgrade to 5.2 can only be
1657-
done from newer 5.1 versions.
1658-
*/
1659-
next_chunk+= 4;
1660-
}
1661-
else
1662-
#endif
16631651
if (share->mysql_version >= 50110 && next_chunk < buff_end)
16641652
{
16651653
/* New auto_partitioned indicator introduced in 5.1.11 */
@@ -3589,17 +3577,6 @@ void append_unescaped(String *res, const char *pos, size_t length)
35893577

35903578
for (; pos != end ; pos++)
35913579
{
3592-
#if MYSQL_VERSION_ID < 40100
3593-
uint mblen;
3594-
if (use_mb(default_charset_info) &&
3595-
(mblen= my_ismbchar(default_charset_info, pos, end)))
3596-
{
3597-
res->append(pos, mblen);
3598-
pos+= mblen;
3599-
continue;
3600-
}
3601-
#endif
3602-
36033580
switch (*pos) {
36043581
case 0: /* Must be escaped for 'mysql' */
36053582
res->append('\\');

storage/myisam/ft_nlq_search.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -17,6 +17,7 @@
1717

1818
#define FT_CORE
1919
#include "ftdefs.h"
20+
#include "my_base.h" /* HA_KEYTYPE_FLOAT */
2021

2122
/* search with natural language queries */
2223

storage/myisam/ft_update.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/* functions to work with full-text indices */
1919

2020
#include "ftdefs.h"
21+
#include "my_base.h" /* HA_KEYTYPE_FLOAT */
2122
#include <math.h>
2223

2324
void _mi_ft_segiterator_init(MI_INFO *info, uint keynr, const uchar *record,

storage/myisam/mi_write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -527,7 +527,7 @@ int _mi_insert(MI_INFO *info, MI_KEYDEF *keyinfo,
527527
uint alen, blen, ft2len=info->s->ft2_keyinfo.keylength;
528528
/* the very first key on the page is always unpacked */
529529
DBUG_ASSERT((*b & 128) == 0);
530-
#if HA_FT_MAXLEN >= 127
530+
#if HA_FT_MAXLEN >= 127 /* TODO: Undefined symbol */
531531
blen= mi_uint2korr(b); b+=2;
532532
#else
533533
blen= *b++;

0 commit comments

Comments
 (0)