"Test the functionality of Python classes implementing operators."
import unittest
+import test.support
testmeths = [
C.a = X()
C.a = X()
+ def test_detach_materialized_dict_no_memory(self):
+ import _testcapi
+ class A:
+ def __init__(self):
+ self.a = 1
+ self.b = 2
+ a = A()
+ d = a.__dict__
+ with test.support.catch_unraisable_exception() as ex:
+ _testcapi.set_nomemory(0, 1)
+ del a
+ self.assertEqual(ex.unraisable.exc_type, MemoryError)
+ with self.assertRaises(KeyError):
+ d["a"]
if __name__ == '__main__':
unittest.main()
}
/* Copies the values, but does not change the reference
- * counts of the objects in the array. */
+ * counts of the objects in the array.
+ * Return NULL, but does *not* set an exception on failure */
static PyDictValues *
copy_values(PyDictValues *values)
{
PyDictValues *newvalues = new_values(values->capacity);
if (newvalues == NULL) {
- PyErr_NoMemory();
return NULL;
}
newvalues->size = values->size;
PyDictValues *values = copy_values(mp->ma_values);
if (values == NULL) {
+ /* Out of memory. Clear the dict */
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyDictKeysObject *oldkeys = mp->ma_keys;
+ set_keys(mp, Py_EMPTY_KEYS);
+ dictkeys_decref(interp, oldkeys, IS_DICT_SHARED(mp));
+ STORE_USED(mp, 0);
+ PyErr_NoMemory();
return -1;
}
mp->ma_values = values;