
On Sat, 15 Jun 2013 03:54:50 +0200 Victor Stinner <victor.stinner@gmail.com> wrote:
The addition of PyMem_RawMalloc() is motivated by the issue #18203 (Replace calls to malloc() with PyMem_Malloc()). The goal is to be able to setup a custom allocator for *all* allocation made by Python, so malloc() should not be called directly. PyMem_RawMalloc() is required in places where the GIL is not held (ex: in os.getcwd() on Windows).
We already had this discussion on IRC and this argument isn't very convincing to me. If os.getcwd() doesn't hold the GIL while allocating memory, then you should fix it to hold the GIL while allocating memory. I don't like the idea of adding of third layer of allocation APIs. The dichotomy between PyObject_Malloc and PyMem_Malloc is already a bit gratuitous (i.e. not motivated by any actual real-world concern, as far as I can tell). As for the debug functions you added: PyMem_GetRawAllocators(), PyMem_SetRawAllocators(), PyMem_GetAllocators(), PyMem_SetAllocators(), PyMem_SetupDebugHooks(), _PyObject_GetArenaAllocators(), _PyObject_SetArenaAllocators(). Well, do we need all *7* of them? Can't you try to make that 2 or 3? Regards Antoine.