Fix an errant g_object_unref
[platform/core/uifw/at-spi2-atk.git] / dbind / dbind-any.c
index 83a87ba..30d8add 100644 (file)
@@ -8,15 +8,13 @@
 
 #undef DEBUG
 
-/* Align a value upward to a boundary, expressed as a number of bytes.
-   E.g. align to an 8-byte boundary with argument of 8.  */
-
-/*
+/*  Align a value upward to a boundary, expressed as a number of bytes.
+ *  E.g. align to an 8-byte boundary with argument of 8.
+ *
  *   (this + boundary - 1)
  *          &
  *    ~(boundary - 1)
  */
-
 #define ALIGN_VALUE(this, boundary) \
   (( ((gulong)(this)) + (((gulong)(boundary)) -1)) & (~(((gulong)(boundary))-1)))
 
@@ -49,9 +47,9 @@ warn_braces ()
 /*---------------------------------------------------------------------------*/
 
 static unsigned int
-dbind_find_c_alignment_r (char **type)
+dbind_find_c_alignment_r (const char **type)
 {
-        unsigned int retval = 1;
+    unsigned int retval = 1;
 
     char t = **type;
     (*type)++;
@@ -82,7 +80,7 @@ dbind_find_c_alignment_r (char **type)
     case DBUS_TYPE_SIGNATURE:
     case DBUS_TYPE_ARRAY:
         return DBIND_ALIGNOF_DBIND_POINTER;
-        case DBUS_STRUCT_BEGIN_CHAR:
+    case DBUS_STRUCT_BEGIN_CHAR:
 #if DBIND_ALIGNOF_DBIND_STRUCT > 1
                 retval = MAX (retval, DBIND_ALIGNOF_DBIND_STRUCT);
 #endif
@@ -91,7 +89,7 @@ dbind_find_c_alignment_r (char **type)
                         retval = MAX (retval, elem_align);
         }
         (*type)++;
-                return retval;
+        return retval;
     case DBUS_TYPE_STRUCT:
     case DBUS_TYPE_DICT_ENTRY:
         warn_braces ();
@@ -99,34 +97,36 @@ dbind_find_c_alignment_r (char **type)
     case '\0':
         g_assert_not_reached();
         break;
-        default:
+    default:
                 return 1;
-        }
+  }
 }
 
 /*---------------------------------------------------------------------------*/
 
 /* gather immediate allocation information for this type */
 static size_t
-dbind_gather_alloc_info_r (char **type)
+dbind_gather_alloc_info_r (const char **type)
 {
-    char t = **type;
-    (*type)++;
-    if (t == DBUS_TYPE_ARRAY) {
-        switch (**type) {
-            case DBUS_STRUCT_BEGIN_CHAR:
-                while (**type != DBUS_STRUCT_END_CHAR && **type != '\0') (*type)++;
-                if (**type != '\0') (*type)++;
-                break;
-            case '\0':
-                break;
-            default:
-                (*type)++;
-                break;
-            }
+  char t = **type;
+  (*type)++;
+  if (t == DBUS_TYPE_ARRAY)
+    {
+      switch (**type)
+        {
+          case DBUS_STRUCT_BEGIN_CHAR:
+              while (**type != DBUS_STRUCT_END_CHAR && **type != '\0') (*type)++;
+              if (**type != '\0') (*type)++;
+              break;
+          case '\0':
+              break;
+          default:
+              (*type)++;
+              break;
         }
+    }
 
-        switch (t) {
+  switch (t) {
     case DBUS_TYPE_BYTE:
         return sizeof (char);
     case DBUS_TYPE_BOOLEAN:
@@ -167,24 +167,22 @@ dbind_gather_alloc_info_r (char **type)
     case DBUS_TYPE_STRUCT:
     case DBUS_TYPE_DICT_ENTRY:
         warn_braces ();
-        default:
-                return 0;
-        }
+    default:
+        return 0;
+  }
 }
 
 static size_t
-dbind_gather_alloc_info (char *type)
+dbind_gather_alloc_info (const char *type)
 {
-    return dbind_gather_alloc_info_r (&type);
+  return dbind_gather_alloc_info_r (&type);
 }
 
 /*---------------------------------------------------------------------------*/
 
 static void
-dbind_any_free_r (char **type, void **data)
+dbind_any_free_r (const char **type, void **data)
 {
-    size_t len;
-
 #ifdef DEBUG
     fprintf (stderr, "any free '%c' to %p\n", **type, *data);
 #endif
@@ -208,7 +206,7 @@ dbind_any_free_r (char **type, void **data)
         int i;
         GArray *vals = **(void ***)data;
         size_t elem_size, elem_align;
-        char *saved_child_type, *child_type_string;
+        const char *saved_child_type;
 
         (*type)++;
         saved_child_type = *type;
@@ -234,7 +232,7 @@ dbind_any_free_r (char **type, void **data)
 
         offset = 0 ;
         while (**type != DBUS_STRUCT_END_CHAR) {
-            char *subt = *type;
+            const char *subt = *type;
                         offset = ALIGN_VALUE (offset, dbind_find_c_alignment (*type));
                         *data = PTR_PLUS (data0, offset);
             dbind_any_free_r (type, data);
@@ -260,7 +258,7 @@ dbind_any_free_r (char **type, void **data)
 
 void
 dbind_any_marshal (DBusMessageIter *iter,
-                   char           **type,
+                   const char           **type,
                    void           **data)
 {
     size_t len;
@@ -284,7 +282,8 @@ dbind_any_marshal (DBusMessageIter *iter,
         GArray *vals = **(void ***)data;
         size_t elem_size, elem_align;
         DBusMessageIter sub;
-        char *saved_child_type, *child_type_string;
+        const char *saved_child_type;
+        char *child_type_string;
 
         (*type)++;
         saved_child_type = *type;
@@ -321,7 +320,7 @@ dbind_any_marshal (DBusMessageIter *iter,
 
         offset = 0 ;
         while (**type != DBUS_STRUCT_END_CHAR) {
-            char *subt = *type;
+            const char *subt = *type;
                         offset = ALIGN_VALUE (offset, dbind_find_c_alignment (*type));
                         *data = PTR_PLUS (data0, offset);
             dbind_any_marshal (&sub, type, data);
@@ -349,10 +348,17 @@ dbind_any_marshal (DBusMessageIter *iter,
 
 void
 dbind_any_marshal_va (DBusMessageIter *iter,
-                      char           **arg_types,
+                      const char           **arg_types,
                       va_list          args)
 {
-    char *p = *arg_types;
+    const char *p = *arg_types;
+
+    /* Guard against null arg types 
+       Fix for - http://bugs.freedesktop.org/show_bug.cgi?id=23027
+     */
+    if (p == NULL)
+        p = "";
+
     {
         /* special case base-types since we need to walk the stack worse-luck */
         for (;*p != '\0' && *p != '=';) {
@@ -414,7 +420,7 @@ dbind_any_marshal_va (DBusMessageIter *iter,
 
 void
 dbind_any_demarshal (DBusMessageIter *iter,
-                     char           **type,
+                     const char           **type,
                      void           **data)
 {
     size_t len;
@@ -446,7 +452,7 @@ dbind_any_demarshal (DBusMessageIter *iter,
         GArray *vals;
         DBusMessageIter child;
         size_t elem_size, elem_align;
-        char *stored_child_type;
+        const char *stored_child_type;
         int i;
 
         (*type)++;
@@ -462,7 +468,7 @@ dbind_any_demarshal (DBusMessageIter *iter,
         dbus_message_iter_recurse (iter, &child);
         while (dbus_message_iter_get_arg_type (&child) != DBUS_TYPE_INVALID) {
             void *ptr;
-            char *subt = stored_child_type;
+            const char *subt = stored_child_type;
             g_array_set_size (vals, i + 1);
             ptr = vals->data + elem_size * i;
             ptr = ALIGN_ADDRESS (ptr, elem_align);
@@ -483,7 +489,7 @@ dbind_any_demarshal (DBusMessageIter *iter,
         dbus_message_iter_recurse (iter, &child);
 
         while (**type != DBUS_STRUCT_END_CHAR) {
-            char *subt = *type;
+            const char *subt = *type;
                         offset = ALIGN_VALUE (offset, dbind_find_c_alignment (*type));
                         *data = PTR_PLUS (data0, offset);
             dbind_any_demarshal (&child, type, data);
@@ -510,10 +516,10 @@ dbind_any_demarshal (DBusMessageIter *iter,
 
 void
 dbind_any_demarshal_va (DBusMessageIter *iter,
-                        char           **arg_types,
+                        const char           **arg_types,
                         va_list          args)
 {
-    char *p = *arg_types;
+    const char *p = *arg_types;
     for (;*p != '\0';) {
         void *arg = va_arg (args, void *);
         dbind_any_demarshal (iter, &p, &arg);
@@ -524,7 +530,7 @@ dbind_any_demarshal_va (DBusMessageIter *iter,
 
 /* nice deep free ... */
 void
-dbind_any_free (char *type,
+dbind_any_free (const char *type,
                 void *ptr)
 {
     dbind_any_free_r (&type, &ptr);
@@ -532,7 +538,7 @@ dbind_any_free (char *type,
 
 /* should this be the default normalization ? */
 void
-dbind_any_free_ptr (char *type, void *ptr)
+dbind_any_free_ptr (const char *type, void *ptr)
 {
     dbind_any_free (type, &ptr);
 }
@@ -540,7 +546,7 @@ dbind_any_free_ptr (char *type, void *ptr)
 /*---------------------------------------------------------------------------*/
 
 unsigned int
-dbind_find_c_alignment (char *type)
+dbind_find_c_alignment (const char *type)
 {
     return dbind_find_c_alignment_r (&type);
 }