[glibmm] Use std::memset() instead of GLIBMM_INITIALIZE_STRUCT.



commit a38f51a9c3833ce581610e368eee1dc360d4de55
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Wed Jul 10 08:37:53 2013 +0200

    Use std::memset() instead of GLIBMM_INITIALIZE_STRUCT.
    
    * glib/glibmm/utility.h: Add a comment that GLIBMM_INITIALIZE_STRUCT is
    deprecated. It generates compiler warnings when __STRICT_ANSI__ is defined.
    * glib/glibmm/value.cc:
    * glib/src/optiongroup.ccg:
    * tools/m4/class_boxedtype_static.m4: Replace GLIBMM_INITIALIZE_STRUCT
    by std::memset().

 glib/glibmm/utility.h              |    4 ++++
 glib/glibmm/value.cc               |    6 +++---
 glib/src/optiongroup.ccg           |    3 ++-
 tools/m4/class_boxedtype_static.m4 |    6 ++++--
 4 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/glib/glibmm/utility.h b/glib/glibmm/utility.h
index 723418d..f5aa2a8 100644
--- a/glib/glibmm/utility.h
+++ b/glib/glibmm/utility.h
@@ -29,6 +29,10 @@
  * i.e. when using structs as class member data.  For convenience, the macro
  * GLIBMM_INITIALIZE_STRUCT(Var, Type) is provided.  It even avoids creating
  * a temporary if the compiler is GCC.
+ *
+ * Deprecated: Use e.g. std::memset() instead.
+ * It's not used any more in the code generated by _CLASS_BOXEDTYPE_STATIC.
+ * It generates compiler warnings if __STRICT_ANSI__ is defined.
  */
 #if ((__GNUC__ >= 3) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)) && !defined(__STRICT_ANSI__)
 
diff --git a/glib/glibmm/value.cc b/glib/glibmm/value.cc
index 6a0f87c..811b82d 100644
--- a/glib/glibmm/value.cc
+++ b/glib/glibmm/value.cc
@@ -22,7 +22,7 @@
 #include <glibmm/objectbase.h>
 #include <glibmm/utility.h>
 #include <glibmm/wrap.h>
-
+#include <cstring> // std::memset()
 
 namespace Glib
 {
@@ -31,7 +31,7 @@ namespace Glib
 
 ValueBase::ValueBase()
 {
-  GLIBMM_INITIALIZE_STRUCT(gobject_, GValue);
+  std::memset(&gobject_, 0, sizeof(GValue));
 }
 
 void ValueBase::init(GType type)
@@ -49,7 +49,7 @@ void ValueBase::init(const GValue* value)
 
 ValueBase::ValueBase(const ValueBase& other)
 {
-  GLIBMM_INITIALIZE_STRUCT(gobject_, GValue);
+  std::memset(&gobject_, 0, sizeof(GValue));
 
   g_value_init(&gobject_, G_VALUE_TYPE(&other.gobject_));
   g_value_copy(&other.gobject_, &gobject_);
diff --git a/glib/src/optiongroup.ccg b/glib/src/optiongroup.ccg
index baa1331..d2f81ff 100644
--- a/glib/src/optiongroup.ccg
+++ b/glib/src/optiongroup.ccg
@@ -21,6 +21,7 @@
 #include <glibmm/exceptionhandler.h>
 //#include <glibmm/containers.h>
 #include <glib.h> // g_malloc
+#include <cstring> // std::memset()
 
 namespace Glib
 {
@@ -308,7 +309,7 @@ void OptionGroup::add_entry(const OptionEntry& entry)
   //Create a temporary array, just so we can give the correct thing to g_option_group_add_entries:
   GOptionEntry array[2];
   array[0] = *(entry.gobj()); //Copy contents.
-  GLIBMM_INITIALIZE_STRUCT(array[1], GOptionEntry);
+  std::memset(&array[1], 0, sizeof(GOptionEntry));
 
   g_option_group_add_entries(gobj(), array);
 }
diff --git a/tools/m4/class_boxedtype_static.m4 b/tools/m4/class_boxedtype_static.m4
index ecda942..c265a0e 100644
--- a/tools/m4/class_boxedtype_static.m4
+++ b/tools/m4/class_boxedtype_static.m4
@@ -70,6 +70,8 @@ class Value<__NAMESPACE__::__CPPNAME__> : public Glib::Value_Boxed<__NAMESPACE__
 
 } // namespace Glib
 
+_SECTION(SECTION_CC_INCLUDES)
+#include <cstring> // std::memset`'()
 _SECTION(SECTION_SRC_GENERATED)
 
 ifdef(`__BOOL_NO_WRAP_FUNCTION__',`dnl
@@ -109,7 +111,7 @@ GType __CPPNAME__::get_type()
 ifdef(`__BOOL_CUSTOM_DEFAULT_CTOR__',,`dnl else
 __CPPNAME__::__CPPNAME__`'()
 {
-  GLIBMM_INITIALIZE_STRUCT`'(gobject_, __CNAME__);
+  std::memset`'(&gobject_, 0, sizeof(__CNAME__));
 }
 ')dnl
 
@@ -119,7 +121,7 @@ __CPPNAME__::__CPPNAME__`'(const __CNAME__* gobject)
   if(gobject)
     gobject_ = *gobject;
   else
-    GLIBMM_INITIALIZE_STRUCT`'(gobject_, __CNAME__);
+    std::memset`'(&gobject_, 0, sizeof(__CNAME__));
 }
 ')dnl
 


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