summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-11-02 15:07:47 (GMT)
committerGitHub <noreply@github.com>2023-11-02 15:07:47 (GMT)
commit0887b9ce8b5b4f9ecdef014b9329da78a46c9f42 (patch)
treea0d0abbf834fde22391c2312cda9250d62d05d09 /Objects
parent4fe22c73770fe86b01ef7a4f1f38e7e925c0e090 (diff)
downloadcpython-0887b9ce8b5b4f9ecdef014b9329da78a46c9f42.zip
cpython-0887b9ce8b5b4f9ecdef014b9329da78a46c9f42.tar.gz
cpython-0887b9ce8b5b4f9ecdef014b9329da78a46c9f42.tar.bz2
GH-109369 Add vectorcall to `PyLong_Type` (GH-111642)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index e73de74..fae70dd 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -5,6 +5,7 @@
#include "Python.h"
#include "pycore_bitutils.h" // _Py_popcount32()
#include "pycore_initconfig.h" // _PyStatus_OK()
+#include "pycore_call.h" // _PyObject_MakeTpCall
#include "pycore_long.h" // _Py_SmallInts
#include "pycore_object.h" // _PyObject_Init()
#include "pycore_runtime.h" // _PY_NSMALLPOSINTS
@@ -6152,6 +6153,29 @@ int_is_integer_impl(PyObject *self)
Py_RETURN_TRUE;
}
+static PyObject *
+long_vectorcall(PyObject *type, PyObject * const*args,
+ size_t nargsf, PyObject *kwnames)
+{
+ Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ if (kwnames != NULL) {
+ PyThreadState *tstate = PyThreadState_GET();
+ return _PyObject_MakeTpCall(tstate, type, args, nargs, kwnames);
+ }
+ switch (nargs) {
+ case 0:
+ return _PyLong_GetZero();
+ case 1:
+ return PyNumber_Long(args[0]);
+ case 2:
+ return long_new_impl(_PyType_CAST(type), args[0], args[1]);
+ default:
+ return PyErr_Format(PyExc_TypeError,
+ "int expected at most 2 argument%s, got %zd",
+ nargs);
+ }
+}
+
static PyMethodDef long_methods[] = {
{"conjugate", long_long_meth, METH_NOARGS,
"Returns self, the complex conjugate of any int."},
@@ -6289,6 +6313,7 @@ PyTypeObject PyLong_Type = {
0, /* tp_alloc */
long_new, /* tp_new */
PyObject_Free, /* tp_free */
+ .tp_vectorcall = long_vectorcall,
};
static PyTypeObject Int_InfoType;