@@ -10159,7 +10159,7 @@ wrap_init(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
1015910159}
1016010160
1016110161static PyObject *
10162- tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds )
10162+ tp_new_wrapper(PyObject *self, PyObject *const * args, Py_ssize_t nargs, PyObject *kwnames )
1016310163{
1016410164 PyTypeObject *staticbase;
1016510165 PyObject *arg0, *res;
@@ -10171,13 +10171,13 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
1017110171 }
1017210172 PyTypeObject *type = (PyTypeObject *)self;
1017310173
10174- if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 1) {
10174+ if (nargs < 1) {
1017510175 PyErr_Format(PyExc_TypeError,
1017610176 "%s.__new__(): not enough arguments",
1017710177 type->tp_name);
1017810178 return NULL;
1017910179 }
10180- arg0 = PyTuple_GET_ITEM( args, 0) ;
10180+ arg0 = args[0] ;
1018110181 if (!PyType_Check(arg0)) {
1018210182 PyErr_Format(PyExc_TypeError,
1018310183 "%s.__new__(X): X is not a type object (%s)",
@@ -10219,16 +10219,26 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
1021910219 return NULL;
1022010220 }
1022110221
10222- args = PyTuple_GetSlice (args, 1, PyTuple_GET_SIZE(args) );
10223- if (args == NULL)
10222+ PyObject *args_tuple = PyTuple_FromArray (args + 1, nargs - 1 );
10223+ if (args_tuple == NULL) {
1022410224 return NULL;
10225- res = type->tp_new(subtype, args, kwds);
10226- Py_DECREF(args);
10225+ }
10226+ PyObject *kwds = NULL;
10227+ if (kwnames != NULL) {
10228+ kwds = _PyStack_AsDict(args + nargs, kwnames);
10229+ if (kwds == NULL) {
10230+ Py_DECREF(args_tuple);
10231+ return NULL;
10232+ }
10233+ }
10234+ res = type->tp_new(subtype, args_tuple, kwds);
10235+ Py_DECREF(args_tuple);
10236+ Py_XDECREF(kwds);
1022710237 return res;
1022810238}
1022910239
1023010240static struct PyMethodDef tp_new_methoddef[] = {
10231- {"__new__", _PyCFunction_CAST(tp_new_wrapper), METH_VARARGS |METH_KEYWORDS,
10241+ {"__new__", _PyCFunction_CAST(tp_new_wrapper), METH_FASTCALL |METH_KEYWORDS,
1023210242 PyDoc_STR("__new__($type, *args, **kwargs)\n--\n\n"
1023310243 "Create and return a new object. "
1023410244 "See help(type) for accurate signature.")},
0 commit comments