Skip to content
Merged
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
10 changes: 10 additions & 0 deletions Lib/test/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# to ensure the Queue locks remain stable.
import itertools
import random
import struct
import threading
import time
import unittest
import weakref
from test.support import gc_collect, bigmemtest
from test.support import import_helper
from test.support import threading_helper
from test import support

# queue module depends on threading primitives
threading_helper.requires_working_threading(module=True)
Expand Down Expand Up @@ -1031,6 +1033,14 @@ def test_is_default(self):
self.assertIs(self.type2test, self.queue.SimpleQueue)
self.assertIs(self.type2test, self.queue.SimpleQueue)

def test_simplequeue_sizeof(self):
q = self.type2test()
basesize = support.calcobjsize('?nnPnnP')
support.check_sizeof(self, q, basesize + struct.calcsize(8 * 'P'))
for _ in range(1000):
q.put(object())
support.check_sizeof(self, q, basesize + struct.calcsize(1024 * 'P'))

def test_reentrancy(self):
# bpo-14976: put() may be called reentrantly in an asynchronous
# callback.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`queue`: Fix :meth:`!SimpleQueue.__sizeof__` computation.
17 changes: 17 additions & 0 deletions Modules/_queuemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,22 @@ _queue_SimpleQueue_qsize_impl(simplequeueobject *self)
return RingBuf_Len(&self->buf);
}

/*[clinic input]
@critical_section
_queue.SimpleQueue.__sizeof__ -> Py_ssize_t
Returns size in memory, in bytes.
[clinic start generated code]*/

static Py_ssize_t
_queue_SimpleQueue___sizeof___impl(simplequeueobject *self)
/*[clinic end generated code: output=58ce4e3bbc078fd4 input=a3a7f05c9616598f]*/
{
Py_ssize_t res = sizeof(simplequeueobject);
res += self->buf.items_cap * sizeof(PyObject *);
return res;
}

static int
queue_traverse(PyObject *m, visitproc visit, void *arg)
{
Expand Down Expand Up @@ -534,6 +550,7 @@ static PyMethodDef simplequeue_methods[] = {
_QUEUE_SIMPLEQUEUE_PUT_METHODDEF
_QUEUE_SIMPLEQUEUE_PUT_NOWAIT_METHODDEF
_QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF
_QUEUE_SIMPLEQUEUE___SIZEOF___METHODDEF
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{NULL, NULL} /* sentinel */
Expand Down
32 changes: 31 additions & 1 deletion Modules/clinic/_queuemodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading