]>
Commit | Line | Data |
---|---|---|
a2e11672 AG |
1 | To: vim_dev@googlegroups.com |
2 | Subject: Patch 7.3.220 | |
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.220 | |
11 | Problem: Python 3: vim.error is a 'str' instead of an 'Exception' object, | |
12 | so 'except' or 'raise' it causes a 'SystemError' exception. | |
13 | Buffer objects do not support slice assignment. | |
14 | When exchanging text between Vim and Python, multibyte texts become | |
15 | gabage or cause Unicode Expceptions, etc. | |
16 | 'py3file' tries to read in the file as Unicode, sometimes causes | |
17 | UnicodeDecodeException | |
18 | Solution: Fix the problems. (lilydjwg) | |
19 | Files: src/if_py_both.h, src/if_python.c, src/if_python3.c | |
20 | ||
21 | ||
22 | *** ../mercurial/vim73/src/if_py_both.h 2011-03-22 15:47:18.000000000 +0100 | |
23 | --- src/if_py_both.h 2011-06-18 23:54:25.000000000 +0200 | |
24 | *************** | |
25 | *** 65,74 **** | |
26 | OutputWrite(PyObject *self, PyObject *args) | |
27 | { | |
28 | int len; | |
29 | ! char *str; | |
30 | int error = ((OutputObject *)(self))->error; | |
31 | ||
32 | ! if (!PyArg_ParseTuple(args, "s#", &str, &len)) | |
33 | return NULL; | |
34 | ||
35 | Py_BEGIN_ALLOW_THREADS | |
36 | --- 65,74 ---- | |
37 | OutputWrite(PyObject *self, PyObject *args) | |
38 | { | |
39 | int len; | |
40 | ! char *str = NULL; | |
41 | int error = ((OutputObject *)(self))->error; | |
42 | ||
43 | ! if (!PyArg_ParseTuple(args, "es#", p_enc, &str, &len)) | |
44 | return NULL; | |
45 | ||
46 | Py_BEGIN_ALLOW_THREADS | |
47 | *************** | |
48 | *** 76,81 **** | |
49 | --- 76,82 ---- | |
50 | writer((writefn)(error ? emsg : msg), (char_u *)str, len); | |
51 | Python_Release_Vim(); | |
52 | Py_END_ALLOW_THREADS | |
53 | + PyMem_Free(str); | |
54 | ||
55 | Py_INCREF(Py_None); | |
56 | return Py_None; | |
57 | *************** | |
58 | *** 104,113 **** | |
59 | for (i = 0; i < n; ++i) | |
60 | { | |
61 | PyObject *line = PyList_GetItem(list, i); | |
62 | ! char *str; | |
63 | PyInt len; | |
64 | ||
65 | ! if (!PyArg_Parse(line, "s#", &str, &len)) { | |
66 | PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings")); | |
67 | Py_DECREF(list); | |
68 | return NULL; | |
69 | --- 105,114 ---- | |
70 | for (i = 0; i < n; ++i) | |
71 | { | |
72 | PyObject *line = PyList_GetItem(list, i); | |
73 | ! char *str = NULL; | |
74 | PyInt len; | |
75 | ||
76 | ! if (!PyArg_Parse(line, "es#", p_enc, &str, &len)) { | |
77 | PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings")); | |
78 | Py_DECREF(list); | |
79 | return NULL; | |
80 | *************** | |
81 | *** 118,123 **** | |
82 | --- 119,125 ---- | |
83 | writer((writefn)(error ? emsg : msg), (char_u *)str, len); | |
84 | Python_Release_Vim(); | |
85 | Py_END_ALLOW_THREADS | |
86 | + PyMem_Free(str); | |
87 | } | |
88 | ||
89 | Py_DECREF(list); | |
90 | *************** | |
91 | *** 681,686 **** | |
92 | --- 683,689 ---- | |
93 | { | |
94 | const char *str; | |
95 | char *save; | |
96 | + PyObject *bytes; | |
97 | PyInt len; | |
98 | PyInt i; | |
99 | char *p; | |
100 | *************** | |
101 | *** 691,698 **** | |
102 | return NULL; | |
103 | } | |
104 | ||
105 | ! str = PyString_AsString(obj); | |
106 | ! len = PyString_Size(obj); | |
107 | ||
108 | /* | |
109 | * Error checking: String must not contain newlines, as we | |
110 | --- 694,702 ---- | |
111 | return NULL; | |
112 | } | |
113 | ||
114 | ! bytes = PyString_AsBytes(obj); /* for Python 2 this does nothing */ | |
115 | ! str = PyString_AsString(bytes); | |
116 | ! len = PyString_Size(bytes); | |
117 | ||
118 | /* | |
119 | * Error checking: String must not contain newlines, as we | |
120 | *************** | |
121 | *** 731,736 **** | |
122 | --- 735,741 ---- | |
123 | } | |
124 | ||
125 | save[i] = '\0'; | |
126 | + PyString_FreeBytes(bytes); /* Python 2 does nothing here */ | |
127 | ||
128 | return save; | |
129 | } | |
130 | *************** | |
131 | *** 817,823 **** | |
132 | invalidate_botline(); | |
133 | } | |
134 | ||
135 | ! /* Replace a line in the specified buffer. The line number is | |
136 | * in Vim format (1-based). The replacement line is given as | |
137 | * a Python string object. The object is checked for validity | |
138 | * and correct format. Errors are returned as a value of FAIL. | |
139 | --- 822,829 ---- | |
140 | invalidate_botline(); | |
141 | } | |
142 | ||
143 | ! /* | |
144 | ! * Replace a line in the specified buffer. The line number is | |
145 | * in Vim format (1-based). The replacement line is given as | |
146 | * a Python string object. The object is checked for validity | |
147 | * and correct format. Errors are returned as a value of FAIL. | |
148 | *************** | |
149 | *** 908,913 **** | |
150 | --- 914,1106 ---- | |
151 | } | |
152 | } | |
153 | ||
154 | + /* Replace a range of lines in the specified buffer. The line numbers are in | |
155 | + * Vim format (1-based). The range is from lo up to, but not including, hi. | |
156 | + * The replacement lines are given as a Python list of string objects. The | |
157 | + * list is checked for validity and correct format. Errors are returned as a | |
158 | + * value of FAIL. The return value is OK on success. | |
159 | + * If OK is returned and len_change is not NULL, *len_change | |
160 | + * is set to the change in the buffer length. | |
161 | + */ | |
162 | + static int | |
163 | + SetBufferLineList(buf_T *buf, PyInt lo, PyInt hi, PyObject *list, PyInt *len_change) | |
164 | + { | |
165 | + /* First of all, we check the thpe of the supplied Python object. | |
166 | + * There are three cases: | |
167 | + * 1. NULL, or None - this is a deletion. | |
168 | + * 2. A list - this is a replacement. | |
169 | + * 3. Anything else - this is an error. | |
170 | + */ | |
171 | + if (list == Py_None || list == NULL) | |
172 | + { | |
173 | + PyInt i; | |
174 | + PyInt n = (int)(hi - lo); | |
175 | + buf_T *savebuf = curbuf; | |
176 | + | |
177 | + PyErr_Clear(); | |
178 | + curbuf = buf; | |
179 | + | |
180 | + if (u_savedel((linenr_T)lo, (long)n) == FAIL) | |
181 | + PyErr_SetVim(_("cannot save undo information")); | |
182 | + else | |
183 | + { | |
184 | + for (i = 0; i < n; ++i) | |
185 | + { | |
186 | + if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
187 | + { | |
188 | + PyErr_SetVim(_("cannot delete line")); | |
189 | + break; | |
190 | + } | |
191 | + } | |
192 | + if (buf == curwin->w_buffer) | |
193 | + py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n); | |
194 | + deleted_lines_mark((linenr_T)lo, (long)i); | |
195 | + } | |
196 | + | |
197 | + curbuf = savebuf; | |
198 | + | |
199 | + if (PyErr_Occurred() || VimErrorCheck()) | |
200 | + return FAIL; | |
201 | + | |
202 | + if (len_change) | |
203 | + *len_change = -n; | |
204 | + | |
205 | + return OK; | |
206 | + } | |
207 | + else if (PyList_Check(list)) | |
208 | + { | |
209 | + PyInt i; | |
210 | + PyInt new_len = PyList_Size(list); | |
211 | + PyInt old_len = hi - lo; | |
212 | + PyInt extra = 0; /* lines added to text, can be negative */ | |
213 | + char **array; | |
214 | + buf_T *savebuf; | |
215 | + | |
216 | + if (new_len == 0) /* avoid allocating zero bytes */ | |
217 | + array = NULL; | |
218 | + else | |
219 | + { | |
220 | + array = (char **)alloc((unsigned)(new_len * sizeof(char *))); | |
221 | + if (array == NULL) | |
222 | + { | |
223 | + PyErr_NoMemory(); | |
224 | + return FAIL; | |
225 | + } | |
226 | + } | |
227 | + | |
228 | + for (i = 0; i < new_len; ++i) | |
229 | + { | |
230 | + PyObject *line = PyList_GetItem(list, i); | |
231 | + | |
232 | + array[i] = StringToLine(line); | |
233 | + if (array[i] == NULL) | |
234 | + { | |
235 | + while (i) | |
236 | + vim_free(array[--i]); | |
237 | + vim_free(array); | |
238 | + return FAIL; | |
239 | + } | |
240 | + } | |
241 | + | |
242 | + savebuf = curbuf; | |
243 | + | |
244 | + PyErr_Clear(); | |
245 | + curbuf = buf; | |
246 | + | |
247 | + if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL) | |
248 | + PyErr_SetVim(_("cannot save undo information")); | |
249 | + | |
250 | + /* If the size of the range is reducing (ie, new_len < old_len) we | |
251 | + * need to delete some old_len. We do this at the start, by | |
252 | + * repeatedly deleting line "lo". | |
253 | + */ | |
254 | + if (!PyErr_Occurred()) | |
255 | + { | |
256 | + for (i = 0; i < old_len - new_len; ++i) | |
257 | + if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
258 | + { | |
259 | + PyErr_SetVim(_("cannot delete line")); | |
260 | + break; | |
261 | + } | |
262 | + extra -= i; | |
263 | + } | |
264 | + | |
265 | + /* For as long as possible, replace the existing old_len with the | |
266 | + * new old_len. This is a more efficient operation, as it requires | |
267 | + * less memory allocation and freeing. | |
268 | + */ | |
269 | + if (!PyErr_Occurred()) | |
270 | + { | |
271 | + for (i = 0; i < old_len && i < new_len; ++i) | |
272 | + if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE) | |
273 | + == FAIL) | |
274 | + { | |
275 | + PyErr_SetVim(_("cannot replace line")); | |
276 | + break; | |
277 | + } | |
278 | + } | |
279 | + else | |
280 | + i = 0; | |
281 | + | |
282 | + /* Now we may need to insert the remaining new old_len. If we do, we | |
283 | + * must free the strings as we finish with them (we can't pass the | |
284 | + * responsibility to vim in this case). | |
285 | + */ | |
286 | + if (!PyErr_Occurred()) | |
287 | + { | |
288 | + while (i < new_len) | |
289 | + { | |
290 | + if (ml_append((linenr_T)(lo + i - 1), | |
291 | + (char_u *)array[i], 0, FALSE) == FAIL) | |
292 | + { | |
293 | + PyErr_SetVim(_("cannot insert line")); | |
294 | + break; | |
295 | + } | |
296 | + vim_free(array[i]); | |
297 | + ++i; | |
298 | + ++extra; | |
299 | + } | |
300 | + } | |
301 | + | |
302 | + /* Free any left-over old_len, as a result of an error */ | |
303 | + while (i < new_len) | |
304 | + { | |
305 | + vim_free(array[i]); | |
306 | + ++i; | |
307 | + } | |
308 | + | |
309 | + /* Free the array of old_len. All of its contents have now | |
310 | + * been dealt with (either freed, or the responsibility passed | |
311 | + * to vim. | |
312 | + */ | |
313 | + vim_free(array); | |
314 | + | |
315 | + /* Adjust marks. Invalidate any which lie in the | |
316 | + * changed range, and move any in the remainder of the buffer. | |
317 | + */ | |
318 | + mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), | |
319 | + (long)MAXLNUM, (long)extra); | |
320 | + changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra); | |
321 | + | |
322 | + if (buf == curwin->w_buffer) | |
323 | + py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra); | |
324 | + | |
325 | + curbuf = savebuf; | |
326 | + | |
327 | + if (PyErr_Occurred() || VimErrorCheck()) | |
328 | + return FAIL; | |
329 | + | |
330 | + if (len_change) | |
331 | + *len_change = new_len - old_len; | |
332 | + | |
333 | + return OK; | |
334 | + } | |
335 | + else | |
336 | + { | |
337 | + PyErr_BadArgument(); | |
338 | + return FAIL; | |
339 | + } | |
340 | + } | |
341 | ||
342 | /* Insert a number of lines into the specified buffer after the specifed line. | |
343 | * The line number is in Vim format (1-based). The lines to be inserted are | |
344 | *************** | |
345 | *** 1108,1113 **** | |
346 | --- 1301,1340 ---- | |
347 | return -1; | |
348 | ||
349 | if (new_end) | |
350 | + *new_end = end + len_change; | |
351 | + | |
352 | + return 0; | |
353 | + } | |
354 | + | |
355 | + static PyInt | |
356 | + RBAsSlice(BufferObject *self, PyInt lo, PyInt hi, PyObject *val, PyInt start, PyInt end, PyInt *new_end) | |
357 | + { | |
358 | + PyInt size; | |
359 | + PyInt len_change; | |
360 | + | |
361 | + /* Self must be a valid buffer */ | |
362 | + if (CheckBuffer(self)) | |
363 | + return -1; | |
364 | + | |
365 | + /* Sort out the slice range */ | |
366 | + size = end - start + 1; | |
367 | + | |
368 | + if (lo < 0) | |
369 | + lo = 0; | |
370 | + else if (lo > size) | |
371 | + lo = size; | |
372 | + if (hi < 0) | |
373 | + hi = 0; | |
374 | + if (hi < lo) | |
375 | + hi = lo; | |
376 | + else if (hi > size) | |
377 | + hi = size; | |
378 | + | |
379 | + if (SetBufferLineList(self->buf, lo + start, hi + start, | |
380 | + val, &len_change) == FAIL) | |
381 | + return -1; | |
382 | + | |
383 | + if (new_end) | |
384 | *new_end = end + len_change; | |
385 | ||
386 | return 0; | |
387 | *** ../mercurial/vim73/src/if_python.c 2011-03-26 18:32:00.000000000 +0100 | |
388 | --- src/if_python.c 2011-06-19 00:02:15.000000000 +0200 | |
389 | *************** | |
390 | *** 56,61 **** | |
391 | --- 56,65 ---- | |
392 | ||
393 | static void init_structs(void); | |
394 | ||
395 | + /* No-op conversion functions, use with care! */ | |
396 | + #define PyString_AsBytes(obj) (obj) | |
397 | + #define PyString_FreeBytes(obj) | |
398 | + | |
399 | #if !defined(FEAT_PYTHON) && defined(PROTO) | |
400 | /* Use this to be able to generate prototypes without python being used. */ | |
401 | # define PyObject Py_ssize_t | |
402 | *************** | |
403 | *** 129,134 **** | |
404 | --- 133,139 ---- | |
405 | */ | |
406 | # define PyArg_Parse dll_PyArg_Parse | |
407 | # define PyArg_ParseTuple dll_PyArg_ParseTuple | |
408 | + # define PyMem_Free dll_PyMem_Free | |
409 | # define PyDict_SetItemString dll_PyDict_SetItemString | |
410 | # define PyErr_BadArgument dll_PyErr_BadArgument | |
411 | # define PyErr_Clear dll_PyErr_Clear | |
412 | *************** | |
413 | *** 189,194 **** | |
414 | --- 194,200 ---- | |
415 | */ | |
416 | static int(*dll_PyArg_Parse)(PyObject *, char *, ...); | |
417 | static int(*dll_PyArg_ParseTuple)(PyObject *, char *, ...); | |
418 | + static int(*dll_PyMem_Free)(void *); | |
419 | static int(*dll_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item); | |
420 | static int(*dll_PyErr_BadArgument)(void); | |
421 | static void(*dll_PyErr_Clear)(void); | |
422 | *************** | |
423 | *** 271,276 **** | |
424 | --- 277,283 ---- | |
425 | { | |
426 | {"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse}, | |
427 | {"PyArg_ParseTuple", (PYTHON_PROC*)&dll_PyArg_ParseTuple}, | |
428 | + {"PyMem_Free", (PYTHON_PROC*)&dll_PyMem_Free}, | |
429 | {"PyDict_SetItemString", (PYTHON_PROC*)&dll_PyDict_SetItemString}, | |
430 | {"PyErr_BadArgument", (PYTHON_PROC*)&dll_PyErr_BadArgument}, | |
431 | {"PyErr_Clear", (PYTHON_PROC*)&dll_PyErr_Clear}, | |
432 | *************** | |
433 | *** 833,876 **** | |
434 | static PyObject *CurrentGetattr(PyObject *, char *); | |
435 | static int CurrentSetattr(PyObject *, char *, PyObject *); | |
436 | ||
437 | - /* Common routines for buffers and line ranges | |
438 | - * ------------------------------------------- | |
439 | - */ | |
440 | - | |
441 | - static PyInt | |
442 | - RBAssSlice(BufferObject *self, PyInt lo, PyInt hi, PyObject *val, PyInt start, PyInt end, PyInt *new_end) | |
443 | - { | |
444 | - PyInt size; | |
445 | - PyInt len_change; | |
446 | - | |
447 | - /* Self must be a valid buffer */ | |
448 | - if (CheckBuffer(self)) | |
449 | - return -1; | |
450 | - | |
451 | - /* Sort out the slice range */ | |
452 | - size = end - start + 1; | |
453 | - | |
454 | - if (lo < 0) | |
455 | - lo = 0; | |
456 | - else if (lo > size) | |
457 | - lo = size; | |
458 | - if (hi < 0) | |
459 | - hi = 0; | |
460 | - if (hi < lo) | |
461 | - hi = lo; | |
462 | - else if (hi > size) | |
463 | - hi = size; | |
464 | - | |
465 | - if (SetBufferLineList(self->buf, lo + start, hi + start, | |
466 | - val, &len_change) == FAIL) | |
467 | - return -1; | |
468 | - | |
469 | - if (new_end) | |
470 | - *new_end = end + len_change; | |
471 | - | |
472 | - return 0; | |
473 | - } | |
474 | - | |
475 | static PySequenceMethods BufferAsSeq = { | |
476 | (PyInquiry) BufferLength, /* sq_length, len(x) */ | |
477 | (binaryfunc) 0, /* BufferConcat, */ /* sq_concat, x+y */ | |
478 | --- 840,845 ---- | |
479 | *************** | |
480 | *** 1038,1044 **** | |
481 | static PyInt | |
482 | BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) | |
483 | { | |
484 | ! return RBAssSlice((BufferObject *)(self), lo, hi, val, 1, | |
485 | (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count, | |
486 | NULL); | |
487 | } | |
488 | --- 1007,1013 ---- | |
489 | static PyInt | |
490 | BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) | |
491 | { | |
492 | ! return RBAsSlice((BufferObject *)(self), lo, hi, val, 1, | |
493 | (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count, | |
494 | NULL); | |
495 | } | |
496 | *************** | |
497 | *** 1088,1094 **** | |
498 | static PyInt | |
499 | RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) | |
500 | { | |
501 | ! return RBAssSlice(((RangeObject *)(self))->buf, lo, hi, val, | |
502 | ((RangeObject *)(self))->start, | |
503 | ((RangeObject *)(self))->end, | |
504 | &((RangeObject *)(self))->end); | |
505 | --- 1057,1063 ---- | |
506 | static PyInt | |
507 | RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val) | |
508 | { | |
509 | ! return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val, | |
510 | ((RangeObject *)(self))->start, | |
511 | ((RangeObject *)(self))->end, | |
512 | &((RangeObject *)(self))->end); | |
513 | *************** | |
514 | *** 1435,1628 **** | |
515 | * 4. Utility functions for handling the interface between Vim and Python. | |
516 | */ | |
517 | ||
518 | - /* Replace a range of lines in the specified buffer. The line numbers are in | |
519 | - * Vim format (1-based). The range is from lo up to, but not including, hi. | |
520 | - * The replacement lines are given as a Python list of string objects. The | |
521 | - * list is checked for validity and correct format. Errors are returned as a | |
522 | - * value of FAIL. The return value is OK on success. | |
523 | - * If OK is returned and len_change is not NULL, *len_change | |
524 | - * is set to the change in the buffer length. | |
525 | - */ | |
526 | - static int | |
527 | - SetBufferLineList(buf_T *buf, PyInt lo, PyInt hi, PyObject *list, PyInt *len_change) | |
528 | - { | |
529 | - /* First of all, we check the thpe of the supplied Python object. | |
530 | - * There are three cases: | |
531 | - * 1. NULL, or None - this is a deletion. | |
532 | - * 2. A list - this is a replacement. | |
533 | - * 3. Anything else - this is an error. | |
534 | - */ | |
535 | - if (list == Py_None || list == NULL) | |
536 | - { | |
537 | - PyInt i; | |
538 | - PyInt n = (int)(hi - lo); | |
539 | - buf_T *savebuf = curbuf; | |
540 | - | |
541 | - PyErr_Clear(); | |
542 | - curbuf = buf; | |
543 | - | |
544 | - if (u_savedel((linenr_T)lo, (long)n) == FAIL) | |
545 | - PyErr_SetVim(_("cannot save undo information")); | |
546 | - else | |
547 | - { | |
548 | - for (i = 0; i < n; ++i) | |
549 | - { | |
550 | - if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
551 | - { | |
552 | - PyErr_SetVim(_("cannot delete line")); | |
553 | - break; | |
554 | - } | |
555 | - } | |
556 | - if (buf == curwin->w_buffer) | |
557 | - py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n); | |
558 | - deleted_lines_mark((linenr_T)lo, (long)i); | |
559 | - } | |
560 | - | |
561 | - curbuf = savebuf; | |
562 | - | |
563 | - if (PyErr_Occurred() || VimErrorCheck()) | |
564 | - return FAIL; | |
565 | - | |
566 | - if (len_change) | |
567 | - *len_change = -n; | |
568 | - | |
569 | - return OK; | |
570 | - } | |
571 | - else if (PyList_Check(list)) | |
572 | - { | |
573 | - PyInt i; | |
574 | - PyInt new_len = PyList_Size(list); | |
575 | - PyInt old_len = hi - lo; | |
576 | - PyInt extra = 0; /* lines added to text, can be negative */ | |
577 | - char **array; | |
578 | - buf_T *savebuf; | |
579 | - | |
580 | - if (new_len == 0) /* avoid allocating zero bytes */ | |
581 | - array = NULL; | |
582 | - else | |
583 | - { | |
584 | - array = (char **)alloc((unsigned)(new_len * sizeof(char *))); | |
585 | - if (array == NULL) | |
586 | - { | |
587 | - PyErr_NoMemory(); | |
588 | - return FAIL; | |
589 | - } | |
590 | - } | |
591 | - | |
592 | - for (i = 0; i < new_len; ++i) | |
593 | - { | |
594 | - PyObject *line = PyList_GetItem(list, i); | |
595 | - | |
596 | - array[i] = StringToLine(line); | |
597 | - if (array[i] == NULL) | |
598 | - { | |
599 | - while (i) | |
600 | - vim_free(array[--i]); | |
601 | - vim_free(array); | |
602 | - return FAIL; | |
603 | - } | |
604 | - } | |
605 | - | |
606 | - savebuf = curbuf; | |
607 | - | |
608 | - PyErr_Clear(); | |
609 | - curbuf = buf; | |
610 | - | |
611 | - if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL) | |
612 | - PyErr_SetVim(_("cannot save undo information")); | |
613 | - | |
614 | - /* If the size of the range is reducing (ie, new_len < old_len) we | |
615 | - * need to delete some old_len. We do this at the start, by | |
616 | - * repeatedly deleting line "lo". | |
617 | - */ | |
618 | - if (!PyErr_Occurred()) | |
619 | - { | |
620 | - for (i = 0; i < old_len - new_len; ++i) | |
621 | - if (ml_delete((linenr_T)lo, FALSE) == FAIL) | |
622 | - { | |
623 | - PyErr_SetVim(_("cannot delete line")); | |
624 | - break; | |
625 | - } | |
626 | - extra -= i; | |
627 | - } | |
628 | - | |
629 | - /* For as long as possible, replace the existing old_len with the | |
630 | - * new old_len. This is a more efficient operation, as it requires | |
631 | - * less memory allocation and freeing. | |
632 | - */ | |
633 | - if (!PyErr_Occurred()) | |
634 | - { | |
635 | - for (i = 0; i < old_len && i < new_len; ++i) | |
636 | - if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE) | |
637 | - == FAIL) | |
638 | - { | |
639 | - PyErr_SetVim(_("cannot replace line")); | |
640 | - break; | |
641 | - } | |
642 | - } | |
643 | - else | |
644 | - i = 0; | |
645 | - | |
646 | - /* Now we may need to insert the remaining new old_len. If we do, we | |
647 | - * must free the strings as we finish with them (we can't pass the | |
648 | - * responsibility to vim in this case). | |
649 | - */ | |
650 | - if (!PyErr_Occurred()) | |
651 | - { | |
652 | - while (i < new_len) | |
653 | - { | |
654 | - if (ml_append((linenr_T)(lo + i - 1), | |
655 | - (char_u *)array[i], 0, FALSE) == FAIL) | |
656 | - { | |
657 | - PyErr_SetVim(_("cannot insert line")); | |
658 | - break; | |
659 | - } | |
660 | - vim_free(array[i]); | |
661 | - ++i; | |
662 | - ++extra; | |
663 | - } | |
664 | - } | |
665 | - | |
666 | - /* Free any left-over old_len, as a result of an error */ | |
667 | - while (i < new_len) | |
668 | - { | |
669 | - vim_free(array[i]); | |
670 | - ++i; | |
671 | - } | |
672 | - | |
673 | - /* Free the array of old_len. All of its contents have now | |
674 | - * been dealt with (either freed, or the responsibility passed | |
675 | - * to vim. | |
676 | - */ | |
677 | - vim_free(array); | |
678 | - | |
679 | - /* Adjust marks. Invalidate any which lie in the | |
680 | - * changed range, and move any in the remainder of the buffer. | |
681 | - */ | |
682 | - mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), | |
683 | - (long)MAXLNUM, (long)extra); | |
684 | - changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra); | |
685 | - | |
686 | - if (buf == curwin->w_buffer) | |
687 | - py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra); | |
688 | - | |
689 | - curbuf = savebuf; | |
690 | - | |
691 | - if (PyErr_Occurred() || VimErrorCheck()) | |
692 | - return FAIL; | |
693 | - | |
694 | - if (len_change) | |
695 | - *len_change = new_len - old_len; | |
696 | - | |
697 | - return OK; | |
698 | - } | |
699 | - else | |
700 | - { | |
701 | - PyErr_BadArgument(); | |
702 | - return FAIL; | |
703 | - } | |
704 | - } | |
705 | - | |
706 | /* Convert a Vim line into a Python string. | |
707 | * All internal newlines are replaced by null characters. | |
708 | * | |
709 | --- 1404,1409 ---- | |
710 | *** ../mercurial/vim73/src/if_python3.c 2011-06-12 21:37:06.000000000 +0200 | |
711 | --- src/if_python3.c 2011-06-19 00:10:42.000000000 +0200 | |
712 | *************** | |
713 | *** 70,77 **** | |
714 | ||
715 | #define PyInt Py_ssize_t | |
716 | #define PyString_Check(obj) PyUnicode_Check(obj) | |
717 | ! #define PyString_AsString(obj) _PyUnicode_AsString(obj) | |
718 | ! #define PyString_Size(obj) PyUnicode_GET_SIZE(obj) | |
719 | #define PyString_FromString(repr) PyUnicode_FromString(repr) | |
720 | ||
721 | #if defined(DYNAMIC_PYTHON3) || defined(PROTO) | |
722 | --- 70,79 ---- | |
723 | ||
724 | #define PyInt Py_ssize_t | |
725 | #define PyString_Check(obj) PyUnicode_Check(obj) | |
726 | ! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)p_enc, NULL); | |
727 | ! #define PyString_FreeBytes(obj) Py_XDECREF(bytes) | |
728 | ! #define PyString_AsString(obj) PyBytes_AsString(obj) | |
729 | ! #define PyString_Size(obj) PyBytes_GET_SIZE(bytes) | |
730 | #define PyString_FromString(repr) PyUnicode_FromString(repr) | |
731 | ||
732 | #if defined(DYNAMIC_PYTHON3) || defined(PROTO) | |
733 | *************** | |
734 | *** 99,104 **** | |
735 | --- 101,107 ---- | |
736 | # define PyArg_Parse py3_PyArg_Parse | |
737 | # undef PyArg_ParseTuple | |
738 | # define PyArg_ParseTuple py3_PyArg_ParseTuple | |
739 | + # define PyMem_Free py3_PyMem_Free | |
740 | # define PyDict_SetItemString py3_PyDict_SetItemString | |
741 | # define PyErr_BadArgument py3_PyErr_BadArgument | |
742 | # define PyErr_Clear py3_PyErr_Clear | |
743 | *************** | |
744 | *** 140,147 **** | |
745 | --- 143,155 ---- | |
746 | # define PyModule_AddObject py3_PyModule_AddObject | |
747 | # define PyImport_AppendInittab py3_PyImport_AppendInittab | |
748 | # define _PyUnicode_AsString py3__PyUnicode_AsString | |
749 | + # undef PyUnicode_AsEncodedString | |
750 | + # define PyUnicode_AsEncodedString py3_PyUnicode_AsEncodedString | |
751 | + # undef PyBytes_AsString | |
752 | + # define PyBytes_AsString py3_PyBytes_AsString | |
753 | # define PyObject_GenericGetAttr py3_PyObject_GenericGetAttr | |
754 | # define PySlice_Type (*py3_PySlice_Type) | |
755 | + # define PyErr_NewException py3_PyErr_NewException | |
756 | # ifdef Py_DEBUG | |
757 | # define _Py_NegativeRefcount py3__Py_NegativeRefcount | |
758 | # define _Py_RefTotal (*py3__Py_RefTotal) | |
759 | *************** | |
760 | *** 157,164 **** | |
761 | # define PyModule_Create2 py3_PyModule_Create2 | |
762 | # undef PyUnicode_FromString | |
763 | # define PyUnicode_FromString py3_PyUnicode_FromString | |
764 | ! # undef PyUnicode_FromStringAndSize | |
765 | ! # define PyUnicode_FromStringAndSize py3_PyUnicode_FromStringAndSize | |
766 | ||
767 | # ifdef Py_DEBUG | |
768 | # undef PyObject_NEW | |
769 | --- 165,172 ---- | |
770 | # define PyModule_Create2 py3_PyModule_Create2 | |
771 | # undef PyUnicode_FromString | |
772 | # define PyUnicode_FromString py3_PyUnicode_FromString | |
773 | ! # undef PyUnicode_Decode | |
774 | ! # define PyUnicode_Decode py3_PyUnicode_Decode | |
775 | ||
776 | # ifdef Py_DEBUG | |
777 | # undef PyObject_NEW | |
778 | *************** | |
779 | *** 199,205 **** | |
780 | static int (*py3_PyType_Ready)(PyTypeObject *type); | |
781 | static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item); | |
782 | static PyObject* (*py3_PyUnicode_FromString)(const char *u); | |
783 | ! static PyObject* (*py3_PyUnicode_FromStringAndSize)(const char *u, Py_ssize_t size); | |
784 | static long (*py3_PyLong_AsLong)(PyObject *); | |
785 | static void (*py3_PyErr_SetNone)(PyObject *); | |
786 | static void (*py3_PyEval_InitThreads)(void); | |
787 | --- 207,214 ---- | |
788 | static int (*py3_PyType_Ready)(PyTypeObject *type); | |
789 | static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item); | |
790 | static PyObject* (*py3_PyUnicode_FromString)(const char *u); | |
791 | ! static PyObject* (*py3_PyUnicode_Decode)(const char *u, Py_ssize_t size, | |
792 | ! const char *encoding, const char *errors); | |
793 | static long (*py3_PyLong_AsLong)(PyObject *); | |
794 | static void (*py3_PyErr_SetNone)(PyObject *); | |
795 | static void (*py3_PyEval_InitThreads)(void); | |
796 | *************** | |
797 | *** 207,212 **** | |
798 | --- 216,222 ---- | |
799 | static PyThreadState*(*py3_PyEval_SaveThread)(void); | |
800 | static int (*py3_PyArg_Parse)(PyObject *, char *, ...); | |
801 | static int (*py3_PyArg_ParseTuple)(PyObject *, char *, ...); | |
802 | + static int (*py3_PyMem_Free)(void *); | |
803 | static int (*py3_Py_IsInitialized)(void); | |
804 | static void (*py3_PyErr_Clear)(void); | |
805 | static PyObject*(*py3__PyObject_Init)(PyObject *, PyTypeObject *); | |
806 | *************** | |
807 | *** 214,224 **** | |
808 | --- 224,237 ---- | |
809 | static int (*py3_PyModule_AddObject)(PyObject *m, const char *name, PyObject *o); | |
810 | static int (*py3_PyImport_AppendInittab)(const char *name, PyObject* (*initfunc)(void)); | |
811 | static char* (*py3__PyUnicode_AsString)(PyObject *unicode); | |
812 | + static PyObject* (*py3_PyUnicode_AsEncodedString)(PyObject *unicode, const char* encoding, const char* errors); | |
813 | + static char* (*py3_PyBytes_AsString)(PyObject *bytes); | |
814 | static PyObject* (*py3_PyObject_GenericGetAttr)(PyObject *obj, PyObject *name); | |
815 | static PyObject* (*py3_PyModule_Create2)(struct PyModuleDef* module, int module_api_version); | |
816 | static PyObject* (*py3_PyType_GenericAlloc)(PyTypeObject *type, Py_ssize_t nitems); | |
817 | static PyObject* (*py3_PyType_GenericNew)(PyTypeObject *type, PyObject *args, PyObject *kwds); | |
818 | static PyTypeObject* py3_PySlice_Type; | |
819 | + static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict); | |
820 | # ifdef Py_DEBUG | |
821 | static void (*py3__Py_NegativeRefcount)(const char *fname, int lineno, PyObject *op); | |
822 | static Py_ssize_t* py3__Py_RefTotal; | |
823 | *************** | |
824 | *** 259,264 **** | |
825 | --- 272,278 ---- | |
826 | {"Py_SetPythonHome", (PYTHON_PROC*)&py3_Py_SetPythonHome}, | |
827 | {"Py_Initialize", (PYTHON_PROC*)&py3_Py_Initialize}, | |
828 | {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple}, | |
829 | + {"PyMem_Free", (PYTHON_PROC*)&py3_PyMem_Free}, | |
830 | {"PyList_New", (PYTHON_PROC*)&py3_PyList_New}, | |
831 | {"PyGILState_Ensure", (PYTHON_PROC*)&py3_PyGILState_Ensure}, | |
832 | {"PyGILState_Release", (PYTHON_PROC*)&py3_PyGILState_Release}, | |
833 | *************** | |
834 | *** 289,295 **** | |
835 | {"PyEval_RestoreThread", (PYTHON_PROC*)&py3_PyEval_RestoreThread}, | |
836 | {"PyEval_SaveThread", (PYTHON_PROC*)&py3_PyEval_SaveThread}, | |
837 | {"PyArg_Parse", (PYTHON_PROC*)&py3_PyArg_Parse}, | |
838 | - {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple}, | |
839 | {"Py_IsInitialized", (PYTHON_PROC*)&py3_Py_IsInitialized}, | |
840 | {"_Py_NoneStruct", (PYTHON_PROC*)&py3__Py_NoneStruct}, | |
841 | {"PyErr_Clear", (PYTHON_PROC*)&py3_PyErr_Clear}, | |
842 | --- 303,308 ---- | |
843 | *************** | |
844 | *** 297,307 **** | |
845 | --- 310,322 ---- | |
846 | {"PyModule_AddObject", (PYTHON_PROC*)&py3_PyModule_AddObject}, | |
847 | {"PyImport_AppendInittab", (PYTHON_PROC*)&py3_PyImport_AppendInittab}, | |
848 | {"_PyUnicode_AsString", (PYTHON_PROC*)&py3__PyUnicode_AsString}, | |
849 | + {"PyBytes_AsString", (PYTHON_PROC*)&py3_PyBytes_AsString}, | |
850 | {"PyObject_GenericGetAttr", (PYTHON_PROC*)&py3_PyObject_GenericGetAttr}, | |
851 | {"PyModule_Create2", (PYTHON_PROC*)&py3_PyModule_Create2}, | |
852 | {"PyType_GenericAlloc", (PYTHON_PROC*)&py3_PyType_GenericAlloc}, | |
853 | {"PyType_GenericNew", (PYTHON_PROC*)&py3_PyType_GenericNew}, | |
854 | {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type}, | |
855 | + {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException}, | |
856 | # ifdef Py_DEBUG | |
857 | {"_Py_NegativeRefcount", (PYTHON_PROC*)&py3__Py_NegativeRefcount}, | |
858 | {"_Py_RefTotal", (PYTHON_PROC*)&py3__Py_RefTotal}, | |
859 | *************** | |
860 | *** 337,343 **** | |
861 | py3_runtime_link_init(char *libname, int verbose) | |
862 | { | |
863 | int i; | |
864 | ! void *ucs_from_string, *ucs_from_string_and_size; | |
865 | ||
866 | # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON) | |
867 | /* Can't have Python and Python3 loaded at the same time. | |
868 | --- 352,358 ---- | |
869 | py3_runtime_link_init(char *libname, int verbose) | |
870 | { | |
871 | int i; | |
872 | ! void *ucs_from_string, *ucs_decode, *ucs_as_encoded_string; | |
873 | ||
874 | # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON) | |
875 | /* Can't have Python and Python3 loaded at the same time. | |
876 | *************** | |
877 | *** 377,395 **** | |
878 | /* Load unicode functions separately as only the ucs2 or the ucs4 functions | |
879 | * will be present in the library. */ | |
880 | ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString"); | |
881 | ! ucs_from_string_and_size = symbol_from_dll(hinstPy3, | |
882 | ! "PyUnicodeUCS2_FromStringAndSize"); | |
883 | ! if (!ucs_from_string || !ucs_from_string_and_size) | |
884 | { | |
885 | ucs_from_string = symbol_from_dll(hinstPy3, | |
886 | "PyUnicodeUCS4_FromString"); | |
887 | ! ucs_from_string_and_size = symbol_from_dll(hinstPy3, | |
888 | ! "PyUnicodeUCS4_FromStringAndSize"); | |
889 | } | |
890 | ! if (ucs_from_string && ucs_from_string_and_size) | |
891 | { | |
892 | py3_PyUnicode_FromString = ucs_from_string; | |
893 | ! py3_PyUnicode_FromStringAndSize = ucs_from_string_and_size; | |
894 | } | |
895 | else | |
896 | { | |
897 | --- 392,415 ---- | |
898 | /* Load unicode functions separately as only the ucs2 or the ucs4 functions | |
899 | * will be present in the library. */ | |
900 | ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString"); | |
901 | ! ucs_decode = symbol_from_dll(hinstPy3, | |
902 | ! "PyUnicodeUCS2_Decode"); | |
903 | ! ucs_as_encoded_string = symbol_from_dll(hinstPy3, | |
904 | ! "PyUnicodeUCS2_AsEncodedString"); | |
905 | ! if (!ucs_from_string || !ucs_decode || !ucs_as_encoded_string) | |
906 | { | |
907 | ucs_from_string = symbol_from_dll(hinstPy3, | |
908 | "PyUnicodeUCS4_FromString"); | |
909 | ! ucs_decode = symbol_from_dll(hinstPy3, | |
910 | ! "PyUnicodeUCS4_Decode"); | |
911 | ! ucs_as_encoded_string = symbol_from_dll(hinstPy3, | |
912 | ! "PyUnicodeUCS4_AsEncodedString"); | |
913 | } | |
914 | ! if (ucs_from_string && ucs_decode && ucs_as_encoded_string) | |
915 | { | |
916 | py3_PyUnicode_FromString = ucs_from_string; | |
917 | ! py3_PyUnicode_Decode = ucs_decode; | |
918 | ! py3_PyUnicode_AsEncodedString = ucs_as_encoded_string; | |
919 | } | |
920 | else | |
921 | { | |
922 | *************** | |
923 | *** 567,574 **** | |
924 | /* Remove the element from sys.path that was added because of our | |
925 | * argv[0] value in Py3Init_vim(). Previously we used an empty | |
926 | * string, but dependinding on the OS we then get an empty entry or | |
927 | ! * the current directory in sys.path. */ | |
928 | ! PyRun_SimpleString("import sys; sys.path = list(filter(lambda x: x != '/must>not&exist', sys.path))"); | |
929 | ||
930 | // lock is created and acquired in PyEval_InitThreads() and thread | |
931 | // state is created in Py_Initialize() | |
932 | --- 587,597 ---- | |
933 | /* Remove the element from sys.path that was added because of our | |
934 | * argv[0] value in Py3Init_vim(). Previously we used an empty | |
935 | * string, but dependinding on the OS we then get an empty entry or | |
936 | ! * the current directory in sys.path. | |
937 | ! * Only after vim has been imported, the element does exist in | |
938 | ! * sys.path. | |
939 | ! */ | |
940 | ! PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))"); | |
941 | ||
942 | // lock is created and acquired in PyEval_InitThreads() and thread | |
943 | // state is created in Py_Initialize() | |
944 | *************** | |
945 | *** 605,610 **** | |
946 | --- 628,635 ---- | |
947 | #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) | |
948 | char *saved_locale; | |
949 | #endif | |
950 | + PyObject *cmdstr; | |
951 | + PyObject *cmdbytes; | |
952 | ||
953 | #if defined(MACOS) && !defined(MACOS_X_UNIX) | |
954 | GetPort(&oldPort); | |
955 | *************** | |
956 | *** 634,640 **** | |
957 | ||
958 | pygilstate = PyGILState_Ensure(); | |
959 | ||
960 | ! PyRun_SimpleString((char *)(cmd)); | |
961 | ||
962 | PyGILState_Release(pygilstate); | |
963 | ||
964 | --- 659,671 ---- | |
965 | ||
966 | pygilstate = PyGILState_Ensure(); | |
967 | ||
968 | ! /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause | |
969 | ! * SyntaxError (unicode error). */ | |
970 | ! cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)p_enc, NULL); | |
971 | ! cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", NULL); | |
972 | ! Py_XDECREF(cmdstr); | |
973 | ! PyRun_SimpleString(PyBytes_AsString(cmdbytes)); | |
974 | ! Py_XDECREF(cmdbytes); | |
975 | ||
976 | PyGILState_Release(pygilstate); | |
977 | ||
978 | *************** | |
979 | *** 693,699 **** | |
980 | * different options under Windows, meaning that stdio pointers aren't | |
981 | * compatible between the two. Yuk. | |
982 | * | |
983 | ! * construct: exec(compile(open('a_filename').read(), 'a_filename', 'exec')) | |
984 | * | |
985 | * We need to escape any backslashes or single quotes in the file name, so that | |
986 | * Python won't mangle the file name. | |
987 | --- 724,733 ---- | |
988 | * different options under Windows, meaning that stdio pointers aren't | |
989 | * compatible between the two. Yuk. | |
990 | * | |
991 | ! * construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec')) | |
992 | ! * | |
993 | ! * Using bytes so that Python can detect the source encoding as it normally | |
994 | ! * does. The doc does not say "compile" accept bytes, though. | |
995 | * | |
996 | * We need to escape any backslashes or single quotes in the file name, so that | |
997 | * Python won't mangle the file name. | |
998 | *************** | |
999 | *** 716,723 **** | |
1000 | return; | |
1001 | if (i==0) | |
1002 | { | |
1003 | ! strcpy(p,"').read(),'"); | |
1004 | ! p += 11; | |
1005 | } | |
1006 | else | |
1007 | { | |
1008 | --- 750,757 ---- | |
1009 | return; | |
1010 | if (i==0) | |
1011 | { | |
1012 | ! strcpy(p,"','rb').read(),'"); | |
1013 | ! p += 16; | |
1014 | } | |
1015 | else | |
1016 | { | |
1017 | *************** | |
1018 | *** 812,819 **** | |
1019 | ||
1020 | static Py_ssize_t BufferLength(PyObject *); | |
1021 | static PyObject *BufferItem(PyObject *, Py_ssize_t); | |
1022 | - static Py_ssize_t BufferAsItem(PyObject *, Py_ssize_t, PyObject *); | |
1023 | static PyObject* BufferSubscript(PyObject *self, PyObject* idx); | |
1024 | ||
1025 | ||
1026 | /* Line range type - Implementation functions | |
1027 | --- 846,853 ---- | |
1028 | ||
1029 | static Py_ssize_t BufferLength(PyObject *); | |
1030 | static PyObject *BufferItem(PyObject *, Py_ssize_t); | |
1031 | static PyObject* BufferSubscript(PyObject *self, PyObject* idx); | |
1032 | + static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val); | |
1033 | ||
1034 | ||
1035 | /* Line range type - Implementation functions | |
1036 | *************** | |
1037 | *** 835,841 **** | |
1038 | (ssizeargfunc) 0, /* sq_repeat, x*n */ | |
1039 | (ssizeargfunc) BufferItem, /* sq_item, x[i] */ | |
1040 | 0, /* was_sq_slice, x[i:j] */ | |
1041 | ! (ssizeobjargproc) BufferAsItem, /* sq_ass_item, x[i]=v */ | |
1042 | 0, /* sq_ass_slice, x[i:j]=v */ | |
1043 | 0, /* sq_contains */ | |
1044 | 0, /* sq_inplace_concat */ | |
1045 | --- 869,875 ---- | |
1046 | (ssizeargfunc) 0, /* sq_repeat, x*n */ | |
1047 | (ssizeargfunc) BufferItem, /* sq_item, x[i] */ | |
1048 | 0, /* was_sq_slice, x[i:j] */ | |
1049 | ! 0, /* sq_ass_item, x[i]=v */ | |
1050 | 0, /* sq_ass_slice, x[i:j]=v */ | |
1051 | 0, /* sq_contains */ | |
1052 | 0, /* sq_inplace_concat */ | |
1053 | *************** | |
1054 | *** 845,851 **** | |
1055 | PyMappingMethods BufferAsMapping = { | |
1056 | /* mp_length */ (lenfunc)BufferLength, | |
1057 | /* mp_subscript */ (binaryfunc)BufferSubscript, | |
1058 | ! /* mp_ass_subscript */ (objobjargproc)0, | |
1059 | }; | |
1060 | ||
1061 | ||
1062 | --- 879,885 ---- | |
1063 | PyMappingMethods BufferAsMapping = { | |
1064 | /* mp_length */ (lenfunc)BufferLength, | |
1065 | /* mp_subscript */ (binaryfunc)BufferSubscript, | |
1066 | ! /* mp_ass_subscript */ (objobjargproc)BufferAsSubscript, | |
1067 | }; | |
1068 | ||
1069 | ||
1070 | *************** | |
1071 | *** 897,902 **** | |
1072 | --- 931,938 ---- | |
1073 | ||
1074 | if (this->buf && this->buf != INVALID_BUFFER_VALUE) | |
1075 | this->buf->b_python3_ref = NULL; | |
1076 | + | |
1077 | + Py_TYPE(self)->tp_free((PyObject*)self); | |
1078 | } | |
1079 | ||
1080 | static PyObject * | |
1081 | *************** | |
1082 | *** 975,989 **** | |
1083 | (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count); | |
1084 | } | |
1085 | ||
1086 | - static Py_ssize_t | |
1087 | - BufferAsItem(PyObject *self, Py_ssize_t n, PyObject *val) | |
1088 | - { | |
1089 | - return RBAsItem((BufferObject *)(self), n, val, 1, | |
1090 | - (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count, | |
1091 | - NULL); | |
1092 | - } | |
1093 | - | |
1094 | - | |
1095 | static PyObject * | |
1096 | BufferSubscript(PyObject *self, PyObject* idx) | |
1097 | { | |
1098 | --- 1011,1016 ---- | |
1099 | *************** | |
1100 | *** 999,1011 **** | |
1101 | &step, &slicelen) < 0) { | |
1102 | return NULL; | |
1103 | } | |
1104 | ! return BufferSlice(self,start,stop+1); | |
1105 | } else { | |
1106 | PyErr_SetString(PyExc_IndexError, "Index must be int or slice"); | |
1107 | return NULL; | |
1108 | } | |
1109 | } | |
1110 | ||
1111 | static PySequenceMethods RangeAsSeq = { | |
1112 | (lenfunc) RangeLength, /* sq_length, len(x) */ | |
1113 | (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */ | |
1114 | --- 1026,1064 ---- | |
1115 | &step, &slicelen) < 0) { | |
1116 | return NULL; | |
1117 | } | |
1118 | ! return BufferSlice(self,start,stop); | |
1119 | } else { | |
1120 | PyErr_SetString(PyExc_IndexError, "Index must be int or slice"); | |
1121 | return NULL; | |
1122 | } | |
1123 | } | |
1124 | ||
1125 | + static Py_ssize_t | |
1126 | + BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val) | |
1127 | + { | |
1128 | + if (PyLong_Check(idx)) { | |
1129 | + long n = PyLong_AsLong(idx); | |
1130 | + return RBAsItem((BufferObject *)(self), n, val, 1, | |
1131 | + (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count, | |
1132 | + NULL); | |
1133 | + } else if (PySlice_Check(idx)) { | |
1134 | + Py_ssize_t start, stop, step, slicelen; | |
1135 | + | |
1136 | + if (PySlice_GetIndicesEx((PySliceObject *)idx, | |
1137 | + (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1, | |
1138 | + &start, &stop, | |
1139 | + &step, &slicelen) < 0) { | |
1140 | + return -1; | |
1141 | + } | |
1142 | + return RBAsSlice((BufferObject *)(self), start, stop, val, 1, | |
1143 | + (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count, | |
1144 | + NULL); | |
1145 | + } else { | |
1146 | + PyErr_SetString(PyExc_IndexError, "Index must be int or slice"); | |
1147 | + return -1; | |
1148 | + } | |
1149 | + } | |
1150 | + | |
1151 | static PySequenceMethods RangeAsSeq = { | |
1152 | (lenfunc) RangeLength, /* sq_length, len(x) */ | |
1153 | (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */ | |
1154 | *************** | |
1155 | *** 1032,1037 **** | |
1156 | --- 1085,1091 ---- | |
1157 | RangeDestructor(PyObject *self) | |
1158 | { | |
1159 | Py_DECREF(((RangeObject *)(self))->buf); | |
1160 | + Py_TYPE(self)->tp_free((PyObject*)self); | |
1161 | } | |
1162 | ||
1163 | static PyObject * | |
1164 | *************** | |
1165 | *** 1159,1164 **** | |
1166 | --- 1213,1220 ---- | |
1167 | ||
1168 | if (this->win && this->win != INVALID_WINDOW_VALUE) | |
1169 | this->win->w_python3_ref = NULL; | |
1170 | + | |
1171 | + Py_TYPE(self)->tp_free((PyObject*)self); | |
1172 | } | |
1173 | ||
1174 | static PyObject * | |
1175 | *************** | |
1176 | *** 1350,1357 **** | |
1177 | PySys_SetArgv(1, argv); | |
1178 | ||
1179 | mod = PyModule_Create(&vimmodule); | |
1180 | ||
1181 | ! VimError = Py_BuildValue("s", "vim.error"); | |
1182 | ||
1183 | PyModule_AddObject(mod, "error", VimError); | |
1184 | Py_INCREF((PyObject *)(void *)&TheBufferList); | |
1185 | --- 1406,1416 ---- | |
1186 | PySys_SetArgv(1, argv); | |
1187 | ||
1188 | mod = PyModule_Create(&vimmodule); | |
1189 | + if (mod == NULL) | |
1190 | + return NULL; | |
1191 | ||
1192 | ! VimError = PyErr_NewException("vim.error", NULL, NULL); | |
1193 | ! Py_INCREF(VimError); | |
1194 | ||
1195 | PyModule_AddObject(mod, "error", VimError); | |
1196 | Py_INCREF((PyObject *)(void *)&TheBufferList); | |
1197 | *************** | |
1198 | *** 1404,1410 **** | |
1199 | } | |
1200 | *p = '\0'; | |
1201 | ||
1202 | ! result = PyUnicode_FromStringAndSize(tmp, len); | |
1203 | ||
1204 | vim_free(tmp); | |
1205 | return result; | |
1206 | --- 1463,1469 ---- | |
1207 | } | |
1208 | *p = '\0'; | |
1209 | ||
1210 | ! result = PyUnicode_Decode(tmp, len, (char *)p_enc, NULL); | |
1211 | ||
1212 | vim_free(tmp); | |
1213 | return result; | |
1214 | *** ../vim-7.3.219/src/version.c 2011-06-13 02:03:55.000000000 +0200 | |
1215 | --- src/version.c 2011-06-19 00:25:38.000000000 +0200 | |
1216 | *************** | |
1217 | *** 711,712 **** | |
1218 | --- 711,714 ---- | |
1219 | { /* Add new patch number below this line */ | |
1220 | + /**/ | |
1221 | + 220, | |
1222 | /**/ | |
1223 | ||
1224 | -- | |
1225 | I'm in shape. Round IS a shape. | |
1226 | ||
1227 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
1228 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
1229 | \\\ an exciting new programming language -- http://www.Zimbu.org /// | |
1230 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |