List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:June 15 2011 1:39pm
Subject:bzr commit into mysql-trunk branch (davi:3205)
View as plain text  
# At a local mysql-trunk repository of davi

 3205 Davi Arnaut	2011-06-15
      A prerequisite patch for making const MYSQL_ERROR objects useable:
      
      Introduce a const iterator for I_P_List.
      Convert MYSQL_ERROR::m_warn_list to a I_P_List.
      Introduce funciton that returns a const iterator to m_warn_list.
      Remove MYSQL_ERROR::warn_list().
     @ sql/sql_error.cc
        Empty list before the memory root is destroyed.
     @ sql/sql_error.h
        Make m_warn_list a intrusive list and add pointers to MYSQL_ERROR
        so that it can participate in the intrusive list.
        
        Instead of exposing a reference to the list, now provide a const
        iterator.
     @ sql/sql_plist.h
        Reorganize I_P_List_iterator so that the complete list type is
        passed as a base type. The type of the object being stored in
        the list is passed as a additional argument. This allows a const
        qualified version of the type to be specified for the value type
        of the iterator without interfering with the non-qualified type of
        the list.
     @ sql/table.h
        Give a type to the intrusive list of TABLE_SHARE objects.

    modified:
      sql/event_scheduler.cc
      sql/log_event.cc
      sql/rpl_slave.cc
      sql/sp_head.cc
      sql/sql_admin.cc
      sql/sql_base.cc
      sql/sql_error.cc
      sql/sql_error.h
      sql/sql_plist.h
      sql/sql_prepare.h
      sql/sql_show.cc
      sql/sql_table.cc
      sql/sql_test.cc
      sql/table.cc
      sql/table.h
=== modified file 'sql/event_scheduler.cc'
--- a/sql/event_scheduler.cc	2011-06-10 16:57:01 +0000
+++ b/sql/event_scheduler.cc	2011-06-15 13:13:06 +0000
@@ -75,7 +75,7 @@ struct scheduler_param {
 void
 Event_worker_thread::print_warnings(THD *thd, Event_job_data *et)
 {
-  MYSQL_ERROR *err;
+  const MYSQL_ERROR *err;
   DBUG_ENTER("evex_print_warnings");
   if (thd->get_stmt_wi()->is_empty())
     DBUG_VOID_RETURN;
@@ -93,7 +93,7 @@ Event_worker_thread::print_warnings(THD
   prefix.append(et->name.str, et->name.length, system_charset_info);
   prefix.append("] ", 2);
 
-  List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+  Warning_info::Const_iterator it= thd->get_stmt_wi()->iterator();
   while ((err= it++))
   {
     String err_msg(msg_buf, sizeof(msg_buf), system_charset_info);

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2011-06-10 16:57:01 +0000
+++ b/sql/log_event.cc	2011-06-15 13:13:06 +0000
@@ -208,8 +208,8 @@ static void inline slave_rows_error_repo
   char buff[MAX_SLAVE_ERRMSG], *slider;
   const char *buff_end= buff + sizeof(buff);
   uint len;
-  List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
-  MYSQL_ERROR *err;
+  Warning_info::Const_iterator it= thd->get_stmt_wi()->iterator();
+  const MYSQL_ERROR *err;
   buff[0]= 0;
 
   for (err= it++, slider= buff; err && slider < buff_end - 1;

=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc	2011-06-10 16:57:01 +0000
+++ b/sql/rpl_slave.cc	2011-06-15 13:13:06 +0000
@@ -3747,8 +3747,8 @@ log '%s' at position %s, relay log '%s'
         }
 
         /* Print any warnings issued */
-        List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
-        MYSQL_ERROR *err;
+        Warning_info::Const_iterator it= thd->get_stmt_wi()->iterator();
+        const MYSQL_ERROR *err;
         /*
           Added controlled slave thread cancel for replication
           of user-defined variables.

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2011-06-10 16:57:01 +0000
+++ b/sql/sp_head.cc	2011-06-15 13:13:06 +0000
@@ -1148,8 +1148,8 @@ find_handler_after_execution(THD *thd, s
   }
   else if (thd->get_stmt_wi()->statement_warn_count())
   {
-    List_iterator<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
-    MYSQL_ERROR *err;
+    Warning_info::Const_iterator it= thd->get_stmt_wi()->iterator();
+    const MYSQL_ERROR *err;
     while ((err= it++))
     {
       if (err->get_level() != MYSQL_ERROR::WARN_LEVEL_WARN &&

=== modified file 'sql/sql_admin.cc'
--- a/sql/sql_admin.cc	2011-06-10 16:57:01 +0000
+++ b/sql/sql_admin.cc	2011-06-15 13:13:06 +0000
@@ -639,8 +639,8 @@ send_result:
     lex->cleanup_after_one_table_open();
     thd->clear_error();  // these errors shouldn't get client
     {
-      List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
-      MYSQL_ERROR *err;
+      Warning_info::Const_iterator it= thd->get_stmt_wi()->iterator();
+      const MYSQL_ERROR *err;
       while ((err= it++))
       {
         protocol->prepare_for_resend();

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2011-06-10 16:57:01 +0000
+++ b/sql/sql_base.cc	2011-06-15 13:13:06 +0000
@@ -182,7 +182,7 @@ static void check_unused(void)
   {
     share= (TABLE_SHARE*) my_hash_element(&table_def_cache, idx);
 
-    I_P_List_iterator<TABLE, TABLE_share> it(share->free_tables);
+    TABLE_SHARE::TABLE_list::Iterator it(share->free_tables);
     while ((entry= it++))
     {
       /* We must not have TABLEs in the free list that have their file closed. */
@@ -857,7 +857,7 @@ OPEN_TABLE_LIST *list_open_tables(THD *t
 		  share->db.str)+1,
 	   share->table_name.str);
     (*start_list)->in_use= 0;
-    I_P_List_iterator<TABLE, TABLE_share> it(share->used_tables);
+    TABLE_SHARE::TABLE_list::Iterator it(share->used_tables);
     while (it++)
       ++(*start_list)->in_use;
     (*start_list)->locked= 0;                   /* Obsolete. */
@@ -938,7 +938,7 @@ void free_io_cache(TABLE *table)
 
 static void kill_delayed_threads_for_table(TABLE_SHARE *share)
 {
-  I_P_List_iterator<TABLE, TABLE_share> it(share->used_tables);
+  TABLE_SHARE::TABLE_list::Iterator it(share->used_tables);
   TABLE *tab;
 
   mysql_mutex_assert_owner(&LOCK_open);
@@ -9015,7 +9015,7 @@ void tdc_remove_table(THD *thd, enum_tdc
   {
     if (share->ref_count)
     {
-      I_P_List_iterator<TABLE, TABLE_share> it(share->free_tables);
+      TABLE_SHARE::TABLE_list::Iterator it(share->free_tables);
 #ifndef DBUG_OFF
       if (remove_type == TDC_RT_REMOVE_ALL)
       {
@@ -9023,7 +9023,7 @@ void tdc_remove_table(THD *thd, enum_tdc
       }
       else if (remove_type == TDC_RT_REMOVE_NOT_OWN)
       {
-        I_P_List_iterator<TABLE, TABLE_share> it2(share->used_tables);
+        TABLE_SHARE::TABLE_list::Iterator it2(share->used_tables);
         while ((table= it2++))
           if (table->in_use != thd)
           {

=== modified file 'sql/sql_error.cc'
--- a/sql/sql_error.cc	2011-06-10 16:57:01 +0000
+++ b/sql/sql_error.cc	2011-06-15 13:13:06 +0000
@@ -499,9 +499,9 @@ Warning_info::~Warning_info()
 void Warning_info::clear_warning_info(ulonglong warn_id_arg)
 {
   m_warn_id= warn_id_arg;
+  m_warn_list.empty();
   free_root(&m_warn_root, MYF(0));
   memset(m_warn_count, 0, sizeof(m_warn_count));
-  m_warn_list.empty();
   m_statement_warn_count= 0;
   m_current_row_for_warning= 1; /* Start counting from the first row */
 }
@@ -559,13 +559,13 @@ MYSQL_ERROR *Warning_info::push_warning(
   if (! m_read_only)
   {
     if (m_allow_unlimited_warnings ||
-        m_warn_list.elements < thd->variables.max_error_count)
+        m_warn_list.elements() < thd->variables.max_error_count)
     {
       cond= new (& m_warn_root) MYSQL_ERROR(& m_warn_root);
       if (cond)
       {
         cond->set(sql_errno, sqlstate, level, msg);
-        m_warn_list.push_back(cond, &m_warn_root);
+        m_warn_list.push_back(cond);
       }
     }
     m_warn_count[(uint) level]++;
@@ -692,7 +692,7 @@ bool mysqld_show_warnings(THD *thd, ulon
                                  Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
     DBUG_RETURN(TRUE);
 
-  MYSQL_ERROR *err;
+  const MYSQL_ERROR *err;
   SELECT_LEX *sel= &thd->lex->select_lex;
   SELECT_LEX_UNIT *unit= &thd->lex->unit;
   ulonglong idx= 0;
@@ -700,7 +700,7 @@ bool mysqld_show_warnings(THD *thd, ulon
 
   unit->set_limit(sel);
 
-  List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
+  Warning_info::Const_iterator it= thd->get_stmt_wi()->iterator();
   while ((err= it++))
   {
     /* Skip levels that the user is not interested in */

=== modified file 'sql/sql_error.h'
--- a/sql/sql_error.h	2011-06-10 07:49:17 +0000
+++ b/sql/sql_error.h	2011-06-15 13:13:06 +0000
@@ -19,6 +19,7 @@
 #include "sql_list.h" /* Sql_alloc, MEM_ROOT */
 #include "m_string.h" /* LEX_STRING */
 #include "sql_string.h"                        /* String */
+#include "sql_plist.h" /* I_P_List */
 #include "mysql_com.h" /* MYSQL_ERRMSG_SIZE */
 
 class THD;
@@ -200,6 +201,24 @@ private:
   /** Severity (error, warning, note) of this condition. */
   MYSQL_ERROR::enum_warning_level m_level;
 
+
+  /** Pointers for participating in the list of conditions. */
+  MYSQL_ERROR *next_in_wi;
+  MYSQL_ERROR **prev_in_wi;
+
+  /** Type that provides access to the list pointers. */
+  typedef I_P_List_adapter<MYSQL_ERROR,
+                           &MYSQL_ERROR::next_in_wi,
+                           &MYSQL_ERROR::prev_in_wi>
+          Adapter;
+
+  /** The type of the counted and doubly linked list of conditions. */
+  typedef I_P_List<MYSQL_ERROR,
+                   Adapter,
+                   I_P_List_counter,
+                   I_P_List_fast_push_back<MYSQL_ERROR> >
+          List;
+
   /** Memory root to use to hold condition item values. */
   MEM_ROOT *m_mem_root;
 };
@@ -216,7 +235,7 @@ class Warning_info
   MEM_ROOT           m_warn_root;
 
   /** List of warnings of all severities (levels). */
-  List <MYSQL_ERROR> m_warn_list;
+  MYSQL_ERROR::List  m_warn_list;
 
   /** A break down of the number of warnings per severity (level). */
   uint	             m_warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_END];
@@ -249,6 +268,15 @@ public:
   Warning_info(ulonglong warn_id_arg, bool allow_unlimited_warnings);
   ~Warning_info();
 
+  /** Type of the warning list. */
+  typedef MYSQL_ERROR::List List;
+
+  /** Iterator used to iterate through the warning list. */
+  typedef List::Iterator Iterator;
+
+  /** Const iterator used to iterate through the warning list. */
+  typedef List::Const_Iterator Const_iterator;
+
   /**
     Reset the warning information. Clear all warnings,
     the number of warnings, reset current row counter
@@ -273,17 +301,17 @@ public:
 
   void append_warning_info(THD *thd, Warning_info *source)
   {
-    append_warnings(thd, & source->warn_list());
+    append_warnings(thd, & source->m_warn_list);
   }
 
   /**
     Concatenate the list of warnings.
     It's considered tolerable to lose a warning.
   */
-  void append_warnings(THD *thd, List<MYSQL_ERROR> *src)
+  void append_warnings(THD *thd, List *src)
   {
     MYSQL_ERROR *err;
-    List_iterator_fast<MYSQL_ERROR> it(*src);
+    Iterator it(*src);
     /*
       Don't use ::push_warning() to avoid invocation of condition
       handlers or escalation of warnings to errors.
@@ -311,7 +339,7 @@ public:
   ulong warn_count() const
   {
     /*
-      This may be higher than warn_list.elements if we have
+      This may be higher than warn_list.elements() if we have
       had more warnings than thd->variables.max_error_count.
     */
     return (m_warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] +
@@ -320,10 +348,9 @@ public:
   }
 
   /**
-    This is for iteration purposes. We return a non-constant reference
-    since List doesn't have constant iterators.
+    Returns a const iterator pointing to the beginning of the warning list.
   */
-  List<MYSQL_ERROR> &warn_list() { return m_warn_list; }
+  Const_iterator iterator() const { return m_warn_list; }
 
   /**
     The number of errors, or number of rows returned by SHOW ERRORS,
@@ -338,7 +365,7 @@ public:
   ulonglong warn_id() const { return m_warn_id; }
 
   /** Do we have any errors and warnings that we can *show*? */
-  bool is_empty() const { return m_warn_list.elements == 0; }
+  bool is_empty() const { return m_warn_list.is_empty(); }
 
   /** Increment the current row counter to point at the next row. */
   void inc_current_row_for_warning() { m_current_row_for_warning++; }

=== modified file 'sql/sql_plist.h'
--- a/sql/sql_plist.h	2011-04-13 11:31:44 +0000
+++ b/sql/sql_plist.h	2011-06-15 13:13:06 +0000
@@ -1,6 +1,6 @@
 #ifndef SQL_PLIST_H
 #define SQL_PLIST_H
-/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
 
 #include <my_global.h>
 
-template <typename T, typename B, typename C, typename I>
+template <typename T, typename L>
 class I_P_List_iterator;
 class I_P_List_null_counter;
 template <typename T> class I_P_List_no_push_back;
@@ -142,10 +142,14 @@ public:
       I::set_last(&rhs.m_first);
     C::swap(rhs);
   }
+  typedef B Adapter;
+  typedef I_P_List<T, B, C, I> Base;
+  typedef I_P_List_iterator<T, Base> Iterator;
+  typedef I_P_List_iterator<const T, Base> Const_Iterator;
 #ifndef _lint
-  friend class I_P_List_iterator<T, B, C, I>;
+  friend class I_P_List_iterator<T, Base>;
+  friend class I_P_List_iterator<const T, Base>;
 #endif
-  typedef I_P_List_iterator<T, B, C, I> Iterator;
 };
 
 
@@ -153,19 +157,17 @@ public:
    Iterator for I_P_List.
 */
 
-template <typename T, typename B,
-          typename C = I_P_List_null_counter,
-          typename I = I_P_List_no_push_back<T> >
+template <typename T, typename L>
 class I_P_List_iterator
 {
-  const I_P_List<T, B, C, I> *list;
+  const L *list;
   T *current;
 public:
-  I_P_List_iterator(const I_P_List<T, B, C, I> &a)
+  I_P_List_iterator(const L &a)
     : list(&a), current(a.m_first) {}
-  I_P_List_iterator(const I_P_List<T, B, C, I> &a, T* current_arg)
+  I_P_List_iterator(const L &a, T* current_arg)
     : list(&a), current(current_arg) {}
-  inline void init(const I_P_List<T, B, C, I> &a)
+  inline void init(const L &a)
   {
     list= &a;
     current= a.m_first;
@@ -174,12 +176,12 @@ public:
   {
     T *result= current;
     if (result)
-      current= *B::next_ptr(current);
+      current= *L::Adapter::next_ptr(current);
     return result;
   }
   inline T* operator++()
   {
-    current= *B::next_ptr(current);
+    current= *L::Adapter::next_ptr(current);
     return current;
   }
   inline void rewind()
@@ -198,7 +200,7 @@ template <typename T, T* T::*next, T** T
 struct I_P_List_adapter
 {
   static inline T **next_ptr(T *el) { return &(el->*next); }
-
+  static inline const T* const* next_ptr(const T *el) { return &(el->*next); }
   static inline T ***prev_ptr(T *el) { return &(el->*prev); }
 };
 

=== modified file 'sql/sql_prepare.h'
--- a/sql/sql_prepare.h	2011-06-10 07:49:17 +0000
+++ b/sql/sql_prepare.h	2011-06-15 13:13:06 +0000
@@ -254,15 +254,6 @@ public:
   {
     return m_diagnostics_area.get_warning_info()->warn_count();
   }
-  /**
-    Get the server warnings as a result set.
-    The result set has fixed metadata:
-    The first column is the level.
-    The second is a numeric code.
-    The third is warning text.
-  */
-  List<MYSQL_ERROR> *get_warn_list()
-  { return &m_diagnostics_area.get_warning_info()->warn_list(); }
 
   /**
     The following members are only valid if execute_direct()

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2011-06-10 08:33:15 +0000
+++ b/sql/sql_show.cc	2011-06-15 13:13:06 +0000
@@ -6830,9 +6830,8 @@ static bool do_fill_table(THD *thd,
   // Filter out warnings with WARN_LEVEL_ERROR level, because they
   // correspond to the errors which were filtered out in fill_table().
 
-
-  List_iterator_fast<MYSQL_ERROR> it(wi_tmp.warn_list());
-  MYSQL_ERROR *err;
+  Warning_info::Const_iterator it= wi_tmp.iterator();
+  const MYSQL_ERROR *err;
 
   while ((err= it++))
   {

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2011-06-10 16:57:01 +0000
+++ b/sql/sql_table.cc	2011-06-15 13:13:06 +0000
@@ -2942,8 +2942,8 @@ const CHARSET_INFO* get_sql_field_charse
 
 bool check_duplicate_warning(THD *thd, char *msg, ulong length)
 {
-  List_iterator_fast<MYSQL_ERROR> it(thd->get_stmt_wi()->warn_list());
-  MYSQL_ERROR *err;
+  Warning_info::Const_iterator it= thd->get_stmt_wi()->iterator();
+  const MYSQL_ERROR *err;
   while ((err= it++))
   {
     if (strncmp(msg, err->get_message_text(), length) == 0)

=== modified file 'sql/sql_test.cc'
--- a/sql/sql_test.cc	2011-05-18 08:29:46 +0000
+++ b/sql/sql_test.cc	2011-06-15 13:13:06 +0000
@@ -91,7 +91,7 @@ static void print_cached_tables(void)
   {
     share= (TABLE_SHARE*) my_hash_element(&table_def_cache, idx);
 
-    I_P_List_iterator<TABLE, TABLE_share> it(share->used_tables);
+    TABLE_SHARE::TABLE_list::Iterator it(share->used_tables);
     while ((entry= it++))
     {
       printf("%-14.14s %-32s%6ld%8ld%6d  %s\n",

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2011-06-09 08:58:41 +0000
+++ b/sql/table.cc	2011-06-15 13:13:06 +0000
@@ -3215,7 +3215,7 @@ bool TABLE_SHARE::visit_subgraph(Wait_fo
   if (gvisitor->m_lock_open_count++ == 0)
     mysql_mutex_lock(&LOCK_open);
 
-  I_P_List_iterator <TABLE, TABLE_share> tables_it(used_tables);
+  TABLE_SHARE::TABLE_list::Iterator tables_it(used_tables);
 
   /*
     In case of multiple searches running in parallel, avoid going

=== modified file 'sql/table.h'
--- a/sql/table.h	2011-05-26 15:20:09 +0000
+++ b/sql/table.h	2011-06-15 13:13:06 +0000
@@ -600,8 +600,9 @@ struct TABLE_SHARE
     Doubly-linked (back-linked) lists of used and unused TABLE objects
     for this share.
   */
-  I_P_List <TABLE, TABLE_share> used_tables;
-  I_P_List <TABLE, TABLE_share> free_tables;
+  typedef I_P_List <TABLE, TABLE_share> TABLE_list;
+  TABLE_list used_tables;
+  TABLE_list free_tables;
 
   /* The following is copied to each TABLE on OPEN */
   Field **field;


Attachment: [text/bzr-bundle] bzr/davi.arnaut@oracle.com-20110615131306-bt1ij3d74zu4azzh.bundle
Thread
bzr commit into mysql-trunk branch (davi:3205) Davi Arnaut16 Jun