From 6641e291ee27fcac101ab097fdc959cf584bdc82 Mon Sep 17 00:00:00 2001
From: Yamashita Yuu <yamashita@geishatokyo.com>
Date: Sat, 29 Mar 2014 16:04:43 +0900
Subject: [PATCH 1/5] Fix build problem of CPython 2.7 with Readline 6.3 (#126,
 #131, #149)

The patch was taken from latest changes in CPython 2.7

* http://hg.python.org/cpython/rev/79b82ebc4fd1
* http://hg.python.org/cpython/rev/5e42e5764ac6
* http://hg.python.org/cpython/rev/0b5b0bfcc7b1
---
 .../2.7.1/Python-2.7.1/002_readline63.patch   | 61 +++++++++++++++++++
 .../2.7.2/Python-2.7.2/002_readline63.patch   | 61 +++++++++++++++++++
 .../2.7.3/Python-2.7.3/002_readline63.patch   | 61 +++++++++++++++++++
 .../2.7.4/Python-2.7.4/002_readline63.patch   | 61 +++++++++++++++++++
 .../2.7.5/Python-2.7.5/002_readline63.patch   | 61 +++++++++++++++++++
 .../2.7.6/Python-2.7.6/002_readline63.patch   | 61 +++++++++++++++++++
 .../2.7/Python-2.7/002_readline63.patch       | 61 +++++++++++++++++++
 7 files changed, 427 insertions(+)
 create mode 100644 plugins/python-build/share/python-build/patches/2.7.1/Python-2.7.1/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/2.7.2/Python-2.7.2/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/2.7.3/Python-2.7.3/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/2.7.4/Python-2.7.4/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/2.7.5/Python-2.7.5/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/2.7.6/Python-2.7.6/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/2.7/Python-2.7/002_readline63.patch

diff --git a/plugins/python-build/share/python-build/patches/2.7.1/Python-2.7.1/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.7.1/Python-2.7.1/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.7.1/Python-2.7.1/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/2.7.2/Python-2.7.2/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.7.2/Python-2.7.2/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.7.2/Python-2.7.2/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/2.7.3/Python-2.7.3/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.7.3/Python-2.7.3/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.7.3/Python-2.7.3/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/2.7.4/Python-2.7.4/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.7.4/Python-2.7.4/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.7.4/Python-2.7.4/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/2.7.5/Python-2.7.5/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.7.5/Python-2.7.5/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.7.5/Python-2.7.5/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/2.7.6/Python-2.7.6/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.7.6/Python-2.7.6/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.7.6/Python-2.7.6/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/2.7/Python-2.7/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.7/Python-2.7/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.7/Python-2.7/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =

From cce1960de0c24254f3726a585f77c8422522795c Mon Sep 17 00:00:00 2001
From: Yamashita Yuu <yamashita@geishatokyo.com>
Date: Sat, 29 Mar 2014 16:11:03 +0900
Subject: [PATCH 2/5] Fix build problem of CPython 2.6 with Readline 6.3 (#126,
 #131, #149)

---
 .../2.6.6/Python-2.6.6/002_readline63.patch   | 61 +++++++++++++++++++
 .../2.6.7/Python-2.6.7/002_readline63.patch   | 61 +++++++++++++++++++
 .../2.6.8/Python-2.6.8/002_readline63.patch   | 61 +++++++++++++++++++
 .../2.6.9/Python-2.6.9/002_readline63.patch   | 61 +++++++++++++++++++
 4 files changed, 244 insertions(+)
 create mode 100644 plugins/python-build/share/python-build/patches/2.6.6/Python-2.6.6/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/2.6.7/Python-2.6.7/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/2.6.8/Python-2.6.8/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/2.6.9/Python-2.6.9/002_readline63.patch

diff --git a/plugins/python-build/share/python-build/patches/2.6.6/Python-2.6.6/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.6.6/Python-2.6.6/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.6.6/Python-2.6.6/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/2.6.7/Python-2.6.7/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.6.7/Python-2.6.7/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.6.7/Python-2.6.7/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/2.6.8/Python-2.6.8/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.6.8/Python-2.6.8/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.6.8/Python-2.6.8/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/2.6.9/Python-2.6.9/002_readline63.patch b/plugins/python-build/share/python-build/patches/2.6.9/Python-2.6.9/002_readline63.patch
new file mode 100644
index 00000000..6d0eb195
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/2.6.9/Python-2.6.9/002_readline63.patch
@@ -0,0 +1,61 @@
+diff -r -u ../Python-2.7.6.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-2.7.6.orig/Modules/readline.c	2013-11-10 16:36:41.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:17:48.643305752 +0900
+@@ -206,8 +206,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -750,14 +749,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -852,7 +859,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -911,12 +918,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =

From 3136fce0c03b2d6670e3038aeaf5d23de02bb080 Mon Sep 17 00:00:00 2001
From: Yamashita Yuu <yamashita@geishatokyo.com>
Date: Sat, 29 Mar 2014 16:28:55 +0900
Subject: [PATCH 3/5] Fix build problem of CPython 3.3 with Readline 6.3 (#126,
 #131, #149)

The patch was taken from CPython 3.3.5
---
 .../3.3.0/Python-3.3.0/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.3.1/Python-3.3.1/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.3.2/Python-3.3.2/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.3.3/Python-3.3.3/002_readline63.patch   | 70 +++++++++++++++++++
 4 files changed, 280 insertions(+)
 create mode 100644 plugins/python-build/share/python-build/patches/3.3.0/Python-3.3.0/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.3.1/Python-3.3.1/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.3.2/Python-3.3.2/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.3.3/Python-3.3.3/002_readline63.patch

diff --git a/plugins/python-build/share/python-build/patches/3.3.0/Python-3.3.0/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.3.0/Python-3.3.0/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.3.0/Python-3.3.0/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.3.1/Python-3.3.1/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.3.1/Python-3.3.1/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.3.1/Python-3.3.1/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.3.2/Python-3.3.2/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.3.2/Python-3.3.2/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.3.2/Python-3.3.2/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.3.3/Python-3.3.3/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.3.3/Python-3.3.3/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.3.3/Python-3.3.3/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =

From 2da9bfd1f87fecb92111e8735389e6ddfe67e53c Mon Sep 17 00:00:00 2001
From: Yamashita Yuu <yamashita@geishatokyo.com>
Date: Sat, 29 Mar 2014 16:34:44 +0900
Subject: [PATCH 4/5] Fix build problem of CPython 3.2 with Readline 6.3 (#126,
 #131, #149)

---
 .../3.2.1/Python-3.2.1/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.2.2/Python-3.2.2/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.2.3/Python-3.2.3/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.2.4/Python-3.2.4/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.2.5/Python-3.2.5/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.2/Python-3.2/002_readline63.patch       | 70 +++++++++++++++++++
 6 files changed, 420 insertions(+)
 create mode 100644 plugins/python-build/share/python-build/patches/3.2.1/Python-3.2.1/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.2.2/Python-3.2.2/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.2.3/Python-3.2.3/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.2.4/Python-3.2.4/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.2.5/Python-3.2.5/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.2/Python-3.2/002_readline63.patch

diff --git a/plugins/python-build/share/python-build/patches/3.2.1/Python-3.2.1/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.2.1/Python-3.2.1/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.2.1/Python-3.2.1/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.2.2/Python-3.2.2/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.2.2/Python-3.2.2/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.2.2/Python-3.2.2/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.2.3/Python-3.2.3/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.2.3/Python-3.2.3/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.2.3/Python-3.2.3/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.2.4/Python-3.2.4/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.2.4/Python-3.2.4/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.2.4/Python-3.2.4/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.2.5/Python-3.2.5/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.2.5/Python-3.2.5/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.2.5/Python-3.2.5/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.2/Python-3.2/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.2/Python-3.2/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.2/Python-3.2/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =

From d737ae9f031cdc948ce316283ab7752f35aa09a0 Mon Sep 17 00:00:00 2001
From: Yamashita Yuu <yamashita@geishatokyo.com>
Date: Sat, 29 Mar 2014 16:41:26 +0900
Subject: [PATCH 5/5] Fix build problem of CPython 3.1 with Readline 6.3 (#126,
 #131, #149)

---
 .../3.1.3/Python-3.1.3/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.1.4/Python-3.1.4/002_readline63.patch   | 70 +++++++++++++++++++
 .../3.1.5/Python-3.1.5/002_readline63.patch   | 70 +++++++++++++++++++
 3 files changed, 210 insertions(+)
 create mode 100644 plugins/python-build/share/python-build/patches/3.1.3/Python-3.1.3/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.1.4/Python-3.1.4/002_readline63.patch
 create mode 100644 plugins/python-build/share/python-build/patches/3.1.5/Python-3.1.5/002_readline63.patch

diff --git a/plugins/python-build/share/python-build/patches/3.1.3/Python-3.1.3/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.1.3/Python-3.1.3/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.1.3/Python-3.1.3/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.1.4/Python-3.1.4/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.1.4/Python-3.1.4/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.1.4/Python-3.1.4/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =
diff --git a/plugins/python-build/share/python-build/patches/3.1.5/Python-3.1.5/002_readline63.patch b/plugins/python-build/share/python-build/patches/3.1.5/Python-3.1.5/002_readline63.patch
new file mode 100644
index 00000000..ed296265
--- /dev/null
+++ b/plugins/python-build/share/python-build/patches/3.1.5/Python-3.1.5/002_readline63.patch
@@ -0,0 +1,70 @@
+diff -r -u ../Python-3.3.3.orig/Modules/readline.c ./Modules/readline.c
+--- ../Python-3.3.3.orig/Modules/readline.c	2013-11-17 16:23:01.000000000 +0900
++++ ./Modules/readline.c	2014-03-29 16:22:10.219305878 +0900
+@@ -231,8 +231,7 @@
+     if (!PyArg_ParseTuple(args, buf, &function))
+         return NULL;
+     if (function == Py_None) {
+-        Py_XDECREF(*hook_var);
+-        *hook_var = NULL;
++        Py_CLEAR(*hook_var);
+     }
+     else if (PyCallable_Check(function)) {
+         PyObject *tmp = *hook_var;
+@@ -774,14 +773,22 @@
+ }
+ 
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_startup_hook(void)
++#else
++on_startup_hook()
++#endif
+ {
+     return on_hook(startup_hook);
+ }
+ 
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+ static int
++#if defined(_RL_FUNCTION_TYPEDEF)
+ on_pre_input_hook(void)
++#else
++on_pre_input_hook()
++#endif
+ {
+     return on_hook(pre_input_hook);
+ }
+@@ -819,7 +826,7 @@
+         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
+         goto error;
+     }
+-    Py_XDECREF(r); r=NULL;
++    Py_CLEAR(r);
+ 
+     if (0) {
+     error:
+@@ -877,7 +884,7 @@
+  * before calling the normal completer */
+ 
+ static char **
+-flex_complete(char *text, int start, int end)
++flex_complete(const char *text, int start, int end)
+ {
+ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+     rl_completion_append_character ='\0';
+@@ -936,12 +943,12 @@
+     rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
+     rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
+     /* Set our hook functions */
+-    rl_startup_hook = (Function *)on_startup_hook;
++    rl_startup_hook = on_startup_hook;
+ #ifdef HAVE_RL_PRE_INPUT_HOOK
+-    rl_pre_input_hook = (Function *)on_pre_input_hook;
++    rl_pre_input_hook = on_pre_input_hook;
+ #endif
+     /* Set our completion function */
+-    rl_attempted_completion_function = (CPPFunction *)flex_complete;
++    rl_attempted_completion_function = flex_complete;
+     /* Set Python word break characters */
+     completer_word_break_characters =
+         rl_completer_word_break_characters =