1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-14 13:41:20 +03:00

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
This commit is contained in:
monty@mysql.com/narttu.mysql.fi
2007-05-10 12:59:39 +03:00
parent 9078e630c6
commit 088e2395f1
474 changed files with 8476 additions and 8346 deletions

View File

@ -170,7 +170,7 @@ int Show_instances::write_data(st_net *net)
while ((instance= iterator.next()))
{
Buffer send_buf; /* buffer for packets */
uint pos= 0;
size_t pos= 0;
instance->lock();
@ -356,7 +356,7 @@ int Show_instance_status::write_data(st_net *net, Instance *instance)
{
Buffer send_buf; /* buffer for packets */
char version_num_buf[MAX_VERSION_LENGTH];
uint pos= 0;
size_t pos= 0;
const char *state_name= instance->get_state_name();
const char *version_tag= "unknown";
@ -379,7 +379,7 @@ int Show_instance_status::write_data(st_net *net, Instance *instance)
store_to_protocol_packet(&send_buf, version_num, &pos) ||
store_to_protocol_packet(&send_buf, version_tag, &pos) ||
store_to_protocol_packet(&send_buf, mysqld_compatible_status, &pos) ||
my_net_write(net, send_buf.buffer, (uint) pos))
my_net_write(net, send_buf.buffer, pos))
{
return ER_OUT_OF_RESOURCES;
}
@ -455,7 +455,7 @@ int Show_instance_options::write_header(st_net *net)
int Show_instance_options::write_data(st_net *net, Instance *instance)
{
Buffer send_buff; /* buffer for packets */
uint pos= 0;
size_t pos= 0;
if (store_to_protocol_packet(&send_buff, "instance_name", &pos) ||
store_to_protocol_packet(&send_buff, get_instance_name()->str, &pos) ||
@ -618,7 +618,7 @@ bool Create_instance::init(const char **text)
bool Create_instance::parse_args(const char **text)
{
uint len;
size_t len;
/* Check if we have something (and trim leading spaces). */
@ -991,13 +991,13 @@ int Show_instance_log::write_header(st_net *net)
int Show_instance_log::write_data(st_net *net, Instance *instance)
{
Buffer send_buff; /* buffer for packets */
uint pos= 0;
size_t pos= 0;
const char *logpath= instance->options.logs[log_type];
File fd;
size_t buff_size;
int read_len;
size_t read_len;
MY_STAT file_stat;
Buffer read_buff;
@ -1020,8 +1020,8 @@ int Show_instance_log::write_data(st_net *net, Instance *instance)
/* read in one chunk */
read_len= (int)my_seek(fd, file_stat.st_size - size, MY_SEEK_SET, MYF(0));
if ((read_len= my_read(fd, (byte*) read_buff.buffer,
buff_size, MYF(0))) < 0)
if ((read_len= my_read(fd, read_buff.buffer, buff_size, MYF(0))) ==
MY_FILE_ERROR)
{
close(fd);
return ER_READ_FILE;
@ -1029,7 +1029,8 @@ int Show_instance_log::write_data(st_net *net, Instance *instance)
close(fd);
if (store_to_protocol_packet(&send_buff, read_buff.buffer, &pos, read_len) ||
if (store_to_protocol_packet(&send_buff, (char*) read_buff.buffer, &pos,
read_len) ||
my_net_write(net, send_buff.buffer, pos))
{
return ER_OUT_OF_RESOURCES;
@ -1142,7 +1143,7 @@ int Show_instance_log_files::write_data(st_net *net, Instance *instance)
enum { LOG_NAME_BUFFER_SIZE= 20 };
char buff[LOG_NAME_BUFFER_SIZE];
uint pos= 0;
size_t pos= 0;
const char *log_path= "";
const char *log_size= "0";
@ -1227,12 +1228,12 @@ bool Instance_options_list::init()
C_MODE_START
static byte* get_item_key(const byte* item, uint* len,
my_bool __attribute__((unused)) t)
static uchar* get_item_key(const uchar* item, size_t* len,
my_bool __attribute__((unused)) t)
{
const Instance_options_list *lst= (const Instance_options_list *) item;
*len= lst->get_instance_name()->length;
return (byte *) lst->get_instance_name()->str;
return (uchar *) lst->get_instance_name()->str;
}
static void delete_item(void *item)
@ -1358,7 +1359,7 @@ Abstract_option_cmd::get_instance_options_list(const LEX_STRING *instance_name)
{
Instance_options_list *lst=
(Instance_options_list *) hash_search(&instance_options_map,
(byte *) instance_name->str,
(uchar *) instance_name->str,
instance_name->length);
if (!lst)
@ -1368,7 +1369,7 @@ Abstract_option_cmd::get_instance_options_list(const LEX_STRING *instance_name)
if (!lst)
return NULL;
if (lst->init() || my_hash_insert(&instance_options_map, (byte *) lst))
if (lst->init() || my_hash_insert(&instance_options_map, (uchar *) lst))
{
delete lst;
return NULL;
@ -1458,7 +1459,7 @@ int Abstract_option_cmd::execute_impl(st_net *net, ulong connection_id)
bool Set_option::parse_args(const char **text)
{
uint len;
size_t len;
/* Check if we have something (and trim leading spaces). */
@ -1632,7 +1633,7 @@ int Set_option::process_option(Instance *instance, Named_value *option)
bool Unset_option::parse_args(const char **text)
{
uint len;
size_t len;
/* Check if we have something (and trim leading spaces). */