|
5 | 5 | #include "Python.h" |
6 | 6 | #include "pycore_bitutils.h" // _Py_popcount32() |
7 | 7 | #include "pycore_initconfig.h" // _PyStatus_OK() |
| 8 | +#include "pycore_call.h" // _PyObject_MakeTpCall |
8 | 9 | #include "pycore_long.h" // _Py_SmallInts |
9 | 10 | #include "pycore_object.h" // _PyObject_Init() |
10 | 11 | #include "pycore_runtime.h" // _PY_NSMALLPOSINTS |
@@ -6152,6 +6153,29 @@ int_is_integer_impl(PyObject *self) |
6152 | 6153 | Py_RETURN_TRUE; |
6153 | 6154 | } |
6154 | 6155 |
|
| 6156 | +static PyObject * |
| 6157 | +long_vectorcall(PyObject *type, PyObject * const*args, |
| 6158 | + size_t nargsf, PyObject *kwnames) |
| 6159 | +{ |
| 6160 | + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
| 6161 | + if (kwnames != NULL) { |
| 6162 | + PyThreadState *tstate = PyThreadState_GET(); |
| 6163 | + return _PyObject_MakeTpCall(tstate, type, args, nargs, kwnames); |
| 6164 | + } |
| 6165 | + switch (nargs) { |
| 6166 | + case 0: |
| 6167 | + return _PyLong_GetZero(); |
| 6168 | + case 1: |
| 6169 | + return PyNumber_Long(args[0]); |
| 6170 | + case 2: |
| 6171 | + return long_new_impl(_PyType_CAST(type), args[0], args[1]); |
| 6172 | + default: |
| 6173 | + return PyErr_Format(PyExc_TypeError, |
| 6174 | + "int expected at most 2 argument%s, got %zd", |
| 6175 | + nargs); |
| 6176 | + } |
| 6177 | +} |
| 6178 | + |
6155 | 6179 | static PyMethodDef long_methods[] = { |
6156 | 6180 | {"conjugate", long_long_meth, METH_NOARGS, |
6157 | 6181 | "Returns self, the complex conjugate of any int."}, |
@@ -6289,6 +6313,7 @@ PyTypeObject PyLong_Type = { |
6289 | 6313 | 0, /* tp_alloc */ |
6290 | 6314 | long_new, /* tp_new */ |
6291 | 6315 | PyObject_Free, /* tp_free */ |
| 6316 | + .tp_vectorcall = long_vectorcall, |
6292 | 6317 | }; |
6293 | 6318 |
|
6294 | 6319 | static PyTypeObject Int_InfoType; |
|
0 commit comments