Mercurial > cpython-lru_cache-weakref
annotate Doc/api/refcounting.tex @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 946bebd00132 |
| children | 059740d52ae5 |
| rev | line source |
|---|---|
|
20390
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 \chapter{Reference Counting \label{countingRefs}} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 The macros in this section are used for managing reference counts |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 of Python objects. |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
7 |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 \begin{cfuncdesc}{void}{Py_INCREF}{PyObject *o} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 Increment the reference count for object \var{o}. The object must |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 not be \NULL; if you aren't sure that it isn't \NULL, use |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 \cfunction{Py_XINCREF()}. |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 \end{cfuncdesc} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 \begin{cfuncdesc}{void}{Py_XINCREF}{PyObject *o} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 Increment the reference count for object \var{o}. The object may be |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 \NULL, in which case the macro has no effect. |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 \end{cfuncdesc} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 \begin{cfuncdesc}{void}{Py_DECREF}{PyObject *o} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 Decrement the reference count for object \var{o}. The object must |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 not be \NULL; if you aren't sure that it isn't \NULL, use |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 \cfunction{Py_XDECREF()}. If the reference count reaches zero, the |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 object's type's deallocation function (which must not be \NULL) is |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
24 invoked. |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
25 |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 \warning{The deallocation function can cause arbitrary Python code |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 to be invoked (e.g. when a class instance with a \method{__del__()} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 method is deallocated). While exceptions in such code are not |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 propagated, the executed code has free access to all Python global |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 variables. This means that any object that is reachable from a |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
31 global variable should be in a consistent state before |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
32 \cfunction{Py_DECREF()} is invoked. For example, code to delete an |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
33 object from a list should copy a reference to the deleted object in |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
34 a temporary variable, update the list data structure, and then call |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
35 \cfunction{Py_DECREF()} for the temporary variable.} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
36 \end{cfuncdesc} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
38 \begin{cfuncdesc}{void}{Py_XDECREF}{PyObject *o} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
39 Decrement the reference count for object \var{o}. The object may be |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 \NULL, in which case the macro has no effect; otherwise the effect |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
41 is the same as for \cfunction{Py_DECREF()}, and the same warning |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
42 applies. |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
43 \end{cfuncdesc} |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
44 |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
45 The following functions or macros are only for use within the |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
46 interpreter core: \cfunction{_Py_Dealloc()}, |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
47 \cfunction{_Py_ForgetReference()}, \cfunction{_Py_NewReference()}, as |
|
946bebd00132
Break the Python/C API manual into smaller files by chapter. This manual
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
48 well as the global variable \cdata{_Py_RefTotal}. |
