a += a
self.assertEqual(len(a), 0)
+ def test_fromlist_reentrant_index_mutation(self):
+
+ class Evil:
+ def __init__(self, lst):
+ self.lst = lst
+ def __index__(self):
+ self.lst.clear()
+ return "not an int"
+
+ for typecode in ('I', 'L', 'Q'):
+ with self.subTest(typecode=typecode):
+ lst = []
+ lst.append(Evil(lst))
+ a = array.array(typecode)
+ with self.assertRaises(TypeError):
+ a.fromlist(lst)
+
# Machine format codes.
#
int do_decref = 0; /* if nb_int was called */
if (!PyLong_Check(v)) {
- v = _PyNumber_Index(v);
- if (NULL == v) {
+ Py_INCREF(v);
+ PyObject *res = _PyNumber_Index(v);
+ Py_DECREF(v);
+ if (NULL == res) {
return -1;
}
+ v = res;
do_decref = 1;
}
x = PyLong_AsUnsignedLong(v);
int do_decref = 0; /* if nb_int was called */
if (!PyLong_Check(v)) {
- v = _PyNumber_Index(v);
- if (NULL == v) {
+ Py_INCREF(v);
+ PyObject *res = _PyNumber_Index(v);
+ Py_DECREF(v);
+ if (NULL == res) {
return -1;
}
+ v = res;
do_decref = 1;
}
x = PyLong_AsUnsignedLong(v);
int do_decref = 0; /* if nb_int was called */
if (!PyLong_Check(v)) {
- v = _PyNumber_Index(v);
- if (NULL == v) {
+ Py_INCREF(v);
+ PyObject *res = _PyNumber_Index(v);
+ Py_DECREF(v);
+ if (NULL == res) {
return -1;
}
+ v = res;
do_decref = 1;
}
x = PyLong_AsUnsignedLongLong(v);