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.1048 < prev    next >
Encoding:
Internet Message Format  |  2013-05-28  |  13.9 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.1048
  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.1048
  11. Problem:    Python: no consistent naming.
  12. Solution:   Python patch 9: Rename d to dict and lookupDict to lookup_dict.
  13.         (ZyX)
  14. Files:        src/if_py_both.h
  15.  
  16.  
  17. *** ../vim-7.3.1047/src/if_py_both.h    2013-05-29 22:36:06.000000000 +0200
  18. --- src/if_py_both.h    2013-05-29 22:39:16.000000000 +0200
  19. ***************
  20. *** 475,481 ****
  21.    * you call VimToPython.
  22.    */
  23.       static PyObject *
  24. ! VimToPython(typval_T *our_tv, int depth, PyObject *lookupDict)
  25.   {
  26.       PyObject    *result;
  27.       PyObject    *newObj;
  28. --- 475,481 ----
  29.    * you call VimToPython.
  30.    */
  31.       static PyObject *
  32. ! VimToPython(typval_T *our_tv, int depth, PyObject *lookup_dict)
  33.   {
  34.       PyObject    *result;
  35.       PyObject    *newObj;
  36. ***************
  37. *** 489,495 ****
  38.       return result;
  39.       }
  40.   
  41. !     /* Check if we run into a recursive loop.  The item must be in lookupDict
  42.        * then and we can use it again. */
  43.       if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
  44.           || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
  45. --- 489,495 ----
  46.       return result;
  47.       }
  48.   
  49. !     /* Check if we run into a recursive loop.  The item must be in lookup_dict
  50.        * then and we can use it again. */
  51.       if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
  52.           || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
  53. ***************
  54. *** 498,504 ****
  55.           our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
  56.                          : (void *)our_tv->vval.v_dict);
  57.   
  58. !     if ((result = PyDict_GetItemString(lookupDict, ptrBuf)))
  59.       {
  60.           Py_INCREF(result);
  61.           return result;
  62. --- 498,504 ----
  63.           our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
  64.                          : (void *)our_tv->vval.v_dict);
  65.   
  66. !     if ((result = PyDict_GetItemString(lookup_dict, ptrBuf)))
  67.       {
  68.           Py_INCREF(result);
  69.           return result;
  70. ***************
  71. *** 538,544 ****
  72.       if (!(result = PyList_New(0)))
  73.           return NULL;
  74.   
  75. !     if (PyDict_SetItemString(lookupDict, ptrBuf, result))
  76.       {
  77.           Py_DECREF(result);
  78.           return NULL;
  79. --- 538,544 ----
  80.       if (!(result = PyList_New(0)))
  81.           return NULL;
  82.   
  83. !     if (PyDict_SetItemString(lookup_dict, ptrBuf, result))
  84.       {
  85.           Py_DECREF(result);
  86.           return NULL;
  87. ***************
  88. *** 546,552 ****
  89.   
  90.       for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
  91.       {
  92. !         if (!(newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict)))
  93.           {
  94.           Py_DECREF(result);
  95.           return NULL;
  96. --- 546,552 ----
  97.   
  98.       for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
  99.       {
  100. !         if (!(newObj = VimToPython(&curr->li_tv, depth + 1, lookup_dict)))
  101.           {
  102.           Py_DECREF(result);
  103.           return NULL;
  104. ***************
  105. *** 573,579 ****
  106.       if (!(result = PyDict_New()))
  107.           return NULL;
  108.   
  109. !     if (PyDict_SetItemString(lookupDict, ptrBuf, result))
  110.       {
  111.           Py_DECREF(result);
  112.           return NULL;
  113. --- 573,579 ----
  114.       if (!(result = PyDict_New()))
  115.           return NULL;
  116.   
  117. !     if (PyDict_SetItemString(lookup_dict, ptrBuf, result))
  118.       {
  119.           Py_DECREF(result);
  120.           return NULL;
  121. ***************
  122. *** 586,592 ****
  123.           --todo;
  124.   
  125.           di = dict_lookup(hi);
  126. !         if (!(newObj = VimToPython(&di->di_tv, depth + 1, lookupDict)))
  127.           {
  128.               Py_DECREF(result);
  129.               return NULL;
  130. --- 586,592 ----
  131.           --todo;
  132.   
  133.           di = dict_lookup(hi);
  134. !         if (!(newObj = VimToPython(&di->di_tv, depth + 1, lookup_dict)))
  135.           {
  136.               Py_DECREF(result);
  137.               return NULL;
  138. ***************
  139. *** 970,980 ****
  140.   {
  141.       char_u    *key;
  142.       typval_T    tv;
  143. !     dict_T    *d = self->dict;
  144.       dictitem_T    *di;
  145.       DICTKEY_DECL
  146.   
  147. !     if (d->dv_lock)
  148.       {
  149.       PyErr_SetVim(_("dict is locked"));
  150.       return -1;
  151. --- 970,980 ----
  152.   {
  153.       char_u    *key;
  154.       typval_T    tv;
  155. !     dict_T    *dict = self->dict;
  156.       dictitem_T    *di;
  157.       DICTKEY_DECL
  158.   
  159. !     if (dict->dv_lock)
  160.       {
  161.       PyErr_SetVim(_("dict is locked"));
  162.       return -1;
  163. ***************
  164. *** 982,988 ****
  165.   
  166.       DICTKEY_GET_NOTEMPTY(-1)
  167.   
  168. !     di = dict_find(d, key, -1);
  169.   
  170.       if (valObject == NULL)
  171.       {
  172. --- 982,988 ----
  173.   
  174.       DICTKEY_GET_NOTEMPTY(-1)
  175.   
  176. !     di = dict_find(dict, key, -1);
  177.   
  178.       if (valObject == NULL)
  179.       {
  180. ***************
  181. *** 994,1001 ****
  182.           PyErr_SetObject(PyExc_KeyError, keyObject);
  183.           return -1;
  184.       }
  185. !     hi = hash_find(&d->dv_hashtab, di->di_key);
  186. !     hash_remove(&d->dv_hashtab, hi);
  187.       dictitem_free(di);
  188.       return 0;
  189.       }
  190. --- 994,1001 ----
  191.           PyErr_SetObject(PyExc_KeyError, keyObject);
  192.           return -1;
  193.       }
  194. !     hi = hash_find(&dict->dv_hashtab, di->di_key);
  195. !     hash_remove(&dict->dv_hashtab, hi);
  196.       dictitem_free(di);
  197.       return 0;
  198.       }
  199. ***************
  200. *** 1013,1019 ****
  201.       }
  202.       di->di_tv.v_lock = 0;
  203.   
  204. !     if (dict_add(d, di) == FAIL)
  205.       {
  206.           DICTKEY_UNREF
  207.           vim_free(di);
  208. --- 1013,1019 ----
  209.       }
  210.       di->di_tv.v_lock = 0;
  211.   
  212. !     if (dict_add(dict, di) == FAIL)
  213.       {
  214.           DICTKEY_UNREF
  215.           vim_free(di);
  216. ***************
  217. *** 1102,1108 ****
  218.   }
  219.   
  220.       static int
  221. ! list_py_concat(list_T *l, PyObject *obj, PyObject *lookupDict)
  222.   {
  223.       Py_ssize_t    i;
  224.       Py_ssize_t    lsize = PySequence_Size(obj);
  225. --- 1102,1108 ----
  226.   }
  227.   
  228.       static int
  229. ! list_py_concat(list_T *l, PyObject *obj, PyObject *lookup_dict)
  230.   {
  231.       Py_ssize_t    i;
  232.       Py_ssize_t    lsize = PySequence_Size(obj);
  233. ***************
  234. *** 1122,1128 ****
  235.       litem = PySequence_GetItem(obj, i);
  236.       if (litem == NULL)
  237.           return -1;
  238. !     if (_ConvertFromPyObject(litem, &li->li_tv, lookupDict) == -1)
  239.           return -1;
  240.   
  241.       list_append(l, li);
  242. --- 1122,1128 ----
  243.       litem = PySequence_GetItem(obj, i);
  244.       if (litem == NULL)
  245.           return -1;
  246. !     if (_ConvertFromPyObject(litem, &li->li_tv, lookup_dict) == -1)
  247.           return -1;
  248.   
  249.       list_append(l, li);
  250. ***************
  251. *** 4009,4032 ****
  252.   }
  253.   
  254.       static int
  255. ! pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
  256.   {
  257. !     dict_T    *d;
  258.       char_u    *key;
  259.       dictitem_T    *di;
  260.       PyObject    *keyObject;
  261.       PyObject    *valObject;
  262.       Py_ssize_t    iter = 0;
  263.   
  264. !     d = dict_alloc();
  265. !     if (d == NULL)
  266.       {
  267.       PyErr_NoMemory();
  268.       return -1;
  269.       }
  270.   
  271.       tv->v_type = VAR_DICT;
  272. !     tv->vval.v_dict = d;
  273.   
  274.       while (PyDict_Next(obj, &iter, &keyObject, &valObject))
  275.       {
  276. --- 4009,4032 ----
  277.   }
  278.   
  279.       static int
  280. ! pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
  281.   {
  282. !     dict_T    *dict;
  283.       char_u    *key;
  284.       dictitem_T    *di;
  285.       PyObject    *keyObject;
  286.       PyObject    *valObject;
  287.       Py_ssize_t    iter = 0;
  288.   
  289. !     dict = dict_alloc();
  290. !     if (dict == NULL)
  291.       {
  292.       PyErr_NoMemory();
  293.       return -1;
  294.       }
  295.   
  296.       tv->v_type = VAR_DICT;
  297. !     tv->vval.v_dict = dict;
  298.   
  299.       while (PyDict_Next(obj, &iter, &keyObject, &valObject))
  300.       {
  301. ***************
  302. *** 4050,4061 ****
  303.       }
  304.       di->di_tv.v_lock = 0;
  305.   
  306. !     if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
  307.       {
  308.           vim_free(di);
  309.           return -1;
  310.       }
  311. !     if (dict_add(d, di) == FAIL)
  312.       {
  313.           vim_free(di);
  314.           PyErr_SetVim(_("failed to add key to dictionary"));
  315. --- 4050,4062 ----
  316.       }
  317.       di->di_tv.v_lock = 0;
  318.   
  319. !     if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1)
  320.       {
  321.           vim_free(di);
  322.           return -1;
  323.       }
  324. !     if (dict_add(dict, di) == FAIL)
  325.       {
  326.           vim_free(di);
  327.           PyErr_SetVim(_("failed to add key to dictionary"));
  328. ***************
  329. *** 4066,4074 ****
  330.   }
  331.   
  332.       static int
  333. ! pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
  334.   {
  335. !     dict_T    *d;
  336.       char_u    *key;
  337.       dictitem_T    *di;
  338.       PyObject    *list;
  339. --- 4067,4075 ----
  340.   }
  341.   
  342.       static int
  343. ! pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
  344.   {
  345. !     dict_T    *dict;
  346.       char_u    *key;
  347.       dictitem_T    *di;
  348.       PyObject    *list;
  349. ***************
  350. *** 4077,4091 ****
  351.       PyObject    *valObject;
  352.       Py_ssize_t    lsize;
  353.   
  354. !     d = dict_alloc();
  355. !     if (d == NULL)
  356.       {
  357.       PyErr_NoMemory();
  358.       return -1;
  359.       }
  360.   
  361.       tv->v_type = VAR_DICT;
  362. !     tv->vval.v_dict = d;
  363.   
  364.       list = PyMapping_Items(obj);
  365.       if (list == NULL)
  366. --- 4078,4092 ----
  367.       PyObject    *valObject;
  368.       Py_ssize_t    lsize;
  369.   
  370. !     dict = dict_alloc();
  371. !     if (dict == NULL)
  372.       {
  373.       PyErr_NoMemory();
  374.       return -1;
  375.       }
  376.   
  377.       tv->v_type = VAR_DICT;
  378. !     tv->vval.v_dict = dict;
  379.   
  380.       list = PyMapping_Items(obj);
  381.       if (list == NULL)
  382. ***************
  383. *** 4133,4146 ****
  384.       }
  385.       di->di_tv.v_lock = 0;
  386.   
  387. !     if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
  388.       {
  389.           vim_free(di);
  390.           Py_DECREF(list);
  391.           Py_DECREF(litem);
  392.           return -1;
  393.       }
  394. !     if (dict_add(d, di) == FAIL)
  395.       {
  396.           vim_free(di);
  397.           Py_DECREF(list);
  398. --- 4134,4147 ----
  399.       }
  400.       di->di_tv.v_lock = 0;
  401.   
  402. !     if (_ConvertFromPyObject(valObject, &di->di_tv, lookup_dict) == -1)
  403.       {
  404.           vim_free(di);
  405.           Py_DECREF(list);
  406.           Py_DECREF(litem);
  407.           return -1;
  408.       }
  409. !     if (dict_add(dict, di) == FAIL)
  410.       {
  411.           vim_free(di);
  412.           Py_DECREF(list);
  413. ***************
  414. *** 4155,4161 ****
  415.   }
  416.   
  417.       static int
  418. ! pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
  419.   {
  420.       list_T    *l;
  421.   
  422. --- 4156,4162 ----
  423.   }
  424.   
  425.       static int
  426. ! pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
  427.   {
  428.       list_T    *l;
  429.   
  430. ***************
  431. *** 4169,4182 ****
  432.       tv->v_type = VAR_LIST;
  433.       tv->vval.v_list = l;
  434.   
  435. !     if (list_py_concat(l, obj, lookupDict) == -1)
  436.       return -1;
  437.   
  438.       return 0;
  439.   }
  440.   
  441.       static int
  442. ! pyiter_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
  443.   {
  444.       PyObject    *iterator = PyObject_GetIter(obj);
  445.       PyObject    *item;
  446. --- 4170,4183 ----
  447.       tv->v_type = VAR_LIST;
  448.       tv->vval.v_list = l;
  449.   
  450. !     if (list_py_concat(l, obj, lookup_dict) == -1)
  451.       return -1;
  452.   
  453.       return 0;
  454.   }
  455.   
  456.       static int
  457. ! pyiter_to_tv(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
  458.   {
  459.       PyObject    *iterator = PyObject_GetIter(obj);
  460.       PyObject    *item;
  461. ***************
  462. *** 4208,4214 ****
  463.       }
  464.       li->li_tv.v_lock = 0;
  465.   
  466. !     if (_ConvertFromPyObject(item, &li->li_tv, lookupDict) == -1)
  467.           return -1;
  468.   
  469.       list_append(l, li);
  470. --- 4209,4215 ----
  471.       }
  472.       li->li_tv.v_lock = 0;
  473.   
  474. !     if (_ConvertFromPyObject(item, &li->li_tv, lookup_dict) == -1)
  475.           return -1;
  476.   
  477.       list_append(l, li);
  478. ***************
  479. *** 4224,4230 ****
  480.   
  481.       static int
  482.   convert_dl(PyObject *obj, typval_T *tv,
  483. !                     pytotvfunc py_to_tv, PyObject *lookupDict)
  484.   {
  485.       PyObject    *capsule;
  486.       char    hexBuf[sizeof(void *) * 2 + 3];
  487. --- 4225,4231 ----
  488.   
  489.       static int
  490.   convert_dl(PyObject *obj, typval_T *tv,
  491. !                     pytotvfunc py_to_tv, PyObject *lookup_dict)
  492.   {
  493.       PyObject    *capsule;
  494.       char    hexBuf[sizeof(void *) * 2 + 3];
  495. ***************
  496. *** 4232,4240 ****
  497.       sprintf(hexBuf, "%p", obj);
  498.   
  499.   # ifdef PY_USE_CAPSULE
  500. !     capsule = PyDict_GetItemString(lookupDict, hexBuf);
  501.   # else
  502. !     capsule = (PyObject *)PyDict_GetItemString(lookupDict, hexBuf);
  503.   # endif
  504.       if (capsule == NULL)
  505.       {
  506. --- 4233,4241 ----
  507.       sprintf(hexBuf, "%p", obj);
  508.   
  509.   # ifdef PY_USE_CAPSULE
  510. !     capsule = PyDict_GetItemString(lookup_dict, hexBuf);
  511.   # else
  512. !     capsule = (PyObject *)PyDict_GetItemString(lookup_dict, hexBuf);
  513.   # endif
  514.       if (capsule == NULL)
  515.       {
  516. ***************
  517. *** 4243,4251 ****
  518.   # else
  519.       capsule = PyCObject_FromVoidPtr(tv, NULL);
  520.   # endif
  521. !     PyDict_SetItemString(lookupDict, hexBuf, capsule);
  522.       Py_DECREF(capsule);
  523. !     if (py_to_tv(obj, tv, lookupDict) == -1)
  524.       {
  525.           tv->v_type = VAR_UNKNOWN;
  526.           return -1;
  527. --- 4244,4252 ----
  528.   # else
  529.       capsule = PyCObject_FromVoidPtr(tv, NULL);
  530.   # endif
  531. !     PyDict_SetItemString(lookup_dict, hexBuf, capsule);
  532.       Py_DECREF(capsule);
  533. !     if (py_to_tv(obj, tv, lookup_dict) == -1)
  534.       {
  535.           tv->v_type = VAR_UNKNOWN;
  536.           return -1;
  537. ***************
  538. *** 4285,4291 ****
  539.   }
  540.   
  541.       static int
  542. ! _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
  543.   {
  544.       if (obj->ob_type == &DictionaryType)
  545.       {
  546. --- 4286,4292 ----
  547.   }
  548.   
  549.       static int
  550. ! _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
  551.   {
  552.       if (obj->ob_type == &DictionaryType)
  553.       {
  554. ***************
  555. *** 4357,4363 ****
  556.       tv->vval.v_number = (varnumber_T) PyLong_AsLong(obj);
  557.       }
  558.       else if (PyDict_Check(obj))
  559. !     return convert_dl(obj, tv, pydict_to_tv, lookupDict);
  560.   #ifdef FEAT_FLOAT
  561.       else if (PyFloat_Check(obj))
  562.       {
  563. --- 4358,4364 ----
  564.       tv->vval.v_number = (varnumber_T) PyLong_AsLong(obj);
  565.       }
  566.       else if (PyDict_Check(obj))
  567. !     return convert_dl(obj, tv, pydict_to_tv, lookup_dict);
  568.   #ifdef FEAT_FLOAT
  569.       else if (PyFloat_Check(obj))
  570.       {
  571. ***************
  572. *** 4366,4376 ****
  573.       }
  574.   #endif
  575.       else if (PyIter_Check(obj))
  576. !     return convert_dl(obj, tv, pyiter_to_tv, lookupDict);
  577.       else if (PySequence_Check(obj))
  578. !     return convert_dl(obj, tv, pyseq_to_tv, lookupDict);
  579.       else if (PyMapping_Check(obj))
  580. !     return convert_dl(obj, tv, pymap_to_tv, lookupDict);
  581.       else
  582.       {
  583.       PyErr_SetString(PyExc_TypeError,
  584. --- 4367,4377 ----
  585.       }
  586.   #endif
  587.       else if (PyIter_Check(obj))
  588. !     return convert_dl(obj, tv, pyiter_to_tv, lookup_dict);
  589.       else if (PySequence_Check(obj))
  590. !     return convert_dl(obj, tv, pyseq_to_tv, lookup_dict);
  591.       else if (PyMapping_Check(obj))
  592. !     return convert_dl(obj, tv, pymap_to_tv, lookup_dict);
  593.       else
  594.       {
  595.       PyErr_SetString(PyExc_TypeError,
  596. *** ../vim-7.3.1047/src/version.c    2013-05-29 22:36:06.000000000 +0200
  597. --- src/version.c    2013-05-29 22:38:23.000000000 +0200
  598. ***************
  599. *** 730,731 ****
  600. --- 730,733 ----
  601.   {   /* Add new patch number below this line */
  602. + /**/
  603. +     1048,
  604.   /**/
  605.  
  606. -- 
  607. hundred-and-one symptoms of being an internet addict:
  608. 23. You can't call your mother...she doesn't have a modem.
  609.  
  610.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  611. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  612. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  613.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  614.