On Fri, Jan 15 2021, Pablo Galindo Salgado wrote: >> Exactly, which is a bit a bummer. Considering Python provides 3 >> different memory allocator, it'd be great if there was some ability to >> be sure that PyObject_Malloc pointer are actually PyObject, not >> Py_GC_HEAD. > > The allocators are specialized based on the allocation strategy > and efficiency, not based on what are you going to use the memory > for. If you want to allocate a buffer using the object allocation > strategy because <insert reason> then nobody is preventing you > to use PyObject_Malloc(). Even if we sanitize the whole stdlib to > be conforming to "only objects are allocated using PyObejct_Malloc()", > 3rd party extension modules and other bests can do whatever, so you > can still crash if you decide to interpreter the output as an object.
Agreed. Then the correct endpoint would more likely to be PyObject_New(), but there's no way to intercept such calls for statistical analysis currently. And as you wrote, if some code decide to use PyMalloc() directly, then that memory won't be tracked. It sounds like the provided C API is a bit too low level for this, preventing any kind of statistical analysis of the allocation patterns. :( -- Julien Danjou # Free Software hacker # https://julien.danjou.info _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/UAWA2ADOQNI5IAGI3YVNE7EYKGSBIHZ5/ Code of Conduct: http://python.org/psf/codeofconduct/