GOption: Allow NULL arguments to parse_strv

Close issue #873
This commit is contained in:
Christian Persch 2019-08-27 10:42:40 +02:00 committed by Emmanuel Fleury
parent 10be2c12ab
commit 9d513beeca
2 changed files with 10 additions and 3 deletions

View File

@ -2708,8 +2708,10 @@ g_option_context_get_description (GOptionContext *context)
/** /**
* g_option_context_parse_strv: * g_option_context_parse_strv:
* @context: a #GOptionContext * @context: a #GOptionContext
* @arguments: (inout) (array zero-terminated=1): a pointer to the * @arguments: (inout) (array null-terminated=1) (optional): a pointer
* command line arguments (which must be in UTF-8 on Windows) * 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 * @error: a return location for errors
* *
* Parses the command line arguments. * Parses the command line arguments.
@ -2743,7 +2745,7 @@ g_option_context_parse_strv (GOptionContext *context,
gint argc; gint argc;
context->strv_mode = TRUE; 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); success = g_option_context_parse (context, &argc, arguments, error);
context->strv_mode = FALSE; context->strv_mode = FALSE;

View File

@ -1912,6 +1912,11 @@ missing_arg_test (void)
g_strfreev (argv_copy); g_strfreev (argv_copy);
g_free (argv); g_free (argv);
g_option_context_free (context); 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; static gchar *test_arg;