Skip to content

Commit b845ba2

Browse files
author
Tor Didriksen
committed
WL#14467: Isolate character set and collation library
The patch is intended to make libstrings, the character set and collation library, an independent self-contained library suitable for use in separate projects where the whole mysys is not needed or is not welcome. API changes =========== - include/m_ctype.h + m_ctype.h is a C++ source file for a long time, so, C-specific code has been removed/converted. + Error message data has been extracted from MY_CHARSET_LOADER into MY_CHARSET_ERRMSG + MY_CHARSET_LOADER has been converted into a C++ abstract interface structure. - include/my_sys.h + all_charsets[] has made an array of constant pointers (was not constant). + The variadic type my_error_reporter of the my_charset_error_reporter callback has been replaced with my_error_vreporter (the latest expects va_list instead of ellipsis). + my_charset_loader_init_mysys() has been removed. + my_collation_get_by_name() and my_charset_get_by_name() have been changed to return error messages via MY_CHARSET_ERRMSG instead of MY_CHARSET_LOADER. Behavior changes ================ - On-demand initialization of lexer tables (former lex_init() and hint_lex_init_maps()). Locks ===== - Global mutex THR_LOCK_charset has been replaced with a local std::mutex. Use cases of new API in server sources ====================================== - Lexer: new API call instead of get_charset_by_csname(). Added to public API =================== - include/mysql/strings/collations.h: new public API of libstring - include/mysql/attribute.h: public version of MY_ATTRIBUTE - include/mysql/declspec.h: public version of MYSQL_PLUGIN_IMPORT Moved to public API =================== - include/mysql/strings/m_ctype.h - include/mysql/my_loglevel.h New important files =================== - strings/collations.cc: hides interactions with implementation internals (i.e. with strings/collations_internal.{h,cc}) Change-Id: I95ab120ab32f8f1225cda9b5837c8b53c9b9c4a4
1 parent 6aac738 commit b845ba2

File tree

914 files changed

+9432
-6648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

914 files changed

+9432
-6648
lines changed

CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,17 @@ ADD_DEFINITIONS(-D__STDC_FORMAT_MACROS) # Enable C99 printf format macros
15761576
ADD_DEFINITIONS(-D_USE_MATH_DEFINES) # Get access to M_PI, M_E, etc. in math.h
15771577
ADD_DEFINITIONS(-DLZ4_DISABLE_DEPRECATE_WARNINGS) # C++14 deprecation warnings in LZ4.
15781578

1579+
# Force the same macro definition MYSQL_PROJECT for all source files being
1580+
# compiled as a part of the MySQL server, client tools, libraries etc.
1581+
# The MYSQL_PROJECT macro helps to distinguish when e.g. some C++ header file
1582+
# is included by the MySQL project source file or by the external project
1583+
# source file.
1584+
# For example, MYSQL_PROJECT helps to detect when include/mysql/strings/api.h
1585+
# is used to a) build a static library, or b) build a Windows DLL, or
1586+
# c) reference the server strings API from plugins (DLLs) loaded by the
1587+
# MySQL server, or d) reference the libstrings DLL from external executables.
1588+
ADD_DEFINITIONS(-DMYSQL_PROJECT)
1589+
15791590
OPTION(ENABLE_EXPERIMENT_SYSVARS "Expose ussually hidden system variables to allow experiments" OFF)
15801591
IF(ENABLE_EXPERIMENT_SYSVARS)
15811592
ADD_DEFINITIONS(-DENABLE_EXPERIMENT_SYSVARS)
@@ -2222,6 +2233,13 @@ IF(NOT WITHOUT_SERVER AND WITH_UNIT_TESTS)
22222233
# If some symbols are still missing, they will be picked up from
22232234
# dependent libraries, since we LINK_PUBLIC.
22242235
# To see what symbols we need to import, remove LINK_PUBLIC above.
2236+
#
2237+
# The strings library uses visibility=hidden for all symbols,
2238+
# except those explicitly tagged with MYSQL_STRINGS_EXPORT.
2239+
# If we get ODR violations for executables using server_unittest_library,
2240+
# it means the symbol has been found in strings and
2241+
# server_unittest_library, which means the unit test is using
2242+
# some non-exported symbol from strings.
22252243
EXPORTS
22262244
builtin_perfschema_plugin # Pulls in the whole server.
22272245
mysql_service_mysql_rwlock_v1 # Pulls in minchassis

client/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ MERGE_CONVENIENCE_LIBRARIES(json_binlog_static
176176
MYSQL_ADD_EXECUTABLE(json_client_library_main
177177
json_client_library_main.cc
178178
INCLUDE_DIRECTORIES ../sql
179-
LINK_LIBRARIES json_client_library strings
179+
LINK_LIBRARIES json_client_library strings mysys
180180
SKIP_INSTALL
181181
)
182182

client/base/abstract_connection_program.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include "client/base/abstract_connection_program.h"
2626

27+
struct CHARSET_INFO;
28+
2729
using namespace Mysql::Tools::Base;
2830

2931
Abstract_connection_program::Abstract_connection_program()
@@ -41,4 +43,4 @@ CHARSET_INFO *Abstract_connection_program::get_current_charset() const {
4143

4244
void Abstract_connection_program::set_current_charset(CHARSET_INFO *charset) {
4345
m_connection_options.set_current_charset(charset);
44-
}
46+
}

client/base/abstract_connection_program.h

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "client/base/mysql_connection_options.h"
3535
#include "client/client_priv.h"
3636

37+
struct CHARSET_INFO;
38+
3739
namespace Mysql {
3840
namespace Tools {
3941
namespace Base {

client/base/message_data.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
#include "client/base/message_data.h"
2626
#include "errmsg.h"
2727

28-
#include "m_ctype.h"
28+
#include "mysql/strings/m_ctype.h"
2929
#include "sql_string.h"
30+
#include "template_utils.h"
3031

3132
using namespace Mysql::Tools::Base;
3233

client/base/mysql_connection_options.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
#include "client/base/abstract_options_provider.h"
3535
#include "client/base/abstract_program.h"
3636
#include "compression.h"
37-
#include "m_ctype.h"
37+
#include "m_string.h"
3838
#include "multi_factor_passwordopt-vars.h"
39+
#include "mysql/strings/m_ctype.h"
3940
#include "mysys_err.h"
41+
#include "nulls.h"
4042
#include "typelib.h"
4143

4244
using Mysql::Tools::Base::Abstract_program;

client/base/mysql_connection_options.h

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "my_compiler.h"
3636
#include "my_inttypes.h"
3737

38+
struct CHARSET_INFO;
39+
3840
namespace Mysql {
3941
namespace Tools {
4042
namespace Base {

client/base/mysql_query_runner.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <atomic>
3030
#include <functional>
3131

32-
#include "m_ctype.h"
32+
#include "mysql/strings/m_ctype.h"
3333
#include "sql_string.h"
3434
#include "template_utils.h"
3535

client/check/mysqlcheck.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
#include "caching_sha2_passwordopt-vars.h"
3232
#include "client/client_priv.h"
3333
#include "compression.h"
34-
#include "m_ctype.h"
3534
#include "my_alloc.h"
3635
#include "my_dbug.h"
3736
#include "my_default.h"
3837
#include "my_inttypes.h"
3938
#include "my_macros.h"
4039
#include "mysql/service_mysql_alloc.h"
40+
#include "mysql/strings/m_ctype.h"
41+
#include "nulls.h"
4142
#include "print_version.h"
4243
#include "sslopt-vars.h"
4344
#include "typelib.h"

client/check/mysqlcheck_core.cc

+16-10
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030

3131
#include "client/check/mysqlcheck.h"
3232
#include "client/client_priv.h"
33-
#include "m_ctype.h"
33+
#include "m_string.h"
3434
#include "my_default.h"
3535
#include "my_inttypes.h"
36+
#include "mysql/strings/m_ctype.h"
3637

3738
using namespace Mysql::Tools::Check;
3839

@@ -354,15 +355,18 @@ static void print_result() {
354355
mysql_free_result(res);
355356
}
356357

357-
void Mysql::Tools::Check::mysql_check(
358-
MYSQL *connection, int what_to_do, bool opt_alldbs,
359-
bool opt_check_only_changed, bool opt_extended, bool opt_databases,
360-
bool opt_fast, bool opt_medium_check, bool opt_quick, bool opt_all_in_1,
361-
bool opt_silent, bool opt_auto_repair, bool ignore_errors, bool opt_frm,
362-
bool opt_fix_table_names, bool opt_fix_db_names, bool opt_upgrade,
363-
bool opt_write_binlog, uint verbose, std::string opt_skip_database,
364-
std::vector<std::string> arguments,
365-
void (*dberror)(MYSQL *mysql, const std::string &when)) {
358+
namespace Mysql::Tools::Check {
359+
360+
void mysql_check(MYSQL *connection, int what_to_do, bool opt_alldbs,
361+
bool opt_check_only_changed, bool opt_extended,
362+
bool opt_databases, bool opt_fast, bool opt_medium_check,
363+
bool opt_quick, bool opt_all_in_1, bool opt_silent,
364+
bool opt_auto_repair, bool ignore_errors, bool opt_frm,
365+
bool opt_fix_table_names, bool opt_fix_db_names,
366+
bool opt_upgrade, bool opt_write_binlog, uint verbose,
367+
std::string opt_skip_database,
368+
std::vector<std::string> arguments,
369+
void (*dberror)(MYSQL *mysql, const std::string &when)) {
366370
::sock = connection;
367371
::what_to_do = what_to_do;
368372
::opt_alldbs = opt_alldbs;
@@ -419,6 +423,8 @@ void Mysql::Tools::Check::mysql_check(
419423
}
420424
}
421425

426+
} // namespace Mysql::Tools::Check
427+
422428
Program::Program()
423429
: m_what_to_do(0),
424430
m_auto_repair(false),

client/client_priv.h

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <mysql.h>
3131

3232
#include "errmsg.h"
33-
#include "m_string.h"
3433
#include "my_getopt.h"
3534
#include "my_sys.h"
3635

client/dump/abstract_mysql_chain_element_extension.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <optional>
3131
#include <sstream>
3232

33-
#include "m_ctype.h"
33+
#include "mysql/strings/m_ctype.h"
3434

3535
using namespace Mysql::Tools::Dump;
3636

client/dump/abstract_mysql_chain_element_extension.h

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8mb4"
4141
#define MAX_NAME_LEN (64 * 3)
4242

43+
struct CHARSET_INFO;
44+
4345
namespace Mysql {
4446
namespace Tools {
4547
namespace Dump {

client/dump/mysqldump_tool_chain_maker.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "client/dump/sql_formatter.h"
3737
#include "client/dump/standard_writer.h"
3838
#include "client/dump/view.h"
39-
#include "m_ctype.h"
39+
#include "mysql/strings/m_ctype.h"
4040

4141
using namespace Mysql::Tools::Dump;
4242
using std::placeholders::_1;

client/dump/mysqldump_tool_chain_maker_options.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <sstream>
2929
#include <string>
3030

31-
#include "m_ctype.h"
31+
#include "mysql/strings/m_ctype.h"
3232

3333
using namespace Mysql::Tools::Dump;
3434
using std::placeholders::_1;

client/dump/sql_formatter.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
#include "client/dump/privilege.h"
3939
#include "client/dump/stored_procedure.h"
4040
#include "client/dump/view.h"
41-
#include "m_ctype.h"
41+
#include "m_string.h"
42+
#include "mysql/strings/m_ctype.h"
4243

4344
using namespace Mysql::Tools::Dump;
4445

client/dump/sql_formatter_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

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

client/migrate_keyring/options.cc

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
*/
2424

25+
#include <sys/types.h>
26+
27+
#include <cstddef>
28+
#include <cstdio>
2529
#include <cstring>
2630
#include <iostream>
2731
#include <string>
32+
#include <utility>
2833

29-
#include <m_ctype.h> /* Character set */
3034
#include <my_alloc.h> /* MEM_ROOT */
3135
#include <my_default.h> /* print_defaults */
3236
#include <my_getopt.h> /* Options handling */
@@ -38,6 +42,10 @@
3842
#include <print_version.h> /* print_version */
3943
#include <typelib.h> /* find_type_or_exit */
4044
#include <welcome_copyright_notice.h> /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
45+
#include "m_string.h"
46+
#include "mysql/strings/m_ctype.h" /* Character set */
47+
#include "nulls.h"
48+
#include "template_utils.h"
4149

4250
#include "options.h"
4351
#include "utilities.h"

client/multi_factor_passwordopt-vars.cc

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "my_getopt.h"
2929
#include "mysql.h"
3030
#include "mysql/service_mysql_alloc.h" // my_free, my_strdup
31+
#include "nulls.h"
3132

3233
char *opt_password[MAX_AUTH_FACTORS] = {nullptr};
3334
bool tty_password[MAX_AUTH_FACTORS] = {false};

client/mysql.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,24 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4343
#include "client/pattern_matcher.h"
4444
#include "compression.h"
4545
#include "lex_string.h"
46-
#include "m_ctype.h"
46+
#include "m_string.h"
4747
#include "my_compiler.h"
4848
#include "my_dbug.h"
4949
#include "my_default.h"
5050
#include "my_dir.h"
5151
#include "my_inttypes.h"
5252
#include "my_io.h"
53-
#include "my_loglevel.h"
5453
#include "my_macros.h"
54+
#include "mysql/my_loglevel.h"
55+
#include "mysql/strings/int2str.h"
56+
#include "mysql/strings/m_ctype.h"
57+
#include "nulls.h"
58+
#include "str2int.h"
59+
#include "strcont.h"
60+
#include "string_with_len.h"
61+
#include "strmake.h"
62+
#include "strxmov.h"
63+
#include "strxnmov.h"
5564
#include "typelib.h"
5665
#include "user_registration.h"
5766
#include "violite.h"

client/mysql_config_editor.cc

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "my_rnd.h"
5151
#include "mysql/service_mysql_alloc.h"
5252
#include "mysys/my_default_priv.h"
53+
#include "nulls.h"
5354
#include "print_version.h"
5455
#include "welcome_copyright_notice.h"
5556

client/mysql_secure_installation.cc

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

2929
#include "client/client_priv.h"
30+
#include "m_string.h"
3031
#ifdef _WIN32
31-
#include "m_ctype.h"
32+
#include "mysql/strings/m_ctype.h"
3233
#endif
3334
#include "my_alloc.h"
3435
#include "my_compiler.h"
@@ -39,6 +40,7 @@
3940
#include "my_shm_defaults.h"
4041
#include "mysql/service_mysql_alloc.h"
4142
#include "mysqld_error.h"
43+
#include "nulls.h"
4244
#include "print_version.h"
4345
#include "typelib.h"
4446
#include "welcome_copyright_notice.h" // ORACLE_WELCOME_COPYRIGHT_NOTICE

client/mysql_ssl_rsa_setup.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "client/logger.h"
4141
#include "client/path.h"
4242
#ifdef _WIN32
43-
#include "m_ctype.h"
43+
#include "mysql/strings/m_ctype.h"
4444
#endif
4545
#include "my_alloc.h"
4646
#include "my_compiler.h"

client/mysqladmin.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#include "client/client_priv.h"
3838
#include "compression.h"
39-
#include "m_ctype.h"
39+
#include "m_string.h"
4040
#include "my_alloc.h"
4141
#include "my_compiler.h"
4242
#include "my_dbug.h"
@@ -46,8 +46,13 @@
4646
#include "my_macros.h"
4747
#include "my_thread.h" /* because of signal() */
4848
#include "mysql/service_mysql_alloc.h"
49+
#include "mysql/strings/int2str.h"
50+
#include "mysql/strings/m_ctype.h"
51+
#include "nulls.h"
4952
#include "print_version.h"
5053
#include "sql_common.h"
54+
#include "str2int.h"
55+
#include "strxmov.h"
5156
#include "typelib.h"
5257
#include "welcome_copyright_notice.h" /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
5358

client/mysqlbinlog.cc

+4
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@
5252
#include "libbinlogevents/include/compression/factory.h"
5353
#include "libbinlogevents/include/compression/iterator.h"
5454
#include "libbinlogevents/include/trx_boundary_parser.h"
55+
#include "m_string.h"
5556
#include "my_byteorder.h"
5657
#include "my_dbug.h"
5758
#include "my_default.h"
5859
#include "my_dir.h"
5960
#include "my_io.h"
6061
#include "my_macros.h"
6162
#include "my_time.h"
63+
#include "mysql/strings/int2str.h"
64+
#include "mysql/strings/m_ctype.h"
65+
#include "nulls.h"
6266
#include "prealloced_array.h"
6367
#include "print_version.h"
6468
#include "sql/binlog_reader.h"

client/mysqldump.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
#include "client/client_priv.h"
4040
#include "compression.h"
41-
#include "m_ctype.h"
4241
#include "m_string.h"
4342
#include "map_helpers.h"
4443
#include "my_compiler.h"
@@ -53,11 +52,16 @@
5352
#include "my_user.h"
5453
#include "mysql.h"
5554
#include "mysql/service_mysql_alloc.h"
55+
#include "mysql/strings/m_ctype.h"
5656
#include "mysql_version.h"
5757
#include "mysqld_error.h"
58+
#include "nulls.h"
5859
#include "prealloced_array.h"
5960
#include "print_version.h"
6061
#include "scope_guard.h"
62+
#include "string_with_len.h"
63+
#include "strmake.h"
64+
#include "strxmov.h"
6165
#include "template_utils.h"
6266
#include "typelib.h"
6367
#include "welcome_copyright_notice.h" /* ORACLE_WELCOME_COPYRIGHT_NOTICE */

0 commit comments

Comments
 (0)