]> granicus.if.org Git - python/commitdiff
GNU readline() mistakenly sets the LC_CTYPE locale.
authorGuido van Rossum <guido@python.org>
Wed, 9 Oct 2002 21:27:33 +0000 (21:27 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 9 Oct 2002 21:27:33 +0000 (21:27 +0000)
This is evil.  Only the user or the app's main() should do this!
We must save and restore the locale around the rl_initialize() call.

Modules/readline.c

index a2efd47f626b32bd8c6351f439789d2f749d2488..59ae8eb37d94321c5710e551e0b21845a74d57de 100644 (file)
 #include <signal.h>
 #include <errno.h>
 
+#if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE)
+/* GNU readline() mistakenly sets the LC_CTYPE locale.
+ * This is evil.  Only the user or the app's main() should do this!
+ * We must save and restore the locale around the rl_initialize() call.
+ */
+#define SAVE_LOCALE
+#include <locale.h>
+#endif
+
 /* GNU readline definitions */
 #undef HAVE_CONFIG_H /* Else readline/chardefs.h includes strings.h */
 #include <readline/readline.h>
@@ -538,6 +547,10 @@ flex_complete(char *text, int start, int end)
 static void
 setup_readline(void)
 {
+#ifdef SAVE_LOCALE
+       char *saved_locale = setlocale(LC_CTYPE, NULL);
+#endif
+
        using_history();
 
        rl_readline_name = "python";
@@ -571,6 +584,10 @@ setup_readline(void)
         * inside this function.  Nothing we can do about it.
         */
        rl_initialize();
+
+#ifdef SAVE_LOCALE
+       setlocale(LC_CTYPE, saved_locale); /* Restore locale */
+#endif
 }