[Telepathy] [Bug 18040] New: tp_list_connection_managers() (and others?) use const on complex types.

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Mon Oct 13 03:26:58 PDT 2008


http://bugs.freedesktop.org/show_bug.cgi?id=18040

           Summary: tp_list_connection_managers() (and others?) use const on
                    complex types.
           Product: Telepathy
           Version: unspecified
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: medium
         Component: telepathy-glib
        AssignedTo: telepathy at lists.freedesktop.org
        ReportedBy: murrayc at murrayc.com


tp_list_connection_managers() takes a TpConnectionManagerListCb callback that
provides a list of const TpConnectionManager*.
http://telepathy.freedesktop.org/doc/telepathy-glib/telepathy-glib-connection-manager.html#TpConnectionManagerListCb

But const should never be used in C for complex types. It is only useful for
simple types (such as char) or structs of simple types, such as GdkRectangle.
Unlike C++, C lacks the mutable keyword, and lacks const and non-const method
overloads, so const just gets annoying for complex types. This is the approach
used by GTK+.

For instance, this code causes compiler warnings because we use g_object_get()
on a const instance. To avoid these, const must be annoyingly casted away
almost always.


static void
on_list_connection_managers(TpConnectionManager * const *connection_managers,
                            gsize n_cms, 
                            const GError *error,
                            gpointer user_data,
                            GObject *weak_object)
{
  TpConnectionManager * const *cm_iter = connection_managers;
  for (; *cm_iter != NULL; ++cm_iter)
    {
      const TpConnectionManager *cm = *cm_iter;

      gchar *cm_name = NULL;
      g_object_get (G_OBJECT(cm),
        "connection-manager", &cm_name,
        NULL);
  ...


(see also 
http://bugs.freedesktop.org/show_bug.cgi?id=17115
about the general horribleness of the pointers-to-pointers in the API.)


-- 
Configure bugmail: http://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Telepathy mailing list