Skip to content

Commit c14c173

Browse files
cmaloneyclaude
andcommitted
gh-87613: Migrate int.__new__ to clinic-generated vectorcall
Replace the hand-written long_vectorcall with a clinic-generated version using the @vectorcall decorator, reducing maintenance burden while preserving the same fast calling path. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 79b71f7 commit c14c173

File tree

2 files changed

+85
-25
lines changed

2 files changed

+85
-25
lines changed

Objects/clinic/longobject.c.h

Lines changed: 83 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/longobject.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5969,6 +5969,7 @@ static PyObject *
59695969
long_subtype_new(PyTypeObject *type, PyObject *x, PyObject *obase);
59705970

59715971
/*[clinic input]
5972+
@vectorcall zero_arg=_PyLong_GetZero()
59725973
@classmethod
59735974
int.__new__ as long_new
59745975
x: object(c_default="NULL") = 0
@@ -5978,7 +5979,7 @@ int.__new__ as long_new
59785979

59795980
static PyObject *
59805981
long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase)
5981-
/*[clinic end generated code: output=e47cfe777ab0f24c input=81c98f418af9eb6f]*/
5982+
/*[clinic end generated code: output=e47cfe777ab0f24c input=fa144948f64fa26d]*/
59825983
{
59835984
Py_ssize_t base;
59845985

@@ -6535,29 +6536,6 @@ int_is_integer_impl(PyObject *self)
65356536
Py_RETURN_TRUE;
65366537
}
65376538

6538-
static PyObject *
6539-
long_vectorcall(PyObject *type, PyObject * const*args,
6540-
size_t nargsf, PyObject *kwnames)
6541-
{
6542-
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
6543-
if (kwnames != NULL) {
6544-
PyThreadState *tstate = PyThreadState_GET();
6545-
return _PyObject_MakeTpCall(tstate, type, args, nargs, kwnames);
6546-
}
6547-
switch (nargs) {
6548-
case 0:
6549-
return _PyLong_GetZero();
6550-
case 1:
6551-
return PyNumber_Long(args[0]);
6552-
case 2:
6553-
return long_new_impl(_PyType_CAST(type), args[0], args[1]);
6554-
default:
6555-
return PyErr_Format(PyExc_TypeError,
6556-
"int expected at most 2 arguments, got %zd",
6557-
nargs);
6558-
}
6559-
}
6560-
65616539
static PyMethodDef long_methods[] = {
65626540
{"conjugate", long_long_meth, METH_NOARGS,
65636541
"Returns self, the complex conjugate of any int."},

0 commit comments

Comments
 (0)