@@ -2941,14 +2941,13 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
2941
2941
PyErr_SetString (PyExc_RuntimeError , "invalid slot offset" );
2942
2942
goto fail ;
2943
2943
}
2944
- if (slot -> slot == Py_tp_base || slot -> slot == Py_tp_bases )
2944
+ else if (slot -> slot == Py_tp_base || slot -> slot == Py_tp_bases ) {
2945
2945
/* Processed above */
2946
2946
continue ;
2947
- * (void * * )(res_start + slotoffsets [slot -> slot ]) = slot -> pfunc ;
2948
-
2949
- /* need to make a copy of the docstring slot, which usually
2950
- points to a static string literal */
2951
- if (slot -> slot == Py_tp_doc ) {
2947
+ }
2948
+ else if (slot -> slot == Py_tp_doc ) {
2949
+ /* For the docstring slot, which usually points to a static string
2950
+ literal, we need to make a copy */
2952
2951
const char * old_doc = _PyType_DocWithoutSignature (type -> tp_name , slot -> pfunc );
2953
2952
size_t len = strlen (old_doc )+ 1 ;
2954
2953
char * tp_doc = PyObject_MALLOC (len );
@@ -2960,13 +2959,16 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
2960
2959
memcpy (tp_doc , old_doc , len );
2961
2960
type -> tp_doc = tp_doc ;
2962
2961
}
2963
-
2964
- /* Move the slots to the heap type itself */
2965
- if (slot -> slot == Py_tp_members ) {
2962
+ else if (slot -> slot == Py_tp_members ) {
2963
+ /* Move the slots to the heap type itself */
2966
2964
size_t len = Py_TYPE (type )-> tp_itemsize * nmembers ;
2967
2965
memcpy (PyHeapType_GET_MEMBERS (res ), slot -> pfunc , len );
2968
2966
type -> tp_members = PyHeapType_GET_MEMBERS (res );
2969
2967
}
2968
+ else {
2969
+ /* Copy other slots directly */
2970
+ * (void * * )(res_start + slotoffsets [slot -> slot ]) = slot -> pfunc ;
2971
+ }
2970
2972
}
2971
2973
if (type -> tp_dealloc == NULL ) {
2972
2974
/* It's a heap type, so needs the heap types' dealloc.
0 commit comments