]> granicus.if.org Git - vim/commitdiff
updated for version 7.3.1226 v7.3.1226
authorBram Moolenaar <Bram@vim.org>
Sun, 23 Jun 2013 10:51:32 +0000 (12:51 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 23 Jun 2013 10:51:32 +0000 (12:51 +0200)
Problem:    Python: duplicate code.
Solution:   Share code between OutputWrite() and OutputWritelines(). (ZyX)

src/if_py_both.h
src/testdir/test86.ok
src/testdir/test87.ok
src/version.c

index 9acb3105b2bc8b7f279fd8233617456ff7b06815..164e2a42aa293ec80e7bb0293d4e9e4076e70787 100644 (file)
@@ -281,15 +281,15 @@ writer(writefn fn, char_u *str, PyInt n)
     }
 }
 
-    static PyObject *
-OutputWrite(OutputObject *self, PyObject *args)
+    static int
+write_output(OutputObject *self, PyObject *string)
 {
-    Py_ssize_t len = 0;
-    char *str = NULL;
-    int error = self->error;
+    Py_ssize_t len = 0;
+    char       *str = NULL;
+    int                error = self->error;
 
-    if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len))
-       return NULL;
+    if (!PyArg_Parse(string, "et#", ENC_OPT, &str, &len))
+       return -1;
 
     Py_BEGIN_ALLOW_THREADS
     Python_Lock_Vim();
@@ -298,44 +298,37 @@ OutputWrite(OutputObject *self, PyObject *args)
     Py_END_ALLOW_THREADS
     PyMem_Free(str);
 
+    return 0;
+}
+
+    static PyObject *
+OutputWrite(OutputObject *self, PyObject *string)
+{
+    if (write_output(self, string))
+       return NULL;
+
     Py_INCREF(Py_None);
     return Py_None;
 }
 
     static PyObject *
-OutputWritelines(OutputObject *self, PyObject *args)
+OutputWritelines(OutputObject *self, PyObject *seq)
 {
-    PyObject   *seq;
     PyObject   *iterator;
     PyObject   *item;
-    int error = self->error;
-
-    if (!PyArg_ParseTuple(args, "O", &seq))
-       return NULL;
 
     if (!(iterator = PyObject_GetIter(seq)))
        return NULL;
 
     while ((item = PyIter_Next(iterator)))
     {
-       char *str = NULL;
-       PyInt len;
-
-       if (!PyArg_Parse(item, "et#", ENC_OPT, &str, &len))
+       if (write_output(self, item))
        {
-           PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
            Py_DECREF(iterator);
            Py_DECREF(item);
            return NULL;
        }
        Py_DECREF(item);
-
-       Py_BEGIN_ALLOW_THREADS
-       Python_Lock_Vim();
-       writer((writefn)(error ? emsg : msg), (char_u *)str, len);
-       Python_Release_Vim();
-       Py_END_ALLOW_THREADS
-       PyMem_Free(str);
     }
 
     Py_DECREF(iterator);
@@ -360,8 +353,8 @@ OutputFlush(PyObject *self UNUSED)
 
 static struct PyMethodDef OutputMethods[] = {
     /* name,       function,                           calling,        doc */
-    {"write",      (PyCFunction)OutputWrite,           METH_VARARGS,   ""},
-    {"writelines",  (PyCFunction)OutputWritelines,     METH_VARARGS,   ""},
+    {"write",      (PyCFunction)OutputWrite,           METH_O,         ""},
+    {"writelines",  (PyCFunction)OutputWritelines,     METH_O,         ""},
     {"flush",      (PyCFunction)OutputFlush,           METH_NOARGS,    ""},
     {"__dir__",            (PyCFunction)OutputDir,             METH_NOARGS,    ""},
     { NULL,        NULL,                               0,              NULL}
@@ -3009,7 +3002,8 @@ TabListItem(PyObject *self UNUSED, PyInt n)
     return NULL;
 }
 
-/* Window object
+/*
+ * Window object
  */
 
 typedef struct
index a4f1ac405130994b3cb45bc6c7d346d28d9d04b8..05d194338b7220d79142d3d548110ab2016c5926 100644 (file)
@@ -444,7 +444,7 @@ sys.stdout.attr = None:AttributeError:('invalid attribute',)
 sys.stdout.write(None):TypeError:('coercing to Unicode: need string or buffer, NoneType found',)
 >> OutputWriteLines
 sys.stdout.writelines(None):TypeError:("'NoneType' object is not iterable",)
-sys.stdout.writelines([1]):TypeError:('writelines() requires list of strings',)
+sys.stdout.writelines([1]):TypeError:('coercing to Unicode: need string or buffer, int found',)
 > VimCommand
 vim.command(1):TypeError:('must be string, not int',)
 > VimToPython
index 1d4044519dfb1f41e913b37537b6340dacca752d..414dc9e424193644ba2c417db333d48ce6a4ee44 100644 (file)
@@ -433,7 +433,7 @@ sys.stdout.attr = None:(<class 'AttributeError'>, AttributeError('invalid attrib
 sys.stdout.write(None):(<class 'TypeError'>, TypeError("Can't convert 'NoneType' object to str implicitly",))
 >> OutputWriteLines
 sys.stdout.writelines(None):(<class 'TypeError'>, TypeError("'NoneType' object is not iterable",))
-sys.stdout.writelines([1]):(<class 'TypeError'>, TypeError('writelines() requires list of strings',))
+sys.stdout.writelines([1]):(<class 'TypeError'>, TypeError("Can't convert 'int' object to str implicitly",))
 >>> Testing *Iter* using sys.stdout.writelines(%s)
 sys.stdout.writelines(FailingIter()):(<class 'NotImplementedError'>, NotImplementedError())
 sys.stdout.writelines(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError())
index 4d2e7a9625a45522c302504c10c089e731226a60..8e33ab62137a2936c707c6f859868e8085f4f47b 100644 (file)
@@ -728,6 +728,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1226,
 /**/
     1225,
 /**/