lkundrak / rpms / vim

Forked from rpms/vim 4 years ago
Clone
85e6442
To: vim-dev@vim.org
85e6442
Subject: Patch 7.2.084
85e6442
Fcc: outbox
85e6442
From: Bram Moolenaar <Bram@moolenaar.net>
85e6442
Mime-Version: 1.0
85e6442
Content-Type: text/plain; charset=ISO-8859-1
85e6442
Content-Transfer-Encoding: 8bit
85e6442
------------
85e6442
85e6442
Patch 7.2.084
85e6442
Problem:    Recursive structures are not handled properly in Python
85e6442
	    vim.eval().
85e6442
Solution:   Keep track of references in a better way. (Yukihiro Nakadaira)
85e6442
Files:	    src/if_python.c
85e6442
85e6442
85e6442
*** ../vim-7.2.083/src/if_python.c	Thu Nov 20 11:04:01 2008
85e6442
--- src/if_python.c	Tue Jan 13 18:08:06 2009
85e6442
***************
85e6442
*** 1151,1164 ****
85e6442
  
85e6442
      /* Check if we run into a recursive loop.  The item must be in lookupDict
85e6442
       * then and we can use it again. */
85e6442
!     sprintf(ptrBuf, PRINTF_DECIMAL_LONG_U, (long_u)our_tv);
85e6442
!     result = PyDict_GetItemString(lookupDict, ptrBuf);
85e6442
!     if (result != NULL)
85e6442
! 	Py_INCREF(result);
85e6442
!     else if (our_tv->v_type == VAR_STRING)
85e6442
      {
85e6442
  	result = Py_BuildValue("s", our_tv->vval.v_string);
85e6442
- 	PyDict_SetItemString(lookupDict, ptrBuf, result);
85e6442
      }
85e6442
      else if (our_tv->v_type == VAR_NUMBER)
85e6442
      {
85e6442
--- 1151,1173 ----
85e6442
  
85e6442
      /* Check if we run into a recursive loop.  The item must be in lookupDict
85e6442
       * then and we can use it again. */
85e6442
!     if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
85e6442
! 	    || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
85e6442
!     {
85e6442
! 	sprintf(ptrBuf, PRINTF_DECIMAL_LONG_U,
85e6442
! 	        our_tv->v_type == VAR_LIST ? (long_u)our_tv->vval.v_list
85e6442
! 		                           : (long_u)our_tv->vval.v_dict);
85e6442
! 	result = PyDict_GetItemString(lookupDict, ptrBuf);
85e6442
! 	if (result != NULL)
85e6442
! 	{
85e6442
! 	    Py_INCREF(result);
85e6442
! 	    return result;
85e6442
! 	}
85e6442
!     }
85e6442
! 
85e6442
!     if (our_tv->v_type == VAR_STRING)
85e6442
      {
85e6442
  	result = Py_BuildValue("s", our_tv->vval.v_string);
85e6442
      }
85e6442
      else if (our_tv->v_type == VAR_NUMBER)
85e6442
      {
85e6442
***************
85e6442
*** 1167,1173 ****
85e6442
  	/* For backwards compatibility numbers are stored as strings. */
85e6442
  	sprintf(buf, "%ld", (long)our_tv->vval.v_number);
85e6442
  	result = Py_BuildValue("s", buf);
85e6442
- 	PyDict_SetItemString(lookupDict, ptrBuf, result);
85e6442
      }
85e6442
  # ifdef FEAT_FLOAT
85e6442
      else if (our_tv->v_type == VAR_FLOAT)
85e6442
--- 1176,1181 ----
85e6442
***************
85e6442
*** 1176,1182 ****
85e6442
  
85e6442
  	sprintf(buf, "%f", our_tv->vval.v_float);
85e6442
  	result = Py_BuildValue("s", buf);
85e6442
- 	PyDict_SetItemString(lookupDict, ptrBuf, result);
85e6442
      }
85e6442
  # endif
85e6442
      else if (our_tv->v_type == VAR_LIST)
85e6442
--- 1184,1189 ----
85e6442
***************
85e6442
*** 1185,1194 ****
85e6442
  	listitem_T	*curr;
85e6442
  
85e6442
  	result = PyList_New(0);
85e6442
- 	PyDict_SetItemString(lookupDict, ptrBuf, result);
85e6442
  
85e6442
  	if (list != NULL)
85e6442
  	{
85e6442
  	    for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
85e6442
  	    {
85e6442
  		newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict);
85e6442
--- 1192,1202 ----
85e6442
  	listitem_T	*curr;
85e6442
  
85e6442
  	result = PyList_New(0);
85e6442
  
85e6442
  	if (list != NULL)
85e6442
  	{
85e6442
+ 	    PyDict_SetItemString(lookupDict, ptrBuf, result);
85e6442
+ 
85e6442
  	    for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
85e6442
  	    {
85e6442
  		newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict);
85e6442
***************
85e6442
*** 1200,1206 ****
85e6442
      else if (our_tv->v_type == VAR_DICT)
85e6442
      {
85e6442
  	result = PyDict_New();
85e6442
- 	PyDict_SetItemString(lookupDict, ptrBuf, result);
85e6442
  
85e6442
  	if (our_tv->vval.v_dict != NULL)
85e6442
  	{
85e6442
--- 1208,1213 ----
85e6442
***************
85e6442
*** 1209,1214 ****
85e6442
--- 1216,1223 ----
85e6442
  	    hashitem_T	*hi;
85e6442
  	    dictitem_T	*di;
85e6442
  
85e6442
+ 	    PyDict_SetItemString(lookupDict, ptrBuf, result);
85e6442
+ 
85e6442
  	    for (hi = ht->ht_array; todo > 0; ++hi)
85e6442
  	    {
85e6442
  		if (!HASHITEM_EMPTY(hi))
85e6442
*** ../vim-7.2.083/src/version.c	Tue Jan 13 17:27:18 2009
85e6442
--- src/version.c	Tue Jan 13 17:54:14 2009
85e6442
***************
85e6442
*** 678,679 ****
85e6442
--- 678,681 ----
85e6442
  {   /* Add new patch number below this line */
85e6442
+ /**/
85e6442
+     84,
85e6442
  /**/
85e6442
85e6442
-- 
85e6442
Article in the first Free Software Magazine: "Bram Moolenaar studied electrical
85e6442
engineering at the Technical University of Delft and graduated in 1985 on a
85e6442
multi-processor Unix architecture."
85e6442
Response by "dimator": Could the school not afford a proper stage for the
85e6442
ceremony?
85e6442
85e6442
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
85e6442
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
85e6442
\\\        download, build and distribute -- http://www.A-A-P.org        ///
85e6442
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///