Skip to content

Commit c7a720b

Browse files
committed
Bug#21881278: SWITCH MYSYS LIBRARY FROM C TO C++
This patch switches all mysys/ files from .c to .cc. By doing this we get stricter compile checks (e.g. type checks) and it makes it possible to use C++ features for future bug fixes and extensions inside mysys.
1 parent 90f1d8c commit c7a720b

File tree

118 files changed

+461
-309
lines changed

Some content is hidden

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

118 files changed

+461
-309
lines changed

client/check/mysqlcheck.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ static void usage(void)
262262
} /* usage */
263263

264264

265+
extern "C" {
265266
static my_bool
266267
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
267268
char *argument)
@@ -355,6 +356,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
355356
}
356357
return 0;
357358
}
359+
}
358360

359361

360362
static int get_options(int *argc, char ***argv)

client/check/mysqlcheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ class Program
136136
}
137137
}
138138

139-
#endif
139+
#endif

client/mysql.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,12 +2809,12 @@ C_MODE_END
28092809

28102810
#if defined(USE_NEW_READLINE_INTERFACE)
28112811
static int fake_magic_space(int, int);
2812-
extern "C" char *no_completion(const char*,int)
2812+
char *no_completion(const char*,int)
28132813
#elif defined(USE_LIBEDIT_INTERFACE)
28142814
static int fake_magic_space(const char *, int);
2815-
extern "C" int no_completion(const char*,int)
2815+
int no_completion(const char*,int)
28162816
#else
2817-
extern "C" char *no_completion()
2817+
char *no_completion()
28182818
#endif
28192819
{
28202820
return 0; /* No filename completion */

client/mysql_config_editor.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ enum commands {
100100
MY_CONFIG_HELP
101101
};
102102

103+
extern "C" {
103104
struct my_command_data {
104105
const int id;
105106
const char *name;
@@ -109,6 +110,7 @@ struct my_command_data {
109110
const struct my_option *opt,
110111
char *argument);
111112
};
113+
}
112114

113115

114116
/* mysql_config_editor utility options. */
@@ -212,6 +214,7 @@ static struct my_option my_help_command_options[]=
212214
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
213215
};
214216

217+
extern "C" {
215218
static my_bool
216219
my_program_get_one_option(int optid,
217220
const struct my_option *opt __attribute__((unused)),
@@ -321,6 +324,7 @@ my_reset_command_get_one_option(int optid,
321324
}
322325
return 0;
323326
}
327+
}
324328

325329
static struct my_command_data command_data[]=
326330
{

client/mysql_secure_installation.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static void free_resources()
120120
free_defaults(defaults_argv);
121121
}
122122

123+
extern "C" {
123124
static my_bool
124125
my_arguments_get_one_option(int optid,
125126
const struct my_option *opt __attribute__((unused)),
@@ -164,6 +165,7 @@ my_arguments_get_one_option(int optid,
164165
}
165166
return 0;
166167
}
168+
}
167169

168170

169171
/* Initialize options for the given connection handle. */

client/mysql_ssl_rsa_setup.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ void usage(void)
370370
}
371371

372372

373+
extern "C" {
373374
static my_bool
374375
my_arguments_get_one_option(int optid,
375376
const struct my_option *opt __attribute__((unused)),
@@ -387,6 +388,7 @@ my_arguments_get_one_option(int optid,
387388
}
388389
return 0;
389390
}
391+
}
390392

391393

392394
static inline

client/mysqlslap.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ static void usage(void)
751751
}
752752

753753

754+
extern "C" {
754755
static my_bool
755756
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
756757
char *argument)
@@ -820,6 +821,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
820821
}
821822
DBUG_RETURN(0);
822823
}
824+
}
823825

824826

825827
size_t

include/my_global.h

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -626,37 +626,12 @@ struct timespec {
626626
#endif /* !HAVE_STRUCT_TIMESPEC */
627627

628628
C_MODE_START
629-
extern ulonglong my_getsystime(void);
630-
C_MODE_END
629+
ulonglong my_getsystime(void);
631630

632-
static inline void set_timespec_nsec(struct timespec *abstime, ulonglong nsec)
633-
{
634-
#ifdef HAVE_STRUCT_TIMESPEC
635-
ulonglong now= my_getsystime() + (nsec / 100);
636-
ulonglong tv_sec= now / 10000000ULL;
637-
#if SIZEOF_TIME_T < SIZEOF_LONG_LONG
638-
/* Ensure that the number of seconds don't overflow. */
639-
tv_sec= MY_MIN(tv_sec, ((ulonglong)INT_MAX32));
640-
#endif
641-
abstime->tv_sec= (time_t)tv_sec;
642-
abstime->tv_nsec= (now % 10000000ULL) * 100 + (nsec % 100);
643-
#else /* !HAVE_STRUCT_TIMESPEC */
644-
ulonglong max_timeout_msec= (nsec / 1000000);
645-
union ft64 tv;
646-
GetSystemTimeAsFileTime(&tv.ft);
647-
abstime->tv.i64= tv.i64 + (__int64)(nsec / 100);
648-
#if SIZEOF_LONG < SIZEOF_LONG_LONG
649-
/* Ensure that the msec value doesn't overflow. */
650-
max_timeout_msec= MY_MIN(max_timeout_msec, ((ulonglong)INT_MAX32));
651-
#endif
652-
abstime->max_timeout_msec= (long)max_timeout_msec;
653-
#endif /* !HAVE_STRUCT_TIMESPEC */
654-
}
631+
void set_timespec_nsec(struct timespec *abstime, ulonglong nsec);
655632

656-
static inline void set_timespec(struct timespec *abstime, ulonglong sec)
657-
{
658-
set_timespec_nsec(abstime, sec * 1000000000ULL);
659-
}
633+
void set_timespec(struct timespec *abstime, ulonglong sec);
634+
C_MODE_END
660635

661636
/**
662637
Compare two timespec structs.

include/my_sys.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -743,13 +743,6 @@ File create_temp_file(char *to, const char *dir, const char *pfx,
743743
int mode, myf MyFlags);
744744

745745
// Use Prealloced_array or std::vector or something similar in C++
746-
#if defined(__cplusplus)
747-
748-
#define init_dynamic_array please_use_an_appropriately_typed_container
749-
#define my_init_dynamic_array please_use_an_appropriately_typed_container
750-
751-
#else
752-
753746
extern my_bool my_init_dynamic_array(DYNAMIC_ARRAY *array,
754747
PSI_memory_key key,
755748
uint element_size,
@@ -762,8 +755,6 @@ extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
762755
#define dynamic_element(array,array_index,type) \
763756
((type)((array)->buffer) +(array_index))
764757

765-
#endif /* __cplusplus */
766-
767758
/* Some functions are still in use in C++, because HASH uses DYNAMIC_ARRAY */
768759
extern my_bool insert_dynamic(DYNAMIC_ARRAY *array, const void *element);
769760
extern void *alloc_dynamic(DYNAMIC_ARRAY *array);
@@ -801,10 +792,7 @@ extern void free_root(MEM_ROOT *root, myf MyFLAGS);
801792
extern void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
802793
size_t prealloc_size);
803794
extern char *strdup_root(MEM_ROOT *root,const char *str);
804-
static inline char *safe_strdup_root(MEM_ROOT *root, const char *str)
805-
{
806-
return str ? strdup_root(root, str) : 0;
807-
}
795+
extern char *safe_strdup_root(MEM_ROOT *root, const char *str);
808796
extern char *strmake_root(MEM_ROOT *root,const char *str,size_t len);
809797
extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
810798
extern void set_memroot_max_capacity(MEM_ROOT *mem_root, size_t size);

include/thr_lock.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <my_list.h>
2727
#include "mysql/psi/mysql_thread.h"
2828

29+
extern mysql_mutex_t THR_LOCK_lock;
30+
2931
#ifdef __cplusplus
3032
extern "C" {
3133
#endif
@@ -134,7 +136,6 @@ typedef struct st_thr_lock {
134136

135137

136138
extern LIST *thr_lock_thread_list;
137-
extern mysql_mutex_t THR_LOCK_lock;
138139

139140
void thr_lock_info_init(THR_LOCK_INFO *info, my_thread_id thread_id,
140141
mysql_cond_t *suspend);

mysys/CMakeLists.txt

Lines changed: 102 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,123 @@
1515

1616
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/mysys)
1717

18-
SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c
19-
errors.c hash.c list.c mf_cache.c mf_dirname.c mf_fn_ext.c
20-
mf_format.c mf_getdate.c mf_iocache.c mf_iocache2.c mf_keycache.c
21-
mf_keycaches.c mf_loadpath.c mf_pack.c mf_path.c mf_qsort.c mf_qsort2.c
22-
mf_radix.c mf_same.c mf_soundex.c mf_arr_appstr.c
23-
mf_tempfile.c mf_unixpath.c mf_wcomp.c mulalloc.c my_access.c
24-
my_alloc.c my_bit.c my_bitmap.c my_chsize.c
25-
my_compress.c my_copy.c my_create.c my_delete.c
26-
my_div.c my_error.c my_file.c my_fopen.c my_fstream.c
27-
my_gethwaddr.c my_getsystime.c my_getwd.c my_compare.c my_init.c
28-
my_lib.c my_lock.c my_malloc.c my_mess.c
29-
my_mkdir.c my_mmap.c my_once.c my_open.c my_pread.c
30-
my_read.c my_redel.c my_rename.c my_seek.c
31-
my_static.c my_symlink.c my_symlink2.c my_sync.c my_thr_init.c
32-
my_write.c ptr_cmp.c queues.c stacktrace.c
33-
string.c thr_cond.c thr_lock.c thr_mutex.c
34-
thr_rwlock.c tree.c typelib.c base64.c my_memmem.c
35-
lf_alloc-pin.c lf_dynarray.c lf_hash.c
36-
my_rdtsc.c psi_noop.c my_syslog.c
37-
my_chmod.c my_thread.c)
18+
SET(MYSYS_SOURCES
19+
array.cc
20+
base64.cc
21+
charset.cc
22+
charset-def.cc
23+
checksum.cc
24+
errors.cc
25+
hash.cc
26+
lf_alloc-pin.cc
27+
lf_dynarray.cc
28+
lf_hash.cc
29+
list.cc
30+
mf_arr_appstr.cc
31+
mf_cache.cc
32+
mf_dirname.cc
33+
mf_fn_ext.cc
34+
mf_format.cc
35+
mf_getdate.cc
36+
mf_iocache2.cc
37+
mf_iocache.cc
38+
mf_keycache.cc
39+
mf_keycaches.cc
40+
mf_loadpath.cc
41+
mf_pack.cc
42+
mf_path.cc
43+
mf_qsort2.cc
44+
mf_qsort.cc
45+
mf_radix.cc
46+
mf_same.cc
47+
mf_soundex.cc
48+
mf_tempfile.cc
49+
mf_unixpath.cc
50+
mf_wcomp.cc
51+
mulalloc.cc
52+
my_access.cc
53+
my_alloc.cc
54+
my_bit.cc
55+
my_bitmap.cc
56+
my_chmod.cc
57+
my_chsize.cc
58+
my_compare.cc
59+
my_compress.cc
60+
my_copy.cc
61+
my_create.cc
62+
my_delete.cc
63+
my_div.cc
64+
my_error.cc
65+
my_file.cc
66+
my_fopen.cc
67+
my_fstream.cc
68+
my_gethwaddr.cc
69+
my_getsystime.cc
70+
my_getwd.cc
71+
my_init.cc
72+
my_lib.cc
73+
my_lock.cc
74+
my_malloc.cc
75+
my_memmem.cc
76+
my_mess.cc
77+
my_mkdir.cc
78+
my_mmap.cc
79+
my_once.cc
80+
my_open.cc
81+
my_pread.cc
82+
my_rdtsc.cc
83+
my_read.cc
84+
my_redel.cc
85+
my_rename.cc
86+
my_seek.cc
87+
my_static.cc
88+
my_symlink2.cc
89+
my_symlink.cc
90+
my_sync.cc
91+
my_syslog.cc
92+
my_thread.cc
93+
my_thr_init.cc
94+
my_timespec.cc
95+
my_write.cc
96+
psi_noop.cc
97+
ptr_cmp.cc
98+
queues.cc
99+
stacktrace.cc
100+
string.cc
101+
thr_cond.cc
102+
thr_lock.cc
103+
thr_mutex.cc
104+
thr_rwlock.cc
105+
tree.cc
106+
typelib.cc
107+
)
38108

39109
IF (WIN32)
40110
LIST(APPEND MYSYS_SOURCES
41-
my_conio.c
42-
my_windac.c
43-
my_winerr.c
44-
my_winfile.c
45-
win_timers.c
111+
my_conio.cc
112+
my_windac.cc
113+
my_winerr.cc
114+
my_winfile.cc
115+
win_timers.cc
46116
)
47117
ENDIF()
48118

49119
IF(HAVE_POSIX_TIMERS)
50-
SET(MYSYS_SOURCES ${MYSYS_SOURCES} posix_timers.c)
120+
SET(MYSYS_SOURCES ${MYSYS_SOURCES} posix_timers.cc)
51121
ENDIF()
52122

53123
IF(HAVE_KQUEUE_TIMERS)
54-
SET(MYSYS_SOURCES ${MYSYS_SOURCES} kqueue_timers.c)
124+
SET(MYSYS_SOURCES ${MYSYS_SOURCES} kqueue_timers.cc)
55125
ENDIF()
56126

57127
IF(CMAKE_SYSTEM_NAME MATCHES "SunOS" AND CMAKE_C_COMPILER_ID MATCHES "SunPro")
58128
# Inline assembly template for rdtsc
59-
SET_SOURCE_FILES_PROPERTIES(my_rdtsc.c
129+
SET_SOURCE_FILES_PROPERTIES(my_rdtsc.cc
60130
PROPERTIES COMPILE_FLAGS "${CMAKE_CURRENT_SOURCE_DIR}/my_timer_cycles.il")
61131
ENDIF()
62132

63133
IF(HAVE_LINUX_LARGE_PAGES)
64-
SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_largepage.c)
134+
SET(MYSYS_SOURCES ${MYSYS_SOURCES} my_largepage.cc)
65135
ENDIF()
66136

67137
ADD_CONVENIENCE_LIBRARY(mysys ${MYSYS_SOURCES})
@@ -74,15 +144,15 @@ IF(CMAKE_USE_PTHREADS_INIT AND CMAKE_C_FLAGS MATCHES "-fsanitize=")
74144
TARGET_LINK_LIBRARIES(mysys pthread)
75145
ENDIF()
76146

77-
ADD_EXECUTABLE(thr_lock thr_lock.c)
147+
ADD_EXECUTABLE(thr_lock thr_lock.cc)
78148
TARGET_LINK_LIBRARIES(thr_lock mysys)
79149
SET_TARGET_PROPERTIES(thr_lock PROPERTIES COMPILE_FLAGS "-DMAIN")
80-
ADD_EXECUTABLE(queues queues.c)
150+
ADD_EXECUTABLE(queues queues.cc)
81151
TARGET_LINK_LIBRARIES(queues mysys)
82152
SET_TARGET_PROPERTIES(queues PROPERTIES COMPILE_FLAGS "-DMAIN")
83153
ADD_TEST(queues_test queues)
84154

85-
ADD_EXECUTABLE(base64_test base64.c)
155+
ADD_EXECUTABLE(base64_test base64.cc)
86156
SET_TARGET_PROPERTIES(base64_test PROPERTIES COMPILE_FLAGS "-DMAIN")
87157
TARGET_LINK_LIBRARIES(base64_test mysys)
88158

0 commit comments

Comments
 (0)