GUnixSocketAddress: fix construct parameter issue
authorRyan Lortie <desrt@desrt.ca>
Tue, 23 Apr 2013 17:38:33 +0000 (13:38 -0400)
committerRyan Lortie <desrt@desrt.ca>
Tue, 23 Apr 2013 18:36:07 +0000 (14:36 -0400)
GUnixSocketAddress has some very strange logic for interpreting its
construct paramters.  This logic behaves differently in these two cases:

  g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
                "abstract", FALSE,
                "address-type", ...,
                NULL);

and

  g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
                "address-type", ...,
                NULL);

even though the default value for "abstract" is already FALSE.

Change the way the code works so that it is not sensitive to people
merely setting a property to its default value.

https://bugzilla.gnome.org/show_bug.cgi?id=698686

gio/gunixsocketaddress.c

index 31615cf..84010e7 100644 (file)
@@ -117,26 +117,15 @@ g_unix_socket_address_set_property (GObject      *object,
       break;
 
     case PROP_ABSTRACT:
-      /* If the caller already set PROP_ADDRESS_TYPE, don't let the
-       * default value of PROP_ABSTRACT overwrite it.
-       */
-      if (address->priv->address_type != G_UNIX_SOCKET_ADDRESS_INVALID)
-       return;
-
+      /* Only set it if it's not the default... */
       if (g_value_get_boolean (value))
-       address->priv->address_type = G_UNIX_SOCKET_ADDRESS_ABSTRACT_PADDED;
-      else
-       address->priv->address_type = G_UNIX_SOCKET_ADDRESS_PATH;
+       address->priv->address_type = G_UNIX_SOCKET_ADDRESS_ABSTRACT_PADDED;
       break;
 
     case PROP_ADDRESS_TYPE:
-      /* If the caller already set PROP_ABSTRACT, don't let the
-       * default value of PROP_ADDRESS_TYPE overwrite it.
-       */
-      if (address->priv->address_type != G_UNIX_SOCKET_ADDRESS_INVALID)
-       return;
-
-      address->priv->address_type = g_value_get_enum (value);
+      /* Only set it if it's not the default... */
+      if (g_value_get_enum (value) != G_UNIX_SOCKET_ADDRESS_PATH)
+        address->priv->address_type = g_value_get_enum (value);
       break;
 
     default:
@@ -322,7 +311,7 @@ g_unix_socket_address_init (GUnixSocketAddress *address)
 
   memset (address->priv->path, 0, sizeof (address->priv->path));
   address->priv->path_len = -1;
-  address->priv->address_type = G_UNIX_SOCKET_ADDRESS_INVALID;
+  address->priv->address_type = G_UNIX_SOCKET_ADDRESS_PATH;
 }
 
 /**