diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/if_py_both.h | 33 | ||||
-rw-r--r-- | src/testdir/test86.in | 10 | ||||
-rw-r--r-- | src/testdir/test86.ok | 7 | ||||
-rw-r--r-- | src/testdir/test87.in | 10 | ||||
-rw-r--r-- | src/testdir/test87.ok | 7 | ||||
-rw-r--r-- | src/version.c | 2 |
6 files changed, 52 insertions, 17 deletions
diff --git a/src/if_py_both.h b/src/if_py_both.h index 2ad19c406..7d3a26ebf 100644 --- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -312,36 +312,30 @@ OutputWrite(OutputObject *self, PyObject *args) static PyObject * OutputWritelines(OutputObject *self, PyObject *args) { - PyInt n; - PyInt i; - PyObject *list; + PyObject *seq; + PyObject *iterator; + PyObject *item; int error = self->error; - if (!PyArg_ParseTuple(args, "O", &list)) + if (!PyArg_ParseTuple(args, "O", &seq)) return NULL; - Py_INCREF(list); - if (!PyList_Check(list)) - { - PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings")); - Py_DECREF(list); + if (!(iterator = PyObject_GetIter(seq))) return NULL; - } - - n = PyList_Size(list); - for (i = 0; i < n; ++i) + while ((item = PyIter_Next(iterator))) { - PyObject *line = PyList_GetItem(list, i); char *str = NULL; PyInt len; - if (!PyArg_Parse(line, "et#", ENC_OPT, &str, &len)) + if (!PyArg_Parse(item, "et#", ENC_OPT, &str, &len)) { PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings")); - Py_DECREF(list); + Py_DECREF(iterator); + Py_DECREF(item); return NULL; } + Py_DECREF(item); Py_BEGIN_ALLOW_THREADS Python_Lock_Vim(); @@ -351,7 +345,12 @@ OutputWritelines(OutputObject *self, PyObject *args) PyMem_Free(str); } - Py_DECREF(list); + Py_DECREF(iterator); + + /* Iterator may have finished due to an exception */ + if (PyErr_Occurred()) + return NULL; + Py_INCREF(Py_None); return Py_None; } diff --git a/src/testdir/test86.in b/src/testdir/test86.in index 45c345f29..cf9768622 100644 --- a/src/testdir/test86.in +++ b/src/testdir/test86.in @@ -709,6 +709,16 @@ del name del o EOF :" +:" +:" Test stdout/stderr +:redir => messages +:py sys.stdout.write('abc') ; sys.stdout.write('def') +:py sys.stderr.write('abc') ; sys.stderr.write('def') +:py sys.stdout.writelines(iter('abc')) +:py sys.stderr.writelines(iter('abc')) +:redir END +:$put =string(substitute(messages, '\d\+', '', 'g')) +:" :" Test exceptions :fun Exe(e) : execute a:e diff --git a/src/testdir/test86.ok b/src/testdir/test86.ok index 0b79b0dbf..fb94c3af1 100644 --- a/src/testdir/test86.ok +++ b/src/testdir/test86.ok @@ -391,6 +391,13 @@ dictionary:__dir__,__members__,keys,locked,scope list:__dir__,__members__,extend,locked function:__call__,__dir__,__members__,softspace output:__dir__,__members__,flush,softspace,write,writelines +' +abcdef +line : +abcdef +abc +line : +abc' (<class 'vim.error'>, error('abc',)) (<class 'vim.error'>, error('def',)) (<class 'vim.error'>, error('ghi',)) diff --git a/src/testdir/test87.in b/src/testdir/test87.in index 210c055d7..b1763edc7 100644 --- a/src/testdir/test87.in +++ b/src/testdir/test87.in @@ -687,6 +687,16 @@ del name del o EOF :" +:" +:" Test stdout/stderr +:redir => messages +:py sys.stdout.write('abc') ; sys.stdout.write('def') +:py sys.stderr.write('abc') ; sys.stderr.write('def') +:py sys.stdout.writelines(iter('abc')) +:py sys.stderr.writelines(iter('abc')) +:redir END +:$put =string(substitute(messages, '\d\+', '', 'g')) +:" :" Test exceptions :fun Exe(e) : execute a:e diff --git a/src/testdir/test87.ok b/src/testdir/test87.ok index 3126fd36f..8ae7a8cb6 100644 --- a/src/testdir/test87.ok +++ b/src/testdir/test87.ok @@ -380,6 +380,13 @@ dictionary:__dir__,keys,locked,scope list:__dir__,extend,locked function:__call__,__dir__,softspace output:__dir__,flush,softspace,write,writelines +' +abcdef +line : +abcdef +abc +line : +abc' (<class 'vim.error'>, error('abc',)) (<class 'vim.error'>, error('def',)) (<class 'vim.error'>, error('ghi',)) diff --git a/src/version.c b/src/version.c index c33c1a687..4d5539a90 100644 --- a/src/version.c +++ b/src/version.c @@ -729,6 +729,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1057, +/**/ 1056, /**/ 1055, |