Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2fc568

Browse files
committed
Enhance documentation on malloc debug hooks
Issue #26564, #26516, #26563.
1 parent 3ca3342 commit c2fc568

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

Doc/c-api/memory.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,9 @@ Customize Memory Allocators
346346
- Detect write before the start of the buffer (buffer underflow)
347347
- Detect write after the end of the buffer (buffer overflow)
348348
- Check that the :term:`GIL <global interpreter lock>` is held when
349-
allocator functions of the :c:data:`PYMEM_DOMAIN_OBJ` domain (ex:
350-
:c:func:`PyObject_Malloc`) are called
349+
allocator functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex:
350+
:c:func:`PyObject_Malloc`) and :c:data:`PYMEM_DOMAIN_MEM` (ex:
351+
:c:func:`PyMem_Malloc`) domains are called
351352
352353
On error, the debug hooks use the :mod:`tracemalloc` module to get the
353354
traceback where a memory block was allocated. The traceback is only
@@ -361,7 +362,9 @@ Customize Memory Allocators
361362
.. versionchanged:: 3.6
362363
This function now also works on Python compiled in release mode.
363364
On error, the debug hooks now use :mod:`tracemalloc` to get the traceback
364-
where a memory block was allocated.
365+
where a memory block was allocated. The debug hooks now also check
366+
if the GIL is hold when functions of :c:data:`PYMEM_DOMAIN_OBJ` and
367+
:c:data:`PYMEM_DOMAIN_MEM` domains are called.
365368
366369
367370
.. _pymalloc:

Doc/using/cmdline.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -638,16 +638,20 @@ conflict.
638638
Install debug hooks:
639639

640640
* ``debug``: install debug hooks on top of the default memory allocator
641-
* ``malloc_debug``: same than ``malloc`` but also install debug hooks
642-
* ``pymalloc_debug``: same than ``malloc`` but also install debug hooks
641+
* ``malloc_debug``: same as ``malloc`` but also install debug hooks
642+
* ``pymalloc_debug``: same as ``pyalloc`` but also install debug hooks
643+
644+
When is compiled in release mode, the default is ``pymalloc``. When Python
645+
is compiled in debug mode, the default is ``pymalloc_debug``: debug hooks
646+
are installed.
647+
648+
If Python is configured without ``pymalloc`` support, ``pymalloc`` and
649+
``pymalloc_debug`` are not available, the default is ``malloc`` in release
650+
mode and ``malloc_debug`` in debug mode.
643651

644652
See the :c:func:`PyMem_SetupDebugHooks` function for debug hooks on Python
645653
memory allocators.
646654

647-
.. note::
648-
``pymalloc`` and ``pymalloc_debug`` are not available if Python is
649-
configured without ``pymalloc`` support.
650-
651655
.. versionadded:: 3.6
652656

653657

Doc/whatsnew/3.6.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ compiled in release mode using ``PYTHONMALLOC=debug``. Effects of debug hooks:
118118
* Detect write before the start of the buffer (buffer underflow)
119119
* Detect write after the end of the buffer (buffer overflow)
120120
* Check that the :term:`GIL <global interpreter lock>` is held when allocator
121-
functions of the :c:data:`PYMEM_DOMAIN_OBJ` domain (ex:
122-
:c:func:`PyObject_Malloc`) are called
121+
functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex: :c:func:`PyObject_Malloc`) and
122+
:c:data:`PYMEM_DOMAIN_MEM` (ex: :c:func:`PyMem_Malloc`) domains are called.
123+
124+
Checking if the GIL is hold is also a new feature of Python 3.6.
123125

124126
See the :c:func:`PyMem_SetupDebugHooks` function for debug hooks on Python
125127
memory allocators.

0 commit comments

Comments
 (0)