Karsten Hopp 36ff25
To: vim_dev@googlegroups.com
Karsten Hopp 36ff25
Subject: Patch 7.3.579
Karsten Hopp 36ff25
Fcc: outbox
Karsten Hopp 36ff25
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 36ff25
Mime-Version: 1.0
Karsten Hopp 36ff25
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 36ff25
Content-Transfer-Encoding: 8bit
Karsten Hopp 36ff25
------------
Karsten Hopp 36ff25
Karsten Hopp 36ff25
Patch 7.3.579 (after 7.3.569)
Karsten Hopp 36ff25
Problem:    Can't compile with Python 2.5.
Karsten Hopp 36ff25
Solution:   Use PyCObject when Capsules are not available.
Karsten Hopp 36ff25
Files:	    src/if_py_both.h, src/if_python.c, src/if_python3.c
Karsten Hopp 36ff25
Karsten Hopp 36ff25
Karsten Hopp 36ff25
*** ../vim-7.3.578/src/if_py_both.h	2012-06-29 16:19:46.000000000 +0200
Karsten Hopp 36ff25
--- src/if_py_both.h	2012-06-29 16:15:29.000000000 +0200
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 56,62 ****
Karsten Hopp 36ff25
      /* name,	    function,		calling,    documentation */
Karsten Hopp 36ff25
      {"write",	    OutputWrite,	1,	    ""},
Karsten Hopp 36ff25
      {"writelines",  OutputWritelines,	1,	    ""},
Karsten Hopp 36ff25
!     {"flush",       OutputFlush,        1,          ""},
Karsten Hopp 36ff25
      { NULL,	    NULL,		0,	    NULL}
Karsten Hopp 36ff25
  };
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
--- 56,62 ----
Karsten Hopp 36ff25
      /* name,	    function,		calling,    documentation */
Karsten Hopp 36ff25
      {"write",	    OutputWrite,	1,	    ""},
Karsten Hopp 36ff25
      {"writelines",  OutputWritelines,	1,	    ""},
Karsten Hopp 36ff25
!     {"flush",	    OutputFlush,	1,	    ""},
Karsten Hopp 36ff25
      { NULL,	    NULL,		0,	    NULL}
Karsten Hopp 36ff25
  };
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 506,513 ****
Karsten Hopp 36ff25
      /* name,	     function,		calling,    documentation */
Karsten Hopp 36ff25
      {"command",	     VimCommand,	1,	    "Execute a Vim ex-mode command" },
Karsten Hopp 36ff25
      {"eval",	     VimEval,		1,	    "Evaluate an expression using Vim evaluator" },
Karsten Hopp 36ff25
!     {"bindeval",     VimEvalPy,         1,          "Like eval(), but returns objects attached to vim ones"},
Karsten Hopp 36ff25
!     {"strwidth",     VimStrwidth,       1,          "Screen string width, counts <Tab> as having width 1"},
Karsten Hopp 36ff25
      { NULL,	     NULL,		0,	    NULL }
Karsten Hopp 36ff25
  };
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
--- 506,513 ----
Karsten Hopp 36ff25
      /* name,	     function,		calling,    documentation */
Karsten Hopp 36ff25
      {"command",	     VimCommand,	1,	    "Execute a Vim ex-mode command" },
Karsten Hopp 36ff25
      {"eval",	     VimEval,		1,	    "Evaluate an expression using Vim evaluator" },
Karsten Hopp 36ff25
!     {"bindeval",     VimEvalPy,		1,	    "Like eval(), but returns objects attached to vim ones"},
Karsten Hopp 36ff25
!     {"strwidth",     VimStrwidth,	1,	    "Screen string width, counts <Tab> as having width 1"},
Karsten Hopp 36ff25
      { NULL,	     NULL,		0,	    NULL }
Karsten Hopp 36ff25
  };
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 2432,2448 ****
Karsten Hopp 36ff25
--- 2432,2463 ----
Karsten Hopp 36ff25
  convert_dl(PyObject *obj, typval_T *tv,
Karsten Hopp 36ff25
  				    pytotvfunc py_to_tv, PyObject *lookupDict)
Karsten Hopp 36ff25
  {
Karsten Hopp 36ff25
+ # ifdef PY_USE_CAPSULE
Karsten Hopp 36ff25
      PyObject	*capsule;
Karsten Hopp 36ff25
+ # else
Karsten Hopp 36ff25
+     PyCObject	*cobject;
Karsten Hopp 36ff25
+ # endif
Karsten Hopp 36ff25
      char	hexBuf[sizeof(void *) * 2 + 3];
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
      sprintf(hexBuf, "%p", obj);
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
+ # ifdef PY_USE_CAPSULE
Karsten Hopp 36ff25
      capsule = PyDict_GetItemString(lookupDict, hexBuf);
Karsten Hopp 36ff25
      if (capsule == NULL)
Karsten Hopp 36ff25
+ # else
Karsten Hopp 36ff25
+     cobject = (PyCObject *)PyDict_GetItemString(lookupDict, hexBuf);
Karsten Hopp 36ff25
+     if (cobject == NULL)
Karsten Hopp 36ff25
+ # endif
Karsten Hopp 36ff25
      {
Karsten Hopp 36ff25
+ # ifdef PY_USE_CAPSULE
Karsten Hopp 36ff25
  	capsule = PyCapsule_New(tv, NULL, NULL);
Karsten Hopp 36ff25
  	PyDict_SetItemString(lookupDict, hexBuf, capsule);
Karsten Hopp 36ff25
  	Py_DECREF(capsule);
Karsten Hopp 36ff25
+ # else
Karsten Hopp 36ff25
+ 	cobject = PyCObject_FromVoidPtr(tv, NULL);
Karsten Hopp 36ff25
+ 	PyDict_SetItemString(lookupDict, hexBuf, cobject);
Karsten Hopp 36ff25
+ 	Py_DECREF(cobject);
Karsten Hopp 36ff25
+ # endif
Karsten Hopp 36ff25
  	if (py_to_tv(obj, tv, lookupDict) == -1)
Karsten Hopp 36ff25
  	{
Karsten Hopp 36ff25
  	    tv->v_type = VAR_UNKNOWN;
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 2458,2464 ****
Karsten Hopp 36ff25
      }
Karsten Hopp 36ff25
      else
Karsten Hopp 36ff25
      {
Karsten Hopp 36ff25
! 	typval_T	*v = PyCapsule_GetPointer(capsule, NULL);
Karsten Hopp 36ff25
  	copy_tv(v, tv);
Karsten Hopp 36ff25
      }
Karsten Hopp 36ff25
      return 0;
Karsten Hopp 36ff25
--- 2473,2485 ----
Karsten Hopp 36ff25
      }
Karsten Hopp 36ff25
      else
Karsten Hopp 36ff25
      {
Karsten Hopp 36ff25
! 	typval_T	*v;
Karsten Hopp 36ff25
! 
Karsten Hopp 36ff25
! # ifdef PY_USE_CAPSULE
Karsten Hopp 36ff25
! 	v = PyCapsule_GetPointer(capsule, NULL);
Karsten Hopp 36ff25
! # else
Karsten Hopp 36ff25
! 	v = PyCObject_AsVoidPtr(cobject);
Karsten Hopp 36ff25
! # endif
Karsten Hopp 36ff25
  	copy_tv(v, tv);
Karsten Hopp 36ff25
      }
Karsten Hopp 36ff25
      return 0;
Karsten Hopp 36ff25
*** ../vim-7.3.578/src/if_python.c	2012-06-29 12:54:32.000000000 +0200
Karsten Hopp 36ff25
--- src/if_python.c	2012-06-29 16:17:44.000000000 +0200
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 71,76 ****
Karsten Hopp 36ff25
--- 71,80 ----
Karsten Hopp 36ff25
  # define PySequenceMethods Py_ssize_t
Karsten Hopp 36ff25
  #endif
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
+ #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
Karsten Hopp 36ff25
+ # define PY_USE_CAPSULE
Karsten Hopp 36ff25
+ #endif
Karsten Hopp 36ff25
+ 
Karsten Hopp 36ff25
  #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000
Karsten Hopp 36ff25
  # define PyInt Py_ssize_t
Karsten Hopp 36ff25
  # define PyInquiry lenfunc
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 220,227 ****
Karsten Hopp 36ff25
  #  define PyObject_Malloc dll_PyObject_Malloc
Karsten Hopp 36ff25
  #  define PyObject_Free dll_PyObject_Free
Karsten Hopp 36ff25
  # endif
Karsten Hopp 36ff25
! # define PyCapsule_New dll_PyCapsule_New
Karsten Hopp 36ff25
! # define PyCapsule_GetPointer dll_PyCapsule_GetPointer
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
  /*
Karsten Hopp 36ff25
   * Pointers for dynamic link
Karsten Hopp 36ff25
--- 224,236 ----
Karsten Hopp 36ff25
  #  define PyObject_Malloc dll_PyObject_Malloc
Karsten Hopp 36ff25
  #  define PyObject_Free dll_PyObject_Free
Karsten Hopp 36ff25
  # endif
Karsten Hopp 36ff25
! # ifdef PY_USE_CAPSULE
Karsten Hopp 36ff25
! #  define PyCapsule_New dll_PyCapsule_New
Karsten Hopp 36ff25
! #  define PyCapsule_GetPointer dll_PyCapsule_GetPointer
Karsten Hopp 36ff25
! # else
Karsten Hopp 36ff25
! #  define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr
Karsten Hopp 36ff25
! #  define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr
Karsten Hopp 36ff25
! # endif
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
  /*
Karsten Hopp 36ff25
   * Pointers for dynamic link
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 309,316 ****
Karsten Hopp 36ff25
--- 318,330 ----
Karsten Hopp 36ff25
  static void* (*dll_PyObject_Malloc)(size_t);
Karsten Hopp 36ff25
  static void (*dll_PyObject_Free)(void*);
Karsten Hopp 36ff25
  # endif
Karsten Hopp 36ff25
+ # ifdef PY_USE_CAPSULE
Karsten Hopp 36ff25
  static PyObject* (*dll_PyCapsule_New)(void *, char *, PyCapsule_Destructor);
Karsten Hopp 36ff25
  static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *);
Karsten Hopp 36ff25
+ # else
Karsten Hopp 36ff25
+ static PyCObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *));
Karsten Hopp 36ff25
+ static void* (*dll_PyCObject_AsVoidPtr)(PyCObject *);
Karsten Hopp 36ff25
+ # endif
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
  static HINSTANCE hinstPython = 0; /* Instance of python.dll */
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 403,409 ****
Karsten Hopp 36ff25
      {"PyType_Ready", (PYTHON_PROC*)&dll_PyType_Ready},
Karsten Hopp 36ff25
      {"Py_BuildValue", (PYTHON_PROC*)&dll_Py_BuildValue},
Karsten Hopp 36ff25
      {"Py_FindMethod", (PYTHON_PROC*)&dll_Py_FindMethod},
Karsten Hopp 36ff25
! # if (PY_VERSION_HEX >= 0x02050000) && SIZEOF_SIZE_T != SIZEOF_INT
Karsten Hopp 36ff25
      {"Py_InitModule4_64", (PYTHON_PROC*)&dll_Py_InitModule4},
Karsten Hopp 36ff25
  # else
Karsten Hopp 36ff25
      {"Py_InitModule4", (PYTHON_PROC*)&dll_Py_InitModule4},
Karsten Hopp 36ff25
--- 417,424 ----
Karsten Hopp 36ff25
      {"PyType_Ready", (PYTHON_PROC*)&dll_PyType_Ready},
Karsten Hopp 36ff25
      {"Py_BuildValue", (PYTHON_PROC*)&dll_Py_BuildValue},
Karsten Hopp 36ff25
      {"Py_FindMethod", (PYTHON_PROC*)&dll_Py_FindMethod},
Karsten Hopp 36ff25
! # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 \
Karsten Hopp 36ff25
! 	&& SIZEOF_SIZE_T != SIZEOF_INT
Karsten Hopp 36ff25
      {"Py_InitModule4_64", (PYTHON_PROC*)&dll_Py_InitModule4},
Karsten Hopp 36ff25
  # else
Karsten Hopp 36ff25
      {"Py_InitModule4", (PYTHON_PROC*)&dll_Py_InitModule4},
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 424,431 ****
Karsten Hopp 36ff25
--- 439,451 ----
Karsten Hopp 36ff25
      {"PyObject_Malloc", (PYTHON_PROC*)&dll_PyObject_Malloc},
Karsten Hopp 36ff25
      {"PyObject_Free", (PYTHON_PROC*)&dll_PyObject_Free},
Karsten Hopp 36ff25
  # endif
Karsten Hopp 36ff25
+ # ifdef PY_USE_CAPSULE
Karsten Hopp 36ff25
      {"PyCapsule_New", (PYTHON_PROC*)&dll_PyCapsule_New},
Karsten Hopp 36ff25
      {"PyCapsule_GetPointer", (PYTHON_PROC*)&dll_PyCapsule_GetPointer},
Karsten Hopp 36ff25
+ # else
Karsten Hopp 36ff25
+     {"PyCObject_FromVoidPtr", (PYTHON_PROC*)&dll_PyCObject_FromVoidPtr},
Karsten Hopp 36ff25
+     {"PyCObject_AsVoidPtr", (PYTHON_PROC*)&dll_PyCObject_AsVoidPtr},
Karsten Hopp 36ff25
+ # endif
Karsten Hopp 36ff25
      {"", NULL},
Karsten Hopp 36ff25
  };
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
*** ../vim-7.3.578/src/if_python3.c	2012-06-29 12:54:32.000000000 +0200
Karsten Hopp 36ff25
--- src/if_python3.c	2012-06-29 16:16:54.000000000 +0200
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 75,80 ****
Karsten Hopp 36ff25
--- 75,83 ----
Karsten Hopp 36ff25
  # define CODEC_ERROR_HANDLER NULL
Karsten Hopp 36ff25
  #endif
Karsten Hopp 36ff25
  
Karsten Hopp 36ff25
+ /* Python 3 does not support CObjects, always use Capsules */
Karsten Hopp 36ff25
+ #define PY_USE_CAPSULE
Karsten Hopp 36ff25
+ 
Karsten Hopp 36ff25
  #define PyInt Py_ssize_t
Karsten Hopp 36ff25
  #define PyString_Check(obj) PyUnicode_Check(obj)
Karsten Hopp 36ff25
  #define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER)
Karsten Hopp 36ff25
*** ../vim-7.3.578/src/version.c	2012-06-29 16:19:46.000000000 +0200
Karsten Hopp 36ff25
--- src/version.c	2012-06-29 16:21:25.000000000 +0200
Karsten Hopp 36ff25
***************
Karsten Hopp 36ff25
*** 716,717 ****
Karsten Hopp 36ff25
--- 716,719 ----
Karsten Hopp 36ff25
  {   /* Add new patch number below this line */
Karsten Hopp 36ff25
+ /**/
Karsten Hopp 36ff25
+     579,
Karsten Hopp 36ff25
  /**/
Karsten Hopp 36ff25
Karsten Hopp 36ff25
-- 
Karsten Hopp 36ff25
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 36ff25
78. You find yourself dialing IP numbers on the phone.
Karsten Hopp 36ff25
Karsten Hopp 36ff25
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 36ff25
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 36ff25
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 36ff25
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///