diff options
author | monty@mysql.com/narttu.mysql.fi <> | 2007-05-10 12:59:39 +0300 |
---|---|---|
committer | monty@mysql.com/narttu.mysql.fi <> | 2007-05-10 12:59:39 +0300 |
commit | 088e2395f1833f16c2ea3f7405f604165b4aa2cc (patch) | |
tree | 6480cbef09e9dec2fa347b1899963ab3658d692f /sql/item_func.cc | |
parent | 9078e630c64a313301cd13ce71d0854fbcf2fd0b (diff) | |
download | mariadb-git-088e2395f1833f16c2ea3f7405f604165b4aa2cc.tar.gz |
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
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r-- | sql/item_func.cc | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc index ab57b047201..64c181fde71 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -143,7 +143,7 @@ Item_func::fix_fields(THD *thd, Item **ref) DBUG_ASSERT(fixed == 0); Item **arg,**arg_end; #ifndef EMBEDDED_LIBRARY // Avoid compiler warning - char buff[STACK_BUFF_ALLOC]; // Max argument in function + uchar buff[STACK_BUFF_ALLOC]; // Max argument in function #endif used_tables_cache= not_null_tables_cache= 0; @@ -196,7 +196,7 @@ Item_func::fix_fields(THD *thd, Item **ref) bool Item_func::walk(Item_processor processor, bool walk_subquery, - byte *argument) + uchar *argument) { if (arg_count) { @@ -259,7 +259,7 @@ void Item_func::traverse_cond(Cond_traverser traverser, Item returned as the result of transformation of the root node */ -Item *Item_func::transform(Item_transformer transformer, byte *argument) +Item *Item_func::transform(Item_transformer transformer, uchar *argument) { DBUG_ASSERT(!current_thd->is_stmt_prepare()); @@ -312,8 +312,8 @@ Item *Item_func::transform(Item_transformer transformer, byte *argument) Item returned as the result of transformation of the root node */ -Item *Item_func::compile(Item_analyzer analyzer, byte **arg_p, - Item_transformer transformer, byte *arg_t) +Item *Item_func::compile(Item_analyzer analyzer, uchar **arg_p, + Item_transformer transformer, uchar *arg_t) { if (!(this->*analyzer)(arg_p)) return 0; @@ -326,7 +326,7 @@ Item *Item_func::compile(Item_analyzer analyzer, byte **arg_p, The same parameter value of arg_p must be passed to analyze any argument of the condition formula. */ - byte *arg_v= *arg_p; + uchar *arg_v= *arg_p; Item *new_item= (*arg)->compile(analyzer, &arg_v, transformer, arg_t); if (new_item && *arg != new_item) current_thd->change_item_tree(arg, new_item); @@ -466,7 +466,7 @@ Field *Item_func::tmp_table_field(TABLE *table) } -bool Item_func::is_expensive_processor(byte *arg) +bool Item_func::is_expensive_processor(uchar *arg) { return is_expensive(); } @@ -2690,7 +2690,7 @@ udf_handler::fix_fields(THD *thd, Item_result_field *func, uint arg_count, Item **arguments) { #ifndef EMBEDDED_LIBRARY // Avoid compiler warning - char buff[STACK_BUFF_ALLOC]; // Max argument in function + uchar buff[STACK_BUFF_ALLOC]; // Max argument in function #endif DBUG_ENTER("Item_udf_func::fix_fields"); @@ -3128,8 +3128,8 @@ static HASH hash_user_locks; class User_level_lock { - char *key; - uint key_length; + uchar *key; + size_t key_length; public: int count; @@ -3138,16 +3138,16 @@ public: my_thread_id thread_id; void set_thread(THD *thd) { thread_id= thd->thread_id; } - User_level_lock(const char *key_arg,uint length, ulong id) + User_level_lock(const uchar *key_arg,uint length, ulong id) :key_length(length),count(1),locked(1), thread_id(id) { - key=(char*) my_memdup((byte*) key_arg,length,MYF(0)); + key= (uchar*) my_memdup(key_arg,length,MYF(0)); pthread_cond_init(&cond,NULL); if (key) { - if (my_hash_insert(&hash_user_locks,(byte*) this)) + if (my_hash_insert(&hash_user_locks,(uchar*) this)) { - my_free((gptr) key,MYF(0)); + my_free(key,MYF(0)); key=0; } } @@ -3156,22 +3156,22 @@ public: { if (key) { - hash_delete(&hash_user_locks,(byte*) this); - my_free((gptr) key,MYF(0)); + hash_delete(&hash_user_locks,(uchar*) this); + my_free(key, MYF(0)); } pthread_cond_destroy(&cond); } inline bool initialized() { return key != 0; } friend void item_user_lock_release(User_level_lock *ull); - friend char *ull_get_key(const User_level_lock *ull, uint *length, - my_bool not_used); + friend uchar *ull_get_key(const User_level_lock *ull, size_t *length, + my_bool not_used); }; -char *ull_get_key(const User_level_lock *ull, uint *length, - my_bool not_used __attribute__((unused))) +uchar *ull_get_key(const User_level_lock *ull, size_t *length, + my_bool not_used __attribute__((unused))) { - *length=(uint) ull->key_length; - return (char*) ull->key; + *length= ull->key_length; + return ull->key; } @@ -3241,8 +3241,8 @@ void debug_sync_point(const char* lock_name, uint lock_timeout) THD* thd=current_thd; User_level_lock* ull; struct timespec abstime; - int lock_name_len; - lock_name_len=strlen(lock_name); + size_t lock_name_len; + lock_name_len= strlen(lock_name); pthread_mutex_lock(&LOCK_user_locks); if (thd->ull) @@ -3257,8 +3257,9 @@ void debug_sync_point(const char* lock_name, uint lock_timeout) this case, we will not be waiting, but rather, just waste CPU and memory on the whole deal */ - if (!(ull= ((User_level_lock*) hash_search(&hash_user_locks, lock_name, - lock_name_len)))) + if (!(ull= ((User_level_lock*) hash_search(&hash_user_locks, + (uchar*) lock_name, + lock_name_len)))) { pthread_mutex_unlock(&LOCK_user_locks); return; @@ -3353,10 +3354,11 @@ longlong Item_func_get_lock::val_int() } if (!(ull= ((User_level_lock *) hash_search(&hash_user_locks, - (byte*) res->ptr(), - res->length())))) + (uchar*) res->ptr(), + (size_t) res->length())))) { - ull=new User_level_lock(res->ptr(),res->length(), thd->thread_id); + ull= new User_level_lock((uchar*) res->ptr(), (size_t) res->length(), + thd->thread_id); if (!ull || !ull->initialized()) { delete ull; @@ -3446,8 +3448,8 @@ longlong Item_func_release_lock::val_int() result=0; pthread_mutex_lock(&LOCK_user_locks); if (!(ull= ((User_level_lock*) hash_search(&hash_user_locks, - (const byte*) res->ptr(), - res->length())))) + (const uchar*) res->ptr(), + (size_t) res->length())))) { null_value=1; } @@ -3592,7 +3594,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name, { user_var_entry *entry; - if (!(entry = (user_var_entry*) hash_search(hash, (byte*) name.str, + if (!(entry = (user_var_entry*) hash_search(hash, (uchar*) name.str, name.length)) && create_if_not_exists) { @@ -3622,7 +3624,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name, entry->used_query_id=current_thd->query_id; entry->type=STRING_RESULT; memcpy(entry->name.str, name.str, name.length+1); - if (my_hash_insert(hash,(byte*) entry)) + if (my_hash_insert(hash,(uchar*) entry)) { my_free((char*) entry,MYF(0)); return 0; @@ -4369,7 +4371,7 @@ int get_var_with_binlog(THD *thd, enum_sql_command sql_command, } /* Mark that this variable has been used by this query */ var_entry->used_query_id= thd->query_id; - if (insert_dynamic(&thd->user_var_events, (gptr) &user_var_event)) + if (insert_dynamic(&thd->user_var_events, (uchar*) &user_var_event)) goto err; *out_entry= var_entry; @@ -4438,7 +4440,7 @@ enum Item_result Item_func_get_user_var::result_type() const { user_var_entry *entry; if (!(entry = (user_var_entry*) hash_search(¤t_thd->user_vars, - (byte*) name.str, + (uchar*) name.str, name.length))) return STRING_RESULT; return entry->type; @@ -4876,7 +4878,7 @@ double Item_func_match::val_real() if ((null_value= (a == 0)) || !a->length()) DBUG_RETURN(0); DBUG_RETURN(ft_handler->please->find_relevance(ft_handler, - (byte *)a->ptr(), a->length())); + (uchar *)a->ptr(), a->length())); } DBUG_RETURN(ft_handler->please->find_relevance(ft_handler, table->record[0], 0)); @@ -4991,8 +4993,8 @@ longlong Item_func_is_free_lock::val_int() } pthread_mutex_lock(&LOCK_user_locks); - ull= (User_level_lock *) hash_search(&hash_user_locks, (byte*) res->ptr(), - res->length()); + ull= (User_level_lock *) hash_search(&hash_user_locks, (uchar*) res->ptr(), + (size_t) res->length()); pthread_mutex_unlock(&LOCK_user_locks); if (!ull || !ull->locked) return 1; @@ -5010,8 +5012,8 @@ longlong Item_func_is_used_lock::val_int() return 0; pthread_mutex_lock(&LOCK_user_locks); - ull= (User_level_lock *) hash_search(&hash_user_locks, (byte*) res->ptr(), - res->length()); + ull= (User_level_lock *) hash_search(&hash_user_locks, (uchar*) res->ptr(), + (size_t) res->length()); pthread_mutex_unlock(&LOCK_user_locks); if (!ull || !ull->locked) return 0; @@ -5109,14 +5111,13 @@ Item_func_sp::func_name() const @retval TRUE is returned on an error @retval FALSE is returned on success. */ + bool Item_func_sp::init_result_field(THD *thd) { - DBUG_ENTER("Item_func_sp::init_result_field"); - LEX_STRING empty_name= { C_STRING_WITH_LEN("") }; - TABLE_SHARE *share; + DBUG_ENTER("Item_func_sp::init_result_field"); DBUG_ASSERT(m_sp == NULL); DBUG_ASSERT(sp_result_field == NULL); @@ -5143,30 +5144,34 @@ Item_func_sp::init_result_field(THD *thd) share->table_cache_key = empty_name; share->table_name = empty_name; - if (!(sp_result_field= m_sp->create_result_field(max_length, name, dummy_table))) + if (!(sp_result_field= m_sp->create_result_field(max_length, name, + dummy_table))) { DBUG_RETURN(TRUE); } if (sp_result_field->pack_length() > sizeof(result_buf)) { - sp_result_field->move_field(sql_alloc(sp_result_field->pack_length())); - } else { - sp_result_field->move_field(result_buf); + void *tmp; + if (!(tmp= sql_alloc(sp_result_field->pack_length()))) + DBUG_RETURN(TRUE); + sp_result_field->move_field((uchar*) tmp); } + else + sp_result_field->move_field(result_buf); sp_result_field->null_ptr= (uchar *) &null_value; sp_result_field->null_bit= 1; - - DBUG_RETURN(FALSE); } + /** @brief Initialize local members with values from the Field interface. @note called from Item::fix_fields. */ + void Item_func_sp::fix_length_and_dec() { DBUG_ENTER("Item_func_sp::fix_length_and_dec"); @@ -5181,6 +5186,7 @@ void Item_func_sp::fix_length_and_dec() DBUG_VOID_RETURN; } + /** @brief Execute function & store value in field. @@ -5194,12 +5200,6 @@ Item_func_sp::execute() { THD *thd= current_thd; - /* - Get field in virtual tmp table to store result. Create the field if - invoked first time. - */ - - /* Execute function and store the return value in the field. */ if (execute_impl(thd)) @@ -5423,8 +5423,8 @@ ulonglong uuid_value; void uuid_short_init() { - uuid_value= (((ulonglong) server_id << 56) + - (ulonglong) server_start_time << 24); + uuid_value= ((((ulonglong) server_id) << 56) + + (((ulonglong) server_start_time) << 24)); } |