Skip to content

Commit bcb7759

Browse files
vuvovaOlernov
authored andcommitted
cleanup: CREATE_TYPELIB_FOR() helper
(cherry picked from commit d046aca)
1 parent b8bdbd1 commit bcb7759

39 files changed

+323
-484
lines changed

client/mysqladmin.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ static const char *command_names[]= {
111111
NullS
112112
};
113113

114-
static TYPELIB command_typelib=
115-
{ array_elements(command_names)-1,"commands", command_names, NULL};
114+
static TYPELIB command_typelib= CREATE_TYPELIB_FOR(command_names);
116115

117116
static struct my_option my_long_options[] =
118117
{

client/mysqlbinlog.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ static bool one_database=0, one_table=0, to_last_remote_log= 0, disable_log_bin=
116116
static bool opt_hexdump= 0, opt_version= 0;
117117
const char *base64_output_mode_names[]=
118118
{"NEVER", "AUTO", "UNSPEC", "DECODE-ROWS", NullS};
119-
TYPELIB base64_output_mode_typelib=
120-
{ array_elements(base64_output_mode_names) - 1, "",
121-
base64_output_mode_names, NULL };
119+
TYPELIB base64_output_mode_typelib=CREATE_TYPELIB_FOR(base64_output_mode_names);
122120
static enum_base64_output_mode opt_base64_output_mode= BASE64_OUTPUT_UNSPEC;
123121
static char *opt_base64_output_mode_str= NullS;
124122
static char* database= 0;

client/mysqlcheck.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ const char *operation_name[]=
6666
typedef enum { DO_VIEWS_NO, DO_VIEWS_YES, DO_UPGRADE, DO_VIEWS_FROM_MYSQL } enum_do_views;
6767
const char *do_views_opts[]= {"NO", "YES", "UPGRADE", "UPGRADE_FROM_MYSQL",
6868
NullS};
69-
TYPELIB do_views_typelib= { array_elements(do_views_opts) - 1, "",
70-
do_views_opts, NULL };
69+
TYPELIB do_views_typelib= CREATE_TYPELIB_FOR(do_views_opts);
7170
static ulong opt_do_views= DO_VIEWS_NO;
7271

7372
static struct my_option my_long_options[] =

client/mysqldump.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_no_data_m
140140
#define OPT_SYSTEM_TIMEZONES 64
141141
static const char *opt_system_type_values[]=
142142
{"all", "users", "plugins", "udfs", "servers", "stats", "timezones"};
143-
static TYPELIB opt_system_types=
144-
{
145-
array_elements(opt_system_type_values), "system dump options",
146-
opt_system_type_values, NULL
147-
};
143+
static TYPELIB opt_system_types=CREATE_TYPELIB_FOR(opt_system_type_values);
148144
static ulonglong opt_system= 0ULL;
149145
static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0,
150146
select_field_names_inited= 0;
@@ -236,8 +232,7 @@ const char *compatible_mode_names[]=
236232
(1U<<6) | /* MAXDB */\
237233
(1U<<10) /* ANSI */\
238234
)
239-
TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
240-
"", compatible_mode_names, NULL};
235+
TYPELIB compatible_mode_typelib= CREATE_TYPELIB_FOR(compatible_mode_names);
241236

242237
#define MED_ENGINES "MRG_MyISAM, MRG_ISAM, CONNECT, OQGRAPH, SPIDER, VP, FEDERATED"
243238

client/mysqltest.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,7 @@ struct st_command
595595
enum enum_commands type;
596596
};
597597

598-
TYPELIB command_typelib= {array_elements(command_names),"",
599-
command_names, 0};
598+
TYPELIB command_typelib= CREATE_TYPELIB_FOR(command_names);
600599

601600
DYNAMIC_STRING ds_res;
602601
/* Points to ds_warning in run_query, so it can be freed */

extra/mariabackup/xbcloud.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ static enum {MODE_GET, MODE_PUT, MODE_DELETE} opt_mode;
176176
static char **file_list = NULL;
177177
static int file_list_size = 0;
178178

179-
TYPELIB storage_typelib =
180-
{array_elements(storage_names)-1, "", storage_names, NULL};
179+
TYPELIB storage_typelib = CREATE_TYPELIB_FOR(storage_names);
181180

182181
enum {
183182
OPT_STORAGE = 256,

extra/mariabackup/xtrabackup.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ static ulong innodb_flush_method;
389389

390390
static const char *binlog_info_values[] = {"off", "lockless", "on", "auto",
391391
NullS};
392-
static TYPELIB binlog_info_typelib = {array_elements(binlog_info_values)-1, "",
393-
binlog_info_values, NULL};
392+
static TYPELIB binlog_info_typelib = CREATE_TYPELIB_FOR(binlog_info_values);
394393
ulong opt_binlog_info;
395394

396395
char *opt_incremental_history_name;
@@ -407,8 +406,7 @@ char *opt_log_bin;
407406

408407
const char *query_type_names[] = { "ALL", "UPDATE", "SELECT", NullS};
409408

410-
TYPELIB query_type_typelib= {array_elements(query_type_names) - 1, "",
411-
query_type_names, NULL};
409+
TYPELIB query_type_typelib= CREATE_TYPELIB_FOR(query_type_names);
412410

413411
ulong opt_lock_wait_query_type;
414412
ulong opt_kill_long_query_type;

include/typelib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ typedef struct st_typelib { /* Different types saved here */
2727
unsigned int *type_lengths;
2828
} TYPELIB;
2929

30+
#define CREATE_TYPELIB_FOR(X) { (unsigned int)(sizeof(X)/sizeof(X[0])) - 1, "", X, NULL }
31+
3032
extern my_ulonglong find_typeset(const char *x, TYPELIB *typelib,
3133
int *error_position);
3234
extern int find_type_with_warning(const char *x, TYPELIB *typelib,

mysys/my_static.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,4 @@ my_bool my_disable_copystat_in_redel=0;
131131
const char *sql_protocol_names_lib[] =
132132
{ "TCP", "SOCKET", "PIPE", NullS };
133133

134-
TYPELIB sql_protocol_typelib ={ array_elements(sql_protocol_names_lib) - 1, "",
135-
sql_protocol_names_lib, NULL };
134+
TYPELIB sql_protocol_typelib= CREATE_TYPELIB_FOR(sql_protocol_names_lib);

mysys/typelib.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ TYPELIB *copy_typelib(MEM_ROOT *root, const TYPELIB *from)
265265

266266

267267
static const char *on_off_default_names[]= { "off","on","default", 0};
268-
static TYPELIB on_off_default_typelib= {array_elements(on_off_default_names)-1,
269-
"", on_off_default_names, 0};
268+
static TYPELIB on_off_default_typelib= CREATE_TYPELIB_FOR(on_off_default_names);
270269

271270
/**
272271
Parse a TYPELIB name from the buffer

0 commit comments

Comments
 (0)