@@ -1031,25 +1031,29 @@ PyType_FromSpec_Alloc(PyTypeObject *type, Py_ssize_t nitems)
1031
1031
/* note that we need to add one, for the sentinel and space for the
1032
1032
provided tp-traverse: See bpo-40217 for more details */
1033
1033
1034
- if (PyType_IS_GC (type ))
1034
+ if (PyType_IS_GC (type )) {
1035
1035
obj = _PyObject_GC_Malloc (size );
1036
- else
1036
+ }
1037
+ else {
1037
1038
obj = (PyObject * )PyObject_MALLOC (size );
1039
+ }
1038
1040
1039
- if (obj == NULL )
1041
+ if (obj == NULL ) {
1040
1042
return PyErr_NoMemory ();
1041
-
1042
- obj = obj ;
1043
+ }
1043
1044
1044
1045
memset (obj , '\0' , size );
1045
1046
1046
- if (type -> tp_itemsize == 0 )
1047
+ if (type -> tp_itemsize == 0 ) {
1047
1048
(void )PyObject_INIT (obj , type );
1048
- else
1049
+ }
1050
+ else {
1049
1051
(void ) PyObject_INIT_VAR ((PyVarObject * )obj , type , nitems );
1052
+ }
1050
1053
1051
- if (PyType_IS_GC (type ))
1054
+ if (PyType_IS_GC (type )) {
1052
1055
_PyObject_GC_TRACK (obj );
1056
+ }
1053
1057
return obj ;
1054
1058
}
1055
1059
@@ -3066,7 +3070,11 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
3066
3070
*
3067
3071
* We store the user-provided traverse function at the end of the type
3068
3072
* (we have allocated space for it) so we can call it from our
3069
- * PyType_FromSpec_tp_traverse wrapper. */
3073
+ * PyType_FromSpec_tp_traverse wrapper.
3074
+ *
3075
+ * Check bpo-40217 for more information and rationale about this issue.
3076
+ *
3077
+ * */
3070
3078
3071
3079
type -> tp_traverse = PyType_FromSpec_tp_traverse ;
3072
3080
size_t _offset = _PyObject_VAR_SIZE (& PyType_Type , nmembers + 1 );
0 commit comments