File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -2079,6 +2079,25 @@ Changes in the C API
2079
2079
#endif
2080
2080
}
2081
2081
2082
+ * Ensure that all custom ``tp_traverse `` functions of heap-allocated types
2083
+ visit the object parent **but not for subclasses **.
2084
+
2085
+ Example:
2086
+
2087
+ .. code-block :: c
2088
+
2089
+ int
2090
+ foo_traverse(foo_struct *self, visitproc visit, void *arg) {
2091
+ // Rest of the traverse function
2092
+ #if PY_VERSION_HEX >= 0x03080000
2093
+ // This was not needed before Python 3.8 (Python issue 35810)
2094
+ PyObject *type = Py_TYPE(instance);
2095
+ if (type->tp_traverse == (traverseproc)foo_traverse) {
2096
+ Py_VISIT(type);
2097
+ }
2098
+ #endif
2099
+ }
2100
+
2082
2101
(Contributed by Eddie Elizondo in :issue: `35810 `.)
2083
2102
2084
2103
* The :c:macro: `Py_DEPRECATED() ` macro has been implemented for MSVC.
Original file line number Diff line number Diff line change @@ -933,6 +933,35 @@ Changes in the Python API
933
933
(Contributed by Inada Naoki in :issue: `34538 `.)
934
934
935
935
936
+ Changes in the C API
937
+ --------------------
938
+
939
+ * Instances of heap-allocated types (such as those created with
940
+ :c:func: `PyType_FromSpec ` and similar APIs) hold a reference to their type
941
+ object since Python 3.8. As indicated in the "Changes in the C API" of Python
942
+ 3.8, for the vast majority of cases, there should be no side effect but for
943
+ types that have a custom :c:member: `~PyTypeObject.tp_traverse ` function,
944
+ ensure that all custom ``tp_traverse `` functions of heap-allocated types
945
+ visit the object parent **but not for subclasses **.
946
+
947
+ Example:
948
+
949
+ .. code-block :: c
950
+
951
+ int
952
+ foo_traverse(foo_struct *self, visitproc visit, void *arg) {
953
+ // Rest of the traverse function
954
+ #if PY_VERSION_HEX >= 0x03080000
955
+ // This was not needed before Python 3.8 (Python issue 35810 and 40217)
956
+ PyObject *type = Py_TYPE(instance);
957
+ if (type->tp_traverse == (traverseproc)foo_traverse) {
958
+ Py_VISIT(type);
959
+ }
960
+ #endif
961
+ }
962
+
963
+ (See :issue: `35810 ` and :issue: `40217 ` for more information.)
964
+
936
965
CPython bytecode changes
937
966
------------------------
938
967
Original file line number Diff line number Diff line change
1
+ Instances of types created with :c:func: `PyType_FromSpecWithBases ` will no
2
+ longer visit automaticallyt its class object when traversing references in
3
+ the garbage collector. The user is expected to manually visit the parent
4
+ class (but not for subclasses). Patch by Pablo Galindo.
You can’t perform that action at this time.
0 commit comments