summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2015-12-21 14:54:42 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2015-12-22 17:33:33 +0800
commitbec6a9a3003d95077ad23c235a9313d79c6a1c4f (patch)
tree68e1501f1443860f271c6af1f738c9912c06e40e
parent5f4b92202b2a36097ffa54fc7dbf96f692074069 (diff)
downloadglib-bec6a9a3003d95077ad23c235a9313d79c6a1c4f.tar.gz
g_application_run(): Fix on Windows When Using Bindings
As g_win32_get_command_line() calls CommandLineToArgvW() to acquire the arguments passed into a GApplication program, it actually returns the whole command line which is used to invoke the program, including the script interpreter and its flags when a script using GNOME bindings (e.g. PyGObject and so on) is being invoked. The issue here is that g_application_run() would most probably have trouble in the scripts scenario on Windows as it is likely unable to "recognize" the script interpreter, causing such scripts to fail to run. Largely based on the patch by Ray Donnelly <mingw.android@gmail.com>. https://bugzilla.gnome.org/show_bug.cgi?id=734095
-rw-r--r--gio/gapplication.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/gio/gapplication.c b/gio/gapplication.c
index e24ab696e..9947e05fc 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -2277,7 +2277,34 @@ g_application_run (GApplication *application,
g_return_val_if_fail (!application->priv->must_quit_now, 1);
#ifdef G_OS_WIN32
- arguments = g_win32_get_command_line ();
+ {
+ gint new_argc = 0;
+
+ arguments = g_win32_get_command_line ();
+
+ /*
+ * CommandLineToArgvW(), which is called by g_win32_get_command_line(),
+ * pulls in the whole command line that is used to call the program. This is
+ * fine in cases where the program is a .exe program, but in the cases where the
+ * program is a called via a script, such as PyGObject's gtk-demo.py, which is normally
+ * called using 'python gtk-demo.py' on Windows, the program name (argv[0])
+ * returned by g_win32_get_command_line() will not be the argv[0] that ->local_command_line()
+ * would expect, causing the program to fail with "This application can not open files."
+ */
+ new_argc = g_strv_length (arguments);
+
+ if (new_argc > argc)
+ {
+ gint i;
+
+ for (i = 0; i < new_argc - argc; i++)
+ g_free (arguments[i]);
+
+ memmove (&arguments[0],
+ &arguments[new_argc - argc],
+ sizeof (arguments[0]) * (argc + 1));
+ }
+ }
#else
{
gint i;