PEP 445: fix examples

This commit is contained in:
Victor Stinner 2013-06-20 23:55:57 +02:00
parent ef6da7e6df
commit 5ad57e290b
1 changed files with 16 additions and 16 deletions

View File

@ -125,10 +125,10 @@ KB called "arenas".
Default allocators: Default allocators:
* ``PYALLOC_PYMEM_RAW``, ``PYALLOC_PYMEM``: ``malloc()``, * ``PYMEM_DOMAIN_RAW``, ``PYMEM_DOMAIN_MEM``: ``malloc()``,
``realloc()``, ``free()`` (and *ctx* is NULL); call ``malloc(1)`` when ``realloc()``, ``free()`` (and *ctx* is NULL); call ``malloc(1)`` when
requesting zero bytes requesting zero bytes
* ``PYALLOC_PYOBJECT``: *pymalloc* allocator which fall backs on * ``PYMEM_DOMAIN_OBJ``: *pymalloc* allocator which fall backs on
``PyMem_Malloc()`` for allocations larger than 512 bytes ``PyMem_Malloc()`` for allocations larger than 512 bytes
* *pymalloc* arena allocator: ``mmap()``, ``munmap()`` (and *ctx* is * *pymalloc* arena allocator: ``mmap()``, ``munmap()`` (and *ctx* is
NULL), or ``malloc()`` and ``free()`` if ``mmap()`` is not available NULL), or ``malloc()`` and ``free()`` if ``mmap()`` is not available
@ -226,8 +226,8 @@ and 10 bytes per memory mapping::
alloc.realloc = my_realloc; alloc.realloc = my_realloc;
alloc.free = my_free; alloc.free = my_free;
PyMem_SetAllocator(PYALLOC_PYMEM_RAW, &alloc); PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &alloc);
PyMem_SetAllocator(PYALLOC_PYMEM, &alloc); PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &alloc);
arena.ctx = &arena_padding; arena.ctx = &arena_padding;
arena.alloc = my_alloc_arena; arena.alloc = my_alloc_arena;
@ -238,7 +238,7 @@ and 10 bytes per memory mapping::
} }
.. warning:: .. warning::
Remove the call ``PyMem_SetAllocator(PYALLOC_PYMEM_RAW, &alloc)`` if Remove the call ``PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &alloc)`` if
the new allocator is not thread-safe. the new allocator is not thread-safe.
@ -280,15 +280,15 @@ Dummy example wasting 2 bytes per memory block::
alloc.realloc = my_realloc; alloc.realloc = my_realloc;
alloc.free = my_free; alloc.free = my_free;
PyMem_SetAllocator(PYALLOC_PYMEM_RAW, &alloc); PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &alloc);
PyMem_SetAllocator(PYALLOC_PYMEM, &alloc); PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &alloc);
PyMem_SetAllocator(PYALLOC_PYOBJECT, &alloc); PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &alloc);
PyMem_SetupDebugHooks(); PyMem_SetupDebugHooks();
} }
.. warning:: .. warning::
Remove the call ``PyMem_SetAllocator(PYALLOC_PYMEM_RAW, &alloc)`` if Remove the call ``PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &alloc)`` if
the new allocator is not thread-safe. the new allocator is not thread-safe.
@ -344,22 +344,22 @@ Example to setup hooks on all memory allocators::
alloc.malloc = hook_malloc; alloc.malloc = hook_malloc;
alloc.realloc = hook_realloc; alloc.realloc = hook_realloc;
alloc.free = hook_free; alloc.free = hook_free;
PyMem_GetAllocator(PYALLOC_PYMEM_RAW, &hook.raw); PyMem_GetAllocator(PYMEM_DOMAIN_RAW, &hook.raw);
PyMem_GetAllocator(PYALLOC_PYMEM, &hook.mem); PyMem_GetAllocator(PYMEM_DOMAIN_MEM, &hook.mem);
PyMem_GetAllocator(PYALLOC_PYOBJECT, &hook.obj); PyMem_GetAllocator(PYMEM_DOMAIN_OBJ, &hook.obj);
alloc.ctx = &hook.raw; alloc.ctx = &hook.raw;
PyMem_SetAllocator(PYALLOC_PYMEM_RAW, &alloc); PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &alloc);
alloc.ctx = &hook.mem; alloc.ctx = &hook.mem;
PyMem_SetAllocator(PYALLOC_PYMEM, &alloc); PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &alloc);
alloc.ctx = &hook.obj; alloc.ctx = &hook.obj;
PyMem_SetAllocator(PYALLOC_PYOBJECT, &alloc); PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &alloc);
} }
.. warning:: .. warning::
Remove the call ``PyMem_SetAllocator(PYALLOC_PYMEM_RAW, &alloc)`` if Remove the call ``PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &alloc)`` if
hooks are not thread-safe. hooks are not thread-safe.
.. note:: .. note::