@@ -281,15 +281,15 @@ writer(writefn fn, char_u *str, PyInt n)
281281 }
282282}
283283
284- static PyObject *
285- OutputWrite (OutputObject * self , PyObject * args )
284+ static int
285+ write_output (OutputObject * self , PyObject * string )
286286{
287- Py_ssize_t len = 0 ;
288- char * str = NULL ;
289- int error = self -> error ;
287+ Py_ssize_t len = 0 ;
288+ char * str = NULL ;
289+ int error = self -> error ;
290290
291- if (!PyArg_ParseTuple ( args , "et#" , ENC_OPT , & str , & len ))
292- return NULL ;
291+ if (!PyArg_Parse ( string , "et#" , ENC_OPT , & str , & len ))
292+ return -1 ;
293293
294294 Py_BEGIN_ALLOW_THREADS
295295 Python_Lock_Vim ();
@@ -298,44 +298,37 @@ OutputWrite(OutputObject *self, PyObject *args)
298298 Py_END_ALLOW_THREADS
299299 PyMem_Free (str );
300300
301+ return 0 ;
302+ }
303+
304+ static PyObject *
305+ OutputWrite (OutputObject * self , PyObject * string )
306+ {
307+ if (write_output (self , string ))
308+ return NULL ;
309+
301310 Py_INCREF (Py_None );
302311 return Py_None ;
303312}
304313
305314 static PyObject *
306- OutputWritelines (OutputObject * self , PyObject * args )
315+ OutputWritelines (OutputObject * self , PyObject * seq )
307316{
308- PyObject * seq ;
309317 PyObject * iterator ;
310318 PyObject * item ;
311- int error = self -> error ;
312-
313- if (!PyArg_ParseTuple (args , "O" , & seq ))
314- return NULL ;
315319
316320 if (!(iterator = PyObject_GetIter (seq )))
317321 return NULL ;
318322
319323 while ((item = PyIter_Next (iterator )))
320324 {
321- char * str = NULL ;
322- PyInt len ;
323-
324- if (!PyArg_Parse (item , "et#" , ENC_OPT , & str , & len ))
325+ if (write_output (self , item ))
325326 {
326- PyErr_SetString (PyExc_TypeError , _ ("writelines() requires list of strings" ));
327327 Py_DECREF (iterator );
328328 Py_DECREF (item );
329329 return NULL ;
330330 }
331331 Py_DECREF (item );
332-
333- Py_BEGIN_ALLOW_THREADS
334- Python_Lock_Vim ();
335- writer ((writefn )(error ? emsg : msg ), (char_u * )str , len );
336- Python_Release_Vim ();
337- Py_END_ALLOW_THREADS
338- PyMem_Free (str );
339332 }
340333
341334 Py_DECREF (iterator );
@@ -360,8 +353,8 @@ OutputFlush(PyObject *self UNUSED)
360353
361354static struct PyMethodDef OutputMethods [] = {
362355 /* name, function, calling, doc */
363- {"write" , (PyCFunction )OutputWrite , METH_VARARGS , "" },
364- {"writelines" , (PyCFunction )OutputWritelines , METH_VARARGS , "" },
356+ {"write" , (PyCFunction )OutputWrite , METH_O , "" },
357+ {"writelines" , (PyCFunction )OutputWritelines , METH_O , "" },
365358 {"flush" , (PyCFunction )OutputFlush , METH_NOARGS , "" },
366359 {"__dir__" , (PyCFunction )OutputDir , METH_NOARGS , "" },
367360 { NULL , NULL , 0 , NULL }
@@ -3009,7 +3002,8 @@ TabListItem(PyObject *self UNUSED, PyInt n)
30093002 return NULL ;
30103003}
30113004
3012- /* Window object
3005+ /*
3006+ * Window object
30133007 */
30143008
30153009typedef struct
0 commit comments