[Commits] SDL: linux: Don't crash if fcitx support is requested but unavai...

libsdl.org revision control commits-owner at libsdl.org
Mon May 29 00:05:51 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/dc895d39212c
changeset: 11053:dc895d39212c
user:      Ryan C. Gordon <icculus at icculus.org>
date:      Mon May 29 02:48:51 2017 -0400
description:
linux: Don't crash if fcitx support is requested but unavailable.

Fixes Bugzilla #3642.

diffstat:

 src/core/linux/SDL_fcitx.c |  17 ++++++++++-------
 src/core/linux/SDL_ime.c   |  16 ++++++++++++++--
 2 files changed, 24 insertions(+), 9 deletions(-)

diffs (75 lines):

diff -r 0666dea591ab -r dc895d39212c src/core/linux/SDL_fcitx.c
--- a/src/core/linux/SDL_fcitx.c	Mon May 29 00:51:38 2017 -0400
+++ b/src/core/linux/SDL_fcitx.c	Mon May 29 02:48:51 2017 -0400
@@ -188,7 +188,7 @@
     SDL_DBus_CallVoidMethod(client->servicename, client->icname, FCITX_IC_DBUS_INTERFACE, "SetCapacity", DBUS_TYPE_UINT32, &caps, DBUS_TYPE_INVALID);
 }
 
-static void
+static SDL_bool
 FcitxClientCreateIC(FcitxClient *client)
 {
     char *appname = GetAppName();
@@ -196,9 +196,11 @@
     int id = -1;
     Uint32 enable, arg1, arg2, arg3, arg4;
 
-    SDL_DBus_CallMethod(client->servicename, FCITX_IM_DBUS_PATH, FCITX_IM_DBUS_INTERFACE, "CreateICv3",
-        DBUS_TYPE_STRING, &appname, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID,
-        DBUS_TYPE_INT32, &id, DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_UINT32, &arg1, DBUS_TYPE_UINT32, &arg2, DBUS_TYPE_UINT32, &arg3, DBUS_TYPE_UINT32, &arg4, DBUS_TYPE_INVALID);
+    if (!SDL_DBus_CallMethod(client->servicename, FCITX_IM_DBUS_PATH, FCITX_IM_DBUS_INTERFACE, "CreateICv3",
+            DBUS_TYPE_STRING, &appname, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID,
+            DBUS_TYPE_INT32, &id, DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_UINT32, &arg1, DBUS_TYPE_UINT32, &arg2, DBUS_TYPE_UINT32, &arg3, DBUS_TYPE_UINT32, &arg4, DBUS_TYPE_INVALID)) {
+        id = -1;  /* just in case. */
+    }
 
     SDL_free(appname);
 
@@ -218,7 +220,10 @@
         dbus->connection_flush(dbus->session_conn);
 
         SDL_AddHintCallback(SDL_HINT_IME_INTERNAL_EDITING, &Fcitx_SetCapabilities, client);
+        return SDL_TRUE;
     }
+
+    return SDL_FALSE;
 }
 
 static Uint32
@@ -252,9 +257,7 @@
             "%s-%d",
             FCITX_DBUS_SERVICE, GetDisplayNumber());
 
-    FcitxClientCreateIC(&fcitx_client);
-
-    return SDL_TRUE;
+    return FcitxClientCreateIC(&fcitx_client);
 }
 
 void
diff -r 0666dea591ab -r dc895d39212c src/core/linux/SDL_ime.c
--- a/src/core/linux/SDL_ime.c	Mon May 29 00:51:38 2017 -0400
+++ b/src/core/linux/SDL_ime.c	Mon May 29 02:48:51 2017 -0400
@@ -87,8 +87,20 @@
 {
     InitIME();
 
-    if (SDL_IME_Init_Real)
-        return SDL_IME_Init_Real();
+    if (SDL_IME_Init_Real) {
+        if (SDL_IME_Init_Real()) {
+            return SDL_TRUE;
+        }
+
+        /* uhoh, the IME implementation's init failed! Disable IME support. */
+        SDL_IME_Init_Real = NULL;
+        SDL_IME_Quit_Real = NULL;
+        SDL_IME_SetFocus_Real = NULL;
+        SDL_IME_Reset_Real = NULL;
+        SDL_IME_ProcessKeyEvent_Real = NULL;
+        SDL_IME_UpdateTextRect_Real = NULL;
+        SDL_IME_PumpEvents_Real = NULL;
+    }
 
     return SDL_FALSE;
 }


More information about the commits mailing list