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/structures.rst

    r2 r391  
    1212All Python objects ultimately share a small number of fields at the beginning
    1313of the object's representation in memory.  These are represented by the
    14 :ctype:`PyObject` and :ctype:`PyVarObject` types, which are defined, in turn,
     14:c:type:`PyObject` and :c:type:`PyVarObject` types, which are defined, in turn,
    1515by the expansions of some macros also used, whether directly or indirectly, in
    1616the definition of all other Python objects.
    1717
    1818
    19 .. ctype:: PyObject
     19.. c:type:: PyObject
    2020
    2121   All object types are extensions of this type.  This is a type which
     
    2727
    2828
    29 .. ctype:: PyVarObject
    30 
    31    This is an extension of :ctype:`PyObject` that adds the :attr:`ob_size`
     29.. c:type:: PyVarObject
     30
     31   This is an extension of :c:type:`PyObject` that adds the :attr:`ob_size`
    3232   field.  This is only used for objects that have some notion of *length*.
    3333   This type does not often appear in the Python/C API.  It corresponds to the
    3434   fields defined by the expansion of the ``PyObject_VAR_HEAD`` macro.
    3535
    36 These macros are used in the definition of :ctype:`PyObject` and
    37 :ctype:`PyVarObject`:
    38 
    39 
    40 .. cmacro:: PyObject_HEAD
     36These macros are used in the definition of :c:type:`PyObject` and
     37:c:type:`PyVarObject`:
     38
     39
     40.. c:macro:: PyObject_HEAD
    4141
    4242   This is a macro which expands to the declarations of the fields of the
    43    :ctype:`PyObject` type; it is used when declaring new types which represent
     43   :c:type:`PyObject` type; it is used when declaring new types which represent
    4444   objects without a varying length.  The specific fields it expands to depend
    45    on the definition of :cmacro:`Py_TRACE_REFS`.  By default, that macro is
    46    not defined, and :cmacro:`PyObject_HEAD` expands to::
     45   on the definition of :c:macro:`Py_TRACE_REFS`.  By default, that macro is
     46   not defined, and :c:macro:`PyObject_HEAD` expands to::
    4747
    4848      Py_ssize_t ob_refcnt;
    4949      PyTypeObject *ob_type;
    5050
    51    When :cmacro:`Py_TRACE_REFS` is defined, it expands to::
     51   When :c:macro:`Py_TRACE_REFS` is defined, it expands to::
    5252
    5353      PyObject *_ob_next, *_ob_prev;
     
    5656
    5757
    58 .. cmacro:: PyObject_VAR_HEAD
     58.. c:macro:: PyObject_VAR_HEAD
    5959
    6060   This is a macro which expands to the declarations of the fields of the
    61    :ctype:`PyVarObject` type; it is used when declaring new types which
     61   :c:type:`PyVarObject` type; it is used when declaring new types which
    6262   represent objects with a length that varies from instance to instance.
    6363   This macro always expands to::
     
    6666      Py_ssize_t ob_size;
    6767
    68    Note that :cmacro:`PyObject_HEAD` is part of the expansion, and that its own
    69    expansion varies depending on the definition of :cmacro:`Py_TRACE_REFS`.
    70 
    71 
    72 .. cmacro:: PyObject_HEAD_INIT(type)
     68   Note that :c:macro:`PyObject_HEAD` is part of the expansion, and that its own
     69   expansion varies depending on the definition of :c:macro:`Py_TRACE_REFS`.
     70
     71
     72.. c:macro:: PyObject_HEAD_INIT(type)
    7373
    7474   This is a macro which expands to initialization values for a new
    75    :ctype:`PyObject` type.  This macro expands to::
     75   :c:type:`PyObject` type.  This macro expands to::
    7676
    7777      _PyObject_EXTRA_INIT
     
    7979
    8080
    81 .. cmacro:: PyVarObject_HEAD_INIT(type, size)
     81.. c:macro:: PyVarObject_HEAD_INIT(type, size)
    8282
    8383   This is a macro which expands to initialization values for a new
    84    :ctype:`PyVarObject` type, including the :attr:`ob_size` field.
     84   :c:type:`PyVarObject` type, including the :attr:`ob_size` field.
    8585   This macro expands to::
    8686
     
    8989
    9090
    91 .. ctype:: PyCFunction
     91.. c:type:: PyCFunction
    9292
    9393   Type of the functions used to implement most Python callables in C.
    94    Functions of this type take two :ctype:`PyObject\*` parameters and return
     94   Functions of this type take two :c:type:`PyObject\*` parameters and return
    9595   one such value.  If the return value is *NULL*, an exception shall have
    9696   been set.  If not *NULL*, the return value is interpreted as the return
     
    9999
    100100
    101 .. ctype:: PyMethodDef
     101.. c:type:: PyMethodDef
    102102
    103103   Structure used to describe a method of an extension type.  This structure has
     
    120120
    121121The :attr:`ml_meth` is a C function pointer.  The functions may be of different
    122 types, but they always return :ctype:`PyObject\*`.  If the function is not of
    123 the :ctype:`PyCFunction`, the compiler will require a cast in the method table.
    124 Even though :ctype:`PyCFunction` defines the first parameter as
    125 :ctype:`PyObject\*`, it is common that the method implementation uses a the
     122types, but they always return :c:type:`PyObject\*`.  If the function is not of
     123the :c:type:`PyCFunction`, the compiler will require a cast in the method table.
     124Even though :c:type:`PyCFunction` defines the first parameter as
     125:c:type:`PyObject\*`, it is common that the method implementation uses a the
    126126specific C type of the *self* object.
    127127
     
    137137
    138138   This is the typical calling convention, where the methods have the type
    139    :ctype:`PyCFunction`. The function expects two :ctype:`PyObject\*` values.
    140    The first one is the *self* object for methods; for module functions, it
    141    has the value given to :cfunc:`Py_InitModule4` (or *NULL* if
    142    :cfunc:`Py_InitModule` was used).  The second parameter (often called
    143    *args*) is a tuple object representing all arguments. This parameter is
    144    typically processed using :cfunc:`PyArg_ParseTuple` or
    145    :cfunc:`PyArg_UnpackTuple`.
     139   :c:type:`PyCFunction`. The function expects two :c:type:`PyObject\*` values.
     140   The first one is the *self* object for methods; for module functions, it is
     141   the module object.  The second parameter (often called *args*) is a tuple
     142   object representing all arguments.  This parameter is typically processed
     143   using :c:func:`PyArg_ParseTuple` or :c:func:`PyArg_UnpackTuple`.
    146144
    147145
    148146.. data:: METH_KEYWORDS
    149147
    150    Methods with these flags must be of type :ctype:`PyCFunctionWithKeywords`.
     148   Methods with these flags must be of type :c:type:`PyCFunctionWithKeywords`.
    151149   The function expects three parameters: *self*, *args*, and a dictionary of
    152150   all the keyword arguments.  The flag is typically combined with
    153151   :const:`METH_VARARGS`, and the parameters are typically processed using
    154    :cfunc:`PyArg_ParseTupleAndKeywords`.
     152   :c:func:`PyArg_ParseTupleAndKeywords`.
    155153
    156154
     
    159157   Methods without parameters don't need to check whether arguments are given if
    160158   they are listed with the :const:`METH_NOARGS` flag.  They need to be of type
    161    :ctype:`PyCFunction`.  When used with object methods, the first parameter is
    162    typically named ``self`` and will hold a reference to the object instance.
    163    In all cases the second parameter will be *NULL*.
     159   :c:type:`PyCFunction`.  The first parameter is typically named ``self`` and
     160   will hold a reference to the module or object instance.  In all cases the
     161   second parameter will be *NULL*.
    164162
    165163
     
    167165
    168166   Methods with a single object argument can be listed with the :const:`METH_O`
    169    flag, instead of invoking :cfunc:`PyArg_ParseTuple` with a ``"O"`` argument.
    170    They have the type :ctype:`PyCFunction`, with the *self* parameter, and a
    171    :ctype:`PyObject\*` parameter representing the single argument.
     167   flag, instead of invoking :c:func:`PyArg_ParseTuple` with a ``"O"`` argument.
     168   They have the type :c:type:`PyCFunction`, with the *self* parameter, and a
     169   :c:type:`PyObject\*` parameter representing the single argument.
    172170
    173171
     
    175173
    176174   This calling convention is deprecated.  The method must be of type
    177    :ctype:`PyCFunction`.  The second argument is *NULL* if no arguments are
     175   :c:type:`PyCFunction`.  The second argument is *NULL* if no arguments are
    178176   given, a single object if exactly one argument is given, and a tuple of
    179177   objects if more than one argument is given.  There is no way for a function
     
    228226
    229227
    230 .. ctype:: PyMemberDef
     228.. c:type:: PyMemberDef
    231229
    232230   Structure which describes an attribute of a type which corresponds to a C
     
    280278   =============== ==================
    281279
    282    :cmacro:`T_OBJECT` and :cmacro:`T_OBJECT_EX` differ in that
    283    :cmacro:`T_OBJECT` returns ``None`` if the member is *NULL* and
    284    :cmacro:`T_OBJECT_EX` raises an :exc:`AttributeError`.  Try to use
    285    :cmacro:`T_OBJECT_EX` over :cmacro:`T_OBJECT` because :cmacro:`T_OBJECT_EX`
     280   :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX` differ in that
     281   :c:macro:`T_OBJECT` returns ``None`` if the member is *NULL* and
     282   :c:macro:`T_OBJECT_EX` raises an :exc:`AttributeError`.  Try to use
     283   :c:macro:`T_OBJECT_EX` over :c:macro:`T_OBJECT` because :c:macro:`T_OBJECT_EX`
    286284   handles use of the :keyword:`del` statement on that attribute more correctly
    287    than :cmacro:`T_OBJECT`.
    288 
    289    :attr:`flags` can be 0 for write and read access or :cmacro:`READONLY` for
    290    read-only access.  Using :cmacro:`T_STRING` for :attr:`type` implies
    291    :cmacro:`READONLY`.  Only :cmacro:`T_OBJECT` and :cmacro:`T_OBJECT_EX`
     285   than :c:macro:`T_OBJECT`.
     286
     287   :attr:`flags` can be 0 for write and read access or :c:macro:`READONLY` for
     288   read-only access.  Using :c:macro:`T_STRING` for :attr:`type` implies
     289   :c:macro:`READONLY`.  Only :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX`
    292290   members can be deleted.  (They are set to *NULL*).
    293291
    294292
    295 .. cfunction:: PyObject* Py_FindMethod(PyMethodDef table[], PyObject *ob, char *name)
     293.. c:function:: PyObject* Py_FindMethod(PyMethodDef table[], PyObject *ob, char *name)
    296294
    297295   Return a bound method object for an extension type implemented in C.  This
    298    can be useful in the implementation of a :attr:`tp_getattro` or
    299    :attr:`tp_getattr` handler that does not use the
    300    :cfunc:`PyObject_GenericGetAttr` function.
     296   can be useful in the implementation of a :c:member:`~PyTypeObject.tp_getattro` or
     297   :c:member:`~PyTypeObject.tp_getattr` handler that does not use the
     298   :c:func:`PyObject_GenericGetAttr` function.
Note: See TracChangeset for help on using the changeset viewer.