gh-140025: Fix queue.SimpleQueue.__sizeof__()#143137
gh-140025: Fix queue.SimpleQueue.__sizeof__()#143137kumaraditya303 merged 11 commits intopython:mainfrom
queue.SimpleQueue.__sizeof__()#143137Conversation
| static PyObject * | ||
| simplequeue_sizeof(PyObject *op, PyObject *Py_UNUSED(ignored)) | ||
| { |
There was a problem hiding this comment.
This needs a critical section (a lock for the queue). The simplest way is to use "Argument Clinic" like the other functions.
Something like:
/*[clinic input]
@critical_section
_queue.SimpleQueue.__sizeof__ -> Py_ssize_t
Returns size in memory, in bytes.
[clinic start generated code]*/
static Py_ssize_t
simplequeue_sizeof_impl(simplequeueobject *self)
/*[clinic end generated code: output=3303f008eaa6a0a5 input=9b51620c76fc4507]*/
Then run make clinic to regenerate the bindings.
| _QUEUE_SIMPLEQUEUE_PUT_METHODDEF | ||
| _QUEUE_SIMPLEQUEUE_PUT_NOWAIT_METHODDEF | ||
| _QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF | ||
| {"__sizeof__", (PyCFunction)simplequeue_sizeof, METH_NOARGS, NULL}, |
There was a problem hiding this comment.
You'll also need to change this to use the Argument Clinic methoddef (like above).
|
|
||
| def test_simplequeue_sizeof_reflects_buffer_growth(self): | ||
| q = self.type2test() | ||
| before = q.__sizeof__() |
There was a problem hiding this comment.
A few changes:
- Don't use ctypes (no support for that in wasi)
- Use
support.calcobjsize - Use
sys.getsizeof()instead of calling__sizeof__directly
|
@colesbury thanks for the feedback. i've applied changes as per suggestions, please let me know if this needs further improvement. |
Please make it so that the CI is green before requesting a new review. |
queue.SimpleQueue.__sizeof__()
|
@picnixz ci is now green. @colesbury could you please review now if you get a chance. Thanks! |
colesbury
left a comment
There was a problem hiding this comment.
Thanks a few comments below
| from test.support import gc_collect, bigmemtest | ||
| from test.support import import_helper | ||
| from test.support import threading_helper | ||
| import sys |
There was a problem hiding this comment.
Move import sys up between import random and import threading
There was a problem hiding this comment.
sure, I missed that. I thought running pre-commit run would take care of it.
| [clinic start generated code]*/ | ||
|
|
||
| static Py_ssize_t | ||
| _queue_SimpleQueue___sizeof___impl(simplequeueobject *self) |
There was a problem hiding this comment.
Can you put the definition of this method after the definition of qsize please?
There was a problem hiding this comment.
Sure, I’ll update this.
Co-authored-by: Sam Gross <colesbury@gmail.com>
…OX58_.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…OX58_.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
Please let me know if my approach or fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.
Thankyou !
queue.SimpleQueue.__sizeof__()ignores the underlying data structure #140025