home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.3 / 7.3.1226 < prev    next >
Encoding:
Internet Message Format  |  2013-06-22  |  7.0 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.1226
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.3.1226
  11. Problem:    Python: duplicate code.
  12. Solution:   Share code between OutputWrite() and OutputWritelines(). (ZyX)
  13. Files:        src/if_py_both.h, src/testdir/test86.ok, src/testdir/test87.ok
  14.  
  15.  
  16. *** ../vim-7.3.1225/src/if_py_both.h    2013-06-16 14:25:53.000000000 +0200
  17. --- src/if_py_both.h    2013-06-23 12:46:03.000000000 +0200
  18. ***************
  19. *** 281,295 ****
  20.       }
  21.   }
  22.   
  23. !     static PyObject *
  24. ! OutputWrite(OutputObject *self, PyObject *args)
  25.   {
  26. !     Py_ssize_t len = 0;
  27. !     char *str = NULL;
  28. !     int error = self->error;
  29.   
  30. !     if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len))
  31. !     return NULL;
  32.   
  33.       Py_BEGIN_ALLOW_THREADS
  34.       Python_Lock_Vim();
  35. --- 281,295 ----
  36.       }
  37.   }
  38.   
  39. !     static int
  40. ! write_output(OutputObject *self, PyObject *string)
  41.   {
  42. !     Py_ssize_t    len = 0;
  43. !     char    *str = NULL;
  44. !     int        error = self->error;
  45.   
  46. !     if (!PyArg_Parse(string, "et#", ENC_OPT, &str, &len))
  47. !     return -1;
  48.   
  49.       Py_BEGIN_ALLOW_THREADS
  50.       Python_Lock_Vim();
  51. ***************
  52. *** 298,341 ****
  53.       Py_END_ALLOW_THREADS
  54.       PyMem_Free(str);
  55.   
  56.       Py_INCREF(Py_None);
  57.       return Py_None;
  58.   }
  59.   
  60.       static PyObject *
  61. ! OutputWritelines(OutputObject *self, PyObject *args)
  62.   {
  63. -     PyObject    *seq;
  64.       PyObject    *iterator;
  65.       PyObject    *item;
  66. -     int error = self->error;
  67. -     if (!PyArg_ParseTuple(args, "O", &seq))
  68. -     return NULL;
  69.   
  70.       if (!(iterator = PyObject_GetIter(seq)))
  71.       return NULL;
  72.   
  73.       while ((item = PyIter_Next(iterator)))
  74.       {
  75. !     char *str = NULL;
  76. !     PyInt len;
  77. !     if (!PyArg_Parse(item, "et#", ENC_OPT, &str, &len))
  78.       {
  79. -         PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
  80.           Py_DECREF(iterator);
  81.           Py_DECREF(item);
  82.           return NULL;
  83.       }
  84.       Py_DECREF(item);
  85. -     Py_BEGIN_ALLOW_THREADS
  86. -     Python_Lock_Vim();
  87. -     writer((writefn)(error ? emsg : msg), (char_u *)str, len);
  88. -     Python_Release_Vim();
  89. -     Py_END_ALLOW_THREADS
  90. -     PyMem_Free(str);
  91.       }
  92.   
  93.       Py_DECREF(iterator);
  94. --- 298,334 ----
  95.       Py_END_ALLOW_THREADS
  96.       PyMem_Free(str);
  97.   
  98. +     return 0;
  99. + }
  100. +     static PyObject *
  101. + OutputWrite(OutputObject *self, PyObject *string)
  102. + {
  103. +     if (write_output(self, string))
  104. +     return NULL;
  105.       Py_INCREF(Py_None);
  106.       return Py_None;
  107.   }
  108.   
  109.       static PyObject *
  110. ! OutputWritelines(OutputObject *self, PyObject *seq)
  111.   {
  112.       PyObject    *iterator;
  113.       PyObject    *item;
  114.   
  115.       if (!(iterator = PyObject_GetIter(seq)))
  116.       return NULL;
  117.   
  118.       while ((item = PyIter_Next(iterator)))
  119.       {
  120. !     if (write_output(self, item))
  121.       {
  122.           Py_DECREF(iterator);
  123.           Py_DECREF(item);
  124.           return NULL;
  125.       }
  126.       Py_DECREF(item);
  127.       }
  128.   
  129.       Py_DECREF(iterator);
  130. ***************
  131. *** 360,367 ****
  132.   
  133.   static struct PyMethodDef OutputMethods[] = {
  134.       /* name,        function,                calling,    doc */
  135. !     {"write",        (PyCFunction)OutputWrite,        METH_VARARGS,    ""},
  136. !     {"writelines",  (PyCFunction)OutputWritelines,    METH_VARARGS,    ""},
  137.       {"flush",        (PyCFunction)OutputFlush,        METH_NOARGS,    ""},
  138.       {"__dir__",        (PyCFunction)OutputDir,        METH_NOARGS,    ""},
  139.       { NULL,        NULL,                0,        NULL}
  140. --- 353,360 ----
  141.   
  142.   static struct PyMethodDef OutputMethods[] = {
  143.       /* name,        function,                calling,    doc */
  144. !     {"write",        (PyCFunction)OutputWrite,        METH_O,        ""},
  145. !     {"writelines",  (PyCFunction)OutputWritelines,    METH_O,        ""},
  146.       {"flush",        (PyCFunction)OutputFlush,        METH_NOARGS,    ""},
  147.       {"__dir__",        (PyCFunction)OutputDir,        METH_NOARGS,    ""},
  148.       { NULL,        NULL,                0,        NULL}
  149. ***************
  150. *** 3009,3015 ****
  151.       return NULL;
  152.   }
  153.   
  154. ! /* Window object
  155.    */
  156.   
  157.   typedef struct
  158. --- 3002,3009 ----
  159.       return NULL;
  160.   }
  161.   
  162. ! /*
  163. !  * Window object
  164.    */
  165.   
  166.   typedef struct
  167. *** ../vim-7.3.1225/src/testdir/test86.ok    2013-06-12 14:26:20.000000000 +0200
  168. --- src/testdir/test86.ok    2013-06-23 12:43:55.000000000 +0200
  169. ***************
  170. *** 444,450 ****
  171.   sys.stdout.write(None):TypeError:('coercing to Unicode: need string or buffer, NoneType found',)
  172.   >> OutputWriteLines
  173.   sys.stdout.writelines(None):TypeError:("'NoneType' object is not iterable",)
  174. ! sys.stdout.writelines([1]):TypeError:('writelines() requires list of strings',)
  175.   > VimCommand
  176.   vim.command(1):TypeError:('must be string, not int',)
  177.   > VimToPython
  178. --- 444,450 ----
  179.   sys.stdout.write(None):TypeError:('coercing to Unicode: need string or buffer, NoneType found',)
  180.   >> OutputWriteLines
  181.   sys.stdout.writelines(None):TypeError:("'NoneType' object is not iterable",)
  182. ! sys.stdout.writelines([1]):TypeError:('coercing to Unicode: need string or buffer, int found',)
  183.   > VimCommand
  184.   vim.command(1):TypeError:('must be string, not int',)
  185.   > VimToPython
  186. *** ../vim-7.3.1225/src/testdir/test87.ok    2013-06-12 14:20:15.000000000 +0200
  187. --- src/testdir/test87.ok    2013-06-23 12:44:00.000000000 +0200
  188. ***************
  189. *** 433,439 ****
  190.   sys.stdout.write(None):(<class 'TypeError'>, TypeError("Can't convert 'NoneType' object to str implicitly",))
  191.   >> OutputWriteLines
  192.   sys.stdout.writelines(None):(<class 'TypeError'>, TypeError("'NoneType' object is not iterable",))
  193. ! sys.stdout.writelines([1]):(<class 'TypeError'>, TypeError('writelines() requires list of strings',))
  194.   >>> Testing *Iter* using sys.stdout.writelines(%s)
  195.   sys.stdout.writelines(FailingIter()):(<class 'NotImplementedError'>, NotImplementedError())
  196.   sys.stdout.writelines(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError())
  197. --- 433,439 ----
  198.   sys.stdout.write(None):(<class 'TypeError'>, TypeError("Can't convert 'NoneType' object to str implicitly",))
  199.   >> OutputWriteLines
  200.   sys.stdout.writelines(None):(<class 'TypeError'>, TypeError("'NoneType' object is not iterable",))
  201. ! sys.stdout.writelines([1]):(<class 'TypeError'>, TypeError("Can't convert 'int' object to str implicitly",))
  202.   >>> Testing *Iter* using sys.stdout.writelines(%s)
  203.   sys.stdout.writelines(FailingIter()):(<class 'NotImplementedError'>, NotImplementedError())
  204.   sys.stdout.writelines(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError())
  205. *** ../vim-7.3.1225/src/version.c    2013-06-22 13:00:14.000000000 +0200
  206. --- src/version.c    2013-06-23 12:45:35.000000000 +0200
  207. ***************
  208. *** 730,731 ****
  209. --- 730,733 ----
  210.   {   /* Add new patch number below this line */
  211. + /**/
  212. +     1226,
  213.   /**/
  214.  
  215. -- 
  216.        We're knights of the round table
  217.        We dance whene'er we're able
  218.        We do routines and chorus scenes
  219.        With footwork impeccable.
  220.        We dine well here in Camelot
  221.        We eat ham and jam and spam a lot.
  222.                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
  223.  
  224.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  225. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  226. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  227.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  228.