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.1162 < prev    next >
Encoding:
Internet Message Format  |  2013-06-09  |  5.2 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.1162
  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.1162
  11. Problem:    Python: Memory leaks
  12. Solution:   Add more Py_DECREF(). (ZyX)
  13. Files:        src/if_py_both.h, src/if_python.c
  14.  
  15.  
  16. *** ../vim-7.3.1161/src/if_py_both.h    2013-06-10 20:38:58.000000000 +0200
  17. --- src/if_py_both.h    2013-06-10 20:43:01.000000000 +0200
  18. ***************
  19. *** 5354,5359 ****
  20. --- 5354,5360 ----
  21.   {
  22.       int        i;
  23.       PyObject    *other_module;
  24. +     PyObject    *attr;
  25.   
  26.       for (i = 0; i < (int)(sizeof(numeric_constants)
  27.                          / sizeof(struct numeric_constant));
  28. ***************
  29. *** 5392,5405 ****
  30.       if (!(py_chdir = PyObject_GetAttrString(other_module, "chdir")))
  31.       return -1;
  32.       ADD_OBJECT(m, "_chdir", py_chdir);
  33. !     if (PyObject_SetAttrString(other_module, "chdir", get_attr(m, "chdir")))
  34.       return -1;
  35.   
  36.       if ((py_fchdir = PyObject_GetAttrString(other_module, "fchdir")))
  37.       {
  38.       ADD_OBJECT(m, "_fchdir", py_fchdir);
  39. !     if (PyObject_SetAttrString(other_module,"fchdir",get_attr(m,"fchdir")))
  40.           return -1;
  41.       }
  42.       else
  43.       PyErr_Clear();
  44. --- 5393,5418 ----
  45.       if (!(py_chdir = PyObject_GetAttrString(other_module, "chdir")))
  46.       return -1;
  47.       ADD_OBJECT(m, "_chdir", py_chdir);
  48. !     if (!(attr = get_attr(m, "chdir")))
  49.       return -1;
  50. +     if (PyObject_SetAttrString(other_module, "chdir", attr))
  51. +     {
  52. +     Py_DECREF(attr);
  53. +     return -1;
  54. +     }
  55. +     Py_DECREF(attr);
  56.   
  57.       if ((py_fchdir = PyObject_GetAttrString(other_module, "fchdir")))
  58.       {
  59.       ADD_OBJECT(m, "_fchdir", py_fchdir);
  60. !     if (!(attr = get_attr(m, "fchdir")))
  61. !         return -1;
  62. !     if (PyObject_SetAttrString(other_module, "fchdir", attr))
  63. !     {
  64. !         Py_DECREF(attr);
  65.           return -1;
  66. +     }
  67. +     Py_DECREF(attr);
  68.       }
  69.       else
  70.       PyErr_Clear();
  71. *** ../vim-7.3.1161/src/if_python.c    2013-06-10 18:36:20.000000000 +0200
  72. --- src/if_python.c    2013-06-10 20:42:44.000000000 +0200
  73. ***************
  74. *** 210,215 ****
  75. --- 210,216 ----
  76.   # define PyMapping_Check dll_PyMapping_Check
  77.   # define PyIter_Next dll_PyIter_Next
  78.   # define PyModule_GetDict dll_PyModule_GetDict
  79. + # define PyModule_AddObject dll_PyModule_AddObject
  80.   # define PyRun_SimpleString dll_PyRun_SimpleString
  81.   # define PyRun_String dll_PyRun_String
  82.   # define PyObject_GetAttrString dll_PyObject_GetAttrString
  83. ***************
  84. *** 344,349 ****
  85. --- 345,351 ----
  86.   static int (*dll_PyMapping_Check)(PyObject *);
  87.   static PyObject* (*dll_PyIter_Next)(PyObject *);
  88.   static PyObject*(*dll_PyModule_GetDict)(PyObject *);
  89. + static int(*dll_PyModule_AddObject)(PyObject *, const char *, PyObject *);
  90.   static int(*dll_PyRun_SimpleString)(char *);
  91.   static PyObject *(*dll_PyRun_String)(char *, int, PyObject *, PyObject *);
  92.   static PyObject* (*dll_PyObject_GetAttrString)(PyObject *, const char *);
  93. ***************
  94. *** 509,514 ****
  95. --- 511,517 ----
  96.       {"PyMapping_Check", (PYTHON_PROC*)&dll_PyMapping_Check},
  97.       {"PyIter_Next", (PYTHON_PROC*)&dll_PyIter_Next},
  98.       {"PyModule_GetDict", (PYTHON_PROC*)&dll_PyModule_GetDict},
  99. +     {"PyModule_AddObject", (PYTHON_PROC*)&dll_PyModule_AddObject},
  100.       {"PyRun_SimpleString", (PYTHON_PROC*)&dll_PyRun_SimpleString},
  101.       {"PyRun_String", (PYTHON_PROC*)&dll_PyRun_String},
  102.       {"PyObject_GetAttrString", (PYTHON_PROC*)&dll_PyObject_GetAttrString},
  103. ***************
  104. *** 1357,1375 ****
  105.   #endif
  106.   
  107.       static int
  108. - add_object(PyObject *dict, const char *name, PyObject *object)
  109. - {
  110. -     if (PyDict_SetItemString(dict, (char *) name, object))
  111. -     return -1;
  112. -     Py_DECREF(object);
  113. -     return 0;
  114. - }
  115. -     static int
  116.   PythonMod_Init(void)
  117.   {
  118.       PyObject *mod;
  119. -     PyObject *dict;
  120.   
  121.       /* The special value is removed from sys.path in Python_Init(). */
  122.       static char *(argv[2]) = {"/must>not&exist/foo", NULL};
  123. --- 1360,1368 ----
  124. ***************
  125. *** 1382,1390 ****
  126.   
  127.       mod = Py_InitModule4("vim", VimMethods, (char *)NULL, (PyObject *)NULL,
  128.                   PYTHON_API_VERSION);
  129. -     dict = PyModule_GetDict(mod);
  130.   
  131. !     return populate_module(dict, add_object, PyDict_GetItemString);
  132.   }
  133.   
  134.   /*************************************************************************
  135. --- 1375,1382 ----
  136.   
  137.       mod = Py_InitModule4("vim", VimMethods, (char *)NULL, (PyObject *)NULL,
  138.                   PYTHON_API_VERSION);
  139.   
  140. !     return populate_module(mod, PyModule_AddObject, PyObject_GetAttrString);
  141.   }
  142.   
  143.   /*************************************************************************
  144. *** ../vim-7.3.1161/src/version.c    2013-06-10 20:38:58.000000000 +0200
  145. --- src/version.c    2013-06-10 20:40:25.000000000 +0200
  146. ***************
  147. *** 730,731 ****
  148. --- 730,733 ----
  149.   {   /* Add new patch number below this line */
  150. + /**/
  151. +     1162,
  152.   /**/
  153.  
  154. -- 
  155. hundred-and-one symptoms of being an internet addict:
  156. 137. You decide to stay in college for an additional year or two,
  157.      just so you can have the free Internet access.
  158.  
  159.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  160. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  161. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  162.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  163.