File tree 2 files changed +29
-4
lines changed 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -73,11 +73,31 @@ Macros
73
73
74
74
Border line:
75
75
76
- * ``Py_TYPE() ``
77
76
* ``Py_SETREF() ``, ``Py_XSETREF() ``: the caller has to manually increment the
78
77
reference counter of the new value
79
78
* ``N `` format of ``Py_BuildValue() ``?
80
79
80
+
81
+ .. _py-type :
82
+
83
+ Py_TYPE() corner case
84
+ =====================
85
+
86
+ Technically, ``Py_TYPE() `` returns a borrowed reference to a ``PyTypeObject* ``.
87
+ In pratice, for heap types, an instance holds already a strong reference
88
+ to the type in ``PyObject.ob_type ``. For static types, instances use a borrowed
89
+ reference, but static types are never destroyed.
90
+
91
+ Hugh Fisher summarized:
92
+
93
+ It don't think it is worth forcing every C extension module to be rewritten,
94
+ and incur a performance hit, to eliminate a rare bug from badly written
95
+ code.
96
+
97
+ See the discussion on capi-sig: `Open questions about borrowed reference.
98
+ <https://mail.python.org/mm3/archives/list/capi-sig@python.org/thread/V5EMBIIJFJGJGBQPLCFFXCHAUFNTA45H/> `_
99
+ (Sept 2018).
100
+
81
101
Borrowed references: PyEval_GetFuncName()
82
102
=========================================
83
103
Original file line number Diff line number Diff line change @@ -34,15 +34,20 @@ New functions
34
34
reference on the item
35
35
* ``PySequence_Fast_GetItemRef() ``
36
36
* ``PyStructSequence_SetItemRef() ``
37
- * ``Py_GetType() ``: similar to ``Py_TYPE() `` but returns a strong reference
38
- * ``Py_TYPE_IS(ob, type) ``: equivalent to ``Py_TYPE(ob) == type ``
39
- * ``%T `` format for ``PyUnicode_FromFormat() ``
40
37
41
38
XXX private functions:
42
39
43
40
* ``_Py_SET_TYPE() ``: see :ref: `Implement a PyTypeObject in C <impl-pytype >`
44
41
* ``_Py_SET_SIZE() ``
45
42
43
+ If we decide that :ref: `Py_TYPE() <py-type >` should go away, 3 more
44
+ functions/features are needed:
45
+
46
+ * ``Py_GetType() ``: similar to ``Py_TYPE() `` but returns a strong reference
47
+ * ``Py_TYPE_IS(ob, type) ``: equivalent to ``Py_TYPE(ob) == type ``
48
+ * ``%T `` format for ``PyUnicode_FromFormat() ``
49
+
50
+
46
51
Non-goal
47
52
========
48
53
You can’t perform that action at this time.
0 commit comments