File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,8 @@ The following functions and structs are used to create
124
124
If *bases* is a tuple, the created heap type contains all types contained
125
125
in it as base types.
126
126
127
- If *bases* is ``NULL``, the *Py_tp_base* slot is used instead.
127
+ If *bases* is ``NULL``, the *Py_tp_bases* slot is used instead.
128
+ If that also is ``NULL``, the *Py_tp_base* slot is used instead.
128
129
If that also is ``NULL``, the new type derives from :class:`object`.
129
130
130
131
This function calls :c:func:`PyType_Ready` on the new type.
@@ -194,7 +195,8 @@ The following functions and structs are used to create
194
195
* :c:member: `~PyBufferProcs.bf_getbuffer `
195
196
* :c:member: `~PyBufferProcs.bf_releasebuffer `
196
197
197
- Setting :c:data: `Py_tp_bases ` may be problematic on some platforms.
198
+ Setting :c:data: `Py_tp_bases ` or :c:data: `Py_tp_base ` may be
199
+ problematic on some platforms.
198
200
To avoid issues, use the *bases * argument of
199
201
:py:func: `PyType_FromSpecWithBases ` instead.
200
202
Original file line number Diff line number Diff line change @@ -2894,26 +2894,40 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
2894
2894
base = slot -> pfunc ;
2895
2895
else if (slot -> slot == Py_tp_bases ) {
2896
2896
bases = slot -> pfunc ;
2897
- Py_INCREF (bases );
2898
2897
}
2899
2898
}
2900
- if (!bases )
2899
+ if (!bases ) {
2901
2900
bases = PyTuple_Pack (1 , base );
2902
- if (!bases )
2901
+ if (!bases )
2902
+ goto fail ;
2903
+ }
2904
+ else if (!PyTuple_Check (bases )) {
2905
+ PyErr_SetString (PyExc_SystemError , "Py_tp_bases is not a tuple" );
2903
2906
goto fail ;
2907
+ }
2908
+ else {
2909
+ Py_INCREF (bases );
2910
+ }
2904
2911
}
2905
- else
2912
+ else if (!PyTuple_Check (bases )) {
2913
+ PyErr_SetString (PyExc_SystemError , "bases is not a tuple" );
2914
+ goto fail ;
2915
+ }
2916
+ else {
2906
2917
Py_INCREF (bases );
2918
+ }
2907
2919
2908
2920
/* Calculate best base, and check that all bases are type objects */
2909
2921
base = best_base (bases );
2910
2922
if (base == NULL ) {
2923
+ Py_DECREF (bases );
2911
2924
goto fail ;
2912
2925
}
2913
2926
if (!PyType_HasFeature (base , Py_TPFLAGS_BASETYPE )) {
2914
2927
PyErr_Format (PyExc_TypeError ,
2915
2928
"type '%.100s' is not an acceptable base type" ,
2916
2929
base -> tp_name );
2930
+ Py_DECREF (bases );
2917
2931
goto fail ;
2918
2932
}
2919
2933
@@ -2925,7 +2939,6 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
2925
2939
type -> tp_as_buffer = & res -> as_buffer ;
2926
2940
/* Set tp_base and tp_bases */
2927
2941
type -> tp_bases = bases ;
2928
- bases = NULL ;
2929
2942
Py_INCREF (base );
2930
2943
type -> tp_base = base ;
2931
2944
You can’t perform that action at this time.
0 commit comments