readline module cleanup
fixed indention to tabs use Py_RETURN_NONE macro added more error checks to on_completion_display_matches_hook open question: Does PyList_SetItem(l, i, o) steal a reference to o in the case of an error?
This commit is contained in:
parent
edc526c161
commit
1bc4af4bdd
|
@ -59,8 +59,7 @@ parse_and_bind(PyObject *self, PyObject *args)
|
|||
strcpy(copy, s);
|
||||
rl_parse_and_bind(copy);
|
||||
free(copy); /* Free the copy */
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_parse_and_bind,
|
||||
|
@ -79,8 +78,7 @@ read_init_file(PyObject *self, PyObject *args)
|
|||
errno = rl_read_init_file(s);
|
||||
if (errno)
|
||||
return PyErr_SetFromErrno(PyExc_IOError);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_read_init_file,
|
||||
|
@ -100,8 +98,7 @@ read_history_file(PyObject *self, PyObject *args)
|
|||
errno = read_history(s);
|
||||
if (errno)
|
||||
return PyErr_SetFromErrno(PyExc_IOError);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static int _history_length = -1; /* do not truncate history by default */
|
||||
|
@ -124,8 +121,7 @@ write_history_file(PyObject *self, PyObject *args)
|
|||
history_truncate_file(s, _history_length);
|
||||
if (errno)
|
||||
return PyErr_SetFromErrno(PyExc_IOError);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_write_history_file,
|
||||
|
@ -143,8 +139,7 @@ set_history_length(PyObject *self, PyObject *args)
|
|||
if (!PyArg_ParseTuple(args, "i:set_history_length", &length))
|
||||
return NULL;
|
||||
_history_length = length;
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(set_history_length_doc,
|
||||
|
@ -195,8 +190,7 @@ set_hook(const char *funcname, PyObject **hook_var, PyObject *args)
|
|||
PyErr_SetString(PyExc_TypeError, buf);
|
||||
return NULL;
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -325,8 +319,7 @@ set_completer_delims(PyObject *self, PyObject *args)
|
|||
}
|
||||
free((void*)rl_completer_word_break_characters);
|
||||
rl_completer_word_break_characters = strdup(break_chars);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_set_completer_delims,
|
||||
|
@ -360,8 +353,7 @@ py_remove_history(PyObject *self, PyObject *args)
|
|||
free(entry->data);
|
||||
free(entry);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_remove_history,
|
||||
|
@ -375,7 +367,8 @@ py_replace_history(PyObject *self, PyObject *args)
|
|||
char *line;
|
||||
HIST_ENTRY *old_entry;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number, &line)) {
|
||||
if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number,
|
||||
&line)) {
|
||||
return NULL;
|
||||
}
|
||||
if (entry_number < 0) {
|
||||
|
@ -397,8 +390,7 @@ py_replace_history(PyObject *self, PyObject *args)
|
|||
free(old_entry->data);
|
||||
free(old_entry);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_replace_history,
|
||||
|
@ -416,8 +408,7 @@ py_add_history(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
}
|
||||
add_history(line);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_add_history,
|
||||
|
@ -458,8 +449,7 @@ static PyObject *
|
|||
get_completer(PyObject *self, PyObject *noargs)
|
||||
{
|
||||
if (completer == NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
Py_INCREF(completer);
|
||||
return completer;
|
||||
|
@ -483,8 +473,7 @@ get_history_item(PyObject *self, PyObject *args)
|
|||
if ((hist_ent = history_get(idx)))
|
||||
return PyString_FromString(hist_ent->line);
|
||||
else {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -530,8 +519,7 @@ static PyObject *
|
|||
py_clear_history(PyObject *self, PyObject *noarg)
|
||||
{
|
||||
clear_history();
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_clear_history,
|
||||
|
@ -549,8 +537,7 @@ insert_text(PyObject *self, PyObject *args)
|
|||
if (!PyArg_ParseTuple(args, "s:insert_text", &s))
|
||||
return NULL;
|
||||
rl_insert_text(s);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_insert_text,
|
||||
|
@ -564,8 +551,7 @@ static PyObject *
|
|||
redisplay(PyObject *self, PyObject *noarg)
|
||||
{
|
||||
rl_redisplay();
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_redisplay,
|
||||
|
@ -682,33 +668,38 @@ on_completion_display_matches_hook(char **matches,
|
|||
int num_matches, int max_length)
|
||||
{
|
||||
int i;
|
||||
PyObject *m, *s;
|
||||
PyObject *r;
|
||||
PyObject *m=NULL, *s=NULL, *r=NULL;
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
#endif
|
||||
m = PyList_New(num_matches);
|
||||
if (m == NULL)
|
||||
goto error;
|
||||
for (i = 0; i < num_matches; i++) {
|
||||
s = PyString_FromString(matches[i+1]);
|
||||
PyList_SetItem(m, i, s);
|
||||
if (s == NULL)
|
||||
goto error;
|
||||
if (PyList_SetItem(m, i, s) == -1)
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = PyObject_CallFunction(completion_display_matches_hook,
|
||||
"sOi", matches[0], m, max_length);
|
||||
|
||||
Py_DECREF(m);
|
||||
Py_DECREF(m), m=NULL;
|
||||
|
||||
if (r == NULL ||
|
||||
(r != Py_None && PyInt_AsLong(r) == -1 && PyErr_Occurred())) {
|
||||
goto error;
|
||||
}
|
||||
Py_XDECREF(r), r=NULL;
|
||||
|
||||
Py_DECREF(r);
|
||||
goto done;
|
||||
if (0) {
|
||||
error:
|
||||
PyErr_Clear();
|
||||
Py_XDECREF(m);
|
||||
Py_XDECREF(r);
|
||||
done:
|
||||
}
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_Release(gilstate);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue