summaryrefslogtreecommitdiff
path: root/source/ap/vim/patches/7.3.007
blob: 30b3745cad7bbe5bc1585a4d201d91f5dd90fc1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
To: vim-dev@vim.org
Subject: Patch 7.3.007
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.007
Problem:    Python code defines global "buffer".  Re-implements a grow-array.
Solution:   Use a grow-array instead of coding the same functionality.  Handle
	    out-of-memory situation properly.
Files:	    src/if_py_both.h


*** ../vim-7.3.006/src/if_py_both.h	2010-08-15 21:57:27.000000000 +0200
--- src/if_py_both.h	2010-09-21 16:00:54.000000000 +0200
***************
*** 34,39 ****
--- 34,40 ----
  static PyObject *OutputWrite(PyObject *, PyObject *);
  static PyObject *OutputWritelines(PyObject *, PyObject *);
  
+ /* Function to write a line, points to either msg() or emsg(). */
  typedef void (*writefn)(char_u *);
  static void writer(writefn fn, char_u *str, PyInt n);
  
***************
*** 122,173 ****
      return Py_None;
  }
  
! static char_u *buffer = NULL;
! static PyInt buffer_len = 0;
! static PyInt buffer_size = 0;
! 
  static writefn old_fn = NULL;
  
      static void
- buffer_ensure(PyInt n)
- {
-     PyInt new_size;
-     char_u *new_buffer;
- 
-     if (n < buffer_size)
- 	return;
- 
-     new_size = buffer_size;
-     while (new_size < n)
- 	new_size += 80;
- 
-     if (new_size != buffer_size)
-     {
- 	new_buffer = alloc((unsigned)new_size);
- 	if (new_buffer == NULL)
- 	    return;
- 
- 	if (buffer)
- 	{
- 	    memcpy(new_buffer, buffer, buffer_len);
- 	    vim_free(buffer);
- 	}
- 
- 	buffer = new_buffer;
- 	buffer_size = new_size;
-     }
- }
- 
-     static void
  PythonIO_Flush(void)
  {
!     if (old_fn && buffer_len)
      {
! 	buffer[buffer_len] = 0;
! 	old_fn(buffer);
      }
! 
!     buffer_len = 0;
  }
  
      static void
--- 123,141 ----
      return Py_None;
  }
  
! /* Buffer IO, we write one whole line at a time. */
! static garray_T io_ga = {0, 0, 1, 80, NULL};
  static writefn old_fn = NULL;
  
      static void
  PythonIO_Flush(void)
  {
!     if (old_fn != NULL && io_ga.ga_len > 0)
      {
! 	((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL;
! 	old_fn((char_u *)io_ga.ga_data);
      }
!     io_ga.ga_len = 0;
  }
  
      static void
***************
*** 175,204 ****
  {
      char_u *ptr;
  
!     if (fn != old_fn && old_fn != NULL)
  	PythonIO_Flush();
- 
      old_fn = fn;
  
      while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL)
      {
  	PyInt len = ptr - str;
  
! 	buffer_ensure(buffer_len + len + 1);
  
! 	memcpy(buffer + buffer_len, str, len);
! 	buffer_len += len;
! 	buffer[buffer_len] = 0;
! 	fn(buffer);
  	str = ptr + 1;
  	n -= len + 1;
! 	buffer_len = 0;
      }
  
!     /* Put the remaining text into the buffer for later printing */
!     buffer_ensure(buffer_len + n + 1);
!     memcpy(buffer + buffer_len, str, n);
!     buffer_len += n;
  }
  
  /***************/
--- 143,176 ----
  {
      char_u *ptr;
  
!     /* Flush when switching output function. */
!     if (fn != old_fn)
  	PythonIO_Flush();
      old_fn = fn;
  
+     /* Write each NL separated line.  Text after the last NL is kept for
+      * writing later. */
      while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL)
      {
  	PyInt len = ptr - str;
  
! 	if (ga_grow(&io_ga, len + 1) == FAIL)
! 	    break;
  
! 	mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len);
! 	((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL;
! 	fn((char_u *)io_ga.ga_data);
  	str = ptr + 1;
  	n -= len + 1;
! 	io_ga.ga_len = 0;
      }
  
!     /* Put the remaining text into io_ga for later printing. */
!     if (n > 0 && ga_grow(&io_ga, n + 1) == OK)
!     {
! 	mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n);
! 	io_ga.ga_len += n;
!     }
  }
  
  /***************/
*** ../vim-7.3.006/src/version.c	2010-09-18 13:36:41.000000000 +0200
--- src/version.c	2010-09-21 16:49:13.000000000 +0200
***************
*** 716,717 ****
--- 716,719 ----
  {   /* Add new patch number below this line */
+ /**/
+     7,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
180. You maintain more than six e-mail addresses.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///