Skip to content

Commit 89f91fc

Browse files
committed
Use SystemError for negative size
Use also UNINITIALIZED_SIZE in test code.
1 parent cc47b10 commit 89f91fc

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

Lib/test/test_capi/test_tuple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ def test_tuple_fromarray(self):
7777
copy = tuple_fromarray(NULL, 0)
7878
self.assertIs(copy, ())
7979

80-
with self.assertRaises(ValueError):
80+
with self.assertRaises(SystemError):
8181
tuple_fromarray(NULL, -1)
82-
with self.assertRaises(ValueError):
82+
with self.assertRaises(SystemError):
8383
tuple_fromarray(NULL, PY_SSIZE_T_MIN)
8484
with self.assertRaises(MemoryError):
8585
tuple_fromarray(NULL, PY_SSIZE_T_MAX)

Modules/_testcapi/tuple.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static PyObject *
108108
tuple_fromarray(PyObject* Py_UNUSED(module), PyObject *args)
109109
{
110110
PyObject *src;
111-
Py_ssize_t size = -1;
111+
Py_ssize_t size = UNINITIALIZED_SIZE;
112112
if (!PyArg_ParseTuple(args, "O|n", &src, &size)) {
113113
return NULL;
114114
}
@@ -120,7 +120,7 @@ tuple_fromarray(PyObject* Py_UNUSED(module), PyObject *args)
120120
PyObject **items;
121121
if (src != Py_None) {
122122
items = &PyTuple_GET_ITEM(src, 0);
123-
if (size < 0) {
123+
if (size == UNINITIALIZED_SIZE) {
124124
size = PyTuple_GET_SIZE(src);
125125
}
126126
}

Objects/tupleobject.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,6 @@ PyTuple_FromArray(PyObject *const *src, Py_ssize_t n)
371371
if (n == 0) {
372372
return tuple_get_empty();
373373
}
374-
if (n < 0) {
375-
PyErr_SetString(PyExc_ValueError, "size must be nonnegative");
376-
return NULL;
377-
}
378374

379375
PyTupleObject *tuple = tuple_alloc(n);
380376
if (tuple == NULL) {

0 commit comments

Comments
 (0)