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.007 < prev    next >
Encoding:
Internet Message Format  |  2012-11-20  |  4.3 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.3.007
  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.007
  11. Problem:    Python code defines global "buffer".  Re-implements a grow-array.
  12. Solution:   Use a grow-array instead of coding the same functionality.  Handle
  13.         out-of-memory situation properly.
  14. Files:        src/if_py_both.h
  15.  
  16.  
  17. *** ../vim-7.3.006/src/if_py_both.h    2010-08-15 21:57:27.000000000 +0200
  18. --- src/if_py_both.h    2010-09-21 16:00:54.000000000 +0200
  19. ***************
  20. *** 34,39 ****
  21. --- 34,40 ----
  22.   static PyObject *OutputWrite(PyObject *, PyObject *);
  23.   static PyObject *OutputWritelines(PyObject *, PyObject *);
  24.   
  25. + /* Function to write a line, points to either msg() or emsg(). */
  26.   typedef void (*writefn)(char_u *);
  27.   static void writer(writefn fn, char_u *str, PyInt n);
  28.   
  29. ***************
  30. *** 122,173 ****
  31.       return Py_None;
  32.   }
  33.   
  34. ! static char_u *buffer = NULL;
  35. ! static PyInt buffer_len = 0;
  36. ! static PyInt buffer_size = 0;
  37.   static writefn old_fn = NULL;
  38.   
  39.       static void
  40. - buffer_ensure(PyInt n)
  41. - {
  42. -     PyInt new_size;
  43. -     char_u *new_buffer;
  44. -     if (n < buffer_size)
  45. -     return;
  46. -     new_size = buffer_size;
  47. -     while (new_size < n)
  48. -     new_size += 80;
  49. -     if (new_size != buffer_size)
  50. -     {
  51. -     new_buffer = alloc((unsigned)new_size);
  52. -     if (new_buffer == NULL)
  53. -         return;
  54. -     if (buffer)
  55. -     {
  56. -         memcpy(new_buffer, buffer, buffer_len);
  57. -         vim_free(buffer);
  58. -     }
  59. -     buffer = new_buffer;
  60. -     buffer_size = new_size;
  61. -     }
  62. - }
  63. -     static void
  64.   PythonIO_Flush(void)
  65.   {
  66. !     if (old_fn && buffer_len)
  67.       {
  68. !     buffer[buffer_len] = 0;
  69. !     old_fn(buffer);
  70.       }
  71. !     buffer_len = 0;
  72.   }
  73.   
  74.       static void
  75. --- 123,141 ----
  76.       return Py_None;
  77.   }
  78.   
  79. ! /* Buffer IO, we write one whole line at a time. */
  80. ! static garray_T io_ga = {0, 0, 1, 80, NULL};
  81.   static writefn old_fn = NULL;
  82.   
  83.       static void
  84.   PythonIO_Flush(void)
  85.   {
  86. !     if (old_fn != NULL && io_ga.ga_len > 0)
  87.       {
  88. !     ((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL;
  89. !     old_fn((char_u *)io_ga.ga_data);
  90.       }
  91. !     io_ga.ga_len = 0;
  92.   }
  93.   
  94.       static void
  95. ***************
  96. *** 175,204 ****
  97.   {
  98.       char_u *ptr;
  99.   
  100. !     if (fn != old_fn && old_fn != NULL)
  101.       PythonIO_Flush();
  102.       old_fn = fn;
  103.   
  104.       while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL)
  105.       {
  106.       PyInt len = ptr - str;
  107.   
  108. !     buffer_ensure(buffer_len + len + 1);
  109.   
  110. !     memcpy(buffer + buffer_len, str, len);
  111. !     buffer_len += len;
  112. !     buffer[buffer_len] = 0;
  113. !     fn(buffer);
  114.       str = ptr + 1;
  115.       n -= len + 1;
  116. !     buffer_len = 0;
  117.       }
  118.   
  119. !     /* Put the remaining text into the buffer for later printing */
  120. !     buffer_ensure(buffer_len + n + 1);
  121. !     memcpy(buffer + buffer_len, str, n);
  122. !     buffer_len += n;
  123.   }
  124.   
  125.   /***************/
  126. --- 143,176 ----
  127.   {
  128.       char_u *ptr;
  129.   
  130. !     /* Flush when switching output function. */
  131. !     if (fn != old_fn)
  132.       PythonIO_Flush();
  133.       old_fn = fn;
  134.   
  135. +     /* Write each NL separated line.  Text after the last NL is kept for
  136. +      * writing later. */
  137.       while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL)
  138.       {
  139.       PyInt len = ptr - str;
  140.   
  141. !     if (ga_grow(&io_ga, len + 1) == FAIL)
  142. !         break;
  143.   
  144. !     mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len);
  145. !     ((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL;
  146. !     fn((char_u *)io_ga.ga_data);
  147.       str = ptr + 1;
  148.       n -= len + 1;
  149. !     io_ga.ga_len = 0;
  150.       }
  151.   
  152. !     /* Put the remaining text into io_ga for later printing. */
  153. !     if (n > 0 && ga_grow(&io_ga, n + 1) == OK)
  154. !     {
  155. !     mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n);
  156. !     io_ga.ga_len += n;
  157. !     }
  158.   }
  159.   
  160.   /***************/
  161. *** ../vim-7.3.006/src/version.c    2010-09-18 13:36:41.000000000 +0200
  162. --- src/version.c    2010-09-21 16:49:13.000000000 +0200
  163. ***************
  164. *** 716,717 ****
  165. --- 716,719 ----
  166.   {   /* Add new patch number below this line */
  167. + /**/
  168. +     7,
  169.   /**/
  170.  
  171. -- 
  172. hundred-and-one symptoms of being an internet addict:
  173. 180. You maintain more than six e-mail addresses.
  174.  
  175.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  176. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  177. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  178.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  179.