Skip to content

Commit 088e239

Browse files
author
monty@mysql.com/narttu.mysql.fi
committed
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done: - Changed byte to uchar - Changed gptr to uchar* - Change my_string to char * - Change my_size_t to size_t - Change size_s to size_t Removed declaration of byte, gptr, my_string, my_size_t and size_s. Following function parameter changes was done: - All string functions in mysys/strings was changed to use size_t instead of uint for string lengths. - All read()/write() functions changed to use size_t (including vio). - All protocoll functions changed to use size_t instead of uint - Functions that used a pointer to a string length was changed to use size_t* - Changed malloc(), free() and related functions from using gptr to use void * as this requires fewer casts in the code and is more in line with how the standard functions work. - Added extra length argument to dirname_part() to return the length of the created string. - Changed (at least) following functions to take uchar* as argument: - db_dump() - my_net_write() - net_write_command() - net_store_data() - DBUG_DUMP() - decimal2bin() & bin2decimal() - Changed my_compress() and my_uncompress() to use size_t. Changed one argument to my_uncompress() from a pointer to a value as we only return one value (makes function easier to use). - Changed type of 'pack_data' argument to packfrm() to avoid casts. - Changed in readfrm() and writefrom(), ha_discover and handler::discover() the type for argument 'frmdata' to uchar** to avoid casts. - Changed most Field functions to use uchar* instead of char* (reduced a lot of casts). - Changed field->val_xxx(xxx, new_ptr) to take const pointers. Other changes: - Removed a lot of not needed casts - Added a few new cast required by other changes - Added some cast to my_multi_malloc() arguments for safety (as string lengths needs to be uint, not size_t). - Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done explicitely as this conflict was often hided by casting the function to hash_get_key). - Changed some buffers to memory regions to uchar* to avoid casts. - Changed some string lengths from uint to size_t. - Changed field->ptr to be uchar* instead of char*. This allowed us to get rid of a lot of casts. - Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar - Include zlib.h in some files as we needed declaration of crc32() - Changed MY_FILE_ERROR to be (size_t) -1. - Changed many variables to hold the result of my_read() / my_write() to be size_t. This was needed to properly detect errors (which are returned as (size_t) -1). - Removed some very old VMS code - Changed packfrm()/unpackfrm() to not be depending on uint size (portability fix) - Removed windows specific code to restore cursor position as this causes slowdown on windows and we should not mix read() and pread() calls anyway as this is not thread safe. Updated function comment to reflect this. Changed function that depended on original behavior of my_pwrite() to itself restore the cursor position (one such case). - Added some missing checking of return value of malloc(). - Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow. - Changed type of table_def::m_size from my_size_t to ulong to reflect that m_size is the number of elements in the array, not a string/memory length. - Moved THD::max_row_length() to table.cc (as it's not depending on THD). Inlined max_row_length_blob() into this function. - More function comments - Fixed some compiler warnings when compiled without partitions. - Removed setting of LEX_STRING() arguments in declaration (portability fix). - Some trivial indentation/variable name changes. - Some trivial code simplifications: - Replaced some calls to alloc_root + memcpy to use strmake_root()/strdup_root(). - Changed some calls from memdup() to strmake() (Safety fix) - Simpler loops in client-simple.c
1 parent 9078e63 commit 088e239

File tree

474 files changed

+8483
-8353
lines changed

Some content is hidden

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

474 files changed

+8483
-8353
lines changed

.bzrignore

+3
Original file line numberDiff line numberDiff line change
@@ -2989,3 +2989,6 @@ win/vs71cache.txt
29892989
win/vs8cache.txt
29902990
zlib/*.ds?
29912991
zlib/*.vcproj
2992+
libmysqld/ha_ndbcluster_cond.cc
2993+
debian/defs.mk
2994+
debian/control

client/completion_hash.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void completion_hash_clean(HashTable *ht)
213213
void completion_hash_free(HashTable *ht)
214214
{
215215
completion_hash_clean(ht);
216-
my_free((gptr) ht->arBuckets,MYF(0));
216+
my_free(ht->arBuckets, MYF(0));
217217
}
218218

219219

client/my_readline.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ typedef struct st_line_buffer
2828
} LINE_BUFFER;
2929

3030
extern LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file);
31-
extern LINE_BUFFER *batch_readline_command(LINE_BUFFER *buffer, my_string str);
31+
extern LINE_BUFFER *batch_readline_command(LINE_BUFFER *buffer, char * str);
3232
extern char *batch_readline(LINE_BUFFER *buffer);
3333
extern void batch_readline_end(LINE_BUFFER *buffer);

client/mysql.cc

+64-64
Large diffs are not rendered by default.

client/mysql_upgrade.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ static struct my_option my_long_options[]=
6363
{"debug", '#', "This is a non-debug version. Catch this and exit",
6464
0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
6565
#else
66-
{"debug", '#', "Output debug log", (gptr *) & default_dbug_option,
67-
(gptr *) & default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
66+
{"debug", '#', "Output debug log", (uchar* *) & default_dbug_option,
67+
(uchar* *) & default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
6868
#endif
6969
{"default-character-set", OPT_DEFAULT_CHARSET,
7070
"Set the default character set.", 0,
@@ -73,16 +73,16 @@ static struct my_option my_long_options[]=
7373
"Directory where character sets are.", 0,
7474
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
7575
{"compress", OPT_COMPRESS, "Use compression in server/client protocol.",
76-
(gptr*)&not_used, (gptr*)&not_used, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
76+
(uchar**)&not_used, (uchar**)&not_used, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
7777
{"force", 'f', "Force execution of mysqlcheck even if mysql_upgrade "
7878
"has already been executed for the current version of MySQL.",
79-
(gptr*)&opt_force, (gptr*)&opt_force, 0,
79+
(uchar**)&opt_force, (uchar**)&opt_force, 0,
8080
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
8181
{"host",'h', "Connect to host.", 0,
8282
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
8383
{"password", 'p',
8484
"Password to use when connecting to server. If password is not given"
85-
" it's solicited on the tty.", (gptr*) &opt_password,(gptr*) &opt_password,
85+
" it's solicited on the tty.", (uchar**) &opt_password,(uchar**) &opt_password,
8686
0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
8787
#ifdef __WIN__
8888
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0,
@@ -100,11 +100,11 @@ static struct my_option my_long_options[]=
100100
#endif
101101
{"socket", 'S', "Socket file to use for connection.",
102102
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
103-
{"user", 'u', "User for login if not current user.", (gptr*) &opt_user,
104-
(gptr*) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
103+
{"user", 'u', "User for login if not current user.", (uchar**) &opt_user,
104+
(uchar**) &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
105105
#include <sslopt-longopts.h>
106106
{"verbose", 'v', "Display more output about the process",
107-
(gptr*) &opt_verbose, (gptr*) &opt_verbose, 0,
107+
(uchar**) &opt_verbose, (uchar**) &opt_verbose, 0,
108108
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
109109
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
110110
};
@@ -387,13 +387,14 @@ static void find_tool(char *tool_path, const char *tool_name)
387387
}
388388
do
389389
{
390+
size_t path_len;
390391
DBUG_PRINT("enter", ("path: %s", path));
391392

392393
/* Chop off last char(since it might be a /) */
393394
path[max((strlen(path)-1), 0)]= 0;
394395

395396
/* Chop off last dir part */
396-
dirname_part(path, path);
397+
dirname_part(path, path, &path_len);
397398

398399
/* Format name of the tool to search for */
399400
fn_format(tool_path, tool_name,

client/mysqladmin.cc

+32-32
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static my_bool option_force=0,interrupted=0,new_line=0,
4444
static uint tcp_port = 0, option_wait = 0, option_silent=0, nr_iterations,
4545
opt_count_iterations= 0;
4646
static ulong opt_connect_timeout, opt_shutdown_timeout;
47-
static my_string unix_port=0;
47+
static char * unix_port=0;
4848
#ifdef LATER_HAVE_NDBCLUSTER_DB
4949
static my_bool opt_ndbcluster=0;
5050
static char *opt_ndb_connectstring=0;
@@ -132,90 +132,90 @@ static struct my_option my_long_options[] =
132132
#endif
133133
{"count", 'c',
134134
"Number of iterations to make. This works with -i (--sleep) only.",
135-
(gptr*) &nr_iterations, (gptr*) &nr_iterations, 0, GET_UINT,
135+
(uchar**) &nr_iterations, (uchar**) &nr_iterations, 0, GET_UINT,
136136
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
137137
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
138138
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
139-
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.", (gptr*) &info_flag,
140-
(gptr*) &info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
139+
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.", (uchar**) &info_flag,
140+
(uchar**) &info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
141141
{"force", 'f',
142142
"Don't ask for confirmation on drop database; with multiple commands, continue even if an error occurs.",
143-
(gptr*) &option_force, (gptr*) &option_force, 0, GET_BOOL, NO_ARG, 0, 0,
143+
(uchar**) &option_force, (uchar**) &option_force, 0, GET_BOOL, NO_ARG, 0, 0,
144144
0, 0, 0, 0},
145145
{"compress", 'C', "Use compression in server/client protocol.",
146-
(gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
146+
(uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
147147
0, 0, 0},
148148
{"character-sets-dir", OPT_CHARSETS_DIR,
149-
"Directory where character sets are.", (gptr*) &charsets_dir,
150-
(gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
149+
"Directory where character sets are.", (uchar**) &charsets_dir,
150+
(uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
151151
{"default-character-set", OPT_DEFAULT_CHARSET,
152-
"Set the default character set.", (gptr*) &default_charset,
153-
(gptr*) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
152+
"Set the default character set.", (uchar**) &default_charset,
153+
(uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
154154
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG,
155155
NO_ARG, 0, 0, 0, 0, 0, 0},
156-
{"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0, GET_STR,
156+
{"host", 'h', "Connect to host.", (uchar**) &host, (uchar**) &host, 0, GET_STR,
157157
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
158-
{"no-beep", 'b', "Turn off beep on error.", (gptr*) &opt_nobeep,
159-
(gptr*) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
158+
{"no-beep", 'b', "Turn off beep on error.", (uchar**) &opt_nobeep,
159+
(uchar**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
160160
{"password", 'p',
161161
"Password to use when connecting to server. If password is not given it's asked from the tty.",
162162
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
163163
#ifdef __WIN__
164164
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
165165
NO_ARG, 0, 0, 0, 0, 0, 0},
166166
#endif
167-
{"port", 'P', "Port number to use for connection.", (gptr*) &tcp_port,
168-
(gptr*) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
167+
{"port", 'P', "Port number to use for connection.", (uchar**) &tcp_port,
168+
(uchar**) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
169169
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
170170
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
171171
{"relative", 'r',
172172
"Show difference between current and previous values when used with -i. Currently works only with extended-status.",
173-
(gptr*) &opt_relative, (gptr*) &opt_relative, 0, GET_BOOL, NO_ARG, 0, 0, 0,
173+
(uchar**) &opt_relative, (uchar**) &opt_relative, 0, GET_BOOL, NO_ARG, 0, 0, 0,
174174
0, 0, 0},
175175
{"set-variable", 'O',
176176
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
177177
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
178178
#ifdef HAVE_SMEM
179179
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
180-
"Base name of shared memory.", (gptr*) &shared_memory_base_name, (gptr*) &shared_memory_base_name,
180+
"Base name of shared memory.", (uchar**) &shared_memory_base_name, (uchar**) &shared_memory_base_name,
181181
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
182182
#endif
183183
{"silent", 's', "Silently exit if one can't connect to server.",
184184
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
185185
{"socket", 'S', "Socket file to use for connection.",
186-
(gptr*) &unix_port, (gptr*) &unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
186+
(uchar**) &unix_port, (uchar**) &unix_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
187187
0, 0, 0},
188188
{"sleep", 'i', "Execute commands again and again with a sleep between.",
189-
(gptr*) &interval, (gptr*) &interval, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0,
189+
(uchar**) &interval, (uchar**) &interval, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0,
190190
0, 0},
191191
#include <sslopt-longopts.h>
192192
#ifndef DONT_ALLOW_USER_CHANGE
193-
{"user", 'u', "User for login if not current user.", (gptr*) &user,
194-
(gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
193+
{"user", 'u', "User for login if not current user.", (uchar**) &user,
194+
(uchar**) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
195195
#endif
196-
{"verbose", 'v', "Write more information.", (gptr*) &opt_verbose,
197-
(gptr*) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
196+
{"verbose", 'v', "Write more information.", (uchar**) &opt_verbose,
197+
(uchar**) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
198198
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
199199
NO_ARG, 0, 0, 0, 0, 0, 0},
200200
{"vertical", 'E',
201201
"Print output vertically. Is similar to --relative, but prints output vertically.",
202-
(gptr*) &opt_vertical, (gptr*) &opt_vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0,
202+
(uchar**) &opt_vertical, (uchar**) &opt_vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0,
203203
0, 0, 0},
204204
{"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_UINT,
205205
OPT_ARG, 0, 0, 0, 0, 0, 0},
206-
{"connect_timeout", OPT_CONNECT_TIMEOUT, "", (gptr*) &opt_connect_timeout,
207-
(gptr*) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 3600*12, 0,
206+
{"connect_timeout", OPT_CONNECT_TIMEOUT, "", (uchar**) &opt_connect_timeout,
207+
(uchar**) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 3600*12, 0,
208208
3600*12, 0, 1, 0},
209-
{"shutdown_timeout", OPT_SHUTDOWN_TIMEOUT, "", (gptr*) &opt_shutdown_timeout,
210-
(gptr*) &opt_shutdown_timeout, 0, GET_ULONG, REQUIRED_ARG,
209+
{"shutdown_timeout", OPT_SHUTDOWN_TIMEOUT, "", (uchar**) &opt_shutdown_timeout,
210+
(uchar**) &opt_shutdown_timeout, 0, GET_ULONG, REQUIRED_ARG,
211211
SHUTDOWN_DEF_TIMEOUT, 0, 3600*12, 0, 1, 0},
212212
#ifdef LATER_HAVE_NDBCLUSTER_DB
213213
{"ndbcluster", OPT_NDBCLUSTER, ""
214-
"", (gptr*) &opt_ndbcluster,
215-
(gptr*) &opt_ndbcluster, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
214+
"", (uchar**) &opt_ndbcluster,
215+
(uchar**) &opt_ndbcluster, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
216216
{"ndb-connectstring", OPT_NDB_CONNECTSTRING, ""
217-
"", (gptr*) &opt_ndb_connectstring,
218-
(gptr*) &opt_ndb_connectstring, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
217+
"", (uchar**) &opt_ndb_connectstring,
218+
(uchar**) &opt_ndb_connectstring, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
219219
#endif
220220
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
221221
};

0 commit comments

Comments
 (0)