tools: Make sure UTF-8 encoded command line arguments on Windows

On Windows, arguments passed in main() are system codepage
encoded and might not be valid UTF-8 string.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3828>
This commit is contained in:
Seungha Yang 2023-01-28 02:32:13 +09:00 committed by GStreamer Marge Bot
parent 090d50e1a0
commit e1a22402d3
8 changed files with 170 additions and 36 deletions

View file

@ -362,7 +362,12 @@ real_main (int argc, char *argv[])
g_option_context_add_main_entries (ctx, options, NULL);
g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
#ifdef G_OS_WIN32
if (!g_option_context_parse_strv (ctx, &argv, &err))
#else
if (!g_option_context_parse (ctx, &argc, &argv, &err))
#endif
{
g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
g_clear_error (&err);
g_option_context_free (ctx);
@ -468,9 +473,21 @@ no_extension:
int
main (int argc, char *argv[])
{
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
return gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
return real_main (argc, argv);
int ret;
#ifdef G_OS_WIN32
argv = g_win32_get_command_line ();
#endif
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
ret = real_main (argc, argv);
#endif
#ifdef G_OS_WIN32
g_strfreev (argv);
#endif
return ret;
}

View file

@ -324,7 +324,12 @@ real_main (int argc, char **argv)
"[DEVICE_CLASSES[:FILTER_CAPS]] …");
g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
#ifdef G_OS_WIN32
if (!g_option_context_parse_strv (ctx, &argv, &err))
#else
if (!g_option_context_parse (ctx, &argc, &argv, &err))
#endif
{
g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
g_option_context_free (ctx);
g_clear_error (&err);
@ -409,9 +414,21 @@ real_main (int argc, char **argv)
int
main (int argc, char *argv[])
{
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
return gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
return real_main (argc, argv);
int ret;
#ifdef G_OS_WIN32
argv = g_win32_get_command_line ();
#endif
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
ret = real_main (argc, argv);
#endif
#ifdef G_OS_WIN32
g_strfreev (argv);
#endif
return ret;
}

View file

@ -671,7 +671,12 @@ real_main (int argc, char **argv)
g_option_context_add_main_entries (ctx, options, NULL);
g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
#ifdef G_OS_WIN32
if (!g_option_context_parse_strv (ctx, &argv, &err))
#else
if (!g_option_context_parse (ctx, &argc, &argv, &err))
#endif
{
g_print ("Error initializing: %s\n", err->message);
g_option_context_free (ctx);
g_clear_error (&err);
@ -738,9 +743,21 @@ real_main (int argc, char **argv)
int
main (int argc, char *argv[])
{
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
return gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
return real_main (argc, argv);
int ret;
#ifdef G_OS_WIN32
argv = g_win32_get_command_line ();
#endif
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
ret = real_main (argc, argv);
#endif
#ifdef G_OS_WIN32
g_strfreev (argv);
#endif
return ret;
}

View file

@ -1690,7 +1690,12 @@ real_main (int argc, char **argv)
ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ...");
g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
#ifdef G_OS_WIN32
if (!g_option_context_parse_strv (ctx, &argv, &err))
#else
if (!g_option_context_parse (ctx, &argc, &argv, &err))
#endif
{
gst_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
g_option_context_free (ctx);
g_clear_error (&err);
@ -1836,9 +1841,21 @@ real_main (int argc, char **argv)
int
main (int argc, char *argv[])
{
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
return gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
return real_main (argc, argv);
int ret;
#ifdef G_OS_WIN32
argv = g_win32_get_command_line ();
#endif
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
ret = real_main (argc, argv);
#endif
#ifdef G_OS_WIN32
g_strfreev (argv);
#endif
return ret;
}

View file

@ -2171,7 +2171,12 @@ real_main (int argc, char *argv[])
ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]");
g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
#if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
if (!g_option_context_parse_strv (ctx, &argv, &err))
#else
if (!g_option_context_parse (ctx, &argc, &argv, &err))
#endif
{
g_printerr ("Error initializing: %s\n", err->message);
g_clear_error (&err);
g_option_context_free (ctx);
@ -2338,9 +2343,22 @@ done:
int
main (int argc, char *argv[])
{
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
return gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
return real_main (argc, argv);
int ret;
/* gstinspect.c calls this function */
#if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
argv = g_win32_get_command_line ();
#endif
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
ret = real_main (argc, argv);
#endif
#if defined(G_OS_WIN32) && !defined(GST_CHECK_MAIN)
g_strfreev (argv);
#endif
return ret;
}

View file

@ -1159,7 +1159,12 @@ real_main (int argc, char *argv[])
ctx = g_option_context_new ("PIPELINE-DESCRIPTION");
g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
#ifdef G_OS_WIN32
if (!g_option_context_parse_strv (ctx, &argv, &err))
#else
if (!g_option_context_parse (ctx, &argc, &argv, &err))
#endif
{
if (err)
gst_printerr ("Error initializing: %s\n", GST_STR_NULL (err->message));
else
@ -1368,9 +1373,21 @@ real_main (int argc, char *argv[])
int
main (int argc, char *argv[])
{
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
return gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
return real_main (argc, argv);
int ret;
#ifdef G_OS_WIN32
argv = g_win32_get_command_line ();
#endif
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
ret = real_main (argc, argv);
#endif
#ifdef G_OS_WIN32
g_strfreev (argv);
#endif
return ret;
}

View file

@ -1283,10 +1283,19 @@ main (gint argc, gchar * argv[])
g_set_prgname ("gst-stats-" GST_API_VERSION);
#ifdef G_OS_WIN32
argv = g_win32_get_command_line ();
#endif
ctx = g_option_context_new ("FILE");
g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
#ifdef G_OS_WIN32
if (!g_option_context_parse_strv (ctx, &argv, &err))
#else
if (!g_option_context_parse (ctx, &argc, &argv, &err))
#endif
{
g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
exit (1);
}
@ -1312,5 +1321,10 @@ main (gint argc, gchar * argv[])
done ();
g_strfreev (filenames);
#ifdef G_OS_WIN23
g_strfreev (argv);
#endif
return 0;
}

View file

@ -164,7 +164,12 @@ real_main (int argc, char *argv[])
ctx = g_option_context_new ("FILES");
g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE);
g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
#ifdef G_OS_WIN32
if (!g_option_context_parse_strv (ctx, &argv, &err))
#else
if (!g_option_context_parse (ctx, &argc, &argv, &err))
#endif
{
g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
g_clear_error (&err);
g_option_context_free (ctx);
@ -193,9 +198,21 @@ real_main (int argc, char *argv[])
int
main (int argc, char *argv[])
{
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
return gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
return real_main (argc, argv);
int ret;
#ifdef G_OS_WIN32
argv = g_win32_get_command_line ();
#endif
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
ret = gst_macos_main ((GstMainFunc) real_main, argc, argv, NULL);
#else
ret = real_main (argc, argv);
#endif
#ifdef G_OS_WIN32
g_strfreev (argv);
#endif
return ret;
}