From ada132cb23a282ca19f213520041734704832f76 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 27 Sep 2010 18:28:40 -0400 Subject: [PATCH 2/3] Fix wocky_implement_finish_*() macro * Fixed missing scope (G_STMT_START/G_STMT_END) and missing parenthesis * Don't call copy_func if the result is NULL (enabling use of g_object_ref as copy_func). * Added missing ; now required when those macro are called. --- wocky/wocky-pubsub-node.c | 12 +++--- wocky/wocky-pubsub-service.c | 2 +- wocky/wocky-utils.h | 74 ++++++++++++++++++++++++++---------------- 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/wocky/wocky-pubsub-node.c b/wocky/wocky-pubsub-node.c index 662bfa0..5228e14 100644 --- a/wocky/wocky-pubsub-node.c +++ b/wocky/wocky-pubsub-node.c @@ -590,7 +590,7 @@ wocky_pubsub_node_unsubscribe_finish (WockyPubsubNode *self, GAsyncResult *result, GError **error) { - wocky_implement_finish_void (self, wocky_pubsub_node_unsubscribe_async) + wocky_implement_finish_void (self, wocky_pubsub_node_unsubscribe_async); } WockyStanza * @@ -626,7 +626,7 @@ wocky_pubsub_node_delete_finish (WockyPubsubNode *self, GAsyncResult *result, GError **error) { - wocky_implement_finish_void (self, wocky_pubsub_node_delete_async) + wocky_implement_finish_void (self, wocky_pubsub_node_delete_async); } WockyStanza * @@ -731,7 +731,7 @@ wocky_pubsub_node_list_subscribers_finish ( { wocky_implement_finish_copy_pointer (self, wocky_pubsub_node_list_subscribers_async, - wocky_pubsub_subscription_list_copy, subscribers) + wocky_pubsub_subscription_list_copy, subscribers); } WockyStanza * @@ -879,7 +879,7 @@ wocky_pubsub_node_list_affiliates_finish ( { wocky_implement_finish_copy_pointer (self, wocky_pubsub_node_list_affiliates_async, - wocky_pubsub_affiliation_list_copy, affiliates) + wocky_pubsub_affiliation_list_copy, affiliates); } /** @@ -1001,7 +1001,7 @@ wocky_pubsub_node_modify_affiliates_finish ( GAsyncResult *result, GError **error) { - wocky_implement_finish_void (self, wocky_pubsub_node_modify_affiliates_async) + wocky_implement_finish_void (self, wocky_pubsub_node_modify_affiliates_async); } /** @@ -1103,7 +1103,7 @@ wocky_pubsub_node_get_configuration_finish ( GError **error) { wocky_implement_finish_return_copy_pointer (self, - wocky_pubsub_node_get_configuration_async, g_object_ref) + wocky_pubsub_node_get_configuration_async, g_object_ref); } WockyPorter * diff --git a/wocky/wocky-pubsub-service.c b/wocky/wocky-pubsub-service.c index 7fba9e7..184cf38 100644 --- a/wocky/wocky-pubsub-service.c +++ b/wocky/wocky-pubsub-service.c @@ -757,7 +757,7 @@ wocky_pubsub_service_retrieve_subscriptions_finish ( { wocky_implement_finish_copy_pointer (self, wocky_pubsub_service_retrieve_subscriptions_async, - wocky_pubsub_subscription_list_copy, subscriptions) + wocky_pubsub_subscription_list_copy, subscriptions); } /** diff --git a/wocky/wocky-utils.h b/wocky/wocky-utils.h index 8e25b49..a9e6975 100644 --- a/wocky/wocky-utils.h +++ b/wocky/wocky-utils.h @@ -79,37 +79,55 @@ void wocky_g_string_free (GString *str); * They should really be in GLib, but let's experiment here first. */ #define wocky_implement_finish_void(source, tag) \ - if (g_simple_async_result_propagate_error (\ - G_SIMPLE_ASYNC_RESULT (result), error)) \ - return FALSE; \ - g_return_val_if_fail (g_simple_async_result_is_valid (result, \ - G_OBJECT(source), tag), \ - FALSE); \ - return TRUE; +G_STMT_START { \ + GSimpleAsyncResult *_simple; \ + _simple = (GSimpleAsyncResult *) result; \ + if (g_simple_async_result_propagate_error ( \ + _simple, error)) \ + return FALSE; \ + g_return_val_if_fail (g_simple_async_result_is_valid (result, \ + G_OBJECT (source), (tag)), \ + FALSE); \ + return TRUE; \ +} G_STMT_END #define wocky_implement_finish_copy_pointer(source, tag, copy_func, \ out_param) \ - GSimpleAsyncResult *_simple; \ - _simple = (GSimpleAsyncResult *) result; \ - if (g_simple_async_result_propagate_error (_simple, error)) \ - return FALSE; \ - g_return_val_if_fail (g_simple_async_result_is_valid (result, \ - G_OBJECT (source), tag), \ - FALSE); \ - if (out_param != NULL) \ - *out_param = copy_func ( \ - g_simple_async_result_get_op_res_gpointer (_simple)); \ - return TRUE; - -#define wocky_implement_finish_return_copy_pointer(source, tag, copy_func) \ - GSimpleAsyncResult *_simple; \ - _simple = (GSimpleAsyncResult *) result; \ - if (g_simple_async_result_propagate_error (_simple, error)) \ - return NULL; \ - g_return_val_if_fail (g_simple_async_result_is_valid (result, \ - G_OBJECT (source), tag), \ - NULL); \ - return copy_func (g_simple_async_result_get_op_res_gpointer (_simple)); +G_STMT_START { \ + GSimpleAsyncResult *_simple; \ + _simple = (GSimpleAsyncResult *) result; \ + if (g_simple_async_result_propagate_error (_simple, error)) \ + return FALSE; \ + g_return_val_if_fail (g_simple_async_result_is_valid (result, \ + G_OBJECT (source), (tag)), \ + FALSE); \ + if ((out_param) != NULL) \ + { \ + gpointer _p = g_simple_async_result_get_op_res_gpointer (_simple); \ + if (_p != NULL) \ + *(out_param) = (copy_func) (_p); \ + else \ + *(out_param) = NULL; \ + } \ + return TRUE; \ +} G_STMT_END + +#define wocky_implement_finish_return_copy_pointer(source, tag, \ + copy_func) \ +G_STMT_START { \ + GSimpleAsyncResult *_simple; \ + gpointer _p; \ + _simple = (GSimpleAsyncResult *) result; \ + if (g_simple_async_result_propagate_error (_simple, error)) \ + return NULL; \ + g_return_val_if_fail (g_simple_async_result_is_valid (result, \ + G_OBJECT (source), (tag)), \ + NULL); \ + _p = g_simple_async_result_get_op_res_gpointer (_simple); \ + if (_p != NULL) \ + return (copy_func) (_p); \ + return NULL; \ +} G_STMT_END G_END_DECLS -- 1.7.2.3