Skip to content

Commit fe89438

Browse files
committed
gh-135698: Fix _interpqueues.create(): max_size >= 0
Make sure that the queue maximum size is greater than or equal to 0.
1 parent 140731f commit fe89438

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Lib/test/test_interpreters/test_queues.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def test_create_destroy(self):
5050
with self.assertRaises(queues.QueueNotFoundError):
5151
_queues.destroy(qid)
5252

53+
with self.assertRaises(ValueError):
54+
# gh-135698: max_size must be greater than or equal to 0
55+
_queues.create(-1, 1, 1)
56+
5357
def test_not_destroyed(self):
5458
# It should have cleaned up any remaining queues.
5559
stdout, stderr = self.assert_python_ok(
@@ -114,8 +118,8 @@ def test_create(self):
114118
self.assertEqual(queue.maxsize, 0)
115119

116120
with self.subTest('negative maxsize'):
117-
queue = queues.create(-10)
118-
self.assertEqual(queue.maxsize, -10)
121+
with self.assertRaises(ValueError):
122+
queues.create(-10)
119123

120124
with self.subTest('bad maxsize'):
121125
with self.assertRaises(TypeError):

Modules/_interpqueuesmodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,11 @@ queuesmod_create(PyObject *self, PyObject *args, PyObject *kwds)
14881488
{
14891489
return NULL;
14901490
}
1491+
if (maxsize < 0) {
1492+
PyErr_SetString(PyExc_ValueError,
1493+
"max_size must be greater than or equal to 0");
1494+
return NULL;
1495+
}
14911496
struct _queuedefaults defaults = {0};
14921497
if (resolve_unboundop(unboundarg, UNBOUND_REPLACE,
14931498
&defaults.unboundop) < 0)

0 commit comments

Comments
 (0)