Uh oh!
There was an error while loading. Please reload this page.
gh-85283: Add PyMem_RawMalloc() to the limited C API - #108570
Conversation
92484f4 to
fa30035Comparevstinner
commented
Aug 28, 2023
See also What To Do About Custom Allocators and the GIL? discussion. I don't think that PyMem_RawMalloc() is causing any trouble here. |
vstinner
commented
Aug 28, 2023
The alternative is to no add these functions to limited C API, and convert grp and pwd to libc malloc() and free(). The drawback is that tracemalloc will no longer be able to trace their memory allocation. |
encukou
commented
Aug 31, 2023
If nogil/mimalloc is merged, will there be any reason to use these instead of |
vstinner
commented
Sep 1, 2023
I understood that with the nogil implementation:
For me, PyMem_RawMalloc() will still be different than PyMem_RawMalloc(). On Python 3.12 and older, PyMem_RawMalloc() must be used if the GIL is not held. Such case was not compatible with the limited C API, since PyMem_RawMalloc() is not part of Python 3.12 limited C API. Having PyMem_RawMalloc() in the limited C API may help compatibility with older Python versions (which use the regular API, not the limited API). cc @colesbury |
vstinner
commented
Sep 1, 2023
Code search using regex The following 34 projects use
|
colesbury
commented
Sep 1, 2023
What @vstinner wrote about nogil is accurate, except that |
vstinner
commented
Sep 1, 2023
The important information is that even with nogil, PyMem_RawMalloc() still fit an use case which is not fitted by PyMem_Malloc(). So it's still relevant to use PyMem_RawMalloc() in "nogil Python". |
ericsnowcurrently
commented
Sep 6, 2023
This shouldn't affect per-interpreter GIL since the only specific concern there is thread-safety. Note that the docs now (3.12+) say that all 3 domains must be thread-safe. (This was discussed in a DPO thread and changed for gh-105766.) So does the rationale here apply to the other two memory domains ( As to my opinion about this change, I think we should be a bit more cautious about expanding the limited API until we have more clarity on where we're going with the C-API (hopefully at the core sprint). I'm particularly reluctant to add |
ericsnowcurrently
commented
Sep 6, 2023
Just to clarify, the GIL must still be held when using the "mem" and "object" domains ( |
vstinner
commented
Sep 6, 2023
My long term goal doesn't concern the Python stdlib extensions, but just converting all C extensions towards the limited C API. Cython uses A quick search on PyPI top 5,000 projects tells me that 113 projects use Affected projects (113):
|
vstinner
commented
Sep 13, 2023
@encukou@colesbury@ericsnowcurrently: I'm sorry, I didn't get your opinion about adding these 4 functions to the limited C API. Do you approve this change? Or are you against it? |
ericsnowcurrently
commented
Sep 13, 2023
For just (In general, however, I think we should slow down on moving things to the limited API until after the discussions at the core sprint next month. I'm not saying that should block this PR though.) |
colesbury
commented
Sep 13, 2023
Seems fine to me too. (To be clear, I don't think this affects PEP 703 one way or the other.) |
2cc3b9a to
ae2f355Comparevstinner
commented
Sep 30, 2023
I rebased my PR on the main branch. |
Add PyMem_RawMalloc(), PyMem_RawCalloc(), PyMem_RawRealloc() and PyMem_RawFree() to the limited C API. These functions were added by Python 3.4 and are needed to port stdlib extensions to the limited C API, like grp and pwd.
ae2f355 to
940ddb1Comparevstinner
commented
Oct 17, 2023
I merged my PR, thanks for reviews. It should help many projects to use the limited C API. |
…8570) Add PyMem_RawMalloc(), PyMem_RawCalloc(), PyMem_RawRealloc() and PyMem_RawFree() to the limited C API. These functions were added by Python 3.4 and are needed to port stdlib extensions to the limited C API, like grp and pwd. Co-authored-by: Erlend E. Aasland <erlend@python.org>
…8570) Add PyMem_RawMalloc(), PyMem_RawCalloc(), PyMem_RawRealloc() and PyMem_RawFree() to the limited C API. These functions were added by Python 3.4 and are needed to port stdlib extensions to the limited C API, like grp and pwd. Co-authored-by: Erlend E. Aasland <erlend@python.org>
Add PyMem_RawMalloc(), PyMem_RawCalloc(), PyMem_RawRealloc() and PyMem_RawFree() to the limited C API.
These functions were added by Python 3.4 and are needed to port stdlib extensions to the limited C API, like grp and pwd.
📚 Documentation preview 📚: https://cpython-previews--108570.org.readthedocs.build/