From 62be3d5d3e8eaecd30f891ba7adee3805c00dbba Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 8 May 2019 12:52:09 +0100 Subject: [PATCH 1/2] tests: Use g_assert_*() in autoptr tests rather than g_assert() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It gives clearer failure messages, and won’t get compiled out when building with G_DISABLE_ASSERT. Signed-off-by: Philip Withnall --- glib/tests/autoptr.c | 112 +++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/glib/tests/autoptr.c b/glib/tests/autoptr.c index 779190f8a..c9d1f07e5 100644 --- a/glib/tests/autoptr.c +++ b/glib/tests/autoptr.c @@ -41,63 +41,63 @@ static void test_g_async_queue (void) { g_autoptr(GAsyncQueue) val = g_async_queue_new (); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_bookmark_file (void) { g_autoptr(GBookmarkFile) val = g_bookmark_file_new (); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_bytes (void) { g_autoptr(GBytes) val = g_bytes_new ("foo", 3); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_checksum (void) { g_autoptr(GChecksum) val = g_checksum_new (G_CHECKSUM_SHA256); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_date_time (void) { g_autoptr(GDateTime) val = g_date_time_new_now_utc (); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_dir (void) { g_autoptr(GDir) val = g_dir_open (".", 0, NULL); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_error (void) { g_autoptr(GError) val = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_FAILED, "oops"); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_hash_table (void) { g_autoptr(GHashTable) val = g_hash_table_new (NULL, NULL); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_hmac (void) { g_autoptr(GHmac) val = g_hmac_new (G_CHECKSUM_SHA256, (guint8*)"hello", 5); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -110,14 +110,14 @@ test_g_io_channel (void) #endif g_autoptr(GIOChannel) val = g_io_channel_new_file (devnull, "r", NULL); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_key_file (void) { g_autoptr(GKeyFile) val = g_key_file_new (); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -125,57 +125,57 @@ test_g_list (void) { g_autoptr(GList) val = NULL; g_autoptr(GList) val2 = g_list_prepend (NULL, "foo"); - g_assert (val == NULL); - g_assert (val2 != NULL); + g_assert_null (val); + g_assert_nonnull (val2); } static void test_g_array (void) { g_autoptr(GArray) val = g_array_new (0, 0, sizeof (gpointer)); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_ptr_array (void) { g_autoptr(GPtrArray) val = g_ptr_array_new (); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_byte_array (void) { g_autoptr(GByteArray) val = g_byte_array_new (); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_main_context (void) { g_autoptr(GMainContext) val = g_main_context_new (); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_main_loop (void) { g_autoptr(GMainLoop) val = g_main_loop_new (NULL, TRUE); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_source (void) { g_autoptr(GSource) val = g_timeout_source_new_seconds (2); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_mapped_file (void) { g_autoptr(GMappedFile) val = g_mapped_file_new (g_test_get_filename (G_TEST_DIST, "keyfiletest.ini", NULL), FALSE, NULL); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -205,35 +205,35 @@ static void test_g_markup_parse_context (void) { g_autoptr(GMarkupParseContext) val = g_markup_parse_context_new (&parser, 0, NULL, NULL); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_node (void) { g_autoptr(GNode) val = g_node_new ("hello"); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_option_context (void) { g_autoptr(GOptionContext) val = g_option_context_new ("hello"); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_option_group (void) { g_autoptr(GOptionGroup) val = g_option_group_new ("hello", "world", "helpme", NULL, NULL); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_pattern_spec (void) { g_autoptr(GPatternSpec) val = g_pattern_spec_new ("plaid"); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -241,7 +241,7 @@ test_g_queue (void) { g_autoptr(GQueue) val = g_queue_new (); g_auto(GQueue) stackval = G_QUEUE_INIT; - g_assert (val != NULL); + g_assert_nonnull (val); g_assert_null (stackval.head); } @@ -249,14 +249,14 @@ static void test_g_rand (void) { g_autoptr(GRand) val = g_rand_new (); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_regex (void) { g_autoptr(GRegex) val = g_regex_new (".*", 0, 0, NULL); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -274,14 +274,14 @@ test_g_scanner (void) { GScannerConfig config = { 0, }; g_autoptr(GScanner) val = g_scanner_new (&config); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_sequence (void) { g_autoptr(GSequence) val = g_sequence_new (NULL); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -289,22 +289,22 @@ test_g_slist (void) { g_autoptr(GSList) val = NULL; g_autoptr(GSList) nonempty_val = g_slist_prepend (NULL, "hello"); - g_assert (val == NULL); - g_assert (nonempty_val != NULL); + g_assert_null (val); + g_assert_nonnull (nonempty_val); } static void test_g_string (void) { g_autoptr(GString) val = g_string_new (""); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_string_chunk (void) { g_autoptr(GStringChunk) val = g_string_chunk_new (42); - g_assert (val != NULL); + g_assert_nonnull (val); } static gpointer @@ -318,7 +318,7 @@ static void test_g_thread (void) { g_autoptr(GThread) val = g_thread_new ("bob", mythread, NULL); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -425,28 +425,28 @@ static void test_g_timer (void) { g_autoptr(GTimer) val = g_timer_new (); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_time_zone (void) { g_autoptr(GTimeZone) val = g_time_zone_new ("UTC"); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_tree (void) { g_autoptr(GTree) val = g_tree_new ((GCompareFunc)strcmp); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_variant (void) { g_autoptr(GVariant) val = g_variant_new_string ("hello"); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -455,7 +455,7 @@ test_g_variant_builder (void) g_autoptr(GVariantBuilder) val = g_variant_builder_new (G_VARIANT_TYPE ("as")); g_auto(GVariantBuilder) stackval; - g_assert (val != NULL); + g_assert_nonnull (val); g_variant_builder_init (&stackval, G_VARIANT_TYPE ("as")); } @@ -464,7 +464,7 @@ test_g_variant_iter (void) { g_autoptr(GVariant) var = g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, "", 0, sizeof(guint32)); g_autoptr(GVariantIter) val = g_variant_iter_new (var); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -475,21 +475,21 @@ test_g_variant_dict (void) g_autoptr(GVariantDict) val = g_variant_dict_new (data); g_variant_dict_init (&stackval, data); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_g_variant_type (void) { g_autoptr(GVariantType) val = g_variant_type_new ("s"); - g_assert (val != NULL); + g_assert_nonnull (val); } static void test_strv (void) { g_auto(GStrv) val = g_strsplit("a:b:c", ":", -1); - g_assert (val != NULL); + g_assert_nonnull (val); } static void @@ -526,13 +526,13 @@ test_autolist (void) /* Only assert if autoptr works */ #ifdef __GNUC__ - g_assert (freed1); - g_assert (freed3); + g_assert_true (freed1); + g_assert_true (freed3); #endif - g_assert (!freed2); + g_assert_false (freed2); g_bytes_unref (b2); - g_assert (freed2); + g_assert_true (freed2); } static void @@ -555,13 +555,13 @@ test_autoslist (void) /* Only assert if autoptr works */ #ifdef __GNUC__ - g_assert (freed1); - g_assert (freed3); + g_assert_true (freed1); + g_assert_true (freed3); #endif - g_assert (!freed2); + g_assert_false (freed2); g_bytes_unref (b2); - g_assert (freed2); + g_assert_true (freed2); } static void @@ -584,13 +584,13 @@ test_autoqueue (void) /* Only assert if autoptr works */ #ifdef __GNUC__ - g_assert (freed1); - g_assert (freed3); + g_assert_true (freed1); + g_assert_true (freed3); #endif - g_assert (!freed2); + g_assert_false (freed2); g_bytes_unref (b2); - g_assert (freed2); + g_assert_true (freed2); } int From 5a30f852d6c7590fbf7809b1b5d6aebc1a156583 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 8 May 2019 12:52:48 +0100 Subject: [PATCH 2/2] docs: Improve formatting of g_autoptr() documentation Signed-off-by: Philip Withnall --- glib/docs.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/glib/docs.c b/glib/docs.c index 7b1920b86..5d09f433e 100644 --- a/glib/docs.c +++ b/glib/docs.c @@ -2224,7 +2224,7 @@ * This macro can be used to avoid having to do explicit cleanups of * local variables when exiting functions. It often vastly simplifies * handling of error conditions, removing the need for various tricks - * such as 'goto out' or repeating of cleanup code. It is also helpful + * such as `goto out` or repeating of cleanup code. It is also helpful * for non-error cases. * * Consider the following example: @@ -2251,8 +2251,8 @@ * } * ]| * - * You must initialize the variable in some way -- either by use of an - * initialiser or by ensuring that an _init function will be called on + * You must initialize the variable in some way — either by use of an + * initialiser or by ensuring that an `_init` function will be called on * it unconditionally before it goes out of scope. * * Since: 2.44 @@ -2273,12 +2273,12 @@ * * This is meant to be used to declare pointers to types with cleanup * functions. The type of the variable is a pointer to @TypeName. You - * must not add your own '*'. + * must not add your own `*`. * * This macro can be used to avoid having to do explicit cleanups of * local variables when exiting functions. It often vastly simplifies * handling of error conditions, removing the need for various tricks - * such as 'goto out' or repeating of cleanup code. It is also helpful + * such as `goto out` or repeating of cleanup code. It is also helpful * for non-error cases. * * Consider the following example: @@ -2308,7 +2308,7 @@ * } * ]| * - * You must initialise the variable in some way -- either by use of an + * You must initialise the variable in some way — either by use of an * initialiser or by ensuring that it is assigned to unconditionally * before it goes out of scope. * @@ -2330,7 +2330,7 @@ * This means it's useful for any type that is returned from * g_malloc(). * - * Otherwise, this macro has similar constraints as g_autoptr() - only + * Otherwise, this macro has similar constraints as g_autoptr(): only * supported on GCC and clang, the variable must be initialized, etc. * * |[ @@ -2365,13 +2365,13 @@ * are intended to be portable to those compilers. * * This is meant to be used to declare lists of a type with a cleanup - * function. The type of the variable is a GList *. You - * must not add your own '*'. + * function. The type of the variable is a `GList *`. You + * must not add your own `*`. * * This macro can be used to avoid having to do explicit cleanups of * local variables when exiting functions. It often vastly simplifies * handling of error conditions, removing the need for various tricks - * such as 'goto out' or repeating of cleanup code. It is also helpful + * such as `goto out` or repeating of cleanup code. It is also helpful * for non-error cases. * * See also g_autoslist(), g_autoptr() and g_steal_pointer(). @@ -2393,13 +2393,13 @@ * are intended to be portable to those compilers. * * This is meant to be used to declare lists of a type with a cleanup - * function. The type of the variable is a GSList *. You - * must not add your own '*'. + * function. The type of the variable is a `GSList *`. You + * must not add your own `*`. * * This macro can be used to avoid having to do explicit cleanups of * local variables when exiting functions. It often vastly simplifies * handling of error conditions, removing the need for various tricks - * such as 'goto out' or repeating of cleanup code. It is also helpful + * such as `goto out` or repeating of cleanup code. It is also helpful * for non-error cases. * * See also g_autolist(), g_autoptr() and g_steal_pointer(). @@ -2446,7 +2446,7 @@ * The function will not be called if the variable to be cleaned up * contains %NULL. * - * This will typically be the _free() or _unref() function for the given + * This will typically be the `_free()` or `_unref()` function for the given * type. * * With this definition, it will be possible to use g_autoptr() with @@ -2469,7 +2469,7 @@ * * Defines the appropriate cleanup function for a type. * - * This will typically be the _clear() function for the given type. + * This will typically be the `_clear()` function for the given type. * * With this definition, it will be possible to use g_auto() with * @TypeName. @@ -2501,7 +2501,7 @@ * and file descriptors. * * @none specifies the "none" value for the type in question. It is - * probably something like %NULL or -1. If the variable is found to + * probably something like %NULL or `-1`. If the variable is found to * contain this value then the free function will not be called. * * |[