List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:June 4 2010 2:25pm
Subject:bzr commit into mysql-5.1-bugteam branch (davi:3417) Bug#42733
View as plain text  
# At a local mysql-5.1-bugteam repository of davi

 3417 Davi Arnaut	2010-06-04
      Bug#42733: Type-punning warnings when compiling MySQL --
                 strict aliasing violations.
      
      One somewhat major source of strict-aliasing violations and
      related warnings is the SQL_LIST structure. For example,
      consider its member function `link_in_list` which takes
      a pointer to pointer of type T (any type) as a pointer to
      pointer to unsigned char. Dereferencing this pointer, which
      is done to reset the next field, violates strict-aliasing
      rules and might cause problems for surrounding code that
      uses the next field of the object being added to the list.
      
      The solution is to use templates to parametrize the SQL_LIST
      structure in order to deference the pointers with compatible
      types. As a side bonus, it becomes possible to remove quite
      a few casts related to acessing data members of SQL_LIST.
     @ sql/handler.h
        Use the appropriate template type argument.
     @ sql/item.cc
        Remove now-unnecessary cast.
     @ sql/item_subselect.cc
        Remove now-unnecessary casts.
     @ sql/item_sum.cc
        Use the appropriate template type argument.
        Remove now-unnecessary cast.
     @ sql/mysql_priv.h
        Move SQL_LIST structure to sql_list.h
        Use the appropriate template type argument.
     @ sql/sp.cc
        Remove now-unnecessary casts.
     @ sql/sql_delete.cc
        Use the appropriate template type argument.
        Remove now-unnecessary casts.
     @ sql/sql_derived.cc
        Remove now-unnecessary casts.
     @ sql/sql_lex.cc
        Remove now-unnecessary casts.
     @ sql/sql_lex.h
        SQL_LIST now takes a template type argument which must
        match the type of the elements of the list. Use forward
        declaration when the type is not available, it is used
        in pointers anyway.
     @ sql/sql_list.h
        Rename SQL_LIST to SQL_I_List. The template parameter is
        the type of object that is stored in the list.
     @ sql/sql_olap.cc
        Remove now-unnecessary casts.
     @ sql/sql_parse.cc
        Remove now-unnecessary casts.
     @ sql/sql_prepare.cc
        Remove now-unnecessary casts.
     @ sql/sql_select.cc
        Remove now-unnecessary casts.
     @ sql/sql_show.cc
        Remove now-unnecessary casts.
     @ sql/sql_table.cc
        Remove now-unnecessary casts.
     @ sql/sql_trigger.cc
        Remove now-unnecessary casts.
     @ sql/sql_union.cc
        Remove now-unnecessary casts.
     @ sql/sql_update.cc
        Remove now-unnecessary casts.
     @ sql/sql_view.cc
        Remove now-unnecessary casts.
     @ sql/sql_yacc.yy
        Remove now-unnecessary casts.
     @ storage/myisammrg/ha_myisammrg.cc
        Remove now-unnecessary casts.

    modified:
      sql/handler.h
      sql/item.cc
      sql/item_subselect.cc
      sql/item_sum.cc
      sql/item_sum.h
      sql/mysql_priv.h
      sql/sp.cc
      sql/sql_delete.cc
      sql/sql_derived.cc
      sql/sql_lex.cc
      sql/sql_lex.h
      sql/sql_list.h
      sql/sql_olap.cc
      sql/sql_parse.cc
      sql/sql_prepare.cc
      sql/sql_select.cc
      sql/sql_show.cc
      sql/sql_table.cc
      sql/sql_trigger.cc
      sql/sql_union.cc
      sql/sql_update.cc
      sql/sql_view.cc
      sql/sql_yacc.yy
      storage/myisammrg/ha_myisammrg.cc
=== modified file 'sql/handler.h'
--- a/sql/handler.h	2010-04-14 09:53:59 +0000
+++ b/sql/handler.h	2010-06-04 14:25:18 +0000
@@ -910,7 +910,7 @@ typedef struct st_ha_create_information
   ulong avg_row_length;
   ulong used_fields;
   ulong key_block_size;
-  SQL_LIST merge_list;
+  SQL_I_List<TABLE_LIST> merge_list;
   handlerton *db_type;
   /**
     Row type of the table definition.

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2010-05-05 08:54:52 +0000
+++ b/sql/item.cc	2010-06-04 14:25:18 +0000
@@ -3841,7 +3841,7 @@ resolve_ref_in_select_and_group(THD *thd
 {
   Item **group_by_ref= NULL;
   Item **select_ref= NULL;
-  ORDER *group_list= (ORDER*) select->group_list.first;
+  ORDER *group_list= select->group_list.first;
   bool ambiguous_fields= FALSE;
   uint counter;
   enum_resolution_type resolution;

=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc	2010-04-06 07:26:59 +0000
+++ b/sql/item_subselect.cc	2010-06-04 14:25:18 +0000
@@ -244,12 +244,12 @@ bool Item_subselect::walk(Item_processor
         if (item->walk(processor, walk_subquery, argument))
           return 1;
       }
-      for (order= (ORDER*) lex->order_list.first ; order; order= order->next)
+      for (order= lex->order_list.first ; order; order= order->next)
       {
         if ((*order->item)->walk(processor, walk_subquery, argument))
           return 1;
       }
-      for (order= (ORDER*) lex->group_list.first ; order; order= order->next)
+      for (order= lex->group_list.first ; order; order= order->next)
       {
         if ((*order->item)->walk(processor, walk_subquery, argument))
           return 1;
@@ -1781,15 +1781,15 @@ int subselect_single_select_engine::prep
   SELECT_LEX *save_select= thd->lex->current_select;
   thd->lex->current_select= select_lex;
   if (join->prepare(&select_lex->ref_pointer_array,
-		    (TABLE_LIST*) select_lex->table_list.first,
+		    select_lex->table_list.first,
 		    select_lex->with_wild,
 		    select_lex->where,
 		    select_lex->order_list.elements +
 		    select_lex->group_list.elements,
-		    (ORDER*) select_lex->order_list.first,
-		    (ORDER*) select_lex->group_list.first,
+		    select_lex->order_list.first,
+		    select_lex->group_list.first,
 		    select_lex->having,
-		    (ORDER*) 0, select_lex,
+		    NULL, select_lex,
 		    select_lex->master_unit()))
     return 1;
   thd->lex->current_select= save_select;
@@ -2450,14 +2450,13 @@ table_map subselect_engine::calc_const_t
 
 table_map subselect_single_select_engine::upper_select_const_tables()
 {
-  return calc_const_tables((TABLE_LIST *) select_lex->outer_select()->
-			   leaf_tables);
+  return calc_const_tables(select_lex->outer_select()->leaf_tables);
 }
 
 
 table_map subselect_union_engine::upper_select_const_tables()
 {
-  return calc_const_tables((TABLE_LIST *) unit->outer_select()->leaf_tables);
+  return calc_const_tables(unit->outer_select()->leaf_tables);
 }
 
 

=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc	2010-03-31 13:00:56 +0000
+++ b/sql/item_sum.cc	2010-06-04 14:25:18 +0000
@@ -2969,7 +2969,7 @@ int dump_leaf_key(uchar* key, element_co
 Item_func_group_concat::
 Item_func_group_concat(Name_resolution_context *context_arg,
                        bool distinct_arg, List<Item> *select_list,
-                       SQL_LIST *order_list, String *separator_arg)
+                       SQL_I_List<ORDER> *order_list, String *separator_arg)
   :tmp_table_param(0), warning(0),
    separator(separator_arg), tree(0), unique_filter(NULL), table(0),
    order(0), context(context_arg),
@@ -3013,7 +3013,7 @@ Item_func_group_concat(Name_resolution_c
   if (arg_count_order)
   {
     ORDER **order_ptr= order;
-    for (ORDER *order_item= (ORDER*) order_list->first;
+    for (ORDER *order_item= order_list->first;
          order_item != NULL;
          order_item= order_item->next)
     {

=== modified file 'sql/item_sum.h'
--- a/sql/item_sum.h	2010-03-14 16:01:45 +0000
+++ b/sql/item_sum.h	2010-06-04 14:25:18 +0000
@@ -1221,7 +1221,7 @@ class Item_func_group_concat : public It
 public:
   Item_func_group_concat(Name_resolution_context *context_arg,
                          bool is_distinct, List<Item> *is_select,
-                         SQL_LIST *is_order, String *is_separator);
+                         SQL_I_List<ORDER> *is_order, String *is_separator);
 
   Item_func_group_concat(THD *thd, Item_func_group_concat *item);
   ~Item_func_group_concat();

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2010-05-27 20:07:40 +0000
+++ b/sql/mysql_priv.h	2010-06-04 14:25:18 +0000
@@ -641,49 +641,6 @@ enum enum_check_fields
   CHECK_FIELD_ERROR_FOR_NULL
 };
 
-                                  
-/** Struct to handle simple linked lists. */
-typedef struct st_sql_list {
-  uint elements;
-  uchar *first;
-  uchar **next;
-
-  st_sql_list() {}                              /* Remove gcc warning */
-  inline void empty()
-  {
-    elements=0;
-    first=0;
-    next= &first;
-  }
-  inline void link_in_list(uchar *element,uchar **next_ptr)
-  {
-    elements++;
-    (*next)=element;
-    next= next_ptr;
-    *next=0;
-  }
-  inline void save_and_clear(struct st_sql_list *save)
-  {
-    *save= *this;
-    empty();
-  }
-  inline void push_front(struct st_sql_list *save)
-  {
-    *save->next= first;				/* link current list last */
-    first= save->first;
-    elements+= save->elements;
-  }
-  inline void push_back(struct st_sql_list *save)
-  {
-    if (save->first)
-    {
-      *next= save->first;
-      next= save->next;
-      elements+= save->elements;
-    }
-  }
-} SQL_LIST;
-
 #if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32)
 extern "C" THD *_current_thd_noinline();
 #define _current_thd() _current_thd_noinline()
@@ -1262,7 +1219,7 @@ int check_that_all_fields_are_given_valu
 void prepare_triggers_for_insert_stmt(TABLE *table);
 int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
 bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
-                  SQL_LIST *order, ha_rows rows, ulonglong options,
+                  SQL_I_List<ORDER> *order, ha_rows rows, ulonglong options,
                   bool reset_auto_increment);
 bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
 bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
@@ -1462,7 +1419,7 @@ Create_field * new_create_field(THD *thd
 				List<String> *interval_list, CHARSET_INFO *cs,
 				uint uint_geom_type);
 void store_position_for_column(const char *name);
-bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
+bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *group,bool asc);
 bool push_new_name_resolution_context(THD *thd,
                                       TABLE_LIST *left_op,
                                       TABLE_LIST *right_op);

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2010-02-05 09:39:46 +0000
+++ b/sql/sp.cc	2010-06-04 14:25:18 +0000
@@ -1630,8 +1630,7 @@ extern "C" uchar* sp_sroutine_key(const 
 void sp_get_prelocking_info(THD *thd, bool *need_prelocking, 
                             bool *first_no_prelocking)
 {
-  Sroutine_hash_entry *routine;
-  routine= (Sroutine_hash_entry*)thd->lex->sroutines_list.first;
+  Sroutine_hash_entry *routine= thd->lex->sroutines_list.first;
 
   DBUG_ASSERT(routine);
   bool first_is_procedure= (routine->key.str[0] == TYPE_ENUM_PROCEDURE);
@@ -1694,7 +1693,7 @@ static bool add_used_routine(LEX *lex, Q
     memcpy(rn->key.str, key->str, key->length + 1);
     if (my_hash_insert(&lex->sroutines, (uchar *)rn))
       return FALSE;
-    lex->sroutines_list.link_in_list((uchar *)rn, (uchar **)&rn->next);
+    lex->sroutines_list.link_in_list(rn, &rn->next);
     rn->belong_to_view= belong_to_view;
     return TRUE;
   }
@@ -1740,7 +1739,7 @@ void sp_add_used_routine(LEX *lex, Query
 void sp_remove_not_own_routines(LEX *lex)
 {
   Sroutine_hash_entry *not_own_rt, *next_rt;
-  for (not_own_rt= *(Sroutine_hash_entry **)lex->sroutines_list_own_last;
+  for (not_own_rt= *lex->sroutines_list_own_last;
        not_own_rt; not_own_rt= next_rt)
   {
     /*
@@ -1751,7 +1750,7 @@ void sp_remove_not_own_routines(LEX *lex
     hash_delete(&lex->sroutines, (uchar *)not_own_rt);
   }
 
-  *(Sroutine_hash_entry **)lex->sroutines_list_own_last= NULL;
+  *lex->sroutines_list_own_last= NULL;
   lex->sroutines_list.next= lex->sroutines_list_own_last;
   lex->sroutines_list.elements= lex->sroutines_list_own_elements;
 }
@@ -1832,11 +1831,11 @@ sp_update_stmt_used_routines(THD *thd, L
     It will also add elements to end of 'LEX::sroutines_list' list.
 */
 
-static void sp_update_stmt_used_routines(THD *thd, LEX *lex, SQL_LIST *src,
+static void sp_update_stmt_used_routines(THD *thd, LEX *lex,
+                                         SQL_I_List<Sroutine_hash_entry> *src,
                                          TABLE_LIST *belong_to_view)
 {
-  for (Sroutine_hash_entry *rt= (Sroutine_hash_entry *)src->first;
-       rt; rt= rt->next)
+  for (Sroutine_hash_entry *rt= src->first; rt; rt= rt->next)
     (void)add_used_routine(lex, thd->stmt_arena, &rt->key, belong_to_view);
 }
 
@@ -1971,8 +1970,7 @@ int
 sp_cache_routines_and_add_tables(THD *thd, LEX *lex, bool first_no_prelock)
 {
   return sp_cache_routines_and_add_tables_aux(thd, lex,
-           (Sroutine_hash_entry *)lex->sroutines_list.first,
-           first_no_prelock);
+           lex->sroutines_list.first, first_no_prelock);
 }
 
 
@@ -1996,8 +1994,7 @@ sp_cache_routines_and_add_tables(THD *th
 int
 sp_cache_routines_and_add_tables_for_view(THD *thd, LEX *lex, TABLE_LIST *view)
 {
-  Sroutine_hash_entry **last_cached_routine_ptr=
-                          (Sroutine_hash_entry **)lex->sroutines_list.next;
+  Sroutine_hash_entry **last_cached_routine_ptr= lex->sroutines_list.next;
   sp_update_stmt_used_routines(thd, lex, &view->view->sroutines_list,
                                view->top_table());
   return sp_cache_routines_and_add_tables_aux(thd, lex,
@@ -2026,8 +2023,7 @@ sp_cache_routines_and_add_tables_for_tri
 {
   int ret= 0;
 
-  Sroutine_hash_entry **last_cached_routine_ptr=
-    (Sroutine_hash_entry **)lex->sroutines_list.next;
+  Sroutine_hash_entry **last_cached_routine_ptr= lex->sroutines_list.next;
 
   if (static_cast<int>(table->lock_type) >=
       static_cast<int>(TL_WRITE_ALLOW_WRITE))

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2010-05-14 11:36:27 +0000
+++ b/sql/sql_delete.cc	2010-06-04 14:25:18 +0000
@@ -33,7 +33,7 @@
 */
 
 bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
-                  SQL_LIST *order, ha_rows limit, ulonglong options,
+                  SQL_I_List<ORDER> *order, ha_rows limit, ulonglong options,
                   bool reset_auto_increment)
 {
   bool          will_batch;
@@ -84,7 +84,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
 
       if (select_lex->setup_ref_array(thd, order->elements) ||
 	  setup_order(thd, select_lex->ref_pointer_array, &tables,
-                    fields, all_fields, (ORDER*) order->first))
+                    fields, all_fields, order->first))
     {
       delete select;
       free_underlaid_joins(thd, &thd->lex->select_lex);
@@ -230,14 +230,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *
     ha_rows examined_rows;
     
     if ((!select || table->quick_keys.is_clear_all()) && limit != HA_POS_ERROR)
-      usable_index= get_index_for_order(table, (ORDER*)(order->first), limit);
+      usable_index= get_index_for_order(table, order->first, limit);
 
     if (usable_index == MAX_KEY)
     {
       table->sort.io_cache= (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
                                                    MYF(MY_FAE | MY_ZEROFILL));
     
-      if (!(sortorder= make_unireg_sortorder((ORDER*) order->first,
+      if (!(sortorder= make_unireg_sortorder(order->first,
                                              &length, NULL)) ||
 	  (table->sort.found_records = filesort(thd, table, sortorder, length,
                                                 select, HA_POS_ERROR, 1,
@@ -547,7 +547,7 @@ extern "C" int refpos_order_cmp(void* ar
 int mysql_multi_delete_prepare(THD *thd)
 {
   LEX *lex= thd->lex;
-  TABLE_LIST *aux_tables= (TABLE_LIST *)lex->auxiliary_table_list.first;
+  TABLE_LIST *aux_tables= lex->auxiliary_table_list.first;
   TABLE_LIST *target_tbl;
   DBUG_ENTER("mysql_multi_delete_prepare");
 

=== modified file 'sql/sql_derived.cc'
--- a/sql/sql_derived.cc	2009-05-27 15:19:44 +0000
+++ b/sql/sql_derived.cc	2010-06-04 14:25:18 +0000
@@ -281,13 +281,13 @@ bool mysql_derived_filling(THD *thd, LEX
 
       lex->current_select= first_select;
       res= mysql_select(thd, &first_select->ref_pointer_array,
-			(TABLE_LIST*) first_select->table_list.first,
+			first_select->table_list.first,
 			first_select->with_wild,
 			first_select->item_list, first_select->where,
 			(first_select->order_list.elements+
 			 first_select->group_list.elements),
-			(ORDER *) first_select->order_list.first,
-			(ORDER *) first_select->group_list.first,
+			first_select->order_list.first,
+			first_select->group_list.first,
 			first_select->having, (ORDER*) NULL,
 			(first_select->options | thd->options |
 			 SELECT_NO_UNLOCK),

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2010-04-01 13:15:22 +0000
+++ b/sql/sql_lex.cc	2010-06-04 14:25:18 +0000
@@ -1641,7 +1641,7 @@ void st_select_lex::init_select()
   linkage= UNSPECIFIED_TYPE;
   order_list.elements= 0;
   order_list.first= 0;
-  order_list.next= (uchar**) &order_list.first;
+  order_list.next= &order_list.first;
   /* Set limit and offset to default values */
   select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
   offset_limit= 0;      /* denotes the default offset = 0 */
@@ -1963,7 +1963,7 @@ uint st_select_lex::get_in_sum_expr()
 
 TABLE_LIST* st_select_lex::get_table_list()
 {
-  return (TABLE_LIST*) table_list.first;
+  return table_list.first;
 }
 
 List<Item>* st_select_lex::get_item_list()
@@ -2020,9 +2020,8 @@ void st_select_lex_unit::print(String *s
     if (fake_select_lex->order_list.elements)
     {
       str->append(STRING_WITH_LEN(" order by "));
-      fake_select_lex->print_order(
-        str,
-        (ORDER *) fake_select_lex->order_list.first,
+      fake_select_lex->print_order(str,
+        fake_select_lex->order_list.first,
         query_type);
     }
     fake_select_lex->print_limit(thd, str, query_type);
@@ -2667,7 +2666,7 @@ TABLE_LIST *st_lex::unlink_first_table(b
     {
       select_lex.context.table_list= 
         select_lex.context.first_name_resolution_table= first->next_local;
-      select_lex.table_list.first= (uchar*) (first->next_local);
+      select_lex.table_list.first= first->next_local;
       select_lex.table_list.elements--;	//safety
       first->next_local= 0;
       /*
@@ -2699,7 +2698,7 @@ TABLE_LIST *st_lex::unlink_first_table(b
 
 void st_lex::first_lists_tables_same()
 {
-  TABLE_LIST *first_table= (TABLE_LIST*) select_lex.table_list.first;
+  TABLE_LIST *first_table= select_lex.table_list.first;
   if (query_tables != first_table && first_table != 0)
   {
     TABLE_LIST *next;
@@ -2746,9 +2745,9 @@ void st_lex::link_first_table_back(TABLE
 
     if (link_to_local)
     {
-      first->next_local= (TABLE_LIST*) select_lex.table_list.first;
+      first->next_local= select_lex.table_list.first;
       select_lex.context.table_list= first;
-      select_lex.table_list.first= (uchar*) first;
+      select_lex.table_list.first= first;
       select_lex.table_list.elements++;	//safety
     }
   }
@@ -2914,7 +2913,7 @@ void st_select_lex::fix_prepare_informat
       prep_having= *having_conds;
       *having_conds= having= prep_having->copy_andor_structure(thd);
     }
-    fix_prepare_info_in_table_list(thd, (TABLE_LIST *)table_list.first);
+    fix_prepare_info_in_table_list(thd, table_list.first);
   }
 }
 

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2010-03-28 08:37:47 +0000
+++ b/sql/sql_lex.h	2010-06-04 14:25:18 +0000
@@ -587,8 +587,8 @@ public:
   st_lex *parent_lex;
   enum olap_type olap;
   /* FROM clause - points to the beginning of the TABLE_LIST::next_local list. */
-  SQL_LIST	      table_list;
-  SQL_LIST	      group_list; /* GROUP BY clause. */
+  SQL_I_List<TABLE_LIST>  table_list;
+  SQL_I_List<ORDER>       group_list; /* GROUP BY clause. */
   List<Item>          item_list;  /* list of fields & expressions */
   List<String>        interval_list;
   bool	              is_item_list_lookup;
@@ -610,8 +610,8 @@ public:
   TABLE_LIST *leaf_tables;
   const char *type;               /* type of select for EXPLAIN          */
 
-  SQL_LIST order_list;                /* ORDER clause */
-  SQL_LIST *gorder_list;
+  SQL_I_List<ORDER> order_list;   /* ORDER clause */
+  SQL_I_List<ORDER> *gorder_list;
   Item *select_limit, *offset_limit;  /* LIMIT clause parameters */
   // Arrays of pointers to top elements of all_fields list
   Item **ref_pointer_array;
@@ -774,7 +774,7 @@ public:
   {
     order_list.elements= 0;
     order_list.first= 0;
-    order_list.next= (uchar**) &order_list.first;
+    order_list.next= &order_list.first;
   }
   /*
     This method created for reiniting LEX in mysql_admin_table() and can be
@@ -953,6 +953,8 @@ enum xa_option_words {XA_NONE, XA_JOIN, 
                       XA_SUSPEND, XA_FOR_MIGRATE};
 
 
+struct Sroutine_hash_entry;
+
 /*
   Class representing list of all tables used by statement.
   It also contains information about stored functions used by statement
@@ -993,9 +995,9 @@ public:
     We use these two members for restoring of 'sroutines_list' to the state
     in which it was right after query parsing.
   */
-  SQL_LIST sroutines_list;
-  uchar    **sroutines_list_own_last;
-  uint     sroutines_list_own_elements;
+  SQL_I_List<Sroutine_hash_entry> sroutines_list;
+  Sroutine_hash_entry **sroutines_list_own_last;
+  uint sroutines_list_own_elements;
 
   /*
     These constructor and destructor serve for creation/destruction
@@ -1599,7 +1601,8 @@ typedef struct st_lex : public Query_tab
   */
   List<Name_resolution_context> context_stack;
 
-  SQL_LIST	      proc_list, auxiliary_table_list, save_list;
+  SQL_I_List<ORDER> proc_list;
+  SQL_I_List<TABLE_LIST> auxiliary_table_list, save_list;
   Create_field	      *last_field;
   Item_sum *in_sum_func;
   udf_func udf;
@@ -1721,7 +1724,7 @@ typedef struct st_lex : public Query_tab
     fields to TABLE object at table open (altough for latter pointer to table
     being opened is probably enough).
   */
-  SQL_LIST trg_table_fields;
+  SQL_I_List<Item_trigger_field> trg_table_fields;
 
   /*
     stmt_definition_begin is intended to point to the next word after

=== modified file 'sql/sql_list.h'
--- a/sql/sql_list.h	2009-06-10 08:59:49 +0000
+++ b/sql/sql_list.h	2010-06-04 14:25:18 +0000
@@ -55,6 +55,75 @@ public:
 };
 
 
+/**
+  Simple intrusive linked list.
+
+  @remark Similar in nature to base_list, but intrusive. It keeps a
+          a pointer to the first element in the list and a indirect
+          reference to the last element.
+
+  @TODO Replace with I_P_List.
+*/
+template <typename T>
+class SQL_I_List :public Sql_alloc
+{
+public:
+  uint elements;
+  /** The first element in the list. */
+  T *first;
+  /** A reference to the next element in the list. */
+  T **next;
+
+  SQL_I_List() {}
+
+  SQL_I_List(const SQL_I_List &tmp)
+  {
+    elements= tmp.elements;
+    first= tmp.first;
+    next= elements ? tmp.next : &first;
+  }
+
+  inline void empty()
+  {
+    elements= 0;
+    first= NULL;
+    next= &first;
+  }
+
+  inline void link_in_list(T *element, T **next_ptr)
+  {
+    elements++;
+    (*next)= element;
+    next= next_ptr;
+    *next= NULL;
+  }
+
+  inline void save_and_clear(SQL_I_List<T> *save)
+  {
+    *save= *this;
+    empty();
+  }
+
+  inline void push_front(SQL_I_List<T> *save)
+  {
+    /* link current list last */
+    *save->next= first;
+    first= save->first;
+    elements+= save->elements;
+  }
+
+  inline void push_back(SQL_I_List<T> *save)
+  {
+    if (save->first)
+    {
+      *next= save->first;
+      next= save->next;
+      elements+= save->elements;
+    }
+  }
+};
+
+
 /*
   Basic single linked list
   Used for item and item_buffs.

=== modified file 'sql/sql_olap.cc'
--- a/sql/sql_olap.cc	2007-05-10 09:59:39 +0000
+++ b/sql/sql_olap.cc	2010-06-04 14:25:18 +0000
@@ -146,14 +146,14 @@ int handle_olaps(LEX *lex, SELECT_LEX *s
 
   lex->last_selects=select_lex;
 
-  for (ORDER *order=(ORDER *)select_lex->group_list.first ; order ; order=order->next)
+  for (ORDER *order= select_lex->group_list.first ; order ; order=order->next)
     item_list_copy.push_back(*(order->item));
 
   List<Item>	all_fields(select_lex->item_list);
 
 
   if (setup_tables(lex->thd, &select_lex->context, &select_lex->top_join_list,
-                   (TABLE_LIST *)select_lex->table_list.first
+                   select_lex->table_list.first
                    &select_lex->leaf_tables, FALSE) ||
       setup_fields(lex->thd, 0, select_lex->item_list, MARK_COLUMNS_READ,
                    &all_fields,1) ||

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2010-06-01 11:48:24 +0000
+++ b/sql/sql_parse.cc	2010-06-04 14:25:18 +0000
@@ -1355,8 +1355,8 @@ bool dispatch_command(enum enum_server_c
     mysql_reset_thd_for_next_command(thd);
 
     thd->lex->
-      select_lex.table_list.link_in_list((uchar*) &table_list,
-                                         (uchar**) &table_list.next_local);
+      select_lex.table_list.link_in_list(&table_list,
+                                         &table_list.next_local);
     thd->lex->add_to_query_tables(&table_list);
 
     /* switch on VIEW optimisation: do not fill temporary tables */
@@ -1829,7 +1829,7 @@ int prepare_schema_table(THD *thd, LEX *
   {
     DBUG_RETURN(1);
   }
-  TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
+  TABLE_LIST *table_list= select_lex->table_list.first;
   table_list->schema_select_lex= schema_select_lex;
   table_list->schema_table_reformed= 1;
   DBUG_RETURN(0);
@@ -2025,7 +2025,7 @@ mysql_execute_command(THD *thd)
   /* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
   SELECT_LEX *select_lex= &lex->select_lex;
   /* first table of first SELECT_LEX */
-  TABLE_LIST *first_table= (TABLE_LIST*) select_lex->table_list.first;
+  TABLE_LIST *first_table= select_lex->table_list.first;
   /* list of all tables in query */
   TABLE_LIST *all_tables;
   /* most outer SELECT_LEX_UNIT of query */
@@ -2060,7 +2060,7 @@ mysql_execute_command(THD *thd)
   all_tables= lex->query_tables;
   /* set context for commands which do not use setup_tables */
   select_lex->
-    context.resolve_in_table_list_only((TABLE_LIST*)select_lex->
+    context.resolve_in_table_list_only(select_lex->
                                        table_list.first);
 
   /*
@@ -2401,7 +2401,7 @@ mysql_execute_command(THD *thd)
       goto error; /* purecov: inspected */
     thd->enable_slow_log= opt_log_slow_admin_statements;
     res = mysql_backup_table(thd, first_table);
-    select_lex->table_list.first= (uchar*) first_table;
+    select_lex->table_list.first= first_table;
     lex->query_tables=all_tables;
     break;
   }
@@ -2413,7 +2413,7 @@ mysql_execute_command(THD *thd)
       goto error; /* purecov: inspected */
     thd->enable_slow_log= opt_log_slow_admin_statements;
     res = mysql_restore_table(thd, first_table);
-    select_lex->table_list.first= (uchar*) first_table;
+    select_lex->table_list.first= first_table;
     lex->query_tables=all_tables;
     break;
   }
@@ -2707,7 +2707,7 @@ mysql_execute_command(THD *thd)
         if (create_info.used_fields & HA_CREATE_USED_UNION)
         {
           TABLE_LIST *tab;
-          for (tab= (TABLE_LIST*) create_info.merge_list.first;
+          for (tab= create_info.merge_list.first;
                tab;
                tab= tab->next_local)
           {
@@ -2877,7 +2877,6 @@ end_with_restore_list:
 	  check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv,0,0,
                        is_schema_db(select_lex->db))||
 	  check_merge_table_access(thd, first_table->db,
-				   (TABLE_LIST *)
 				   create_info.merge_list.first))
 	goto error;				/* purecov: inspected */
       if (check_grant(thd, priv_needed, all_tables, 0, UINT_MAX, 0))
@@ -3012,7 +3011,7 @@ end_with_restore_list:
       */
       res= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
     }
-    select_lex->table_list.first= (uchar*) first_table;
+    select_lex->table_list.first= first_table;
     lex->query_tables=all_tables;
     break;
   }
@@ -3024,7 +3023,7 @@ end_with_restore_list:
       goto error; /* purecov: inspected */
     thd->enable_slow_log= opt_log_slow_admin_statements;
     res = mysql_check_table(thd, first_table, &lex->check_opt);
-    select_lex->table_list.first= (uchar*) first_table;
+    select_lex->table_list.first= first_table;
     lex->query_tables=all_tables;
     break;
   }
@@ -3044,7 +3043,7 @@ end_with_restore_list:
       */
       res= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
     }
-    select_lex->table_list.first= (uchar*) first_table;
+    select_lex->table_list.first= first_table;
     lex->query_tables=all_tables;
     break;
   }
@@ -3067,7 +3066,7 @@ end_with_restore_list:
       */
       res= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
     }
-    select_lex->table_list.first= (uchar*) first_table;
+    select_lex->table_list.first= first_table;
     lex->query_tables=all_tables;
     break;
   }
@@ -3085,7 +3084,7 @@ end_with_restore_list:
                                   lex->value_list,
                                   select_lex->where,
                                   select_lex->order_list.elements,
-                                  (ORDER *) select_lex->order_list.first,
+                                  select_lex->order_list.first,
                                   unit->select_limit_cnt,
                                   lex->duplicates, lex->ignore));
     /* mysql_update return 2 if we need to switch to multi-update */
@@ -3245,7 +3244,7 @@ end_with_restore_list:
     {
       /* Skip first table, which is the table we are inserting in */
       TABLE_LIST *second_table= first_table->next_local;
-      select_lex->table_list.first= (uchar*) second_table;
+      select_lex->table_list.first= second_table;
       select_lex->context.table_list= 
         select_lex->context.first_name_resolution_table= second_table;
       res= mysql_insert_select_prepare(thd);
@@ -3276,7 +3275,7 @@ end_with_restore_list:
         delete sel_result;
       }
       /* revert changes for SP */
-      select_lex->table_list.first= (uchar*) first_table;
+      select_lex->table_list.first= first_table;
     }
 
     /*
@@ -3338,8 +3337,7 @@ end_with_restore_list:
   case SQLCOM_DELETE_MULTI:
   {
     DBUG_ASSERT(first_table == all_tables && first_table != 0);
-    TABLE_LIST *aux_tables=
-      (TABLE_LIST *)thd->lex->auxiliary_table_list.first;
+    TABLE_LIST *aux_tables= thd->lex->auxiliary_table_list.first;
     multi_delete *del_result;
 
     if (!thd->locked_tables &&
@@ -5347,7 +5345,7 @@ static bool check_show_access(THD *thd, 
   case SCH_STATISTICS:
   {
     TABLE_LIST *dst_table;
-    dst_table= (TABLE_LIST *) table->schema_select_lex->table_list.first;
+    dst_table= table->schema_select_lex->table_list.first;
 
     DBUG_ASSERT(dst_table);
 
@@ -6046,7 +6044,7 @@ bool mysql_test_parse_for_slave(THD *thd
   mysql_reset_thd_for_next_command(thd);
 
   if (!parse_sql(thd, & parser_state, NULL) &&
-      all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
+      all_tables_not_ok(thd, lex->select_lex.table_list.first))
     error= 1;                  /* Ignore question */
   thd->end_statement();
   thd->cleanup_after_query();
@@ -6184,7 +6182,7 @@ add_proc_to_list(THD* thd, Item *item)
   *item_ptr= item;
   order->item=item_ptr;
   order->free_me=0;
-  thd->lex->proc_list.link_in_list((uchar*) order,(uchar**) &order->next);
+  thd->lex->proc_list.link_in_list(order, &order->next);
   return 0;
 }
 
@@ -6193,7 +6191,7 @@ add_proc_to_list(THD* thd, Item *item)
   save order by and tables in own lists.
 */
 
-bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
+bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *item,bool asc)
 {
   ORDER *order;
   DBUG_ENTER("add_to_list");
@@ -6205,7 +6203,7 @@ bool add_to_list(THD *thd, SQL_LIST &lis
   order->free_me=0;
   order->used=0;
   order->counter_used= 0;
-  list.link_in_list((uchar*) order,(uchar**) &order->next);
+  list.link_in_list(order, &order->next);
   DBUG_RETURN(0);
 }
 
@@ -6319,7 +6317,7 @@ TABLE_LIST *st_select_lex::add_table_to_
   /* check that used name is unique */
   if (lock_type != TL_IGNORE)
   {
-    TABLE_LIST *first_table= (TABLE_LIST*) table_list.first;
+    TABLE_LIST *first_table= table_list.first;
     if (lex->sql_command == SQLCOM_CREATE_VIEW)
       first_table= first_table ? first_table->next_local : NULL;
     for (TABLE_LIST *tables= first_table ;
@@ -6361,7 +6359,7 @@ TABLE_LIST *st_select_lex::add_table_to_
     previous table reference to 'ptr'. Here we also add one element to the
     list 'table_list'.
   */
-  table_list.link_in_list((uchar*) ptr, (uchar**) &ptr->next_local);
+  table_list.link_in_list(ptr, &ptr->next_local);
   ptr->next_name_resolution_table= NULL;
   /* Link table in global list (all used tables) */
   lex->add_to_query_tables(ptr);
@@ -6594,7 +6592,7 @@ void st_select_lex::set_lock_for_tables(
   DBUG_ENTER("set_lock_for_tables");
   DBUG_PRINT("enter", ("lock_type: %d  for_update: %d", lock_type,
 		       for_update));
-  for (TABLE_LIST *tables= (TABLE_LIST*) table_list.first;
+  for (TABLE_LIST *tables= table_list.first;
        tables;
        tables= tables->next_local)
   {
@@ -7286,8 +7284,7 @@ bool multi_update_precheck(THD *thd, TAB
 bool multi_delete_precheck(THD *thd, TABLE_LIST *tables)
 {
   SELECT_LEX *select_lex= &thd->lex->select_lex;
-  TABLE_LIST *aux_tables=
-    (TABLE_LIST *)thd->lex->auxiliary_table_list.first;
+  TABLE_LIST *aux_tables= thd->lex->auxiliary_table_list.first;
   TABLE_LIST **save_query_tables_own_last= thd->lex->query_tables_own_last;
   DBUG_ENTER("multi_delete_precheck");
 
@@ -7333,13 +7330,13 @@ bool multi_delete_precheck(THD *thd, TAB
 
 bool multi_delete_set_locks_and_link_aux_tables(LEX *lex)
 {
-  TABLE_LIST *tables= (TABLE_LIST*)lex->select_lex.table_list.first;
+  TABLE_LIST *tables= lex->select_lex.table_list.first;
   TABLE_LIST *target_tbl;
   DBUG_ENTER("multi_delete_set_locks_and_link_aux_tables");
 
   lex->table_count= 0;
 
-  for (target_tbl= (TABLE_LIST *)lex->auxiliary_table_list.first;
+  for (target_tbl= lex->auxiliary_table_list.first;
        target_tbl; target_tbl= target_tbl->next_local)
   {
     lex->table_count++;
@@ -7509,8 +7506,7 @@ bool create_table_precheck(THD *thd, TAB
 		   &create_table->grant.privilege, 0, 0,
                    test(create_table->schema_table)) ||
       check_merge_table_access(thd, create_table->db,
-			       (TABLE_LIST *)
-			       lex->create_info.merge_list.first))
+                               lex->create_info.merge_list.first))
     goto err;
   if (want_priv != CREATE_TMP_ACL &&
       check_grant(thd, want_priv, create_table, 0, 1, 0))

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2010-01-16 07:44:24 +0000
+++ b/sql/sql_prepare.cc	2010-06-04 14:25:18 +0000
@@ -1240,7 +1240,7 @@ static int mysql_test_update(Prepared_st
 
   if (mysql_prepare_update(thd, table_list, &select->where,
                            select->order_list.elements,
-                           (ORDER *) select->order_list.first))
+                           select->order_list.first))
     goto error;
 
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
@@ -1746,11 +1746,10 @@ error:
 static int mysql_insert_select_prepare_tester(THD *thd)
 {
   SELECT_LEX *first_select= &thd->lex->select_lex;
-  TABLE_LIST *second_table= ((TABLE_LIST*)first_select->table_list.first)->
-    next_local;
+  TABLE_LIST *second_table= first_select->table_list.first->next_local;
 
   /* Skip first table, which is the table we are inserting in */
-  first_select->table_list.first= (uchar *) second_table;
+  first_select->table_list.first= second_table;
   thd->lex->select_lex.context.table_list=
     thd->lex->select_lex.context.first_name_resolution_table= second_table;
 
@@ -1787,7 +1786,7 @@ static bool mysql_test_insert_select(Pre
     return 1;
 
   /* store it, because mysql_insert_select_prepare_tester change it */
-  first_local_table= (TABLE_LIST *)lex->select_lex.table_list.first;
+  first_local_table= lex->select_lex.table_list.first;
   DBUG_ASSERT(first_local_table != 0);
 
   res=
@@ -1795,7 +1794,7 @@ static bool mysql_test_insert_select(Pre
                                     &mysql_insert_select_prepare_tester,
                                     OPTION_SETUP_TABLES_DONE);
   /* revert changes  made by mysql_insert_select_prepare_tester */
-  lex->select_lex.table_list.first= (uchar*) first_local_table;
+  lex->select_lex.table_list.first= first_local_table;
   return res;
 }
 
@@ -2339,10 +2338,10 @@ void reinit_stmt_before_use(THD *thd, LE
       DBUG_ASSERT(sl->join == 0);
       ORDER *order;
       /* Fix GROUP list */
-      for (order= (ORDER *)sl->group_list.first; order; order= order->next)
+      for (order= sl->group_list.first; order; order= order->next)
         order->item= &order->item_ptr;
       /* Fix ORDER list */
-      for (order= (ORDER *)sl->order_list.first; order; order= order->next)
+      for (order= sl->order_list.first; order; order= order->next)
         order->item= &order->item_ptr;
 
       /* clear the no_error flag for INSERT/UPDATE IGNORE */
@@ -2379,7 +2378,7 @@ void reinit_stmt_before_use(THD *thd, LE
     (multi-delete).  We do a full clean up, although at the moment all we
     need to clean in the tables of MULTI-DELETE list is 'table' member.
   */
-  for (TABLE_LIST *tables= (TABLE_LIST*) lex->auxiliary_table_list.first;
+  for (TABLE_LIST *tables= lex->auxiliary_table_list.first;
        tables;
        tables= tables->next_global)
   {

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-05-27 15:13:53 +0000
+++ b/sql/sql_select.cc	2010-06-04 14:25:18 +0000
@@ -255,15 +255,15 @@ bool handle_select(THD *thd, LEX *lex, s
       setup_tables_done_option changed for next rexecution
     */
     res= mysql_select(thd, &select_lex->ref_pointer_array,
-		      (TABLE_LIST*) select_lex->table_list.first,
+		      select_lex->table_list.first,
 		      select_lex->with_wild, select_lex->item_list,
 		      select_lex->where,
 		      select_lex->order_list.elements +
 		      select_lex->group_list.elements,
-		      (ORDER*) select_lex->order_list.first,
-		      (ORDER*) select_lex->group_list.first,
+		      select_lex->order_list.first,
+		      select_lex->group_list.first,
 		      select_lex->having,
-		      (ORDER*) lex->proc_list.first,
+		      lex->proc_list.first,
 		      select_lex->options | thd->options |
                       setup_tables_done_option,
 		      result, unit, select_lex);
@@ -16803,15 +16803,15 @@ bool mysql_explain_union(THD *thd, SELEC
     thd->lex->current_select= first;
     unit->set_limit(unit->global_parameters);
     res= mysql_select(thd, &first->ref_pointer_array,
-			(TABLE_LIST*) first->table_list.first,
+			first->table_list.first,
 			first->with_wild, first->item_list,
 			first->where,
 			first->order_list.elements +
 			first->group_list.elements,
-			(ORDER*) first->order_list.first,
-			(ORDER*) first->group_list.first,
+			first->order_list.first,
+			first->group_list.first,
 			first->having,
-			(ORDER*) thd->lex->proc_list.first,
+			thd->lex->proc_list.first,
 			first->options | thd->options | SELECT_DESCRIBE,
 			result, unit, first);
   }
@@ -17098,7 +17098,7 @@ void st_select_lex::print(THD *thd, Stri
   if (group_list.elements)
   {
     str->append(STRING_WITH_LEN(" group by "));
-    print_order(str, (ORDER *) group_list.first, query_type);
+    print_order(str, group_list.first, query_type);
     switch (olap)
     {
       case CUBE_TYPE:
@@ -17129,7 +17129,7 @@ void st_select_lex::print(THD *thd, Stri
   if (order_list.elements)
   {
     str->append(STRING_WITH_LEN(" order by "));
-    print_order(str, (ORDER *) order_list.first, query_type);
+    print_order(str, order_list.first, query_type);
   }
 
   // limit

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2010-05-18 08:28:21 +0000
+++ b/sql/sql_show.cc	2010-06-04 14:25:18 +0000
@@ -2998,8 +2998,7 @@ fill_schema_show_cols_or_idxs(THD *thd, 
   bool res;
   LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
   enum_sql_command save_sql_command= lex->sql_command;
-  TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
-    table_list.first;
+  TABLE_LIST *show_table_list= tables->schema_select_lex->table_list.first;
   TABLE *table= tables->table;
   int error= 1;
   DBUG_ENTER("fill_schema_show");
@@ -3445,7 +3444,7 @@ int get_all_tables(THD *thd, TABLE_LIST 
               goto err;
             if (make_table_list(thd, &sel, db_name, table_name))
               goto err;
-            TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
+            TABLE_LIST *show_table_list= sel.table_list.first;
             lex->all_selects_list= &sel;
             lex->derived_tables= 0;
             lex->sql_command= SQLCOM_SHOW_FIELDS;

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-05-23 16:08:33 +0000
+++ b/sql/sql_table.cc	2010-06-04 14:25:18 +0000
@@ -4592,7 +4592,7 @@ static bool mysql_admin_table(THD* thd, 
       table->next_global= 0;
       save_next_local= table->next_local;
       table->next_local= 0;
-      select->table_list.first= (uchar*)table;
+      select->table_list.first= table;
       /*
         Time zone tables and SP tables can be add to lex->query_tables list,
         so it have to be prepared.

=== modified file 'sql/sql_trigger.cc'
--- a/sql/sql_trigger.cc	2010-01-28 14:41:14 +0000
+++ b/sql/sql_trigger.cc	2010-06-04 14:25:18 +0000
@@ -653,7 +653,7 @@ bool Table_triggers_list::create_trigger
   */
   old_field= new_field= table->field;
 
-  for (trg_field= (Item_trigger_field *)(lex->trg_table_fields.first);
+  for (trg_field= lex->trg_table_fields.first;
        trg_field; trg_field= trg_field->next_trg_field)
   {
     /*
@@ -1413,7 +1413,7 @@ bool Table_triggers_list::check_n_load(T
         */
         triggers->trigger_fields[lex.trg_chistics.event]
                                 [lex.trg_chistics.action_time]=
-          (Item_trigger_field *)(lex.trg_table_fields.first);
+          lex.trg_table_fields.first;
         /*
           Also let us bind these objects to Field objects in table being
           opened.
@@ -1423,8 +1423,7 @@ bool Table_triggers_list::check_n_load(T
           SELECT)...
           Anyway some things can be checked only during trigger execution.
         */
-        for (Item_trigger_field *trg_field=
-               (Item_trigger_field *)(lex.trg_table_fields.first);
+        for (Item_trigger_field *trg_field= lex.trg_table_fields.first;
              trg_field;
              trg_field= trg_field->next_trg_field)
         {

=== modified file 'sql/sql_union.cc'
--- a/sql/sql_union.cc	2009-12-22 15:52:15 +0000
+++ b/sql/sql_union.cc	2010-06-04 14:25:18 +0000
@@ -144,20 +144,19 @@ void
 st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg) 
 {
   thd_arg->lex->current_select= fake_select_lex;
-  fake_select_lex->table_list.link_in_list((uchar *)&result_table_list,
-					   (uchar **)
-					   &result_table_list.next_local);
+  fake_select_lex->table_list.link_in_list(&result_table_list,
+                                           &result_table_list.next_local);
   fake_select_lex->context.table_list= 
     fake_select_lex->context.first_name_resolution_table= 
     fake_select_lex->get_table_list();
   if (!fake_select_lex->first_execution)
   {
-    for (ORDER *order= (ORDER *) global_parameters->order_list.first;
+    for (ORDER *order= global_parameters->order_list.first;
          order;
          order= order->next)
       order->item= &order->item_ptr;
   }
-  for (ORDER *order= (ORDER *)global_parameters->order_list.first;
+  for (ORDER *order= global_parameters->order_list.first;
        order;
        order=order->next)
   {
@@ -249,18 +248,18 @@ bool st_select_lex_unit::prepare(THD *th
     can_skip_order_by= is_union_select && !(sl->braces && sl->explicit_limit);
 
     saved_error= join->prepare(&sl->ref_pointer_array,
-                               (TABLE_LIST*) sl->table_list.first,
+                               sl->table_list.first,
                                sl->with_wild,
                                sl->where,
                                (can_skip_order_by ? 0 :
                                 sl->order_list.elements) +
                                sl->group_list.elements,
                                can_skip_order_by ?
-                               (ORDER*) 0 : (ORDER *)sl->order_list.first,
-                               (ORDER*) sl->group_list.first,
+                               NULL : sl->order_list.first,
+                               sl->group_list.first,
                                sl->having,
-                               (is_union_select ? (ORDER*) 0 :
-                                (ORDER*) thd_arg->lex->proc_list.first),
+                               (is_union_select ? NULL :
+                                thd_arg->lex->proc_list.first),
                                sl, this);
     /* There are no * in the statement anymore (for PS) */
     sl->with_wild= 0;
@@ -354,7 +353,7 @@ bool st_select_lex_unit::prepare(THD *th
     {
       ORDER *ord;
       Item_func::Functype ft=  Item_func::FT_FUNC;
-      for (ord= (ORDER*)global_parameters->order_list.first; ord; ord= ord->next)
+      for (ord= global_parameters->order_list.first; ord; ord= ord->next)
         if ((*ord->item)->walk (&Item::find_function_processor, FALSE, 
                                 (uchar *) &ft))
         {
@@ -416,12 +415,11 @@ bool st_select_lex_unit::prepare(THD *th
 	thd_arg->lex->current_select= fake_select_lex;
 	saved_error= fake_select_lex->join->
 	  prepare(&fake_select_lex->ref_pointer_array,
-		  (TABLE_LIST*) fake_select_lex->table_list.first,
+		  fake_select_lex->table_list.first,
 		  0, 0,
 		  fake_select_lex->order_list.elements,
-		  (ORDER*) fake_select_lex->order_list.first,
-		  (ORDER*) NULL, NULL,
-                  (ORDER*) NULL,
+		  fake_select_lex->order_list.first,
+		  NULL, NULL, NULL,
 		  fake_select_lex, this);
 	fake_select_lex->table_list.empty();
       }
@@ -597,8 +595,8 @@ bool st_select_lex_unit::exec()
                               &result_table_list,
                               0, item_list, NULL,
                               global_parameters->order_list.elements,
-                              (ORDER*)global_parameters->order_list.first,
-                              (ORDER*) NULL, NULL, (ORDER*) NULL,
+                              global_parameters->order_list.first,
+                              NULL, NULL, NULL,
                               fake_select_lex->options | SELECT_NO_UNLOCK,
                               result, this, fake_select_lex);
       }
@@ -620,8 +618,8 @@ bool st_select_lex_unit::exec()
                                 &result_table_list,
                                 0, item_list, NULL,
                                 global_parameters->order_list.elements,
-                                (ORDER*)global_parameters->order_list.first,
-                                (ORDER*) NULL, NULL, (ORDER*) NULL,
+                                global_parameters->order_list.first,
+                                NULL, NULL, NULL,
                                 fake_select_lex->options | SELECT_NO_UNLOCK,
                                 result, this, fake_select_lex);
         }
@@ -697,7 +695,7 @@ bool st_select_lex_unit::cleanup()
     if (global_parameters->order_list.elements)
     {
       ORDER *ord;
-      for (ord= (ORDER*)global_parameters->order_list.first; ord; ord= ord->next)
+      for (ord= global_parameters->order_list.first; ord; ord= ord->next)
         (*ord->item)->walk (&Item::cleanup_processor, 0, 0);
     }
   }

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2010-05-27 20:07:40 +0000
+++ b/sql/sql_update.cc	2010-06-04 14:25:18 +0000
@@ -1331,7 +1331,7 @@ int multi_update::prepare(List<Item> &no
 			  SELECT_LEX_UNIT *lex_unit)
 {
   TABLE_LIST *table_ref;
-  SQL_LIST update;
+  SQL_I_List<TABLE_LIST> update;
   table_map tables_to_update;
   Item_field *item;
   List_iterator_fast<Item> field_it(*fields);
@@ -1412,11 +1412,11 @@ int multi_update::prepare(List<Item> &no
     leaf_table_count++;
     if (tables_to_update & table->map)
     {
-      TABLE_LIST *tl= (TABLE_LIST*) thd->memdup((char*) table_ref,
+      TABLE_LIST *tl= (TABLE_LIST*) thd->memdup(table_ref,
 						sizeof(*tl));
       if (!tl)
 	DBUG_RETURN(1);
-      update.link_in_list((uchar*) tl, (uchar**) &tl->next_local);
+      update.link_in_list(tl, &tl->next_local);
       tl->shared= table_count++;
       table->no_keyread=1;
       table->covering_keys.clear_all();
@@ -1437,7 +1437,7 @@ int multi_update::prepare(List<Item> &no
 
 
   table_count=  update.elements;
-  update_tables= (TABLE_LIST*) update.first;
+  update_tables= update.first;
 
   tmp_tables = (TABLE**) thd->calloc(sizeof(TABLE *) * table_count);
   tmp_table_param = (TMP_TABLE_PARAM*) thd->calloc(sizeof(TMP_TABLE_PARAM) *

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2010-03-09 10:36:26 +0000
+++ b/sql/sql_view.cc	2010-06-04 14:25:18 +0000
@@ -887,7 +887,7 @@ static int mysql_register_view(THD *thd,
                               view->algorithm != VIEW_ALGORITHM_TMPTABLE)))
   {
     /* TODO: change here when we will support UNIONs */
-    for (TABLE_LIST *tbl= (TABLE_LIST *)lex->select_lex.table_list.first;
+    for (TABLE_LIST *tbl= lex->select_lex.table_list.first;
 	 tbl;
 	 tbl= tbl->next_local)
     {
@@ -1006,7 +1006,7 @@ loop_out:
   */
   if (view->updatable_view &&
       !lex->select_lex.master_unit()->is_union() &&
-      !((TABLE_LIST*)lex->select_lex.table_list.first)->next_local &&
+      !(lex->select_lex.table_list.first)->next_local &&
       find_table_in_global_list(lex->query_tables->next_global,
 				lex->query_tables->db,
 				lex->query_tables->table_name))
@@ -1349,8 +1349,7 @@ bool mysql_make_view(THD *thd, File_pars
         This may change in future, for example if we enable merging of
         views with subqueries in select list.
       */
-      view_main_select_tables=
-        (TABLE_LIST*)lex->select_lex.table_list.first;
+      view_main_select_tables= lex->select_lex.table_list.first;
 
       /*
         Let us set proper lock type for tables of the view's main

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2010-05-04 14:03:28 +0000
+++ b/sql/sql_yacc.yy	2010-06-04 14:25:18 +0000
@@ -514,8 +514,7 @@ set_trigger_new_row(THD *thd, LEX_STRING
     Let us add this item to list of all Item_trigger_field
     objects in trigger.
   */
-  lex->trg_table_fields.link_in_list((uchar *) trg_fld,
-                                     (uchar **) &trg_fld->next_trg_field);
+  lex->trg_table_fields.link_in_list(trg_fld, &trg_fld->next_trg_field);
 
   return lex->sphead->add_instr(sp_fld);
 }
@@ -4678,11 +4677,9 @@ create_table_option:
             TABLE_LIST *table_list= lex->select_lex.get_table_list();
             lex->create_info.merge_list= lex->select_lex.table_list;
             lex->create_info.merge_list.elements--;
-            lex->create_info.merge_list.first=
-              (uchar*) (table_list->next_local);
+            lex->create_info.merge_list.first= table_list->next_local;
             lex->select_lex.table_list.elements=1;
-            lex->select_lex.table_list.next=
-              (uchar**) &(table_list->next_local);
+            lex->select_lex.table_list.next= &(table_list->next_local);
             table_list->next_local= 0;
             lex->create_info.used_fields|= HA_CREATE_USED_UNION;
           }
@@ -5638,8 +5635,7 @@ alter:
             lex->alter_info.reset();
             lex->col_list.empty();
             lex->select_lex.init_order();
-            lex->select_lex.db=
-              ((TABLE_LIST*) lex->select_lex.table_list.first)->db;
+            lex->select_lex.db= (lex->select_lex.table_list.first)->db;
             bzero((char*) &lex->create_info,sizeof(lex->create_info));
             lex->create_info.db_type= 0;
             lex->create_info.default_table_charset= NULL;
@@ -8348,9 +8344,8 @@ opt_gorder_clause:
         | order_clause
           {
             SELECT_LEX *select= Select;
-            select->gorder_list=
-              (SQL_LIST*) sql_memdup((char*) &select->order_list,
-                                     sizeof(st_sql_list));
+            select->gorder_list= new (YYTHD->mem_root)
+                                   SQL_I_List<ORDER>(select->order_list);
             if (select->gorder_list == NULL)
               MYSQL_YYABORT;
             select->order_list.empty();
@@ -9294,7 +9289,7 @@ procedure_clause:
             }
             lex->proc_list.elements=0;
             lex->proc_list.first=0;
-            lex->proc_list.next= (uchar**) &lex->proc_list.first;
+            lex->proc_list.next= &lex->proc_list.first;
             Item_field *item= new (YYTHD->mem_root)
                                 Item_field(&lex->current_select->context,
                                            NULL, NULL, $2.str);
@@ -11252,8 +11247,8 @@ simple_ident_q:
                 Let us add this item to list of all Item_trigger_field objects
                 in trigger.
               */
-              lex->trg_table_fields.link_in_list((uchar*) trg_fld,
-                                                 (uchar**) &trg_fld->next_trg_field);
+              lex->trg_table_fields.link_in_list(trg_fld,
+                                                 &trg_fld->next_trg_field);
 
               $$= trg_fld;
             }
@@ -11339,7 +11334,7 @@ field_ident:
           ident { $$=$1;}
         | ident '.' ident '.' ident
           {
-            TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
+            TABLE_LIST *table= Select->table_list.first;
             if (my_strcasecmp(table_alias_charset, $1.str, table->db))
             {
               my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
@@ -11355,7 +11350,7 @@ field_ident:
           }
         | ident '.' ident
           {
-            TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first;
+            TABLE_LIST *table= Select->table_list.first;
             if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
             {
               my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);

=== modified file 'storage/myisammrg/ha_myisammrg.cc'
--- a/storage/myisammrg/ha_myisammrg.cc	2010-03-14 16:01:45 +0000
+++ b/storage/myisammrg/ha_myisammrg.cc	2010-06-04 14:25:18 +0000
@@ -1130,8 +1130,8 @@ void ha_myisammrg::update_create_info(HA
 	goto err;
 
       create_info->merge_list.elements++;
-      (*create_info->merge_list.next) = (uchar*) ptr;
-      create_info->merge_list.next= (uchar**) &ptr->next_local;
+      (*create_info->merge_list.next) = ptr;
+      create_info->merge_list.next= &ptr->next_local;
     }
     *create_info->merge_list.next=0;
   }
@@ -1153,7 +1153,7 @@ int ha_myisammrg::create(const char *nam
 {
   char buff[FN_REFLEN];
   const char **table_names, **pos;
-  TABLE_LIST *tables= (TABLE_LIST*) create_info->merge_list.first;
+  TABLE_LIST *tables= create_info->merge_list.first;
   THD *thd= current_thd;
   size_t dirlgt= dirname_length(name);
   DBUG_ENTER("ha_myisammrg::create");


Attachment: [text/bzr-bundle] bzr/davi.arnaut@sun.com-20100604142518-movjvpf8hq22ngsv.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (davi:3417) Bug#42733Davi Arnaut4 Jun