Commit 6b57f2a8 authored by Adam Groszer's avatar Adam Groszer

added error handling + reference counting

parent 25b52694
...@@ -632,21 +632,48 @@ pickle___setstate__(PyObject *self, PyObject *state) ...@@ -632,21 +632,48 @@ pickle___setstate__(PyObject *self, PyObject *state)
fall back to iterating over items, instead of silently fall back to iterating over items, instead of silently
failing with PyDict_Next */ failing with PyDict_Next */
items = PyMapping_Items(state); items = PyMapping_Items(state);
if (items == NULL)
return NULL;
len = PySequence_Size(items); len = PySequence_Size(items);
if (len < 0)
{
Py_DECREF(items);
return NULL;
}
for ( i=0; i<len; ++i ) { for ( i=0; i<len; ++i ) {
PyObject *item = PySequence_GetItem(items, i); PyObject *item = PySequence_GetItem(items, i);
if (item == NULL)
return NULL;
d_key = PyTuple_GetItem(item, 0); d_key = PyTuple_GetItem(item, 0);
if (d_key == NULL)
{
Py_DECREF(item);
Py_DECREF(items);
return NULL;
}
d_value = PyTuple_GetItem(item, 1); d_value = PyTuple_GetItem(item, 1);
if (d_value == NULL)
{
Py_DECREF(d_key);
Py_DECREF(item);
Py_DECREF(items);
return NULL;
}
if (NATIVE_CHECK_EXACT(d_key)) { if (NATIVE_CHECK_EXACT(d_key)) {
Py_INCREF(d_key); Py_INCREF(d_key);
INTERN_INPLACE(&d_key); INTERN_INPLACE(&d_key);
Py_DECREF(d_key); Py_DECREF(d_key);
} }
Py_DECREF(item);
if (PyObject_SetItem(*dict, d_key, d_value) < 0) if (PyObject_SetItem(*dict, d_key, d_value) < 0)
{
Py_DECREF(items);
return NULL; return NULL;
} }
} }
Py_DECREF(items);
}
} }
if (slots && pickle_setattrs_from_dict(self, slots) < 0) if (slots && pickle_setattrs_from_dict(self, slots) < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment