home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.3 / 7.3.671 < prev    next >
Encoding:
Internet Message Format  |  2012-11-20  |  8.0 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.671
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.3.671
  11. Problem:    More Python code can be shared between Python 2 and 3.
  12. Solution:   Move code to if_py_both.h. (ZyX)
  13. Files:        src/if_py_both.h, src/if_python.c, src/if_python3.c
  14.  
  15.  
  16. *** ../vim-7.3.670/src/if_py_both.h    2012-09-21 13:43:09.000000000 +0200
  17. --- src/if_py_both.h    2012-09-21 13:45:02.000000000 +0200
  18. ***************
  19. *** 71,76 ****
  20. --- 71,101 ----
  21.   /* Output buffer management
  22.    */
  23.   
  24. +     static int
  25. + OutputSetattr(PyObject *self, char *name, PyObject *val)
  26. + {
  27. +     if (val == NULL)
  28. +     {
  29. +     PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
  30. +     return -1;
  31. +     }
  32. +     if (strcmp(name, "softspace") == 0)
  33. +     {
  34. +     if (!PyInt_Check(val))
  35. +     {
  36. +         PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
  37. +         return -1;
  38. +     }
  39. +     ((OutputObject *)(self))->softspace = PyInt_AsLong(val);
  40. +     return 0;
  41. +     }
  42. +     PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
  43. +     return -1;
  44. + }
  45.       static PyObject *
  46.   OutputWrite(PyObject *self, PyObject *args)
  47.   {
  48. *** ../vim-7.3.670/src/if_python.c    2012-09-12 20:21:38.000000000 +0200
  49. --- src/if_python.c    2012-09-21 13:45:02.000000000 +0200
  50. ***************
  51. *** 951,981 ****
  52.       return Py_FindMethod(OutputMethods, self, name);
  53.   }
  54.   
  55. -     static int
  56. - OutputSetattr(PyObject *self, char *name, PyObject *val)
  57. - {
  58. -     if (val == NULL)
  59. -     {
  60. -     PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
  61. -     return -1;
  62. -     }
  63. -     if (strcmp(name, "softspace") == 0)
  64. -     {
  65. -     if (!PyInt_Check(val))
  66. -     {
  67. -         PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
  68. -         return -1;
  69. -     }
  70. -     ((OutputObject *)(self))->softspace = PyInt_AsLong(val);
  71. -     return 0;
  72. -     }
  73. -     PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
  74. -     return -1;
  75. - }
  76.   /***************/
  77.   
  78.       static int
  79. --- 951,956 ----
  80. *** ../vim-7.3.670/src/if_python3.c    2012-09-12 20:21:38.000000000 +0200
  81. --- src/if_python3.c    2012-09-21 13:45:02.000000000 +0200
  82. ***************
  83. *** 88,93 ****
  84. --- 88,96 ----
  85.   #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
  86.   #define PyString_FromString(repr) PyUnicode_FromString(repr)
  87.   #define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len)
  88. + #define PyInt_Check(obj) PyLong_Check(obj)
  89. + #define PyInt_FromLong(i) PyLong_FromLong(i)
  90. + #define PyInt_AsLong(obj) PyLong_AsLong(obj)
  91.   
  92.   #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
  93.   
  94. ***************
  95. *** 586,591 ****
  96. --- 589,599 ----
  97.    */
  98.   #include "if_py_both.h"
  99.   
  100. + #define GET_ATTR_STRING(name, nameobj) \
  101. +     char    *name = ""; \
  102. +     if(PyUnicode_Check(nameobj)) \
  103. +         name = _PyUnicode_AsString(nameobj)
  104.   #define PY3OBJ_DELETED(obj) (obj->ob_base.ob_refcnt<=0)
  105.   
  106.       static void
  107. ***************
  108. *** 923,931 ****
  109.       static PyObject *
  110.   OutputGetattro(PyObject *self, PyObject *nameobj)
  111.   {
  112. !     char *name = "";
  113. !     if (PyUnicode_Check(nameobj))
  114. !     name = _PyUnicode_AsString(nameobj);
  115.   
  116.       if (strcmp(name, "softspace") == 0)
  117.       return PyLong_FromLong(((OutputObject *)(self))->softspace);
  118. --- 931,937 ----
  119.       static PyObject *
  120.   OutputGetattro(PyObject *self, PyObject *nameobj)
  121.   {
  122. !     GET_ATTR_STRING(name, nameobj);
  123.   
  124.       if (strcmp(name, "softspace") == 0)
  125.       return PyLong_FromLong(((OutputObject *)(self))->softspace);
  126. ***************
  127. *** 936,965 ****
  128.       static int
  129.   OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
  130.   {
  131. !     char *name = "";
  132. !     if (PyUnicode_Check(nameobj))
  133. !     name = _PyUnicode_AsString(nameobj);
  134. !     if (val == NULL)
  135. !     {
  136. !     PyErr_SetString(PyExc_AttributeError, _("can't delete OutputObject attributes"));
  137. !     return -1;
  138. !     }
  139.   
  140. !     if (strcmp(name, "softspace") == 0)
  141. !     {
  142. !     if (!PyLong_Check(val))
  143. !     {
  144. !         PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
  145. !         return -1;
  146. !     }
  147. !     ((OutputObject *)(self))->softspace = PyLong_AsLong(val);
  148. !     return 0;
  149. !     }
  150. !     PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
  151. !     return -1;
  152.   }
  153.   
  154.   /***************/
  155. --- 942,950 ----
  156.       static int
  157.   OutputSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
  158.   {
  159. !     GET_ATTR_STRING(name, nameobj);
  160.   
  161. !     return OutputSetattr(self, name, val);
  162.   }
  163.   
  164.   /***************/
  165. ***************
  166. *** 1091,1099 ****
  167.   {
  168.       BufferObject *this = (BufferObject *)(self);
  169.   
  170. !     char *name = "";
  171. !     if (PyUnicode_Check(nameobj))
  172. !     name = _PyUnicode_AsString(nameobj);
  173.   
  174.       if (CheckBuffer(this))
  175.       return NULL;
  176. --- 1076,1082 ----
  177.   {
  178.       BufferObject *this = (BufferObject *)(self);
  179.   
  180. !     GET_ATTR_STRING(name, nameobj);
  181.   
  182.       if (CheckBuffer(this))
  183.       return NULL;
  184. ***************
  185. *** 1257,1265 ****
  186.       static PyObject *
  187.   RangeGetattro(PyObject *self, PyObject *nameobj)
  188.   {
  189. !     char *name = "";
  190. !     if (PyUnicode_Check(nameobj))
  191. !     name = _PyUnicode_AsString(nameobj);
  192.   
  193.       if (strcmp(name, "start") == 0)
  194.       return Py_BuildValue("n", ((RangeObject *)(self))->start - 1);
  195. --- 1240,1246 ----
  196.       static PyObject *
  197.   RangeGetattro(PyObject *self, PyObject *nameobj)
  198.   {
  199. !     GET_ATTR_STRING(name, nameobj);
  200.   
  201.       if (strcmp(name, "start") == 0)
  202.       return Py_BuildValue("n", ((RangeObject *)(self))->start - 1);
  203. ***************
  204. *** 1430,1439 ****
  205.   {
  206.       WindowObject *this = (WindowObject *)(self);
  207.   
  208. !     char *name = "";
  209. !     if (PyUnicode_Check(nameobj))
  210. !     name = _PyUnicode_AsString(nameobj);
  211.   
  212.       if (CheckWindow(this))
  213.       return NULL;
  214. --- 1411,1417 ----
  215.   {
  216.       WindowObject *this = (WindowObject *)(self);
  217.   
  218. !     GET_ATTR_STRING(name, nameobj);
  219.   
  220.       if (CheckWindow(this))
  221.       return NULL;
  222. ***************
  223. *** 1461,1470 ****
  224.       static int
  225.   WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
  226.   {
  227. !     char *name = "";
  228. !     if (PyUnicode_Check(nameobj))
  229. !     name = _PyUnicode_AsString(nameobj);
  230.   
  231.       return WindowSetattr(self, name, val);
  232.   }
  233. --- 1439,1445 ----
  234.       static int
  235.   WindowSetattro(PyObject *self, PyObject *nameobj, PyObject *val)
  236.   {
  237. !     GET_ATTR_STRING(name, nameobj);
  238.   
  239.       return WindowSetattr(self, name, val);
  240.   }
  241. ***************
  242. *** 1508,1516 ****
  243.       static PyObject *
  244.   CurrentGetattro(PyObject *self UNUSED, PyObject *nameobj)
  245.   {
  246. !     char *name = "";
  247. !     if (PyUnicode_Check(nameobj))
  248. !     name = _PyUnicode_AsString(nameobj);
  249.   
  250.       if (strcmp(name, "buffer") == 0)
  251.       return (PyObject *)BufferNew(curbuf);
  252. --- 1483,1489 ----
  253.       static PyObject *
  254.   CurrentGetattro(PyObject *self UNUSED, PyObject *nameobj)
  255.   {
  256. !     GET_ATTR_STRING(name, nameobj);
  257.   
  258.       if (strcmp(name, "buffer") == 0)
  259.       return (PyObject *)BufferNew(curbuf);
  260. ***************
  261. *** 1681,1689 ****
  262.   FunctionGetattro(PyObject *self, PyObject *nameobj)
  263.   {
  264.       FunctionObject    *this = (FunctionObject *)(self);
  265. !     char    *name = "";
  266. !     if (PyUnicode_Check(nameobj))
  267. !     name = _PyUnicode_AsString(nameobj);
  268.   
  269.       if (strcmp(name, "name") == 0)
  270.       return PyUnicode_FromString((char *)(this->name));
  271. --- 1654,1661 ----
  272.   FunctionGetattro(PyObject *self, PyObject *nameobj)
  273.   {
  274.       FunctionObject    *this = (FunctionObject *)(self);
  275. !     GET_ATTR_STRING(name, nameobj);
  276.   
  277.       if (strcmp(name, "name") == 0)
  278.       return PyUnicode_FromString((char *)(this->name));
  279. *** ../vim-7.3.670/src/version.c    2012-09-21 13:43:09.000000000 +0200
  280. --- src/version.c    2012-09-21 13:45:28.000000000 +0200
  281. ***************
  282. *** 721,722 ****
  283. --- 721,724 ----
  284.   {   /* Add new patch number below this line */
  285. + /**/
  286. +     671,
  287.   /**/
  288.  
  289. -- 
  290. The war between Emacs and Vi is over.  Vi has won with 3 to 1.
  291.             http://www.ssc.com/lg/issue30/raymond.html
  292.  
  293.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  294. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  295. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  296.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  297.