Merge branch 'allow_NULL_argument_to_parse_strv' into 'master'

GOption: Allow NULL arguments to parse_strv

Closes #873

See merge request GNOME/glib!1064
This commit is contained in:
Nirbheek Chauhan 2019-08-27 13:17:39 +00:00
commit e0e4968dca
2 changed files with 10 additions and 3 deletions

View File

@ -2709,8 +2709,10 @@ g_option_context_get_description (GOptionContext *context)
/**
* g_option_context_parse_strv:
* @context: a #GOptionContext
* @arguments: (inout) (array zero-terminated=1): a pointer to the
* command line arguments (which must be in UTF-8 on Windows)
* @arguments: (inout) (array null-terminated=1) (optional): a pointer
* to the command line arguments (which must be in UTF-8 on Windows).
* Starting with GLib 2.62, @arguments can be %NULL, which matches
* g_option_context_parse().
* @error: a return location for errors
*
* Parses the command line arguments.
@ -2744,7 +2746,7 @@ g_option_context_parse_strv (GOptionContext *context,
gint argc;
context->strv_mode = TRUE;
argc = g_strv_length (*arguments);
argc = arguments && *arguments ? g_strv_length (*arguments) : 0;
success = g_option_context_parse (context, &argc, arguments, error);
context->strv_mode = FALSE;

View File

@ -1912,6 +1912,11 @@ missing_arg_test (void)
g_strfreev (argv_copy);
g_free (argv);
g_option_context_free (context);
/* Checking g_option_context_parse_strv on NULL args */
context = g_option_context_new (NULL);
g_assert_true (g_option_context_parse_strv (context, NULL, NULL));
g_option_context_free (context);
}
static gchar *test_arg;