Changeset 391 for python/trunk/Doc/c-api/gcsupport.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/c-api/gcsupport.rst
r2 r391 16 16 .. Cycle Collector (XXX not found: ../ext/example-cycle-support.html)". 17 17 18 To create a container type, the : attr:`tp_flags` field of the type object must18 To create a container type, the :c:member:`~PyTypeObject.tp_flags` field of the type object must 19 19 include the :const:`Py_TPFLAGS_HAVE_GC` and provide an implementation of the 20 : attr:`tp_traverse` handler. If instances of the type are mutable, a21 : attr:`tp_clear` implementation must also be provided.20 :c:member:`~PyTypeObject.tp_traverse` handler. If instances of the type are mutable, a 21 :c:member:`~PyTypeObject.tp_clear` implementation must also be provided. 22 22 23 23 … … 31 31 Constructors for container types must conform to two rules: 32 32 33 #. The memory for the object must be allocated using :c func:`PyObject_GC_New`34 or :c func:`PyObject_GC_VarNew`.33 #. The memory for the object must be allocated using :c:func:`PyObject_GC_New` 34 or :c:func:`PyObject_GC_NewVar`. 35 35 36 36 #. Once all the fields which may contain references to other containers are 37 initialized, it must call :c func:`PyObject_GC_Track`.37 initialized, it must call :c:func:`PyObject_GC_Track`. 38 38 39 39 40 .. c function:: TYPE* PyObject_GC_New(TYPE, PyTypeObject *type)40 .. c:function:: TYPE* PyObject_GC_New(TYPE, PyTypeObject *type) 41 41 42 Analogous to :c func:`PyObject_New` but for container objects with the42 Analogous to :c:func:`PyObject_New` but for container objects with the 43 43 :const:`Py_TPFLAGS_HAVE_GC` flag set. 44 44 45 45 46 .. c function:: TYPE* PyObject_GC_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)46 .. c:function:: TYPE* PyObject_GC_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size) 47 47 48 Analogous to :c func:`PyObject_NewVar` but for container objects with the48 Analogous to :c:func:`PyObject_NewVar` but for container objects with the 49 49 :const:`Py_TPFLAGS_HAVE_GC` flag set. 50 50 51 51 .. versionchanged:: 2.5 52 This function used an :c type:`int` type for *size*. This might require52 This function used an :c:type:`int` type for *size*. This might require 53 53 changes in your code for properly supporting 64-bit systems. 54 54 55 55 56 .. c function:: TYPE* PyObject_GC_Resize(TYPE, PyVarObject *op, Py_ssize_t newsize)56 .. c:function:: TYPE* PyObject_GC_Resize(TYPE, PyVarObject *op, Py_ssize_t newsize) 57 57 58 Resize an object allocated by :c func:`PyObject_NewVar`. Returns the58 Resize an object allocated by :c:func:`PyObject_NewVar`. Returns the 59 59 resized object or *NULL* on failure. 60 60 61 61 .. versionchanged:: 2.5 62 This function used an :c type:`int` type for *newsize*. This might62 This function used an :c:type:`int` type for *newsize*. This might 63 63 require changes in your code for properly supporting 64-bit systems. 64 64 65 65 66 .. c function:: void PyObject_GC_Track(PyObject *op)66 .. c:function:: void PyObject_GC_Track(PyObject *op) 67 67 68 68 Adds the object *op* to the set of container objects tracked by the 69 69 collector. The collector can run at unexpected times so objects must be 70 70 valid while being tracked. This should be called once all the fields 71 followed by the : attr:`tp_traverse` handler become valid, usually near the71 followed by the :c:member:`~PyTypeObject.tp_traverse` handler become valid, usually near the 72 72 end of the constructor. 73 73 74 74 75 .. c function:: void _PyObject_GC_TRACK(PyObject *op)75 .. c:function:: void _PyObject_GC_TRACK(PyObject *op) 76 76 77 A macro version of :c func:`PyObject_GC_Track`. It should not be used for77 A macro version of :c:func:`PyObject_GC_Track`. It should not be used for 78 78 extension modules. 79 79 … … 82 82 83 83 #. Before fields which refer to other containers are invalidated, 84 :c func:`PyObject_GC_UnTrack` must be called.84 :c:func:`PyObject_GC_UnTrack` must be called. 85 85 86 #. The object's memory must be deallocated using :c func:`PyObject_GC_Del`.86 #. The object's memory must be deallocated using :c:func:`PyObject_GC_Del`. 87 87 88 88 89 .. c function:: void PyObject_GC_Del(void *op)89 .. c:function:: void PyObject_GC_Del(void *op) 90 90 91 Releases memory allocated to an object using :c func:`PyObject_GC_New` or92 :c func:`PyObject_GC_NewVar`.91 Releases memory allocated to an object using :c:func:`PyObject_GC_New` or 92 :c:func:`PyObject_GC_NewVar`. 93 93 94 94 95 .. c function:: void PyObject_GC_UnTrack(void *op)95 .. c:function:: void PyObject_GC_UnTrack(void *op) 96 96 97 97 Remove the object *op* from the set of container objects tracked by the 98 collector. Note that :c func:`PyObject_GC_Track` can be called again on98 collector. Note that :c:func:`PyObject_GC_Track` can be called again on 99 99 this object to add it back to the set of tracked objects. The deallocator 100 (: attr:`tp_dealloc` handler) should call this for the object before any of101 the fields used by the : attr:`tp_traverse` handler become invalid.100 (:c:member:`~PyTypeObject.tp_dealloc` handler) should call this for the object before any of 101 the fields used by the :c:member:`~PyTypeObject.tp_traverse` handler become invalid. 102 102 103 103 104 .. c function:: void _PyObject_GC_UNTRACK(PyObject *op)104 .. c:function:: void _PyObject_GC_UNTRACK(PyObject *op) 105 105 106 A macro version of :c func:`PyObject_GC_UnTrack`. It should not be used for106 A macro version of :c:func:`PyObject_GC_UnTrack`. It should not be used for 107 107 extension modules. 108 108 109 The : attr:`tp_traverse` handler accepts a function parameter of this type:109 The :c:member:`~PyTypeObject.tp_traverse` handler accepts a function parameter of this type: 110 110 111 111 112 .. c type:: int (*visitproc)(PyObject *object, void *arg)112 .. c:type:: int (*visitproc)(PyObject *object, void *arg) 113 113 114 Type of the visitor function passed to the : attr:`tp_traverse` handler.114 Type of the visitor function passed to the :c:member:`~PyTypeObject.tp_traverse` handler. 115 115 The function should be called with an object to traverse as *object* and 116 the third parameter to the : attr:`tp_traverse` handler as *arg*. The116 the third parameter to the :c:member:`~PyTypeObject.tp_traverse` handler as *arg*. The 117 117 Python core uses several visitor functions to implement cyclic garbage 118 118 detection; it's not expected that users will need to write their own 119 119 visitor functions. 120 120 121 The : attr:`tp_traverse` handler must have the following type:121 The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type: 122 122 123 123 124 .. c type:: int (*traverseproc)(PyObject *self, visitproc visit, void *arg)124 .. c:type:: int (*traverseproc)(PyObject *self, visitproc visit, void *arg) 125 125 126 126 Traversal function for a container object. Implementations must call the … … 131 131 returned immediately. 132 132 133 To simplify writing : attr:`tp_traverse` handlers, a :cfunc:`Py_VISIT` macro is134 provided. In order to use this macro, the : attr:`tp_traverse` implementation133 To simplify writing :c:member:`~PyTypeObject.tp_traverse` handlers, a :c:func:`Py_VISIT` macro is 134 provided. In order to use this macro, the :c:member:`~PyTypeObject.tp_traverse` implementation 135 135 must name its arguments exactly *visit* and *arg*: 136 136 137 137 138 .. c function:: void Py_VISIT(PyObject *o)138 .. c:function:: void Py_VISIT(PyObject *o) 139 139 140 140 Call the *visit* callback, with arguments *o* and *arg*. If *visit* returns 141 a non-zero value, then return it. Using this macro, : attr:`tp_traverse`141 a non-zero value, then return it. Using this macro, :c:member:`~PyTypeObject.tp_traverse` 142 142 handlers look like:: 143 143 … … 152 152 .. versionadded:: 2.4 153 153 154 The : attr:`tp_clear` handler must be of the :ctype:`inquiry` type, or *NULL*154 The :c:member:`~PyTypeObject.tp_clear` handler must be of the :c:type:`inquiry` type, or *NULL* 155 155 if the object is immutable. 156 156 157 157 158 .. c type:: int (*inquiry)(PyObject *self)158 .. c:type:: int (*inquiry)(PyObject *self) 159 159 160 160 Drop references that may have created reference cycles. Immutable objects 161 161 do not have to define this method since they can never directly create 162 162 reference cycles. Note that the object must still be valid after calling 163 this method (don't just call :c func:`Py_DECREF` on a reference). The163 this method (don't just call :c:func:`Py_DECREF` on a reference). The 164 164 collector will call this method if it detects that this object is involved 165 165 in a reference cycle.
Note:
See TracChangeset
for help on using the changeset viewer.