4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
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
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
22 static PyObject *OutputWrite(PyObject *, PyObject *);
23 static PyObject *OutputWritelines(PyObject *, PyObject *);
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);
34 ! static char_u *buffer = NULL;
35 ! static PyInt buffer_len = 0;
36 ! static PyInt buffer_size = 0;
38 static writefn old_fn = NULL;
41 - buffer_ensure(PyInt n)
46 - if (n < buffer_size)
49 - new_size = buffer_size;
50 - while (new_size < n)
53 - if (new_size != buffer_size)
55 - new_buffer = alloc((unsigned)new_size);
56 - if (new_buffer == NULL)
61 - memcpy(new_buffer, buffer, buffer_len);
65 - buffer = new_buffer;
66 - buffer_size = new_size;
73 ! if (old_fn && buffer_len)
75 ! buffer[buffer_len] = 0;
87 ! /* Buffer IO, we write one whole line at a time. */
88 ! static garray_T io_ga = {0, 0, 1, 80, NULL};
89 static writefn old_fn = NULL;
94 ! if (old_fn != NULL && io_ga.ga_len > 0)
96 ! ((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL;
97 ! old_fn((char_u *)io_ga.ga_data);
108 ! if (fn != old_fn && old_fn != NULL)
113 while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL)
115 PyInt len = ptr - str;
117 ! buffer_ensure(buffer_len + len + 1);
119 ! memcpy(buffer + buffer_len, str, len);
121 ! buffer[buffer_len] = 0;
128 ! /* Put the remaining text into the buffer for later printing */
129 ! buffer_ensure(buffer_len + n + 1);
130 ! memcpy(buffer + buffer_len, str, n);
139 ! /* Flush when switching output function. */
144 + /* Write each NL separated line. Text after the last NL is kept for
145 + * writing later. */
146 while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL)
148 PyInt len = ptr - str;
150 ! if (ga_grow(&io_ga, len + 1) == FAIL)
153 ! mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len);
154 ! ((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL;
155 ! fn((char_u *)io_ga.ga_data);
161 ! /* Put the remaining text into io_ga for later printing. */
162 ! if (n > 0 && ga_grow(&io_ga, n + 1) == OK)
164 ! mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n);
170 *** ../vim-7.3.006/src/version.c 2010-09-18 13:36:41.000000000 +0200
171 --- src/version.c 2010-09-21 16:49:13.000000000 +0200
175 { /* Add new patch number below this line */
181 hundred-and-one symptoms of being an internet addict:
182 180. You maintain more than six e-mail addresses.
184 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
185 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
186 \\\ download, build and distribute -- http://www.A-A-P.org ///
187 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///