GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||
GeezerVison is showing github.com — gh-85283: Add PyMem_RawMalloc() to the limited C API by vstinner · Pull Request #108570 · python/cpython Conversation
|
|
See also What To Do About Custom Allocators and the GIL? discussion. I don't think that PyMem_RawMalloc() is causing any trouble here. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If nogil/mimalloc is merged, will there be any reason to use these instead of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Code search using regex The following 34 projects use
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
What @vstinner wrote about nogil is accurate, except that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Just to clarify, the GIL must still be held when using the "mem" and "object" domains ( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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):
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@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? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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.) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Seems fine to me too. (To be clear, I don't think this affects PEP 703 one way or the other.) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
2cc3b9a to
ae2f355
Compare
|
I rebased my PR on the main branch. |
Sorry, something went wrong.
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.
ae2f355 to
940ddb1
Compare
|
I merged my PR, thanks for reviews. It should help many projects to use the limited C API. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…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 <[email protected]>
…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 <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.