Karsten Hopp f8967f
To: vim_dev@googlegroups.com
Karsten Hopp f8967f
Subject: Patch 7.3.1045
Karsten Hopp f8967f
Fcc: outbox
Karsten Hopp f8967f
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp f8967f
Mime-Version: 1.0
Karsten Hopp f8967f
Content-Type: text/plain; charset=UTF-8
Karsten Hopp f8967f
Content-Transfer-Encoding: 8bit
Karsten Hopp f8967f
------------
Karsten Hopp f8967f
Karsten Hopp f8967f
Patch 7.3.1045
Karsten Hopp f8967f
Problem:    Python: No error handling for VimToPython function.
Karsten Hopp f8967f
Solution:   Python patch 6. (ZyX)
Karsten Hopp f8967f
Files:	    src/if_py_both.h
Karsten Hopp f8967f
Karsten Hopp f8967f
Karsten Hopp f8967f
*** ../vim-7.3.1044/src/if_py_both.h	2013-05-29 22:15:26.000000000 +0200
Karsten Hopp f8967f
--- src/if_py_both.h	2013-05-29 22:17:56.000000000 +0200
Karsten Hopp f8967f
***************
Karsten Hopp f8967f
*** 432,439 ****
Karsten Hopp f8967f
  	sprintf(ptrBuf, "%p",
Karsten Hopp f8967f
  		our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
Karsten Hopp f8967f
  					   : (void *)our_tv->vval.v_dict);
Karsten Hopp f8967f
! 	result = PyDict_GetItemString(lookupDict, ptrBuf);
Karsten Hopp f8967f
! 	if (result != NULL)
Karsten Hopp f8967f
  	{
Karsten Hopp f8967f
  	    Py_INCREF(result);
Karsten Hopp f8967f
  	    return result;
Karsten Hopp f8967f
--- 432,439 ----
Karsten Hopp f8967f
  	sprintf(ptrBuf, "%p",
Karsten Hopp f8967f
  		our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
Karsten Hopp f8967f
  					   : (void *)our_tv->vval.v_dict);
Karsten Hopp f8967f
! 
Karsten Hopp f8967f
! 	if ((result = PyDict_GetItemString(lookupDict, ptrBuf)))
Karsten Hopp f8967f
  	{
Karsten Hopp f8967f
  	    Py_INCREF(result);
Karsten Hopp f8967f
  	    return result;
Karsten Hopp f8967f
***************
Karsten Hopp f8967f
*** 467,510 ****
Karsten Hopp f8967f
  	list_T		*list = our_tv->vval.v_list;
Karsten Hopp f8967f
  	listitem_T	*curr;
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	result = PyList_New(0);
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	if (list != NULL)
Karsten Hopp f8967f
  	{
Karsten Hopp f8967f
! 	    PyDict_SetItemString(lookupDict, ptrBuf, result);
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	    for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
Karsten Hopp f8967f
  	    {
Karsten Hopp f8967f
- 		newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict);
Karsten Hopp f8967f
- 		PyList_Append(result, newObj);
Karsten Hopp f8967f
  		Py_DECREF(newObj);
Karsten Hopp f8967f
  	    }
Karsten Hopp f8967f
  	}
Karsten Hopp f8967f
      }
Karsten Hopp f8967f
      else if (our_tv->v_type == VAR_DICT)
Karsten Hopp f8967f
      {
Karsten Hopp f8967f
- 	result = PyDict_New();
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	if (our_tv->vval.v_dict != NULL)
Karsten Hopp f8967f
! 	{
Karsten Hopp f8967f
! 	    hashtab_T	*ht = &our_tv->vval.v_dict->dv_hashtab;
Karsten Hopp f8967f
! 	    long_u	todo = ht->ht_used;
Karsten Hopp f8967f
! 	    hashitem_T	*hi;
Karsten Hopp f8967f
! 	    dictitem_T	*di;
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	    PyDict_SetItemString(lookupDict, ptrBuf, result);
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	    for (hi = ht->ht_array; todo > 0; ++hi)
Karsten Hopp f8967f
  	    {
Karsten Hopp f8967f
! 		if (!HASHITEM_EMPTY(hi))
Karsten Hopp f8967f
! 		{
Karsten Hopp f8967f
! 		    --todo;
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 		    di = dict_lookup(hi);
Karsten Hopp f8967f
! 		    newObj = VimToPython(&di->di_tv, depth + 1, lookupDict);
Karsten Hopp f8967f
! 		    PyDict_SetItemString(result, (char *)hi->hi_key, newObj);
Karsten Hopp f8967f
  		    Py_DECREF(newObj);
Karsten Hopp f8967f
  		}
Karsten Hopp f8967f
  	    }
Karsten Hopp f8967f
  	}
Karsten Hopp f8967f
      }
Karsten Hopp f8967f
--- 467,538 ----
Karsten Hopp f8967f
  	list_T		*list = our_tv->vval.v_list;
Karsten Hopp f8967f
  	listitem_T	*curr;
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	if (list == NULL)
Karsten Hopp f8967f
! 	    return NULL;
Karsten Hopp f8967f
! 
Karsten Hopp f8967f
! 	if (!(result = PyList_New(0)))
Karsten Hopp f8967f
! 	    return NULL;
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	if (PyDict_SetItemString(lookupDict, ptrBuf, result))
Karsten Hopp f8967f
  	{
Karsten Hopp f8967f
! 	    Py_DECREF(result);
Karsten Hopp f8967f
! 	    return NULL;
Karsten Hopp f8967f
! 	}
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
Karsten Hopp f8967f
! 	{
Karsten Hopp f8967f
! 	    if (!(newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict)))
Karsten Hopp f8967f
! 	    {
Karsten Hopp f8967f
! 		Py_DECREF(result);
Karsten Hopp f8967f
! 		return NULL;
Karsten Hopp f8967f
! 	    }
Karsten Hopp f8967f
! 	    if (PyList_Append(result, newObj))
Karsten Hopp f8967f
  	    {
Karsten Hopp f8967f
  		Py_DECREF(newObj);
Karsten Hopp f8967f
+ 		Py_DECREF(result);
Karsten Hopp f8967f
+ 		return NULL;
Karsten Hopp f8967f
  	    }
Karsten Hopp f8967f
+ 	    Py_DECREF(newObj);
Karsten Hopp f8967f
  	}
Karsten Hopp f8967f
      }
Karsten Hopp f8967f
      else if (our_tv->v_type == VAR_DICT)
Karsten Hopp f8967f
      {
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	hashtab_T	*ht = &our_tv->vval.v_dict->dv_hashtab;
Karsten Hopp f8967f
! 	long_u	todo = ht->ht_used;
Karsten Hopp f8967f
! 	hashitem_T	*hi;
Karsten Hopp f8967f
! 	dictitem_T	*di;
Karsten Hopp f8967f
! 	if (our_tv->vval.v_dict == NULL)
Karsten Hopp f8967f
! 	    return NULL;
Karsten Hopp f8967f
! 
Karsten Hopp f8967f
! 	if (!(result = PyDict_New()))
Karsten Hopp f8967f
! 	    return NULL;
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	if (PyDict_SetItemString(lookupDict, ptrBuf, result))
Karsten Hopp f8967f
! 	{
Karsten Hopp f8967f
! 	    Py_DECREF(result);
Karsten Hopp f8967f
! 	    return NULL;
Karsten Hopp f8967f
! 	}
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 	for (hi = ht->ht_array; todo > 0; ++hi)
Karsten Hopp f8967f
! 	{
Karsten Hopp f8967f
! 	    if (!HASHITEM_EMPTY(hi))
Karsten Hopp f8967f
  	    {
Karsten Hopp f8967f
! 		--todo;
Karsten Hopp f8967f
  
Karsten Hopp f8967f
! 		di = dict_lookup(hi);
Karsten Hopp f8967f
! 		if (!(newObj = VimToPython(&di->di_tv, depth + 1, lookupDict)))
Karsten Hopp f8967f
! 		{
Karsten Hopp f8967f
! 		    Py_DECREF(result);
Karsten Hopp f8967f
! 		    return NULL;
Karsten Hopp f8967f
! 		}
Karsten Hopp f8967f
! 		if (PyDict_SetItemString(result, (char *)hi->hi_key, newObj))
Karsten Hopp f8967f
! 		{
Karsten Hopp f8967f
! 		    Py_DECREF(result);
Karsten Hopp f8967f
  		    Py_DECREF(newObj);
Karsten Hopp f8967f
+ 		    return NULL;
Karsten Hopp f8967f
  		}
Karsten Hopp f8967f
+ 		Py_DECREF(newObj);
Karsten Hopp f8967f
  	    }
Karsten Hopp f8967f
  	}
Karsten Hopp f8967f
      }
Karsten Hopp f8967f
*** ../vim-7.3.1044/src/version.c	2013-05-29 22:15:26.000000000 +0200
Karsten Hopp f8967f
--- src/version.c	2013-05-29 22:17:30.000000000 +0200
Karsten Hopp f8967f
***************
Karsten Hopp f8967f
*** 730,731 ****
Karsten Hopp f8967f
--- 730,733 ----
Karsten Hopp f8967f
  {   /* Add new patch number below this line */
Karsten Hopp f8967f
+ /**/
Karsten Hopp f8967f
+     1045,
Karsten Hopp f8967f
  /**/
Karsten Hopp f8967f
Karsten Hopp f8967f
-- 
Karsten Hopp f8967f
Shift happens.
Karsten Hopp f8967f
                -- Doppler
Karsten Hopp f8967f
Karsten Hopp f8967f
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp f8967f
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp f8967f
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp f8967f
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///