#define DICTKEY_DECL \
PyObject *dictkey_todecref;
-#define DICTKEY_GET(err) \
+#define DICTKEY_GET(err, decref) \
if (!(key = StringToChars(keyObject, &dictkey_todecref))) \
+ { \
+ if (decref) \
+ { \
+ Py_DECREF(keyObject); \
+ } \
return err; \
+ } \
+ if (decref && !dictkey_todecref) \
+ dictkey_todecref = keyObject; \
if (*key == NUL) \
{ \
PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
Py_DECREF(newObj);
return NULL;
}
- Py_DECREF(newObj);
}
}
}
dictitem_T *di;
DICTKEY_DECL
- DICTKEY_GET(NULL)
+ DICTKEY_GET(NULL, 0)
di = dict_find(self->dict, key, -1);
return -1;
}
- DICTKEY_GET(-1)
+ DICTKEY_GET(-1, 0)
di = dict_find(dict, key, -1);
if (self->Check(self->from))
return NULL;
- DICTKEY_GET(NULL)
+ DICTKEY_GET(NULL, 0)
flags = get_option_value_strict(key, &numval, &stringval,
self->opt_type, self->from);
if (self->Check(self->from))
return -1;
- DICTKEY_GET(-1)
+ DICTKEY_GET(-1, 0)
flags = get_option_value_strict(key, NULL, NULL,
self->opt_type, self->from);
{
DICTKEY_DECL
- if (keyObject == NULL)
- return -1;
- if (valObject == NULL)
+ if (keyObject == NULL || valObject == NULL)
return -1;
- DICTKEY_GET(-1)
+ DICTKEY_GET(-1, 0)
di = dictitem_alloc(key);
if (dict_add(dict, di) == FAIL)
{
+ clear_tv(&di->di_tv);
vim_free(di);
PyErr_SetVim(_("failed to add key to dictionary"));
return -1;
return -1;
}
- keyObject = PyTuple_GetItem(litem, 0);
- if (keyObject == NULL)
+ if (!(keyObject = PyTuple_GetItem(litem, 0)))
{
Py_DECREF(list);
Py_DECREF(litem);
return -1;
}
- DICTKEY_GET(-1)
+ DICTKEY_GET(-1, 1)
- valObject = PyTuple_GetItem(litem, 1);
- if (valObject == NULL)
+ if (!(valObject = PyTuple_GetItem(litem, 1)))
{
Py_DECREF(list);
Py_DECREF(litem);
+ DICTKEY_UNREF
return -1;
}
+ Py_DECREF(litem);
+
di = dictitem_alloc(key);
DICTKEY_UNREF
if (di == NULL)
{
Py_DECREF(list);
- Py_DECREF(litem);
+ Py_DECREF(valObject);
PyErr_NoMemory();
return -1;
}
{
vim_free(di);
Py_DECREF(list);
- Py_DECREF(litem);
+ Py_DECREF(valObject);
return -1;
}
+
+ Py_DECREF(valObject);
+
if (dict_add(dict, di) == FAIL)
{
+ clear_tv(&di->di_tv);
vim_free(di);
Py_DECREF(list);
- Py_DECREF(litem);
PyErr_SetVim(_("failed to add key to dictionary"));
return -1;
}
- Py_DECREF(litem);
}
Py_DECREF(list);
return 0;
li = listitem_alloc();
if (li == NULL)
{
+ Py_DECREF(iterator);
PyErr_NoMemory();
return -1;
}
li->li_tv.v_lock = 0;
if (_ConvertFromPyObject(item, &li->li_tv, lookup_dict) == -1)
+ {
+ Py_DECREF(item);
+ Py_DECREF(iterator);
return -1;
+ }
list_append(l, li);
# else
capsule = PyCObject_FromVoidPtr(tv, NULL);
# endif
- PyDict_SetItemString(lookup_dict, hexBuf, capsule);
- Py_DECREF(capsule);
+ if (PyDict_SetItemString(lookup_dict, hexBuf, capsule))
+ {
+ Py_DECREF(capsule);
+ tv->v_type = VAR_UNKNOWN;
+ return -1;
+ }
if (py_to_tv(obj, tv, lookup_dict) == -1)
{
tv->v_type = VAR_UNKNOWN;