[glibmm] Avoid shadowed variables.



commit 254f5b93e08e45cd32ccdbb0f4a31c433ece9d08
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Jul 15 11:48:55 2015 +0200

    Avoid shadowed variables.
    
    Because this generally invites programming errors, though I am
    less concerned about shadowing of method names by parameter or
    variable names, which requires some tedious parameter renaming.
    
    In MatchInfo::set_gobject() the confusion between take_ownership and
    this.take_ownership does seem to have caused a programming error,
    hopefully now corrected.

 gio/src/dbussubtreevtable.ccg               |   10 +++++-----
 gio/src/fileinfo.hg                         |    4 ++--
 glib/glibmm/error.cc                        |   12 ++++++------
 glib/glibmm/error.h                         |    6 +++---
 glib/glibmm/streamiochannel.cc              |   24 ++++++++++++------------
 glib/src/datetime.hg                        |    2 +-
 glib/src/iochannel.hg                       |    4 ++--
 glib/src/regex.ccg                          |   10 +++++-----
 glib/src/regex.hg                           |    6 +++---
 tests/giomm_tls_client/main.cc              |    2 --
 tests/glibmm_btree/main.cc                  |    1 -
 tests/glibmm_valuearray/main.cc             |   18 +++++++++---------
 tools/extra_defs_gen/generate_extra_defs.cc |    6 +++---
 13 files changed, 51 insertions(+), 54 deletions(-)
---
diff --git a/gio/src/dbussubtreevtable.ccg b/gio/src/dbussubtreevtable.ccg
index a248101..5e726cc 100644
--- a/gio/src/dbussubtreevtable.ccg
+++ b/gio/src/dbussubtreevtable.ccg
@@ -105,21 +105,21 @@ static const GDBusInterfaceVTable* DBusSubtreeVTable_Dispatch_giomm_callback(
   const char* interface_name, const char* node, void** out_user_data,
   void* user_data)
 {
-  Gio::DBus::SubtreeVTable* vtable =
+  Gio::DBus::SubtreeVTable* vtable_subtree =
     static_cast<Gio::DBus::SubtreeVTable*>(user_data);
 
   Gio::DBus::SubtreeVTable::SlotSubtreeDispatch* the_slot =
-    vtable->get_slot_dispatch();
+    vtable_subtree->get_slot_dispatch();
 
   try
   {
-    const Gio::DBus::InterfaceVTable* vtable =
+    const Gio::DBus::InterfaceVTable* vtable_iface =
       (*the_slot)(Glib::wrap(connection, true), sender, object_path,
       interface_name, (node ? node : ""));
 
-    *out_user_data = const_cast<Gio::DBus::InterfaceVTable*>(vtable);
+    *out_user_data = const_cast<Gio::DBus::InterfaceVTable*>(vtable_iface);
 
-    return vtable->gobj();
+    return vtable_iface->gobj();
   }
   catch(...)
   {
diff --git a/gio/src/fileinfo.hg b/gio/src/fileinfo.hg
index d10eb68..b14a601 100644
--- a/gio/src/fileinfo.hg
+++ b/gio/src/fileinfo.hg
@@ -200,8 +200,8 @@ public:
   // helper setters
 
   _WRAP_METHOD(void set_file_type(FileType type), g_file_info_set_file_type)
-  _WRAP_METHOD(void set_is_hidden(bool is_hidden = true), g_file_info_set_is_hidden)
-  _WRAP_METHOD(void set_is_symlink(bool is_symlink = true), g_file_info_set_is_symlink)
+  _WRAP_METHOD(void set_is_hidden(bool hidden = true), g_file_info_set_is_hidden)
+  _WRAP_METHOD(void set_is_symlink(bool symlink = true), g_file_info_set_is_symlink)
   _WRAP_METHOD(void set_name(const std::string& name), g_file_info_set_name)
 
   //TODO: This should take a ustring instead. See https://bugzilla.gnome.org/show_bug.cgi?id=615950#c4
diff --git a/glib/glibmm/error.cc b/glib/glibmm/error.cc
index 5784414..d55cb43 100644
--- a/glib/glibmm/error.cc
+++ b/glib/glibmm/error.cc
@@ -42,9 +42,9 @@ Error::Error()
   gobject_ (0)
 {}
 
-Error::Error(GQuark domain, int code, const Glib::ustring& message)
+Error::Error(GQuark error_domain, int error_code, const Glib::ustring& message)
 :
-  gobject_ (g_error_new_literal(domain, code, message.c_str()))
+  gobject_ (g_error_new_literal(error_domain, error_code, message.c_str()))
 {}
 
 Error::Error(GError* gobject, bool take_copy)
@@ -103,9 +103,9 @@ Glib::ustring Error::what() const
   return gobject_->message;
 }
 
-bool Error::matches(GQuark domain, int code) const
+bool Error::matches(GQuark error_domain, int error_code) const
 {
-  return g_error_matches(gobject_, domain, code);
+  return g_error_matches(gobject_, error_domain, error_code);
 }
 
 GError* Error::gobj()
@@ -146,11 +146,11 @@ void Error::register_cleanup()
 }
 
 // static
-void Error::register_domain(GQuark domain, Error::ThrowFunc throw_func)
+void Error::register_domain(GQuark error_domain, Error::ThrowFunc throw_func)
 {
   g_assert(throw_func_table != 0);
 
-  (*throw_func_table)[domain] = throw_func;
+  (*throw_func_table)[error_domain] = throw_func;
 }
 
 // static, noreturn
diff --git a/glib/glibmm/error.h b/glib/glibmm/error.h
index b68df85..d2701da 100644
--- a/glib/glibmm/error.h
+++ b/glib/glibmm/error.h
@@ -32,7 +32,7 @@ class Error : public Glib::Exception
 {
 public:
   Error();
-  Error(GQuark domain, int code, const Glib::ustring& message);
+  Error(GQuark error_domain, int error_code, const Glib::ustring& message);
   explicit Error(GError* gobject, bool take_copy = false);
 
   Error(const Error& other);
@@ -44,7 +44,7 @@ public:
   int code() const;
   virtual Glib::ustring what() const;
 
-  bool matches(GQuark domain, int code) const;
+  bool matches(GQuark error_domain, int error_code) const;
 
   GError* gobj();
   const GError* gobj() const;
@@ -57,7 +57,7 @@ public:
 
   static void register_init();
   static void register_cleanup();
-  static void register_domain(GQuark domain, ThrowFunc throw_func);
+  static void register_domain(GQuark error_domain, ThrowFunc throw_func);
 
   static void throw_exception(GError* gobject) G_GNUC_NORETURN;
 
diff --git a/glib/glibmm/streamiochannel.cc b/glib/glibmm/streamiochannel.cc
index e5201db..8a1b10a 100644
--- a/glib/glibmm/streamiochannel.cc
+++ b/glib/glibmm/streamiochannel.cc
@@ -133,23 +133,23 @@ IOStatus StreamIOChannel::close_vfunc()
 {
   bool failed = false;
 
-  if(std::fstream *const stream = dynamic_cast<std::fstream*>(stream_in_))
+  if(std::fstream *const fstream = dynamic_cast<std::fstream*>(stream_in_))
   {
-    stream->clear();
-    stream->close();
-    failed = stream->fail();
+    fstream->clear();
+    fstream->close();
+    failed = fstream->fail();
   }
-  else if(std::ifstream *const stream = dynamic_cast<std::ifstream*>(stream_in_))
+  else if(std::ifstream *const ifstream = dynamic_cast<std::ifstream*>(stream_in_))
   {
-    stream->clear();
-    stream->close();
-    failed = stream->fail();
+    ifstream->clear();
+    ifstream->close();
+    failed = ifstream->fail();
   }
-  else if(std::ofstream *const stream = dynamic_cast<std::ofstream*>(stream_out_))
+  else if(std::ofstream *const ofstream = dynamic_cast<std::ofstream*>(stream_out_))
   {
-    stream->clear();
-    stream->close();
-    failed = stream->fail();
+    ofstream->clear();
+    ofstream->close();
+    failed = ofstream->fail();
   }
   else
   {
diff --git a/glib/src/datetime.hg b/glib/src/datetime.hg
index a9c4221..82bcd56 100644
--- a/glib/src/datetime.hg
+++ b/glib/src/datetime.hg
@@ -149,7 +149,7 @@ public:
   _WRAP_METHOD(DateTime to_timezone(const TimeZone& tz) const, g_date_time_to_timezone)
   _WRAP_METHOD(DateTime to_local() const, g_date_time_to_local)
   _WRAP_METHOD(DateTime to_utc() const, g_date_time_to_utc)
-  _WRAP_METHOD(Glib::ustring format(const Glib::ustring& format) const, g_date_time_format)
+  _WRAP_METHOD(Glib::ustring format(const Glib::ustring& format_str) const, g_date_time_format)
 };
 
 } // namespace Glib
diff --git a/glib/src/iochannel.hg b/glib/src/iochannel.hg
index 3c3d530..93bf749 100644
--- a/glib/src/iochannel.hg
+++ b/glib/src/iochannel.hg
@@ -269,11 +269,11 @@ public:
    * Any pending data to be written will be flushed if @a flush is <tt>true</tt>.
    * The channel will not be freed until the last reference is dropped.
    * Accessing the channel after closing it is considered an error.
-   * @param flush Whether to flush() pending data before closing the channel.
+   * @param flush_pending Whether to flush() pending data before closing the channel.
    * @return The status of the operation.
    * @throw Glib::IOChannelError
    */
-  _WRAP_METHOD(IOStatus close(bool flush = true), g_io_channel_shutdown, errthrow)
+  _WRAP_METHOD(IOStatus close(bool flush_pending = true), g_io_channel_shutdown, errthrow)
 
   /** Get the IOChannel internal buffer size.
    * @return The buffer size.
diff --git a/glib/src/regex.ccg b/glib/src/regex.ccg
index af91d4a..ba5b393 100644
--- a/glib/src/regex.ccg
+++ b/glib/src/regex.ccg
@@ -242,19 +242,19 @@ MatchInfo::MatchInfo()
 {
 }
 
-MatchInfo::MatchInfo(GMatchInfo* castitem, bool take_ownership)
+MatchInfo::MatchInfo(GMatchInfo* castitem, bool take_the_ownership)
 : gobject_(castitem),
-  take_ownership(take_ownership)
+  take_ownership(take_the_ownership)
 {
 }
 
-void MatchInfo::set_gobject(GMatchInfo* castitem, bool take_ownership)
+void MatchInfo::set_gobject(GMatchInfo* castitem, bool take_the_ownership)
 {
-  if(gobject_ && take_ownership)
+  if(gobject_ && this->take_ownership)
     g_match_info_free(gobject_);
 
   gobject_ = castitem;
-  this->take_ownership = take_ownership;
+  this->take_ownership = take_the_ownership;
 }
 
 MatchInfo::~MatchInfo()
diff --git a/glib/src/regex.hg b/glib/src/regex.hg
index 1b0d5e8..f35af4a 100644
--- a/glib/src/regex.hg
+++ b/glib/src/regex.hg
@@ -222,10 +222,10 @@ public:
 
   /** C object constructor.
    * @param castitem The C object.
-   * @param take_ownership Whether to destroy the C object with the wrapper or
+   * @param take_the_ownership Whether to destroy the C object with the wrapper or
    * not.
    */
-  explicit MatchInfo(GMatchInfo* castitem, bool take_ownership = true);
+  explicit MatchInfo(GMatchInfo* castitem, bool take_the_ownership = true); //TODO: Rename to take_ownership 
when we can rename the member variable.
 
   /// Destructor.
   virtual ~MatchInfo();
@@ -272,7 +272,7 @@ public:
 
 protected:
   GMatchInfo* gobject_;      // The C object.
-  bool take_ownership;       // Bool signaling ownership.
+  bool take_ownership;       // Bool signaling ownership. //TODO: Give this a _ suffix when we can break API.
 
 protected:
   // So that Glib::Regex::match() can set the C object.
diff --git a/tests/giomm_tls_client/main.cc b/tests/giomm_tls_client/main.cc
index a14fe9f..a8099b7 100644
--- a/tests/giomm_tls_client/main.cc
+++ b/tests/giomm_tls_client/main.cc
@@ -120,8 +120,6 @@ int main(int, char**)
     address->get_address()->to_string() << ":" << address->get_port() <<
     "." << std::endl;
 
-  Glib::RefPtr<Gio::TlsClientConnection> tls_connection;
-
   try
   {
     Glib::RefPtr<Gio::TlsClientConnection> tls_connection =
diff --git a/tests/glibmm_btree/main.cc b/tests/glibmm_btree/main.cc
index c678c37..8ee1114 100644
--- a/tests/glibmm_btree/main.cc
+++ b/tests/glibmm_btree/main.cc
@@ -74,7 +74,6 @@ my_p_key_compare(const type_p_key_value& key_a, const type_p_key_value& key_b)
 int
 main()
 {
-  type_key_value::const_iterator i;
   Glib::RefPtr< Glib::BalancedTree<type_key_value, type_key_value> > tree = 
Glib::BalancedTree<type_key_value, type_key_value>::create();
 
   for (type_key_value::size_type i = 0; i < str.size(); ++i)
diff --git a/tests/glibmm_valuearray/main.cc b/tests/glibmm_valuearray/main.cc
index 2139d43..62b19ed 100644
--- a/tests/glibmm_valuearray/main.cc
+++ b/tests/glibmm_valuearray/main.cc
@@ -41,23 +41,23 @@ int on_compare(const Glib::ValueBase& v1, const Glib::ValueBase& v2)
 
 int main(int, char**)
 {
-  const int VALUES = 10;
+  const int VALUES_COUNT = 10;
 
   Glib::init();
 
-  Glib::Value<int> value[VALUES];
+  Glib::Value<int> values[VALUES_COUNT];
   Glib::ValueArray array;
 
-  for(int i = 0; i < VALUES; i++)
+  for(int i = 0; i < VALUES_COUNT; i++)
   {
-    value[i].init(Glib::Value<int>::value_type());
-    value[i].set(i + 1); //  (i + 1) ==> Set to natural counting numbers.
-    array.prepend(value[i]);
+    values[i].init(Glib::Value<int>::value_type());
+    values[i].set(i + 1); //  (i + 1) ==> Set to natural counting numbers.
+    array.prepend(values[i]);
   }
 
   ostr << "Array members before sorting:" << std::endl;
 
-  for(int i = 0; i < VALUES; i++)
+  for(int i = 0; i < VALUES_COUNT; i++)
   {
     Glib::ValueBase value;
 
@@ -75,12 +75,12 @@ int main(int, char**)
   ostr << std::endl; // End of line for list of array elements.
 
   // Sort array and remove last element:
-  array.sort(sigc::ptr_fun(&on_compare)).remove(VALUES - 1);
+  array.sort(sigc::ptr_fun(&on_compare)).remove(VALUES_COUNT - 1);
 
   ostr << "Array members after sorting without last element:" <<
     std::endl;
 
-  for(int i = 0; i < VALUES - 1; i++)
+  for(int i = 0; i < VALUES_COUNT - 1; i++)
   {
     Glib::ValueBase value;
 
diff --git a/tools/extra_defs_gen/generate_extra_defs.cc b/tools/extra_defs_gen/generate_extra_defs.cc
index f209348..8477f05 100644
--- a/tools/extra_defs_gen/generate_extra_defs.cc
+++ b/tools/extra_defs_gen/generate_extra_defs.cc
@@ -220,13 +220,13 @@ std::string get_signals(GType gtype, GTypeIsAPointerFunc is_a_pointer_func)
       {
         strResult += "  (parameters\n";
 
-        for(unsigned i = 0; i < signalQuery.n_params; i++)
+        for(unsigned j = 0; j < signalQuery.n_params; j++)
         {
-          GType typeParamMangled = pParameters[i];
+          GType typeParamMangled = pParameters[j];
 
           //Parameter name:
           //We can't get the real parameter name from the GObject system. It's not registered with 
g_signal_new().
-          gchar* pchNum = g_strdup_printf("%d", i);
+          gchar* pchNum = g_strdup_printf("%d", j);
           std::string strParamName = "p" + std::string(pchNum);
           g_free(pchNum);
           pchNum = 0;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]