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:
@ -123,23 +123,23 @@ uint32 get_partition_id_hash_sub(partition_info *part_info);
|
||||
uint32 get_partition_id_key_sub(partition_info *part_info);
|
||||
uint32 get_partition_id_linear_hash_sub(partition_info *part_info);
|
||||
uint32 get_partition_id_linear_key_sub(partition_info *part_info);
|
||||
static uint32 get_next_partition_via_walking(PARTITION_ITERATOR*);
|
||||
static void set_up_range_analysis_info(partition_info *part_info);
|
||||
static uint32 get_next_subpartition_via_walking(PARTITION_ITERATOR*);
|
||||
#endif
|
||||
|
||||
static uint32 get_next_partition_via_walking(PARTITION_ITERATOR*);
|
||||
static uint32 get_next_subpartition_via_walking(PARTITION_ITERATOR*);
|
||||
uint32 get_next_partition_id_range(PARTITION_ITERATOR* part_iter);
|
||||
uint32 get_next_partition_id_list(PARTITION_ITERATOR* part_iter);
|
||||
int get_part_iter_for_interval_via_mapping(partition_info *part_info,
|
||||
bool is_subpart,
|
||||
char *min_value, char *max_value,
|
||||
uchar *min_value, uchar *max_value,
|
||||
uint flags,
|
||||
PARTITION_ITERATOR *part_iter);
|
||||
int get_part_iter_for_interval_via_walking(partition_info *part_info,
|
||||
bool is_subpart,
|
||||
char *min_value, char *max_value,
|
||||
uchar *min_value, uchar *max_value,
|
||||
uint flags,
|
||||
PARTITION_ITERATOR *part_iter);
|
||||
static void set_up_range_analysis_info(partition_info *part_info);
|
||||
|
||||
/*
|
||||
A routine used by the parser to decide whether we are specifying a full
|
||||
@ -318,8 +318,8 @@ bool check_reorganise_list(partition_info *new_part_info,
|
||||
> 0 Error code
|
||||
*/
|
||||
|
||||
int get_parts_for_update(const byte *old_data, byte *new_data,
|
||||
const byte *rec0, partition_info *part_info,
|
||||
int get_parts_for_update(const uchar *old_data, uchar *new_data,
|
||||
const uchar *rec0, partition_info *part_info,
|
||||
uint32 *old_part_id, uint32 *new_part_id,
|
||||
longlong *new_func_value)
|
||||
{
|
||||
@ -392,7 +392,7 @@ int get_parts_for_update(const byte *old_data, byte *new_data,
|
||||
calculate the partition id.
|
||||
*/
|
||||
|
||||
int get_part_for_delete(const byte *buf, const byte *rec0,
|
||||
int get_part_for_delete(const uchar *buf, const uchar *rec0,
|
||||
partition_info *part_info, uint32 *part_id)
|
||||
{
|
||||
int error;
|
||||
@ -931,7 +931,7 @@ bool fix_fields_part_func(THD *thd, Item* func_expr, TABLE *table,
|
||||
context->table_list= &tables;
|
||||
context->first_name_resolution_table= &tables;
|
||||
context->last_name_resolution_table= NULL;
|
||||
func_expr->walk(&Item::change_context_processor, 0, (byte*) context);
|
||||
func_expr->walk(&Item::change_context_processor, 0, (uchar*) context);
|
||||
save_where= thd->where;
|
||||
thd->where= "partition function";
|
||||
/*
|
||||
@ -1697,7 +1697,7 @@ end:
|
||||
|
||||
static int add_write(File fptr, const char *buf, uint len)
|
||||
{
|
||||
uint len_written= my_write(fptr, (const byte*)buf, len, MYF(0));
|
||||
uint len_written= my_write(fptr, (const uchar*)buf, len, MYF(0));
|
||||
|
||||
if (likely(len == len_written))
|
||||
return 0;
|
||||
@ -2144,13 +2144,13 @@ char *generate_partition_syntax(partition_info *part_info,
|
||||
goto close_file;
|
||||
*buf_length= (uint)buffer_length;
|
||||
if (use_sql_alloc)
|
||||
buf= sql_alloc(*buf_length+1);
|
||||
buf= (char*) sql_alloc(*buf_length+1);
|
||||
else
|
||||
buf= my_malloc(*buf_length+1, MYF(MY_WME));
|
||||
buf= (char*) my_malloc(*buf_length+1, MYF(MY_WME));
|
||||
if (!buf)
|
||||
goto close_file;
|
||||
|
||||
if (unlikely(my_read(fptr, (byte*)buf, *buf_length, MYF(MY_FNABP))))
|
||||
if (unlikely(my_read(fptr, (uchar*)buf, *buf_length, MYF(MY_FNABP))))
|
||||
{
|
||||
if (!use_sql_alloc)
|
||||
my_free(buf, MYF(0));
|
||||
@ -2413,8 +2413,8 @@ static uint32 get_part_id_linear_key(partition_info *part_info,
|
||||
*/
|
||||
|
||||
static void copy_to_part_field_buffers(Field **ptr,
|
||||
char **field_bufs,
|
||||
char **restore_ptr)
|
||||
uchar **field_bufs,
|
||||
uchar **restore_ptr)
|
||||
{
|
||||
Field *field;
|
||||
while ((field= *(ptr++)))
|
||||
@ -2425,7 +2425,7 @@ static void copy_to_part_field_buffers(Field **ptr,
|
||||
{
|
||||
CHARSET_INFO *cs= ((Field_str*)field)->charset();
|
||||
uint len= field->pack_length();
|
||||
char *field_buf= *field_bufs;
|
||||
uchar *field_buf= *field_bufs;
|
||||
/*
|
||||
We only use the field buffer for VARCHAR and CHAR strings
|
||||
which isn't of a binary collation. We also only use the
|
||||
@ -2436,17 +2436,17 @@ static void copy_to_part_field_buffers(Field **ptr,
|
||||
if (field->type() == MYSQL_TYPE_VARCHAR)
|
||||
{
|
||||
uint len_bytes= ((Field_varstring*)field)->length_bytes;
|
||||
my_strnxfrm(cs, (uchar*)(field_buf + len_bytes), (len - len_bytes),
|
||||
(uchar*)(field->ptr + len_bytes), field->field_length);
|
||||
my_strnxfrm(cs, field_buf + len_bytes, (len - len_bytes),
|
||||
field->ptr + len_bytes, field->field_length);
|
||||
if (len_bytes == 1)
|
||||
*field_buf= (uchar)field->field_length;
|
||||
*field_buf= (uchar) field->field_length;
|
||||
else
|
||||
int2store(field_buf, field->field_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
my_strnxfrm(cs, (uchar*)field_buf, len,
|
||||
(uchar*)field->ptr, field->field_length);
|
||||
my_strnxfrm(cs, field_buf, len,
|
||||
field->ptr, field->field_length);
|
||||
}
|
||||
field->ptr= field_buf;
|
||||
}
|
||||
@ -2465,7 +2465,7 @@ static void copy_to_part_field_buffers(Field **ptr,
|
||||
RETURN VALUES
|
||||
*/
|
||||
|
||||
static void restore_part_field_pointers(Field **ptr, char **restore_ptr)
|
||||
static void restore_part_field_pointers(Field **ptr, uchar **restore_ptr)
|
||||
{
|
||||
Field *field;
|
||||
while ((field= *(ptr++)))
|
||||
@ -3307,16 +3307,16 @@ static bool check_part_func_bound(Field **ptr)
|
||||
get the partition identity and restore field pointers afterwards.
|
||||
*/
|
||||
|
||||
static uint32 get_sub_part_id_from_key(const TABLE *table,byte *buf,
|
||||
static uint32 get_sub_part_id_from_key(const TABLE *table,uchar *buf,
|
||||
KEY *key_info,
|
||||
const key_range *key_spec)
|
||||
{
|
||||
byte *rec0= table->record[0];
|
||||
uchar *rec0= table->record[0];
|
||||
partition_info *part_info= table->part_info;
|
||||
uint32 part_id;
|
||||
DBUG_ENTER("get_sub_part_id_from_key");
|
||||
|
||||
key_restore(buf, (byte*)key_spec->key, key_info, key_spec->length);
|
||||
key_restore(buf, (uchar*)key_spec->key, key_info, key_spec->length);
|
||||
if (likely(rec0 == buf))
|
||||
part_id= part_info->get_subpartition_id(part_info);
|
||||
else
|
||||
@ -3350,16 +3350,16 @@ static uint32 get_sub_part_id_from_key(const TABLE *table,byte *buf,
|
||||
get the partition identity and restore field pointers afterwards.
|
||||
*/
|
||||
|
||||
bool get_part_id_from_key(const TABLE *table, byte *buf, KEY *key_info,
|
||||
bool get_part_id_from_key(const TABLE *table, uchar *buf, KEY *key_info,
|
||||
const key_range *key_spec, uint32 *part_id)
|
||||
{
|
||||
bool result;
|
||||
byte *rec0= table->record[0];
|
||||
uchar *rec0= table->record[0];
|
||||
partition_info *part_info= table->part_info;
|
||||
longlong func_value;
|
||||
DBUG_ENTER("get_part_id_from_key");
|
||||
|
||||
key_restore(buf, (byte*)key_spec->key, key_info, key_spec->length);
|
||||
key_restore(buf, (uchar*)key_spec->key, key_info, key_spec->length);
|
||||
if (likely(rec0 == buf))
|
||||
result= part_info->get_part_partition_id(part_info, part_id,
|
||||
&func_value);
|
||||
@ -3395,18 +3395,18 @@ bool get_part_id_from_key(const TABLE *table, byte *buf, KEY *key_info,
|
||||
get the partition identity and restore field pointers afterwards.
|
||||
*/
|
||||
|
||||
void get_full_part_id_from_key(const TABLE *table, byte *buf,
|
||||
void get_full_part_id_from_key(const TABLE *table, uchar *buf,
|
||||
KEY *key_info,
|
||||
const key_range *key_spec,
|
||||
part_id_range *part_spec)
|
||||
{
|
||||
bool result;
|
||||
partition_info *part_info= table->part_info;
|
||||
byte *rec0= table->record[0];
|
||||
uchar *rec0= table->record[0];
|
||||
longlong func_value;
|
||||
DBUG_ENTER("get_full_part_id_from_key");
|
||||
|
||||
key_restore(buf, (byte*)key_spec->key, key_info, key_spec->length);
|
||||
key_restore(buf, (uchar*)key_spec->key, key_info, key_spec->length);
|
||||
if (likely(rec0 == buf))
|
||||
result= part_info->get_partition_id(part_info, &part_spec->start_part,
|
||||
&func_value);
|
||||
@ -3494,7 +3494,7 @@ void prune_partition_set(const TABLE *table, part_id_range *part_spec)
|
||||
RETURN VALUE
|
||||
part_spec
|
||||
*/
|
||||
void get_partition_set(const TABLE *table, byte *buf, const uint index,
|
||||
void get_partition_set(const TABLE *table, uchar *buf, const uint index,
|
||||
const key_range *key_spec, part_id_range *part_spec)
|
||||
{
|
||||
partition_info *part_info= table->part_info;
|
||||
@ -3831,9 +3831,9 @@ bool mysql_unpack_partition(THD *thd,
|
||||
char *part_func_string= NULL;
|
||||
char *subpart_func_string= NULL;
|
||||
if ((part_func_len &&
|
||||
!((part_func_string= thd->alloc(part_func_len)))) ||
|
||||
!((part_func_string= (char*) thd->alloc(part_func_len)))) ||
|
||||
(subpart_func_len &&
|
||||
!((subpart_func_string= thd->alloc(subpart_func_len)))))
|
||||
!((subpart_func_string= (char*) thd->alloc(subpart_func_len)))))
|
||||
{
|
||||
mem_alloc_error(part_func_len);
|
||||
thd->free_items();
|
||||
@ -6404,8 +6404,8 @@ uint fast_alter_partition_table(THD *thd, TABLE *table,
|
||||
also for other programs.
|
||||
*/
|
||||
|
||||
void set_field_ptr(Field **ptr, const byte *new_buf,
|
||||
const byte *old_buf)
|
||||
void set_field_ptr(Field **ptr, const uchar *new_buf,
|
||||
const uchar *old_buf)
|
||||
{
|
||||
my_ptrdiff_t diff= (new_buf - old_buf);
|
||||
DBUG_ENTER("set_field_ptr");
|
||||
@ -6438,8 +6438,8 @@ void set_field_ptr(Field **ptr, const byte *new_buf,
|
||||
also for other programs.
|
||||
*/
|
||||
|
||||
void set_key_field_ptr(KEY *key_info, const byte *new_buf,
|
||||
const byte *old_buf)
|
||||
void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
|
||||
const uchar *old_buf)
|
||||
{
|
||||
KEY_PART_INFO *key_part= key_info->key_part;
|
||||
uint key_parts= key_info->key_parts;
|
||||
@ -6690,7 +6690,7 @@ typedef uint32 (*get_endpoint_func)(partition_info*, bool left_endpoint,
|
||||
|
||||
int get_part_iter_for_interval_via_mapping(partition_info *part_info,
|
||||
bool is_subpart,
|
||||
char *min_value, char *max_value,
|
||||
uchar *min_value, uchar *max_value,
|
||||
uint flags,
|
||||
PARTITION_ITERATOR *part_iter)
|
||||
{
|
||||
@ -6846,7 +6846,7 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info,
|
||||
|
||||
int get_part_iter_for_interval_via_walking(partition_info *part_info,
|
||||
bool is_subpart,
|
||||
char *min_value, char *max_value,
|
||||
uchar *min_value, uchar *max_value,
|
||||
uint flags,
|
||||
PARTITION_ITERATOR *part_iter)
|
||||
{
|
||||
|
Reference in New Issue
Block a user