1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +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

@ -59,11 +59,11 @@ typedef struct my_dblock_st
lock_db key.
*/
static byte* lock_db_get_key(my_dblock_t *ptr, uint *length,
my_bool not_used __attribute__((unused)))
static uchar* lock_db_get_key(my_dblock_t *ptr, size_t *length,
my_bool not_used __attribute__((unused)))
{
*length= ptr->name_length;
return (byte*) ptr->name;
return (uchar*) ptr->name;
}
@ -73,7 +73,7 @@ static byte* lock_db_get_key(my_dblock_t *ptr, uint *length,
static void lock_db_free_element(void *ptr)
{
my_free((gptr) ptr, MYF(0));
my_free(ptr, MYF(0));
}
@ -98,12 +98,12 @@ static my_bool lock_db_insert(const char *dbname, uint length)
safe_mutex_assert_owner(&LOCK_lock_db);
if (!(opt= (my_dblock_t*) hash_search(&lock_db_cache,
(byte*) dbname, length)))
(uchar*) dbname, length)))
{
/* Db is not in the hash, insert it */
char *tmp_name;
if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
&opt, (uint) sizeof(*opt), &tmp_name, length+1,
&opt, (uint) sizeof(*opt), &tmp_name, (uint) length+1,
NullS))
{
error= 1;
@ -114,11 +114,8 @@ static my_bool lock_db_insert(const char *dbname, uint length)
strmov(opt->name, dbname);
opt->name_length= length;
if ((error= my_hash_insert(&lock_db_cache, (byte*) opt)))
{
my_free((gptr) opt, MYF(0));
goto end;
}
if ((error= my_hash_insert(&lock_db_cache, (uchar*) opt)))
my_free(opt, MYF(0));
}
end:
@ -135,8 +132,8 @@ void lock_db_delete(const char *name, uint length)
my_dblock_t *opt;
safe_mutex_assert_owner(&LOCK_lock_db);
if ((opt= (my_dblock_t *)hash_search(&lock_db_cache,
(const byte*) name, length)))
hash_delete(&lock_db_cache, (byte*) opt);
(const uchar*) name, length)))
hash_delete(&lock_db_cache, (uchar*) opt);
}
@ -158,11 +155,11 @@ typedef struct my_dbopt_st
Function we use in the creation of our hash to get key.
*/
static byte* dboptions_get_key(my_dbopt_t *opt, uint *length,
my_bool not_used __attribute__((unused)))
static uchar* dboptions_get_key(my_dbopt_t *opt, size_t *length,
my_bool not_used __attribute__((unused)))
{
*length= opt->name_length;
return (byte*) opt->name;
return (uchar*) opt->name;
}
@ -187,7 +184,7 @@ static inline void write_to_binlog(THD *thd, char *query, uint q_len,
static void free_dbopt(void *dbopt)
{
my_free((gptr) dbopt, MYF(0));
my_free((uchar*) dbopt, MYF(0));
}
@ -280,7 +277,7 @@ static my_bool get_dbopt(const char *dbname, HA_CREATE_INFO *create)
length= (uint) strlen(dbname);
rw_rdlock(&LOCK_dboptions);
if ((opt= (my_dbopt_t*) hash_search(&dboptions, (byte*) dbname, length)))
if ((opt= (my_dbopt_t*) hash_search(&dboptions, (uchar*) dbname, length)))
{
create->default_table_charset= opt->charset;
error= 0;
@ -312,12 +309,12 @@ static my_bool put_dbopt(const char *dbname, HA_CREATE_INFO *create)
length= (uint) strlen(dbname);
rw_wrlock(&LOCK_dboptions);
if (!(opt= (my_dbopt_t*) hash_search(&dboptions, (byte*) dbname, length)))
if (!(opt= (my_dbopt_t*) hash_search(&dboptions, (uchar*) dbname, length)))
{
/* Options are not in the hash, insert them */
char *tmp_name;
if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
&opt, (uint) sizeof(*opt), &tmp_name, length+1,
&opt, (uint) sizeof(*opt), &tmp_name, (uint) length+1,
NullS))
{
error= 1;
@ -328,9 +325,9 @@ static my_bool put_dbopt(const char *dbname, HA_CREATE_INFO *create)
strmov(opt->name, dbname);
opt->name_length= length;
if ((error= my_hash_insert(&dboptions, (byte*) opt)))
if ((error= my_hash_insert(&dboptions, (uchar*) opt)))
{
my_free((gptr) opt, MYF(0));
my_free(opt, MYF(0));
goto end;
}
}
@ -352,9 +349,9 @@ void del_dbopt(const char *path)
{
my_dbopt_t *opt;
rw_wrlock(&LOCK_dboptions);
if ((opt= (my_dbopt_t *)hash_search(&dboptions, (const byte*) path,
if ((opt= (my_dbopt_t *)hash_search(&dboptions, (const uchar*) path,
strlen(path))))
hash_delete(&dboptions, (byte*) opt);
hash_delete(&dboptions, (uchar*) opt);
rw_unlock(&LOCK_dboptions);
}
@ -392,7 +389,7 @@ static bool write_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
"\n", NullS) - buf);
/* Error is written by my_write */
if (!my_write(file,(byte*) buf, length, MYF(MY_NABP+MY_WME)))
if (!my_write(file,(uchar*) buf, length, MYF(MY_NABP+MY_WME)))
error=0;
my_close(file,MYF(0));
}
@ -920,7 +917,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
TABLE_LIST *tbl;
uint db_len;
if (!(query= thd->alloc(MAX_DROP_TABLE_Q_LEN)))
if (!(query= (char*) thd->alloc(MAX_DROP_TABLE_Q_LEN)))
goto exit; /* not much else we can do */
query_pos= query_data_start= strmov(query,"drop table ");
query_end= query + MAX_DROP_TABLE_Q_LEN;
@ -1021,7 +1018,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
DBUG_PRINT("my",("New subdir found: %s", newpath));
if ((mysql_rm_known_files(thd, new_dirp, NullS, newpath,1,0)) < 0)
goto err;
if (!(copy_of_path= thd->memdup(newpath, length+1)) ||
if (!(copy_of_path= (char*) thd->memdup(newpath, length+1)) ||
!(dir= new (thd->mem_root) String(copy_of_path, length,
&my_charset_bin)) ||
raid_dirs.push_back(dir))
@ -1511,8 +1508,8 @@ lock_databases(THD *thd, const char *db1, uint length1,
{
pthread_mutex_lock(&LOCK_lock_db);
while (!thd->killed &&
(hash_search(&lock_db_cache,(byte*) db1, length1) ||
hash_search(&lock_db_cache,(byte*) db2, length2)))
(hash_search(&lock_db_cache,(uchar*) db1, length1) ||
hash_search(&lock_db_cache,(uchar*) db2, length2)))
{
wait_for_condition(thd, &LOCK_lock_db, &COND_refresh);
pthread_mutex_lock(&LOCK_lock_db);
@ -1654,7 +1651,7 @@ bool mysql_rename_db(THD *thd, LEX_STRING *old_db, LEX_STRING *new_db)
table_str.length= filename_to_tablename(file->name,
tname, sizeof(tname)-1);
table_str.str= sql_memdup(tname, table_str.length + 1);
table_str.str= (char*) sql_memdup(tname, table_str.length + 1);
Table_ident *old_ident= new Table_ident(thd, *old_db, table_str, 0);
Table_ident *new_ident= new Table_ident(thd, *new_db, table_str, 0);
if (!old_ident || !new_ident ||