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.1077 < prev    next >
Encoding:
Internet Message Format  |  2013-05-29  |  9.8 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.1077
  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.1077
  11. Problem:    Python: Allocating dict the wrong way, causing a crash.
  12. Solution:   Use py_dict_alloc(). Fix some exception problems. (ZyX)
  13. Files:        src/if_py_both.h
  14.  
  15.  
  16. *** ../vim-7.3.1076/src/if_py_both.h    2013-05-30 19:01:20.000000000 +0200
  17. --- src/if_py_both.h    2013-05-30 21:53:00.000000000 +0200
  18. ***************
  19. *** 26,56 ****
  20.   
  21.   #define PyErr_SetVim(str) PyErr_SetString(VimError, str)
  22.   
  23.   #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
  24.   #define INVALID_WINDOW_VALUE ((win_T *)(-1))
  25.   #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1))
  26.   
  27. - #define DICTKEY_DECL \
  28. -     PyObject    *dictkey_todecref = NULL;
  29. - #define DICTKEY_GET(err, decref) \
  30. -     if (!(key = StringToChars(keyObject, &dictkey_todecref))) \
  31. -     { \
  32. -     if (decref) \
  33. -     { \
  34. -         Py_DECREF(keyObject); \
  35. -     } \
  36. -     return err; \
  37. -     } \
  38. -     if (decref && !dictkey_todecref) \
  39. -     dictkey_todecref = keyObject; \
  40. -     if (*key == NUL) \
  41. -     { \
  42. -     PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
  43. -     return err; \
  44. -     }
  45. - #define DICTKEY_UNREF \
  46. -     Py_XDECREF(dictkey_todecref);
  47.   typedef void (*rangeinitializer)(void *);
  48.   typedef void (*runner)(const char *, void *
  49.   #ifdef PY_CAN_RECURSE
  50. --- 26,38 ----
  51.   
  52.   #define PyErr_SetVim(str) PyErr_SetString(VimError, str)
  53.   
  54. + #define RAISE_NO_EMPTY_KEYS PyErr_SetString(PyExc_ValueError, \
  55. +                         _("empty keys are not allowed"))
  56.   #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
  57.   #define INVALID_WINDOW_VALUE ((win_T *)(-1))
  58.   #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1))
  59.   
  60.   typedef void (*rangeinitializer)(void *);
  61.   typedef void (*runner)(const char *, void *
  62.   #ifdef PY_CAN_RECURSE
  63. ***************
  64. *** 1016,1023 ****
  65.       dictitem_T    *di;
  66.       dict_T    *dict = self->dict;
  67.       hashitem_T    *hi;
  68. !     DICTKEY_DECL
  69.   
  70.       if (flags & DICT_FLAG_HAS_DEFAULT)
  71.       {
  72. --- 998,1004 ----
  73.       dictitem_T    *di;
  74.       dict_T    *dict = self->dict;
  75.       hashitem_T    *hi;
  76. !     PyObject    *todecref;
  77.   
  78.       if (flags & DICT_FLAG_HAS_DEFAULT)
  79.       {
  80. ***************
  81. *** 1030,1040 ****
  82.       if (flags & DICT_FLAG_RETURN_BOOL)
  83.       defObject = Py_False;
  84.   
  85. !     DICTKEY_GET(NULL, 0)
  86.   
  87.       hi = hash_find(&dict->dv_hashtab, key);
  88.   
  89. !     DICTKEY_UNREF
  90.   
  91.       if (HASHITEM_EMPTY(hi))
  92.       {
  93. --- 1011,1028 ----
  94.       if (flags & DICT_FLAG_RETURN_BOOL)
  95.       defObject = Py_False;
  96.   
  97. !     if (!(key = StringToChars(keyObject, &todecref)))
  98. !     return NULL;
  99. !     if (*key == NUL)
  100. !     {
  101. !     RAISE_NO_EMPTY_KEYS;
  102. !     return NULL;
  103. !     }
  104.   
  105.       hi = hash_find(&dict->dv_hashtab, key);
  106.   
  107. !     Py_XDECREF(todecref);
  108.   
  109.       if (HASHITEM_EMPTY(hi))
  110.       {
  111. ***************
  112. *** 1173,1179 ****
  113.       typval_T    tv;
  114.       dict_T    *dict = self->dict;
  115.       dictitem_T    *di;
  116. !     DICTKEY_DECL
  117.   
  118.       if (dict->dv_lock)
  119.       {
  120. --- 1161,1167 ----
  121.       typval_T    tv;
  122.       dict_T    *dict = self->dict;
  123.       dictitem_T    *di;
  124. !     PyObject    *todecref;
  125.   
  126.       if (dict->dv_lock)
  127.       {
  128. ***************
  129. *** 1181,1187 ****
  130.       return -1;
  131.       }
  132.   
  133. !     DICTKEY_GET(-1, 0)
  134.   
  135.       di = dict_find(dict, key, -1);
  136.   
  137. --- 1169,1181 ----
  138.       return -1;
  139.       }
  140.   
  141. !     if (!(key = StringToChars(keyObject, &todecref)))
  142. !     return -1;
  143. !     if (*key == NUL)
  144. !     {
  145. !     RAISE_NO_EMPTY_KEYS;
  146. !     return -1;
  147. !     }
  148.   
  149.       di = dict_find(dict, key, -1);
  150.   
  151. ***************
  152. *** 1191,1197 ****
  153.   
  154.       if (di == NULL)
  155.       {
  156. !         DICTKEY_UNREF
  157.           PyErr_SetObject(PyExc_KeyError, keyObject);
  158.           return -1;
  159.       }
  160. --- 1185,1191 ----
  161.   
  162.       if (di == NULL)
  163.       {
  164. !         Py_XDECREF(todecref);
  165.           PyErr_SetObject(PyExc_KeyError, keyObject);
  166.           return -1;
  167.       }
  168. ***************
  169. *** 1208,1213 ****
  170. --- 1202,1208 ----
  171.       {
  172.       if (!(di = dictitem_alloc(key)))
  173.       {
  174. +         Py_XDECREF(todecref);
  175.           PyErr_NoMemory();
  176.           return -1;
  177.       }
  178. ***************
  179. *** 1216,1222 ****
  180.   
  181.       if (dict_add(dict, di) == FAIL)
  182.       {
  183. !         DICTKEY_UNREF
  184.           vim_free(di);
  185.           dictitem_free(di);
  186.           PyErr_SetVim(_("failed to add key to dictionary"));
  187. --- 1211,1217 ----
  188.   
  189.       if (dict_add(dict, di) == FAIL)
  190.       {
  191. !         Py_XDECREF(todecref);
  192.           vim_free(di);
  193.           dictitem_free(di);
  194.           PyErr_SetVim(_("failed to add key to dictionary"));
  195. ***************
  196. *** 1226,1232 ****
  197.       else
  198.       clear_tv(&di->di_tv);
  199.   
  200. !     DICTKEY_UNREF
  201.   
  202.       copy_tv(&tv, &di->di_tv);
  203.       clear_tv(&tv);
  204. --- 1221,1227 ----
  205.       else
  206.       clear_tv(&di->di_tv);
  207.   
  208. !     Py_XDECREF(todecref);
  209.   
  210.       copy_tv(&tv, &di->di_tv);
  211.       clear_tv(&tv);
  212. ***************
  213. *** 2202,2218 ****
  214.       int        flags;
  215.       long    numval;
  216.       char_u    *stringval;
  217. !     DICTKEY_DECL
  218.   
  219.       if (self->Check(self->from))
  220.       return NULL;
  221.   
  222. !     DICTKEY_GET(NULL, 0)
  223.   
  224.       flags = get_option_value_strict(key, &numval, &stringval,
  225.                       self->opt_type, self->from);
  226.   
  227. !     DICTKEY_UNREF
  228.   
  229.       if (flags == 0)
  230.       {
  231. --- 2197,2219 ----
  232.       int        flags;
  233.       long    numval;
  234.       char_u    *stringval;
  235. !     PyObject    *todecref;
  236.   
  237.       if (self->Check(self->from))
  238.       return NULL;
  239.   
  240. !     if (!(key = StringToChars(keyObject, &todecref)))
  241. !     return NULL;
  242. !     if (*key == NUL)
  243. !     {
  244. !     RAISE_NO_EMPTY_KEYS;
  245. !     return NULL;
  246. !     }
  247.   
  248.       flags = get_option_value_strict(key, &numval, &stringval,
  249.                       self->opt_type, self->from);
  250.   
  251. !     Py_XDECREF(todecref);
  252.   
  253.       if (flags == 0)
  254.       {
  255. ***************
  256. *** 2329,2340 ****
  257.       int        flags;
  258.       int        opt_flags;
  259.       int        r = 0;
  260. !     DICTKEY_DECL
  261.   
  262.       if (self->Check(self->from))
  263.       return -1;
  264.   
  265. !     DICTKEY_GET(-1, 0)
  266.   
  267.       flags = get_option_value_strict(key, NULL, NULL,
  268.                       self->opt_type, self->from);
  269. --- 2330,2347 ----
  270.       int        flags;
  271.       int        opt_flags;
  272.       int        r = 0;
  273. !     PyObject    *todecref;
  274.   
  275.       if (self->Check(self->from))
  276.       return -1;
  277.   
  278. !     if (!(key = StringToChars(keyObject, &todecref)))
  279. !     return -1;
  280. !     if (*key == NUL)
  281. !     {
  282. !     RAISE_NO_EMPTY_KEYS;
  283. !     return -1;
  284. !     }
  285.   
  286.       flags = get_option_value_strict(key, NULL, NULL,
  287.                       self->opt_type, self->from);
  288. ***************
  289. *** 2342,2348 ****
  290.       if (flags == 0)
  291.       {
  292.       PyErr_SetObject(PyExc_KeyError, keyObject);
  293. !     DICTKEY_UNREF
  294.       return -1;
  295.       }
  296.   
  297. --- 2349,2355 ----
  298.       if (flags == 0)
  299.       {
  300.       PyErr_SetObject(PyExc_KeyError, keyObject);
  301. !     Py_XDECREF(todecref);
  302.       return -1;
  303.       }
  304.   
  305. ***************
  306. *** 2352,2371 ****
  307.       {
  308.           PyErr_SetString(PyExc_ValueError,
  309.               _("unable to unset global option"));
  310. !         DICTKEY_UNREF
  311.           return -1;
  312.       }
  313.       else if (!(flags & SOPT_GLOBAL))
  314.       {
  315.           PyErr_SetString(PyExc_ValueError, _("unable to unset option "
  316.                           "without global value"));
  317. !         DICTKEY_UNREF
  318.           return -1;
  319.       }
  320.       else
  321.       {
  322.           unset_global_local_option(key, self->from);
  323. !         DICTKEY_UNREF
  324.           return 0;
  325.       }
  326.       }
  327. --- 2359,2378 ----
  328.       {
  329.           PyErr_SetString(PyExc_ValueError,
  330.               _("unable to unset global option"));
  331. !         Py_XDECREF(todecref);
  332.           return -1;
  333.       }
  334.       else if (!(flags & SOPT_GLOBAL))
  335.       {
  336.           PyErr_SetString(PyExc_ValueError, _("unable to unset option "
  337.                           "without global value"));
  338. !         Py_XDECREF(todecref);
  339.           return -1;
  340.       }
  341.       else
  342.       {
  343.           unset_global_local_option(key, self->from);
  344. !         Py_XDECREF(todecref);
  345.           return 0;
  346.       }
  347.       }
  348. ***************
  349. *** 2396,2402 ****
  350.       else
  351.       {
  352.           PyErr_SetString(PyExc_TypeError, _("object must be integer"));
  353. !         DICTKEY_UNREF
  354.           return -1;
  355.       }
  356.   
  357. --- 2403,2409 ----
  358.       else
  359.       {
  360.           PyErr_SetString(PyExc_TypeError, _("object must be integer"));
  361. !         Py_XDECREF(todecref);
  362.           return -1;
  363.       }
  364.   
  365. ***************
  366. *** 2418,2424 ****
  367.           r = -1;
  368.       }
  369.   
  370. !     DICTKEY_UNREF
  371.   
  372.       return r;
  373.   }
  374. --- 2425,2431 ----
  375.           r = -1;
  376.       }
  377.   
  378. !     Py_XDECREF(todecref);
  379.   
  380.       return r;
  381.   }
  382. ***************
  383. *** 4528,4534 ****
  384.       PyObject    *valObject;
  385.       Py_ssize_t    iter = 0;
  386.   
  387. !     if (!(dict = dict_alloc()))
  388.       return -1;
  389.   
  390.       tv->v_type = VAR_DICT;
  391. --- 4535,4541 ----
  392.       PyObject    *valObject;
  393.       Py_ssize_t    iter = 0;
  394.   
  395. !     if (!(dict = py_dict_alloc()))
  396.       return -1;
  397.   
  398.       tv->v_type = VAR_DICT;
  399. ***************
  400. *** 4553,4558 ****
  401. --- 4560,4566 ----
  402.       {
  403.           dict_unref(dict);
  404.           Py_XDECREF(todecref);
  405. +         RAISE_NO_EMPTY_KEYS;
  406.           return -1;
  407.       }
  408.   
  409. ***************
  410. *** 4600,4606 ****
  411.       PyObject    *keyObject;
  412.       PyObject    *valObject;
  413.   
  414. !     if (!(dict = dict_alloc()))
  415.       return -1;
  416.   
  417.       tv->v_type = VAR_DICT;
  418. --- 4608,4614 ----
  419.       PyObject    *keyObject;
  420.       PyObject    *valObject;
  421.   
  422. !     if (!(dict = py_dict_alloc()))
  423.       return -1;
  424.   
  425.       tv->v_type = VAR_DICT;
  426. ***************
  427. *** 4637,4642 ****
  428. --- 4645,4651 ----
  429.           Py_DECREF(iterator);
  430.           Py_XDECREF(todecref);
  431.           dict_unref(dict);
  432. +         RAISE_NO_EMPTY_KEYS;
  433.           return -1;
  434.       }
  435.   
  436. *** ../vim-7.3.1076/src/version.c    2013-05-30 21:42:09.000000000 +0200
  437. --- src/version.c    2013-05-30 21:49:50.000000000 +0200
  438. ***************
  439. *** 730,731 ****
  440. --- 730,733 ----
  441.   {   /* Add new patch number below this line */
  442. + /**/
  443. +     1077,
  444.   /**/
  445.  
  446. -- 
  447. The History of every major Galactic Civilization tends to pass through
  448. three distinct and recognizable phases, those of Survival, Inquiry and
  449. Sophistication, otherwise known as the How, Why and Where phases.
  450. For instance, the first phase is characterized by the question 'How can
  451. we eat?' the second by the question 'Why do we eat?' and the third by
  452. the question 'Where shall we have lunch?'
  453.         -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"
  454.  
  455.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  456. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  457. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  458.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  459.