@@ -9000,19 +9000,28 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co,
9000
9000
return 0 ;
9001
9001
}
9002
9002
9003
+ static int super_init_impl (PyObject * self , PyTypeObject * type , PyObject * obj );
9004
+
9003
9005
static int
9004
9006
super_init (PyObject * self , PyObject * args , PyObject * kwds )
9005
9007
{
9006
- superobject * su = (superobject * )self ;
9007
9008
PyTypeObject * type = NULL ;
9008
9009
PyObject * obj = NULL ;
9009
- PyTypeObject * obj_type = NULL ;
9010
9010
9011
9011
if (!_PyArg_NoKeywords ("super" , kwds ))
9012
9012
return -1 ;
9013
9013
if (!PyArg_ParseTuple (args , "|O!O:super" , & PyType_Type , & type , & obj ))
9014
9014
return -1 ;
9015
+ if (super_init_impl (self , type , obj ) < 0 ) {
9016
+ return -1 ;
9017
+ }
9018
+ return 0 ;
9019
+ }
9015
9020
9021
+ static inline int
9022
+ super_init_impl (PyObject * self , PyTypeObject * type , PyObject * obj ) {
9023
+ superobject * su = (superobject * )self ;
9024
+ PyTypeObject * obj_type = NULL ;
9016
9025
if (type == NULL ) {
9017
9026
/* Call super(), without args -- fill in from __class__
9018
9027
and first local variable on the stack. */
@@ -9072,6 +9081,47 @@ super_traverse(PyObject *self, visitproc visit, void *arg)
9072
9081
return 0 ;
9073
9082
}
9074
9083
9084
+ static PyObject *
9085
+ super_vectorcall (PyObject * self , PyObject * const * args ,
9086
+ size_t nargsf , PyObject * kwnames )
9087
+ {
9088
+ assert (PyType_Check (self ));
9089
+ if (!_PyArg_NoKwnames ("super" , kwnames )) {
9090
+ return NULL ;
9091
+ }
9092
+ Py_ssize_t nargs = PyVectorcall_NARGS (nargsf );
9093
+ if (!_PyArg_CheckPositional ("super()" , nargs , 0 , 2 )) {
9094
+ return NULL ;
9095
+ }
9096
+ PyTypeObject * type = NULL ;
9097
+ PyObject * obj = NULL ;
9098
+ PyTypeObject * self_type = (PyTypeObject * )self ;
9099
+ PyObject * su = self_type -> tp_alloc (self_type , 0 );
9100
+ if (su == NULL ) {
9101
+ return NULL ;
9102
+ }
9103
+ // 1 or 2 argument form super().
9104
+ if (nargs != 0 ) {
9105
+ PyObject * arg0 = args [0 ];
9106
+ if (!PyType_Check (arg0 )) {
9107
+ PyErr_Format (PyExc_TypeError ,
9108
+ "super() argument 1 must be a type, not %.200s" , Py_TYPE (arg0 )-> tp_name );
9109
+ goto fail ;
9110
+ }
9111
+ type = (PyTypeObject * )arg0 ;
9112
+ }
9113
+ if (nargs == 2 ) {
9114
+ obj = args [1 ];
9115
+ }
9116
+ if (super_init_impl (su , type , obj ) < 0 ) {
9117
+ goto fail ;
9118
+ }
9119
+ return su ;
9120
+ fail :
9121
+ Py_DECREF (su );
9122
+ return NULL ;
9123
+ }
9124
+
9075
9125
PyTypeObject PySuper_Type = {
9076
9126
PyVarObject_HEAD_INIT (& PyType_Type , 0 )
9077
9127
"super" , /* tp_name */
@@ -9114,4 +9164,5 @@ PyTypeObject PySuper_Type = {
9114
9164
PyType_GenericAlloc , /* tp_alloc */
9115
9165
PyType_GenericNew , /* tp_new */
9116
9166
PyObject_GC_Del , /* tp_free */
9167
+ .tp_vectorcall = (vectorcallfunc )super_vectorcall ,
9117
9168
};
0 commit comments