Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-85283: Add PyMem_RawMalloc() to the limited C API#108570
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
See alsoWhat To Do About Custom Allocators and the GIL? discussion. I don't think that PyMem_RawMalloc() is causing any trouble here. |
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. |
If nogil/mimalloc is merged, will there be any reason to use these instead of |
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). |
Code search using regex The following 34 projects use
|
What@vstinner wrote about nogil is accurate, except that |
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". |
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 aDPO thread and changed forgh-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 |
Just to clarify, the GIL must still be held whenusing the "mem" and "object" domains ( |
My long term goal doesn't concern the Python stdlib extensions, butjust convertingall C extensions towards the limited C API. Cython uses A quick search on PyPI top 5,000 projects tells me that113 projects use
Affected projects (113):
|
@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? |
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 blockthis PR though.) |
Seems fine to me too. (To be clear, I don't think this affects PEP 703 one way or the other.) |
2cc3b9a
toae2f355
CompareI rebased my PR on the main branch. |
Add PyMem_RawMalloc(), PyMem_RawCalloc(), PyMem_RawRealloc() andPyMem_RawFree() to the limited C API.These functions were added by Python 3.4 and are needed to portstdlib extensions to the limited C API, like grp and pwd.
I merged my PR, thanks for reviews. It should helpmany projects to use the limited C API. |
…8570)Add PyMem_RawMalloc(), PyMem_RawCalloc(), PyMem_RawRealloc() andPyMem_RawFree() to the limited C API.These functions were added by Python 3.4 and are needed to portstdlib 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() andPyMem_RawFree() to the limited C API.These functions were added by Python 3.4 and are needed to portstdlib extensions to the limited C API, like grp and pwd.Co-authored-by: Erlend E. Aasland <erlend@python.org>
Uh oh!
There was an error while loading.Please reload this page.
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/