Author: yamakenz
Date: Mon Feb 11 03:45:59 2008
New Revision: 5155

Modified:
  trunk/uim/Makefile.am
  trunk/uim/uim-error.c
  trunk/uim/uim-internal.h
  trunk/uim/uim-notify.c

Log:
* uim/uim-error.c
 - Cooperate with uim-notify iff UIM_USE_NOTIFY and compiled for libuim
 - (ERRMSG_UIM_HAS_BEEN_DISABLED): New macro
 - (print_caught_error): Fix uim-notify cooperation
* uim/uim-internal.h
 - (uim_notify_fatal_raw): New function decl
* uim/uim-notify.c
 - (uim_notify_fatal_raw): New function
 - (uim_notify_stderr_info, uim_notify_stderr_fatal):
   * Remove the inappropriate FIXME comment by my misrecognition
   * Replace fprintf() with fputs()s to reduce stack consumption
* uim/Makefile.am
 - (uim_helper_server_CPPFLAGS): Add -DUIM_NON_LIBUIM_PROG as
   uim-notify workaround for uim-error.c combined with non-libuim
   program


Modified: trunk/uim/Makefile.am
==============================================================================
--- trunk/uim/Makefile.am       (original)
+++ trunk/uim/Makefile.am       Mon Feb 11 03:45:59 2008
@@ -203,6 +203,8 @@

uim_helper_server_LIBS =
uim_helper_server_CPPFLAGS = $(uim_defs) -I$(top_srcdir)
+# uim-notify workaround for uim-error.c combined with non-libuim program
+uim_helper_server_CPPFLAGS += -DUIM_NON_LIBUIM_PROG
uim_helper_server_CFLAGS =
uim_helper_server_SOURCES = uim-helper.c uim-helper-server.c uim-error.c
uim_helper_server_LDADD = $(top_builddir)/replace/libreplace.la

Modified: trunk/uim/uim-error.c
==============================================================================
--- trunk/uim/uim-error.c       (original)
+++ trunk/uim/uim-error.c       Mon Feb 11 03:45:59 2008
@@ -43,7 +43,7 @@

#include "uim.h"
#include "uim-internal.h"
-#if 0 /* FIXME: temporarily disabled -- YamaKen 2008-01-15 */
+#if UIM_USE_NOTIFY && !UIM_NON_LIBUIM_PROG
#include "uim-notify.h"
#endif

@@ -52,6 +52,9 @@
#define EX_SOFTWARE 70
#endif

+#define ERRMSG_UIM_HAS_BEEN_DISABLED                                   \
+  "All functionality has been disabled to save user application data."
+
static void print_caught_error(void);

/* Immediately returns UIM_TRUE if uim is disabled by a fatal error. */
@@ -77,23 +80,32 @@
print_caught_error(void)
{
  if (err_msg) {
-#if 0 /* FIXME: temporarily disabled -- YamaKen 2008-01-15 */
-    /* Since this function will also be called on hard situations such
-     * as memory exhaustion, this uim_notify_fatal() call need a
-     * careful review. I'll do it until uim 1.5.0.
-     *   -- YamaKen 2008-01-15 */
- uim_notify_fatal(err_msg); /* XXX: stdout messges will be duplicated */
-#else
+    /* Print the error to stderr first. */
    fputs("libuim: ", stderr);
    if (fatal_errored)
-      fputs("fatal error: ", stderr);
+      fputs("[fatal] ", stderr);
    fputs(err_msg, stderr);
    fputs("\n", stderr);
    if (fatal_errored) {
- fputs("libuim: all functionality has been disabled to save user application data", stderr);
+      fputs("libuim: " ERRMSG_UIM_HAS_BEEN_DISABLED, stderr);
      fputs("\n", stderr);
    }
-#endif
+
+ /* And notify user of it via uim-notify in addition to the stderr msg. */
+#if UIM_USE_NOTIFY && !UIM_NON_LIBUIM_PROG
+    /* Since this function will also be called on hard situations such
+     * as memory exhaustion, these uim_notify_*() calls may be failed
+     * to notify user of the error, due to the memory shortage.
+     *   -- YamaKen 2008-02-11 */
+
+    /* XXX: stderr messges will be duplicated */
+    if (fatal_errored) {
+      uim_notify_fatal_raw(err_msg);
+      uim_notify_fatal_raw(ERRMSG_UIM_HAS_BEEN_DISABLED);
+    } else {
+      uim_notify_info(err_msg);
+    }
+#endif  /* UIM_USE_NOTIFY */
  }
}


Modified: trunk/uim/uim-internal.h
==============================================================================
--- trunk/uim/uim-internal.h    (original)
+++ trunk/uim/uim-internal.h    Mon Feb 11 03:45:59 2008
@@ -163,7 +163,9 @@
void uim_init_rk_subrs(void);
void uim_init_intl_subrs(void);

-#if !UIM_USE_NOTIFY
+#if UIM_USE_NOTIFY
+int uim_notify_fatal_raw(const char *msg);
+#else
/* FIXME: Output to stderr */
#define uim_notify_info printf
#define uim_notify_fatal printf

Modified: trunk/uim/uim-notify.c
==============================================================================
--- trunk/uim/uim-notify.c      (original)
+++ trunk/uim/uim-notify.c      Mon Feb 11 03:45:59 2008
@@ -208,6 +208,13 @@
  return agent->notify_fatal(msg);
}

+/* Low stack-consumption version of uim_notify_fatal(). */
+int
+uim_notify_fatal_raw(const char *msg)
+{
+  return agent->notify_fatal(msg);
+}
+
/*
 * Scheme interfaces
 */
@@ -346,17 +353,25 @@
  return;
}

-/* FIXME: accept extra args */
static int
uim_notify_stderr_info(const char *msg)
{
-  return fprintf(stderr, "uim [Info]: %s\n", msg);
+  fputs("libuim: [info] ", stderr);
+  fputs(msg, stderr);
+  fputs("\n", stderr);
+
+  return UIM_TRUE;
}

-/* FIXME: accept extra args */
static int
uim_notify_stderr_fatal(const char *msg)
{
-  return fprintf(stderr, "uim [Fatal]: %s\n", msg);
-}
+  /* To reduce stack consumption on hard situations such as memory
+   * exhaustion, printf()s with indirect directives are intentionally
+   * avoided here.  -- YamaKen 2008-02-11 */
+  fputs("libuim: [fatal] ", stderr);
+  fputs(msg, stderr);
+  fputs("\n", stderr);

+  return UIM_TRUE;
+}

Reply via email to