diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 3a87440c63e8d24..d17b3df4dfbbb14 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -302,6 +302,7 @@ get_weak_cache(zoneinfo_state *state, PyTypeObject *type) } /*[clinic input] +@vectorcall @critical_section @classmethod zoneinfo.ZoneInfo.__new__ @@ -313,7 +314,7 @@ Create a new ZoneInfo instance. static PyObject * zoneinfo_ZoneInfo_impl(PyTypeObject *type, PyObject *key) -/*[clinic end generated code: output=95e61dab86bb95c3 input=ef73d7a83bf8790e]*/ +/*[clinic end generated code: output=95e61dab86bb95c3 input=8cb93934e6a8d11b]*/ { zoneinfo_state *state = zoneinfo_get_state_by_self(type); PyObject *instance = zone_from_strong_cache(state, type, key); @@ -2685,6 +2686,7 @@ static PyType_Slot zoneinfo_slots[] = { {Py_tp_methods, zoneinfo_methods}, {Py_tp_members, zoneinfo_members}, {Py_tp_new, zoneinfo_ZoneInfo}, + {Py_tp_vectorcall, zoneinfo_ZoneInfo_vectorcall}, {Py_tp_dealloc, zoneinfo_dealloc}, {Py_tp_traverse, zoneinfo_traverse}, {Py_tp_clear, zoneinfo_clear}, diff --git a/Modules/clinic/_zoneinfo.c.h b/Modules/clinic/_zoneinfo.c.h index b3c5defcbd937d1..4ec36c2209a7743 100644 --- a/Modules/clinic/_zoneinfo.c.h +++ b/Modules/clinic/_zoneinfo.c.h @@ -19,7 +19,8 @@ static PyObject * zoneinfo_ZoneInfo_impl(PyTypeObject *type, PyObject *key); static PyObject * -zoneinfo_ZoneInfo(PyTypeObject *type, PyObject *args, PyObject *kwargs) +zoneinfo_ZoneInfo_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) @@ -51,10 +52,9 @@ zoneinfo_ZoneInfo(PyTypeObject *type, PyObject *args, PyObject *kwargs) #undef KWTUPLE PyObject *argsbuf[1]; PyObject * const *fastargs; - Py_ssize_t nargs = PyTuple_GET_SIZE(args); PyObject *key; - 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; @@ -68,6 +68,40 @@ zoneinfo_ZoneInfo(PyTypeObject *type, PyObject *args, PyObject *kwargs) return return_value; } +static PyObject * +zoneinfo_ZoneInfo(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + return zoneinfo_ZoneInfo_helper(type, _PyTuple_CAST(args)->ob_item, + PyTuple_GET_SIZE(args), + kwargs ? PyDict_GET_SIZE(kwargs) : 0, + kwargs, NULL); +} + +static PyObject * +zoneinfo_ZoneInfo_vectorcall(PyObject *type, PyObject *const *args, + size_t nargsf, PyObject *kwnames) +{ + PyObject *return_value = NULL; + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); + PyObject *key; + + assert(_PyType_CAST(type)->tp_new == zoneinfo_ZoneInfo); + /* 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 zoneinfo_ZoneInfo_helper(_PyType_CAST(type), args, nargs, + kwnames ? PyTuple_GET_SIZE(kwnames) : 0, + NULL, kwnames); + } + key = args[0]; + Py_BEGIN_CRITICAL_SECTION(type); + return_value = zoneinfo_ZoneInfo_impl(_PyType_CAST(type), key); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + PyDoc_STRVAR(zoneinfo_ZoneInfo_from_file__doc__, "from_file($type, file_obj, /, key=None)\n" "--\n" @@ -434,4 +468,4 @@ zoneinfo_ZoneInfo___init_subclass__(PyObject *type, PyObject *args, PyObject *kw return return_value; } -/*[clinic end generated code: output=42fad9178a9395ea input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e64d1d5b38e0c6e5 input=a9049054013a1b77]*/