Karsten Hopp 81c146
To: vim_dev@googlegroups.com
Karsten Hopp 81c146
Subject: Patch 7.3.1069
Karsten Hopp 81c146
Fcc: outbox
Karsten Hopp 81c146
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 81c146
Mime-Version: 1.0
Karsten Hopp 81c146
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 81c146
Content-Transfer-Encoding: 8bit
Karsten Hopp 81c146
------------
Karsten Hopp 81c146
Karsten Hopp 81c146
Patch 7.3.1069
Karsten Hopp 81c146
Problem:    Python: memory leaks.
Karsten Hopp 81c146
Solution:   Python patch 28: Purge out DICTKEY_CHECK_EMPTY macros. (ZyX)
Karsten Hopp 81c146
Files:	    src/if_py_both.h
Karsten Hopp 81c146
Karsten Hopp 81c146
Karsten Hopp 81c146
*** ../vim-7.3.1068/src/if_py_both.h	2013-05-30 13:37:23.000000000 +0200
Karsten Hopp 81c146
--- src/if_py_both.h	2013-05-30 14:50:11.000000000 +0200
Karsten Hopp 81c146
***************
Karsten Hopp 81c146
*** 32,46 ****
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  #define DICTKEY_DECL \
Karsten Hopp 81c146
      PyObject	*dictkey_todecref = NULL;
Karsten Hopp 81c146
- #define DICTKEY_CHECK_EMPTY(err) \
Karsten Hopp 81c146
-     if (*key == NUL) \
Karsten Hopp 81c146
-     { \
Karsten Hopp 81c146
- 	PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
Karsten Hopp 81c146
- 	return err; \
Karsten Hopp 81c146
-     }
Karsten Hopp 81c146
- #define DICTKEY_SET_KEY (key = StringToChars(keyObject, &dictkey_todecref))
Karsten Hopp 81c146
  #define DICTKEY_GET(err, decref) \
Karsten Hopp 81c146
!     if (!DICTKEY_SET_KEY) \
Karsten Hopp 81c146
      { \
Karsten Hopp 81c146
  	if (decref) \
Karsten Hopp 81c146
  	{ \
Karsten Hopp 81c146
--- 32,39 ----
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  #define DICTKEY_DECL \
Karsten Hopp 81c146
      PyObject	*dictkey_todecref = NULL;
Karsten Hopp 81c146
  #define DICTKEY_GET(err, decref) \
Karsten Hopp 81c146
!     if (!(key = StringToChars(keyObject, &dictkey_todecref))) \
Karsten Hopp 81c146
      { \
Karsten Hopp 81c146
  	if (decref) \
Karsten Hopp 81c146
  	{ \
Karsten Hopp 81c146
***************
Karsten Hopp 81c146
*** 50,56 ****
Karsten Hopp 81c146
      } \
Karsten Hopp 81c146
      if (decref && !dictkey_todecref) \
Karsten Hopp 81c146
  	dictkey_todecref = keyObject; \
Karsten Hopp 81c146
!     DICTKEY_CHECK_EMPTY(err)
Karsten Hopp 81c146
  #define DICTKEY_UNREF \
Karsten Hopp 81c146
      Py_XDECREF(dictkey_todecref);
Karsten Hopp 81c146
  
Karsten Hopp 81c146
--- 43,53 ----
Karsten Hopp 81c146
      } \
Karsten Hopp 81c146
      if (decref && !dictkey_todecref) \
Karsten Hopp 81c146
  	dictkey_todecref = keyObject; \
Karsten Hopp 81c146
!     if (*key == NUL) \
Karsten Hopp 81c146
!     { \
Karsten Hopp 81c146
! 	PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
Karsten Hopp 81c146
! 	return err; \
Karsten Hopp 81c146
!     }
Karsten Hopp 81c146
  #define DICTKEY_UNREF \
Karsten Hopp 81c146
      Py_XDECREF(dictkey_todecref);
Karsten Hopp 81c146
  
Karsten Hopp 81c146
***************
Karsten Hopp 81c146
*** 4551,4557 ****
Karsten Hopp 81c146
  
Karsten Hopp 81c146
      while (PyDict_Next(obj, &iter, &keyObject, &valObject))
Karsten Hopp 81c146
      {
Karsten Hopp 81c146
! 	DICTKEY_DECL
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	if (keyObject == NULL || valObject == NULL)
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
--- 4548,4554 ----
Karsten Hopp 81c146
  
Karsten Hopp 81c146
      while (PyDict_Next(obj, &iter, &keyObject, &valObject))
Karsten Hopp 81c146
      {
Karsten Hopp 81c146
! 	PyObject	*todecref = NULL;
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	if (keyObject == NULL || valObject == NULL)
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
***************
Karsten Hopp 81c146
*** 4559,4574 ****
Karsten Hopp 81c146
  	    return -1;
Karsten Hopp 81c146
  	}
Karsten Hopp 81c146
  
Karsten Hopp 81c146
! 	if (!DICTKEY_SET_KEY)
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
  	    dict_unref(dict);
Karsten Hopp 81c146
  	    return -1;
Karsten Hopp 81c146
  	}
Karsten Hopp 81c146
- 	DICTKEY_CHECK_EMPTY(-1)
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	di = dictitem_alloc(key);
Karsten Hopp 81c146
  
Karsten Hopp 81c146
! 	DICTKEY_UNREF
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	if (di == NULL)
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
--- 4556,4576 ----
Karsten Hopp 81c146
  	    return -1;
Karsten Hopp 81c146
  	}
Karsten Hopp 81c146
  
Karsten Hopp 81c146
! 	if (!(key = StringToChars(keyObject, &todecref)))
Karsten Hopp 81c146
! 	{
Karsten Hopp 81c146
! 	    dict_unref(dict);
Karsten Hopp 81c146
! 	    return -1;
Karsten Hopp 81c146
! 	}
Karsten Hopp 81c146
! 	if (*key == NUL)
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
  	    dict_unref(dict);
Karsten Hopp 81c146
+ 	    Py_XDECREF(todecref);
Karsten Hopp 81c146
  	    return -1;
Karsten Hopp 81c146
  	}
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	di = dictitem_alloc(key);
Karsten Hopp 81c146
  
Karsten Hopp 81c146
! 	Py_XDECREF(todecref);
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	if (di == NULL)
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
***************
Karsten Hopp 81c146
*** 4632,4662 ****
Karsten Hopp 81c146
  
Karsten Hopp 81c146
      while ((keyObject = PyIter_Next(iterator)))
Karsten Hopp 81c146
      {
Karsten Hopp 81c146
! 	DICTKEY_DECL
Karsten Hopp 81c146
  
Karsten Hopp 81c146
! 	if (!DICTKEY_SET_KEY)
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
  	    Py_DECREF(iterator);
Karsten Hopp 81c146
  	    dict_unref(dict);
Karsten Hopp 81c146
- 	    DICTKEY_UNREF
Karsten Hopp 81c146
  	    return -1;
Karsten Hopp 81c146
  	}
Karsten Hopp 81c146
! 	DICTKEY_CHECK_EMPTY(-1)
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	if (!(valObject = PyObject_GetItem(obj, keyObject)))
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
  	    Py_DECREF(keyObject);
Karsten Hopp 81c146
  	    Py_DECREF(iterator);
Karsten Hopp 81c146
  	    dict_unref(dict);
Karsten Hopp 81c146
- 	    DICTKEY_UNREF
Karsten Hopp 81c146
  	    return -1;
Karsten Hopp 81c146
  	}
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	di = dictitem_alloc(key);
Karsten Hopp 81c146
  
Karsten Hopp 81c146
- 	DICTKEY_UNREF
Karsten Hopp 81c146
- 
Karsten Hopp 81c146
  	Py_DECREF(keyObject);
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	if (di == NULL)
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
--- 4634,4670 ----
Karsten Hopp 81c146
  
Karsten Hopp 81c146
      while ((keyObject = PyIter_Next(iterator)))
Karsten Hopp 81c146
      {
Karsten Hopp 81c146
! 	PyObject	*todecref;
Karsten Hopp 81c146
  
Karsten Hopp 81c146
! 	if (!(key = StringToChars(keyObject, &todecref)))
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
+ 	    Py_DECREF(keyObject);
Karsten Hopp 81c146
  	    Py_DECREF(iterator);
Karsten Hopp 81c146
  	    dict_unref(dict);
Karsten Hopp 81c146
  	    return -1;
Karsten Hopp 81c146
  	}
Karsten Hopp 81c146
! 	if (*key == NUL)
Karsten Hopp 81c146
! 	{
Karsten Hopp 81c146
! 	    Py_DECREF(keyObject);
Karsten Hopp 81c146
! 	    Py_DECREF(iterator);
Karsten Hopp 81c146
! 	    Py_XDECREF(todecref);
Karsten Hopp 81c146
! 	    dict_unref(dict);
Karsten Hopp 81c146
! 	    return -1;
Karsten Hopp 81c146
! 	}
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	if (!(valObject = PyObject_GetItem(obj, keyObject)))
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
  	    Py_DECREF(keyObject);
Karsten Hopp 81c146
  	    Py_DECREF(iterator);
Karsten Hopp 81c146
+ 	    Py_XDECREF(todecref);
Karsten Hopp 81c146
  	    dict_unref(dict);
Karsten Hopp 81c146
  	    return -1;
Karsten Hopp 81c146
  	}
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	di = dictitem_alloc(key);
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	Py_DECREF(keyObject);
Karsten Hopp 81c146
+ 	Py_XDECREF(todecref);
Karsten Hopp 81c146
  
Karsten Hopp 81c146
  	if (di == NULL)
Karsten Hopp 81c146
  	{
Karsten Hopp 81c146
*** ../vim-7.3.1068/src/version.c	2013-05-30 13:37:23.000000000 +0200
Karsten Hopp 81c146
--- src/version.c	2013-05-30 13:38:46.000000000 +0200
Karsten Hopp 81c146
***************
Karsten Hopp 81c146
*** 730,731 ****
Karsten Hopp 81c146
--- 730,733 ----
Karsten Hopp 81c146
  {   /* Add new patch number below this line */
Karsten Hopp 81c146
+ /**/
Karsten Hopp 81c146
+     1069,
Karsten Hopp 81c146
  /**/
Karsten Hopp 81c146
Karsten Hopp 81c146
-- 
Karsten Hopp 81c146
How To Keep A Healthy Level Of Insanity:
Karsten Hopp 81c146
11. Specify that your drive-through order is "to go".
Karsten Hopp 81c146
Karsten Hopp 81c146
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 81c146
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 81c146
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 81c146
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///