From caf8a54947cd02df44195621a8d70d3dc54f7d89 Mon Sep 17 00:00:00 2001 From: Tan Long Date: Sun, 22 Nov 2026 21:54:27 +0800 Subject: [PATCH 1/5] memoryview AC vectorcall --- Objects/clinic/memoryobject.c.h | 40 +++++++++++++++++++++++++++++---- Objects/memoryobject.c | 4 +++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h index 93daf550b0092c..bb81e11e9a0ce2 100644 --- a/Objects/clinic/memoryobject.c.h +++ b/Objects/clinic/memoryobject.c.h @@ -20,7 +20,8 @@ static PyObject * memoryview_impl(PyTypeObject *type, PyObject *object); static PyObject * -memoryview(PyTypeObject *type, PyObject *args, PyObject *kwargs) +memoryview_helper(PyTypeObject *type, PyObject *const *args, + Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -52,10 +53,9 @@ memoryview(PyTypeObject *type, PyObject *args, PyObject *kwargs) #undef KWTUPLE PyObject *argsbuf[1]; PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); PyObject *object; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, + fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); if (!fastargs) { goto exit; @@ -67,6 +67,38 @@ memoryview(PyTypeObject *type, PyObject *args, PyObject *kwargs) return return_value; } +static PyObject * +memoryview(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + return memoryview_helper(type, _PyTuple_CAST(args)->ob_item, + PyTuple_GET_SIZE(args), + kwargs ? PyDict_GET_SIZE(kwargs) : 0, + kwargs, NULL); +} + +static PyObject * +memoryview_vectorcall(PyObject *type, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + PyObject *return_value = NULL; + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + PyObject *object; + + assert(_PyType_CAST(type)->tp_new == memoryview); + /* Make sure the type object is immutable: the generated + * vectorcall doesn't deal e.g. with users reassigning __init__. */ + assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); + if (kwnames != NULL || nargs < 1 || nargs > 1) { + return memoryview_helper(_PyType_CAST(type), args, nargs, + kwnames ? PyTuple_GET_SIZE(kwnames) : 0, + NULL, kwnames); + } + object = args[0]; + return_value = memoryview_impl(_PyType_CAST(type), object); + + return return_value; +} + PyDoc_STRVAR(memoryview__from_flags__doc__, "_from_flags($type, /, object, flags)\n" "--\n" @@ -556,4 +588,4 @@ memoryview_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=889b7cc1a94bfc9b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=cdca13a132752f15 input=a9049054013a1b77]*/ diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index 11a0a7ab04f08b..d695d8cac2feda 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -1131,6 +1131,7 @@ PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order) /*[clinic input] +@vectorcall @classmethod memoryview.__new__ @@ -1141,7 +1142,7 @@ Create a new memoryview object which references the given object. static PyObject * memoryview_impl(PyTypeObject *type, PyObject *object) -/*[clinic end generated code: output=7de78e184ed66db8 input=f04429eb0bdf8c6e]*/ +/*[clinic end generated code: output=7de78e184ed66db8 input=8e10a66aebe8e657]*/ { return PyMemoryView_FromObject(object); } @@ -4136,4 +4137,5 @@ PyTypeObject PyMemoryView_Type = { 0, /* tp_init */ 0, /* tp_alloc */ memoryview, /* tp_new */ + .tp_vectorcall = memoryview_vectorcall, }; From 04722b77dd4ac70a10035d306d58b796468975c3 Mon Sep 17 00:00:00 2001 From: Tan Long Date: Sun, 22 Nov 2026 21:54:28 +0800 Subject: [PATCH 2/5] property AC vectorcall --- Objects/clinic/descrobject.c.h | 86 +++++++++++++++++++++++++++++++--- Objects/descrobject.c | 4 +- 2 files changed, 83 insertions(+), 7 deletions(-) diff --git a/Objects/clinic/descrobject.c.h b/Objects/clinic/descrobject.c.h index 744e5edf922b57..f1bc37933d120d 100644 --- a/Objects/clinic/descrobject.c.h +++ b/Objects/clinic/descrobject.c.h @@ -4,9 +4,9 @@ preserve #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head -# include "pycore_runtime.h" // _Py_ID() #endif #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_runtime.h" // _Py_SINGLETON() PyDoc_STRVAR(mappingproxy_new__doc__, "mappingproxy(mapping)\n" @@ -138,7 +138,8 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, PyObject *fdel, PyObject *doc); static int -property_init(PyObject *self, PyObject *args, PyObject *kwargs) +property_init_helper(PyObject *self, PyObject *const *args, + Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) { int return_value = -1; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -170,14 +171,13 @@ property_init(PyObject *self, PyObject *args, PyObject *kwargs) #undef KWTUPLE PyObject *argsbuf[4]; PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; + Py_ssize_t noptargs = nargs + nkw - 0; PyObject *fget = NULL; PyObject *fset = NULL; PyObject *fdel = NULL; PyObject *doc = NULL; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, + fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, /*minpos*/ 0, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); if (!fastargs) { goto exit; @@ -210,4 +210,78 @@ property_init(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=fb62ee8be13af793 input=a9049054013a1b77]*/ + +static int +property_init(PyObject *self, PyObject *args, PyObject *kwargs) +{ + return property_init_helper(self, _PyTuple_CAST(args)->ob_item, + PyTuple_GET_SIZE(args), + kwargs ? PyDict_GET_SIZE(kwargs) : 0, + kwargs, NULL); +} + +static PyObject * +property_vectorcall(PyObject *type, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + PyObject *return_value = NULL; + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + PyObject *self; + int _result; + PyObject *fget = NULL; + PyObject *fset = NULL; + PyObject *fdel = NULL; + PyObject *doc = NULL; + + assert(_PyType_CAST(type)->tp_init == property_init); + /* Make sure the type object is immutable: the generated + * vectorcall doesn't deal e.g. with users reassigning __init__. */ + assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); + if (kwnames != NULL || nargs > 4) { + self = _PyType_CAST(type)->tp_new(_PyType_CAST(type), + (PyObject *)&_Py_SINGLETON(tuple_empty), NULL); + if (self == NULL) { + return NULL; + } + _result = property_init_helper(self, args, nargs, + kwnames ? PyTuple_GET_SIZE(kwnames) : 0, + NULL, kwnames); + if (_result != 0) { + Py_DECREF(self); + return NULL; + } + return self; + } + if (nargs < 1) { + goto skip_optional; + } + fget = args[0]; + if (nargs < 2) { + goto skip_optional; + } + fset = args[1]; + if (nargs < 3) { + goto skip_optional; + } + fdel = args[2]; + if (nargs < 4) { + goto skip_optional; + } + doc = args[3]; +skip_optional: + self = _PyType_CAST(type)->tp_new(_PyType_CAST(type), + (PyObject *)&_Py_SINGLETON(tuple_empty), NULL); + if (self == NULL) { + goto exit; + } + _result = property_init_impl((propertyobject *)self, fget, fset, fdel, doc); + if (_result != 0) { + Py_DECREF(self); + goto exit; + } + return_value = self; + +exit: + return return_value; +} +/*[clinic end generated code: output=d9469a062823c117 input=a9049054013a1b77]*/ diff --git a/Objects/descrobject.c b/Objects/descrobject.c index c4e525797d19ae..6d186cb3db951b 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1816,6 +1816,7 @@ property_copy(PyObject *old, PyObject *get, PyObject *set, PyObject *del) } /*[clinic input] +@vectorcall property.__init__ as property_init fget: object(c_default="NULL") = None @@ -1855,7 +1856,7 @@ class C(object): static int property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, PyObject *fdel, PyObject *doc) -/*[clinic end generated code: output=01a960742b692b57 input=dfb5dbbffc6932d5]*/ +/*[clinic end generated code: output=01a960742b692b57 input=ea89304c10df241b]*/ { if (fget == Py_None) fget = NULL; @@ -2101,4 +2102,5 @@ PyTypeObject PyProperty_Type = { PyType_GenericAlloc, /* tp_alloc */ PyType_GenericNew, /* tp_new */ PyObject_GC_Del, /* tp_free */ + .tp_vectorcall = property_vectorcall, }; From 0d28c475fe118b4c352f51601d4dcfe947c51214 Mon Sep 17 00:00:00 2001 From: Tan Long Date: Sun, 22 Nov 2026 21:54:29 +0800 Subject: [PATCH 3/5] sentinel AC vectorcall --- Objects/clinic/sentinelobject.c.h | 34 ++++++++++++++++++++++++++----- Objects/sentinelobject.c | 4 +++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Objects/clinic/sentinelobject.c.h b/Objects/clinic/sentinelobject.c.h index f8503194ae5c74..1f7d82c524a24c 100644 --- a/Objects/clinic/sentinelobject.c.h +++ b/Objects/clinic/sentinelobject.c.h @@ -12,7 +12,8 @@ static PyObject * sentinel_new_impl(PyTypeObject *type, PyObject *name, PyObject *repr); static PyObject * -sentinel_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +sentinel_new_helper(PyTypeObject *type, PyObject *const *args, + Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -44,12 +45,11 @@ sentinel_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) #undef KWTUPLE PyObject *argsbuf[2]; PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; + Py_ssize_t noptargs = nargs + nkw - 1; PyObject *name; PyObject *repr = Py_None; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, + fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); if (!fastargs) { goto exit; @@ -69,4 +69,28 @@ sentinel_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=958842ece254c82f input=a9049054013a1b77]*/ + +static PyObject * +sentinel_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + return sentinel_new_helper(type, _PyTuple_CAST(args)->ob_item, + PyTuple_GET_SIZE(args), + kwargs ? PyDict_GET_SIZE(kwargs) : 0, + kwargs, NULL); +} + +static PyObject * +sentinel_vectorcall(PyObject *type, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + + assert(_PyType_CAST(type)->tp_new == sentinel_new); + /* Make sure the type object is immutable: the generated + * vectorcall doesn't deal e.g. with users reassigning __init__. */ + assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); + return sentinel_new_helper(_PyType_CAST(type), args, nargs, + kwnames ? PyTuple_GET_SIZE(kwnames) : 0, + NULL, kwnames); +} +/*[clinic end generated code: output=388b220fe03ae62c input=a9049054013a1b77]*/ diff --git a/Objects/sentinelobject.c b/Objects/sentinelobject.c index 77bffbc397be58..aa8bb963348b71 100644 --- a/Objects/sentinelobject.c +++ b/Objects/sentinelobject.c @@ -63,6 +63,7 @@ sentinel_new_with_module(PyTypeObject *type, PyObject *name, PyObject *module, P } /*[clinic input] +@vectorcall @classmethod sentinel.__new__ as sentinel_new @@ -74,7 +75,7 @@ sentinel.__new__ as sentinel_new static PyObject * sentinel_new_impl(PyTypeObject *type, PyObject *name, PyObject *repr) -/*[clinic end generated code: output=1eb7fab52e57d8c8 input=28cab6c468997b35]*/ +/*[clinic end generated code: output=1eb7fab52e57d8c8 input=af2ba470062edc82]*/ { if (repr == Py_None) { repr = NULL; @@ -218,5 +219,6 @@ PyTypeObject PySentinel_Type = { .tp_methods = sentinel_methods, .tp_members = sentinel_members, .tp_new = sentinel_new, + .tp_vectorcall = sentinel_vectorcall, .tp_free = PyObject_GC_Del, }; From 2c3d3f748dc117cfd128632e133a9131b5eb09d1 Mon Sep 17 00:00:00 2001 From: Tan Long Date: Sun, 22 Nov 2026 21:54:31 +0800 Subject: [PATCH 4/5] typing TypeAliasType/ParamSpecArgs/ParamSpecKwargs AC vectorcall --- Objects/clinic/typevarobject.c.h | 110 +++++++++++++++++++++++++++---- Objects/typevarobject.c | 12 +++- 2 files changed, 108 insertions(+), 14 deletions(-) diff --git a/Objects/clinic/typevarobject.c.h b/Objects/clinic/typevarobject.c.h index 95f09faceba0b5..a14f8cdace44da 100644 --- a/Objects/clinic/typevarobject.c.h +++ b/Objects/clinic/typevarobject.c.h @@ -219,7 +219,8 @@ static PyObject * paramspecargs_new_impl(PyTypeObject *type, PyObject *origin); static PyObject * -paramspecargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +paramspecargs_new_helper(PyTypeObject *type, PyObject *const *args, + Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -251,10 +252,9 @@ paramspecargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) #undef KWTUPLE PyObject *argsbuf[1]; PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); PyObject *origin; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, + fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); if (!fastargs) { goto exit; @@ -266,6 +266,38 @@ paramspecargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return return_value; } +static PyObject * +paramspecargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + return paramspecargs_new_helper(type, _PyTuple_CAST(args)->ob_item, + PyTuple_GET_SIZE(args), + kwargs ? PyDict_GET_SIZE(kwargs) : 0, + kwargs, NULL); +} + +static PyObject * +paramspecargs_vectorcall(PyObject *type, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + PyObject *return_value = NULL; + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + PyObject *origin; + + assert(_PyType_CAST(type)->tp_new == paramspecargs_new); + /* Make sure the type object is immutable: the generated + * vectorcall doesn't deal e.g. with users reassigning __init__. */ + assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); + if (kwnames != NULL || nargs < 1 || nargs > 1) { + return paramspecargs_new_helper(_PyType_CAST(type), args, nargs, + kwnames ? PyTuple_GET_SIZE(kwnames) : 0, + NULL, kwnames); + } + origin = args[0]; + return_value = paramspecargs_new_impl(_PyType_CAST(type), origin); + + return return_value; +} + PyDoc_STRVAR(paramspeckwargs_new__doc__, "paramspeckwargs(origin)\n" "--\n" @@ -276,7 +308,8 @@ static PyObject * paramspeckwargs_new_impl(PyTypeObject *type, PyObject *origin); static PyObject * -paramspeckwargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +paramspeckwargs_new_helper(PyTypeObject *type, PyObject *const *args, + Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -308,10 +341,9 @@ paramspeckwargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) #undef KWTUPLE PyObject *argsbuf[1]; PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); PyObject *origin; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, + fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); if (!fastargs) { goto exit; @@ -323,6 +355,38 @@ paramspeckwargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return return_value; } +static PyObject * +paramspeckwargs_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + return paramspeckwargs_new_helper(type, _PyTuple_CAST(args)->ob_item, + PyTuple_GET_SIZE(args), + kwargs ? PyDict_GET_SIZE(kwargs) : 0, + kwargs, NULL); +} + +static PyObject * +paramspeckwargs_vectorcall(PyObject *type, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + PyObject *return_value = NULL; + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + PyObject *origin; + + assert(_PyType_CAST(type)->tp_new == paramspeckwargs_new); + /* Make sure the type object is immutable: the generated + * vectorcall doesn't deal e.g. with users reassigning __init__. */ + assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); + if (kwnames != NULL || nargs < 1 || nargs > 1) { + return paramspeckwargs_new_helper(_PyType_CAST(type), args, nargs, + kwnames ? PyTuple_GET_SIZE(kwnames) : 0, + NULL, kwnames); + } + origin = args[0]; + return_value = paramspeckwargs_new_impl(_PyType_CAST(type), origin); + + return return_value; +} + PyDoc_STRVAR(paramspec_new__doc__, "paramspec(name, *, bound=None, default=typing.NoDefault,\n" " covariant=False, contravariant=False, infer_variance=False)\n" @@ -737,7 +801,8 @@ typealias_new_impl(PyTypeObject *type, PyObject *name, PyObject *value, PyObject *type_params, PyObject *qualname); static PyObject * -typealias_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +typealias_new_helper(PyTypeObject *type, PyObject *const *args, + Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -769,14 +834,13 @@ typealias_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) #undef KWTUPLE PyObject *argsbuf[4]; PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); - Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2; + Py_ssize_t noptargs = nargs + nkw - 2; PyObject *name; PyObject *value; PyObject *type_params = NULL; PyObject *qualname = NULL; - fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, + fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); if (!fastargs) { goto exit; @@ -803,4 +867,28 @@ typealias_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=310ab79d0f3a4b5c input=a9049054013a1b77]*/ + +static PyObject * +typealias_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + return typealias_new_helper(type, _PyTuple_CAST(args)->ob_item, + PyTuple_GET_SIZE(args), + kwargs ? PyDict_GET_SIZE(kwargs) : 0, + kwargs, NULL); +} + +static PyObject * +typealias_vectorcall(PyObject *type, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + + assert(_PyType_CAST(type)->tp_new == typealias_new); + /* Make sure the type object is immutable: the generated + * vectorcall doesn't deal e.g. with users reassigning __init__. */ + assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); + return typealias_new_helper(_PyType_CAST(type), args, nargs, + kwnames ? PyTuple_GET_SIZE(kwnames) : 0, + NULL, kwnames); +} +/*[clinic end generated code: output=87b75f9eb5c613f1 input=a9049054013a1b77]*/ diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c index 11ff8320fd9a48..5eb78093f3596d 100644 --- a/Objects/typevarobject.c +++ b/Objects/typevarobject.c @@ -1025,6 +1025,7 @@ paramspecargs_repr(PyObject *self) /*[clinic input] +@vectorcall @classmethod paramspecargs.__new__ as paramspecargs_new @@ -1035,7 +1036,7 @@ Create a ParamSpecArgs object. static PyObject * paramspecargs_new_impl(PyTypeObject *type, PyObject *origin) -/*[clinic end generated code: output=9a1463dc8942fe4e input=3596a0bb6183c208]*/ +/*[clinic end generated code: output=9a1463dc8942fe4e input=af38ada22a6b114a]*/ { return (PyObject *)paramspecattr_new(type, origin); } @@ -1072,6 +1073,7 @@ static PyType_Slot paramspecargs_slots[] = { {Py_tp_doc, (void *)paramspecargs_doc}, {Py_tp_methods, paramspecargs_methods}, {Py_tp_new, paramspecargs_new}, + {Py_tp_vectorcall, paramspecargs_vectorcall}, {Py_tp_dealloc, paramspecattr_dealloc}, {Py_tp_alloc, PyType_GenericAlloc}, {Py_tp_free, PyObject_GC_Del}, @@ -1105,6 +1107,7 @@ paramspeckwargs_repr(PyObject *self) } /*[clinic input] +@vectorcall @classmethod paramspeckwargs.__new__ as paramspeckwargs_new @@ -1115,7 +1118,7 @@ Create a ParamSpecKwargs object. static PyObject * paramspeckwargs_new_impl(PyTypeObject *type, PyObject *origin) -/*[clinic end generated code: output=277b11967ebaf4ab input=981bca9b0cf9e40a]*/ +/*[clinic end generated code: output=277b11967ebaf4ab input=200fd6f0d3ea40ba]*/ { return (PyObject *)paramspecattr_new(type, origin); } @@ -1152,6 +1155,7 @@ static PyType_Slot paramspeckwargs_slots[] = { {Py_tp_doc, (void *)paramspeckwargs_doc}, {Py_tp_methods, paramspeckwargs_methods}, {Py_tp_new, paramspeckwargs_new}, + {Py_tp_vectorcall, paramspeckwargs_vectorcall}, {Py_tp_dealloc, paramspecattr_dealloc}, {Py_tp_alloc, PyType_GenericAlloc}, {Py_tp_free, PyObject_GC_Del}, @@ -2149,6 +2153,7 @@ static PyMethodDef typealias_methods[] = { /*[clinic input] +@vectorcall @classmethod typealias.__new__ as typealias_new @@ -2164,7 +2169,7 @@ Create a TypeAliasType. static PyObject * typealias_new_impl(PyTypeObject *type, PyObject *name, PyObject *value, PyObject *type_params, PyObject *qualname) -/*[clinic end generated code: output=b7f6d9f1c577cd9c input=6516623275f87b5e]*/ +/*[clinic end generated code: output=b7f6d9f1c577cd9c input=7245ee7629d55ea9]*/ { if (type_params != NULL && !PyTuple_Check(type_params)) { PyErr_SetString(PyExc_TypeError, "type_params must be a tuple"); @@ -2245,6 +2250,7 @@ PyTypeObject _PyTypeAlias_Type = { .tp_alloc = PyType_GenericAlloc, .tp_dealloc = typealias_dealloc, .tp_new = typealias_new, + .tp_vectorcall = typealias_vectorcall, .tp_free = PyObject_GC_Del, .tp_iter = unpack_iter, .tp_traverse = typealias_traverse, From 2581acd8ec78f9bd8aa8dd722f7b5ee9db0c2c42 Mon Sep 17 00:00:00 2001 From: Tan Long Date: Mon, 23 Nov 2026 11:06:33 +0800 Subject: [PATCH 5/5] Revert "memoryview AC vectorcall" This reverts commit caf8a54947cd02df44195621a8d70d3dc54f7d89. --- Objects/clinic/memoryobject.c.h | 40 ++++----------------------------- Objects/memoryobject.c | 4 +--- 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h index bb81e11e9a0ce2..93daf550b0092c 100644 --- a/Objects/clinic/memoryobject.c.h +++ b/Objects/clinic/memoryobject.c.h @@ -20,8 +20,7 @@ static PyObject * memoryview_impl(PyTypeObject *type, PyObject *object); static PyObject * -memoryview_helper(PyTypeObject *type, PyObject *const *args, - Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) +memoryview(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -53,9 +52,10 @@ memoryview_helper(PyTypeObject *type, PyObject *const *args, #undef KWTUPLE PyObject *argsbuf[1]; PyObject * const *fastargs; + Py_ssize_t nargs = PyTuple_GET_SIZE(args); PyObject *object; - fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, + fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); if (!fastargs) { goto exit; @@ -67,38 +67,6 @@ memoryview_helper(PyTypeObject *type, PyObject *const *args, return return_value; } -static PyObject * -memoryview(PyTypeObject *type, PyObject *args, PyObject *kwargs) -{ - return memoryview_helper(type, _PyTuple_CAST(args)->ob_item, - PyTuple_GET_SIZE(args), - kwargs ? PyDict_GET_SIZE(kwargs) : 0, - kwargs, NULL); -} - -static PyObject * -memoryview_vectorcall(PyObject *type, PyObject *const *args, - size_t nargsf, PyObject *kwnames) -{ - PyObject *return_value = NULL; - Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); - PyObject *object; - - assert(_PyType_CAST(type)->tp_new == memoryview); - /* Make sure the type object is immutable: the generated - * vectorcall doesn't deal e.g. with users reassigning __init__. */ - assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); - if (kwnames != NULL || nargs < 1 || nargs > 1) { - return memoryview_helper(_PyType_CAST(type), args, nargs, - kwnames ? PyTuple_GET_SIZE(kwnames) : 0, - NULL, kwnames); - } - object = args[0]; - return_value = memoryview_impl(_PyType_CAST(type), object); - - return return_value; -} - PyDoc_STRVAR(memoryview__from_flags__doc__, "_from_flags($type, /, object, flags)\n" "--\n" @@ -588,4 +556,4 @@ memoryview_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=cdca13a132752f15 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=889b7cc1a94bfc9b input=a9049054013a1b77]*/ diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index d695d8cac2feda..11a0a7ab04f08b 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -1131,7 +1131,6 @@ PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order) /*[clinic input] -@vectorcall @classmethod memoryview.__new__ @@ -1142,7 +1141,7 @@ Create a new memoryview object which references the given object. static PyObject * memoryview_impl(PyTypeObject *type, PyObject *object) -/*[clinic end generated code: output=7de78e184ed66db8 input=8e10a66aebe8e657]*/ +/*[clinic end generated code: output=7de78e184ed66db8 input=f04429eb0bdf8c6e]*/ { return PyMemoryView_FromObject(object); } @@ -4137,5 +4136,4 @@ PyTypeObject PyMemoryView_Type = { 0, /* tp_init */ 0, /* tp_alloc */ memoryview, /* tp_new */ - .tp_vectorcall = memoryview_vectorcall, };