# HG changeset patch
# User ZyX <[email protected]>
# Date 1369474461 -14400
# Node ID cc578271bc44d90911e71c3e0992772826e5e26c
# Parent a71b70fc1b4ea887cc5361a13e43c0b594309593
Add error handling to VimToPython function
diff -r a71b70fc1b4e -r cc578271bc44 src/if_py_both.h
--- a/src/if_py_both.h Sat May 25 13:20:52 2013 +0400
+++ b/src/if_py_both.h Sat May 25 13:34:21 2013 +0400
@@ -432,8 +432,8 @@
sprintf(ptrBuf, "%p",
our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
: (void *)our_tv->vval.v_dict);
- result = PyDict_GetItemString(lookupDict, ptrBuf);
- if (result != NULL)
+
+ if ((result = PyDict_GetItemString(lookupDict, ptrBuf)))
{
Py_INCREF(result);
return result;
@@ -467,44 +467,72 @@
list_T *list = our_tv->vval.v_list;
listitem_T *curr;
- result = PyList_New(0);
-
- if (list != NULL)
+ if (list == NULL)
+ return NULL;
+
+ if (!(result = PyList_New(0)))
+ return NULL;
+
+ if (PyDict_SetItemString(lookupDict, ptrBuf, result))
{
- PyDict_SetItemString(lookupDict, ptrBuf, result);
-
- for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
+ Py_DECREF(result);
+ return NULL;
+ }
+
+ for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
+ {
+ if (!(newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict)))
{
- newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict);
- PyList_Append(result, newObj);
+ Py_DECREF(result);
+ return NULL;
+ }
+ if (PyList_Append(result, newObj))
+ {
Py_DECREF(newObj);
+ Py_DECREF(result);
+ return NULL;
}
+ Py_DECREF(newObj);
}
}
else if (our_tv->v_type == VAR_DICT)
{
- result = PyDict_New();
-
- if (our_tv->vval.v_dict != NULL)
+
+ hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab;
+ long_u todo = ht->ht_used;
+ hashitem_T *hi;
+ dictitem_T *di;
+ if (our_tv->vval.v_dict == NULL)
+ return NULL;
+
+ if (!(result = PyDict_New()))
+ return NULL;
+
+ if (PyDict_SetItemString(lookupDict, ptrBuf, result))
{
- hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab;
- long_u todo = ht->ht_used;
- hashitem_T *hi;
- dictitem_T *di;
-
- PyDict_SetItemString(lookupDict, ptrBuf, result);
-
- for (hi = ht->ht_array; todo > 0; ++hi)
+ Py_DECREF(result);
+ return NULL;
+ }
+
+ for (hi = ht->ht_array; todo > 0; ++hi)
+ {
+ if (!HASHITEM_EMPTY(hi))
{
- if (!HASHITEM_EMPTY(hi))
+ --todo;
+
+ di = dict_lookup(hi);
+ if (!(newObj = VimToPython(&di->di_tv, depth + 1, lookupDict)))
{
- --todo;
-
- di = dict_lookup(hi);
- newObj = VimToPython(&di->di_tv, depth + 1, lookupDict);
- PyDict_SetItemString(result, (char *)hi->hi_key, newObj);
+ Py_DECREF(result);
+ return NULL;
+ }
+ if (PyDict_SetItemString(result, (char *)hi->hi_key, newObj))
+ {
+ Py_DECREF(result);
Py_DECREF(newObj);
+ return NULL;
}
+ Py_DECREF(newObj);
}
}
}
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
*** /tmp/extdiff.xOrSlf/vim.a71b70fc1b4e/src/if_py_both.h 2013-05-25 14:59:23.117004482 +0400
--- vim.cc578271bc44/src/if_py_both.h 2013-05-25 14:59:23.123001426 +0400
***************
*** 432,439 ****
sprintf(ptrBuf, "%p",
our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
: (void *)our_tv->vval.v_dict);
! result = PyDict_GetItemString(lookupDict, ptrBuf);
! if (result != NULL)
{
Py_INCREF(result);
return result;
--- 432,439 ----
sprintf(ptrBuf, "%p",
our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
: (void *)our_tv->vval.v_dict);
!
! if ((result = PyDict_GetItemString(lookupDict, ptrBuf)))
{
Py_INCREF(result);
return result;
***************
*** 467,510 ****
list_T *list = our_tv->vval.v_list;
listitem_T *curr;
! result = PyList_New(0);
! if (list != NULL)
{
! PyDict_SetItemString(lookupDict, ptrBuf, result);
! for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
{
- newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict);
- PyList_Append(result, newObj);
Py_DECREF(newObj);
}
}
}
else if (our_tv->v_type == VAR_DICT)
{
- result = PyDict_New();
! if (our_tv->vval.v_dict != NULL)
! {
! hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab;
! long_u todo = ht->ht_used;
! hashitem_T *hi;
! dictitem_T *di;
! PyDict_SetItemString(lookupDict, ptrBuf, result);
! for (hi = ht->ht_array; todo > 0; ++hi)
{
! if (!HASHITEM_EMPTY(hi))
! {
! --todo;
! di = dict_lookup(hi);
! newObj = VimToPython(&di->di_tv, depth + 1, lookupDict);
! PyDict_SetItemString(result, (char *)hi->hi_key, newObj);
Py_DECREF(newObj);
}
}
}
}
--- 467,538 ----
list_T *list = our_tv->vval.v_list;
listitem_T *curr;
! if (list == NULL)
! return NULL;
!
! if (!(result = PyList_New(0)))
! return NULL;
! if (PyDict_SetItemString(lookupDict, ptrBuf, result))
{
! Py_DECREF(result);
! return NULL;
! }
! for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
! {
! if (!(newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict)))
! {
! Py_DECREF(result);
! return NULL;
! }
! if (PyList_Append(result, newObj))
{
Py_DECREF(newObj);
+ Py_DECREF(result);
+ return NULL;
}
+ Py_DECREF(newObj);
}
}
else if (our_tv->v_type == VAR_DICT)
{
! hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab;
! long_u todo = ht->ht_used;
! hashitem_T *hi;
! dictitem_T *di;
! if (our_tv->vval.v_dict == NULL)
! return NULL;
!
! if (!(result = PyDict_New()))
! return NULL;
! if (PyDict_SetItemString(lookupDict, ptrBuf, result))
! {
! Py_DECREF(result);
! return NULL;
! }
! for (hi = ht->ht_array; todo > 0; ++hi)
! {
! if (!HASHITEM_EMPTY(hi))
{
! --todo;
! di = dict_lookup(hi);
! if (!(newObj = VimToPython(&di->di_tv, depth + 1, lookupDict)))
! {
! Py_DECREF(result);
! return NULL;
! }
! if (PyDict_SetItemString(result, (char *)hi->hi_key, newObj))
! {
! Py_DECREF(result);
Py_DECREF(newObj);
+ return NULL;
}
+ Py_DECREF(newObj);
}
}
}