Karsten Hopp 9bc07e
To: vim_dev@googlegroups.com
Karsten Hopp 9bc07e
Subject: Patch 7.3.1059
Karsten Hopp 9bc07e
Fcc: outbox
Karsten Hopp 9bc07e
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 9bc07e
Mime-Version: 1.0
Karsten Hopp 9bc07e
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 9bc07e
Content-Transfer-Encoding: 8bit
Karsten Hopp 9bc07e
------------
Karsten Hopp 9bc07e
Karsten Hopp 9bc07e
Patch 7.3.1059
Karsten Hopp 9bc07e
Problem:    Python: Using fixed size buffers.
Karsten Hopp 9bc07e
Solution:   Python patch 18: Use python's own formatter. (ZyX)
Karsten Hopp 9bc07e
Files:	    src/if_py_both.h, src/if_python3.c, src/if_python.c
Karsten Hopp 9bc07e
Karsten Hopp 9bc07e
Karsten Hopp 9bc07e
*** ../vim-7.3.1058/src/if_py_both.h	2013-05-30 12:26:52.000000000 +0200
Karsten Hopp 9bc07e
--- src/if_py_both.h	2013-05-30 12:38:22.000000000 +0200
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 2006,2029 ****
Karsten Hopp 9bc07e
      static PyObject *
Karsten Hopp 9bc07e
  TabPageRepr(TabPageObject *self)
Karsten Hopp 9bc07e
  {
Karsten Hopp 9bc07e
-     static char repr[100];
Karsten Hopp 9bc07e
- 
Karsten Hopp 9bc07e
      if (self->tab == INVALID_TABPAGE_VALUE)
Karsten Hopp 9bc07e
!     {
Karsten Hopp 9bc07e
! 	vim_snprintf(repr, 100, _("<tabpage object (deleted) at %p>"), (self));
Karsten Hopp 9bc07e
! 	return PyString_FromString(repr);
Karsten Hopp 9bc07e
!     }
Karsten Hopp 9bc07e
      else
Karsten Hopp 9bc07e
      {
Karsten Hopp 9bc07e
  	int	t = get_tab_number(self->tab);
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
  	if (t == 0)
Karsten Hopp 9bc07e
! 	    vim_snprintf(repr, 100, _("<tabpage object (unknown) at %p>"),
Karsten Hopp 9bc07e
! 								      (self));
Karsten Hopp 9bc07e
  	else
Karsten Hopp 9bc07e
! 	    vim_snprintf(repr, 100, _("<tabpage %d>"), t - 1);
Karsten Hopp 9bc07e
! 
Karsten Hopp 9bc07e
! 	return PyString_FromString(repr);
Karsten Hopp 9bc07e
      }
Karsten Hopp 9bc07e
  }
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
--- 2006,2022 ----
Karsten Hopp 9bc07e
      static PyObject *
Karsten Hopp 9bc07e
  TabPageRepr(TabPageObject *self)
Karsten Hopp 9bc07e
  {
Karsten Hopp 9bc07e
      if (self->tab == INVALID_TABPAGE_VALUE)
Karsten Hopp 9bc07e
! 	return PyString_FromFormat("<tabpage object (deleted) at %p>", (self));
Karsten Hopp 9bc07e
      else
Karsten Hopp 9bc07e
      {
Karsten Hopp 9bc07e
  	int	t = get_tab_number(self->tab);
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
  	if (t == 0)
Karsten Hopp 9bc07e
! 	    return PyString_FromFormat("<tabpage object (unknown) at %p>",
Karsten Hopp 9bc07e
! 					(self));
Karsten Hopp 9bc07e
  	else
Karsten Hopp 9bc07e
! 	    return PyString_FromFormat("<tabpage %d>", t - 1);
Karsten Hopp 9bc07e
      }
Karsten Hopp 9bc07e
  }
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 2344,2367 ****
Karsten Hopp 9bc07e
      static PyObject *
Karsten Hopp 9bc07e
  WindowRepr(WindowObject *self)
Karsten Hopp 9bc07e
  {
Karsten Hopp 9bc07e
-     static char repr[100];
Karsten Hopp 9bc07e
- 
Karsten Hopp 9bc07e
      if (self->win == INVALID_WINDOW_VALUE)
Karsten Hopp 9bc07e
!     {
Karsten Hopp 9bc07e
! 	vim_snprintf(repr, 100, _("<window object (deleted) at %p>"), (self));
Karsten Hopp 9bc07e
! 	return PyString_FromString(repr);
Karsten Hopp 9bc07e
!     }
Karsten Hopp 9bc07e
      else
Karsten Hopp 9bc07e
      {
Karsten Hopp 9bc07e
  	int	w = get_win_number(self->win, firstwin);
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
  	if (w == 0)
Karsten Hopp 9bc07e
! 	    vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
Karsten Hopp 9bc07e
  								      (self));
Karsten Hopp 9bc07e
  	else
Karsten Hopp 9bc07e
! 	    vim_snprintf(repr, 100, _("<window %d>"), w - 1);
Karsten Hopp 9bc07e
! 
Karsten Hopp 9bc07e
! 	return PyString_FromString(repr);
Karsten Hopp 9bc07e
      }
Karsten Hopp 9bc07e
  }
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
--- 2337,2353 ----
Karsten Hopp 9bc07e
      static PyObject *
Karsten Hopp 9bc07e
  WindowRepr(WindowObject *self)
Karsten Hopp 9bc07e
  {
Karsten Hopp 9bc07e
      if (self->win == INVALID_WINDOW_VALUE)
Karsten Hopp 9bc07e
! 	return PyString_FromFormat("<window object (deleted) at %p>", (self));
Karsten Hopp 9bc07e
      else
Karsten Hopp 9bc07e
      {
Karsten Hopp 9bc07e
  	int	w = get_win_number(self->win, firstwin);
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
  	if (w == 0)
Karsten Hopp 9bc07e
! 	    return PyString_FromFormat("<window object (unknown) at %p>",
Karsten Hopp 9bc07e
  								      (self));
Karsten Hopp 9bc07e
  	else
Karsten Hopp 9bc07e
! 	    return PyString_FromFormat("<window %d>", w - 1);
Karsten Hopp 9bc07e
      }
Karsten Hopp 9bc07e
  }
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 3281,3311 ****
Karsten Hopp 9bc07e
      static PyObject *
Karsten Hopp 9bc07e
  RangeRepr(RangeObject *self)
Karsten Hopp 9bc07e
  {
Karsten Hopp 9bc07e
-     static char repr[100];
Karsten Hopp 9bc07e
- 
Karsten Hopp 9bc07e
      if (self->buf->buf == INVALID_BUFFER_VALUE)
Karsten Hopp 9bc07e
!     {
Karsten Hopp 9bc07e
! 	vim_snprintf(repr, 100, "<range object (for deleted buffer) at %p>",
Karsten Hopp 9bc07e
! 								      (self));
Karsten Hopp 9bc07e
! 	return PyString_FromString(repr);
Karsten Hopp 9bc07e
!     }
Karsten Hopp 9bc07e
      else
Karsten Hopp 9bc07e
      {
Karsten Hopp 9bc07e
  	char *name = (char *)self->buf->buf->b_fname;
Karsten Hopp 9bc07e
- 	int len;
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
  	if (name == NULL)
Karsten Hopp 9bc07e
  	    name = "";
Karsten Hopp 9bc07e
- 	len = (int)strlen(name);
Karsten Hopp 9bc07e
- 
Karsten Hopp 9bc07e
- 	if (len > 45)
Karsten Hopp 9bc07e
- 	    name = name + (45 - len);
Karsten Hopp 9bc07e
- 
Karsten Hopp 9bc07e
- 	vim_snprintf(repr, 100, "<range %s%s (%d:%d)>",
Karsten Hopp 9bc07e
- 		len > 45 ? "..." : "", name,
Karsten Hopp 9bc07e
- 		self->start, self->end);
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
! 	return PyString_FromString(repr);
Karsten Hopp 9bc07e
      }
Karsten Hopp 9bc07e
  }
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
--- 3267,3284 ----
Karsten Hopp 9bc07e
      static PyObject *
Karsten Hopp 9bc07e
  RangeRepr(RangeObject *self)
Karsten Hopp 9bc07e
  {
Karsten Hopp 9bc07e
      if (self->buf->buf == INVALID_BUFFER_VALUE)
Karsten Hopp 9bc07e
! 	return PyString_FromFormat("<range object (for deleted buffer) at %p>",
Karsten Hopp 9bc07e
! 				    (self));
Karsten Hopp 9bc07e
      else
Karsten Hopp 9bc07e
      {
Karsten Hopp 9bc07e
  	char *name = (char *)self->buf->buf->b_fname;
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
  	if (name == NULL)
Karsten Hopp 9bc07e
  	    name = "";
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
! 	return PyString_FromFormat("<range %s (%d:%d)>",
Karsten Hopp 9bc07e
! 				    name, self->start, self->end);
Karsten Hopp 9bc07e
      }
Karsten Hopp 9bc07e
  }
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 3534,3561 ****
Karsten Hopp 9bc07e
      static PyObject *
Karsten Hopp 9bc07e
  BufferRepr(BufferObject *self)
Karsten Hopp 9bc07e
  {
Karsten Hopp 9bc07e
-     static char repr[100];
Karsten Hopp 9bc07e
- 
Karsten Hopp 9bc07e
      if (self->buf == INVALID_BUFFER_VALUE)
Karsten Hopp 9bc07e
!     {
Karsten Hopp 9bc07e
! 	vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self));
Karsten Hopp 9bc07e
! 	return PyString_FromString(repr);
Karsten Hopp 9bc07e
!     }
Karsten Hopp 9bc07e
      else
Karsten Hopp 9bc07e
      {
Karsten Hopp 9bc07e
! 	char *name = (char *)self->buf->b_fname;
Karsten Hopp 9bc07e
! 	PyInt len;
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
  	if (name == NULL)
Karsten Hopp 9bc07e
  	    name = "";
Karsten Hopp 9bc07e
- 	len = strlen(name);
Karsten Hopp 9bc07e
- 
Karsten Hopp 9bc07e
- 	if (len > 35)
Karsten Hopp 9bc07e
- 	    name = name + (35 - len);
Karsten Hopp 9bc07e
- 
Karsten Hopp 9bc07e
- 	vim_snprintf(repr, 100, "<buffer %s%s>", len > 35 ? "..." : "", name);
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
! 	return PyString_FromString(repr);
Karsten Hopp 9bc07e
      }
Karsten Hopp 9bc07e
  }
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
--- 3507,3522 ----
Karsten Hopp 9bc07e
      static PyObject *
Karsten Hopp 9bc07e
  BufferRepr(BufferObject *self)
Karsten Hopp 9bc07e
  {
Karsten Hopp 9bc07e
      if (self->buf == INVALID_BUFFER_VALUE)
Karsten Hopp 9bc07e
! 	return PyString_FromFormat("<buffer object (deleted) at %p>", self);
Karsten Hopp 9bc07e
      else
Karsten Hopp 9bc07e
      {
Karsten Hopp 9bc07e
! 	char	*name = (char *)self->buf->b_fname;
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
  	if (name == NULL)
Karsten Hopp 9bc07e
  	    name = "";
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
! 	return PyString_FromFormat("<buffer %s>", name);
Karsten Hopp 9bc07e
      }
Karsten Hopp 9bc07e
  }
Karsten Hopp 9bc07e
  
Karsten Hopp 9bc07e
*** ../vim-7.3.1058/src/if_python3.c	2013-05-29 22:36:06.000000000 +0200
Karsten Hopp 9bc07e
--- src/if_python3.c	2013-05-30 12:39:25.000000000 +0200
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 90,95 ****
Karsten Hopp 9bc07e
--- 90,96 ----
Karsten Hopp 9bc07e
  #define PyString_AsString(obj) PyBytes_AsString(obj)
Karsten Hopp 9bc07e
  #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
Karsten Hopp 9bc07e
  #define PyString_FromString(repr) PyUnicode_FromString(repr)
Karsten Hopp 9bc07e
+ #define PyString_FromFormat PyUnicode_FromFormat
Karsten Hopp 9bc07e
  #define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len)
Karsten Hopp 9bc07e
  #define PyInt_Check(obj) PyLong_Check(obj)
Karsten Hopp 9bc07e
  #define PyInt_FromLong(i) PyLong_FromLong(i)
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 230,235 ****
Karsten Hopp 9bc07e
--- 231,246 ----
Karsten Hopp 9bc07e
  # define PyType_GenericNew py3_PyType_GenericNew
Karsten Hopp 9bc07e
  # undef PyUnicode_FromString
Karsten Hopp 9bc07e
  # define PyUnicode_FromString py3_PyUnicode_FromString
Karsten Hopp 9bc07e
+ # ifndef PyUnicode_FromFormat
Karsten Hopp 9bc07e
+ #  define PyUnicode_FromFormat py3_PyUnicode_FromFormat
Karsten Hopp 9bc07e
+ # else
Karsten Hopp 9bc07e
+ #  define Py_UNICODE_USE_UCS_FUNCTIONS
Karsten Hopp 9bc07e
+ #  ifdef Py_UNICODE_WIDE
Karsten Hopp 9bc07e
+ #   define PyUnicodeUCS4_FromFormat py3_PyUnicodeUCS4_FromFormat
Karsten Hopp 9bc07e
+ #  else
Karsten Hopp 9bc07e
+ #   define PyUnicodeUCS2_FromFormat py3_PyUnicodeUCS2_FromFormat
Karsten Hopp 9bc07e
+ #  endif
Karsten Hopp 9bc07e
+ # endif
Karsten Hopp 9bc07e
  # undef PyUnicode_Decode
Karsten Hopp 9bc07e
  # define PyUnicode_Decode py3_PyUnicode_Decode
Karsten Hopp 9bc07e
  # define PyType_IsSubtype py3_PyType_IsSubtype
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 293,298 ****
Karsten Hopp 9bc07e
--- 304,318 ----
Karsten Hopp 9bc07e
  static int (*py3_PyType_Ready)(PyTypeObject *type);
Karsten Hopp 9bc07e
  static int (*py3_PyDict_SetItemString)(PyObject *dp, char *key, PyObject *item);
Karsten Hopp 9bc07e
  static PyObject* (*py3_PyUnicode_FromString)(const char *u);
Karsten Hopp 9bc07e
+ # ifndef Py_UNICODE_USE_UCS_FUNCTIONS
Karsten Hopp 9bc07e
+ static PyObject* (*py3_PyUnicode_FromFormat)(const char *u, ...);
Karsten Hopp 9bc07e
+ # else
Karsten Hopp 9bc07e
+ #  ifdef Py_UNICODE_WIDE
Karsten Hopp 9bc07e
+ static PyObject* (*py3_PyUnicodeUCS4_FromFormat)(const char *u, ...);
Karsten Hopp 9bc07e
+ #  else
Karsten Hopp 9bc07e
+ static PyObject* (*py3_PyUnicodeUCS2_FromFormat)(const char *u, ...);
Karsten Hopp 9bc07e
+ #  endif
Karsten Hopp 9bc07e
+ # endif
Karsten Hopp 9bc07e
  static PyObject* (*py3_PyUnicode_Decode)(const char *u, Py_ssize_t size,
Karsten Hopp 9bc07e
  	const char *encoding, const char *errors);
Karsten Hopp 9bc07e
  static long (*py3_PyLong_AsLong)(PyObject *);
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 458,463 ****
Karsten Hopp 9bc07e
--- 478,492 ----
Karsten Hopp 9bc07e
  # else
Karsten Hopp 9bc07e
      {"_PyUnicode_AsString", (PYTHON_PROC*)&py3__PyUnicode_AsString},
Karsten Hopp 9bc07e
  # endif
Karsten Hopp 9bc07e
+ # ifndef Py_UNICODE_USE_UCS_FUNCTIONS
Karsten Hopp 9bc07e
+     {"PyUnicode_FromFormat", (PYTHON_PROC*)&py3_PyUnicode_FromFormat},
Karsten Hopp 9bc07e
+ # else
Karsten Hopp 9bc07e
+ #  ifdef Py_UNICODE_WIDE
Karsten Hopp 9bc07e
+     {"PyUnicodeUCS4_FromFormat", (PYTHON_PROC*)&py3_PyUnicodeUCS4_FromFormat},
Karsten Hopp 9bc07e
+ #  else
Karsten Hopp 9bc07e
+     {"PyUnicodeUCS2_FromFormat", (PYTHON_PROC*)&py3_PyUnicodeUCS2_FromFormat},
Karsten Hopp 9bc07e
+ #  endif
Karsten Hopp 9bc07e
+ # endif
Karsten Hopp 9bc07e
      {"PyBytes_AsString", (PYTHON_PROC*)&py3_PyBytes_AsString},
Karsten Hopp 9bc07e
      {"PyBytes_AsStringAndSize", (PYTHON_PROC*)&py3_PyBytes_AsStringAndSize},
Karsten Hopp 9bc07e
      {"PyBytes_FromString", (PYTHON_PROC*)&py3_PyBytes_FromString},
Karsten Hopp 9bc07e
*** ../vim-7.3.1058/src/if_python.c	2013-05-29 22:36:06.000000000 +0200
Karsten Hopp 9bc07e
--- src/if_python.c	2013-05-30 12:38:22.000000000 +0200
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 212,217 ****
Karsten Hopp 9bc07e
--- 212,218 ----
Karsten Hopp 9bc07e
  # define PyString_AsString dll_PyString_AsString
Karsten Hopp 9bc07e
  # define PyString_AsStringAndSize dll_PyString_AsStringAndSize
Karsten Hopp 9bc07e
  # define PyString_FromString dll_PyString_FromString
Karsten Hopp 9bc07e
+ # define PyString_FromFormat dll_PyString_FromFormat
Karsten Hopp 9bc07e
  # define PyString_FromStringAndSize dll_PyString_FromStringAndSize
Karsten Hopp 9bc07e
  # define PyString_Size dll_PyString_Size
Karsten Hopp 9bc07e
  # define PyString_Type (*dll_PyString_Type)
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 340,345 ****
Karsten Hopp 9bc07e
--- 341,347 ----
Karsten Hopp 9bc07e
  static char*(*dll_PyString_AsString)(PyObject *);
Karsten Hopp 9bc07e
  static int(*dll_PyString_AsStringAndSize)(PyObject *, char **, int *);
Karsten Hopp 9bc07e
  static PyObject*(*dll_PyString_FromString)(const char *);
Karsten Hopp 9bc07e
+ static PyObject*(*dll_PyString_FromFormat)(const char *, ...);
Karsten Hopp 9bc07e
  static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt);
Karsten Hopp 9bc07e
  static PyInt(*dll_PyString_Size)(PyObject *);
Karsten Hopp 9bc07e
  static PyTypeObject* dll_PyString_Type;
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 499,504 ****
Karsten Hopp 9bc07e
--- 501,507 ----
Karsten Hopp 9bc07e
      {"PyString_AsString", (PYTHON_PROC*)&dll_PyString_AsString},
Karsten Hopp 9bc07e
      {"PyString_AsStringAndSize", (PYTHON_PROC*)&dll_PyString_AsStringAndSize},
Karsten Hopp 9bc07e
      {"PyString_FromString", (PYTHON_PROC*)&dll_PyString_FromString},
Karsten Hopp 9bc07e
+     {"PyString_FromFormat", (PYTHON_PROC*)&dll_PyString_FromFormat},
Karsten Hopp 9bc07e
      {"PyString_FromStringAndSize", (PYTHON_PROC*)&dll_PyString_FromStringAndSize},
Karsten Hopp 9bc07e
      {"PyString_Size", (PYTHON_PROC*)&dll_PyString_Size},
Karsten Hopp 9bc07e
      {"PyString_Type", (PYTHON_PROC*)&dll_PyString_Type},
Karsten Hopp 9bc07e
*** ../vim-7.3.1058/src/version.c	2013-05-30 12:35:48.000000000 +0200
Karsten Hopp 9bc07e
--- src/version.c	2013-05-30 12:39:51.000000000 +0200
Karsten Hopp 9bc07e
***************
Karsten Hopp 9bc07e
*** 730,731 ****
Karsten Hopp 9bc07e
--- 730,733 ----
Karsten Hopp 9bc07e
  {   /* Add new patch number below this line */
Karsten Hopp 9bc07e
+ /**/
Karsten Hopp 9bc07e
+     1059,
Karsten Hopp 9bc07e
  /**/
Karsten Hopp 9bc07e
Karsten Hopp 9bc07e
-- 
Karsten Hopp 9bc07e
How To Keep A Healthy Level Of Insanity:
Karsten Hopp 9bc07e
2. Page yourself over the intercom. Don't disguise your voice.
Karsten Hopp 9bc07e
Karsten Hopp 9bc07e
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 9bc07e
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 9bc07e
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 9bc07e
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///