From 9042486dac38a2900c702dffd9372a8095d5cce3 Mon Sep 17 00:00:00 2001 From: Lukas Oberhuber Date: Sat, 15 Feb 2025 16:28:01 +0000 Subject: [PATCH] plugin, macos: Fix #12711, #12898 This fix does not cause the problems that the alternative fix caused (as detailed in #12898). --- app/plug-in/gimpplugin.c | 75 ++++++++++++++++++++++++++++++++-------- libgimpbase/gimpbase.def | 1 - libgimpbase/gimpwire.c | 36 ------------------- libgimpbase/gimpwire.h | 2 -- 4 files changed, 60 insertions(+), 54 deletions(-) diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c index f91f800dae..7753735425 100644 --- a/app/plug-in/gimpplugin.c +++ b/app/plug-in/gimpplugin.c @@ -43,6 +43,10 @@ #include #include +#ifdef __APPLE__ +#include +#endif + #if defined(G_OS_WIN32) || defined(G_WITH_CYGWIN) #define STRICT @@ -95,26 +99,30 @@ #include "gimp-intl.h" -static void gimp_plug_in_finalize (GObject *object); +static void gimp_plug_in_finalize (GObject *object); -static gboolean gimp_plug_in_recv_message (GIOChannel *channel, - GIOCondition cond, - gpointer data); -static gboolean gimp_plug_in_write (GIOChannel *channel, - const guint8 *buf, - gulong count, - gpointer data); -static gboolean gimp_plug_in_flush (GIOChannel *channel, - gpointer data); +static gboolean gimp_plug_in_recv_message (GIOChannel *channel, + GIOCondition cond, + gpointer data); +static gboolean gimp_plug_in_write (GIOChannel *channel, + const guint8 *buf, + gulong count, + gpointer data); +static gboolean gimp_plug_in_flush (GIOChannel *channel, + gpointer data); #if defined G_OS_WIN32 && defined WIN32_32BIT_DLL_FOLDER -static void gimp_plug_in_set_dll_directory (const gchar *path); +static void gimp_plug_in_set_dll_directory (const gchar *path); #endif #ifndef G_OS_WIN32 -static void gimp_plug_in_close_waitpid (GPid pid, - gint status, - GimpPlugIn *plug_in); +static void gimp_plug_in_close_waitpid (GPid pid, + gint status, + GimpPlugIn *plug_in); +#endif + +#ifdef __APPLE__ +static guint gimp_plug_in_wire_count_bytes_ready (GIOChannel *channel); #endif @@ -208,7 +216,7 @@ gimp_plug_in_recv_message (GIOChannel *channel, * else reads will hang, and the app appear non-responsive. */ - if (gimp_wire_count_bytes_ready (channel) < 4) + if (gimp_plug_in_wire_count_bytes_ready (channel) < 4) return TRUE; #endif @@ -407,6 +415,43 @@ gimp_plug_in_close_waitpid (GPid pid, } #endif +#ifdef __APPLE__ +/* Returns the count of bytes in the channel. + * Bytes that can be read without blocking. + * + * Returns zero on an IO error. + * Also may return zero if the channel is empty. + * + * Requires channel is a pipe open for reading. + * + * This should only be used in extraordinary situations. + * It is only for UNIX-like platforms; might not be portable to MSWindows. + * It can also be used for debugging the protocol, to know message lengths. + * + * Used on MacOS for a seeming bug in IO events. + * Usually, on an IO event on condition G_IO_IN, + * you can assume the pipe is not empty and a read will not block. + */ +static guint +gimp_plug_in_wire_count_bytes_ready (GIOChannel *channel) +{ + int err = 0; + guint result; + int fd; + + fd = g_io_channel_unix_get_fd (channel); + err = ioctl (fd, FIONREAD, &result); + if (err < 0) + { + g_warning ("%s ioctl failed.", G_STRFUNC); + result = 0; + } + + g_debug ("%s bytes ready: %d", G_STRFUNC, result); + return result; +} +#endif + /* public functions */ diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def index a43a1d6aaf..ceddf33dd6 100644 --- a/libgimpbase/gimpbase.def +++ b/libgimpbase/gimpbase.def @@ -273,7 +273,6 @@ EXPORTS gimp_value_take_double_array gimp_value_take_int32_array gimp_wire_clear_error - gimp_wire_count_bytes_ready gimp_wire_destroy gimp_wire_error gimp_wire_flush diff --git a/libgimpbase/gimpwire.c b/libgimpbase/gimpwire.c index 906b0c5b5c..02f060784f 100644 --- a/libgimpbase/gimpwire.c +++ b/libgimpbase/gimpwire.c @@ -21,7 +21,6 @@ #include #include -#include #include @@ -311,41 +310,6 @@ gimp_wire_destroy (GimpWireMessage *msg) (* handler->destroy_func) (msg); } -/* Returns the count of bytes in the channel. - * Bytes that can be read without blocking. - * - * Returns zero on an IO error. - * Also may return zero if the channel is empty. - * - * Requires channel is a pipe open for reading. - * - * This should only be used in extraordinary situations. - * It is only for UNIX-like platforms; might not be portable to MSWindows. - * It can also be used for debugging the protocol, to know message lengths. - * - * Used on MacOS for a seeming bug in IO events. - * Usually, on an IO event on condition G_IO_IN, - * you can assume the pipe is not empty and a read will not block. - */ -guint -gimp_wire_count_bytes_ready (GIOChannel *channel) -{ - int err = 0; - guint result; - int fd; - - fd = g_io_channel_unix_get_fd (channel); - err = ioctl (fd, FIONREAD, &result); - if (err < 0) - { - g_warning ("%s ioctl failed.", G_STRFUNC); - result = 0; - } - - g_debug ("%s bytes ready: %d", G_STRFUNC, result); - return result; -} - gboolean _gimp_wire_read_int64 (GIOChannel *channel, guint64 *data, diff --git a/libgimpbase/gimpwire.h b/libgimpbase/gimpwire.h index decb409a08..57f4c6c796 100644 --- a/libgimpbase/gimpwire.h +++ b/libgimpbase/gimpwire.h @@ -80,8 +80,6 @@ gboolean gimp_wire_write_msg (GIOChannel *channel, void gimp_wire_destroy (GimpWireMessage *msg); -guint gimp_wire_count_bytes_ready (GIOChannel *channel); - /* for internal use in libgimpbase */