Skip to content

Commit 0887b9c

Browse files
authored
GH-109369 Add vectorcall to PyLong_Type (GH-111642)
1 parent 4fe22c7 commit 0887b9c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Objects/longobject.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Python.h"
66
#include "pycore_bitutils.h" // _Py_popcount32()
77
#include "pycore_initconfig.h" // _PyStatus_OK()
8+
#include "pycore_call.h" // _PyObject_MakeTpCall
89
#include "pycore_long.h" // _Py_SmallInts
910
#include "pycore_object.h" // _PyObject_Init()
1011
#include "pycore_runtime.h" // _PY_NSMALLPOSINTS
@@ -6152,6 +6153,29 @@ int_is_integer_impl(PyObject *self)
61526153
Py_RETURN_TRUE;
61536154
}
61546155

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+
61556179
static PyMethodDef long_methods[] = {
61566180
{"conjugate", long_long_meth, METH_NOARGS,
61576181
"Returns self, the complex conjugate of any int."},
@@ -6289,6 +6313,7 @@ PyTypeObject PyLong_Type = {
62896313
0, /* tp_alloc */
62906314
long_new, /* tp_new */
62916315
PyObject_Free, /* tp_free */
6316+
.tp_vectorcall = long_vectorcall,
62926317
};
62936318

62946319
static PyTypeObject Int_InfoType;

0 commit comments

Comments
 (0)