Skip to content

gh-135698: Fix _interpqueues.create(): max_size >= 0 #135703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Lib/test/test_interpreters/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def test_create_destroy(self):
with self.assertRaises(queues.QueueNotFoundError):
_queues.destroy(qid)

with self.assertRaises(ValueError):
# gh-135698: max_size must be greater than or equal to 0
_queues.create(-1, 1, 1)

def test_not_destroyed(self):
# It should have cleaned up any remaining queues.
stdout, stderr = self.assert_python_ok(
Expand Down Expand Up @@ -114,8 +118,8 @@ def test_create(self):
self.assertEqual(queue.maxsize, 0)

with self.subTest('negative maxsize'):
queue = queues.create(-10)
self.assertEqual(queue.maxsize, -10)
with self.assertRaises(ValueError):
queues.create(-10)

with self.subTest('bad maxsize'):
with self.assertRaises(TypeError):
Expand Down
5 changes: 5 additions & 0 deletions Modules/_interpqueuesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,11 @@ queuesmod_create(PyObject *self, PyObject *args, PyObject *kwds)
{
return NULL;
}
if (maxsize < 0) {
PyErr_SetString(PyExc_ValueError,
"max_size must be greater than or equal to 0");
return NULL;
}
Comment on lines +1491 to +1495
Copy link
Member

@ericsnowcurrently ericsnowcurrently Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A negative value is fine. That's the same as queue.Queue. The logic (and the assert) in _queue_is_full() is actually wrong. I'll put up a PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See gh-135724.

struct _queuedefaults defaults = {0};
if (resolve_unboundop(unboundarg, UNBOUND_REPLACE,
&defaults.unboundop) < 0)
Expand Down
Loading