From 23dffdd949eb1cde6900d0ddc1f543261401fdbd Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Tue, 28 Mar 2017 08:02:55 +0200 Subject: [PATCH] gspawn: Remove old win32 codepage ABI compat code Makes new code link against the normal symbol names again. Variants with utf8 suffix are there for existing binaries/ABI compat. https://bugzilla.gnome.org/show_bug.cgi?id=780634 --- glib/gspawn-win32.c | 483 ++++++++++++++++---------------------------- glib/gspawn.h | 53 ----- 2 files changed, 174 insertions(+), 362 deletions(-) diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c index e1048d2c3..35e96125f 100644 --- a/glib/gspawn-win32.c +++ b/glib/gspawn-win32.c @@ -211,25 +211,25 @@ G_DEFINE_QUARK (g-exec-error-quark, g_spawn_error) G_DEFINE_QUARK (g-spawn-exit-error-quark, g_spawn_exit_error) gboolean -g_spawn_async_utf8 (const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - GPid *child_handle, - GError **error) +g_spawn_async (const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + GPid *child_handle, + GError **error) { g_return_val_if_fail (argv != NULL, FALSE); - return g_spawn_async_with_pipes_utf8 (working_directory, - argv, envp, - flags, - child_setup, - user_data, - child_handle, - NULL, NULL, NULL, - error); + return g_spawn_async_with_pipes (working_directory, + argv, envp, + flags, + child_setup, + user_data, + child_handle, + NULL, NULL, NULL, + error); } /* Avoids a danger in threaded situations (calling close() @@ -876,16 +876,16 @@ do_spawn_with_pipes (gint *exit_status, } gboolean -g_spawn_sync_utf8 (const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - gchar **standard_output, - gchar **standard_error, - gint *exit_status, - GError **error) +g_spawn_sync (const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + gchar **standard_output, + gchar **standard_error, + gint *exit_status, + GError **error) { gint outpipe = -1; gint errpipe = -1; @@ -1118,17 +1118,17 @@ g_spawn_sync_utf8 (const gchar *working_directory, } gboolean -g_spawn_async_with_pipes_utf8 (const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - GPid *child_handle, - gint *standard_input, - gint *standard_output, - gint *standard_error, - GError **error) +g_spawn_async_with_pipes (const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + GPid *child_handle, + gint *standard_input, + gint *standard_output, + gint *standard_error, + GError **error) { g_return_val_if_fail (argv != NULL, FALSE); g_return_val_if_fail (standard_output == NULL || @@ -1155,11 +1155,11 @@ g_spawn_async_with_pipes_utf8 (const gchar *working_directory, } gboolean -g_spawn_command_line_sync_utf8 (const gchar *command_line, - gchar **standard_output, - gchar **standard_error, - gint *exit_status, - GError **error) +g_spawn_command_line_sync (const gchar *command_line, + gchar **standard_output, + gchar **standard_error, + gint *exit_status, + GError **error) { gboolean retval; gchar **argv = 0; @@ -1171,24 +1171,24 @@ g_spawn_command_line_sync_utf8 (const gchar *command_line, error)) return FALSE; - retval = g_spawn_sync_utf8 (NULL, - argv, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - standard_output, - standard_error, - exit_status, - error); + retval = g_spawn_sync (NULL, + argv, + NULL, + G_SPAWN_SEARCH_PATH, + NULL, + NULL, + standard_output, + standard_error, + exit_status, + error); g_strfreev (argv); return retval; } gboolean -g_spawn_command_line_async_utf8 (const gchar *command_line, - GError **error) +g_spawn_command_line_async (const gchar *command_line, + GError **error) { gboolean retval; gchar **argv = 0; @@ -1200,14 +1200,14 @@ g_spawn_command_line_async_utf8 (const gchar *command_line, error)) return FALSE; - retval = g_spawn_async_utf8 (NULL, - argv, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - NULL, - error); + retval = g_spawn_async (NULL, + argv, + NULL, + G_SPAWN_SEARCH_PATH, + NULL, + NULL, + NULL, + error); g_strfreev (argv); return retval; @@ -1238,273 +1238,138 @@ g_spawn_check_exit_status (gint exit_status, return ret; } -#if !defined (_WIN64) +#endif /* !GSPAWN_HELPER */ -/* Binary compatibility versions that take system codepage pathnames, - * argument vectors and environments. These get used only by code - * built against 2.8.1 or earlier. Code built against 2.8.2 or later - * will use the _utf8 versions above (see the #defines in gspawn.h). - */ +#ifdef G_OS_WIN32 -#undef g_spawn_async -#undef g_spawn_async_with_pipes -#undef g_spawn_sync -#undef g_spawn_command_line_sync -#undef g_spawn_command_line_async +/* Binary compatibility versions. Not for newly compiled code. */ -static gboolean -setup_utf8_copies (const gchar *working_directory, - gchar **utf8_working_directory, - gchar **argv, - gchar ***utf8_argv, - gchar **envp, - gchar ***utf8_envp, - GError **error) +_GLIB_EXTERN gboolean g_spawn_async_utf8 (const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + GPid *child_pid, + GError **error); +_GLIB_EXTERN gboolean g_spawn_async_with_pipes_utf8 (const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + GPid *child_pid, + gint *standard_input, + gint *standard_output, + gint *standard_error, + GError **error); +_GLIB_EXTERN gboolean g_spawn_sync_utf8 (const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + gchar **standard_output, + gchar **standard_error, + gint *exit_status, + GError **error); +_GLIB_EXTERN gboolean g_spawn_command_line_sync_utf8 (const gchar *command_line, + gchar **standard_output, + gchar **standard_error, + gint *exit_status, + GError **error); +_GLIB_EXTERN gboolean g_spawn_command_line_async_utf8 (const gchar *command_line, + GError **error); + +gboolean +g_spawn_async_utf8 (const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + GPid *child_handle, + GError **error) { - gint i, argc, envc; - - if (working_directory == NULL) - *utf8_working_directory = NULL; - else - { - GError *conv_error = NULL; - - *utf8_working_directory = g_locale_to_utf8 (working_directory, -1, NULL, NULL, &conv_error); - if (*utf8_working_directory == NULL) - { - g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_CHDIR, - _("Invalid working directory: %s"), - conv_error->message); - g_error_free (conv_error); - return FALSE; - } - } - - argc = 0; - while (argv[argc]) - ++argc; - *utf8_argv = g_new (gchar *, argc + 1); - for (i = 0; i < argc; i++) - { - GError *conv_error = NULL; - - (*utf8_argv)[i] = g_locale_to_utf8 (argv[i], -1, NULL, NULL, &conv_error); - if ((*utf8_argv)[i] == NULL) - { - g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED, - _("Invalid string in argument vector at %d: %s"), - i, conv_error->message); - g_error_free (conv_error); - - g_strfreev (*utf8_argv); - *utf8_argv = NULL; - - g_free (*utf8_working_directory); - *utf8_working_directory = NULL; - - return FALSE; - } - } - (*utf8_argv)[argc] = NULL; - - if (envp == NULL) - { - *utf8_envp = NULL; - } - else - { - envc = 0; - while (envp[envc]) - ++envc; - *utf8_envp = g_new (gchar *, envc + 1); - for (i = 0; i < envc; i++) - { - GError *conv_error = NULL; - - (*utf8_envp)[i] = g_locale_to_utf8 (envp[i], -1, NULL, NULL, &conv_error); - if ((*utf8_envp)[i] == NULL) - { - g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED, - _("Invalid string in environment: %s"), - conv_error->message); - g_error_free (conv_error); - - g_strfreev (*utf8_envp); - *utf8_envp = NULL; - - g_strfreev (*utf8_argv); - *utf8_argv = NULL; - - g_free (*utf8_working_directory); - *utf8_working_directory = NULL; - - return FALSE; - } - } - (*utf8_envp)[envc] = NULL; - } - return TRUE; -} - -static void -free_utf8_copies (gchar *utf8_working_directory, - gchar **utf8_argv, - gchar **utf8_envp) -{ - g_free (utf8_working_directory); - g_strfreev (utf8_argv); - g_strfreev (utf8_envp); + return g_spawn_async (working_directory, + argv, + envp, + flags, + child_setup, + user_data, + child_handle, + error); } gboolean -g_spawn_async_with_pipes (const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - GPid *child_handle, - gint *standard_input, - gint *standard_output, - gint *standard_error, - GError **error) -{ - gchar *utf8_working_directory; - gchar **utf8_argv; - gchar **utf8_envp; - gboolean retval; - - if (!setup_utf8_copies (working_directory, &utf8_working_directory, - argv, &utf8_argv, - envp, &utf8_envp, - error)) - return FALSE; - - retval = g_spawn_async_with_pipes_utf8 (utf8_working_directory, - utf8_argv, utf8_envp, - flags, child_setup, user_data, - child_handle, - standard_input, standard_output, standard_error, - error); - - free_utf8_copies (utf8_working_directory, utf8_argv, utf8_envp); - - return retval; -} - -gboolean -g_spawn_async (const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - GPid *child_handle, - GError **error) +g_spawn_async_with_pipes_utf8 (const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + GPid *child_handle, + gint *standard_input, + gint *standard_output, + gint *standard_error, + GError **error) { return g_spawn_async_with_pipes (working_directory, - argv, envp, - flags, - child_setup, - user_data, - child_handle, - NULL, NULL, NULL, - error); + argv, + envp, + flags, + child_setup, + user_data, + child_handle, + standard_input, + standard_output, + standard_error, + error); } gboolean -g_spawn_sync (const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - gchar **standard_output, - gchar **standard_error, - gint *exit_status, - GError **error) +g_spawn_sync_utf8 (const gchar *working_directory, + gchar **argv, + gchar **envp, + GSpawnFlags flags, + GSpawnChildSetupFunc child_setup, + gpointer user_data, + gchar **standard_output, + gchar **standard_error, + gint *exit_status, + GError **error) { - gchar *utf8_working_directory; - gchar **utf8_argv; - gchar **utf8_envp; - gboolean retval; - - if (!setup_utf8_copies (working_directory, &utf8_working_directory, - argv, &utf8_argv, - envp, &utf8_envp, - error)) - return FALSE; - - retval = g_spawn_sync_utf8 (utf8_working_directory, - utf8_argv, utf8_envp, - flags, child_setup, user_data, - standard_output, standard_error, exit_status, - error); - - free_utf8_copies (utf8_working_directory, utf8_argv, utf8_envp); - - return retval; + return g_spawn_sync (working_directory, + argv, + envp, + flags, + child_setup, + user_data, + standard_output, + standard_error, + exit_status, + error); } gboolean -g_spawn_command_line_sync (const gchar *command_line, - gchar **standard_output, - gchar **standard_error, - gint *exit_status, - GError **error) +g_spawn_command_line_sync_utf8 (const gchar *command_line, + gchar **standard_output, + gchar **standard_error, + gint *exit_status, + GError **error) { - gboolean retval; - gchar **argv = 0; - - g_return_val_if_fail (command_line != NULL, FALSE); - - if (!g_shell_parse_argv (command_line, - NULL, &argv, - error)) - return FALSE; - - retval = g_spawn_sync (NULL, - argv, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - standard_output, - standard_error, - exit_status, - error); - g_strfreev (argv); - - return retval; + return g_spawn_command_line_sync (command_line, + standard_output, + standard_error, + exit_status, + error); } gboolean -g_spawn_command_line_async (const gchar *command_line, - GError **error) +g_spawn_command_line_async_utf8 (const gchar *command_line, + GError **error) { - gboolean retval; - gchar **argv = 0; - - g_return_val_if_fail (command_line != NULL, FALSE); - - if (!g_shell_parse_argv (command_line, - NULL, &argv, - error)) - return FALSE; - - retval = g_spawn_async (NULL, - argv, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - NULL, - error); - g_strfreev (argv); - - return retval; + return g_spawn_command_line_async (command_line, error); } -#endif /* !_WIN64 */ - -#endif /* !GSPAWN_HELPER */ +#endif diff --git a/glib/gspawn.h b/glib/gspawn.h index 1409e2f44..9f96102de 100644 --- a/glib/gspawn.h +++ b/glib/gspawn.h @@ -249,59 +249,6 @@ gboolean g_spawn_check_exit_status (gint exit_status, GLIB_AVAILABLE_IN_ALL void g_spawn_close_pid (GPid pid); -#ifndef __GTK_DOC_IGNORE__ -#ifdef G_OS_WIN32 -#define g_spawn_async g_spawn_async_utf8 -#define g_spawn_async_with_pipes g_spawn_async_with_pipes_utf8 -#define g_spawn_sync g_spawn_sync_utf8 -#define g_spawn_command_line_sync g_spawn_command_line_sync_utf8 -#define g_spawn_command_line_async g_spawn_command_line_async_utf8 - -GLIB_AVAILABLE_IN_ALL -gboolean g_spawn_async_utf8 (const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - GPid *child_pid, - GError **error); -GLIB_AVAILABLE_IN_ALL -gboolean g_spawn_async_with_pipes_utf8 (const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - GPid *child_pid, - gint *standard_input, - gint *standard_output, - gint *standard_error, - GError **error); -GLIB_AVAILABLE_IN_ALL -gboolean g_spawn_sync_utf8 (const gchar *working_directory, - gchar **argv, - gchar **envp, - GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, - gchar **standard_output, - gchar **standard_error, - gint *exit_status, - GError **error); - -GLIB_AVAILABLE_IN_ALL -gboolean g_spawn_command_line_sync_utf8 (const gchar *command_line, - gchar **standard_output, - gchar **standard_error, - gint *exit_status, - GError **error); -GLIB_AVAILABLE_IN_ALL -gboolean g_spawn_command_line_async_utf8 (const gchar *command_line, - GError **error); -#endif -#endif - G_END_DECLS #endif /* __G_SPAWN_H__ */