From: Sam Gross Date: Fri, 3 May 2024 15:33:05 +0000 (-0400) Subject: gh-118527: Use deferred reference counting for C functions on modules (#118529) X-Git-Tag: v3.13.0b1~135 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=608192ee2f6c60aaae1c6f2f64ea45ad2667ff2d;p=thirdparty%2FPython%2Fcpython.git gh-118527: Use deferred reference counting for C functions on modules (#118529) This addresses a scaling bottleneck in the free-threaded build when calling functions like `math.floor()` concurrently from multiple threads. --- diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index d877edaf5453..a570b13e1208 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -183,6 +183,7 @@ _add_methods_to_object(PyObject *module, PyObject *name, PyMethodDef *functions) if (func == NULL) { return -1; } + _PyObject_SetDeferredRefcount(func); if (PyObject_SetAttrString(module, fdef->ml_name, func) != 0) { Py_DECREF(func); return -1;