@@ -13,10 +13,14 @@ objects.
13
13
14
14
.. c :function :: void Py_INCREF (PyObject *o)
15
15
16
- Increment the reference count for object *o *. The object must not be ``NULL ``; if
17
- you aren't sure that it isn't ``NULL ``, use :c:func: `Py_XINCREF `.
16
+ Increment the reference count for object *o *.
18
17
19
- See also :c:func: `Py_NewRef `.
18
+ This function is usually used to convert a :term: `borrowed reference ` to a
19
+ :term: `strong reference ` in-place. The :c:func: `Py_NewRef ` function can be
20
+ used to create a new :term: `strong reference `.
21
+
22
+ The object must not be ``NULL ``; if you aren't sure that it isn't
23
+ ``NULL ``, use :c:func: `Py_XINCREF `.
20
24
21
25
22
26
.. c :function :: void Py_XINCREF (PyObject *o)
@@ -29,9 +33,14 @@ objects.
29
33
30
34
.. c :function :: PyObject* Py_NewRef (PyObject *o)
31
35
32
- Increment the reference count of the object *o * and return the object *o *.
36
+ Create a new :term: `strong reference ` to an object: increment the reference
37
+ count of the object *o * and return the object *o *.
38
+
39
+ When the :term: `strong reference ` is no longer needed, :c:func: `Py_DECREF `
40
+ should be called on it to decrement the object reference count.
33
41
34
- The object *o * must not be ``NULL ``.
42
+ The object *o * must not be ``NULL ``; use :c:func: `Py_XNewRef ` if *o * can be
43
+ ``NULL ``.
35
44
36
45
For example::
37
46
@@ -42,6 +51,8 @@ objects.
42
51
43
52
self->attr = Py_NewRef(obj);
44
53
54
+ See also :c:func: `Py_INCREF `.
55
+
45
56
.. versionadded :: 3.10
46
57
47
58
@@ -56,10 +67,16 @@ objects.
56
67
57
68
.. c :function :: void Py_DECREF (PyObject *o)
58
69
59
- Decrement the reference count for object *o *. The object must not be ``NULL ``; if
60
- you aren't sure that it isn't ``NULL ``, use :c:func: `Py_XDECREF `. If the reference
61
- count reaches zero, the object's type's deallocation function (which must not be
62
- ``NULL ``) is invoked.
70
+ Decrement the reference count for object *o *.
71
+
72
+ If the reference count reaches zero, the object's type's deallocation
73
+ function (which must not be ``NULL ``) is invoked.
74
+
75
+ This function is usually used to delete a :term:`strong reference` before
76
+ exiting its scope.
77
+
78
+ The object must not be ``NULL``; if you aren' t sure that it isn' t ``NULL ``,
79
+ use :c:func: `Py_XDECREF `.
63
80
64
81
.. warning ::
65
82
0 commit comments