Skip to content

Commit f7eb8f1

Browse files
author
Tor Didriksen
committed
Bug #30303461 REMOVE THE C MACRO ARRAY_ELLEMENTS
Remove the C macro version of array_elements. Move the C++ template version of array_elements to template_utils.h Remove usage of DBUG macros from template_utils.h, use the standard assert() and -DNDEBUG instead. Remove macros C_MODE_START and C_MODE_END Most usage was obsolete, all code has been converted from C to C++ Some usage is still needed: in plugins, so use 'extern "C"' instead. Change-Id: I2b81a6f07cf2e6a56078f4e716e2bdf96510d199
1 parent dba8906 commit f7eb8f1

39 files changed

+54
-97
lines changed

client/dump/sql_formatter_options.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2015, 2019, 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, version 2.0,
@@ -29,6 +29,7 @@
2929

3030
#include "client/base/abstract_options_provider.h"
3131
#include "client/dump/mysql_chain_element_options.h"
32+
#include "template_utils.h"
3233
#include "typelib.h"
3334

3435
namespace Mysql {

components/audit_api_message_emit/audit_api_message_emit.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
3333

3434
#include <ctype.h>
3535
#include <my_dbug.h>
36-
#include <my_macros.h>
3736
#include <mysql/components/component_implementation.h>
3837
#include <mysql/components/my_service.h>
3938
#include <mysql/components/service_implementation.h>
4039
#include <mysql/components/services/audit_api_message_service.h>
4140
#include <mysql/components/services/udf_registration.h>
4241
#include <mysql/service_plugin_registry.h>
4342
#include <mysql_com.h>
43+
#include "template_utils.h"
44+
4445
#include <stdio.h>
4546
#include <stdlib.h>
4647
#include <string.h>

components/mysql_server/dynamic_loader.cc

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
4545
#include "rwlock_scoped_lock.h"
4646
#include "scope_guard.h"
4747
#include "server_component.h"
48+
#include "template_utils.h"
4849

4950
/**
5051
@page PAGE_COMPONENTS Component Subsystem

components/mysql_server/dynamic_loader_scheme_file.cc

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
3737
#include "rwlock_scoped_lock.h"
3838
#include "scope_guard.h"
3939
#include "server_component.h"
40+
#include "template_utils.h"
4041

4142
#ifdef HAVE_DLFCN_H
4243
#include <dlfcn.h>

components/mysql_server/registry.cc

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
3232
#include "registry.h"
3333
#include "rwlock_scoped_lock.h"
3434
#include "server_component.h"
35+
#include "template_utils.h"
3536

3637
/**
3738
@page PAGE_COMPONENTS_REGISTRY The Service Registry Service

include/m_ctype.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
along with this program; if not, write to the Free Software
2121
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2222

23+
#ifndef M_CTYPE_INCLUDED
24+
#define M_CTYPE_INCLUDED
25+
2326
/**
2427
@file include/m_ctype.h
2528
A better implementation of the UNIX ctype(3) library.
2629
*/
2730

28-
#ifndef _m_ctype_h
29-
#define _m_ctype_h
30-
3131
#ifndef __cplusplus
3232
#include <stdbool.h>
3333
#endif
@@ -410,9 +410,7 @@ struct CHARSET_INFO {
410410
*/
411411

412412
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin;
413-
C_MODE_START
414413
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_latin1;
415-
C_MODE_END
416414
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_filename;
417415
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_utf8mb4_0900_ai_ci;
418416
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_utf8mb4_0900_bin;
@@ -745,4 +743,4 @@ static inline uint my_ismbchar(const CHARSET_INFO *cs, const uchar *str,
745743
((s)->cset->strntoull((s), (a), (b), (c), (d), (e)))
746744
#define my_strntod(s, a, b, c, d) ((s)->cset->strntod((s), (a), (b), (c), (d)))
747745

748-
#endif /* _m_ctype_h */
746+
#endif // M_CTYPE_INCLUDED

include/m_string.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
along with this program; if not, write to the Free Software
2222
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2323

24-
#ifndef _m_string_h
25-
#define _m_string_h
24+
#ifndef M_STRING_INCLUDED
25+
#define M_STRING_INCLUDED
2626

2727
/**
2828
@file include/m_string.h
@@ -280,9 +280,7 @@ static constexpr int FLOATING_POINT_BUFFER{311 + DECIMAL_NOT_SPECIFIED};
280280
(DBL_DIG + 4 + MY_MAX(5, MAX_DECPT_FOR_F_FORMAT))
281281

282282
extern char *int2str(long val, char *dst, int radix, int upcase);
283-
C_MODE_START
284283
extern char *int10_to_str(long val, char *dst, int radix);
285-
C_MODE_END
286284
extern const char *str2int(const char *src, int radix, long lower, long upper,
287285
long *val);
288286
longlong my_strtoll10(const char *nptr, const char **endptr, int *error);
@@ -367,4 +365,4 @@ static inline void lex_cstring_set(LEX_CSTRING *lex_str, const char *c_str) {
367365
lex_str->length = strlen(c_str);
368366
}
369367

370-
#endif
368+
#endif // M_STRING_INCLUDED

include/my_byteorder.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#include "my_config.h"
3434

35+
#include "my_compiler.h"
36+
3537
#include <string.h>
3638
#include <sys/types.h>
3739

include/my_macros.h

+1-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2016, 2019, 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, version 2.0,
@@ -30,19 +30,6 @@
3030
with code from \<algorithm\> or similar.
3131
*/
3232

33-
#ifndef MYSQL_ABI_CHECK
34-
#include <stddef.h>
35-
#endif
36-
37-
/* Macros to make switching between C and C++ mode easier */
38-
#ifdef __cplusplus
39-
#define C_MODE_START extern "C" {
40-
#define C_MODE_END }
41-
#else
42-
#define C_MODE_START
43-
#define C_MODE_END
44-
#endif
45-
4633
/* Make it easier to add conditional code in _expressions_ */
4734
#ifdef _WIN32
4835
#define IF_WIN(A, B) A
@@ -70,20 +57,4 @@
7057
} while (0)
7158
#define test_all_bits(a, b) (((a) & (b)) == (b))
7259

73-
/* Bug in developerstudio: use the C version */
74-
#if defined(__cplusplus) && !defined(__SUNPRO_CC)
75-
76-
template <class T, size_t N>
77-
constexpr size_t array_elements(T (&)[N]) noexcept {
78-
return N;
79-
}
80-
81-
#else
82-
83-
// Less type-safe version that e.g. allows sending in pointers
84-
// or STL containers without an error.
85-
#define array_elements(A) ((size_t)(sizeof(A) / sizeof(A[0])))
86-
87-
#endif
88-
8960
#endif // MY_MACROS_INCLUDED

include/sslopt-vars.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "m_string.h"
3333
#include "my_inttypes.h"
3434
#include "mysql.h"
35+
#include "template_utils.h"
3536
#include "typelib.h"
3637

3738
#if defined(HAVE_OPENSSL)

include/template_utils.h

+13-5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
#ifndef TEMPLATE_UTILS_INCLUDED
2424
#define TEMPLATE_UTILS_INCLUDED
2525

26+
#include <assert.h>
2627
#include <stddef.h>
27-
28-
#include "my_dbug.h"
28+
#include <type_traits>
2929

3030
/**
3131
@file include/template_utils.h
@@ -89,7 +89,7 @@ inline const T pointer_cast(const void *p) {
8989
*/
9090
template <typename Target, typename Source>
9191
inline Target down_cast(Source *arg) {
92-
DBUG_ASSERT(NULL != dynamic_cast<Target>(arg));
92+
assert(nullptr != dynamic_cast<Target>(arg));
9393
return static_cast<Target>(arg);
9494
}
9595

@@ -109,8 +109,8 @@ inline Target down_cast(Source &arg) {
109109
// We still use the pointer version of dynamic_cast, as the
110110
// reference-accepting version throws exceptions, and we don't want to deal
111111
// with that.
112-
DBUG_ASSERT(dynamic_cast<typename std::remove_reference<Target>::type *>(
113-
&arg) != nullptr);
112+
assert(dynamic_cast<typename std::remove_reference<Target>::type *>(&arg) !=
113+
nullptr);
114114
return static_cast<Target>(arg);
115115
}
116116

@@ -144,4 +144,12 @@ struct ReturnValueOrError {
144144
bool error;
145145
};
146146

147+
/**
148+
Number of elements in a constant C array.
149+
*/
150+
template <class T, size_t N>
151+
constexpr size_t array_elements(T (&)[N]) noexcept {
152+
return N;
153+
}
154+
147155
#endif // TEMPLATE_UTILS_INCLUDED

libmysql/errmsg.cc

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "errmsg.h"
3232
#include "my_sys.h"
33+
#include "template_utils.h"
3334

3435
const char *client_errors[] = {
3536
"Unknown MySQL error",

mysys/stacktrace.cc

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "my_inttypes.h"
4747
#include "my_macros.h"
4848
#include "my_stacktrace.h"
49+
#include "template_utils.h"
4950

5051
#ifndef _WIN32
5152
#include <signal.h>

mysys/thr_lock.cc

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ lock at the same time as multiple read locks.
107107
#include "mysql/psi/psi_stage.h"
108108
#include "mysql/psi/psi_table.h"
109109
#include "mysys/mysys_priv.h"
110+
#include "template_utils.h"
110111
#include "thr_lock.h"
111112
#include "thr_mutex.h"
112113

plugin/group_replication/libmysqlgcs/src/interface/gcs_psi.cc

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "mysql/psi/mysql_memory.h"
2727
#include "mysql/psi/mysql_thread.h"
28+
#include "template_utils.h"
2829

2930
PSI_thread_key key_GCS_THD_Gcs_ext_logger_impl_m_consumer,
3031
key_GCS_THD_Gcs_xcom_engine_m_engine_thread,

plugin/x/tests/driver/connector/session_holder.cc

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "plugin/x/tests/driver/connector/session_holder.h"
2626

2727
#include "my_dbug.h"
28+
#include "template_utils.h"
2829

2930
#include "plugin/x/tests/driver/connector/mysqlx_all_msgs.h"
3031

sql-common/client_plugin.cc

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "mysql/psi/mysql_mutex.h"
6262
#include "mysql/service_mysql_alloc.h"
6363
#include "sql_common.h"
64+
#include "template_utils.h"
6465

6566
#ifdef HAVE_DLFCN_H
6667
#include <dlfcn.h>

sql-common/compression.cc

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "compression.h"
2424
#include "m_ctype.h"
25+
#include "my_dbug.h"
2526
#include "my_sys.h"
2627
#include "mysqld_error.h"
2728

sql/derror.cc

-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "my_inttypes.h"
3434
#include "my_io.h"
3535
#include "my_loglevel.h"
36-
#include "my_macros.h"
3736
#include "my_sys.h"
3837
#include "mysql/components/services/log_builtins.h"
3938
#include "mysql/psi/mysql_file.h"
@@ -139,8 +138,6 @@ static const char *error_message_fetch(int mysql_errno) {
139138
return nullptr;
140139
}
141140

142-
C_MODE_START
143-
144141
/**
145142
Get the error-message corresponding to the given MySQL error-code,
146143
or nullptr if no message is available for that code (this may indicate
@@ -179,7 +176,6 @@ const char *error_message_for_client(int mysql_errno) {
179176

180177
return error_message_fetch(mysql_errno);
181178
}
182-
C_MODE_END
183179

184180
bool init_errmessage() {
185181
DBUG_TRACE;

sql/derror.h

-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <sys/types.h>
2828

2929
#include "my_inttypes.h"
30-
#include "my_macros.h"
3130

3231
#ifdef EXTRA_CODE_FOR_UNIT_TESTING
3332
#include "mysqld_error.h"
@@ -109,10 +108,8 @@ const char *ER_THD(const THD *thd, int mysql_errno);
109108
const char *ER_DEFAULT_NONCONST(int mysql_errno);
110109
const char *ER_THD_NONCONST(const THD *thd, int mysql_errno);
111110

112-
C_MODE_START
113111
const char *error_message_for_error_log(int mysql_errno);
114112
const char *error_message_for_client(int mysql_errno);
115-
C_MODE_END
116113

117114
const char *mysql_errno_to_symbol(int mysql_errno);
118115
int mysql_symbol_to_errno(const char *error_symbol);

sql/gen_keyword_list.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
#include <map>
3131
#include <set>
3232

33-
#include "lex.h" // symbols[]
33+
#include "lex.h" // symbols[]
34+
#include "template_utils.h"
3435
#include "welcome_copyright_notice.h" // ORACLE_WELCOME_COPYRIGHT_NOTICE
3536

3637
using icu::RegexMatcher;

sql/gen_lex_hash.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2019, 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, version 2.0,
@@ -92,9 +92,9 @@ So, we can read full search-structure as 32-bit word
9292
#include <utility>
9393

9494
#include "my_inttypes.h"
95-
#include "my_macros.h"
9695
#include "sql/lex.h"
9796
#include "sql/lex_symbol.h"
97+
#include "template_utils.h"
9898
#include "welcome_copyright_notice.h" /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
9999

100100
static bool check_duplicates(uint group_mask);

sql/mysqld.cc

-4
Original file line numberDiff line numberDiff line change
@@ -9609,8 +9609,6 @@ bool mysqld_get_one_option(int optid,
96099609

96109610
/** Handle arguments for multiple key caches. */
96119611

9612-
C_MODE_START
9613-
96149612
static void *mysql_getopt_value(const char *keyname, size_t key_length,
96159613
const struct my_option *option, int *error) {
96169614
if (error) *error = 0;
@@ -9639,8 +9637,6 @@ static void *mysql_getopt_value(const char *keyname, size_t key_length,
96399637
return option->value;
96409638
}
96419639

9642-
C_MODE_END
9643-
96449640
/**
96459641
Get server options from the command line,
96469642
and perform related server initializations.

sql/psi_memory_key.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
#include "sql/psi_memory_key.h"
2424

25-
#include "my_macros.h"
2625
#include "my_psi_config.h"
2726
#include "mysql/components/services/psi_memory_bits.h"
2827
#include "mysql/psi/mysql_memory.h"
2928
#include "mysql/psi/psi_base.h" // PSI_FLAG_ONLY_GLOBAL_STAT
3029
#include "mysql/psi/psi_memory.h"
30+
#include "template_utils.h"
3131

3232
/*
3333
MAINTAINER: Please keep this list in order, to limit merge collisions.

sql/stream_cipher.cc

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "sql/stream_cipher.h"
2424
#include <algorithm>
2525
#include "my_byteorder.h"
26+
#include "my_dbug.h"
2627

2728
#define HAVE_BYTESTOKEY_SHA512_HANDLING
2829
#define HAVE_DECRYPTION_INTO_SAME_SOURCE_BUFFER

0 commit comments

Comments
 (0)