dbus-glib on debian lenny.

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Apr 15 04:24:44 PDT 2009


On Tue, 14 Apr 2009 at 20:43:01 -0500, Fujitaka Daidouji wrote:
> static void print_hash_value (gpointer key, gpointer val, gpointer data)
> {
>   printf ("%s -> %s\n", (char *) key, (char *) val);
> }

No, val points to a GValue, not a string. Try something like this:

static void print_hash_value (gpointer k, gpointer v, gpointer data)
{
  const gchar *key = k;
  const GValue *val = v;

  if (G_VALUE_HOLDS_STRING (val))
    {
      printf ("%s -> %s\n", key, g_value_get_string (val));
    }
  else if (G_VALUE_HOLDS_UINT (val))
    {
      printf ("%s -> %u\n", key, g_value_get_uint (val));
    }
  /* ... insert any more types you might need here ... */
  else
    {
      /* the result of this function is only suitable for debug output */
      gchar *tmp = g_strdup_value_contents (val);

      printf ("%s -> unhandled type %s with value %s",
          key, G_VALUE_TYPE_NAME (value), tmp);
      g_free (tmp);
    }
}


More information about the dbus mailing list