[Telepathy-commits] [telepathy-doc/master] Correct the use of the arrays of pointers.
Murray Cumming
murrayc at murrayc.com
Mon Aug 18 03:02:30 PDT 2008
---
docs/examples/contacts_list_all/main.c | 37 +++++++++++++++++--------------
1 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/docs/examples/contacts_list_all/main.c b/docs/examples/contacts_list_all/main.c
index fc96ef6..a7780c2 100644
--- a/docs/examples/contacts_list_all/main.c
+++ b/docs/examples/contacts_list_all/main.c
@@ -37,44 +37,47 @@ on_list_connection_managers(TpConnectionManager * const *connection_manager,
g_printf ("Found %" G_GSIZE_FORMAT " connection managers:\n", n_cms);
+ if(!connection_manager)
+ return;
+
//TODO: See http://bugs.freedesktop.org/show_bug.cgi?id=17115
//about the awkwardness of these pointers to pointers:
- const TpConnectionManager *cm_iter = (connection_manager ? *connection_manager : NULL);
- for (; cm_iter != NULL; ++cm_iter)
+ TpConnectionManager * const *cm_iter = connection_manager;
+ for (; *cm_iter != NULL; ++cm_iter)
{
- if(!cm_iter)
+ const TpConnectionManager *cm = *cm_iter;
+ if (!cm)
continue;
//TODO: The protocols really shouldn't be const.
//const shouldn't be used for complex types in C because C doesn't have full const support.
//For instance, g_object_get() takes a non-const, so this causes a warning:
gchar *cm_name = NULL;
- g_object_get (cm_iter,
+ g_object_get (G_OBJECT(cm),
"connection-manager", &cm_name,
NULL);
g_printf (" Connection Manager name: %s\n", cm_name);
+ g_free (cm_name);
+ cm_name = NULL;
//TODO: See http://bugs.freedesktop.org/show_bug.cgi?id=17112
//about the lack of real API for this:
- //Note that it's an array of pointers, not a pointer to an array
- //(unlike the connection_manager array above.)
- const TpConnectionManagerProtocol * const *protocols = cm_iter->protocols;
- const TpConnectionManagerProtocol * const *protocols_iter = protocols;
- for (; protocols_iter != NULL; ++protocols_iter)
+ if(cm->protocols)
{
- if(!protocols_iter)
- continue;
-
- const TpConnectionManagerProtocol *protocol = *protocols_iter;
- if (protocol)
+ const TpConnectionManagerProtocol * const *protocols_iter = cm->protocols;
+ for (; *protocols_iter != NULL; ++protocols_iter)
{
- if(protocol->name)
- g_printf (" Protocol name: %s\n", protocol->name);
+ const TpConnectionManagerProtocol *protocol = *protocols_iter;
+ if (protocol)
+ {
+ if(protocol->name)
+ g_printf (" Protocol name: %s\n", protocol->name);
+ }
}
}
- g_free (cm_name);
+
}
/* Stop the mainloop so the program finishes: */
--
1.5.6.3
More information about the Telepathy-commits
mailing list