From d79b0592d0b241da8b27fca15828c9aecc60d51b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 25 Aug 2023 23:32:17 +0200 Subject: [PATCH] gh-85283: _statistics uses the limited C API Argument Clinic supports positional-only arguments for the limited C API. --- ...3-08-25-23-33-31.gh-issue-85283.7t0PPx.rst | 2 + Modules/_statisticsmodule.c | 2 + Modules/clinic/_statisticsmodule.c.h | 46 ++----------------- 3 files changed, 9 insertions(+), 41 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2023-08-25-23-33-31.gh-issue-85283.7t0PPx.rst diff --git a/Misc/NEWS.d/next/Build/2023-08-25-23-33-31.gh-issue-85283.7t0PPx.rst b/Misc/NEWS.d/next/Build/2023-08-25-23-33-31.gh-issue-85283.7t0PPx.rst new file mode 100644 index 00000000000000..032813101574ea --- /dev/null +++ b/Misc/NEWS.d/next/Build/2023-08-25-23-33-31.gh-issue-85283.7t0PPx.rst @@ -0,0 +1,2 @@ +The ``_statistics`` C extension is now built with the :ref:`Limited API +`. Patch by Victor Stinner. diff --git a/Modules/_statisticsmodule.c b/Modules/_statisticsmodule.c index 1d5465fbe6d04e..a055110ebeb70f 100644 --- a/Modules/_statisticsmodule.c +++ b/Modules/_statisticsmodule.c @@ -1,5 +1,7 @@ /* statistics accelerator C extension: _statistics module. */ +#define Py_LIMITED_API 0x030d0000 + #include "Python.h" #include "clinic/_statisticsmodule.c.h" diff --git a/Modules/clinic/_statisticsmodule.c.h b/Modules/clinic/_statisticsmodule.c.h index 4dedadd2939ad6..289b39c52c80db 100644 --- a/Modules/clinic/_statisticsmodule.c.h +++ b/Modules/clinic/_statisticsmodule.c.h @@ -2,26 +2,20 @@ preserve [clinic start generated code]*/ -#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) -# include "pycore_gc.h" // PyGC_Head -# include "pycore_runtime.h" // _Py_ID() -#endif - - PyDoc_STRVAR(_statistics__normal_dist_inv_cdf__doc__, "_normal_dist_inv_cdf($module, p, mu, sigma, /)\n" "--\n" "\n"); #define _STATISTICS__NORMAL_DIST_INV_CDF_METHODDEF \ - {"_normal_dist_inv_cdf", _PyCFunction_CAST(_statistics__normal_dist_inv_cdf), METH_FASTCALL, _statistics__normal_dist_inv_cdf__doc__}, + {"_normal_dist_inv_cdf", (PyCFunction)_statistics__normal_dist_inv_cdf, METH_VARARGS, _statistics__normal_dist_inv_cdf__doc__}, static double _statistics__normal_dist_inv_cdf_impl(PyObject *module, double p, double mu, double sigma); static PyObject * -_statistics__normal_dist_inv_cdf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +_statistics__normal_dist_inv_cdf(PyObject *module, PyObject *args) { PyObject *return_value = NULL; double p; @@ -29,39 +23,9 @@ _statistics__normal_dist_inv_cdf(PyObject *module, PyObject *const *args, Py_ssi double sigma; double _return_value; - if (!_PyArg_CheckPositional("_normal_dist_inv_cdf", nargs, 3, 3)) { + if (!PyArg_ParseTuple(args, "ddd:_normal_dist_inv_cdf", + &p, &mu, &sigma)) goto exit; - } - if (PyFloat_CheckExact(args[0])) { - p = PyFloat_AS_DOUBLE(args[0]); - } - else - { - p = PyFloat_AsDouble(args[0]); - if (p == -1.0 && PyErr_Occurred()) { - goto exit; - } - } - if (PyFloat_CheckExact(args[1])) { - mu = PyFloat_AS_DOUBLE(args[1]); - } - else - { - mu = PyFloat_AsDouble(args[1]); - if (mu == -1.0 && PyErr_Occurred()) { - goto exit; - } - } - if (PyFloat_CheckExact(args[2])) { - sigma = PyFloat_AS_DOUBLE(args[2]); - } - else - { - sigma = PyFloat_AsDouble(args[2]); - if (sigma == -1.0 && PyErr_Occurred()) { - goto exit; - } - } _return_value = _statistics__normal_dist_inv_cdf_impl(module, p, mu, sigma); if ((_return_value == -1.0) && PyErr_Occurred()) { goto exit; @@ -71,4 +35,4 @@ _statistics__normal_dist_inv_cdf(PyObject *module, PyObject *const *args, Py_ssi exit: return return_value; } -/*[clinic end generated code: output=6899dc752cc6b457 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=63371081183774c9 input=a9049054013a1b77]*/