summaryrefslogtreecommitdiffstats
path: root/Modules/readline.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-05-06 19:54:07 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-05-06 19:54:07 (GMT)
commit9b5d4d8cef6c465292f02105b5e408eb5f7db01d (patch)
treeb80834a4b6f73372cff6de69ffd1cd9252b53f34 /Modules/readline.c
parentb1294fa9f4063ceba827ec739269cbeb0941be4f (diff)
parenta7f7deb6eddc666aee507c04633d95ed78e289e0 (diff)
downloadcpython-9b5d4d8cef6c465292f02105b5e408eb5f7db01d.zip
cpython-9b5d4d8cef6c465292f02105b5e408eb5f7db01d.tar.gz
cpython-9b5d4d8cef6c465292f02105b5e408eb5f7db01d.tar.bz2
Issue #17289: The readline module now plays nicer with external modules or applications changing the rl_completer_word_break_characters global variable.
Initial patch by Bradley Froehle.
Diffstat (limited to 'Modules/readline.c')
-rw-r--r--Modules/readline.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/Modules/readline.c b/Modules/readline.c
index 0d99dc9..5a14b59 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -70,6 +70,10 @@ on_completion_display_matches_hook(char **matches,
int num_matches, int max_length);
#endif
+/* Memory allocated for rl_completer_word_break_characters
+ (see issue #17289 for the motivation). */
+static char *completer_word_break_characters;
+
/* Exported function to send one line to readline's init file parser */
static PyObject *
@@ -368,12 +372,20 @@ set_completer_delims(PyObject *self, PyObject *args)
{
char *break_chars;
- if(!PyArg_ParseTuple(args, "s:set_completer_delims", &break_chars)) {
+ if (!PyArg_ParseTuple(args, "s:set_completer_delims", &break_chars)) {
return NULL;
}
- free((void*)rl_completer_word_break_characters);
- rl_completer_word_break_characters = strdup(break_chars);
- Py_RETURN_NONE;
+ /* Keep a reference to the allocated memory in the module state in case
+ some other module modifies rl_completer_word_break_characters
+ (see issue #17289). */
+ free(completer_word_break_characters);
+ completer_word_break_characters = strdup(break_chars);
+ if (completer_word_break_characters) {
+ rl_completer_word_break_characters = completer_word_break_characters;
+ Py_RETURN_NONE;
+ }
+ else
+ return PyErr_NoMemory();
}
PyDoc_STRVAR(doc_set_completer_delims,
@@ -914,7 +926,8 @@ setup_readline(void)
/* Set our completion function */
rl_attempted_completion_function = (CPPFunction *)flex_complete;
/* Set Python word break characters */
- rl_completer_word_break_characters =
+ completer_word_break_characters =
+ rl_completer_word_break_characters =
strdup(" \t\n`~!@#$%^&*()-=+[{]}\\|;:'\",<>/?");
/* All nonalphanums except '.' */
@@ -1170,8 +1183,6 @@ PyInit_readline(void)
if (m == NULL)
return NULL;
-
-
PyOS_ReadlineFunctionPointer = call_readline;
setup_readline();
return m;