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

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