]> git.pld-linux.org Git - packages/vim.git/blob - 7.3.007
- new
[packages/vim.git] / 7.3.007
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
38   static writefn old_fn = NULL;
39   
40       static void
41 - buffer_ensure(PyInt n)
42 - {
43 -     PyInt new_size;
44 -     char_u *new_buffer;
45
46 -     if (n < buffer_size)
47 -       return;
48
49 -     new_size = buffer_size;
50 -     while (new_size < n)
51 -       new_size += 80;
52
53 -     if (new_size != buffer_size)
54 -     {
55 -       new_buffer = alloc((unsigned)new_size);
56 -       if (new_buffer == NULL)
57 -           return;
58
59 -       if (buffer)
60 -       {
61 -           memcpy(new_buffer, buffer, buffer_len);
62 -           vim_free(buffer);
63 -       }
64
65 -       buffer = new_buffer;
66 -       buffer_size = new_size;
67 -     }
68 - }
69
70 -     static void
71   PythonIO_Flush(void)
72   {
73 !     if (old_fn && buffer_len)
74       {
75 !       buffer[buffer_len] = 0;
76 !       old_fn(buffer);
77       }
78
79 !     buffer_len = 0;
80   }
81   
82       static void
83 --- 123,141 ----
84       return Py_None;
85   }
86   
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;
90   
91       static void
92   PythonIO_Flush(void)
93   {
94 !     if (old_fn != NULL && io_ga.ga_len > 0)
95       {
96 !       ((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL;
97 !       old_fn((char_u *)io_ga.ga_data);
98       }
99 !     io_ga.ga_len = 0;
100   }
101   
102       static void
103 ***************
104 *** 175,204 ****
105   {
106       char_u *ptr;
107   
108 !     if (fn != old_fn && old_fn != NULL)
109         PythonIO_Flush();
110
111       old_fn = fn;
112   
113       while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL)
114       {
115         PyInt len = ptr - str;
116   
117 !       buffer_ensure(buffer_len + len + 1);
118   
119 !       memcpy(buffer + buffer_len, str, len);
120 !       buffer_len += len;
121 !       buffer[buffer_len] = 0;
122 !       fn(buffer);
123         str = ptr + 1;
124         n -= len + 1;
125 !       buffer_len = 0;
126       }
127   
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);
131 !     buffer_len += n;
132   }
133   
134   /***************/
135 --- 143,176 ----
136   {
137       char_u *ptr;
138   
139 !     /* Flush when switching output function. */
140 !     if (fn != old_fn)
141         PythonIO_Flush();
142       old_fn = fn;
143   
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)
147       {
148         PyInt len = ptr - str;
149   
150 !       if (ga_grow(&io_ga, len + 1) == FAIL)
151 !           break;
152   
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);
156         str = ptr + 1;
157         n -= len + 1;
158 !       io_ga.ga_len = 0;
159       }
160   
161 !     /* Put the remaining text into io_ga for later printing. */
162 !     if (n > 0 && ga_grow(&io_ga, n + 1) == OK)
163 !     {
164 !       mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n);
165 !       io_ga.ga_len += n;
166 !     }
167   }
168   
169   /***************/
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
172 ***************
173 *** 716,717 ****
174 --- 716,719 ----
175   {   /* Add new patch number below this line */
176 + /**/
177 +     7,
178   /**/
179
180 -- 
181 hundred-and-one symptoms of being an internet addict:
182 180. You maintain more than six e-mail addresses.
183
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    ///
This page took 0.07033 seconds and 3 git commands to generate.