Karsten Hopp 521789
To: vim_dev@googlegroups.com
Karsten Hopp 521789
Subject: Patch 7.3.220
Karsten Hopp 521789
Fcc: outbox
Karsten Hopp 521789
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 521789
Mime-Version: 1.0
Karsten Hopp 521789
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 521789
Content-Transfer-Encoding: 8bit
Karsten Hopp 521789
------------
Karsten Hopp 521789
Karsten Hopp 521789
Patch 7.3.220
Karsten Hopp 521789
Problem:    Python 3: vim.error is a 'str' instead of an 'Exception' object,
Karsten Hopp 521789
            so 'except' or 'raise' it causes a 'SystemError' exception.
Karsten Hopp 521789
            Buffer objects do not support slice assignment.
Karsten Hopp 521789
            When exchanging text between Vim and Python, multibyte texts become
Karsten Hopp 521789
            gabage or cause Unicode Expceptions, etc.
Karsten Hopp 521789
            'py3file' tries to read in the file as Unicode, sometimes causes
Karsten Hopp 521789
            UnicodeDecodeException
Karsten Hopp 521789
Solution:   Fix the problems. (lilydjwg)
Karsten Hopp 521789
Files:      src/if_py_both.h, src/if_python.c, src/if_python3.c
Karsten Hopp 521789
    
Karsten Hopp 521789
Karsten Hopp 521789
*** ../mercurial/vim73/src/if_py_both.h	2011-03-22 15:47:18.000000000 +0100
Karsten Hopp 521789
--- src/if_py_both.h	2011-06-18 23:54:25.000000000 +0200
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 65,74 ****
Karsten Hopp 521789
  OutputWrite(PyObject *self, PyObject *args)
Karsten Hopp 521789
  {
Karsten Hopp 521789
      int len;
Karsten Hopp 521789
!     char *str;
Karsten Hopp 521789
      int error = ((OutputObject *)(self))->error;
Karsten Hopp 521789
  
Karsten Hopp 521789
!     if (!PyArg_ParseTuple(args, "s#", &str, &len))
Karsten Hopp 521789
  	return NULL;
Karsten Hopp 521789
  
Karsten Hopp 521789
      Py_BEGIN_ALLOW_THREADS
Karsten Hopp 521789
--- 65,74 ----
Karsten Hopp 521789
  OutputWrite(PyObject *self, PyObject *args)
Karsten Hopp 521789
  {
Karsten Hopp 521789
      int len;
Karsten Hopp 521789
!     char *str = NULL;
Karsten Hopp 521789
      int error = ((OutputObject *)(self))->error;
Karsten Hopp 521789
  
Karsten Hopp 521789
!     if (!PyArg_ParseTuple(args, "es#", p_enc, &str, &len))
Karsten Hopp 521789
  	return NULL;
Karsten Hopp 521789
  
Karsten Hopp 521789
      Py_BEGIN_ALLOW_THREADS
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 76,81 ****
Karsten Hopp 521789
--- 76,82 ----
Karsten Hopp 521789
      writer((writefn)(error ? emsg : msg), (char_u *)str, len);
Karsten Hopp 521789
      Python_Release_Vim();
Karsten Hopp 521789
      Py_END_ALLOW_THREADS
Karsten Hopp 521789
+     PyMem_Free(str);
Karsten Hopp 521789
  
Karsten Hopp 521789
      Py_INCREF(Py_None);
Karsten Hopp 521789
      return Py_None;
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 104,113 ****
Karsten Hopp 521789
      for (i = 0; i < n; ++i)
Karsten Hopp 521789
      {
Karsten Hopp 521789
  	PyObject *line = PyList_GetItem(list, i);
Karsten Hopp 521789
! 	char *str;
Karsten Hopp 521789
  	PyInt len;
Karsten Hopp 521789
  
Karsten Hopp 521789
! 	if (!PyArg_Parse(line, "s#", &str, &len)) {
Karsten Hopp 521789
  	    PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
Karsten Hopp 521789
  	    Py_DECREF(list);
Karsten Hopp 521789
  	    return NULL;
Karsten Hopp 521789
--- 105,114 ----
Karsten Hopp 521789
      for (i = 0; i < n; ++i)
Karsten Hopp 521789
      {
Karsten Hopp 521789
  	PyObject *line = PyList_GetItem(list, i);
Karsten Hopp 521789
! 	char *str = NULL;
Karsten Hopp 521789
  	PyInt len;
Karsten Hopp 521789
  
Karsten Hopp 521789
! 	if (!PyArg_Parse(line, "es#", p_enc, &str, &len)) {
Karsten Hopp 521789
  	    PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
Karsten Hopp 521789
  	    Py_DECREF(list);
Karsten Hopp 521789
  	    return NULL;
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 118,123 ****
Karsten Hopp 521789
--- 119,125 ----
Karsten Hopp 521789
  	writer((writefn)(error ? emsg : msg), (char_u *)str, len);
Karsten Hopp 521789
  	Python_Release_Vim();
Karsten Hopp 521789
  	Py_END_ALLOW_THREADS
Karsten Hopp 521789
+ 	PyMem_Free(str);
Karsten Hopp 521789
      }
Karsten Hopp 521789
  
Karsten Hopp 521789
      Py_DECREF(list);
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 681,686 ****
Karsten Hopp 521789
--- 683,689 ----
Karsten Hopp 521789
  {
Karsten Hopp 521789
      const char *str;
Karsten Hopp 521789
      char *save;
Karsten Hopp 521789
+     PyObject *bytes;
Karsten Hopp 521789
      PyInt len;
Karsten Hopp 521789
      PyInt i;
Karsten Hopp 521789
      char *p;
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 691,698 ****
Karsten Hopp 521789
  	return NULL;
Karsten Hopp 521789
      }
Karsten Hopp 521789
  
Karsten Hopp 521789
!     str = PyString_AsString(obj);
Karsten Hopp 521789
!     len = PyString_Size(obj);
Karsten Hopp 521789
  
Karsten Hopp 521789
      /*
Karsten Hopp 521789
       * Error checking: String must not contain newlines, as we
Karsten Hopp 521789
--- 694,702 ----
Karsten Hopp 521789
  	return NULL;
Karsten Hopp 521789
      }
Karsten Hopp 521789
  
Karsten Hopp 521789
!     bytes = PyString_AsBytes(obj);  /* for Python 2 this does nothing */
Karsten Hopp 521789
!     str = PyString_AsString(bytes);
Karsten Hopp 521789
!     len = PyString_Size(bytes);
Karsten Hopp 521789
  
Karsten Hopp 521789
      /*
Karsten Hopp 521789
       * Error checking: String must not contain newlines, as we
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 731,736 ****
Karsten Hopp 521789
--- 735,741 ----
Karsten Hopp 521789
      }
Karsten Hopp 521789
  
Karsten Hopp 521789
      save[i] = '\0';
Karsten Hopp 521789
+     PyString_FreeBytes(bytes);  /* Python 2 does nothing here */
Karsten Hopp 521789
  
Karsten Hopp 521789
      return save;
Karsten Hopp 521789
  }
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 817,823 ****
Karsten Hopp 521789
      invalidate_botline();
Karsten Hopp 521789
  }
Karsten Hopp 521789
  
Karsten Hopp 521789
! /* Replace a line in the specified buffer. The line number is
Karsten Hopp 521789
   * in Vim format (1-based). The replacement line is given as
Karsten Hopp 521789
   * a Python string object. The object is checked for validity
Karsten Hopp 521789
   * and correct format. Errors are returned as a value of FAIL.
Karsten Hopp 521789
--- 822,829 ----
Karsten Hopp 521789
      invalidate_botline();
Karsten Hopp 521789
  }
Karsten Hopp 521789
  
Karsten Hopp 521789
! /*
Karsten Hopp 521789
!  * Replace a line in the specified buffer. The line number is
Karsten Hopp 521789
   * in Vim format (1-based). The replacement line is given as
Karsten Hopp 521789
   * a Python string object. The object is checked for validity
Karsten Hopp 521789
   * and correct format. Errors are returned as a value of FAIL.
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 908,913 ****
Karsten Hopp 521789
--- 914,1106 ----
Karsten Hopp 521789
      }
Karsten Hopp 521789
  }
Karsten Hopp 521789
  
Karsten Hopp 521789
+ /* Replace a range of lines in the specified buffer. The line numbers are in
Karsten Hopp 521789
+  * Vim format (1-based). The range is from lo up to, but not including, hi.
Karsten Hopp 521789
+  * The replacement lines are given as a Python list of string objects. The
Karsten Hopp 521789
+  * list is checked for validity and correct format. Errors are returned as a
Karsten Hopp 521789
+  * value of FAIL.  The return value is OK on success.
Karsten Hopp 521789
+  * If OK is returned and len_change is not NULL, *len_change
Karsten Hopp 521789
+  * is set to the change in the buffer length.
Karsten Hopp 521789
+  */
Karsten Hopp 521789
+     static int
Karsten Hopp 521789
+ SetBufferLineList(buf_T *buf, PyInt lo, PyInt hi, PyObject *list, PyInt *len_change)
Karsten Hopp 521789
+ {
Karsten Hopp 521789
+     /* First of all, we check the thpe of the supplied Python object.
Karsten Hopp 521789
+      * There are three cases:
Karsten Hopp 521789
+      *	  1. NULL, or None - this is a deletion.
Karsten Hopp 521789
+      *	  2. A list	   - this is a replacement.
Karsten Hopp 521789
+      *	  3. Anything else - this is an error.
Karsten Hopp 521789
+      */
Karsten Hopp 521789
+     if (list == Py_None || list == NULL)
Karsten Hopp 521789
+     {
Karsten Hopp 521789
+ 	PyInt	i;
Karsten Hopp 521789
+ 	PyInt	n = (int)(hi - lo);
Karsten Hopp 521789
+ 	buf_T	*savebuf = curbuf;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	PyErr_Clear();
Karsten Hopp 521789
+ 	curbuf = buf;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	if (u_savedel((linenr_T)lo, (long)n) == FAIL)
Karsten Hopp 521789
+ 	    PyErr_SetVim(_("cannot save undo information"));
Karsten Hopp 521789
+ 	else
Karsten Hopp 521789
+ 	{
Karsten Hopp 521789
+ 	    for (i = 0; i < n; ++i)
Karsten Hopp 521789
+ 	    {
Karsten Hopp 521789
+ 		if (ml_delete((linenr_T)lo, FALSE) == FAIL)
Karsten Hopp 521789
+ 		{
Karsten Hopp 521789
+ 		    PyErr_SetVim(_("cannot delete line"));
Karsten Hopp 521789
+ 		    break;
Karsten Hopp 521789
+ 		}
Karsten Hopp 521789
+ 	    }
Karsten Hopp 521789
+ 	    if (buf == curwin->w_buffer)
Karsten Hopp 521789
+ 		py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
Karsten Hopp 521789
+ 	    deleted_lines_mark((linenr_T)lo, (long)i);
Karsten Hopp 521789
+ 	}
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	curbuf = savebuf;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	if (PyErr_Occurred() || VimErrorCheck())
Karsten Hopp 521789
+ 	    return FAIL;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	if (len_change)
Karsten Hopp 521789
+ 	    *len_change = -n;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	return OK;
Karsten Hopp 521789
+     }
Karsten Hopp 521789
+     else if (PyList_Check(list))
Karsten Hopp 521789
+     {
Karsten Hopp 521789
+ 	PyInt	i;
Karsten Hopp 521789
+ 	PyInt	new_len = PyList_Size(list);
Karsten Hopp 521789
+ 	PyInt	old_len = hi - lo;
Karsten Hopp 521789
+ 	PyInt	extra = 0;	/* lines added to text, can be negative */
Karsten Hopp 521789
+ 	char	**array;
Karsten Hopp 521789
+ 	buf_T	*savebuf;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	if (new_len == 0)	/* avoid allocating zero bytes */
Karsten Hopp 521789
+ 	    array = NULL;
Karsten Hopp 521789
+ 	else
Karsten Hopp 521789
+ 	{
Karsten Hopp 521789
+ 	    array = (char **)alloc((unsigned)(new_len * sizeof(char *)));
Karsten Hopp 521789
+ 	    if (array == NULL)
Karsten Hopp 521789
+ 	    {
Karsten Hopp 521789
+ 		PyErr_NoMemory();
Karsten Hopp 521789
+ 		return FAIL;
Karsten Hopp 521789
+ 	    }
Karsten Hopp 521789
+ 	}
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	for (i = 0; i < new_len; ++i)
Karsten Hopp 521789
+ 	{
Karsten Hopp 521789
+ 	    PyObject *line = PyList_GetItem(list, i);
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	    array[i] = StringToLine(line);
Karsten Hopp 521789
+ 	    if (array[i] == NULL)
Karsten Hopp 521789
+ 	    {
Karsten Hopp 521789
+ 		while (i)
Karsten Hopp 521789
+ 		    vim_free(array[--i]);
Karsten Hopp 521789
+ 		vim_free(array);
Karsten Hopp 521789
+ 		return FAIL;
Karsten Hopp 521789
+ 	    }
Karsten Hopp 521789
+ 	}
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	savebuf = curbuf;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	PyErr_Clear();
Karsten Hopp 521789
+ 	curbuf = buf;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
Karsten Hopp 521789
+ 	    PyErr_SetVim(_("cannot save undo information"));
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	/* If the size of the range is reducing (ie, new_len < old_len) we
Karsten Hopp 521789
+ 	 * need to delete some old_len. We do this at the start, by
Karsten Hopp 521789
+ 	 * repeatedly deleting line "lo".
Karsten Hopp 521789
+ 	 */
Karsten Hopp 521789
+ 	if (!PyErr_Occurred())
Karsten Hopp 521789
+ 	{
Karsten Hopp 521789
+ 	    for (i = 0; i < old_len - new_len; ++i)
Karsten Hopp 521789
+ 		if (ml_delete((linenr_T)lo, FALSE) == FAIL)
Karsten Hopp 521789
+ 		{
Karsten Hopp 521789
+ 		    PyErr_SetVim(_("cannot delete line"));
Karsten Hopp 521789
+ 		    break;
Karsten Hopp 521789
+ 		}
Karsten Hopp 521789
+ 	    extra -= i;
Karsten Hopp 521789
+ 	}
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	/* For as long as possible, replace the existing old_len with the
Karsten Hopp 521789
+ 	 * new old_len. This is a more efficient operation, as it requires
Karsten Hopp 521789
+ 	 * less memory allocation and freeing.
Karsten Hopp 521789
+ 	 */
Karsten Hopp 521789
+ 	if (!PyErr_Occurred())
Karsten Hopp 521789
+ 	{
Karsten Hopp 521789
+ 	    for (i = 0; i < old_len && i < new_len; ++i)
Karsten Hopp 521789
+ 		if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE)
Karsten Hopp 521789
+ 								      == FAIL)
Karsten Hopp 521789
+ 		{
Karsten Hopp 521789
+ 		    PyErr_SetVim(_("cannot replace line"));
Karsten Hopp 521789
+ 		    break;
Karsten Hopp 521789
+ 		}
Karsten Hopp 521789
+ 	}
Karsten Hopp 521789
+ 	else
Karsten Hopp 521789
+ 	    i = 0;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	/* Now we may need to insert the remaining new old_len. If we do, we
Karsten Hopp 521789
+ 	 * must free the strings as we finish with them (we can't pass the
Karsten Hopp 521789
+ 	 * responsibility to vim in this case).
Karsten Hopp 521789
+ 	 */
Karsten Hopp 521789
+ 	if (!PyErr_Occurred())
Karsten Hopp 521789
+ 	{
Karsten Hopp 521789
+ 	    while (i < new_len)
Karsten Hopp 521789
+ 	    {
Karsten Hopp 521789
+ 		if (ml_append((linenr_T)(lo + i - 1),
Karsten Hopp 521789
+ 					(char_u *)array[i], 0, FALSE) == FAIL)
Karsten Hopp 521789
+ 		{
Karsten Hopp 521789
+ 		    PyErr_SetVim(_("cannot insert line"));
Karsten Hopp 521789
+ 		    break;
Karsten Hopp 521789
+ 		}
Karsten Hopp 521789
+ 		vim_free(array[i]);
Karsten Hopp 521789
+ 		++i;
Karsten Hopp 521789
+ 		++extra;
Karsten Hopp 521789
+ 	    }
Karsten Hopp 521789
+ 	}
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	/* Free any left-over old_len, as a result of an error */
Karsten Hopp 521789
+ 	while (i < new_len)
Karsten Hopp 521789
+ 	{
Karsten Hopp 521789
+ 	    vim_free(array[i]);
Karsten Hopp 521789
+ 	    ++i;
Karsten Hopp 521789
+ 	}
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	/* Free the array of old_len. All of its contents have now
Karsten Hopp 521789
+ 	 * been dealt with (either freed, or the responsibility passed
Karsten Hopp 521789
+ 	 * to vim.
Karsten Hopp 521789
+ 	 */
Karsten Hopp 521789
+ 	vim_free(array);
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	/* Adjust marks. Invalidate any which lie in the
Karsten Hopp 521789
+ 	 * changed range, and move any in the remainder of the buffer.
Karsten Hopp 521789
+ 	 */
Karsten Hopp 521789
+ 	mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
Karsten Hopp 521789
+ 						  (long)MAXLNUM, (long)extra);
Karsten Hopp 521789
+ 	changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	if (buf == curwin->w_buffer)
Karsten Hopp 521789
+ 	    py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra);
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	curbuf = savebuf;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	if (PyErr_Occurred() || VimErrorCheck())
Karsten Hopp 521789
+ 	    return FAIL;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	if (len_change)
Karsten Hopp 521789
+ 	    *len_change = new_len - old_len;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	return OK;
Karsten Hopp 521789
+     }
Karsten Hopp 521789
+     else
Karsten Hopp 521789
+     {
Karsten Hopp 521789
+ 	PyErr_BadArgument();
Karsten Hopp 521789
+ 	return FAIL;
Karsten Hopp 521789
+     }
Karsten Hopp 521789
+ }
Karsten Hopp 521789
  
Karsten Hopp 521789
  /* Insert a number of lines into the specified buffer after the specifed line.
Karsten Hopp 521789
   * The line number is in Vim format (1-based). The lines to be inserted are
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 1108,1113 ****
Karsten Hopp 521789
--- 1301,1340 ----
Karsten Hopp 521789
  	return -1;
Karsten Hopp 521789
  
Karsten Hopp 521789
      if (new_end)
Karsten Hopp 521789
+ 	*new_end = end + len_change;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+     return 0;
Karsten Hopp 521789
+ }
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+     static PyInt
Karsten Hopp 521789
+ RBAsSlice(BufferObject *self, PyInt lo, PyInt hi, PyObject *val, PyInt start, PyInt end, PyInt *new_end)
Karsten Hopp 521789
+ {
Karsten Hopp 521789
+     PyInt size;
Karsten Hopp 521789
+     PyInt len_change;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+     /* Self must be a valid buffer */
Karsten Hopp 521789
+     if (CheckBuffer(self))
Karsten Hopp 521789
+ 	return -1;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+     /* Sort out the slice range */
Karsten Hopp 521789
+     size = end - start + 1;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+     if (lo < 0)
Karsten Hopp 521789
+ 	lo = 0;
Karsten Hopp 521789
+     else if (lo > size)
Karsten Hopp 521789
+ 	lo = size;
Karsten Hopp 521789
+     if (hi < 0)
Karsten Hopp 521789
+ 	hi = 0;
Karsten Hopp 521789
+     if (hi < lo)
Karsten Hopp 521789
+ 	hi = lo;
Karsten Hopp 521789
+     else if (hi > size)
Karsten Hopp 521789
+ 	hi = size;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+     if (SetBufferLineList(self->buf, lo + start, hi + start,
Karsten Hopp 521789
+ 						    val, &len_change) == FAIL)
Karsten Hopp 521789
+ 	return -1;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+     if (new_end)
Karsten Hopp 521789
  	*new_end = end + len_change;
Karsten Hopp 521789
  
Karsten Hopp 521789
      return 0;
Karsten Hopp 521789
*** ../mercurial/vim73/src/if_python.c	2011-03-26 18:32:00.000000000 +0100
Karsten Hopp 521789
--- src/if_python.c	2011-06-19 00:02:15.000000000 +0200
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 56,61 ****
Karsten Hopp 521789
--- 56,65 ----
Karsten Hopp 521789
  
Karsten Hopp 521789
  static void init_structs(void);
Karsten Hopp 521789
  
Karsten Hopp 521789
+ /* No-op conversion functions, use with care! */
Karsten Hopp 521789
+ #define PyString_AsBytes(obj) (obj)
Karsten Hopp 521789
+ #define PyString_FreeBytes(obj)
Karsten Hopp 521789
+ 
Karsten Hopp 521789
  #if !defined(FEAT_PYTHON) && defined(PROTO)
Karsten Hopp 521789
  /* Use this to be able to generate prototypes without python being used. */
Karsten Hopp 521789
  # define PyObject Py_ssize_t
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 129,134 ****
Karsten Hopp 521789
--- 133,139 ----
Karsten Hopp 521789
   */
Karsten Hopp 521789
  # define PyArg_Parse dll_PyArg_Parse
Karsten Hopp 521789
  # define PyArg_ParseTuple dll_PyArg_ParseTuple
Karsten Hopp 521789
+ # define PyMem_Free dll_PyMem_Free
Karsten Hopp 521789
  # define PyDict_SetItemString dll_PyDict_SetItemString
Karsten Hopp 521789
  # define PyErr_BadArgument dll_PyErr_BadArgument
Karsten Hopp 521789
  # define PyErr_Clear dll_PyErr_Clear
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 189,194 ****
Karsten Hopp 521789
--- 194,200 ----
Karsten Hopp 521789
   */
Karsten Hopp 521789
  static int(*dll_PyArg_Parse)(PyObject *, char *, ...);
Karsten Hopp 521789
  static int(*dll_PyArg_ParseTuple)(PyObject *, char *, ...);
Karsten Hopp 521789
+ static int(*dll_PyMem_Free)(void *);
Karsten Hopp 521789
  static int(*dll_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
Karsten Hopp 521789
  static int(*dll_PyErr_BadArgument)(void);
Karsten Hopp 521789
  static void(*dll_PyErr_Clear)(void);
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 271,276 ****
Karsten Hopp 521789
--- 277,283 ----
Karsten Hopp 521789
  {
Karsten Hopp 521789
      {"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse},
Karsten Hopp 521789
      {"PyArg_ParseTuple", (PYTHON_PROC*)&dll_PyArg_ParseTuple},
Karsten Hopp 521789
+     {"PyMem_Free", (PYTHON_PROC*)&dll_PyMem_Free},
Karsten Hopp 521789
      {"PyDict_SetItemString", (PYTHON_PROC*)&dll_PyDict_SetItemString},
Karsten Hopp 521789
      {"PyErr_BadArgument", (PYTHON_PROC*)&dll_PyErr_BadArgument},
Karsten Hopp 521789
      {"PyErr_Clear", (PYTHON_PROC*)&dll_PyErr_Clear},
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 833,876 ****
Karsten Hopp 521789
  static PyObject *CurrentGetattr(PyObject *, char *);
Karsten Hopp 521789
  static int CurrentSetattr(PyObject *, char *, PyObject *);
Karsten Hopp 521789
  
Karsten Hopp 521789
- /* Common routines for buffers and line ranges
Karsten Hopp 521789
-  * -------------------------------------------
Karsten Hopp 521789
-  */
Karsten Hopp 521789
- 
Karsten Hopp 521789
-     static PyInt
Karsten Hopp 521789
- RBAssSlice(BufferObject *self, PyInt lo, PyInt hi, PyObject *val, PyInt start, PyInt end, PyInt *new_end)
Karsten Hopp 521789
- {
Karsten Hopp 521789
-     PyInt size;
Karsten Hopp 521789
-     PyInt len_change;
Karsten Hopp 521789
- 
Karsten Hopp 521789
-     /* Self must be a valid buffer */
Karsten Hopp 521789
-     if (CheckBuffer(self))
Karsten Hopp 521789
- 	return -1;
Karsten Hopp 521789
- 
Karsten Hopp 521789
-     /* Sort out the slice range */
Karsten Hopp 521789
-     size = end - start + 1;
Karsten Hopp 521789
- 
Karsten Hopp 521789
-     if (lo < 0)
Karsten Hopp 521789
- 	lo = 0;
Karsten Hopp 521789
-     else if (lo > size)
Karsten Hopp 521789
- 	lo = size;
Karsten Hopp 521789
-     if (hi < 0)
Karsten Hopp 521789
- 	hi = 0;
Karsten Hopp 521789
-     if (hi < lo)
Karsten Hopp 521789
- 	hi = lo;
Karsten Hopp 521789
-     else if (hi > size)
Karsten Hopp 521789
- 	hi = size;
Karsten Hopp 521789
- 
Karsten Hopp 521789
-     if (SetBufferLineList(self->buf, lo + start, hi + start,
Karsten Hopp 521789
- 						    val, &len_change) == FAIL)
Karsten Hopp 521789
- 	return -1;
Karsten Hopp 521789
- 
Karsten Hopp 521789
-     if (new_end)
Karsten Hopp 521789
- 	*new_end = end + len_change;
Karsten Hopp 521789
- 
Karsten Hopp 521789
-     return 0;
Karsten Hopp 521789
- }
Karsten Hopp 521789
- 
Karsten Hopp 521789
  static PySequenceMethods BufferAsSeq = {
Karsten Hopp 521789
      (PyInquiry)		BufferLength,	    /* sq_length,    len(x)   */
Karsten Hopp 521789
      (binaryfunc)	0, /* BufferConcat, */	     /* sq_concat,    x+y      */
Karsten Hopp 521789
--- 840,845 ----
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 1038,1044 ****
Karsten Hopp 521789
      static PyInt
Karsten Hopp 521789
  BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
Karsten Hopp 521789
  {
Karsten Hopp 521789
!     return RBAssSlice((BufferObject *)(self), lo, hi, val, 1,
Karsten Hopp 521789
  		      (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
Karsten Hopp 521789
  		      NULL);
Karsten Hopp 521789
  }
Karsten Hopp 521789
--- 1007,1013 ----
Karsten Hopp 521789
      static PyInt
Karsten Hopp 521789
  BufferAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
Karsten Hopp 521789
  {
Karsten Hopp 521789
!     return RBAsSlice((BufferObject *)(self), lo, hi, val, 1,
Karsten Hopp 521789
  		      (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
Karsten Hopp 521789
  		      NULL);
Karsten Hopp 521789
  }
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 1088,1094 ****
Karsten Hopp 521789
      static PyInt
Karsten Hopp 521789
  RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
Karsten Hopp 521789
  {
Karsten Hopp 521789
!     return RBAssSlice(((RangeObject *)(self))->buf, lo, hi, val,
Karsten Hopp 521789
  		      ((RangeObject *)(self))->start,
Karsten Hopp 521789
  		      ((RangeObject *)(self))->end,
Karsten Hopp 521789
  		      &((RangeObject *)(self))->end);
Karsten Hopp 521789
--- 1057,1063 ----
Karsten Hopp 521789
      static PyInt
Karsten Hopp 521789
  RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
Karsten Hopp 521789
  {
Karsten Hopp 521789
!     return RBAsSlice(((RangeObject *)(self))->buf, lo, hi, val,
Karsten Hopp 521789
  		      ((RangeObject *)(self))->start,
Karsten Hopp 521789
  		      ((RangeObject *)(self))->end,
Karsten Hopp 521789
  		      &((RangeObject *)(self))->end);
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 1435,1628 ****
Karsten Hopp 521789
   * 4. Utility functions for handling the interface between Vim and Python.
Karsten Hopp 521789
   */
Karsten Hopp 521789
  
Karsten Hopp 521789
- /* Replace a range of lines in the specified buffer. The line numbers are in
Karsten Hopp 521789
-  * Vim format (1-based). The range is from lo up to, but not including, hi.
Karsten Hopp 521789
-  * The replacement lines are given as a Python list of string objects. The
Karsten Hopp 521789
-  * list is checked for validity and correct format. Errors are returned as a
Karsten Hopp 521789
-  * value of FAIL.  The return value is OK on success.
Karsten Hopp 521789
-  * If OK is returned and len_change is not NULL, *len_change
Karsten Hopp 521789
-  * is set to the change in the buffer length.
Karsten Hopp 521789
-  */
Karsten Hopp 521789
-     static int
Karsten Hopp 521789
- SetBufferLineList(buf_T *buf, PyInt lo, PyInt hi, PyObject *list, PyInt *len_change)
Karsten Hopp 521789
- {
Karsten Hopp 521789
-     /* First of all, we check the thpe of the supplied Python object.
Karsten Hopp 521789
-      * There are three cases:
Karsten Hopp 521789
-      *	  1. NULL, or None - this is a deletion.
Karsten Hopp 521789
-      *	  2. A list	   - this is a replacement.
Karsten Hopp 521789
-      *	  3. Anything else - this is an error.
Karsten Hopp 521789
-      */
Karsten Hopp 521789
-     if (list == Py_None || list == NULL)
Karsten Hopp 521789
-     {
Karsten Hopp 521789
- 	PyInt	i;
Karsten Hopp 521789
- 	PyInt	n = (int)(hi - lo);
Karsten Hopp 521789
- 	buf_T	*savebuf = curbuf;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	PyErr_Clear();
Karsten Hopp 521789
- 	curbuf = buf;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	if (u_savedel((linenr_T)lo, (long)n) == FAIL)
Karsten Hopp 521789
- 	    PyErr_SetVim(_("cannot save undo information"));
Karsten Hopp 521789
- 	else
Karsten Hopp 521789
- 	{
Karsten Hopp 521789
- 	    for (i = 0; i < n; ++i)
Karsten Hopp 521789
- 	    {
Karsten Hopp 521789
- 		if (ml_delete((linenr_T)lo, FALSE) == FAIL)
Karsten Hopp 521789
- 		{
Karsten Hopp 521789
- 		    PyErr_SetVim(_("cannot delete line"));
Karsten Hopp 521789
- 		    break;
Karsten Hopp 521789
- 		}
Karsten Hopp 521789
- 	    }
Karsten Hopp 521789
- 	    if (buf == curwin->w_buffer)
Karsten Hopp 521789
- 		py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
Karsten Hopp 521789
- 	    deleted_lines_mark((linenr_T)lo, (long)i);
Karsten Hopp 521789
- 	}
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	curbuf = savebuf;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	if (PyErr_Occurred() || VimErrorCheck())
Karsten Hopp 521789
- 	    return FAIL;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	if (len_change)
Karsten Hopp 521789
- 	    *len_change = -n;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	return OK;
Karsten Hopp 521789
-     }
Karsten Hopp 521789
-     else if (PyList_Check(list))
Karsten Hopp 521789
-     {
Karsten Hopp 521789
- 	PyInt	i;
Karsten Hopp 521789
- 	PyInt	new_len = PyList_Size(list);
Karsten Hopp 521789
- 	PyInt	old_len = hi - lo;
Karsten Hopp 521789
- 	PyInt	extra = 0;	/* lines added to text, can be negative */
Karsten Hopp 521789
- 	char	**array;
Karsten Hopp 521789
- 	buf_T	*savebuf;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	if (new_len == 0)	/* avoid allocating zero bytes */
Karsten Hopp 521789
- 	    array = NULL;
Karsten Hopp 521789
- 	else
Karsten Hopp 521789
- 	{
Karsten Hopp 521789
- 	    array = (char **)alloc((unsigned)(new_len * sizeof(char *)));
Karsten Hopp 521789
- 	    if (array == NULL)
Karsten Hopp 521789
- 	    {
Karsten Hopp 521789
- 		PyErr_NoMemory();
Karsten Hopp 521789
- 		return FAIL;
Karsten Hopp 521789
- 	    }
Karsten Hopp 521789
- 	}
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	for (i = 0; i < new_len; ++i)
Karsten Hopp 521789
- 	{
Karsten Hopp 521789
- 	    PyObject *line = PyList_GetItem(list, i);
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	    array[i] = StringToLine(line);
Karsten Hopp 521789
- 	    if (array[i] == NULL)
Karsten Hopp 521789
- 	    {
Karsten Hopp 521789
- 		while (i)
Karsten Hopp 521789
- 		    vim_free(array[--i]);
Karsten Hopp 521789
- 		vim_free(array);
Karsten Hopp 521789
- 		return FAIL;
Karsten Hopp 521789
- 	    }
Karsten Hopp 521789
- 	}
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	savebuf = curbuf;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	PyErr_Clear();
Karsten Hopp 521789
- 	curbuf = buf;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
Karsten Hopp 521789
- 	    PyErr_SetVim(_("cannot save undo information"));
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	/* If the size of the range is reducing (ie, new_len < old_len) we
Karsten Hopp 521789
- 	 * need to delete some old_len. We do this at the start, by
Karsten Hopp 521789
- 	 * repeatedly deleting line "lo".
Karsten Hopp 521789
- 	 */
Karsten Hopp 521789
- 	if (!PyErr_Occurred())
Karsten Hopp 521789
- 	{
Karsten Hopp 521789
- 	    for (i = 0; i < old_len - new_len; ++i)
Karsten Hopp 521789
- 		if (ml_delete((linenr_T)lo, FALSE) == FAIL)
Karsten Hopp 521789
- 		{
Karsten Hopp 521789
- 		    PyErr_SetVim(_("cannot delete line"));
Karsten Hopp 521789
- 		    break;
Karsten Hopp 521789
- 		}
Karsten Hopp 521789
- 	    extra -= i;
Karsten Hopp 521789
- 	}
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	/* For as long as possible, replace the existing old_len with the
Karsten Hopp 521789
- 	 * new old_len. This is a more efficient operation, as it requires
Karsten Hopp 521789
- 	 * less memory allocation and freeing.
Karsten Hopp 521789
- 	 */
Karsten Hopp 521789
- 	if (!PyErr_Occurred())
Karsten Hopp 521789
- 	{
Karsten Hopp 521789
- 	    for (i = 0; i < old_len && i < new_len; ++i)
Karsten Hopp 521789
- 		if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE)
Karsten Hopp 521789
- 								      == FAIL)
Karsten Hopp 521789
- 		{
Karsten Hopp 521789
- 		    PyErr_SetVim(_("cannot replace line"));
Karsten Hopp 521789
- 		    break;
Karsten Hopp 521789
- 		}
Karsten Hopp 521789
- 	}
Karsten Hopp 521789
- 	else
Karsten Hopp 521789
- 	    i = 0;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	/* Now we may need to insert the remaining new old_len. If we do, we
Karsten Hopp 521789
- 	 * must free the strings as we finish with them (we can't pass the
Karsten Hopp 521789
- 	 * responsibility to vim in this case).
Karsten Hopp 521789
- 	 */
Karsten Hopp 521789
- 	if (!PyErr_Occurred())
Karsten Hopp 521789
- 	{
Karsten Hopp 521789
- 	    while (i < new_len)
Karsten Hopp 521789
- 	    {
Karsten Hopp 521789
- 		if (ml_append((linenr_T)(lo + i - 1),
Karsten Hopp 521789
- 					(char_u *)array[i], 0, FALSE) == FAIL)
Karsten Hopp 521789
- 		{
Karsten Hopp 521789
- 		    PyErr_SetVim(_("cannot insert line"));
Karsten Hopp 521789
- 		    break;
Karsten Hopp 521789
- 		}
Karsten Hopp 521789
- 		vim_free(array[i]);
Karsten Hopp 521789
- 		++i;
Karsten Hopp 521789
- 		++extra;
Karsten Hopp 521789
- 	    }
Karsten Hopp 521789
- 	}
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	/* Free any left-over old_len, as a result of an error */
Karsten Hopp 521789
- 	while (i < new_len)
Karsten Hopp 521789
- 	{
Karsten Hopp 521789
- 	    vim_free(array[i]);
Karsten Hopp 521789
- 	    ++i;
Karsten Hopp 521789
- 	}
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	/* Free the array of old_len. All of its contents have now
Karsten Hopp 521789
- 	 * been dealt with (either freed, or the responsibility passed
Karsten Hopp 521789
- 	 * to vim.
Karsten Hopp 521789
- 	 */
Karsten Hopp 521789
- 	vim_free(array);
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	/* Adjust marks. Invalidate any which lie in the
Karsten Hopp 521789
- 	 * changed range, and move any in the remainder of the buffer.
Karsten Hopp 521789
- 	 */
Karsten Hopp 521789
- 	mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
Karsten Hopp 521789
- 						  (long)MAXLNUM, (long)extra);
Karsten Hopp 521789
- 	changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	if (buf == curwin->w_buffer)
Karsten Hopp 521789
- 	    py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra);
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	curbuf = savebuf;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	if (PyErr_Occurred() || VimErrorCheck())
Karsten Hopp 521789
- 	    return FAIL;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	if (len_change)
Karsten Hopp 521789
- 	    *len_change = new_len - old_len;
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 	return OK;
Karsten Hopp 521789
-     }
Karsten Hopp 521789
-     else
Karsten Hopp 521789
-     {
Karsten Hopp 521789
- 	PyErr_BadArgument();
Karsten Hopp 521789
- 	return FAIL;
Karsten Hopp 521789
-     }
Karsten Hopp 521789
- }
Karsten Hopp 521789
- 
Karsten Hopp 521789
  /* Convert a Vim line into a Python string.
Karsten Hopp 521789
   * All internal newlines are replaced by null characters.
Karsten Hopp 521789
   *
Karsten Hopp 521789
--- 1404,1409 ----
Karsten Hopp 521789
*** ../mercurial/vim73/src/if_python3.c	2011-06-12 21:37:06.000000000 +0200
Karsten Hopp 521789
--- src/if_python3.c	2011-06-19 00:10:42.000000000 +0200
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 70,77 ****
Karsten Hopp 521789
  
Karsten Hopp 521789
  #define PyInt Py_ssize_t
Karsten Hopp 521789
  #define PyString_Check(obj) PyUnicode_Check(obj)
Karsten Hopp 521789
! #define PyString_AsString(obj) _PyUnicode_AsString(obj)
Karsten Hopp 521789
! #define PyString_Size(obj) PyUnicode_GET_SIZE(obj)
Karsten Hopp 521789
  #define PyString_FromString(repr) PyUnicode_FromString(repr)
Karsten Hopp 521789
  
Karsten Hopp 521789
  #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
Karsten Hopp 521789
--- 70,79 ----
Karsten Hopp 521789
  
Karsten Hopp 521789
  #define PyInt Py_ssize_t
Karsten Hopp 521789
  #define PyString_Check(obj) PyUnicode_Check(obj)
Karsten Hopp 521789
! #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)p_enc, NULL);
Karsten Hopp 521789
! #define PyString_FreeBytes(obj) Py_XDECREF(bytes)
Karsten Hopp 521789
! #define PyString_AsString(obj) PyBytes_AsString(obj)
Karsten Hopp 521789
! #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
Karsten Hopp 521789
  #define PyString_FromString(repr) PyUnicode_FromString(repr)
Karsten Hopp 521789
  
Karsten Hopp 521789
  #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 99,104 ****
Karsten Hopp 521789
--- 101,107 ----
Karsten Hopp 521789
  # define PyArg_Parse py3_PyArg_Parse
Karsten Hopp 521789
  # undef PyArg_ParseTuple
Karsten Hopp 521789
  # define PyArg_ParseTuple py3_PyArg_ParseTuple
Karsten Hopp 521789
+ # define PyMem_Free py3_PyMem_Free
Karsten Hopp 521789
  # define PyDict_SetItemString py3_PyDict_SetItemString
Karsten Hopp 521789
  # define PyErr_BadArgument py3_PyErr_BadArgument
Karsten Hopp 521789
  # define PyErr_Clear py3_PyErr_Clear
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 140,147 ****
Karsten Hopp 521789
--- 143,155 ----
Karsten Hopp 521789
  # define PyModule_AddObject py3_PyModule_AddObject
Karsten Hopp 521789
  # define PyImport_AppendInittab py3_PyImport_AppendInittab
Karsten Hopp 521789
  # define _PyUnicode_AsString py3__PyUnicode_AsString
Karsten Hopp 521789
+ # undef PyUnicode_AsEncodedString
Karsten Hopp 521789
+ # define PyUnicode_AsEncodedString py3_PyUnicode_AsEncodedString
Karsten Hopp 521789
+ # undef PyBytes_AsString
Karsten Hopp 521789
+ # define PyBytes_AsString py3_PyBytes_AsString
Karsten Hopp 521789
  # define PyObject_GenericGetAttr py3_PyObject_GenericGetAttr
Karsten Hopp 521789
  # define PySlice_Type (*py3_PySlice_Type)
Karsten Hopp 521789
+ # define PyErr_NewException py3_PyErr_NewException
Karsten Hopp 521789
  # ifdef Py_DEBUG
Karsten Hopp 521789
  #  define _Py_NegativeRefcount py3__Py_NegativeRefcount
Karsten Hopp 521789
  #  define _Py_RefTotal (*py3__Py_RefTotal)
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 157,164 ****
Karsten Hopp 521789
  # define PyModule_Create2 py3_PyModule_Create2
Karsten Hopp 521789
  # undef PyUnicode_FromString
Karsten Hopp 521789
  # define PyUnicode_FromString py3_PyUnicode_FromString
Karsten Hopp 521789
! # undef PyUnicode_FromStringAndSize
Karsten Hopp 521789
! # define PyUnicode_FromStringAndSize py3_PyUnicode_FromStringAndSize
Karsten Hopp 521789
  
Karsten Hopp 521789
  # ifdef Py_DEBUG
Karsten Hopp 521789
  #  undef PyObject_NEW
Karsten Hopp 521789
--- 165,172 ----
Karsten Hopp 521789
  # define PyModule_Create2 py3_PyModule_Create2
Karsten Hopp 521789
  # undef PyUnicode_FromString
Karsten Hopp 521789
  # define PyUnicode_FromString py3_PyUnicode_FromString
Karsten Hopp 521789
! # undef PyUnicode_Decode
Karsten Hopp 521789
! # define PyUnicode_Decode py3_PyUnicode_Decode
Karsten Hopp 521789
  
Karsten Hopp 521789
  # ifdef Py_DEBUG
Karsten Hopp 521789
  #  undef PyObject_NEW
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 199,205 ****
Karsten Hopp 521789
  static int (*py3_PyType_Ready)(PyTypeObject *type);
Karsten Hopp 521789
  static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
Karsten Hopp 521789
  static PyObject* (*py3_PyUnicode_FromString)(const char *u);
Karsten Hopp 521789
! static PyObject* (*py3_PyUnicode_FromStringAndSize)(const char *u, Py_ssize_t size);
Karsten Hopp 521789
  static long (*py3_PyLong_AsLong)(PyObject *);
Karsten Hopp 521789
  static void (*py3_PyErr_SetNone)(PyObject *);
Karsten Hopp 521789
  static void (*py3_PyEval_InitThreads)(void);
Karsten Hopp 521789
--- 207,214 ----
Karsten Hopp 521789
  static int (*py3_PyType_Ready)(PyTypeObject *type);
Karsten Hopp 521789
  static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
Karsten Hopp 521789
  static PyObject* (*py3_PyUnicode_FromString)(const char *u);
Karsten Hopp 521789
! static PyObject* (*py3_PyUnicode_Decode)(const char *u, Py_ssize_t size,
Karsten Hopp 521789
! 	const char *encoding, const char *errors);
Karsten Hopp 521789
  static long (*py3_PyLong_AsLong)(PyObject *);
Karsten Hopp 521789
  static void (*py3_PyErr_SetNone)(PyObject *);
Karsten Hopp 521789
  static void (*py3_PyEval_InitThreads)(void);
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 207,212 ****
Karsten Hopp 521789
--- 216,222 ----
Karsten Hopp 521789
  static PyThreadState*(*py3_PyEval_SaveThread)(void);
Karsten Hopp 521789
  static int (*py3_PyArg_Parse)(PyObject *, char *, ...);
Karsten Hopp 521789
  static int (*py3_PyArg_ParseTuple)(PyObject *, char *, ...);
Karsten Hopp 521789
+ static int (*py3_PyMem_Free)(void *);
Karsten Hopp 521789
  static int (*py3_Py_IsInitialized)(void);
Karsten Hopp 521789
  static void (*py3_PyErr_Clear)(void);
Karsten Hopp 521789
  static PyObject*(*py3__PyObject_Init)(PyObject *, PyTypeObject *);
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 214,224 ****
Karsten Hopp 521789
--- 224,237 ----
Karsten Hopp 521789
  static int (*py3_PyModule_AddObject)(PyObject *m, const char *name, PyObject *o);
Karsten Hopp 521789
  static int (*py3_PyImport_AppendInittab)(const char *name, PyObject* (*initfunc)(void));
Karsten Hopp 521789
  static char* (*py3__PyUnicode_AsString)(PyObject *unicode);
Karsten Hopp 521789
+ static PyObject* (*py3_PyUnicode_AsEncodedString)(PyObject *unicode, const char* encoding, const char* errors);
Karsten Hopp 521789
+ static char* (*py3_PyBytes_AsString)(PyObject *bytes);
Karsten Hopp 521789
  static PyObject* (*py3_PyObject_GenericGetAttr)(PyObject *obj, PyObject *name);
Karsten Hopp 521789
  static PyObject* (*py3_PyModule_Create2)(struct PyModuleDef* module, int module_api_version);
Karsten Hopp 521789
  static PyObject* (*py3_PyType_GenericAlloc)(PyTypeObject *type, Py_ssize_t nitems);
Karsten Hopp 521789
  static PyObject* (*py3_PyType_GenericNew)(PyTypeObject *type, PyObject *args, PyObject *kwds);
Karsten Hopp 521789
  static PyTypeObject* py3_PySlice_Type;
Karsten Hopp 521789
+ static PyObject* (*py3_PyErr_NewException)(char *name, PyObject *base, PyObject *dict);
Karsten Hopp 521789
  # ifdef Py_DEBUG
Karsten Hopp 521789
      static void (*py3__Py_NegativeRefcount)(const char *fname, int lineno, PyObject *op);
Karsten Hopp 521789
      static Py_ssize_t* py3__Py_RefTotal;
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 259,264 ****
Karsten Hopp 521789
--- 272,278 ----
Karsten Hopp 521789
      {"Py_SetPythonHome", (PYTHON_PROC*)&py3_Py_SetPythonHome},
Karsten Hopp 521789
      {"Py_Initialize", (PYTHON_PROC*)&py3_Py_Initialize},
Karsten Hopp 521789
      {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple},
Karsten Hopp 521789
+     {"PyMem_Free", (PYTHON_PROC*)&py3_PyMem_Free},
Karsten Hopp 521789
      {"PyList_New", (PYTHON_PROC*)&py3_PyList_New},
Karsten Hopp 521789
      {"PyGILState_Ensure", (PYTHON_PROC*)&py3_PyGILState_Ensure},
Karsten Hopp 521789
      {"PyGILState_Release", (PYTHON_PROC*)&py3_PyGILState_Release},
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 289,295 ****
Karsten Hopp 521789
      {"PyEval_RestoreThread", (PYTHON_PROC*)&py3_PyEval_RestoreThread},
Karsten Hopp 521789
      {"PyEval_SaveThread", (PYTHON_PROC*)&py3_PyEval_SaveThread},
Karsten Hopp 521789
      {"PyArg_Parse", (PYTHON_PROC*)&py3_PyArg_Parse},
Karsten Hopp 521789
-     {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple},
Karsten Hopp 521789
      {"Py_IsInitialized", (PYTHON_PROC*)&py3_Py_IsInitialized},
Karsten Hopp 521789
      {"_Py_NoneStruct", (PYTHON_PROC*)&py3__Py_NoneStruct},
Karsten Hopp 521789
      {"PyErr_Clear", (PYTHON_PROC*)&py3_PyErr_Clear},
Karsten Hopp 521789
--- 303,308 ----
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 297,307 ****
Karsten Hopp 521789
--- 310,322 ----
Karsten Hopp 521789
      {"PyModule_AddObject", (PYTHON_PROC*)&py3_PyModule_AddObject},
Karsten Hopp 521789
      {"PyImport_AppendInittab", (PYTHON_PROC*)&py3_PyImport_AppendInittab},
Karsten Hopp 521789
      {"_PyUnicode_AsString", (PYTHON_PROC*)&py3__PyUnicode_AsString},
Karsten Hopp 521789
+     {"PyBytes_AsString", (PYTHON_PROC*)&py3_PyBytes_AsString},
Karsten Hopp 521789
      {"PyObject_GenericGetAttr", (PYTHON_PROC*)&py3_PyObject_GenericGetAttr},
Karsten Hopp 521789
      {"PyModule_Create2", (PYTHON_PROC*)&py3_PyModule_Create2},
Karsten Hopp 521789
      {"PyType_GenericAlloc", (PYTHON_PROC*)&py3_PyType_GenericAlloc},
Karsten Hopp 521789
      {"PyType_GenericNew", (PYTHON_PROC*)&py3_PyType_GenericNew},
Karsten Hopp 521789
      {"PySlice_Type", (PYTHON_PROC*)&py3_PySlice_Type},
Karsten Hopp 521789
+     {"PyErr_NewException", (PYTHON_PROC*)&py3_PyErr_NewException},
Karsten Hopp 521789
  # ifdef Py_DEBUG
Karsten Hopp 521789
      {"_Py_NegativeRefcount", (PYTHON_PROC*)&py3__Py_NegativeRefcount},
Karsten Hopp 521789
      {"_Py_RefTotal", (PYTHON_PROC*)&py3__Py_RefTotal},
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 337,343 ****
Karsten Hopp 521789
  py3_runtime_link_init(char *libname, int verbose)
Karsten Hopp 521789
  {
Karsten Hopp 521789
      int i;
Karsten Hopp 521789
!     void *ucs_from_string, *ucs_from_string_and_size;
Karsten Hopp 521789
  
Karsten Hopp 521789
  # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON)
Karsten Hopp 521789
      /* Can't have Python and Python3 loaded at the same time.
Karsten Hopp 521789
--- 352,358 ----
Karsten Hopp 521789
  py3_runtime_link_init(char *libname, int verbose)
Karsten Hopp 521789
  {
Karsten Hopp 521789
      int i;
Karsten Hopp 521789
!     void *ucs_from_string, *ucs_decode, *ucs_as_encoded_string;
Karsten Hopp 521789
  
Karsten Hopp 521789
  # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON)
Karsten Hopp 521789
      /* Can't have Python and Python3 loaded at the same time.
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 377,395 ****
Karsten Hopp 521789
      /* Load unicode functions separately as only the ucs2 or the ucs4 functions
Karsten Hopp 521789
       * will be present in the library. */
Karsten Hopp 521789
      ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString");
Karsten Hopp 521789
!     ucs_from_string_and_size = symbol_from_dll(hinstPy3,
Karsten Hopp 521789
! 	    "PyUnicodeUCS2_FromStringAndSize");
Karsten Hopp 521789
!     if (!ucs_from_string || !ucs_from_string_and_size)
Karsten Hopp 521789
      {
Karsten Hopp 521789
  	ucs_from_string = symbol_from_dll(hinstPy3,
Karsten Hopp 521789
  		"PyUnicodeUCS4_FromString");
Karsten Hopp 521789
! 	ucs_from_string_and_size = symbol_from_dll(hinstPy3,
Karsten Hopp 521789
! 		"PyUnicodeUCS4_FromStringAndSize");
Karsten Hopp 521789
      }
Karsten Hopp 521789
!     if (ucs_from_string && ucs_from_string_and_size)
Karsten Hopp 521789
      {
Karsten Hopp 521789
  	py3_PyUnicode_FromString = ucs_from_string;
Karsten Hopp 521789
! 	py3_PyUnicode_FromStringAndSize = ucs_from_string_and_size;
Karsten Hopp 521789
      }
Karsten Hopp 521789
      else
Karsten Hopp 521789
      {
Karsten Hopp 521789
--- 392,415 ----
Karsten Hopp 521789
      /* Load unicode functions separately as only the ucs2 or the ucs4 functions
Karsten Hopp 521789
       * will be present in the library. */
Karsten Hopp 521789
      ucs_from_string = symbol_from_dll(hinstPy3, "PyUnicodeUCS2_FromString");
Karsten Hopp 521789
!     ucs_decode = symbol_from_dll(hinstPy3,
Karsten Hopp 521789
! 	    "PyUnicodeUCS2_Decode");
Karsten Hopp 521789
!     ucs_as_encoded_string = symbol_from_dll(hinstPy3,
Karsten Hopp 521789
! 	    "PyUnicodeUCS2_AsEncodedString");
Karsten Hopp 521789
!     if (!ucs_from_string || !ucs_decode || !ucs_as_encoded_string)
Karsten Hopp 521789
      {
Karsten Hopp 521789
  	ucs_from_string = symbol_from_dll(hinstPy3,
Karsten Hopp 521789
  		"PyUnicodeUCS4_FromString");
Karsten Hopp 521789
! 	ucs_decode = symbol_from_dll(hinstPy3,
Karsten Hopp 521789
! 		"PyUnicodeUCS4_Decode");
Karsten Hopp 521789
! 	ucs_as_encoded_string = symbol_from_dll(hinstPy3,
Karsten Hopp 521789
! 		"PyUnicodeUCS4_AsEncodedString");
Karsten Hopp 521789
      }
Karsten Hopp 521789
!     if (ucs_from_string && ucs_decode && ucs_as_encoded_string)
Karsten Hopp 521789
      {
Karsten Hopp 521789
  	py3_PyUnicode_FromString = ucs_from_string;
Karsten Hopp 521789
! 	py3_PyUnicode_Decode = ucs_decode;
Karsten Hopp 521789
! 	py3_PyUnicode_AsEncodedString = ucs_as_encoded_string;
Karsten Hopp 521789
      }
Karsten Hopp 521789
      else
Karsten Hopp 521789
      {
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 567,574 ****
Karsten Hopp 521789
  	/* Remove the element from sys.path that was added because of our
Karsten Hopp 521789
  	 * argv[0] value in Py3Init_vim().  Previously we used an empty
Karsten Hopp 521789
  	 * string, but dependinding on the OS we then get an empty entry or
Karsten Hopp 521789
! 	 * the current directory in sys.path. */
Karsten Hopp 521789
! 	PyRun_SimpleString("import sys; sys.path = list(filter(lambda x: x != '/must>not&exist', sys.path))");
Karsten Hopp 521789
  
Karsten Hopp 521789
  	// lock is created and acquired in PyEval_InitThreads() and thread
Karsten Hopp 521789
  	// state is created in Py_Initialize()
Karsten Hopp 521789
--- 587,597 ----
Karsten Hopp 521789
  	/* Remove the element from sys.path that was added because of our
Karsten Hopp 521789
  	 * argv[0] value in Py3Init_vim().  Previously we used an empty
Karsten Hopp 521789
  	 * string, but dependinding on the OS we then get an empty entry or
Karsten Hopp 521789
! 	 * the current directory in sys.path.
Karsten Hopp 521789
! 	 * Only after vim has been imported, the element does exist in
Karsten Hopp 521789
! 	 * sys.path.
Karsten Hopp 521789
! 	 */
Karsten Hopp 521789
! 	PyRun_SimpleString("import vim; import sys; sys.path = list(filter(lambda x: not x.endswith('must>not&exist'), sys.path))");
Karsten Hopp 521789
  
Karsten Hopp 521789
  	// lock is created and acquired in PyEval_InitThreads() and thread
Karsten Hopp 521789
  	// state is created in Py_Initialize()
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 605,610 ****
Karsten Hopp 521789
--- 628,635 ----
Karsten Hopp 521789
  #if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
Karsten Hopp 521789
      char		*saved_locale;
Karsten Hopp 521789
  #endif
Karsten Hopp 521789
+     PyObject		*cmdstr;
Karsten Hopp 521789
+     PyObject		*cmdbytes;
Karsten Hopp 521789
  
Karsten Hopp 521789
  #if defined(MACOS) && !defined(MACOS_X_UNIX)
Karsten Hopp 521789
      GetPort(&oldPort);
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 634,640 ****
Karsten Hopp 521789
  
Karsten Hopp 521789
      pygilstate = PyGILState_Ensure();
Karsten Hopp 521789
  
Karsten Hopp 521789
!     PyRun_SimpleString((char *)(cmd));
Karsten Hopp 521789
  
Karsten Hopp 521789
      PyGILState_Release(pygilstate);
Karsten Hopp 521789
  
Karsten Hopp 521789
--- 659,671 ----
Karsten Hopp 521789
  
Karsten Hopp 521789
      pygilstate = PyGILState_Ensure();
Karsten Hopp 521789
  
Karsten Hopp 521789
!     /* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
Karsten Hopp 521789
!      * SyntaxError (unicode error). */
Karsten Hopp 521789
!     cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)p_enc, NULL);
Karsten Hopp 521789
!     cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", NULL);
Karsten Hopp 521789
!     Py_XDECREF(cmdstr);
Karsten Hopp 521789
!     PyRun_SimpleString(PyBytes_AsString(cmdbytes));
Karsten Hopp 521789
!     Py_XDECREF(cmdbytes);
Karsten Hopp 521789
  
Karsten Hopp 521789
      PyGILState_Release(pygilstate);
Karsten Hopp 521789
  
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 693,699 ****
Karsten Hopp 521789
       * different options under Windows, meaning that stdio pointers aren't
Karsten Hopp 521789
       * compatible between the two. Yuk.
Karsten Hopp 521789
       *
Karsten Hopp 521789
!      * construct: exec(compile(open('a_filename').read(), 'a_filename', 'exec'))
Karsten Hopp 521789
       *
Karsten Hopp 521789
       * We need to escape any backslashes or single quotes in the file name, so that
Karsten Hopp 521789
       * Python won't mangle the file name.
Karsten Hopp 521789
--- 724,733 ----
Karsten Hopp 521789
       * different options under Windows, meaning that stdio pointers aren't
Karsten Hopp 521789
       * compatible between the two. Yuk.
Karsten Hopp 521789
       *
Karsten Hopp 521789
!      * construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec'))
Karsten Hopp 521789
!      *
Karsten Hopp 521789
!      * Using bytes so that Python can detect the source encoding as it normally
Karsten Hopp 521789
!      * does. The doc does not say "compile" accept bytes, though.
Karsten Hopp 521789
       *
Karsten Hopp 521789
       * We need to escape any backslashes or single quotes in the file name, so that
Karsten Hopp 521789
       * Python won't mangle the file name.
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 716,723 ****
Karsten Hopp 521789
  	    return;
Karsten Hopp 521789
  	if (i==0)
Karsten Hopp 521789
  	{
Karsten Hopp 521789
! 	    strcpy(p,"').read(),'");
Karsten Hopp 521789
! 	    p += 11;
Karsten Hopp 521789
  	}
Karsten Hopp 521789
  	else
Karsten Hopp 521789
  	{
Karsten Hopp 521789
--- 750,757 ----
Karsten Hopp 521789
  	    return;
Karsten Hopp 521789
  	if (i==0)
Karsten Hopp 521789
  	{
Karsten Hopp 521789
! 	    strcpy(p,"','rb').read(),'");
Karsten Hopp 521789
! 	    p += 16;
Karsten Hopp 521789
  	}
Karsten Hopp 521789
  	else
Karsten Hopp 521789
  	{
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 812,819 ****
Karsten Hopp 521789
  
Karsten Hopp 521789
  static Py_ssize_t BufferLength(PyObject *);
Karsten Hopp 521789
  static PyObject *BufferItem(PyObject *, Py_ssize_t);
Karsten Hopp 521789
- static Py_ssize_t BufferAsItem(PyObject *, Py_ssize_t, PyObject *);
Karsten Hopp 521789
  static PyObject* BufferSubscript(PyObject *self, PyObject* idx);
Karsten Hopp 521789
  
Karsten Hopp 521789
  
Karsten Hopp 521789
  /* Line range type - Implementation functions
Karsten Hopp 521789
--- 846,853 ----
Karsten Hopp 521789
  
Karsten Hopp 521789
  static Py_ssize_t BufferLength(PyObject *);
Karsten Hopp 521789
  static PyObject *BufferItem(PyObject *, Py_ssize_t);
Karsten Hopp 521789
  static PyObject* BufferSubscript(PyObject *self, PyObject* idx);
Karsten Hopp 521789
+ static Py_ssize_t BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val);
Karsten Hopp 521789
  
Karsten Hopp 521789
  
Karsten Hopp 521789
  /* Line range type - Implementation functions
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 835,841 ****
Karsten Hopp 521789
      (ssizeargfunc)	0,		    /* sq_repeat,    x*n      */
Karsten Hopp 521789
      (ssizeargfunc)	BufferItem,	    /* sq_item,      x[i]     */
Karsten Hopp 521789
      0,					    /* was_sq_slice,	 x[i:j]   */
Karsten Hopp 521789
!     (ssizeobjargproc)	BufferAsItem,	    /* sq_ass_item,  x[i]=v   */
Karsten Hopp 521789
      0,					    /* sq_ass_slice, x[i:j]=v */
Karsten Hopp 521789
      0,					    /* sq_contains */
Karsten Hopp 521789
      0,					    /* sq_inplace_concat */
Karsten Hopp 521789
--- 869,875 ----
Karsten Hopp 521789
      (ssizeargfunc)	0,		    /* sq_repeat,    x*n      */
Karsten Hopp 521789
      (ssizeargfunc)	BufferItem,	    /* sq_item,      x[i]     */
Karsten Hopp 521789
      0,					    /* was_sq_slice,	 x[i:j]   */
Karsten Hopp 521789
!     0,					    /* sq_ass_item,  x[i]=v   */
Karsten Hopp 521789
      0,					    /* sq_ass_slice, x[i:j]=v */
Karsten Hopp 521789
      0,					    /* sq_contains */
Karsten Hopp 521789
      0,					    /* sq_inplace_concat */
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 845,851 ****
Karsten Hopp 521789
  PyMappingMethods BufferAsMapping = {
Karsten Hopp 521789
      /* mp_length	*/ (lenfunc)BufferLength,
Karsten Hopp 521789
      /* mp_subscript     */ (binaryfunc)BufferSubscript,
Karsten Hopp 521789
!     /* mp_ass_subscript */ (objobjargproc)0,
Karsten Hopp 521789
  };
Karsten Hopp 521789
  
Karsten Hopp 521789
  
Karsten Hopp 521789
--- 879,885 ----
Karsten Hopp 521789
  PyMappingMethods BufferAsMapping = {
Karsten Hopp 521789
      /* mp_length	*/ (lenfunc)BufferLength,
Karsten Hopp 521789
      /* mp_subscript     */ (binaryfunc)BufferSubscript,
Karsten Hopp 521789
!     /* mp_ass_subscript */ (objobjargproc)BufferAsSubscript,
Karsten Hopp 521789
  };
Karsten Hopp 521789
  
Karsten Hopp 521789
  
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 897,902 ****
Karsten Hopp 521789
--- 931,938 ----
Karsten Hopp 521789
  
Karsten Hopp 521789
      if (this->buf && this->buf != INVALID_BUFFER_VALUE)
Karsten Hopp 521789
  	this->buf->b_python3_ref = NULL;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+     Py_TYPE(self)->tp_free((PyObject*)self);
Karsten Hopp 521789
  }
Karsten Hopp 521789
  
Karsten Hopp 521789
      static PyObject *
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 975,989 ****
Karsten Hopp 521789
  	       (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count);
Karsten Hopp 521789
  }
Karsten Hopp 521789
  
Karsten Hopp 521789
-     static Py_ssize_t
Karsten Hopp 521789
- BufferAsItem(PyObject *self, Py_ssize_t n, PyObject *val)
Karsten Hopp 521789
- {
Karsten Hopp 521789
-     return RBAsItem((BufferObject *)(self), n, val, 1,
Karsten Hopp 521789
- 		(Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
Karsten Hopp 521789
- 		NULL);
Karsten Hopp 521789
- }
Karsten Hopp 521789
- 
Karsten Hopp 521789
- 
Karsten Hopp 521789
      static PyObject *
Karsten Hopp 521789
  BufferSubscript(PyObject *self, PyObject* idx)
Karsten Hopp 521789
  {
Karsten Hopp 521789
--- 1011,1016 ----
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 999,1011 ****
Karsten Hopp 521789
  	      &step, &slicelen) < 0) {
Karsten Hopp 521789
  	    return NULL;
Karsten Hopp 521789
  	}
Karsten Hopp 521789
! 	return BufferSlice(self,start,stop+1);
Karsten Hopp 521789
      } else {
Karsten Hopp 521789
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 521789
  	return NULL;
Karsten Hopp 521789
      }
Karsten Hopp 521789
  }
Karsten Hopp 521789
  
Karsten Hopp 521789
  static PySequenceMethods RangeAsSeq = {
Karsten Hopp 521789
      (lenfunc)		RangeLength,	 /* sq_length,	  len(x)   */
Karsten Hopp 521789
      (binaryfunc)	0,		 /* RangeConcat, sq_concat,  x+y   */
Karsten Hopp 521789
--- 1026,1064 ----
Karsten Hopp 521789
  	      &step, &slicelen) < 0) {
Karsten Hopp 521789
  	    return NULL;
Karsten Hopp 521789
  	}
Karsten Hopp 521789
! 	return BufferSlice(self,start,stop);
Karsten Hopp 521789
      } else {
Karsten Hopp 521789
  	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 521789
  	return NULL;
Karsten Hopp 521789
      }
Karsten Hopp 521789
  }
Karsten Hopp 521789
  
Karsten Hopp 521789
+     static Py_ssize_t
Karsten Hopp 521789
+ BufferAsSubscript(PyObject *self, PyObject* idx, PyObject* val)
Karsten Hopp 521789
+ {
Karsten Hopp 521789
+     if (PyLong_Check(idx)) {
Karsten Hopp 521789
+ 	long n = PyLong_AsLong(idx);
Karsten Hopp 521789
+ 	return RBAsItem((BufferObject *)(self), n, val, 1,
Karsten Hopp 521789
+ 		    (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count,
Karsten Hopp 521789
+ 		    NULL);
Karsten Hopp 521789
+     } else if (PySlice_Check(idx)) {
Karsten Hopp 521789
+ 	Py_ssize_t start, stop, step, slicelen;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+ 	if (PySlice_GetIndicesEx((PySliceObject *)idx,
Karsten Hopp 521789
+ 	      (Py_ssize_t)((BufferObject *)(self))->buf->b_ml.ml_line_count+1,
Karsten Hopp 521789
+ 	      &start, &stop,
Karsten Hopp 521789
+ 	      &step, &slicelen) < 0) {
Karsten Hopp 521789
+ 	    return -1;
Karsten Hopp 521789
+ 	}
Karsten Hopp 521789
+ 	return RBAsSlice((BufferObject *)(self), start, stop, val, 1,
Karsten Hopp 521789
+ 			  (PyInt)((BufferObject *)(self))->buf->b_ml.ml_line_count,
Karsten Hopp 521789
+ 			  NULL);
Karsten Hopp 521789
+     } else {
Karsten Hopp 521789
+ 	PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
Karsten Hopp 521789
+ 	return -1;
Karsten Hopp 521789
+     }
Karsten Hopp 521789
+ }
Karsten Hopp 521789
+ 
Karsten Hopp 521789
  static PySequenceMethods RangeAsSeq = {
Karsten Hopp 521789
      (lenfunc)		RangeLength,	 /* sq_length,	  len(x)   */
Karsten Hopp 521789
      (binaryfunc)	0,		 /* RangeConcat, sq_concat,  x+y   */
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 1032,1037 ****
Karsten Hopp 521789
--- 1085,1091 ----
Karsten Hopp 521789
  RangeDestructor(PyObject *self)
Karsten Hopp 521789
  {
Karsten Hopp 521789
      Py_DECREF(((RangeObject *)(self))->buf);
Karsten Hopp 521789
+     Py_TYPE(self)->tp_free((PyObject*)self);
Karsten Hopp 521789
  }
Karsten Hopp 521789
  
Karsten Hopp 521789
      static PyObject *
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 1159,1164 ****
Karsten Hopp 521789
--- 1213,1220 ----
Karsten Hopp 521789
  
Karsten Hopp 521789
      if (this->win && this->win != INVALID_WINDOW_VALUE)
Karsten Hopp 521789
  	this->win->w_python3_ref = NULL;
Karsten Hopp 521789
+ 
Karsten Hopp 521789
+     Py_TYPE(self)->tp_free((PyObject*)self);
Karsten Hopp 521789
  }
Karsten Hopp 521789
  
Karsten Hopp 521789
      static PyObject *
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 1350,1357 ****
Karsten Hopp 521789
      PySys_SetArgv(1, argv);
Karsten Hopp 521789
  
Karsten Hopp 521789
      mod = PyModule_Create(&vimmodule);
Karsten Hopp 521789
  
Karsten Hopp 521789
!     VimError = Py_BuildValue("s", "vim.error");
Karsten Hopp 521789
  
Karsten Hopp 521789
      PyModule_AddObject(mod, "error", VimError);
Karsten Hopp 521789
      Py_INCREF((PyObject *)(void *)&TheBufferList);
Karsten Hopp 521789
--- 1406,1416 ----
Karsten Hopp 521789
      PySys_SetArgv(1, argv);
Karsten Hopp 521789
  
Karsten Hopp 521789
      mod = PyModule_Create(&vimmodule);
Karsten Hopp 521789
+     if (mod == NULL)
Karsten Hopp 521789
+ 	return NULL;
Karsten Hopp 521789
  
Karsten Hopp 521789
!     VimError = PyErr_NewException("vim.error", NULL, NULL);
Karsten Hopp 521789
!     Py_INCREF(VimError);
Karsten Hopp 521789
  
Karsten Hopp 521789
      PyModule_AddObject(mod, "error", VimError);
Karsten Hopp 521789
      Py_INCREF((PyObject *)(void *)&TheBufferList);
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 1404,1410 ****
Karsten Hopp 521789
      }
Karsten Hopp 521789
      *p = '\0';
Karsten Hopp 521789
  
Karsten Hopp 521789
!     result = PyUnicode_FromStringAndSize(tmp, len);
Karsten Hopp 521789
  
Karsten Hopp 521789
      vim_free(tmp);
Karsten Hopp 521789
      return result;
Karsten Hopp 521789
--- 1463,1469 ----
Karsten Hopp 521789
      }
Karsten Hopp 521789
      *p = '\0';
Karsten Hopp 521789
  
Karsten Hopp 521789
!     result = PyUnicode_Decode(tmp, len, (char *)p_enc, NULL);
Karsten Hopp 521789
  
Karsten Hopp 521789
      vim_free(tmp);
Karsten Hopp 521789
      return result;
Karsten Hopp 521789
*** ../vim-7.3.219/src/version.c	2011-06-13 02:03:55.000000000 +0200
Karsten Hopp 521789
--- src/version.c	2011-06-19 00:25:38.000000000 +0200
Karsten Hopp 521789
***************
Karsten Hopp 521789
*** 711,712 ****
Karsten Hopp 521789
--- 711,714 ----
Karsten Hopp 521789
  {   /* Add new patch number below this line */
Karsten Hopp 521789
+ /**/
Karsten Hopp 521789
+     220,
Karsten Hopp 521789
  /**/
Karsten Hopp 521789
Karsten Hopp 521789
-- 
Karsten Hopp 521789
I'm in shape.  Round IS a shape.
Karsten Hopp 521789
Karsten Hopp 521789
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 521789
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 521789
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 521789
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///