summaryrefslogtreecommitdiff
path: root/Modules/readline.c
diff options
context:
space:
mode:
authorMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
committerMariatta Wijaya <mariatta.wijaya@gmail.com>2017-02-06 20:16:58 -0800
commitda79bcf8ac7ae72218ab023e1ed54390bc1a3a27 (patch)
tree74845e2dbd9521d9748b9c32f1922f4123083bf3 /Modules/readline.c
parente3c7e835bdfc97750eb9b7fc0ad2493108c2d438 (diff)
parent1fe806ac56f8b83694d24ab604eb695d00bc8497 (diff)
downloadcpython-da79bcf8ac7ae72218ab023e1ed54390bc1a3a27.tar.gz
Issue #29371: merge with 3.5
Diffstat (limited to 'Modules/readline.c')
-rw-r--r--Modules/readline.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/Modules/readline.c b/Modules/readline.c
index 54f15bc1c9..3b94d4a0d1 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -343,10 +343,8 @@ set_hook(const char *funcname, PyObject **hook_var, PyObject *args)
Py_CLEAR(*hook_var);
}
else if (PyCallable_Check(function)) {
- PyObject *tmp = *hook_var;
Py_INCREF(function);
- *hook_var = function;
- Py_XDECREF(tmp);
+ Py_XSETREF(*hook_var, function);
}
else {
PyErr_Format(PyExc_TypeError,
@@ -604,6 +602,24 @@ PyDoc_STRVAR(doc_add_history,
"add_history(string) -> None\n\
add an item to the history buffer");
+static int should_auto_add_history = 1;
+
+/* Enable or disable automatic history */
+
+static PyObject *
+py_set_auto_history(PyObject *self, PyObject *args)
+{
+ if (!PyArg_ParseTuple(args, "p:set_auto_history",
+ &should_auto_add_history)) {
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(doc_set_auto_history,
+"set_auto_history(enabled) -> None\n\
+Enables or disables automatic history.");
+
/* Get the tab-completion word-delimiters that readline uses */
@@ -822,6 +838,7 @@ static struct PyMethodDef readline_methods[] =
{"set_completer_delims", set_completer_delims,
METH_O, doc_set_completer_delims},
+ {"set_auto_history", py_set_auto_history, METH_VARARGS, doc_set_auto_history},
{"add_history", py_add_history, METH_O, doc_add_history},
{"remove_history_item", py_remove_history, METH_VARARGS, doc_remove_history},
{"replace_history_item", py_replace_history, METH_VARARGS, doc_replace_history},
@@ -857,7 +874,7 @@ on_hook(PyObject *func)
if (r == Py_None)
result = 0;
else {
- result = PyLong_AsLong(r);
+ result = _PyLong_AsInt(r);
if (result == -1 && PyErr_Occurred())
goto error;
}
@@ -1327,7 +1344,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
/* we have a valid line */
n = strlen(p);
- if (n > 0) {
+ if (should_auto_add_history && n > 0) {
const char *line;
int length = _py_get_history_length();
if (length > 0)