Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/c-api/memory.rst

    r2 r391  
    4848
    4949To avoid memory corruption, extension writers should never try to operate on
    50 Python objects with the functions exported by the C library: :cfunc:`malloc`,
    51 :cfunc:`calloc`, :cfunc:`realloc` and :cfunc:`free`.  This will result in  mixed
     50Python objects with the functions exported by the C library: :c:func:`malloc`,
     51:c:func:`calloc`, :c:func:`realloc` and :c:func:`free`.  This will result in  mixed
    5252calls between the C allocator and the Python memory manager with fatal
    5353consequences, because they implement different algorithms and operate on
     
    9595
    9696
    97 .. cfunction:: void* PyMem_Malloc(size_t n)
    98 
    99    Allocates *n* bytes and returns a pointer of type :ctype:`void\*` to the
     97.. c:function:: void* PyMem_Malloc(size_t n)
     98
     99   Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the
    100100   allocated memory, or *NULL* if the request fails. Requesting zero bytes returns
    101    a distinct non-*NULL* pointer if possible, as if :cfunc:`PyMem_Malloc(1)` had
     101   a distinct non-*NULL* pointer if possible, as if ``PyMem_Malloc(1)`` had
    102102   been called instead. The memory will not have been initialized in any way.
    103103
    104104
    105 .. cfunction:: void* PyMem_Realloc(void *p, size_t n)
     105.. c:function:: void* PyMem_Realloc(void *p, size_t n)
    106106
    107107   Resizes the memory block pointed to by *p* to *n* bytes. The contents will be
    108108   unchanged to the minimum of the old and the new sizes. If *p* is *NULL*, the
    109    call is equivalent to :cfunc:`PyMem_Malloc(n)`; else if *n* is equal to zero,
     109   call is equivalent to ``PyMem_Malloc(n)``; else if *n* is equal to zero,
    110110   the memory block is resized but is not freed, and the returned pointer is
    111111   non-*NULL*.  Unless *p* is *NULL*, it must have been returned by a previous call
    112    to :cfunc:`PyMem_Malloc` or :cfunc:`PyMem_Realloc`. If the request fails,
    113    :cfunc:`PyMem_Realloc` returns *NULL* and *p* remains a valid pointer to the
     112   to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`. If the request fails,
     113   :c:func:`PyMem_Realloc` returns *NULL* and *p* remains a valid pointer to the
    114114   previous memory area.
    115115
    116116
    117 .. cfunction:: void PyMem_Free(void *p)
     117.. c:function:: void PyMem_Free(void *p)
    118118
    119119   Frees the memory block pointed to by *p*, which must have been returned by a
    120    previous call to :cfunc:`PyMem_Malloc` or :cfunc:`PyMem_Realloc`.  Otherwise, or
    121    if :cfunc:`PyMem_Free(p)` has been called before, undefined behavior occurs. If
     120   previous call to :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc`.  Otherwise, or
     121   if ``PyMem_Free(p)`` has been called before, undefined behavior occurs. If
    122122   *p* is *NULL*, no operation is performed.
    123123
     
    126126
    127127
    128 .. cfunction:: TYPE* PyMem_New(TYPE, size_t n)
    129 
    130    Same as :cfunc:`PyMem_Malloc`, but allocates ``(n * sizeof(TYPE))`` bytes of
    131    memory.  Returns a pointer cast to :ctype:`TYPE\*`.  The memory will not have
     128.. c:function:: TYPE* PyMem_New(TYPE, size_t n)
     129
     130   Same as :c:func:`PyMem_Malloc`, but allocates ``(n * sizeof(TYPE))`` bytes of
     131   memory.  Returns a pointer cast to :c:type:`TYPE\*`.  The memory will not have
    132132   been initialized in any way.
    133133
    134134
    135 .. cfunction:: TYPE* PyMem_Resize(void *p, TYPE, size_t n)
    136 
    137    Same as :cfunc:`PyMem_Realloc`, but the memory block is resized to ``(n *
    138    sizeof(TYPE))`` bytes.  Returns a pointer cast to :ctype:`TYPE\*`. On return,
     135.. c:function:: TYPE* PyMem_Resize(void *p, TYPE, size_t n)
     136
     137   Same as :c:func:`PyMem_Realloc`, but the memory block is resized to ``(n *
     138   sizeof(TYPE))`` bytes.  Returns a pointer cast to :c:type:`TYPE\*`. On return,
    139139   *p* will be a pointer to the new memory area, or *NULL* in the event of
    140140   failure.  This is a C preprocessor macro; p is always reassigned.  Save
     
    142142
    143143
    144 .. cfunction:: void PyMem_Del(void *p)
    145 
    146    Same as :cfunc:`PyMem_Free`.
     144.. c:function:: void PyMem_Del(void *p)
     145
     146   Same as :c:func:`PyMem_Free`.
    147147
    148148In addition, the following macro sets are provided for calling the Python memory
     
    151151versions and is therefore deprecated in extension modules.
    152152
    153 :cfunc:`PyMem_MALLOC`, :cfunc:`PyMem_REALLOC`, :cfunc:`PyMem_FREE`.
    154 
    155 :cfunc:`PyMem_NEW`, :cfunc:`PyMem_RESIZE`, :cfunc:`PyMem_DEL`.
     153:c:func:`PyMem_MALLOC`, :c:func:`PyMem_REALLOC`, :c:func:`PyMem_FREE`.
     154
     155:c:func:`PyMem_NEW`, :c:func:`PyMem_RESIZE`, :c:func:`PyMem_DEL`.
    156156
    157157
     
    202202
    203203In addition to the functions aimed at handling raw memory blocks from the Python
    204 heap, objects in Python are allocated and released with :cfunc:`PyObject_New`,
    205 :cfunc:`PyObject_NewVar` and :cfunc:`PyObject_Del`.
     204heap, objects in Python are allocated and released with :c:func:`PyObject_New`,
     205:c:func:`PyObject_NewVar` and :c:func:`PyObject_Del`.
    206206
    207207These will be explained in the next chapter on defining and implementing new
Note: See TracChangeset for help on using the changeset viewer.