Karsten Hopp 62c2fb
To: vim_dev@googlegroups.com
Karsten Hopp 62c2fb
Subject: Patch 7.3.671
Karsten Hopp 62c2fb
Fcc: outbox
Karsten Hopp 62c2fb
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 62c2fb
Mime-Version: 1.0
Karsten Hopp 62c2fb
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 62c2fb
Content-Transfer-Encoding: 8bit
Karsten Hopp 62c2fb
------------
Karsten Hopp 62c2fb
Karsten Hopp 62c2fb
Patch 7.3.671
Karsten Hopp 62c2fb
Problem:    More Python code can be shared between Python 2 and 3.
Karsten Hopp 62c2fb
Solution:   Move code to if_py_both.h. (ZyX)
Karsten Hopp 62c2fb
Files:	    src/if_py_both.h, src/if_python.c, src/if_python3.c
Karsten Hopp 62c2fb
Karsten Hopp 62c2fb
Karsten Hopp 62c2fb
*** ../vim-7.3.670/src/if_py_both.h	2012-09-21 13:43:09.000000000 +0200
Karsten Hopp 62c2fb
--- src/if_py_both.h	2012-09-21 13:45:02.000000000 +0200
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 71,76 ****
Karsten Hopp 62c2fb
--- 71,101 ----
Karsten Hopp 62c2fb
  /* Output buffer management
Karsten Hopp 62c2fb
   */
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
+     static int
Karsten Hopp 62c2fb
+ OutputSetattr(PyObject *self, char *name, PyObject *val)
Karsten Hopp 62c2fb
+ {
Karsten Hopp 62c2fb
+     if (val == NULL)
Karsten Hopp 62c2fb
+     {
Karsten Hopp 62c2fb
+ 	PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
Karsten Hopp 62c2fb
+ 	return -1;
Karsten Hopp 62c2fb
+     }
Karsten Hopp 62c2fb
+ 
Karsten Hopp 62c2fb
+     if (strcmp(name, "softspace") == 0)
Karsten Hopp 62c2fb
+     {
Karsten Hopp 62c2fb
+ 	if (!PyInt_Check(val))
Karsten Hopp 62c2fb
+ 	{
Karsten Hopp 62c2fb
+ 	    PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
Karsten Hopp 62c2fb
+ 	    return -1;
Karsten Hopp 62c2fb
+ 	}
Karsten Hopp 62c2fb
+ 
Karsten Hopp 62c2fb
+ 	((OutputObject *)(self))->softspace = PyInt_AsLong(val);
Karsten Hopp 62c2fb
+ 	return 0;
Karsten Hopp 62c2fb
+     }
Karsten Hopp 62c2fb
+ 
Karsten Hopp 62c2fb
+     PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
Karsten Hopp 62c2fb
+     return -1;
Karsten Hopp 62c2fb
+ }
Karsten Hopp 62c2fb
+ 
Karsten Hopp 62c2fb
      static PyObject *
Karsten Hopp 62c2fb
  OutputWrite(PyObject *self, PyObject *args)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
*** ../vim-7.3.670/src/if_python.c	2012-09-12 20:21:38.000000000 +0200
Karsten Hopp 62c2fb
--- src/if_python.c	2012-09-21 13:45:02.000000000 +0200
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 951,981 ****
Karsten Hopp 62c2fb
      return Py_FindMethod(OutputMethods, self, name);
Karsten Hopp 62c2fb
  }
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
-     static int
Karsten Hopp 62c2fb
- OutputSetattr(PyObject *self, char *name, PyObject *val)
Karsten Hopp 62c2fb
- {
Karsten Hopp 62c2fb
-     if (val == NULL)
Karsten Hopp 62c2fb
-     {
Karsten Hopp 62c2fb
- 	PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
Karsten Hopp 62c2fb
- 	return -1;
Karsten Hopp 62c2fb
-     }
Karsten Hopp 62c2fb
- 
Karsten Hopp 62c2fb
-     if (strcmp(name, "softspace") == 0)
Karsten Hopp 62c2fb
-     {
Karsten Hopp 62c2fb
- 	if (!PyInt_Check(val))
Karsten Hopp 62c2fb
- 	{
Karsten Hopp 62c2fb
- 	    PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
Karsten Hopp 62c2fb
- 	    return -1;
Karsten Hopp 62c2fb
- 	}
Karsten Hopp 62c2fb
- 
Karsten Hopp 62c2fb
- 	((OutputObject *)(self))->softspace = PyInt_AsLong(val);
Karsten Hopp 62c2fb
- 	return 0;
Karsten Hopp 62c2fb
-     }
Karsten Hopp 62c2fb
- 
Karsten Hopp 62c2fb
-     PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
Karsten Hopp 62c2fb
-     return -1;
Karsten Hopp 62c2fb
- }
Karsten Hopp 62c2fb
- 
Karsten Hopp 62c2fb
  /***************/
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      static int
Karsten Hopp 62c2fb
--- 951,956 ----
Karsten Hopp 62c2fb
*** ../vim-7.3.670/src/if_python3.c	2012-09-12 20:21:38.000000000 +0200
Karsten Hopp 62c2fb
--- src/if_python3.c	2012-09-21 13:45:02.000000000 +0200
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 88,93 ****
Karsten Hopp 62c2fb
--- 88,96 ----
Karsten Hopp 62c2fb
  #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
Karsten Hopp 62c2fb
  #define PyString_FromString(repr) PyUnicode_FromString(repr)
Karsten Hopp 62c2fb
  #define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len)
Karsten Hopp 62c2fb
+ #define PyInt_Check(obj) PyLong_Check(obj)
Karsten Hopp 62c2fb
+ #define PyInt_FromLong(i) PyLong_FromLong(i)
Karsten Hopp 62c2fb
+ #define PyInt_AsLong(obj) PyLong_AsLong(obj)
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
  #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 586,591 ****
Karsten Hopp 62c2fb
--- 589,599 ----
Karsten Hopp 62c2fb
   */
Karsten Hopp 62c2fb
  #include "if_py_both.h"
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
+ #define GET_ATTR_STRING(name, nameobj) \
Karsten Hopp 62c2fb
+     char	*name = ""; \
Karsten Hopp 62c2fb
+     if(PyUnicode_Check(nameobj)) \
Karsten Hopp 62c2fb
+         name = _PyUnicode_AsString(nameobj)
Karsten Hopp 62c2fb
+ 
Karsten Hopp 62c2fb
  #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      static void
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 923,931 ****
Karsten Hopp 62c2fb
      static PyObject *
Karsten Hopp 62c2fb
  OutputGetattro(PyObject *self, PyObject *nameobj)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     char *name = "";
Karsten Hopp 62c2fb
!     if (PyUnicode_Check(nameobj))
Karsten Hopp 62c2fb
! 	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (strcmp(name, "softspace") == 0)
Karsten Hopp 62c2fb
  	return PyLong_FromLong(((OutputObject *)(self))->softspace);
Karsten Hopp 62c2fb
--- 931,937 ----
Karsten Hopp 62c2fb
      static PyObject *
Karsten Hopp 62c2fb
  OutputGetattro(PyObject *self, PyObject *nameobj)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     GET_ATTR_STRING(name, nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (strcmp(name, "softspace") == 0)
Karsten Hopp 62c2fb
  	return PyLong_FromLong(((OutputObject *)(self))->softspace);
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 936,965 ****
Karsten Hopp 62c2fb
      static int
Karsten Hopp 62c2fb
  OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     char *name = "";
Karsten Hopp 62c2fb
!     if (PyUnicode_Check(nameobj))
Karsten Hopp 62c2fb
! 	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 62c2fb
! 
Karsten Hopp 62c2fb
!     if (val == NULL)
Karsten Hopp 62c2fb
!     {
Karsten Hopp 62c2fb
! 	PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
Karsten Hopp 62c2fb
! 	return -1;
Karsten Hopp 62c2fb
!     }
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
!     if (strcmp(name, "softspace") == 0)
Karsten Hopp 62c2fb
!     {
Karsten Hopp 62c2fb
! 	if (!PyLong_Check(val))
Karsten Hopp 62c2fb
! 	{
Karsten Hopp 62c2fb
! 	    PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
Karsten Hopp 62c2fb
! 	    return -1;
Karsten Hopp 62c2fb
! 	}
Karsten Hopp 62c2fb
! 
Karsten Hopp 62c2fb
! 	((OutputObject *)(self))->softspace = PyLong_AsLong(val);
Karsten Hopp 62c2fb
! 	return 0;
Karsten Hopp 62c2fb
!     }
Karsten Hopp 62c2fb
! 
Karsten Hopp 62c2fb
!     PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
Karsten Hopp 62c2fb
!     return -1;
Karsten Hopp 62c2fb
  }
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
  /***************/
Karsten Hopp 62c2fb
--- 942,950 ----
Karsten Hopp 62c2fb
      static int
Karsten Hopp 62c2fb
  OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     GET_ATTR_STRING(name, nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
!     return OutputSetattr(self, name, val);
Karsten Hopp 62c2fb
  }
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
  /***************/
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 1091,1099 ****
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
      BufferObject *this = (BufferObject *)(self);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
!     char *name = "";
Karsten Hopp 62c2fb
!     if (PyUnicode_Check(nameobj))
Karsten Hopp 62c2fb
! 	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (CheckBuffer(this))
Karsten Hopp 62c2fb
  	return NULL;
Karsten Hopp 62c2fb
--- 1076,1082 ----
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
      BufferObject *this = (BufferObject *)(self);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
!     GET_ATTR_STRING(name, nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (CheckBuffer(this))
Karsten Hopp 62c2fb
  	return NULL;
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 1257,1265 ****
Karsten Hopp 62c2fb
      static PyObject *
Karsten Hopp 62c2fb
  RangeGetattro(PyObject *self, PyObject *nameobj)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     char *name = "";
Karsten Hopp 62c2fb
!     if (PyUnicode_Check(nameobj))
Karsten Hopp 62c2fb
! 	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (strcmp(name, "start") == 0)
Karsten Hopp 62c2fb
  	return Py_BuildValue("n", ((RangeObject *)(self))->start - 1);
Karsten Hopp 62c2fb
--- 1240,1246 ----
Karsten Hopp 62c2fb
      static PyObject *
Karsten Hopp 62c2fb
  RangeGetattro(PyObject *self, PyObject *nameobj)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     GET_ATTR_STRING(name, nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (strcmp(name, "start") == 0)
Karsten Hopp 62c2fb
  	return Py_BuildValue("n", ((RangeObject *)(self))->start - 1);
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 1430,1439 ****
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
      WindowObject *this = (WindowObject *)(self);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
!     char *name = "";
Karsten Hopp 62c2fb
!     if (PyUnicode_Check(nameobj))
Karsten Hopp 62c2fb
! 	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 62c2fb
! 
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (CheckWindow(this))
Karsten Hopp 62c2fb
  	return NULL;
Karsten Hopp 62c2fb
--- 1411,1417 ----
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
      WindowObject *this = (WindowObject *)(self);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
!     GET_ATTR_STRING(name, nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (CheckWindow(this))
Karsten Hopp 62c2fb
  	return NULL;
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 1461,1470 ****
Karsten Hopp 62c2fb
      static int
Karsten Hopp 62c2fb
  WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     char *name = "";
Karsten Hopp 62c2fb
! 
Karsten Hopp 62c2fb
!     if (PyUnicode_Check(nameobj))
Karsten Hopp 62c2fb
! 	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      return WindowSetattr(self, name, val);
Karsten Hopp 62c2fb
  }
Karsten Hopp 62c2fb
--- 1439,1445 ----
Karsten Hopp 62c2fb
      static int
Karsten Hopp 62c2fb
  WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     GET_ATTR_STRING(name, nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      return WindowSetattr(self, name, val);
Karsten Hopp 62c2fb
  }
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 1508,1516 ****
Karsten Hopp 62c2fb
      static PyObject *
Karsten Hopp 62c2fb
  CurrentGetattro(PyObject *self UNUSED, PyObject *nameobj)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     char *name = "";
Karsten Hopp 62c2fb
!     if (PyUnicode_Check(nameobj))
Karsten Hopp 62c2fb
! 	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (strcmp(name, "buffer") == 0)
Karsten Hopp 62c2fb
  	return (PyObject *)BufferNew(curbuf);
Karsten Hopp 62c2fb
--- 1483,1489 ----
Karsten Hopp 62c2fb
      static PyObject *
Karsten Hopp 62c2fb
  CurrentGetattro(PyObject *self UNUSED, PyObject *nameobj)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
!     GET_ATTR_STRING(name, nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (strcmp(name, "buffer") == 0)
Karsten Hopp 62c2fb
  	return (PyObject *)BufferNew(curbuf);
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 1681,1689 ****
Karsten Hopp 62c2fb
  FunctionGetattro(PyObject *self, PyObject *nameobj)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
      FunctionObject	*this = (FunctionObject *)(self);
Karsten Hopp 62c2fb
!     char	*name = "";
Karsten Hopp 62c2fb
!     if (PyUnicode_Check(nameobj))
Karsten Hopp 62c2fb
! 	name = _PyUnicode_AsString(nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (strcmp(name, "name") == 0)
Karsten Hopp 62c2fb
  	return PyUnicode_FromString((char *)(this->name));
Karsten Hopp 62c2fb
--- 1654,1661 ----
Karsten Hopp 62c2fb
  FunctionGetattro(PyObject *self, PyObject *nameobj)
Karsten Hopp 62c2fb
  {
Karsten Hopp 62c2fb
      FunctionObject	*this = (FunctionObject *)(self);
Karsten Hopp 62c2fb
! 
Karsten Hopp 62c2fb
!     GET_ATTR_STRING(name, nameobj);
Karsten Hopp 62c2fb
  
Karsten Hopp 62c2fb
      if (strcmp(name, "name") == 0)
Karsten Hopp 62c2fb
  	return PyUnicode_FromString((char *)(this->name));
Karsten Hopp 62c2fb
*** ../vim-7.3.670/src/version.c	2012-09-21 13:43:09.000000000 +0200
Karsten Hopp 62c2fb
--- src/version.c	2012-09-21 13:45:28.000000000 +0200
Karsten Hopp 62c2fb
***************
Karsten Hopp 62c2fb
*** 721,722 ****
Karsten Hopp 62c2fb
--- 721,724 ----
Karsten Hopp 62c2fb
  {   /* Add new patch number below this line */
Karsten Hopp 62c2fb
+ /**/
Karsten Hopp 62c2fb
+     671,
Karsten Hopp 62c2fb
  /**/
Karsten Hopp 62c2fb
Karsten Hopp 62c2fb
-- 
Karsten Hopp 62c2fb
The war between Emacs and Vi is over.  Vi has won with 3 to 1.
Karsten Hopp 62c2fb
			http://www.ssc.com/lg/issue30/raymond.html
Karsten Hopp 62c2fb
Karsten Hopp 62c2fb
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 62c2fb
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 62c2fb
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 62c2fb
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///